diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-27 20:01:27 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-27 20:01:27 +0000 |
commit | c6321d8e201af8f7b91cd0b134d4ad32844f66c1 (patch) | |
tree | 3ed92a2f921e6165692c64bfad0b1582a76aad11 | |
parent | 891acc9b216198f8a143a8b0f1a0dada8d989299 (diff) | |
download | chromium_src-c6321d8e201af8f7b91cd0b134d4ad32844f66c1.zip chromium_src-c6321d8e201af8f7b91cd0b134d4ad32844f66c1.tar.gz chromium_src-c6321d8e201af8f7b91cd0b134d4ad32844f66c1.tar.bz2 |
Rev 12100 changed the way that we spool and render printed output, most notably
introducing use of the PrintContext class. The existing
PrintContext::spoolPage() method applies a webkit scaling factor before
rendering output to the graphics context. ChromePrintContext::spoolPage() (in
webframe_impl.cc), which is used by chromium instead of
PrintContext::spoolPage(), does not apply this scaling factor, but instead
eventually returns the scaling factor via WebFrame::PrintPage(). This is a
problem for the Chromium Embedded Framework (CEF) because, unlike chromium, the
CEF renders directly to the printer device context. It is therefore important
for CEF that we retrieve and apply the webkit scaling factor before calling
PrintPage(). In order to support this capability the following adds a
WebFrame::GetPrintPageShrink() method.
Patch contributed by Marshall Greenblatt <magreenblatt@gmail.com>
Review: http://codereview.chromium.org/99058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14639 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/glue/webframe.h | 7 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 14 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.h | 1 |
3 files changed, 21 insertions, 1 deletions
diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h index 6849573..67a1013 100644 --- a/webkit/glue/webframe.h +++ b/webkit/glue/webframe.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 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. @@ -377,6 +377,11 @@ class WebFrame { virtual bool BeginPrint(const WebKit::WebSize& page_size_px, int* page_count) = 0; + // Returns the page shrinking factor calculated by webkit (usually between + // 1/1.25 and 1/2). Returns 0 if the page number is invalid or not in printing + // mode. + virtual float GetPrintPageShrink(int page) = 0; + // Prints one page. |page| is 0-based. // Returns the page shrinking factor calculated by webkit (usually between // 1/1.25 and 1/2). Returns 0 if the page number is invalid or not in printing diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index dfed0aa..3b87d4f 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -307,6 +307,10 @@ class ChromePrintContext : public WebCore::PrintContext { printed_page_width_ = width; WebCore::PrintContext::begin(printed_page_width_); } + float getPageShrink(int pageNumber) const { + IntRect pageRect = m_pageRects[pageNumber]; + return printed_page_width_ / pageRect.width(); + } // Spools the printed page, a subrect of m_frame. // Skip the scale step. NativeTheme doesn't play well with scaling. Scaling // is done browser side instead. @@ -1884,6 +1888,16 @@ bool WebFrameImpl::BeginPrint(const WebSize& page_size_px, return true; } +float WebFrameImpl::GetPrintPageShrink(int page) { + // Ensure correct state. + if (!print_context_.get() || page < 0) { + NOTREACHED(); + return 0; + } + + return print_context_->getPageShrink(page); +} + float WebFrameImpl::PrintPage(int page, skia::PlatformCanvas* canvas) { // Ensure correct state. if (!print_context_.get() || page < 0 || !frame() || !frame()->document()) { diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index 3cf12f1..61162f7 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -179,6 +179,7 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { virtual bool BeginPrint(const WebKit::WebSize& page_size_px, int* page_count); + virtual float GetPrintPageShrink(int page); virtual float PrintPage(int page, skia::PlatformCanvas* canvas); virtual void EndPrint(); |