diff options
author | hamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-02 05:32:38 +0000 |
---|---|---|
committer | hamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-02 05:32:38 +0000 |
commit | 3c5fb6bed1e6c9ce80276653f4b053583c299d5b (patch) | |
tree | 3fff8754dc395584e8d9eab4ec56f0e6f78cc246 | |
parent | 638c48f806e23adf510ea2006f66f84f4d43c5de (diff) | |
download | chromium_src-3c5fb6bed1e6c9ce80276653f4b053583c299d5b.zip chromium_src-3c5fb6bed1e6c9ce80276653f4b053583c299d5b.tar.gz chromium_src-3c5fb6bed1e6c9ce80276653f4b053583c299d5b.tar.bz2 |
Implement limited paged media support for win.
BUG=47277
TEST=none
Review URL: http://codereview.chromium.org/2859040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51501 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/printing/print_view_manager.cc | 3 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 7 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper.cc | 9 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_win.cc | 48 | ||||
-rw-r--r-- | printing/page_overlays_unittest.cc | 2 | ||||
-rw-r--r-- | printing/printed_document.cc | 8 | ||||
-rw-r--r-- | printing/printed_document.h | 3 | ||||
-rw-r--r-- | printing/printed_document_win.cc | 17 | ||||
-rw-r--r-- | printing/printed_page.cc | 6 | ||||
-rw-r--r-- | printing/printed_page.h | 7 |
10 files changed, 92 insertions, 18 deletions
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index 2795a3d..1daecfb 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -135,7 +135,8 @@ void PrintViewManager::DidPrintPage( metafile.release(), params.actual_shrink, params.page_size, - params.content_area); + params.content_area, + params.has_visible_overlays); #endif ShouldQuitFromInnerMessageLoop(); } diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 618b5e7..0d9422b 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -461,6 +461,9 @@ struct ViewHostMsg_DidPrintPage_Params { // The printable area the page author specified. gfx::Rect content_area; + + // True if the page has visible overlays. + bool has_visible_overlays; }; // Parameters for creating an audio output stream. @@ -1584,6 +1587,7 @@ struct ParamTraits<ViewHostMsg_DidPrintPage_Params> { WriteParam(m, p.actual_shrink); WriteParam(m, p.page_size); WriteParam(m, p.content_area); + WriteParam(m, p.has_visible_overlays); } static bool Read(const Message* m, void** iter, param_type* p) { return ReadParam(m, iter, &p->metafile_data_handle) && @@ -1592,7 +1596,8 @@ struct ParamTraits<ViewHostMsg_DidPrintPage_Params> { ReadParam(m, iter, &p->page_number) && ReadParam(m, iter, &p->actual_shrink) && ReadParam(m, iter, &p->page_size) && - ReadParam(m, iter, &p->content_area); + ReadParam(m, iter, &p->content_area) && + ReadParam(m, iter, &p->has_visible_overlays); } static void Log(const param_type& p, std::wstring* l) { l->append(L"<ViewHostMsg_DidPrintPage_Params>"); diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc index fb0ece7..b0ae1d2 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/print_web_view_helper.cc @@ -22,6 +22,7 @@ using printing::ConvertPixelsToPoint; using printing::ConvertPixelsToPointDouble; using printing::ConvertUnit; +using printing::ConvertUnitDouble; using WebKit::WebConsoleMessage; using WebKit::WebFrame; using WebKit::WebRect; @@ -437,15 +438,21 @@ void PrintWebViewHelper::GetPageSizeAndMarginsInPoints( void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( WebFrame* frame, ViewMsg_Print_Params* params) { -#if defined(OS_MACOSX) double content_width_in_points; double content_height_in_points; PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params, &content_width_in_points, &content_height_in_points, NULL, NULL, NULL, NULL); +#if defined(OS_MACOSX) params->printable_size = gfx::Size( static_cast<int>(content_width_in_points), static_cast<int>(content_height_in_points)); +#else + params->printable_size = gfx::Size( + static_cast<int>(ConvertUnitDouble( + content_width_in_points, printing::kPointsPerInch, params->dpi)), + static_cast<int>(ConvertUnitDouble( + content_height_in_points, printing::kPointsPerInch, params->dpi))); #endif } diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc index 396edb5..3ceb8ee 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/print_web_view_helper_win.cc @@ -11,9 +11,12 @@ #include "gfx/size.h" #include "grit/generated_resources.h" #include "printing/native_metafile.h" +#include "printing/units.h" #include "skia/ext/vector_canvas.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" +using printing::ConvertUnitDouble; +using printing::kPointsPerInch; using WebKit::WebFrame; using WebKit::WebString; @@ -27,12 +30,30 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, HDC hdc = metafile.hdc(); DCHECK(hdc); skia::PlatformDevice::InitializeDC(hdc); + + double content_width_in_points; + double content_height_in_points; + double margin_top_in_points; + double margin_right_in_points; + double margin_bottom_in_points; + double margin_left_in_points; + GetPageSizeAndMarginsInPoints(frame, + params.page_number, + params.params, + &content_width_in_points, + &content_height_in_points, + &margin_top_in_points, + &margin_right_in_points, + &margin_bottom_in_points, + &margin_left_in_points); + // Since WebKit extends the page width depending on the magical shrink // factor we make sure the canvas covers the worst case scenario // (x2.0 currently). PrintContext will then set the correct clipping region. - int size_x = static_cast<int>(canvas_size.width() * params.params.max_shrink); - int size_y = static_cast<int>(canvas_size.height() * - params.params.max_shrink); + int size_x = static_cast<int>(content_width_in_points * + params.params.max_shrink); + int size_y = static_cast<int>(content_height_in_points * + params.params.max_shrink); // Calculate the dpi adjustment. float shrink = static_cast<float>(canvas_size.width()) / params.params.printable_size.width(); @@ -94,6 +115,26 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, page_params.page_number = params.page_number; page_params.document_cookie = params.params.document_cookie; page_params.actual_shrink = shrink; + page_params.page_size = gfx::Size( + static_cast<int>(ConvertUnitDouble( + content_width_in_points + + margin_left_in_points + margin_right_in_points, + kPointsPerInch, params.params.dpi)), + static_cast<int>(ConvertUnitDouble( + content_height_in_points + + margin_top_in_points + margin_bottom_in_points, + kPointsPerInch, params.params.dpi))); + page_params.content_area = gfx::Rect( + static_cast<int>(ConvertUnitDouble( + margin_left_in_points, kPointsPerInch, params.params.dpi)), + static_cast<int>(ConvertUnitDouble( + margin_top_in_points, kPointsPerInch, params.params.dpi)), + static_cast<int>(ConvertUnitDouble( + content_width_in_points, kPointsPerInch, params.params.dpi)), + static_cast<int>(ConvertUnitDouble( + content_height_in_points, kPointsPerInch, params.params.dpi))); + page_params.has_visible_overlays = + frame->isPageBoxVisible(params.page_number); base::SharedMemory shared_buf; // http://msdn2.microsoft.com/en-us/library/ms535522.aspx @@ -125,4 +166,3 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, Send(new ViewHostMsg_DidPrintPage(routing_id(), page_params)); } } - diff --git a/printing/page_overlays_unittest.cc b/printing/page_overlays_unittest.cc index 8a19dcd..a7ea283 100644 --- a/printing/page_overlays_unittest.cc +++ b/printing/page_overlays_unittest.cc @@ -59,7 +59,7 @@ TEST_F(PageOverlaysTest, StringConversion) { gfx::Size page_size(100, 100); gfx::Rect page_content_area(5, 5, 90, 90); scoped_refptr<printing::PrintedPage> page( - new printing::PrintedPage(1, NULL, page_size, page_content_area)); + new printing::PrintedPage(1, NULL, page_size, page_content_area, true)); std::wstring input; std::wstring out; diff --git a/printing/printed_document.cc b/printing/printed_document.cc index 333f1d87..ec040d4 100644 --- a/printing/printed_document.cc +++ b/printing/printed_document.cc @@ -72,14 +72,16 @@ void PrintedDocument::SetPage(int page_number, NativeMetafile* metafile, double shrink, const gfx::Size& paper_size, - const gfx::Rect& page_rect) { + const gfx::Rect& page_rect, + bool has_visible_overlays) { // Notice the page_number + 1, the reason is that this is the value that will // be shown. Users dislike 0-based counting. scoped_refptr<PrintedPage> page( new PrintedPage(page_number + 1, metafile, paper_size, - page_rect)); + page_rect, + has_visible_overlays)); { AutoLock lock(lock_); mutable_.pages_[page_number] = page; @@ -184,7 +186,7 @@ void PrintedDocument::PrintHeaderFooter(gfx::NativeDrawingContext context, PageOverlays::VerticalPosition y, const gfx::Font& font) const { const PrintSettings& settings = immutable_.settings_; - if (!settings.use_overlays) { + if (!settings.use_overlays || !page.has_visible_overlays()) { return; } const std::wstring& line = settings.overlays.GetOverlay(x, y); diff --git a/printing/printed_document.h b/printing/printed_document.h index 049add0..752c1c3 100644 --- a/printing/printed_document.h +++ b/printing/printed_document.h @@ -43,7 +43,8 @@ class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> { // Sets a page's data. 0-based. Takes metafile ownership. // Note: locks for a short amount of time. void SetPage(int page_number, NativeMetafile* metafile, double shrink, - const gfx::Size& paper_size, const gfx::Rect& page_rect); + const gfx::Size& paper_size, const gfx::Rect& page_rect, + bool has_visible_overlays); // Retrieves a page. If the page is not available right now, it // requests to have this page be rendered and returns false. diff --git a/printing/printed_document_win.cc b/printing/printed_document_win.cc index 42c1b45..e80ac78a 100644 --- a/printing/printed_document_win.cc +++ b/printing/printed_document_win.cc @@ -51,6 +51,17 @@ void PrintedDocument::RenderPrintedPage( const printing::PageSetup& page_setup( immutable_.settings_.page_setup_device_units()); + gfx::Rect content_area(page.page_content_rect()); + const gfx::Size& physical_size = page_setup.physical_size(); + // http://dev.w3.org/csswg/css3-page/#positioning-page-box + if (physical_size.width() > page.page_size().width()) { + int diff = physical_size.width() - page.page_size().width(); + content_area.set_x(content_area.x() + diff / 2); + } + if (physical_size.height() > page.page_size().height()) { + int diff = physical_size.height() - page.page_size().height(); + content_area.set_y(content_area.y() + diff / 2); + } // Save the state to make sure the context this function call does not modify // the device context. @@ -81,7 +92,7 @@ void PrintedDocument::RenderPrintedPage( SelectObject(context, CreateSolidBrush(RGB(0xb0, 0xb0, 0xb0))); DrawRect(context, debug_overlay_area); // Content area: - gfx::Rect debug_content_area(page_setup.content_area()); + gfx::Rect debug_content_area(content_area()); debug_content_area.Offset(-page_setup.printable_area().x(), -page_setup.printable_area().y()); SelectObject(context, CreateSolidBrush(RGB(0xd0, 0xd0, 0xd0))); @@ -94,8 +105,8 @@ void PrintedDocument::RenderPrintedPage( // That is 0,0 is offset by PHYSICALOFFSETX/Y from the page. SimpleModifyWorldTransform( context, - page_setup.content_area().x() - page_setup.printable_area().x(), - page_setup.content_area().y() - page_setup.printable_area().y(), + content_area.x() - page_setup.printable_area().x(), + content_area.y() - page_setup.printable_area().y(), mutable_.shrink_factor); if (!page.native_metafile()->SafePlayback(context)) { diff --git a/printing/printed_page.cc b/printing/printed_page.cc index 242adb2..8abedeee 100644 --- a/printing/printed_page.cc +++ b/printing/printed_page.cc @@ -9,11 +9,13 @@ namespace printing { PrintedPage::PrintedPage(int page_number, NativeMetafile* native_metafile, const gfx::Size& page_size, - const gfx::Rect& page_content_rect) + const gfx::Rect& page_content_rect, + bool has_visible_overlays) : page_number_(page_number), native_metafile_(native_metafile), page_size_(page_size), - page_content_rect_(page_content_rect) { + page_content_rect_(page_content_rect), + has_visible_overlays_(has_visible_overlays) { } PrintedPage::~PrintedPage() { diff --git a/printing/printed_page.h b/printing/printed_page.h index 83425ba..17181c6 100644 --- a/printing/printed_page.h +++ b/printing/printed_page.h @@ -24,13 +24,15 @@ class PrintedPage : public base::RefCountedThreadSafe<PrintedPage> { PrintedPage(int page_number, NativeMetafile* native_metafile, const gfx::Size& page_size, - const gfx::Rect& page_content_rect); + const gfx::Rect& page_content_rect, + bool has_visible_overlays); // Getters int page_number() const { return page_number_; } const NativeMetafile* native_metafile() const; const gfx::Size& page_size() const { return page_size_; } const gfx::Rect& page_content_rect() const { return page_content_rect_; } + bool has_visible_overlays() const { return has_visible_overlays_; } private: friend class base::RefCountedThreadSafe<PrintedPage>; @@ -50,6 +52,9 @@ class PrintedPage : public base::RefCountedThreadSafe<PrintedPage> { // The printable area of the page. const gfx::Rect page_content_rect_; + // True if the overlays should be visible in this page. + bool has_visible_overlays_; + DISALLOW_COPY_AND_ASSIGN(PrintedPage); }; |