[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

darin at chromium.org darin at chromium.org
Thu Apr 8 02:19:06 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit c1986ab0dede43c35a7fe179b827e54d210ad2d1
Author: darin at chromium.org <darin at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Mar 10 23:28:05 2010 +0000

    2010-03-10  Sanjeev Radhakrishnan  <sanjeevr at chromium.org>
    
            Reviewed by Darin Fisher.
    
            Allow a plugin to participate in the browser's print workflow.
            https://bugs.webkit.org/show_bug.cgi?id=35550
    
            * loader/PluginDocument.cpp:
            * loader/PluginDocument.h:
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55814 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 3aebf8f..a018878 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,13 @@
+2010-03-10  Sanjeev Radhakrishnan  <sanjeevr at chromium.org>
+
+        Reviewed by Darin Fisher.
+
+        Allow a plugin to participate in the browser's print workflow.
+        https://bugs.webkit.org/show_bug.cgi?id=35550
+
+        * loader/PluginDocument.cpp:
+        * loader/PluginDocument.h:
+
 2010-03-10  Ilya Tikhonovsky  <loislo at loislo-macbookpro.local>
 
         Reviewed by Pavel Feldman.
diff --git a/WebCore/loader/PluginDocument.cpp b/WebCore/loader/PluginDocument.cpp
index 604defc..d0bc62e 100644
--- a/WebCore/loader/PluginDocument.cpp
+++ b/WebCore/loader/PluginDocument.cpp
@@ -34,6 +34,7 @@
 #include "HTMLNames.h"
 #include "MainResourceLoader.h"
 #include "Page.h"
+#include "RenderEmbeddedObject.h"
 #include "RenderWidget.h"
 #include "SegmentedString.h"
 #include "Settings.h"
@@ -47,6 +48,7 @@ using namespace HTMLNames;
 class PluginTokenizer : public Tokenizer {
 public:
     PluginTokenizer(Document* doc) : m_doc(doc), m_embedElement(0) {}
+    static Widget* pluginWidgetFromDocument(Document* doc);
         
 private:
     virtual void write(const SegmentedString&, bool appendData);
@@ -62,7 +64,21 @@ private:
     Document* m_doc;
     HTMLEmbedElement* m_embedElement;
 };
-    
+
+Widget* PluginTokenizer::pluginWidgetFromDocument(Document* doc)
+{
+    ASSERT(doc);
+    RefPtr<Element> body = doc->body();
+    if (body) {
+        RefPtr<Node> node = body->firstChild();
+        if (node && node->renderer()) {
+            ASSERT(node->renderer()->isEmbeddedObject());
+            return toRenderEmbeddedObject(node->renderer())->widget();
+        }
+    }
+    return 0;
+}
+
 void PluginTokenizer::write(const SegmentedString&, bool)
 {
     ASSERT_NOT_REACHED();
@@ -146,5 +162,10 @@ Tokenizer* PluginDocument::createTokenizer()
 {
     return new PluginTokenizer(this);
 }
-    
+
+Widget* PluginDocument::pluginWidget()
+{
+    return PluginTokenizer::pluginWidgetFromDocument(this);
+}
+
 }
diff --git a/WebCore/loader/PluginDocument.h b/WebCore/loader/PluginDocument.h
index 1d5c964..60dfd25 100644
--- a/WebCore/loader/PluginDocument.h
+++ b/WebCore/loader/PluginDocument.h
@@ -28,7 +28,8 @@
 #include "HTMLDocument.h"
 
 namespace WebCore {
-    
+
+class Widget;
 class PluginDocument : public HTMLDocument {
 public:
     static PassRefPtr<PluginDocument> create(Frame* frame)
@@ -36,6 +37,8 @@ public:
         return adoptRef(new PluginDocument(frame));
     }
 
+    Widget* pluginWidget();
+
 private:
     PluginDocument(Frame*);
 
diff --git a/WebKit/chromium/ChangeLog b/WebKit/chromium/ChangeLog
index de66d13..0a0c65d 100644
--- a/WebKit/chromium/ChangeLog
+++ b/WebKit/chromium/ChangeLog
@@ -1,3 +1,17 @@
+2010-03-10  Sanjeev Radhakrishnan  <sanjeevr at chromium.org>
+
+        Reviewed by Darin Fisher.
+
+        Allow a plugin to participate in the browser's print workflow.
+        https://bugs.webkit.org/show_bug.cgi?id=35550
+
+        * public/WebFrame.h:
+        * public/WebPlugin.h:
+        * src/WebFrameImpl.cpp:
+        * src/WebFrameImpl.h:
+        * src/WebPluginContainerImpl.cpp:
+        * src/WebPluginContainerImpl.h:
+
 2010-03-10  John Abd-El-Malek  <jam at chromium.org>
 
         Reviewed by Nate Chapin.
diff --git a/WebKit/chromium/public/WebFrame.h b/WebKit/chromium/public/WebFrame.h
index a6466e0..4fb00e6 100644
--- a/WebKit/chromium/public/WebFrame.h
+++ b/WebKit/chromium/public/WebFrame.h
@@ -370,10 +370,14 @@ public:
 
     // Printing ------------------------------------------------------------
 
-    // Reformats the WebFrame for printing.  pageSize is the page size in
-    // pixels.  Returns the number of pages that can be printed at the
-    // given page size.
-    virtual int printBegin(const WebSize& pageSize) = 0;
+    // Reformats the WebFrame for printing. pageSize is the page size in
+    // points (a point in 1/72 of an inch). 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, int printerDPI = 72,
+                           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
diff --git a/WebKit/chromium/public/WebPlugin.h b/WebKit/chromium/public/WebPlugin.h
index 5097265..f57c621 100644
--- a/WebKit/chromium/public/WebPlugin.h
+++ b/WebKit/chromium/public/WebPlugin.h
@@ -80,6 +80,19 @@ public:
     virtual void didFailLoadingFrameRequest(
         const WebURL&, void* notifyData, const WebURLError&) = 0;
 
+    // Printing interface.
+    // Whether the plugin supports its own paginated print. The other print
+    // interface methods are called only if this method returns true.
+    virtual bool supportsPaginatedPrint() { 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; }
+    // 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.
+    virtual void printEnd() { }
+
 protected:
     ~WebPlugin() { }
 };
diff --git a/WebKit/chromium/src/WebFrameImpl.cpp b/WebKit/chromium/src/WebFrameImpl.cpp
index 37f9691..1353c94 100644
--- a/WebKit/chromium/src/WebFrameImpl.cpp
+++ b/WebKit/chromium/src/WebFrameImpl.cpp
@@ -101,6 +101,7 @@
 #include "markup.h"
 #include "Page.h"
 #include "PlatformContextSkia.h"
+#include "PluginDocument.h"
 #include "PrintContext.h"
 #include "RenderFrame.h"
 #include "RenderTreeAsText.h"
@@ -130,6 +131,7 @@
 #include "WebHistoryItem.h"
 #include "WebInputElement.h"
 #include "WebPasswordAutocompleteListener.h"
+#include "WebPluginContainerImpl.h"
 #include "WebRange.h"
 #include "WebRect.h"
 #include "WebScriptSource.h"
@@ -246,7 +248,20 @@ static void frameContentAsPlainText(size_t maxChars, Frame* frame,
     }
 }
 
-// Simple class to override some of PrintContext behavior.
+// If the frame hosts a PluginDocument, this method returns the WebPluginContainerImpl
+// that hosts the plugin.
+static WebPluginContainerImpl* pluginContainerFromFrame(Frame* frame)
+{
+    if (!frame)
+        return 0;
+    if (!frame->document() || !frame->document()->isPluginDocument())
+        return 0;
+    PluginDocument* pluginDocument = static_cast<PluginDocument*>(frame->document());
+    return static_cast<WebPluginContainerImpl *>(pluginDocument->pluginWidget());
+}
+
+// Simple class to override some of PrintContext behavior. Some of the methods
+// made virtual so that they can be overriden by ChromePluginPrintContext.
 class ChromePrintContext : public PrintContext, public Noncopyable {
 public:
     ChromePrintContext(Frame* frame)
@@ -255,14 +270,19 @@ public:
     {
     }
 
-    void begin(float width)
+    virtual void begin(float width)
     {
         ASSERT(!m_printedPageWidth);
         m_printedPageWidth = width;
         PrintContext::begin(m_printedPageWidth);
     }
 
-    float getPageShrink(int pageNumber) const
+    virtual void end()
+    {
+        PrintContext::end();
+    }
+
+    virtual float getPageShrink(int pageNumber) const
     {
         IntRect pageRect = m_pageRects[pageNumber];
         return m_printedPageWidth / pageRect.width();
@@ -271,7 +291,7 @@ public:
     // 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.  Returns the scale to be applied.
-    float spoolPage(GraphicsContext& ctx, int pageNumber)
+    virtual float spoolPage(GraphicsContext& ctx, int pageNumber)
     {
         IntRect pageRect = m_pageRects[pageNumber];
         float scale = m_printedPageWidth / pageRect.width();
@@ -285,11 +305,95 @@ public:
         return scale;
     }
 
+    virtual void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight)
+    {
+        return PrintContext::computePageRects(printRect, headerHeight, footerHeight, userScaleFactor, outPageHeight);
+    }
+
+    virtual int pageCount() const
+    {
+        return PrintContext::pageCount();
+    }
+
+    virtual bool shouldUseBrowserOverlays() const
+    {
+        return true;
+    }
+
 private:
     // Set when printing.
     float m_printedPageWidth;
 };
 
+// Simple class to override some of PrintContext behavior. This is used when
+// the frame hosts a plugin that supports custom printing. In this case, we
+// want to delegate all printing related calls to the plugin.
+class ChromePluginPrintContext : public ChromePrintContext {
+public:
+    ChromePluginPrintContext(Frame* frame, int printerDPI)
+        : ChromePrintContext(frame), m_pageCount(0), m_printerDPI(printerDPI)
+    {
+        // This HAS to be a frame hosting a full-mode plugin
+        ASSERT(frame->document()->isPluginDocument());
+    }
+
+    virtual void begin(float width)
+    {
+    }
+
+    virtual void end()
+    {
+        WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(m_frame);
+        if (pluginContainer && pluginContainer->supportsPaginatedPrint())
+            pluginContainer->printEnd();
+        else
+            ASSERT_NOT_REACHED();
+    }
+
+    virtual float getPageShrink(int pageNumber) const
+    {
+        // We don't shrink the page (maybe we should ask the widget ??)
+        return 1.0;
+    }
+
+    virtual void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight)
+    {
+        WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(m_frame);
+        if (pluginContainer && pluginContainer->supportsPaginatedPrint())
+            m_pageCount = pluginContainer->printBegin(IntRect(printRect), m_printerDPI);
+        else
+            ASSERT_NOT_REACHED();
+    }
+
+    virtual int pageCount() const
+    {
+        return m_pageCount;
+    }
+
+    // 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.  Returns the scale to be applied.
+    virtual float spoolPage(GraphicsContext& ctx, int pageNumber)
+    {
+        WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(m_frame);
+        if (pluginContainer && pluginContainer->supportsPaginatedPrint())
+            pluginContainer->printPage(pageNumber, &ctx);
+        else
+            ASSERT_NOT_REACHED();
+        return 1.0;
+    }
+
+    virtual bool shouldUseBrowserOverlays() const
+    {
+        return false;
+    }
+
+private:
+    // Set when printing.
+    int m_pageCount;
+    int m_printerDPI;
+};
+
 static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader)
 {
     return loader ? WebDataSourceImpl::fromDocumentLoader(loader) : 0;
@@ -1092,11 +1196,17 @@ bool WebFrameImpl::selectWordAroundCaret()
     return true;
 }
 
-int WebFrameImpl::printBegin(const WebSize& pageSize)
+int WebFrameImpl::printBegin(const WebSize& pageSize, int printerDPI, bool *useBrowserOverlays)
 {
     ASSERT(!frame()->document()->isFrameSet());
+    // If this is a plugin document, check if the plugin supports its own
+    // printing. If it does, we will delegate all printing to that.
+    WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(frame());
+    if (pluginContainer && pluginContainer->supportsPaginatedPrint())
+        m_printContext.set(new ChromePluginPrintContext(frame(), printerDPI));
+    else
+        m_printContext.set(new ChromePrintContext(frame()));
 
-    m_printContext.set(new ChromePrintContext(frame()));
     FloatRect rect(0, 0, static_cast<float>(pageSize.width),
                          static_cast<float>(pageSize.height));
     m_printContext->begin(rect.width());
@@ -1104,6 +1214,9 @@ int WebFrameImpl::printBegin(const WebSize& pageSize)
     // We ignore the overlays calculation for now since they are generated in the
     // browser. pageHeight is actually an output parameter.
     m_printContext->computePageRects(rect, 0, 0, 1.0, pageHeight);
+    if (useBrowserOverlays)
+        *useBrowserOverlays = m_printContext->shouldUseBrowserOverlays();
+
     return m_printContext->pageCount();
 }
 
diff --git a/WebKit/chromium/src/WebFrameImpl.h b/WebKit/chromium/src/WebFrameImpl.h
index 0379cf7..245acf3 100644
--- a/WebKit/chromium/src/WebFrameImpl.h
+++ b/WebKit/chromium/src/WebFrameImpl.h
@@ -142,7 +142,8 @@ public:
     virtual WebString selectionAsText() const;
     virtual WebString selectionAsMarkup() const;
     virtual bool selectWordAroundCaret();
-    virtual int printBegin(const WebSize& pageSize);
+    virtual int printBegin(const WebSize& pageSize, int printerDPI,
+                           bool* useBrowserOverlays);
     virtual float printPage(int pageToPrint, WebCanvas*);
     virtual float getPrintPageShrink(int page);
     virtual void printEnd();
diff --git a/WebKit/chromium/src/WebPluginContainerImpl.cpp b/WebKit/chromium/src/WebPluginContainerImpl.cpp
index 051979b..2cdf255 100644
--- a/WebKit/chromium/src/WebPluginContainerImpl.cpp
+++ b/WebKit/chromium/src/WebPluginContainerImpl.cpp
@@ -209,6 +209,36 @@ void WebPluginContainerImpl::setParent(ScrollView* view)
         reportGeometry();
 }
 
+bool WebPluginContainerImpl::supportsPaginatedPrint() const
+{
+    return m_webPlugin->supportsPaginatedPrint();
+}
+
+int WebPluginContainerImpl::printBegin(const IntRect& printableArea,
+                                       int printerDPI) const
+{
+    return m_webPlugin->printBegin(printableArea, printerDPI);
+}
+
+bool WebPluginContainerImpl::printPage(int pageNumber,
+                                       WebCore::GraphicsContext* gc)
+{
+    gc->save();
+#if WEBKIT_USING_SKIA
+    WebCanvas* canvas = gc->platformContext()->canvas();
+#elif WEBKIT_USING_CG
+    WebCanvas* canvas = gc->platformContext();
+#endif
+    bool ret = m_webPlugin->printPage(pageNumber, canvas);
+    gc->restore();
+    return ret;
+}
+
+void WebPluginContainerImpl::printEnd()
+{
+    return m_webPlugin->printEnd();
+}
+
 void WebPluginContainerImpl::invalidate()
 {
     Widget::invalidate();
diff --git a/WebKit/chromium/src/WebPluginContainerImpl.h b/WebKit/chromium/src/WebPluginContainerImpl.h
index 890098c..3160394 100644
--- a/WebKit/chromium/src/WebPluginContainerImpl.h
+++ b/WebKit/chromium/src/WebPluginContainerImpl.h
@@ -85,6 +85,20 @@ public:
     virtual WebString executeScriptURL(const WebURL&, bool popupsAllowed);
     virtual void loadFrameRequest(const WebURLRequest&, const WebString& target, bool notifyNeeded, void* notifyData);
 
+    // Printing interface. The plugin can support custom printing
+    // (which means it controls the layout, number of pages etc).
+    // Whether the plugin supports its own paginated print. The other print
+    // interface methods are called only if this method returns true.
+    bool supportsPaginatedPrint() 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;
+    // Prints the page specified by pageNumber (0-based index) into the supplied canvas.
+    bool printPage(int pageNumber, WebCore::GraphicsContext* gc);
+    // Ends the print operation.
+    void printEnd();
+
     // Resource load events for the plugin's source data:
     void didReceiveResponse(const WebCore::ResourceResponse&);
     void didReceiveData(const char *data, int dataLength);

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list