[chromium] Overloaded printBegin() function to support auto fit to page functionality.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 May 2012 01:42:46 +0000 (01:42 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 May 2012 01:42:46 +0000 (01:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=84312

Patch by Kausalya Madhusudhanan <kmadhusu@chromium.org> on 2012-05-15
Reviewed by Darin Fisher.

* WebKit.gyp:
* public/WebFrame.h:
(WebKit):
(WebFrame):
* public/WebPlugin.h:
(WebKit):
(WebPlugin):
(WebKit::WebPlugin::printBegin):
* public/WebPrintParams.h: Added.
(WebKit):
(WebPrintParams):
(WebKit::WebPrintParams::WebPrintParams):
* src/WebFrameImpl.cpp:
(WebKit::ChromePluginPrintContext::ChromePluginPrintContext):
(WebKit::ChromePluginPrintContext::computePageRects):
(ChromePluginPrintContext):
(WebKit):
(WebKit::WebFrameImpl::printBegin):
* src/WebFrameImpl.h:
(WebKit):
(WebFrameImpl):
* src/WebPluginContainerImpl.cpp:
(WebKit::WebPluginContainerImpl::printBegin):
* src/WebPluginContainerImpl.h:
(WebKit):
(WebPluginContainerImpl):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@117200 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gyp
Source/WebKit/chromium/public/WebFrame.h
Source/WebKit/chromium/public/WebPlugin.h
Source/WebKit/chromium/public/WebPrintParams.h [new file with mode: 0644]
Source/WebKit/chromium/src/WebFrameImpl.cpp
Source/WebKit/chromium/src/WebFrameImpl.h
Source/WebKit/chromium/src/WebPluginContainerImpl.cpp
Source/WebKit/chromium/src/WebPluginContainerImpl.h

index 76a8e03..2913aba 100644 (file)
@@ -1,3 +1,37 @@
+2012-05-15  Kausalya Madhusudhanan  <kmadhusu@chromium.org>
+
+        [chromium] Overloaded printBegin() function to support auto fit to page functionality.
+        https://bugs.webkit.org/show_bug.cgi?id=84312
+
+        Reviewed by Darin Fisher.
+
+        * WebKit.gyp:
+        * public/WebFrame.h:
+        (WebKit):
+        (WebFrame):
+        * public/WebPlugin.h:
+        (WebKit):
+        (WebPlugin):
+        (WebKit::WebPlugin::printBegin):
+        * public/WebPrintParams.h: Added.
+        (WebKit):
+        (WebPrintParams):
+        (WebKit::WebPrintParams::WebPrintParams):
+        * src/WebFrameImpl.cpp:
+        (WebKit::ChromePluginPrintContext::ChromePluginPrintContext):
+        (WebKit::ChromePluginPrintContext::computePageRects):
+        (ChromePluginPrintContext):
+        (WebKit):
+        (WebKit::WebFrameImpl::printBegin):
+        * src/WebFrameImpl.h:
+        (WebKit):
+        (WebFrameImpl):
+        * src/WebPluginContainerImpl.cpp:
+        (WebKit::WebPluginContainerImpl::printBegin):
+        * src/WebPluginContainerImpl.h:
+        (WebKit):
+        (WebPluginContainerImpl):
+
 2012-05-15  Shawn Singh  <shawnsingh@chromium.org>
 
         [chromium] Add unit testing to WebTransformationMatrix
index c9792da..818b8ad 100644 (file)
                 'public/WebPluginContainer.h',
                 'public/WebPluginDocument.h',
                 'public/WebPluginListBuilder.h',
+                'public/WebPrintParams.h',
                 'public/WebPrintScalingOption.h',
                 'public/WebPopupMenu.h',
                 'public/WebPopupMenuInfo.h',
index 017cb0d..b76e9fa 100644 (file)
@@ -73,6 +73,7 @@ class WebView;
 struct WebConsoleMessage;
 struct WebFindOptions;
 struct WebPoint;
+struct WebPrintParams;
 struct WebRect;
 struct WebScriptSource;
 struct WebSize;
@@ -452,19 +453,35 @@ public:
 
     // Printing ------------------------------------------------------------
 
-    // Reformats the WebFrame for printing. pageSize is the page size in
-    // points (a point in 1/72 of an inch). If |constrainToNode| node is
-    // specified, then only the given node is printed (for now only plugins are
-    // supported), instead of the entire frame.  printerDPI is the user
-    // selected, DPI for the printer. Returns the number of pages that can be
-    // printed at the given page size. The out param useBrowserOverlays
+    // Reformats the WebFrame for printing. printContentSize is the print
+    // content size in points (a point is 1/72 of an inch). If constrainToNode
+    // node is specified, then only the given node is printed (for now only
+    // plugins are supported), instead of the entire frame. printerDPI is the
+    // user selected, DPI for the printer. Returns the number of pages that can
+    // be printed at the given page size. The out param useBrowserOverlays
     // specifies whether the browser process should use its overlays (header,
     // footer, margins etc) or whether the renderer controls this.
-    virtual int printBegin(const WebSize& pageSize,
+    //
+    // FIXME: This is a temporary interface to avoid the compile errors. Remove
+    // this interface after fixing crbug.com/85132. We will use the overloaded
+    // printBegin function.
+    virtual int printBegin(const WebSize& printContentSize,
                            const WebNode& constrainToNode = WebNode(),
                            int printerDPI = 72,
                            bool* useBrowserOverlays = 0) = 0;
 
+    // Reformats the WebFrame for printing. WebPrintParams specifies the printable
+    // content size, paper size, printable area size, printer DPI and print
+    // scaling option. If constrainToNode node is specified, then only the given node
+    // is printed (for now only plugins are supported), instead of the entire frame.
+    // Returns the number of pages that can be printed at the given
+    // page size. The out param useBrowserOverlays specifies whether the browser
+    // process should use its overlays (header, footer, margins etc) or whether
+    // the renderer controls this.
+    virtual int printBegin(const WebPrintParams&,
+                           const WebNode& constrainToNode = WebNode(),
+                           bool* useBrowserOverlays = 0) = 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.
index 3f2d12d..717f6a7 100644 (file)
@@ -46,6 +46,7 @@ class WebPluginContainer;
 class WebURLResponse;
 struct WebCursorInfo;
 struct WebPluginParams;
+struct WebPrintParams;
 struct WebPoint;
 struct WebRect;
 struct WebURLError;
@@ -96,10 +97,17 @@ public:
     // Returns true if the printed content should not be scaled to
     // the printer's printable area.
     virtual bool isPrintScalingDisabled() { return false; }
-    // Sets up printing at the given print rect and printer DPI. printableArea
-    // is in points (a point is 1/72 of an inch).Returns the number of pages to
-    // be printed at these settings.
-    virtual int printBegin(const WebRect& printableArea, int printerDPI) { return 0; }
+
+    // Sets up printing at the given print rect and printer DPI.
+    // printContentArea is in points ( a point is 1/72 of an inch). Returns the
+    // number of pages to be printed at these settings.
+    // FIXME: Remove this function after fixing crbug.com/85132. For detailed
+    // information, please refer to the comments in WebFrame.h
+    virtual int printBegin(const WebRect& printContentArea, int printerDPI) { return 0; }
+    // Sets up printing with the specified printParams. Returns the number of
+    // pages to be printed at these settings.
+    virtual int printBegin(const WebPrintParams& printParams) { return 0; }
+
     // Prints the page specified by pageNumber (0-based index) into the supplied canvas.
     virtual bool printPage(int pageNumber, WebCanvas* canvas) { return false; }
     // Ends the print operation.
diff --git a/Source/WebKit/chromium/public/WebPrintParams.h b/Source/WebKit/chromium/public/WebPrintParams.h
new file mode 100644 (file)
index 0000000..d2d25bd
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebPrintParams_h
+#define WebPrintParams_h
+
+#include "WebPrintScalingOption.h"
+#include "platform/WebRect.h"
+#include "platform/WebSize.h"
+
+namespace WebKit {
+
+struct WebPrintParams {
+    // Specifies printable content rect in points (a point is 1/72 of an inch).
+    WebRect printContentArea;
+
+    // Specifies the selected printer default printable area details in
+    // points.
+    WebRect printableArea;
+
+    // Specifies the selected printer default paper size in points.
+    WebSize paperSize;
+
+    // Specifies user selected DPI for printing.
+    int printerDPI;
+
+    // Specifies whether to reduce/enlarge/retain the print contents to fit the
+    // printable area. (This is used only by plugin printing).
+    WebPrintScalingOption printScalingOption;
+
+    WebPrintParams()
+        : printerDPI(72)
+        , printScalingOption(WebPrintScalingOptionFitToPrintableArea) { }
+
+    WebPrintParams(const WebRect& printContentArea, const WebRect& printableArea, const WebSize& paperSize, int printerDPI, WebPrintScalingOption printScalingOption)
+        : printContentArea(printContentArea)
+        , printableArea(printableArea)
+        , paperSize(paperSize)
+        , printerDPI(printerDPI)
+        , printScalingOption(printScalingOption) { }
+};
+
+} // namespace WebKit
+
+#endif
index e60a27a..ac49f10 100644 (file)
 #include "WebPerformance.h"
 #include "WebPlugin.h"
 #include "WebPluginContainerImpl.h"
+#include "WebPrintParams.h"
 #include "WebRange.h"
 #include "WebScriptSource.h"
 #include "WebSecurityOrigin.h"
@@ -444,8 +445,8 @@ private:
 // want to delegate all printing related calls to the plugin.
 class ChromePluginPrintContext : public ChromePrintContext {
 public:
-    ChromePluginPrintContext(Frame* frame, WebPluginContainerImpl* plugin, int printerDPI)
-        : ChromePrintContext(frame), m_plugin(plugin), m_pageCount(0), m_printerDPI(printerDPI)
+    ChromePluginPrintContext(Frame* frame, WebPluginContainerImpl* plugin, const WebPrintParams& printParams)
+        : ChromePrintContext(frame), m_plugin(plugin), m_pageCount(0), m_printParams(printParams)
     {
     }
 
@@ -468,7 +469,8 @@ public:
 
     virtual void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight)
     {
-        m_pageCount = m_plugin->printBegin(IntRect(printRect), m_printerDPI);
+        m_printParams.printContentArea = IntRect(printRect);
+        m_pageCount = m_plugin->printBegin(m_printParams);
     }
 
     virtual int pageCount() const
@@ -494,7 +496,9 @@ private:
     // Set when printing.
     WebPluginContainerImpl* m_plugin;
     int m_pageCount;
-    int m_printerDPI;
+    WebPrintParams m_printParams;
+    WebPrintScalingOption m_printScalingOption;
+
 };
 
 static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader)
@@ -1439,9 +1443,23 @@ VisiblePosition WebFrameImpl::visiblePositionForWindowPoint(const WebPoint& poin
     return node->renderer()->positionForPoint(result.localPoint());
 }
 
-int WebFrameImpl::printBegin(const WebSize& pageSize,
+// TODO(kmadhusu@chromium.org): Remove this function after fixing
+// crbug.com/85132. For more information, please refer to the comments in
+// WebFrame.h
+int WebFrameImpl::printBegin(const WebSize& printContentSize,
                              const WebNode& constrainToNode,
                              int printerDPI,
+                             bool* useBrowserOverlays) {
+    WebRect printableArea(0, 0, printContentSize.width, printContentSize.height);
+    WebSize paperSize(printContentSize);
+    WebRect printContentArea(0, 0, printContentSize.width, printContentSize.height);
+    WebPrintParams printParams(printContentArea, printableArea, paperSize,
+                               printerDPI, WebPrintScalingOptionSourceSize);
+    return printBegin(printParams, constrainToNode, useBrowserOverlays);
+}
+
+int WebFrameImpl::printBegin(const WebPrintParams& printParams,
+                             const WebNode& constrainToNode,
                              bool* useBrowserOverlays)
 {
     ASSERT(!frame()->document()->isFrameSet());
@@ -1456,12 +1474,12 @@ int WebFrameImpl::printBegin(const WebSize& pageSize,
     }
 
     if (pluginContainer && pluginContainer->supportsPaginatedPrint())
-        m_printContext = adoptPtr(new ChromePluginPrintContext(frame(), pluginContainer, printerDPI));
+        m_printContext = adoptPtr(new ChromePluginPrintContext(frame(), pluginContainer, printParams));
     else
         m_printContext = adoptPtr(new ChromePrintContext(frame()));
 
-    FloatRect rect(0, 0, static_cast<float>(pageSize.width),
-                         static_cast<float>(pageSize.height));
+    FloatRect rect(0, 0, static_cast<float>(printParams.printContentArea.width),
+                         static_cast<float>(printParams.printContentArea.height));
     m_printContext->begin(rect.width(), rect.height());
     float pageHeight;
     // We ignore the overlays calculation for now since they are generated in the
index 389946d..82f3ec8 100644 (file)
@@ -61,6 +61,7 @@ class WebPerformance;
 class WebPluginContainerImpl;
 class WebView;
 class WebViewImpl;
+struct WebPrintParams;
 
 template <typename T> class WebVector;
 
@@ -175,10 +176,15 @@ public:
     virtual bool selectWordAroundCaret();
     virtual void selectRange(const WebPoint& start, const WebPoint& end);
     virtual void selectRange(const WebRange&);
-    virtual int printBegin(const WebSize& pageSize,
+    // FIXME: Remove this function after fixing crbug.com/85132. For detailed
+    // information, please refer to the comments in WebFrame.h
+    virtual int printBegin(const WebSize& printContentSize,
                            const WebNode& constrainToNode,
                            int printerDPI,
                            bool* useBrowserOverlays);
+    virtual int printBegin(const WebPrintParams&,
+                           const WebNode& constrainToNode,
+                           bool* useBrowserOverlays);
     virtual float printPage(int pageToPrint, WebCanvas*);
     virtual float getPrintPageShrink(int page);
     virtual void printEnd();
index 6ee01ef..4192b9d 100644 (file)
@@ -72,6 +72,7 @@
 #include "ScrollView.h"
 #include "ScrollbarTheme.h"
 #include "UserGestureIndicator.h"
+#include "WebPrintParams.h"
 #include "WheelEvent.h"
 #include <public/Platform.h>
 #include <public/WebClipboard.h>
@@ -243,10 +244,12 @@ bool WebPluginContainerImpl::isPrintScalingDisabled() const
     return m_webPlugin->isPrintScalingDisabled();
 }
 
-int WebPluginContainerImpl::printBegin(const IntRect& printableArea,
-                                       int printerDPI) const
+int WebPluginContainerImpl::printBegin(const WebPrintParams& printParams) const
 {
-    return m_webPlugin->printBegin(printableArea, printerDPI);
+    return m_webPlugin->printBegin(printParams.printContentArea, printParams.printerDPI);
+    // FIXME: After committing this CL, update the chrome plugin printBegin()
+    // function to use the overloaded printBegin function.
+    // return m_webPlugin->printBegin(printParams);
 }
 
 bool WebPluginContainerImpl::printPage(int pageNumber,
index 0487845..1003585 100644 (file)
@@ -61,6 +61,8 @@ class PlatformGestureEvent;
 
 namespace WebKit {
 
+struct WebPrintParams;
+
 class ScrollbarGroup;
 class WebPlugin;
 class WebPluginLoadObserver;
@@ -120,10 +122,8 @@ public:
     // If the plugin content should not be scaled to the printable area of
     // the page, then this method should return true.
     bool isPrintScalingDisabled() const;
-    // Sets up printing at the given print rect and printer DPI. printableArea
-    // is in points (a point is 1/72 of an inch).Returns the number of pages to
-    // be printed at these settings.
-    int printBegin(const WebCore::IntRect& printableArea, int printerDPI) const;
+    // Sets up printing at the specified WebPrintParams. Returns the number of pages to be printed at these settings.
+    int printBegin(const WebPrintParams&) const;
     // Prints the page specified by pageNumber (0-based index) into the supplied canvas.
     bool printPage(int pageNumber, WebCore::GraphicsContext* gc);
     // Ends the print operation.