[SCM] WebKit Debian packaging branch, webkit-1.3, updated. upstream/1.3.7-4207-g178b198

ap at apple.com ap at apple.com
Sun Feb 20 23:06:50 UTC 2011


The following commit has been merged in the webkit-1.3 branch:
commit 2320483d3657e052e5d18e112a65b6a6bd9f6534
Author: ap at apple.com <ap at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Jan 17 18:31:12 2011 +0000

            Reviewed by Dan Bernstein.
    
            https://bugs.webkit.org/show_bug.cgi?id=52495
    
            No change in behavior, so no tests.
    
            * WebCore.exp.in: Export additional methods, as I'm going to use more code from PrintContext.
    
            * page/PrintContext.cpp:
            (WebCore::PrintContext::~PrintContext): No need to clear m_pageRects, the object is being
            destroyed already.
            (WebCore::PrintContext::pageCount): Changed page count from int to size_t.
            (WebCore::PrintContext::pageRect): Ditto.
            (WebCore::PrintContext::computePageRects): Pass allowHorizontalTiling as an argument.
            PrintContext already has code to calculate scale factor, so it makes sense to make methods
            that contain it universal (allowHorizontalTiling is always true for Safari).
            Round page height to an integer, because Mac code does that, and because page height is
            treated as integer almost everywhere else in code.
            (WebCore::PrintContext::begin): Allow calling this function multiple times. There is no need
            to return to screen mode if e.g. "print backgounds" option changes.
            (WebCore::PrintContext::computeAutomaticScaleFactor): Expose scale factor computation, so
            that clients don't have to copy it.
            (WebCore::PrintContext::spoolRect): Add a way to spool a precomputed rect - handy if a request
            comes from code that doesn't have page number.
            (WebCore::PrintContext::pageNumberForElement): Page number int -> size_t.
    
            * page/PrintContext.h: Added comments and FIXMEs. PrintContext needs cleanup, but that
            depends on deciding how it really needs to work (e.g. whether computePageRects() should
            cause relayout).
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75955 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index b0d97df..2a3a6fa 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,35 @@
+2011-01-17  Alexey Proskuryakov  <ap at apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        https://bugs.webkit.org/show_bug.cgi?id=52495
+
+        No change in behavior, so no tests.
+
+        * WebCore.exp.in: Export additional methods, as I'm going to use more code from PrintContext.
+
+        * page/PrintContext.cpp:
+        (WebCore::PrintContext::~PrintContext): No need to clear m_pageRects, the object is being
+        destroyed already.
+        (WebCore::PrintContext::pageCount): Changed page count from int to size_t.
+        (WebCore::PrintContext::pageRect): Ditto.
+        (WebCore::PrintContext::computePageRects): Pass allowHorizontalTiling as an argument.
+        PrintContext already has code to calculate scale factor, so it makes sense to make methods
+        that contain it universal (allowHorizontalTiling is always true for Safari).
+        Round page height to an integer, because Mac code does that, and because page height is
+        treated as integer almost everywhere else in code.
+        (WebCore::PrintContext::begin): Allow calling this function multiple times. There is no need
+        to return to screen mode if e.g. "print backgounds" option changes.
+        (WebCore::PrintContext::computeAutomaticScaleFactor): Expose scale factor computation, so
+        that clients don't have to copy it.
+        (WebCore::PrintContext::spoolRect): Add a way to spool a precomputed rect - handy if a request
+        comes from code that doesn't have page number.
+        (WebCore::PrintContext::pageNumberForElement): Page number int -> size_t.
+
+        * page/PrintContext.h: Added comments and FIXMEs. PrintContext needs cleanup, but that
+        depends on deciding how it really needs to work (e.g. whether computePageRects() should
+        cause relayout).
+
 2011-01-17  Pavel Feldman  <pfeldman at chromium.org>
 
         Reviewed by Yury Semikhatsky.
diff --git a/Source/WebCore/WebCore.exp.in b/Source/WebCore/WebCore.exp.in
index cac7485..f3a4bc4 100644
--- a/Source/WebCore/WebCore.exp.in
+++ b/Source/WebCore/WebCore.exp.in
@@ -262,11 +262,17 @@ __ZN7WebCore12IconDatabase9setClientEPNS_18IconDatabaseClientE
 __ZN7WebCore12PopupMenuMacC1EPNS_15PopupMenuClientE
 __ZN7WebCore12PrintContext12pagePropertyEPNS_5FrameEPKci
 __ZN7WebCore12PrintContext13numberOfPagesEPNS_5FrameERKNS_9FloatSizeE
+__ZN7WebCore12PrintContext16computePageRectsERKNS_9FloatRectEfffRfb
 __ZN7WebCore12PrintContext16isPageBoxVisibleEPNS_5FrameEi
 __ZN7WebCore12PrintContext20pageNumberForElementEPNS_7ElementERKNS_9FloatSizeE
 __ZN7WebCore12PrintContext26pageSizeAndMarginsInPixelsEPNS_5FrameEiiiiiii
+__ZN7WebCore12PrintContext27computeAutomaticScaleFactorEf
 __ZN7WebCore12PrintContext27spoolAllPagesWithBoundariesEPNS_5FrameERNS_15GraphicsContextERKNS_9FloatSizeE
 __ZN7WebCore12PrintContext28computePageRectsWithPageSizeERKNS_9FloatSizeEb
+__ZN7WebCore12PrintContext3endEv
+__ZN7WebCore12PrintContext5beginEff
+__ZN7WebCore12PrintContext9spoolPageERNS_15GraphicsContextEif
+__ZN7WebCore12PrintContext9spoolRectERNS_15GraphicsContextERKNS_7IntRectE
 __ZN7WebCore12PrintContextC1EPNS_5FrameE
 __ZN7WebCore12PrintContextD1Ev
 __ZN7WebCore12RenderObject16repaintRectangleERKNS_7IntRectEb
diff --git a/Source/WebCore/page/PrintContext.cpp b/Source/WebCore/page/PrintContext.cpp
index f051ead..d322c29 100644
--- a/Source/WebCore/page/PrintContext.cpp
+++ b/Source/WebCore/page/PrintContext.cpp
@@ -28,10 +28,21 @@
 #include "RenderView.h"
 #include <wtf/text/StringConcatenate.h>
 
-using namespace WebCore;
-
 namespace WebCore {
 
+// By imaging to a width a little wider than the available pixels,
+// thin pages will be scaled down a little, matching the way they
+// print in IE and Camino. This lets them use fewer sheets than they
+// would otherwise, which is presumably why other browsers do this.
+// Wide pages will be scaled down more than this.
+const float printingMinimumShrinkFactor = 1.25;
+
+// This number determines how small we are willing to reduce the page content
+// in order to accommodate the widest line. If the page would have to be
+// reduced smaller to make the widest line fit, we just clip instead (this
+// behavior matches MacIE and Mozilla, at least)
+const float printingMaximumShrinkFactor = 2;
+
 PrintContext::PrintContext(Frame* frame)
     : m_frame(frame)
     , m_isPrinting(false)
@@ -42,20 +53,19 @@ PrintContext::~PrintContext()
 {
     if (m_isPrinting)
         end();
-    m_pageRects.clear();
 }
 
-int PrintContext::pageCount() const
+size_t PrintContext::pageCount() const
 {
     return m_pageRects.size();
 }
 
-const IntRect& PrintContext::pageRect(int pageNumber) const
+const IntRect& PrintContext::pageRect(size_t pageNumber) const
 {
     return m_pageRects[pageNumber];
 }
 
-void PrintContext::computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight)
+void PrintContext::computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight, bool allowHorizontalTiling)
 {
     m_pageRects.clear();
     outPageHeight = 0;
@@ -73,7 +83,7 @@ void PrintContext::computePageRects(const FloatRect& printRect, float headerHeig
     float ratio = printRect.height() / printRect.width();
 
     float pageWidth  = view->docWidth();
-    float pageHeight = pageWidth * ratio;
+    float pageHeight = floorf(pageWidth * ratio);
     outPageHeight = pageHeight; // this is the height of the page adjusted by margins
     pageHeight -= headerHeight + footerHeight;
 
@@ -82,16 +92,16 @@ void PrintContext::computePageRects(const FloatRect& printRect, float headerHeig
         return;
     }
 
-    computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor), false);
+    computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor), allowHorizontalTiling);
 }
 
-void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages)
+void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling)
 {
     m_pageRects.clear();
-    computePageRectsWithPageSizeInternal(pageSizeInPixels, allowHorizontalMultiPages);
+    computePageRectsWithPageSizeInternal(pageSizeInPixels, allowHorizontalTiling);
 }
 
-void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages)
+void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling)
 {
     if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderer())
         return;
@@ -105,7 +115,7 @@ void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSiz
 
     unsigned pageCount = ceilf((float)docRect.height() / pageHeight);
     for (unsigned i = 0; i < pageCount; ++i) {
-        if (allowHorizontalMultiPages) {
+        if (allowHorizontalTiling) {
             for (int currentX = docRect.x(); currentX < docRect.right(); currentX += pageWidth)
                 m_pageRects.append(IntRect(currentX, docRect.y() + i * pageHeight, pageWidth, pageHeight));
         } else
@@ -115,28 +125,28 @@ void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSiz
 
 void PrintContext::begin(float width, float height)
 {
-    ASSERT(!m_isPrinting);
+    // This function can be called multiple times to adjust printing parameters without going back to screen mode.
     m_isPrinting = true;
 
-    // By imaging to a width a little wider than the available pixels,
-    // thin pages will be scaled down a little, matching the way they
-    // print in IE and Camino. This lets them use fewer sheets than they
-    // would otherwise, which is presumably why other browsers do this.
-    // Wide pages will be scaled down more than this.
-    const float PrintingMinimumShrinkFactor = 1.25f;
-
-    // This number determines how small we are willing to reduce the page content
-    // in order to accommodate the widest line. If the page would have to be
-    // reduced smaller to make the widest line fit, we just clip instead (this
-    // behavior matches MacIE and Mozilla, at least)
-    const float PrintingMaximumShrinkFactor = 2.0f;
-
-    float minLayoutWidth = width * PrintingMinimumShrinkFactor;
-    float minLayoutHeight = height * PrintingMinimumShrinkFactor;
-
-    // FIXME: This will modify the rendering of the on-screen frame.
-    // Could lead to flicker during printing.
-    m_frame->setPrinting(true, FloatSize(minLayoutWidth, minLayoutHeight), PrintingMaximumShrinkFactor / PrintingMinimumShrinkFactor, Frame::AdjustViewSize);
+    float minLayoutWidth = width * printingMinimumShrinkFactor;
+    float minLayoutHeight = height * printingMinimumShrinkFactor;
+
+    // This changes layout, so callers need to make sure that they don't paint to screen while in printing mode.
+    m_frame->setPrinting(true, FloatSize(minLayoutWidth, minLayoutHeight), printingMaximumShrinkFactor / printingMinimumShrinkFactor, Frame::AdjustViewSize);
+}
+
+float PrintContext::computeAutomaticScaleFactor(float availablePaperWidth)
+{
+    if (!m_frame->view())
+        return 1;
+
+    float viewWidth = m_frame->view()->contentsWidth();
+    if (viewWidth < 1)
+        return 1;
+
+    float maxShrinkToFitScaleFactor = 1 / printingMaximumShrinkFactor;
+    float shrinkToFitScaleFactor = availablePaperWidth / viewWidth;
+    return max(maxShrinkToFitScaleFactor, shrinkToFitScaleFactor);
 }
 
 void PrintContext::spoolPage(GraphicsContext& ctx, int pageNumber, float width)
@@ -152,6 +162,16 @@ void PrintContext::spoolPage(GraphicsContext& ctx, int pageNumber, float width)
     ctx.restore();
 }
 
+void PrintContext::spoolRect(GraphicsContext& ctx, const IntRect& rect)
+{
+    ctx.save();
+    ctx.scale(FloatSize(1, -1));
+    ctx.translate(0, -rect.height());
+    ctx.clip(rect);
+    m_frame->view()->paintContents(&ctx, rect);
+    ctx.restore();
+}
+
 void PrintContext::end()
 {
     ASSERT(m_isPrinting);
@@ -189,7 +209,7 @@ int PrintContext::pageNumberForElement(Element* element, const FloatSize& pageSi
 
     int top = box->offsetTop();
     int left = box->offsetLeft();
-    int pageNumber = 0;
+    size_t pageNumber = 0;
     for (; pageNumber < printContext.pageCount(); pageNumber++) {
         const IntRect& page = printContext.pageRect(pageNumber);
         if (page.x() <= left && left < page.right() && page.y() <= top && top < page.bottom())
diff --git a/Source/WebCore/page/PrintContext.h b/Source/WebCore/page/PrintContext.h
index ceda892..ce2554a 100644
--- a/Source/WebCore/page/PrintContext.h
+++ b/Source/WebCore/page/PrintContext.h
@@ -38,23 +38,38 @@ public:
     PrintContext(Frame*);
     ~PrintContext();
 
-    int pageCount() const;
-    const IntRect& pageRect(int pageNumber) const;
+    Frame* frame() const { return m_frame; }
+
+    // Break up a page into rects without relayout.
+    // FIXME: This means that CSS page breaks won't be on page boundary if the size is different than what was passed to begin(). That's probably not always desirable.
+    // FIXME: Header and footer height should be applied before layout, not after.
+    // FIXME: The printRect argument is only used to determine page aspect ratio, it would be better to pass a FloatSize with page dimensions instead.
+    void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight, bool allowHorizontalTiling = false);
+
+    // Deprecated. Page size computation is already in this class, clients shouldn't be copying it.
+    void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling);
+
+    // These are only valid after page rects are computed.
+    size_t pageCount() const;
+    const IntRect& pageRect(size_t pageNumber) const;
     const Vector<IntRect>& pageRects() const { return m_pageRects; }
 
-    void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight);
-    void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages);
+    float computeAutomaticScaleFactor(float availablePaperWidth);
 
-    // TODO: eliminate width param
+    // Enter print mode, updating layout for new page size.
+    // This function can be called multiple times to apply new print options without going back to screen mode.
     void begin(float width, float height = 0);
 
-    // TODO: eliminate width param
+    // FIXME: eliminate width argument.
     void spoolPage(GraphicsContext& ctx, int pageNumber, float width);
 
+    void spoolRect(GraphicsContext& ctx, const IntRect&);
+
+    // Return to screen mode.
     void end();
 
     // Used by layout tests.
-    static int pageNumberForElement(Element*, const FloatSize& pageSizeInPixels);
+    static int pageNumberForElement(Element*, const FloatSize& pageSizeInPixels); // Returns -1 if page isn't found.
     static String pageProperty(Frame* frame, const char* propertyName, int pageNumber);
     static bool isPageBoxVisible(Frame* frame, int pageNumber);
     static String pageSizeAndMarginsInPixels(Frame* frame, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
@@ -69,7 +84,7 @@ protected:
     Vector<IntRect> m_pageRects;
 
 private:
-    void computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages);
+    void computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling);
 
     // Used to prevent misuses of begin() and end() (e.g., call end without begin).
     bool m_isPrinting;
diff --git a/Source/WebKit/qt/Api/qwebframe.cpp b/Source/WebKit/qt/Api/qwebframe.cpp
index 701cfe0..9c89a4c 100644
--- a/Source/WebKit/qt/Api/qwebframe.cpp
+++ b/Source/WebKit/qt/Api/qwebframe.cpp
@@ -1454,7 +1454,7 @@ void QWebFrame::print(QPrinter *printer) const
     }
     // paranoia check
     fromPage = qMax(1, fromPage);
-    toPage = qMin(printContext.pageCount(), toPage);
+    toPage = qMin(static_cast<int>(printContext.pageCount()), toPage);
     if (toPage < fromPage) {
         // if the user entered a page range outside the actual number
         // of printable pages, just return
diff --git a/Source/WebKit/qt/ChangeLog b/Source/WebKit/qt/ChangeLog
index 7ccb0d4..06fb368 100644
--- a/Source/WebKit/qt/ChangeLog
+++ b/Source/WebKit/qt/ChangeLog
@@ -1,3 +1,10 @@
+2011-01-17  Alexey Proskuryakov  <ap at apple.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=52495
+
+        * Api/qwebframe.cpp: (QWebFrame::print): Avoid breaking the build due to type mismatch.
+        Longer term, this code should be changed to use an unsigned type for page count.
+
 2011-01-17  Yi Shen  <yi.4.shen at nokia.com>
 
         Reviewed by Andreas Kling.

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list