+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
'public/WebPluginContainer.h',
'public/WebPluginDocument.h',
'public/WebPluginListBuilder.h',
+ 'public/WebPrintParams.h',
'public/WebPrintScalingOption.h',
'public/WebPopupMenu.h',
'public/WebPopupMenuInfo.h',
struct WebConsoleMessage;
struct WebFindOptions;
struct WebPoint;
+struct WebPrintParams;
struct WebRect;
struct WebScriptSource;
struct WebSize;
// 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.
class WebURLResponse;
struct WebCursorInfo;
struct WebPluginParams;
+struct WebPrintParams;
struct WebPoint;
struct WebRect;
struct WebURLError;
// 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.
--- /dev/null
+/*
+ * 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
#include "WebPerformance.h"
#include "WebPlugin.h"
#include "WebPluginContainerImpl.h"
+#include "WebPrintParams.h"
#include "WebRange.h"
#include "WebScriptSource.h"
#include "WebSecurityOrigin.h"
// 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)
{
}
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
// Set when printing.
WebPluginContainerImpl* m_plugin;
int m_pageCount;
- int m_printerDPI;
+ WebPrintParams m_printParams;
+ WebPrintScalingOption m_printScalingOption;
+
};
static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader)
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());
}
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
class WebPluginContainerImpl;
class WebView;
class WebViewImpl;
+struct WebPrintParams;
template <typename T> class WebVector;
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();
#include "ScrollView.h"
#include "ScrollbarTheme.h"
#include "UserGestureIndicator.h"
+#include "WebPrintParams.h"
#include "WheelEvent.h"
#include <public/Platform.h>
#include <public/WebClipboard.h>
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,
namespace WebKit {
+struct WebPrintParams;
+
class ScrollbarGroup;
class WebPlugin;
class WebPluginLoadObserver;
// 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.