mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Update all files to use Windows CRLF (\r\n) line endings (issue #45).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@33 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
// 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.
|
||||
|
||||
// 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 "precompiled_libcef.h"
|
||||
#include "context.h"
|
||||
#include "browser_impl.h"
|
||||
@ -13,9 +13,9 @@
|
||||
|
||||
#include "base/string_util.h"
|
||||
#include "base/win_util.h"
|
||||
#include "skia/ext/vector_canvas.h"
|
||||
#include "webkit/api/public/WebRect.h"
|
||||
#include "webkit/api/public/WebSize.h"
|
||||
#include "skia/ext/vector_canvas.h"
|
||||
#include "webkit/api/public/WebRect.h"
|
||||
#include "webkit/api/public/WebSize.h"
|
||||
#include "webkit/glue/webframe.h"
|
||||
#include "webkit/glue/webkit_glue.h"
|
||||
|
||||
@ -39,59 +39,59 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
|
||||
CefBrowserImpl* browser =
|
||||
static_cast<CefBrowserImpl*>(win_util::GetWindowUserData(hwnd));
|
||||
|
||||
switch (message) {
|
||||
case WM_COMMAND:
|
||||
{
|
||||
int wmId = LOWORD(wParam);
|
||||
int wmEvent = HIWORD(wParam);
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
{
|
||||
CefRefPtr<CefHandler> handler = browser->GetHandler();
|
||||
if(handler.get()) {
|
||||
// Notify the handler that the window is about to be closed
|
||||
handler->HandleBeforeWindowClose(browser);
|
||||
}
|
||||
RevokeDragDrop(browser->GetWebViewWndHandle());
|
||||
|
||||
// Call GC twice to clean up garbage.
|
||||
browser->GetWebView()->GetMainFrame()->CallJSGC();
|
||||
browser->GetWebView()->GetMainFrame()->CallJSGC();
|
||||
|
||||
// Clean up anything associated with the WebViewHost widget.
|
||||
browser->GetWebViewHost()->webwidget()->close();
|
||||
|
||||
// Remove the browser from the list maintained by the context
|
||||
_Context->RemoveBrowser(browser);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_SIZE:
|
||||
if (browser && browser->GetWebView()) {
|
||||
// resize the web view window to the full size of the browser window
|
||||
RECT rc;
|
||||
GetClientRect(browser->GetMainWndHandle(), &rc);
|
||||
MoveWindow(browser->GetWebViewWndHandle(), 0, 0, rc.right, rc.bottom,
|
||||
TRUE);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_SETFOCUS:
|
||||
if (browser && browser->GetWebView())
|
||||
browser->GetWebView()->setFocus(true);
|
||||
return 0;
|
||||
|
||||
case WM_KILLFOCUS:
|
||||
if (browser && browser->GetWebView())
|
||||
browser->GetWebView()->setFocus(false);
|
||||
return 0;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
return 0;
|
||||
switch (message) {
|
||||
case WM_COMMAND:
|
||||
{
|
||||
int wmId = LOWORD(wParam);
|
||||
int wmEvent = HIWORD(wParam);
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
{
|
||||
CefRefPtr<CefHandler> handler = browser->GetHandler();
|
||||
if(handler.get()) {
|
||||
// Notify the handler that the window is about to be closed
|
||||
handler->HandleBeforeWindowClose(browser);
|
||||
}
|
||||
RevokeDragDrop(browser->GetWebViewWndHandle());
|
||||
|
||||
// Call GC twice to clean up garbage.
|
||||
browser->GetWebView()->GetMainFrame()->CallJSGC();
|
||||
browser->GetWebView()->GetMainFrame()->CallJSGC();
|
||||
|
||||
// Clean up anything associated with the WebViewHost widget.
|
||||
browser->GetWebViewHost()->webwidget()->close();
|
||||
|
||||
// Remove the browser from the list maintained by the context
|
||||
_Context->RemoveBrowser(browser);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_SIZE:
|
||||
if (browser && browser->GetWebView()) {
|
||||
// resize the web view window to the full size of the browser window
|
||||
RECT rc;
|
||||
GetClientRect(browser->GetMainWndHandle(), &rc);
|
||||
MoveWindow(browser->GetWebViewWndHandle(), 0, 0, rc.right, rc.bottom,
|
||||
TRUE);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_SETFOCUS:
|
||||
if (browser && browser->GetWebView())
|
||||
browser->GetWebView()->setFocus(true);
|
||||
return 0;
|
||||
|
||||
case WM_KILLFOCUS:
|
||||
if (browser && browser->GetWebView())
|
||||
browser->GetWebView()->setFocus(false);
|
||||
return 0;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DefWindowProc(hwnd, message, wParam, lParam);
|
||||
@ -111,9 +111,9 @@ std::wstring CefBrowserImpl::GetSource(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
// We need to send the request to the UI thread and wait for the result
|
||||
|
||||
// Event that will be used to signal that data is available. Start
|
||||
// in non-signaled mode so that the event will block.
|
||||
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
// Event that will be used to signal that data is available. Start
|
||||
// in non-signaled mode so that the event will block.
|
||||
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
DCHECK(hEvent != NULL);
|
||||
|
||||
CefRefPtr<CefStreamWriter> stream(new CefBytesWriter(BUFFER_SIZE));
|
||||
@ -148,9 +148,9 @@ std::wstring CefBrowserImpl::GetText(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
// We need to send the request to the UI thread and wait for the result
|
||||
|
||||
// Event that will be used to signal that data is available. Start
|
||||
// in non-signaled mode so that the event will block.
|
||||
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
// Event that will be used to signal that data is available. Start
|
||||
// in non-signaled mode so that the event will block.
|
||||
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
DCHECK(hEvent != NULL);
|
||||
|
||||
CefRefPtr<CefStreamWriter> stream(new CefBytesWriter(BUFFER_SIZE));
|
||||
@ -185,9 +185,9 @@ bool CefBrowserImpl::CanGoBack()
|
||||
{
|
||||
// We need to send the request to the UI thread and wait for the result
|
||||
|
||||
// Event that will be used to signal that data is available. Start
|
||||
// in non-signaled mode so that the event will block.
|
||||
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
// Event that will be used to signal that data is available. Start
|
||||
// in non-signaled mode so that the event will block.
|
||||
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
DCHECK(hEvent != NULL);
|
||||
|
||||
bool retVal = true;
|
||||
@ -215,9 +215,9 @@ bool CefBrowserImpl::CanGoForward()
|
||||
{
|
||||
// We need to send the request to the UI thread and wait for the result
|
||||
|
||||
// Event that will be used to signal that data is available. Start
|
||||
// in non-signaled mode so that the event will block.
|
||||
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
// Event that will be used to signal that data is available. Start
|
||||
// in non-signaled mode so that the event will block.
|
||||
HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
DCHECK(hEvent != NULL);
|
||||
|
||||
bool retVal = true;
|
||||
@ -244,31 +244,31 @@ void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
|
||||
REQUIRE_UIT();
|
||||
|
||||
// Create the new browser window
|
||||
window_info_.m_hWnd = CreateWindowEx(window_info_.m_dwExStyle, GetWndClass(),
|
||||
window_info_.m_windowName, 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,
|
||||
_Context->GetInstanceHandle(), NULL);
|
||||
DCHECK(window_info_.m_hWnd != NULL);
|
||||
|
||||
// Set window user data to this object for future reference from the window
|
||||
// procedure
|
||||
win_util::SetWindowUserData(window_info_.m_hWnd, this);
|
||||
|
||||
// Add the new browser to the list maintained by the context
|
||||
_Context->AddBrowser(this);
|
||||
|
||||
// Create the webview host object
|
||||
webviewhost_.reset(
|
||||
WebViewHost::Create(window_info_.m_hWnd, delegate_.get(),
|
||||
*_Context->GetWebPreferences()));
|
||||
GetWebView()->SetUseEditorDelegate(true);
|
||||
delegate_->RegisterDragDrop();
|
||||
|
||||
// Size the web view window to the browser window
|
||||
RECT cr;
|
||||
GetClientRect(window_info_.m_hWnd, &cr);
|
||||
SetWindowPos(GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
|
||||
window_info_.m_hWnd = CreateWindowEx(window_info_.m_dwExStyle, GetWndClass(),
|
||||
window_info_.m_windowName, 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,
|
||||
_Context->GetInstanceHandle(), NULL);
|
||||
DCHECK(window_info_.m_hWnd != NULL);
|
||||
|
||||
// Set window user data to this object for future reference from the window
|
||||
// procedure
|
||||
win_util::SetWindowUserData(window_info_.m_hWnd, this);
|
||||
|
||||
// Add the new browser to the list maintained by the context
|
||||
_Context->AddBrowser(this);
|
||||
|
||||
// Create the webview host object
|
||||
webviewhost_.reset(
|
||||
WebViewHost::Create(window_info_.m_hWnd, delegate_.get(),
|
||||
*_Context->GetWebPreferences()));
|
||||
GetWebView()->SetUseEditorDelegate(true);
|
||||
delegate_->RegisterDragDrop();
|
||||
|
||||
// Size the web view window to the browser window
|
||||
RECT cr;
|
||||
GetClientRect(window_info_.m_hWnd, &cr);
|
||||
SetWindowPos(GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
|
||||
cr.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
|
||||
|
||||
if(handler_.get()) {
|
||||
@ -286,46 +286,46 @@ void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
|
||||
void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
if (enable)
|
||||
::SetFocus(host->view_handle());
|
||||
else if (::GetFocus() == host->view_handle())
|
||||
|
||||
if (enable)
|
||||
::SetFocus(host->view_handle());
|
||||
else if (::GetFocus() == host->view_handle())
|
||||
::SetFocus(NULL);
|
||||
}
|
||||
|
||||
WebKit::WebWidget* CefBrowserImpl::UIT_CreatePopupWidget(WebView* webview)
|
||||
{
|
||||
|
||||
WebKit::WebWidget* CefBrowserImpl::UIT_CreatePopupWidget(WebView* webview)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
DCHECK(!popuphost_);
|
||||
popuphost_ = WebWidgetHost::Create(NULL, popup_delegate_.get());
|
||||
ShowWindow(GetPopupWndHandle(), SW_SHOW);
|
||||
|
||||
return popuphost_->webwidget();
|
||||
|
||||
DCHECK(!popuphost_);
|
||||
popuphost_ = WebWidgetHost::Create(NULL, popup_delegate_.get());
|
||||
ShowWindow(GetPopupWndHandle(), SW_SHOW);
|
||||
|
||||
return popuphost_->webwidget();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_ClosePopupWidget()
|
||||
{
|
||||
|
||||
void CefBrowserImpl::UIT_ClosePopupWidget()
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
PostMessage(GetPopupWndHandle(), WM_CLOSE, 0, 0);
|
||||
popuphost_ = 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(WebFrame *frame)
|
||||
{
|
||||
|
||||
PostMessage(GetPopupWndHandle(), WM_CLOSE, 0, 0);
|
||||
popuphost_ = 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(WebFrame *frame)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
DWORD dwRetVal;
|
||||
@ -333,7 +333,7 @@ bool CefBrowserImpl::UIT_ViewDocumentString(WebFrame *frame)
|
||||
TCHAR lpPathBuffer[512];
|
||||
UINT uRetVal;
|
||||
TCHAR szTempName[512];
|
||||
|
||||
|
||||
dwRetVal = GetTempPath(dwBufSize, // length of the buffer
|
||||
lpPathBuffer); // buffer for path
|
||||
if (dwRetVal > dwBufSize || (dwRetVal == 0))
|
||||
@ -349,22 +349,22 @@ bool CefBrowserImpl::UIT_ViewDocumentString(WebFrame *frame)
|
||||
|
||||
size_t len = wcslen(szTempName);
|
||||
wcscpy(szTempName + len - 3, L"txt");
|
||||
WriteTextToFile(frame->GetFullPageHtml(), szTempName);
|
||||
|
||||
WriteTextToFile(frame->GetFullPageHtml(), szTempName);
|
||||
|
||||
int errorCode = (int)ShellExecute(GetMainWndHandle(), L"open", szTempName,
|
||||
NULL, NULL, SW_SHOWNORMAL);
|
||||
if(errorCode <= 32)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
if(errorCode <= 32)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_GetDocumentStringNotify(CefFrame* frame,
|
||||
CefStreamWriter* writer,
|
||||
HANDLE hEvent)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
|
||||
WebFrame* web_frame = GetWebFrame(frame);
|
||||
if(web_frame) {
|
||||
// Retrieve the document string
|
||||
@ -378,14 +378,14 @@ void CefBrowserImpl::UIT_GetDocumentStringNotify(CefFrame* frame,
|
||||
|
||||
writer->Release();
|
||||
frame->Release();
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_GetDocumentTextNotify(CefFrame* frame,
|
||||
CefStreamWriter* writer,
|
||||
HANDLE hEvent)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
|
||||
WebFrame* web_frame = GetWebFrame(frame);
|
||||
if(web_frame) {
|
||||
// Retrieve the document string
|
||||
@ -400,12 +400,12 @@ void CefBrowserImpl::UIT_GetDocumentTextNotify(CefFrame* frame,
|
||||
|
||||
writer->Release();
|
||||
frame->Release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_CanGoBackNotify(bool *retVal, HANDLE hEvent)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
|
||||
*retVal = UIT_CanGoBack();
|
||||
|
||||
// Notify the calling thread that the data is now available
|
||||
@ -415,190 +415,190 @@ void CefBrowserImpl::UIT_CanGoBackNotify(bool *retVal, HANDLE hEvent)
|
||||
void CefBrowserImpl::UIT_CanGoForwardNotify(bool *retVal, HANDLE hEvent)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
|
||||
*retVal = UIT_CanGoForward();
|
||||
|
||||
// Notify the calling thread that the data is now available
|
||||
SetEvent(hEvent);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
|
||||
const gfx::Size& canvas_size,
|
||||
WebFrame* frame) {
|
||||
#if !CEF_PATCHES_APPLIED
|
||||
NOTREACHED() << "CEF patches must be applied to support printing.";
|
||||
return;
|
||||
#endif // !CEF_PATCHES_APPLIED
|
||||
|
||||
REQUIRE_UIT();
|
||||
|
||||
printing::PrintParams params;
|
||||
const printing::PrintSettings &settings = print_context_.settings();
|
||||
settings.RenderParams(¶ms);
|
||||
|
||||
int src_size_x = canvas_size.width();
|
||||
int src_size_y = canvas_size.height();
|
||||
float src_margin = .1f * src_size_x;
|
||||
|
||||
int dest_size_x = settings.page_setup_pixels().physical_size().width();
|
||||
int dest_size_y = settings.page_setup_pixels().physical_size().height();
|
||||
float dest_margin = .1f * dest_size_x;
|
||||
|
||||
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);
|
||||
|
||||
skia::VectorCanvas canvas(hDC, dest_size_x, dest_size_y);
|
||||
|
||||
// Adjust for the margin offset.
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
|
||||
const gfx::Size& canvas_size,
|
||||
WebFrame* frame) {
|
||||
#if !CEF_PATCHES_APPLIED
|
||||
NOTREACHED() << "CEF patches must be applied to support printing.";
|
||||
return;
|
||||
#endif // !CEF_PATCHES_APPLIED
|
||||
|
||||
REQUIRE_UIT();
|
||||
|
||||
printing::PrintParams params;
|
||||
const printing::PrintSettings &settings = print_context_.settings();
|
||||
settings.RenderParams(¶ms);
|
||||
|
||||
int src_size_x = canvas_size.width();
|
||||
int src_size_y = canvas_size.height();
|
||||
float src_margin = .1f * src_size_x;
|
||||
|
||||
int dest_size_x = settings.page_setup_pixels().physical_size().width();
|
||||
int dest_size_y = settings.page_setup_pixels().physical_size().height();
|
||||
float dest_margin = .1f * dest_size_x;
|
||||
|
||||
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);
|
||||
|
||||
skia::VectorCanvas canvas(hDC, dest_size_x, dest_size_y);
|
||||
|
||||
// Adjust for the margin offset.
|
||||
canvas.translate(dest_margin, dest_margin);
|
||||
|
||||
// Apply the print scaling factor.
|
||||
float print_scale = (dest_size_x - dest_margin * 2) / src_size_x;
|
||||
canvas.scale(print_scale, print_scale);
|
||||
|
||||
// Set the clipping region to be sure to not overflow.
|
||||
SkRect clip_rect;
|
||||
clip_rect.set(0, 0, static_cast<float>(src_size_x),
|
||||
static_cast<float>(src_size_y));
|
||||
canvas.clipRect(clip_rect);
|
||||
|
||||
// Apply the WebKit scaling factor.
|
||||
|
||||
// Apply the print scaling factor.
|
||||
float print_scale = (dest_size_x - dest_margin * 2) / src_size_x;
|
||||
canvas.scale(print_scale, print_scale);
|
||||
|
||||
// Set the clipping region to be sure to not overflow.
|
||||
SkRect clip_rect;
|
||||
clip_rect.set(0, 0, static_cast<float>(src_size_x),
|
||||
static_cast<float>(src_size_y));
|
||||
canvas.clipRect(clip_rect);
|
||||
|
||||
// Apply the WebKit scaling factor.
|
||||
float webkit_scale = 0;
|
||||
#if CEF_PATCHES_APPLIED
|
||||
webkit_scale = frame->GetPrintPageShrink(page_number);
|
||||
#endif // CEF_PATCHES_APPLIED
|
||||
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);
|
||||
|
||||
if(handler_.get()) {
|
||||
saved_state = SaveDC(hDC);
|
||||
DCHECK_NE(saved_state, 0);
|
||||
|
||||
// Gather print header state information
|
||||
RECT rect;
|
||||
rect.left = (int)floor(dest_margin / 2);
|
||||
rect.top = rect.left;
|
||||
rect.right = (int)ceil(dest_size_x - dest_margin / 2);
|
||||
rect.bottom = (int)ceil(dest_size_y - dest_margin / 2);
|
||||
|
||||
double scale = (double)settings.dpi() / (double)settings.desired_dpi;
|
||||
|
||||
CefPrintInfo printInfo;
|
||||
|
||||
printInfo.m_hDC = hDC;
|
||||
printInfo.m_Rect = rect;
|
||||
printInfo.m_Scale = scale;
|
||||
|
||||
std::wstring url = UTF8ToWide(frame->GetURL().spec());
|
||||
std::wstring title = title_;
|
||||
|
||||
std::wstring topLeft, topCenter, topRight;
|
||||
std::wstring bottomLeft, bottomCenter, bottomRight;
|
||||
|
||||
// allow the handler to format print header and/or footer
|
||||
CefHandler::RetVal rv = handler_->HandlePrintHeaderFooter(this,
|
||||
GetCefFrame(frame), printInfo, url, title, page_number+1, total_pages,
|
||||
topLeft, topCenter, topRight, bottomLeft, bottomCenter, bottomRight);
|
||||
|
||||
if(rv != RV_HANDLED) {
|
||||
// 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.
|
||||
if(topLeft.size() > 0) {
|
||||
DrawText(hDC, topLeft.c_str(), topLeft.size(), &rect,
|
||||
DT_LEFT | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
|
||||
| DT_EXPANDTABS | DT_NOPREFIX);
|
||||
}
|
||||
if(topCenter.size() > 0) {
|
||||
DrawText(hDC, topCenter.c_str(), topCenter.size(), &rect,
|
||||
DT_CENTER | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
|
||||
| DT_EXPANDTABS | DT_NOPREFIX);
|
||||
}
|
||||
if(topRight.size() > 0) {
|
||||
DrawText(hDC, topRight.c_str(), topRight.size(), &rect,
|
||||
DT_RIGHT | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
|
||||
| DT_EXPANDTABS | DT_NOPREFIX);
|
||||
}
|
||||
if(bottomLeft.size() > 0) {
|
||||
DrawText(hDC, bottomLeft.c_str(), bottomLeft.size(), &rect,
|
||||
DT_LEFT | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
|
||||
| DT_EXPANDTABS | DT_NOPREFIX);
|
||||
}
|
||||
if(bottomCenter.size() > 0) {
|
||||
DrawText(hDC, bottomCenter.c_str(), bottomCenter.size(), &rect,
|
||||
DT_CENTER | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
|
||||
| DT_EXPANDTABS | DT_NOPREFIX);
|
||||
}
|
||||
if(bottomRight.size() > 0) {
|
||||
DrawText(hDC, bottomRight.c_str(), bottomRight.size(), &rect,
|
||||
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(WebFrame* frame) {
|
||||
#if !CEF_PATCHES_APPLIED
|
||||
NOTREACHED() << "CEF patches must be applied to support printing.";
|
||||
return;
|
||||
#endif // !CEF_PATCHES_APPLIED
|
||||
|
||||
}
|
||||
canvas.scale(webkit_scale, webkit_scale);
|
||||
|
||||
frame->PrintPage(page_number, &canvas);
|
||||
|
||||
res = RestoreDC(hDC, saved_state);
|
||||
DCHECK_NE(res, 0);
|
||||
|
||||
if(handler_.get()) {
|
||||
saved_state = SaveDC(hDC);
|
||||
DCHECK_NE(saved_state, 0);
|
||||
|
||||
// Gather print header state information
|
||||
RECT rect;
|
||||
rect.left = (int)floor(dest_margin / 2);
|
||||
rect.top = rect.left;
|
||||
rect.right = (int)ceil(dest_size_x - dest_margin / 2);
|
||||
rect.bottom = (int)ceil(dest_size_y - dest_margin / 2);
|
||||
|
||||
double scale = (double)settings.dpi() / (double)settings.desired_dpi;
|
||||
|
||||
CefPrintInfo printInfo;
|
||||
|
||||
printInfo.m_hDC = hDC;
|
||||
printInfo.m_Rect = rect;
|
||||
printInfo.m_Scale = scale;
|
||||
|
||||
std::wstring url = UTF8ToWide(frame->GetURL().spec());
|
||||
std::wstring title = title_;
|
||||
|
||||
std::wstring topLeft, topCenter, topRight;
|
||||
std::wstring bottomLeft, bottomCenter, bottomRight;
|
||||
|
||||
// allow the handler to format print header and/or footer
|
||||
CefHandler::RetVal rv = handler_->HandlePrintHeaderFooter(this,
|
||||
GetCefFrame(frame), printInfo, url, title, page_number+1, total_pages,
|
||||
topLeft, topCenter, topRight, bottomLeft, bottomCenter, bottomRight);
|
||||
|
||||
if(rv != RV_HANDLED) {
|
||||
// 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.
|
||||
if(topLeft.size() > 0) {
|
||||
DrawText(hDC, topLeft.c_str(), topLeft.size(), &rect,
|
||||
DT_LEFT | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
|
||||
| DT_EXPANDTABS | DT_NOPREFIX);
|
||||
}
|
||||
if(topCenter.size() > 0) {
|
||||
DrawText(hDC, topCenter.c_str(), topCenter.size(), &rect,
|
||||
DT_CENTER | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
|
||||
| DT_EXPANDTABS | DT_NOPREFIX);
|
||||
}
|
||||
if(topRight.size() > 0) {
|
||||
DrawText(hDC, topRight.c_str(), topRight.size(), &rect,
|
||||
DT_RIGHT | DT_TOP | DT_SINGLELINE | DT_END_ELLIPSIS
|
||||
| DT_EXPANDTABS | DT_NOPREFIX);
|
||||
}
|
||||
if(bottomLeft.size() > 0) {
|
||||
DrawText(hDC, bottomLeft.c_str(), bottomLeft.size(), &rect,
|
||||
DT_LEFT | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
|
||||
| DT_EXPANDTABS | DT_NOPREFIX);
|
||||
}
|
||||
if(bottomCenter.size() > 0) {
|
||||
DrawText(hDC, bottomCenter.c_str(), bottomCenter.size(), &rect,
|
||||
DT_CENTER | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
|
||||
| DT_EXPANDTABS | DT_NOPREFIX);
|
||||
}
|
||||
if(bottomRight.size() > 0) {
|
||||
DrawText(hDC, bottomRight.c_str(), bottomRight.size(), &rect,
|
||||
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(WebFrame* frame) {
|
||||
#if !CEF_PATCHES_APPLIED
|
||||
NOTREACHED() << "CEF patches must be applied to support printing.";
|
||||
return;
|
||||
#endif // !CEF_PATCHES_APPLIED
|
||||
|
||||
REQUIRE_UIT();
|
||||
|
||||
TCHAR printername[512];
|
||||
DWORD size = sizeof(printername)-1;
|
||||
if(GetDefaultPrinter(printername, &size)) {
|
||||
printing::PrintSettings settings;
|
||||
settings.set_device_name(printername);
|
||||
// Initialize it.
|
||||
print_context_.InitWithSettings(settings);
|
||||
}
|
||||
|
||||
if(print_context_.AskUserForSettings(
|
||||
GetMainWndHandle(), UIT_GetPagesCount(frame), false)
|
||||
!= printing::PrintingContext::OK)
|
||||
return;
|
||||
|
||||
printing::PrintParams params;
|
||||
const printing::PrintSettings &settings = print_context_.settings();
|
||||
|
||||
settings.RenderParams(¶ms);
|
||||
|
||||
|
||||
TCHAR printername[512];
|
||||
DWORD size = sizeof(printername)-1;
|
||||
if(GetDefaultPrinter(printername, &size)) {
|
||||
printing::PrintSettings settings;
|
||||
settings.set_device_name(printername);
|
||||
// Initialize it.
|
||||
print_context_.InitWithSettings(settings);
|
||||
}
|
||||
|
||||
if(print_context_.AskUserForSettings(
|
||||
GetMainWndHandle(), UIT_GetPagesCount(frame), false)
|
||||
!= 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;
|
||||
|
||||
@ -611,46 +611,46 @@ void CefBrowserImpl::UIT_PrintPages(WebFrame* frame) {
|
||||
printing::ConvertUnit(
|
||||
settings.page_setup_pixels().physical_size().height(),
|
||||
static_cast<int>(params.dpi),
|
||||
params.desired_dpi));
|
||||
params.desired_dpi));
|
||||
page_count = frame->PrintBegin(WebSize(canvas_size));
|
||||
|
||||
if (page_count) {
|
||||
bool old_state = MessageLoop::current()->NestableTasksAllowed();
|
||||
MessageLoop::current()->SetNestableTasksAllowed(false);
|
||||
|
||||
// TODO(cef): Use the page title as the document name
|
||||
print_context_.NewDocument(L"New Document");
|
||||
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(WebFrame* frame)
|
||||
{
|
||||
|
||||
if (page_count) {
|
||||
bool old_state = MessageLoop::current()->NestableTasksAllowed();
|
||||
MessageLoop::current()->SetNestableTasksAllowed(false);
|
||||
|
||||
// TODO(cef): Use the page title as the document name
|
||||
print_context_.NewDocument(L"New Document");
|
||||
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(WebFrame* frame)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
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;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
@ -663,9 +663,9 @@ int CefBrowserImpl::UIT_GetPagesCount(WebFrame* frame)
|
||||
printing::ConvertUnit(
|
||||
settings.page_setup_pixels().physical_size().height(),
|
||||
static_cast<int>(params.dpi),
|
||||
params.desired_dpi));
|
||||
page_count = frame->PrintBegin(WebSize(canvas_size));
|
||||
frame->PrintEnd();
|
||||
|
||||
return page_count;
|
||||
}
|
||||
params.desired_dpi));
|
||||
page_count = frame->PrintBegin(WebSize(canvas_size));
|
||||
frame->PrintEnd();
|
||||
|
||||
return page_count;
|
||||
}
|
||||
|
Reference in New Issue
Block a user