2010-10-03 23:04:50 +02:00
|
|
|
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "cef_context.h"
|
|
|
|
#include "browser_impl.h"
|
2010-11-18 22:05:25 +01:00
|
|
|
#include "browser_settings.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "printing/units.h"
|
|
|
|
|
|
|
|
#include "skia/ext/vector_canvas.h"
|
2011-05-16 18:56:12 +02:00
|
|
|
#include "skia/ext/vector_platform_device_emf_win.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
|
|
|
#include "ui/base/win/hwnd_util.h"
|
2010-11-18 22:05:25 +01:00
|
|
|
#include "webkit/glue/webpreferences.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
#include <shellapi.h>
|
|
|
|
#include <shlwapi.h>
|
|
|
|
#include <wininet.h>
|
|
|
|
#include <winspool.h>
|
|
|
|
|
|
|
|
using WebKit::WebRect;
|
|
|
|
using WebKit::WebSize;
|
|
|
|
|
|
|
|
|
|
|
|
LPCTSTR CefBrowserImpl::GetWndClass()
|
|
|
|
{
|
|
|
|
return L"CefBrowserWindow";
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
|
|
|
|
WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
CefBrowserImpl* browser =
|
2011-02-15 19:07:24 +01:00
|
|
|
static_cast<CefBrowserImpl*>(ui::GetWindowUserData(hwnd));
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
switch (message) {
|
2011-06-14 17:09:55 +02:00
|
|
|
case WM_CLOSE:
|
|
|
|
// It is the responsibility of the client to send this message to this
|
|
|
|
// window if it is created as a child window of a client's frame window.
|
|
|
|
// This is particularly important when this window is modal.
|
|
|
|
if(browser) {
|
|
|
|
// Here the window really is about to get closed.
|
|
|
|
if (browser->client_.get()) {
|
|
|
|
CefRefPtr<CefLifeSpanHandler> handler =
|
|
|
|
browser->client_->GetLifeSpanHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler that the window is about to be closed.
|
|
|
|
handler->OnBeforeClose(browser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We must re-enable the opener (owner of the modal window)
|
|
|
|
// before we close the popup to avoid focus/activation/z-order issues.
|
|
|
|
if (browser->opener_ && browser->opener_was_disabled_by_modal_loop_) {
|
|
|
|
HWND owner = ::GetAncestor(browser->opener_, GA_ROOT);
|
|
|
|
::EnableWindow(owner, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't do the default if this is a contained window as the destruction
|
|
|
|
// will occur when the parent frame window is destroyed.
|
|
|
|
if (::GetAncestor(hwnd, GA_ROOT) != hwnd)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
case WM_DESTROY:
|
2010-11-15 16:39:56 +01:00
|
|
|
if (browser) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// Clear the user data pointer.
|
2011-02-15 19:07:24 +01:00
|
|
|
ui::SetWindowUserData(hwnd, NULL);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2010-11-15 16:39:56 +01:00
|
|
|
// Destroy the browser.
|
|
|
|
browser->UIT_DestroyBrowser();
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_SIZE:
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser && browser->UIT_GetWebView()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// resize the web view window to the full size of the browser window
|
|
|
|
RECT rc;
|
2011-01-29 02:42:59 +01:00
|
|
|
GetClientRect(browser->UIT_GetMainWndHandle(), &rc);
|
|
|
|
MoveWindow(browser->UIT_GetWebViewWndHandle(), 0, 0, rc.right, rc.bottom,
|
2010-10-03 23:04:50 +02:00
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_SETFOCUS:
|
2011-06-06 17:14:35 +02:00
|
|
|
if (browser)
|
|
|
|
browser->UIT_SetFocus(browser->UIT_GetWebViewHost(), true);
|
2010-10-03 23:04:50 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_ERASEBKGND:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc(hwnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefWindowHandle CefBrowserImpl::GetWindowHandle()
|
|
|
|
{
|
2011-01-29 02:42:59 +01:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return window_info_.m_hWnd;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
bool CefBrowserImpl::IsWindowRenderingDisabled()
|
|
|
|
{
|
|
|
|
return (window_info_.m_bWindowRenderingDisabled ? true : false);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::NativeWindow CefBrowserImpl::UIT_GetMainWndHandle() {
|
2011-01-29 02:42:59 +01:00
|
|
|
REQUIRE_UIT();
|
2011-03-24 21:36:47 +01:00
|
|
|
return window_info_.m_bWindowRenderingDisabled ?
|
|
|
|
window_info_.m_hWndParent : window_info_.m_hWnd;
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
2011-01-29 02:42:59 +01:00
|
|
|
Lock();
|
2010-11-22 18:49:46 +01:00
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
if (!window_info_.m_bWindowRenderingDisabled) {
|
|
|
|
std::wstring windowName(CefString(&window_info_.m_windowName));
|
|
|
|
|
|
|
|
// Create the new browser window
|
|
|
|
window_info_.m_hWnd = CreateWindowEx(window_info_.m_dwExStyle,
|
|
|
|
GetWndClass(), windowName.c_str(), window_info_.m_dwStyle,
|
|
|
|
window_info_.m_x, window_info_.m_y, window_info_.m_nWidth,
|
|
|
|
window_info_.m_nHeight, window_info_.m_hWndParent, window_info_.m_hMenu,
|
|
|
|
::GetModuleHandle(NULL), NULL);
|
|
|
|
DCHECK(window_info_.m_hWnd != NULL);
|
|
|
|
|
|
|
|
// Set window user data to this object for future reference from the window
|
|
|
|
// procedure
|
|
|
|
ui::SetWindowUserData(window_info_.m_hWnd, this);
|
|
|
|
} else {
|
|
|
|
// Create a new paint delegate.
|
|
|
|
paint_delegate_.reset(new PaintDelegate(this));
|
|
|
|
}
|
2011-01-25 19:37:27 +01:00
|
|
|
|
|
|
|
if (!settings_.developer_tools_disabled)
|
|
|
|
dev_tools_agent_.reset(new BrowserDevToolsAgent());
|
|
|
|
|
2010-11-15 16:39:56 +01:00
|
|
|
// Add a reference that will be released in UIT_DestroyBrowser().
|
2010-10-03 23:04:50 +02:00
|
|
|
AddRef();
|
|
|
|
|
|
|
|
// Add the new browser to the list maintained by the context
|
|
|
|
_Context->AddBrowser(this);
|
|
|
|
|
2010-11-18 22:05:25 +01:00
|
|
|
WebPreferences prefs;
|
|
|
|
BrowserToWebSettings(settings_, prefs);
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Create the webview host object
|
|
|
|
webviewhost_.reset(
|
2010-11-15 16:39:56 +01:00
|
|
|
WebViewHost::Create(window_info_.m_hWnd, gfx::Rect(), delegate_.get(),
|
2011-03-24 21:36:47 +01:00
|
|
|
paint_delegate_.get(), dev_tools_agent_.get(),
|
|
|
|
prefs));
|
2011-01-25 19:37:27 +01:00
|
|
|
|
|
|
|
if (!settings_.developer_tools_disabled)
|
|
|
|
dev_tools_agent_->SetWebView(webviewhost_->webview());
|
2010-11-18 22:05:25 +01:00
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
Unlock();
|
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
if (!window_info_.m_bWindowRenderingDisabled) {
|
|
|
|
if (!settings_.drag_drop_disabled)
|
|
|
|
delegate_->RegisterDragDrop();
|
|
|
|
|
|
|
|
// Size the web view window to the browser window
|
|
|
|
RECT cr;
|
|
|
|
GetClientRect(window_info_.m_hWnd, &cr);
|
|
|
|
|
|
|
|
// Respect the WS_VISIBLE window style when setting the window's position
|
|
|
|
UINT flags = SWP_NOZORDER;
|
|
|
|
if (window_info_.m_dwStyle & WS_VISIBLE)
|
|
|
|
flags |= SWP_SHOWWINDOW;
|
|
|
|
else
|
|
|
|
flags |= SWP_NOACTIVATE;
|
|
|
|
|
|
|
|
SetWindowPos(UIT_GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
|
|
|
|
cr.bottom, flags);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
if(client_.get()) {
|
|
|
|
CefRefPtr<CefLifeSpanHandler> handler = client_->GetLifeSpanHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
// Notify the handler that we're done creating the new window
|
|
|
|
handler->OnAfterCreated(this);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-01-29 23:52:34 +01:00
|
|
|
if(url.length() > 0)
|
|
|
|
UIT_LoadURL(GetMainFrame(), url);
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
if (!host)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
::SetFocus(host->view_handle());
|
|
|
|
else if (::GetFocus() == host->view_handle())
|
|
|
|
::SetFocus(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WriteTextToFile(const std::string& data,
|
|
|
|
const std::wstring& file_path)
|
|
|
|
{
|
|
|
|
FILE* fp;
|
|
|
|
errno_t err = _wfopen_s(&fp, file_path.c_str(), L"wt");
|
|
|
|
if (err)
|
|
|
|
return;
|
|
|
|
fwrite(data.c_str(), 1, data.size(), fp);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserImpl::UIT_ViewDocumentString(WebKit::WebFrame *frame)
|
|
|
|
{
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
DWORD dwRetVal;
|
|
|
|
DWORD dwBufSize = 512;
|
|
|
|
TCHAR lpPathBuffer[512];
|
|
|
|
UINT uRetVal;
|
|
|
|
TCHAR szTempName[512];
|
|
|
|
|
|
|
|
dwRetVal = GetTempPath(dwBufSize, // length of the buffer
|
|
|
|
lpPathBuffer); // buffer for path
|
|
|
|
if (dwRetVal > dwBufSize || (dwRetVal == 0))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Create a temporary file.
|
|
|
|
uRetVal = GetTempFileName(lpPathBuffer, // directory for tmp files
|
|
|
|
TEXT("src"), // temp file name prefix
|
|
|
|
0, // create unique name
|
|
|
|
szTempName); // buffer for name
|
|
|
|
if (uRetVal == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
size_t len = wcslen(szTempName);
|
|
|
|
wcscpy(szTempName + len - 3, L"txt");
|
|
|
|
std::string markup = frame->contentAsMarkup().utf8();
|
|
|
|
WriteTextToFile(markup, szTempName);
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
int errorCode = (int)ShellExecute(UIT_GetMainWndHandle(), L"open", szTempName,
|
2010-10-03 23:04:50 +02:00
|
|
|
NULL, NULL, SW_SHOWNORMAL);
|
|
|
|
if(errorCode <= 32)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
|
|
|
|
const gfx::Size& canvas_size,
|
|
|
|
WebKit::WebFrame* frame) {
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
printing::PrintParams params;
|
|
|
|
const printing::PrintSettings &settings = print_context_.settings();
|
|
|
|
settings.RenderParams(¶ms);
|
|
|
|
|
|
|
|
const int src_size_x = canvas_size.width();
|
|
|
|
const int src_size_y = canvas_size.height();
|
|
|
|
|
2011-02-01 16:37:47 +01:00
|
|
|
const int dest_size_x =
|
|
|
|
settings.page_setup_pixels().printable_area().width();
|
|
|
|
const int dest_size_y =
|
|
|
|
settings.page_setup_pixels().printable_area().height();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
print_context_.NewPage();
|
|
|
|
|
|
|
|
HDC hDC = print_context_.context();
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
// Save the state to make sure the context this function call does not modify
|
|
|
|
// the device context.
|
|
|
|
int saved_state = SaveDC(hDC);
|
|
|
|
DCHECK_NE(saved_state, 0);
|
|
|
|
|
2011-04-05 18:17:33 +02:00
|
|
|
skia::PlatformDevice* device =
|
2011-05-16 18:56:12 +02:00
|
|
|
skia::VectorPlatformDeviceEmfFactory::CreateDevice(dest_size_x,
|
|
|
|
dest_size_y,
|
|
|
|
true, hDC);
|
2011-04-05 18:17:33 +02:00
|
|
|
DCHECK(device);
|
|
|
|
skia::VectorCanvas canvas(device);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-02-01 16:37:47 +01:00
|
|
|
// The hDC 0 coord is the left most printeable area and not physical area of
|
|
|
|
// the paper so subtract that out of our canvas translate.
|
|
|
|
const int left_margin_offset =
|
|
|
|
settings.page_setup_pixels().effective_margins().left -
|
|
|
|
settings.page_setup_pixels().printable_area().x();
|
|
|
|
const int top_margin_offset =
|
|
|
|
settings.page_setup_pixels().effective_margins().top -
|
|
|
|
settings.page_setup_pixels().printable_area().y();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// Adjust for the margin offset.
|
|
|
|
canvas.translate(static_cast<float>(left_margin_offset),
|
|
|
|
static_cast<float>(top_margin_offset));
|
|
|
|
|
|
|
|
// Apply the print scaling factor.
|
2011-02-01 16:37:47 +01:00
|
|
|
const float print_scale_x =
|
|
|
|
static_cast<float>(settings.page_setup_pixels().content_area().width())
|
2010-10-03 23:04:50 +02:00
|
|
|
/ src_size_x;
|
2011-02-01 16:37:47 +01:00
|
|
|
const float print_scale_y =
|
|
|
|
static_cast<float>(settings.page_setup_pixels().content_area().height())
|
2010-10-03 23:04:50 +02:00
|
|
|
/ src_size_y;
|
|
|
|
canvas.scale(print_scale_x, print_scale_y);
|
|
|
|
|
|
|
|
// Apply the WebKit scaling factor.
|
|
|
|
const float webkit_scale = frame->getPrintPageShrink(page_number);
|
|
|
|
if (webkit_scale <= 0) {
|
|
|
|
NOTREACHED() << "Printing page " << page_number << " failed.";
|
|
|
|
}
|
|
|
|
canvas.scale(webkit_scale, webkit_scale);
|
|
|
|
|
|
|
|
frame->printPage(page_number, &canvas);
|
|
|
|
|
|
|
|
res = RestoreDC(hDC, saved_state);
|
|
|
|
DCHECK_NE(res, 0);
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefPrintHandler> handler;
|
|
|
|
if (client_.get())
|
|
|
|
handler = client_->GetPrintHandler();
|
|
|
|
|
|
|
|
if(handler.get()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
saved_state = SaveDC(hDC);
|
|
|
|
DCHECK_NE(saved_state, 0);
|
|
|
|
|
|
|
|
// Gather print header state information
|
|
|
|
RECT rect;
|
|
|
|
rect.left = left_margin_offset;
|
|
|
|
rect.top = settings.page_setup_pixels().effective_margins().header -
|
|
|
|
settings.page_setup_pixels().printable_area().y();
|
2011-02-01 16:37:47 +01:00
|
|
|
rect.right = left_margin_offset +
|
|
|
|
settings.page_setup_pixels().content_area().width();
|
2010-10-03 23:04:50 +02:00
|
|
|
rect.bottom = settings.page_setup_pixels().printable_area().height() -
|
|
|
|
(settings.page_setup_pixels().effective_margins().footer -
|
|
|
|
(settings.page_setup_pixels().physical_size().height() -
|
|
|
|
settings.page_setup_pixels().printable_area().bottom()));
|
|
|
|
|
|
|
|
const double scale = static_cast<double>(settings.dpi()) /
|
|
|
|
static_cast<double>(settings.desired_dpi);
|
|
|
|
|
|
|
|
CefPrintInfo printInfo;
|
|
|
|
|
|
|
|
printInfo.m_hDC = hDC;
|
|
|
|
printInfo.m_Rect = rect;
|
|
|
|
printInfo.m_Scale = scale;
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CefString url(frame->url().spec());
|
|
|
|
CefString title = title_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CefString topLeft, topCenter, topRight;
|
|
|
|
CefString bottomLeft, bottomCenter, bottomRight;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// Allow the handler to format print header and/or footer.
|
|
|
|
bool handled = handler->GetPrintHeaderFooter(this, UIT_GetCefFrame(frame),
|
|
|
|
printInfo, url, title, page_number+1, total_pages, topLeft, topCenter,
|
|
|
|
topRight, bottomLeft, bottomCenter, bottomRight);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
if (!handled) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// Draw handler-defined headers and/or footers.
|
|
|
|
LOGFONT lf;
|
|
|
|
memset(&lf, 0, sizeof(lf));
|
|
|
|
lf.lfHeight = (int)ceil(10. * scale);
|
|
|
|
lf.lfPitchAndFamily = FF_SWISS;
|
|
|
|
HFONT hFont = CreateFontIndirect(&lf);
|
|
|
|
|
|
|
|
HFONT hOldFont = (HFONT)SelectObject(hDC, hFont);
|
|
|
|
COLORREF hOldColor = SetTextColor(hDC, RGB(0,0,0));
|
|
|
|
int hOldBkMode = SetBkMode(hDC, TRANSPARENT);
|
|
|
|
|
|
|
|
// TODO(cef): Keep the header strings inside a reasonable bounding box
|
|
|
|
// so that they don't overlap each other.
|
2010-11-22 18:49:46 +01:00
|
|
|
if(topLeft.length() > 0) {
|
|
|
|
std::wstring topLeftStr(topLeft);
|
|
|
|
DrawText(hDC, topLeftStr.c_str(), topLeftStr.length(), &rect,
|
2010-10-03 23:04:50 +02:00
|
|
|
DT_LEFT | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
|
|
|
|
| DT_EXPANDTABS | DT_NOPREFIX);
|
|
|
|
}
|
2010-11-22 18:49:46 +01:00
|
|
|
if(topCenter.length() > 0) {
|
|
|
|
std::wstring topCenterStr(topCenter);
|
|
|
|
DrawText(hDC, topCenterStr.c_str(), topCenterStr.length(), &rect,
|
2010-10-03 23:04:50 +02:00
|
|
|
DT_CENTER | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
|
|
|
|
| DT_EXPANDTABS | DT_NOPREFIX);
|
|
|
|
}
|
2010-11-22 18:49:46 +01:00
|
|
|
if(topRight.length() > 0) {
|
|
|
|
std::wstring topRightStr(topRight);
|
|
|
|
DrawText(hDC, topRightStr.c_str(), topRightStr.length(), &rect,
|
2010-10-03 23:04:50 +02:00
|
|
|
DT_RIGHT | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
|
|
|
|
| DT_EXPANDTABS | DT_NOPREFIX);
|
|
|
|
}
|
2010-11-22 18:49:46 +01:00
|
|
|
if(bottomLeft.length() > 0) {
|
|
|
|
std::wstring bottomLeftStr(bottomLeft);
|
|
|
|
DrawText(hDC, bottomLeftStr.c_str(), bottomLeftStr.length(), &rect,
|
2010-10-03 23:04:50 +02:00
|
|
|
DT_LEFT | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
|
|
|
|
| DT_EXPANDTABS | DT_NOPREFIX);
|
|
|
|
}
|
2010-11-22 18:49:46 +01:00
|
|
|
if(bottomCenter.length() > 0) {
|
|
|
|
std::wstring bottomCenterStr(bottomCenter);
|
|
|
|
DrawText(hDC, bottomCenterStr.c_str(), bottomCenterStr.length(), &rect,
|
2010-10-03 23:04:50 +02:00
|
|
|
DT_CENTER | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
|
|
|
|
| DT_EXPANDTABS | DT_NOPREFIX);
|
|
|
|
}
|
2010-11-22 18:49:46 +01:00
|
|
|
if(bottomRight.length() > 0) {
|
|
|
|
std::wstring bottomRightStr(bottomRight);
|
|
|
|
DrawText(hDC, bottomRightStr.c_str(), bottomRightStr.length(), &rect,
|
2010-10-03 23:04:50 +02:00
|
|
|
DT_RIGHT | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
|
|
|
|
| DT_EXPANDTABS | DT_NOPREFIX);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetTextColor(hDC, hOldColor);
|
|
|
|
SelectObject(hDC, hOldFont);
|
|
|
|
DeleteObject(hFont);
|
|
|
|
SetBkMode(hDC, hOldBkMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = RestoreDC(hDC, saved_state);
|
|
|
|
DCHECK_NE(res, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_context_.PageDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserImpl::UIT_PrintPages(WebKit::WebFrame* frame) {
|
|
|
|
REQUIRE_UIT();
|
|
|
|
|
|
|
|
print_context_.Init();
|
|
|
|
{
|
|
|
|
// Make a copy of settings.
|
|
|
|
printing::PrintSettings settings = print_context_.settings();
|
|
|
|
cef_print_options_t print_options;
|
2010-11-23 15:46:01 +01:00
|
|
|
memset(&print_options, 0, sizeof(print_options));
|
2010-10-03 23:04:50 +02:00
|
|
|
settings.UpdatePrintOptions(print_options);
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefPrintHandler> handler;
|
|
|
|
if (client_.get())
|
|
|
|
handler = client_->GetPrintHandler();
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Ask the handler if they want to update the print options.
|
2011-05-20 16:42:25 +02:00
|
|
|
if (handler.get() && handler->GetPrintOptions(this, print_options)) {
|
2010-10-03 23:04:50 +02:00
|
|
|
settings.UpdateFromPrintOptions(print_options);
|
|
|
|
print_context_.InitWithSettings(settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(print_context_.AskUserForSettings(
|
2011-01-29 02:42:59 +01:00
|
|
|
UIT_GetMainWndHandle(), UIT_GetPagesCount(frame), false)
|
2010-10-03 23:04:50 +02:00
|
|
|
!= printing::PrintingContext::OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
printing::PrintParams params;
|
|
|
|
const printing::PrintSettings &settings = print_context_.settings();
|
|
|
|
|
|
|
|
settings.RenderParams(¶ms);
|
|
|
|
|
|
|
|
int page_count = 0;
|
|
|
|
gfx::Size canvas_size;
|
|
|
|
|
|
|
|
canvas_size.set_width(
|
|
|
|
printing::ConvertUnit(
|
|
|
|
settings.page_setup_pixels().content_area().width(),
|
|
|
|
static_cast<int>(params.dpi),
|
|
|
|
params.desired_dpi));
|
|
|
|
canvas_size.set_height(
|
|
|
|
printing::ConvertUnit(
|
|
|
|
settings.page_setup_pixels().content_area().height(),
|
|
|
|
static_cast<int>(params.dpi),
|
|
|
|
params.desired_dpi));
|
|
|
|
page_count = frame->printBegin(WebSize(canvas_size));
|
|
|
|
|
|
|
|
if (page_count) {
|
|
|
|
bool old_state = MessageLoop::current()->NestableTasksAllowed();
|
|
|
|
MessageLoop::current()->SetNestableTasksAllowed(false);
|
|
|
|
|
|
|
|
if (print_context_.NewDocument(title_) == printing::PrintingContext::OK) {
|
|
|
|
if(settings.ranges.size() > 0) {
|
|
|
|
for (unsigned x = 0; x < settings.ranges.size(); ++x) {
|
|
|
|
const printing::PageRange& range = settings.ranges[x];
|
|
|
|
for(int i = range.from; i <= range.to; ++i)
|
|
|
|
UIT_PrintPage(i, page_count, canvas_size, frame);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(int i = 0; i < page_count; ++i)
|
|
|
|
UIT_PrintPage(i, page_count, canvas_size, frame);
|
|
|
|
}
|
|
|
|
print_context_.DocumentDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageLoop::current()->SetNestableTasksAllowed(old_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->printEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefBrowserImpl::UIT_GetPagesCount(WebKit::WebFrame* frame)
|
|
|
|
{
|
2011-02-01 16:37:47 +01:00
|
|
|
REQUIRE_UIT();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
printing::PrintParams params;
|
|
|
|
const printing::PrintSettings &settings = print_context_.settings();
|
|
|
|
|
|
|
|
settings.RenderParams(¶ms);
|
|
|
|
|
|
|
|
// The dbi will be 0 if no default printer is configured.
|
|
|
|
if(params.dpi == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int page_count = 0;
|
|
|
|
gfx::Size canvas_size;
|
|
|
|
|
|
|
|
canvas_size.set_width(
|
|
|
|
printing::ConvertUnit(
|
|
|
|
settings.page_setup_pixels().content_area().width(),
|
|
|
|
static_cast<int>(params.dpi),
|
|
|
|
params.desired_dpi));
|
|
|
|
canvas_size.set_height(
|
|
|
|
printing::ConvertUnit(
|
|
|
|
settings.page_setup_pixels().content_area().height(),
|
|
|
|
static_cast<int>(params.dpi),
|
|
|
|
params.desired_dpi));
|
|
|
|
page_count = frame->printBegin(WebSize(canvas_size));
|
|
|
|
frame->printEnd();
|
|
|
|
|
|
|
|
return page_count;
|
|
|
|
}
|
2011-02-01 16:37:47 +01:00
|
|
|
|
|
|
|
// static
|
|
|
|
void CefBrowserImpl::UIT_CloseView(gfx::NativeView view)
|
|
|
|
{
|
|
|
|
PostMessage(view, WM_CLOSE, 0, 0);
|
|
|
|
}
|
2011-03-08 04:54:50 +01:00
|
|
|
|
|
|
|
// static
|
|
|
|
bool CefBrowserImpl::UIT_IsViewVisible(gfx::NativeView view)
|
|
|
|
{
|
|
|
|
return IsWindowVisible(view) ? true : false;
|
|
|
|
}
|