Changeset 77257 in webkit


Ignore:
Timestamp:
Feb 1, 2011 10:44:10 AM (13 years ago)
Author:
hyatt@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=46422, make printing and pagination work
with vertical text.

Reviewed by Darin Adler.

../WebCore:

Change printing functions to check writing-mode and properly swap width and height
as needed.

Fix the setScrollOrigin function so that the origin doesn't cause
scroll spasming during printing (this is only partially successful, but it's better
than it was).

Rewrite computePageRects to handle both RTL documents properly as well as vertical
text documents properly.

  • WebCore.exp.in:
  • page/FrameView.cpp:

(WebCore::FrameView::adjustViewSize):
(WebCore::FrameView::forceLayoutForPagination):

  • page/PrintContext.cpp:

(WebCore::PrintContext::computePageRects):
(WebCore::PrintContext::computePageRectsWithPageSizeInternal):
(WebCore::PrintContext::computeAutomaticScaleFactor):
(WebCore::PrintContext::spoolPage):
(WebCore::PrintContext::spoolRect):

  • page/PrintContext.h:
  • page/mac/WebCoreFrameView.h:
  • platform/ScrollView.cpp:

(WebCore::ScrollView::wheelEvent):

  • platform/ScrollView.h:
  • platform/mac/ScrollViewMac.mm:

(WebCore::ScrollView::platformSetScrollOrigin):

  • rendering/RenderView.cpp:

(WebCore::RenderView::layout):

../WebKit/mac:

Change printing functions to check writing-mode and properly swap width and height
as needed.

  • WebView/WebDynamicScrollBarsView.mm:

(-[WebDynamicScrollBarsView setScrollOrigin:updatePositionAtAll:immediately:]):

  • WebView/WebFrame.mm:

(-[WebFrame _computePageRectsWithPrintScaleFactor:pageSize:]):

  • WebView/WebFrameInternal.h:
  • WebView/WebHTMLView.mm:

(-[WebHTMLView _web_setPrintingModeRecursive]):
(-[WebHTMLView _web_clearPrintingModeRecursive]):
(-[WebHTMLView _web_setPrintingModeRecursiveAndAdjustViewSize]):
(-[WebHTMLView _beginPrintModeWithMinimumPageWidth:height:maximumPageWidth:]):
(-[WebHTMLView _beginPrintModeWithPageWidth:height:shrinkToFit:]):
(-[WebHTMLView _endPrintMode]):
(-[WebHTMLView _beginScreenPaginationModeWithPageSize:shrinkToFit:]):
(-[WebHTMLView _endScreenPaginationMode]):
(-[WebHTMLView layoutToMinimumPageWidth:height:maximumPageWidth:adjustingViewSize:]):
(-[WebHTMLView _setPrinting:minimumPageLogicalWidth:logicalHeight:maximumPageLogicalWidth:adjustViewSize:paginateScreenContent:]):
(-[WebHTMLView adjustPageHeightNew:top:bottom:limit:]):
(-[WebHTMLView _scaleFactorForPrintOperation:]):
(-[WebHTMLView setPageWidthForPrinting:]):
(-[WebHTMLView knowsPageRange:]):

../WebKit2:

Change printing functions to check writing-mode and properly swap width and height
as needed.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::computePagesForPrinting):

Location:
trunk/Source
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r77254 r77257  
     12011-02-01  Dave Hyatt  <hyatt@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=46422, make printing and pagination work
     6        with vertical text.
     7
     8        Change printing functions to check writing-mode and properly swap width and height
     9        as needed.
     10       
     11        Fix the setScrollOrigin function so that the origin doesn't cause
     12        scroll spasming during printing (this is only partially successful, but it's better
     13        than it was).
     14
     15        Rewrite computePageRects to handle both RTL documents properly as well as vertical
     16        text documents properly.
     17
     18        * WebCore.exp.in:
     19        * page/FrameView.cpp:
     20        (WebCore::FrameView::adjustViewSize):
     21        (WebCore::FrameView::forceLayoutForPagination):
     22        * page/PrintContext.cpp:
     23        (WebCore::PrintContext::computePageRects):
     24        (WebCore::PrintContext::computePageRectsWithPageSizeInternal):
     25        (WebCore::PrintContext::computeAutomaticScaleFactor):
     26        (WebCore::PrintContext::spoolPage):
     27        (WebCore::PrintContext::spoolRect):
     28        * page/PrintContext.h:
     29        * page/mac/WebCoreFrameView.h:
     30        * platform/ScrollView.cpp:
     31        (WebCore::ScrollView::wheelEvent):
     32        * platform/ScrollView.h:
     33        * platform/mac/ScrollViewMac.mm:
     34        (WebCore::ScrollView::platformSetScrollOrigin):
     35        * rendering/RenderView.cpp:
     36        (WebCore::RenderView::layout):
     37
    1382011-02-01  Mikhail Naganov  <mnaganov@chromium.org>
    239
  • trunk/Source/WebCore/WebCore.exp.in

    r77220 r77257  
    267267__ZN7WebCore12PrintContext20pageNumberForElementEPNS_7ElementERKNS_9FloatSizeE
    268268__ZN7WebCore12PrintContext26pageSizeAndMarginsInPixelsEPNS_5FrameEiiiiiii
    269 __ZN7WebCore12PrintContext27computeAutomaticScaleFactorEf
     269__ZN7WebCore12PrintContext27computeAutomaticScaleFactorERKNS_9FloatSizeE
    270270__ZN7WebCore12PrintContext27spoolAllPagesWithBoundariesEPNS_5FrameERNS_15GraphicsContextERKNS_9FloatSizeE
    271271__ZN7WebCore12PrintContext28computePageRectsWithPageSizeERKNS_9FloatSizeEb
     
    12221222__ZTVN7WebCore17FrameLoaderClientE
    12231223__ZTVN7WebCore25HistoryPropertyListWriterE
     1224__ZNK7WebCore12RenderObject4viewEv
     1225__ZNK7WebCore10RenderView7docLeftEv
     1226__ZNK7WebCore10RenderView6docTopEv
     1227__ZNK7WebCore10RenderView8docRightEv
     1228__ZNK7WebCore10RenderView9docBottomEv
     1229__ZNK7WebCore8Document10renderViewEv
    12241230_filenameByFixingIllegalCharacters
    12251231_hasCaseInsensitiveSubstring
     
    14371443__ZN7WebCore16jsStringSlowCaseEPN3JSC9ExecStateERNS0_9WeakGCMapIPN3WTF10StringImplENS0_8JSStringEEES6_
    14381444__ZN7WebCore17HTMLPlugInElement11getNPObjectEv
    1439 __ZNK7WebCore12RenderObject4viewEv
    14401445__ZNK7WebCore14SecurityOrigin9canAccessEPKS0_
    14411446__ZNK7WebCore4KURL10protocolIsEPKc
  • trunk/Source/WebCore/page/FrameView.cpp

    r76872 r77257  
    454454    IntSize size = IntSize(root->docWidth(), root->docHeight());
    455455
    456     ScrollView::setScrollOrigin(IntPoint(-root->docLeft(), -root->docTop()), size == contentsSize());
     456    ScrollView::setScrollOrigin(IntPoint(-root->docLeft(), -root->docTop()), !m_frame->document()->printing(), size == contentsSize());
    457457   
    458458    setContentsSize(size);
     
    22782278    RenderView *root = toRenderView(m_frame->document()->renderer());
    22792279    if (root) {
    2280         int pageW = ceilf(pageSize.width());
    2281         root->setWidth(pageW);
    2282         root->setPageLogicalHeight(pageSize.height());
     2280        float pageLogicalWidth = root->style()->isHorizontalWritingMode() ? pageSize.width() : pageSize.height();
     2281        float pageLogicalHeight = root->style()->isHorizontalWritingMode() ? pageSize.height() : pageSize.width();
     2282
     2283        int flooredPageLogicalWidth = static_cast<int>(pageLogicalWidth);
     2284        root->setLogicalWidth(flooredPageLogicalWidth);
     2285        root->setPageLogicalHeight(pageLogicalHeight);
    22832286        root->setNeedsLayoutAndPrefWidthsRecalc();
    22842287        forceLayout();
    2285 
     2288       
    22862289        // If we don't fit in the given page width, we'll lay out again. If we don't fit in the
    22872290        // page width when shrunk, we will lay out at maximum shrink and clip extra content.
    22882291        // FIXME: We are assuming a shrink-to-fit printing implementation.  A cropping
    22892292        // implementation should not do this!
    2290         int docWidth = root->docWidth();
    2291         if (docWidth > pageSize.width()) {
    2292             pageW = std::min<int>(docWidth, ceilf(pageSize.width() * maximumShrinkFactor));
    2293             if (pageSize.height())
    2294                 root->setPageLogicalHeight(pageW / pageSize.width() * pageSize.height());
    2295             root->setWidth(pageW);
     2293        int docLogicalWidth = root->style()->isHorizontalWritingMode() ? root->docWidth() : root->docHeight();
     2294        if (docLogicalWidth > pageLogicalWidth) {
     2295            flooredPageLogicalWidth = std::min<int>(docLogicalWidth, pageLogicalWidth * maximumShrinkFactor);
     2296            if (pageLogicalHeight)
     2297                root->setPageLogicalHeight(flooredPageLogicalWidth / pageSize.width() * pageSize.height());
     2298            root->setLogicalWidth(flooredPageLogicalWidth);
    22962299            root->setNeedsLayoutAndPrefWidthsRecalc();
    22972300            forceLayout();
    2298             int docHeight = root->docHeight();
    22992301            root->clearLayoutOverflow();
    2300             root->addLayoutOverflow(IntRect(0, 0, pageW, docHeight)); // This is how we clip in case we overflow again.
     2302            int docLogicalHeight = root->style()->isHorizontalWritingMode() ? root->docHeight() : root->docWidth();
     2303            int docLogicalTop = root->style()->isHorizontalWritingMode() ? root->docTop() : root->docLeft();
     2304            int docLogicalRight = root->style()->isHorizontalWritingMode() ? root->docRight() : root->docBottom();
     2305            int clippedLogicalLeft = 0;
     2306            if (!root->style()->isLeftToRightDirection())
     2307                clippedLogicalLeft = docLogicalRight - flooredPageLogicalWidth;
     2308            IntRect overflow(clippedLogicalLeft, docLogicalTop, flooredPageLogicalWidth, docLogicalHeight);
     2309            if (!root->style()->isHorizontalWritingMode())
     2310                overflow = overflow.transposedRect();
     2311            root->addLayoutOverflow(overflow); // This is how we clip in case we overflow again.
    23012312        }
    23022313    }
  • trunk/Source/WebCore/page/PrintContext.cpp

    r76821 r77257  
    8181    RenderView* view = toRenderView(m_frame->document()->renderer());
    8282
    83     float ratio = printRect.height() / printRect.width();
    84 
    85     float pageWidth  = view->docWidth();
    86     float pageHeight = floorf(pageWidth * ratio);
     83    bool isHorizontal = view->style()->isHorizontalWritingMode();
     84
     85    float pageWidth;
     86    float pageHeight;
     87    if (isHorizontal) {
     88        float ratio = printRect.height() / printRect.width();
     89        pageWidth = view->docWidth();
     90        pageHeight = floorf(pageWidth * ratio);
     91    } else {
     92        float ratio = printRect.width() / printRect.height();
     93        pageHeight = view->docHeight();
     94        pageWidth = floorf(pageHeight * ratio);
     95    }
     96
    8797    outPageHeight = pageHeight; // this is the height of the page adjusted by margins
    8898    pageHeight -= headerHeight + footerHeight;
     
    102112}
    103113
    104 void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling)
     114void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowInlineDirectionTiling)
    105115{
    106116    if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderer())
     
    114124    int pageHeight = pageSizeInPixels.height();
    115125
    116     unsigned pageCount = ceilf((float)docRect.height() / pageHeight);
     126    bool isHorizontal = view->style()->isHorizontalWritingMode();
     127
     128    int docLogicalHeight = isHorizontal ? docRect.height() : docRect.width();
     129    int pageLogicalHeight = isHorizontal ? pageHeight : pageWidth;
     130    int pageLogicalWidth = isHorizontal ? pageWidth : pageHeight;
     131
     132    int inlineDirectionStart;
     133    int inlineDirectionEnd;
     134    int blockDirectionStart;
     135    int blockDirectionEnd;
     136    if (isHorizontal) {
     137        if (view->style()->isFlippedBlocksWritingMode()) {
     138            blockDirectionStart = docRect.bottom();
     139            blockDirectionEnd = docRect.y();
     140        } else {
     141            blockDirectionStart = docRect.y();
     142            blockDirectionEnd = docRect.bottom();
     143        }
     144        inlineDirectionStart = view->style()->isLeftToRightDirection() ? docRect.x() : docRect.right();
     145        inlineDirectionEnd = view->style()->isLeftToRightDirection() ? docRect.right() : docRect.x();
     146    } else {
     147        if (view->style()->isFlippedBlocksWritingMode()) {
     148            blockDirectionStart = docRect.right();
     149            blockDirectionEnd = docRect.x();
     150        } else {
     151            blockDirectionStart = docRect.x();
     152            blockDirectionEnd = docRect.right();
     153        }
     154        inlineDirectionStart = view->style()->isLeftToRightDirection() ? docRect.y() : docRect.bottom();
     155        inlineDirectionEnd = view->style()->isLeftToRightDirection() ? docRect.bottom() : docRect.y();
     156    }
     157
     158    unsigned pageCount = ceilf((float)docLogicalHeight / pageLogicalHeight);
    117159    for (unsigned i = 0; i < pageCount; ++i) {
    118         if (allowHorizontalTiling) {
    119             for (int currentX = docRect.x(); currentX < docRect.right(); currentX += pageWidth)
    120                 m_pageRects.append(IntRect(currentX, docRect.y() + i * pageHeight, pageWidth, pageHeight));
    121         } else
    122             m_pageRects.append(IntRect(docRect.x(), docRect.y() + i * pageHeight, pageWidth, pageHeight));
     160        int pageLogicalTop = blockDirectionEnd > blockDirectionStart ?
     161                                blockDirectionStart + i * pageLogicalHeight :
     162                                blockDirectionStart - (i + 1) * pageLogicalHeight;
     163        if (allowInlineDirectionTiling) {
     164            for (int currentInlinePosition = inlineDirectionStart;
     165                 inlineDirectionEnd > inlineDirectionStart ? currentInlinePosition < inlineDirectionEnd : currentInlinePosition > inlineDirectionEnd;
     166                 currentInlinePosition += (inlineDirectionEnd > inlineDirectionStart ? pageLogicalWidth : -pageLogicalWidth)) {
     167                int pageLogicalLeft = inlineDirectionEnd > inlineDirectionStart ? currentInlinePosition : currentInlinePosition - pageLogicalWidth;
     168                IntRect pageRect(pageLogicalLeft, pageLogicalTop, pageLogicalWidth, pageLogicalHeight);
     169                if (!isHorizontal)
     170                    pageRect = pageRect.transposedRect();
     171                m_pageRects.append(pageRect);
     172            }
     173        } else {
     174            int pageLogicalLeft = inlineDirectionEnd > inlineDirectionStart ? inlineDirectionStart : inlineDirectionStart - pageLogicalWidth;
     175            IntRect pageRect(pageLogicalLeft, pageLogicalTop, pageLogicalWidth, pageLogicalHeight);
     176            if (!isHorizontal)
     177                pageRect = pageRect.transposedRect();
     178            m_pageRects.append(pageRect);
     179        }
    123180    }
    124181}
     
    136193}
    137194
    138 float PrintContext::computeAutomaticScaleFactor(float availablePaperWidth)
     195float PrintContext::computeAutomaticScaleFactor(const FloatSize& availablePaperSize)
    139196{
    140197    if (!m_frame->view())
    141198        return 1;
    142199
    143     float viewWidth = m_frame->view()->contentsWidth();
    144     if (viewWidth < 1)
     200    bool useViewWidth = true;
     201    if (m_frame->document() && m_frame->document()->renderView())
     202        useViewWidth = m_frame->document()->renderView()->style()->isHorizontalWritingMode();
     203
     204    float viewLogicalWidth = useViewWidth ? m_frame->view()->contentsWidth() : m_frame->view()->contentsHeight();
     205    if (viewLogicalWidth < 1)
    145206        return 1;
    146207
    147208    float maxShrinkToFitScaleFactor = 1 / printingMaximumShrinkFactor;
    148     float shrinkToFitScaleFactor = availablePaperWidth / viewWidth;
     209    float shrinkToFitScaleFactor = (useViewWidth ? availablePaperSize.width() : availablePaperSize.height()) / viewLogicalWidth;
    149210    return max(maxShrinkToFitScaleFactor, shrinkToFitScaleFactor);
    150211}
     
    152213void PrintContext::spoolPage(GraphicsContext& ctx, int pageNumber, float width)
    153214{
     215    // FIXME: Not correct for vertical text.
    154216    IntRect pageRect = m_pageRects[pageNumber];
    155217    float scale = width / pageRect.width();
     
    165227void PrintContext::spoolRect(GraphicsContext& ctx, const IntRect& rect)
    166228{
     229    // FIXME: Not correct for vertical text.
    167230    ctx.save();
    168231    ctx.translate(-rect.x(), -rect.y());
  • trunk/Source/WebCore/page/PrintContext.h

    r75955 r77257  
    5555    const Vector<IntRect>& pageRects() const { return m_pageRects; }
    5656
    57     float computeAutomaticScaleFactor(float availablePaperWidth);
     57    float computeAutomaticScaleFactor(const FloatSize& availablePaperSize);
    5858
    5959    // Enter print mode, updating layout for new page size.
  • trunk/Source/WebCore/page/mac/WebCoreFrameView.h

    r73063 r77257  
    3434- (void)scrollingModes:(WebCore::ScrollbarMode*)hMode vertical:(WebCore::ScrollbarMode*)vMode;
    3535- (void)setScrollBarsSuppressed:(BOOL)suppressed repaintOnUnsuppress:(BOOL)repaint;
    36 - (void)setScrollOrigin:(NSPoint)origin updatePosition:(BOOL)updatePosition;
     36- (void)setScrollOrigin:(NSPoint)origin updatePositionAtAll:(BOOL)updatePositionAtAll immediately:(BOOL)updatePositionImmediately;
    3737- (NSPoint)scrollOrigin;
    3838@end
  • trunk/Source/WebCore/platform/ScrollView.cpp

    r76956 r77257  
    10951095}
    10961096
    1097 void ScrollView::setScrollOrigin(const IntPoint& origin, bool updatePosition)
     1097void ScrollView::setScrollOrigin(const IntPoint& origin, bool updatePositionAtAll, bool updatePositionSynchronously)
    10981098{
    10991099    if (m_scrollOrigin == origin)
     
    11031103
    11041104    if (platformWidget()) {
    1105         platformSetScrollOrigin(origin, updatePosition);
     1105        platformSetScrollOrigin(origin, updatePositionAtAll, updatePositionSynchronously);
    11061106        return;
    11071107    }
    11081108   
    11091109    // Update if the scroll origin changes, since our position will be different if the content size did not change.
    1110     if (updatePosition)
     1110    if (updatePositionAtAll && updatePositionSynchronously)
    11111111        updateScrollbars(scrollOffset());
    11121112}
     
    11421142}
    11431143
    1144 void ScrollView::platformSetScrollOrigin(const IntPoint&, bool updatePosition)
     1144void ScrollView::platformSetScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updatePositionSynchronously)
    11451145{
    11461146}
  • trunk/Source/WebCore/platform/ScrollView.h

    r76956 r77257  
    297297    virtual void scrollContentsSlowPath(const IntRect& updateRect);
    298298
    299     void setScrollOrigin(const IntPoint&, bool updatePosition);
     299    void setScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updatePositionSynchronously);
    300300    IntPoint scrollOrigin() { return m_scrollOrigin; }
    301301
     
    384384    bool platformIsOffscreen() const;
    385385   
    386     void platformSetScrollOrigin(const IntPoint&, bool updatePosition);
     386    void platformSetScrollOrigin(const IntPoint&, bool updatePositionAtAll, bool updatePositionSynchronously);
    387387
    388388#if PLATFORM(MAC) && defined __OBJC__
  • trunk/Source/WebCore/platform/mac/ScrollViewMac.mm

    r73063 r77257  
    204204}
    205205
    206 void ScrollView::platformSetScrollOrigin(const IntPoint& origin, bool updatePosition)
    207 {
    208     BEGIN_BLOCK_OBJC_EXCEPTIONS;
    209     [scrollView() setScrollOrigin:origin updatePosition:updatePosition];
     206void ScrollView::platformSetScrollOrigin(const IntPoint& origin, bool updatePositionAtAll, bool updatePositionSynchronously)
     207{
     208    BEGIN_BLOCK_OBJC_EXCEPTIONS;
     209    [scrollView() setScrollOrigin:origin updatePositionAtAll:updatePositionAtAll immediately:updatePositionSynchronously];
    210210    END_BLOCK_OBJC_EXCEPTIONS;
    211211}
  • trunk/Source/WebCore/rendering/RenderView.cpp

    r75892 r77257  
    106106
    107107    if (printing())
    108         m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = width();
     108        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = logicalWidth();
    109109
    110110    // Use calcWidth/Height to get the new width/height, since this will take the full page zoom factor into account.
  • trunk/Source/WebKit/mac/ChangeLog

    r77151 r77257  
     12011-02-01  Dave Hyatt  <hyatt@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=46422, make printing and pagination work
     6        with vertical text.
     7
     8        Change printing functions to check writing-mode and properly swap width and height
     9        as needed.
     10
     11        * WebView/WebDynamicScrollBarsView.mm:
     12        (-[WebDynamicScrollBarsView setScrollOrigin:updatePositionAtAll:immediately:]):
     13        * WebView/WebFrame.mm:
     14        (-[WebFrame _computePageRectsWithPrintScaleFactor:pageSize:]):
     15        * WebView/WebFrameInternal.h:
     16        * WebView/WebHTMLView.mm:
     17        (-[WebHTMLView _web_setPrintingModeRecursive]):
     18        (-[WebHTMLView _web_clearPrintingModeRecursive]):
     19        (-[WebHTMLView _web_setPrintingModeRecursiveAndAdjustViewSize]):
     20        (-[WebHTMLView _beginPrintModeWithMinimumPageWidth:height:maximumPageWidth:]):
     21        (-[WebHTMLView _beginPrintModeWithPageWidth:height:shrinkToFit:]):
     22        (-[WebHTMLView _endPrintMode]):
     23        (-[WebHTMLView _beginScreenPaginationModeWithPageSize:shrinkToFit:]):
     24        (-[WebHTMLView _endScreenPaginationMode]):
     25        (-[WebHTMLView layoutToMinimumPageWidth:height:maximumPageWidth:adjustingViewSize:]):
     26        (-[WebHTMLView _setPrinting:minimumPageLogicalWidth:logicalHeight:maximumPageLogicalWidth:adjustViewSize:paginateScreenContent:]):
     27        (-[WebHTMLView adjustPageHeightNew:top:bottom:limit:]):
     28        (-[WebHTMLView _scaleFactorForPrintOperation:]):
     29        (-[WebHTMLView setPageWidthForPrinting:]):
     30        (-[WebHTMLView knowsPageRange:]):
     31
    1322011-01-31  Oliver Hunt  <oliver@apple.com>
    233
  • trunk/Source/WebKit/mac/WebView/WebDynamicScrollBarsView.mm

    r76044 r77257  
    569569}
    570570
    571 - (void)setScrollOrigin:(NSPoint)scrollOrigin updatePosition:(BOOL)updatePosition
     571- (void)setScrollOrigin:(NSPoint)scrollOrigin updatePositionAtAll:(BOOL)updatePositionAtAll immediately:(BOOL)updatePositionSynchronously
    572572{
    573573    // The cross-platform ScrollView call already checked to see if the old/new scroll origins were the same or not
     
    580580    [docView setBoundsOrigin:NSMakePoint(-scrollOrigin.x, -scrollOrigin.y)];
    581581
    582     _private->scrollOriginChanged = true;
     582    if (updatePositionAtAll)
     583        _private->scrollOriginChanged = true;
    583584
    584585    // Maintain our original position in the presence of the new scroll origin.
    585586    _private->scrollPositionExcludingOrigin = NSMakePoint(visibleRect.origin.x + scrollOrigin.x, visibleRect.origin.y + scrollOrigin.y);
    586587
    587     if (updatePosition) // Otherwise we'll just let the snap happen when we update for the resize.
     588    if (updatePositionAtAll && updatePositionSynchronously) // Otherwise we'll just let the snap happen when we update for the resize.
    588589        [self adjustForScrollOriginChange];
    589590}
  • trunk/Source/WebKit/mac/WebView/WebFrame.mm

    r76107 r77257  
    588588
    589589// Used by pagination code called from AppKit when a standalone web page is printed.
    590 - (NSArray*)_computePageRectsWithPrintWidthScaleFactor:(float)printWidthScaleFactor printHeight:(float)printHeight
     590- (NSArray*)_computePageRectsWithPrintScaleFactor:(float)printScaleFactor pageSize:(NSSize)pageSize
    591591{
    592592    NSMutableArray* pages = [NSMutableArray arrayWithCapacity:5];
    593     if (printWidthScaleFactor <= 0) {
    594         LOG_ERROR("printWidthScaleFactor has bad value %.2f", printWidthScaleFactor);
    595         return pages;
    596     }
    597    
    598     if (printHeight <= 0) {
    599         LOG_ERROR("printHeight has bad value %.2f", printHeight);
     593    if (printScaleFactor <= 0) {
     594        LOG_ERROR("printScaleFactor has bad value %.2f", printScaleFactor);
    600595        return pages;
    601596    }
     
    613608        return pages;
    614609
    615     float docWidth = root->layer()->width();
    616     float printWidth = docWidth / printWidthScaleFactor;
     610    float docWidth = root->docWidth();
     611    float docHeight = root->docHeight();
     612
     613    float printWidth = root->style()->isHorizontalWritingMode() ? docWidth / printScaleFactor : pageSize.width;
     614    float printHeight = root->style()->isHorizontalWritingMode() ? pageSize.height : docHeight / printScaleFactor;
    617615
    618616    PrintContext printContext(_private->coreFrame);
  • trunk/Source/WebKit/mac/WebView/WebFrameInternal.h

    r75031 r77257  
    125125- (void)_drawRect:(NSRect)rect contentsOnly:(BOOL)contentsOnly;
    126126- (BOOL)_getVisibleRect:(NSRect*)rect;
    127 - (NSArray*)_computePageRectsWithPrintWidthScaleFactor:(float)printWidthScaleFactor printHeight:(float)printHeight;
     127- (NSArray*)_computePageRectsWithPrintScaleFactor:(float)printWidthScaleFactor pageSize:(NSSize)pageSize;
    128128
    129129- (NSString *)_stringByEvaluatingJavaScriptFromString:(NSString *)string;
  • trunk/Source/WebKit/mac/WebView/WebHTMLView.mm

    r76813 r77257  
    105105#import <WebCore/Range.h>
    106106#import <WebCore/RenderWidget.h>
     107#import <WebCore/RenderView.h>
    107108#import <WebCore/RuntimeApplicationChecks.h>
    108109#import <WebCore/SelectionController.h>
     
    429430
    430431@interface WebHTMLView (WebForwardDeclaration) // FIXME: Put this in a normal category and stop doing the forward declaration trick.
    431 - (void)_setPrinting:(BOOL)printing minimumPageWidth:(float)minPageWidth height:(float)minPageHeight maximumPageWidth:(float)maxPageWidth adjustViewSize:(BOOL)adjustViewSize paginateScreenContent:(BOOL)paginateScreenContent;
     432- (void)_setPrinting:(BOOL)printing minimumPageLogicalWidth:(float)minPageWidth logicalHeight:(float)minPageHeight maximumPageLogicalWidth:(float)maxPageWidth adjustViewSize:(BOOL)adjustViewSize paginateScreenContent:(BOOL)paginateScreenContent;
    432433@end
    433434
     
    10811082- (void)_web_setPrintingModeRecursive
    10821083{
    1083     [self _setPrinting:YES minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
     1084    [self _setPrinting:YES minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
    10841085
    10851086#ifndef NDEBUG
     
    10931094    unsigned count = [descendantWebHTMLViews count];
    10941095    for (unsigned i = 0; i < count; ++i)
    1095         [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:YES minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
     1096        [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:YES minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
    10961097
    10971098    [descendantWebHTMLViews release];
     
    11041105- (void)_web_clearPrintingModeRecursive
    11051106{
    1106     [self _setPrinting:NO minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
     1107    [self _setPrinting:NO minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
    11071108
    11081109#ifndef NDEBUG
     
    11161117    unsigned count = [descendantWebHTMLViews count];
    11171118    for (unsigned i = 0; i < count; ++i)
    1118         [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:NO minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
     1119        [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:NO minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
    11191120
    11201121    [descendantWebHTMLViews release];
     
    11271128- (void)_web_setPrintingModeRecursiveAndAdjustViewSize
    11281129{
    1129     [self _setPrinting:YES minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
     1130    [self _setPrinting:YES minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
    11301131
    11311132#ifndef NDEBUG
     
    11391140    unsigned count = [descendantWebHTMLViews count];
    11401141    for (unsigned i = 0; i < count; ++i)
    1141         [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:YES minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
     1142        [[descendantWebHTMLViews objectAtIndex:i] _setPrinting:YES minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
    11421143
    11431144    [descendantWebHTMLViews release];
     
    22022203    }
    22032204
    2204     [self _setPrinting:YES minimumPageWidth:minimumPageWidth height:minimumPageHeight maximumPageWidth:maximumPageWidth adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
     2205    [self _setPrinting:YES minimumPageLogicalWidth:minimumPageWidth logicalHeight:minimumPageHeight maximumPageLogicalWidth:maximumPageWidth adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
    22052206    return YES;
    22062207}
     
    22122213        return NO;
    22132214
    2214     float minLayoutWidth = 0;
    2215     float minLayoutHeight = 0;
    2216     float maxLayoutWidth = 0;
     2215    Document* document = frame->document();
     2216    bool isHorizontal = !document || !document->renderView() || document->renderView()->style()->isHorizontalWritingMode();
     2217
     2218    float minLayoutLogicalWidth = isHorizontal ? pageWidth : pageHeight;
     2219    float minLayoutLogicalHeight = isHorizontal ? pageHeight : pageWidth;
     2220    float maxLayoutLogicalWidth = minLayoutLogicalWidth;
    22172221
    22182222    // If we are a frameset just print with the layout we have onscreen, otherwise relayout
    22192223    // according to the page width.
    2220     if (!frame->document() || !frame->document()->isFrameSet()) {
    2221         minLayoutWidth = shrinkToFit ? pageWidth * _WebHTMLViewPrintingMinimumShrinkFactor : pageWidth;
    2222         minLayoutHeight = shrinkToFit ? pageHeight * _WebHTMLViewPrintingMinimumShrinkFactor : pageHeight;
    2223         maxLayoutWidth = shrinkToFit ? pageWidth * _WebHTMLViewPrintingMaximumShrinkFactor : pageWidth;
    2224     }
    2225     [self _setPrinting:YES minimumPageWidth:minLayoutWidth height:minLayoutHeight maximumPageWidth:maxLayoutWidth adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
     2224    if (shrinkToFit && (!frame->document() || !frame->document()->isFrameSet())) {
     2225        minLayoutLogicalWidth *= _WebHTMLViewPrintingMinimumShrinkFactor;
     2226        minLayoutLogicalHeight *= _WebHTMLViewPrintingMinimumShrinkFactor;
     2227        maxLayoutLogicalWidth *= _WebHTMLViewPrintingMaximumShrinkFactor;
     2228    }
     2229    [self _setPrinting:YES minimumPageLogicalWidth:minLayoutLogicalWidth logicalHeight:minLayoutLogicalHeight maximumPageLogicalWidth:maxLayoutLogicalWidth adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
    22262230
    22272231    return YES;
     
    22302234- (void)_endPrintMode
    22312235{
    2232     [self _setPrinting:NO minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
     2236    [self _setPrinting:NO minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
    22332237}
    22342238
     
    22442248        return NO;
    22452249
    2246     CGFloat minLayoutWidth = 0;
    2247     CGFloat minLayoutHeight = 0;
    2248     CGFloat maxLayoutWidth = 0;
    2249 
    2250     // If we are a frameset just print with the layout we have on the screen. Otherwise do a relayout
     2250    Document* document = frame->document();
     2251    bool isHorizontal = !document || !document->renderView() || document->renderView()->style()->isHorizontalWritingMode();
     2252
     2253    float minLayoutLogicalWidth = isHorizontal ? pageSize.width : pageSize.height;
     2254    float minLayoutLogicalHeight = isHorizontal ? pageSize.height : pageSize.width;
     2255    float maxLayoutLogicalWidth = minLayoutLogicalWidth;
     2256
     2257    // If we are a frameset just print with the layout we have onscreen, otherwise relayout
    22512258    // according to the page width.
    2252     if (!frame->document() || !frame->document()->isFrameSet()) {
    2253         minLayoutWidth = shrinkToFit ? pageSize.width * _WebHTMLViewPrintingMinimumShrinkFactor : pageSize.width;
    2254         minLayoutHeight = shrinkToFit ? pageSize.height * _WebHTMLViewPrintingMinimumShrinkFactor : pageSize.height;
    2255         maxLayoutWidth = shrinkToFit ? pageSize.width * _WebHTMLViewPrintingMaximumShrinkFactor : pageSize.width;
    2256     }
    2257     [self _setPrinting:[self _isInPrintMode] minimumPageWidth:minLayoutWidth height:minLayoutHeight maximumPageWidth:maxLayoutWidth adjustViewSize:YES paginateScreenContent:YES];
     2259    if (shrinkToFit && (!frame->document() || !frame->document()->isFrameSet())) {
     2260        minLayoutLogicalWidth *= _WebHTMLViewPrintingMinimumShrinkFactor;
     2261        minLayoutLogicalHeight *= _WebHTMLViewPrintingMinimumShrinkFactor;
     2262        maxLayoutLogicalWidth *= _WebHTMLViewPrintingMaximumShrinkFactor;
     2263    }
     2264    [self _setPrinting:[self _isInPrintMode] minimumPageLogicalWidth:minLayoutLogicalWidth logicalHeight:minLayoutLogicalHeight maximumPageLogicalWidth:maxLayoutLogicalWidth adjustViewSize:YES paginateScreenContent:YES];
    22582265
    22592266    return YES;
     
    22622269- (void)_endScreenPaginationMode
    22632270{
    2264     [self _setPrinting:[self _isInPrintMode] minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:YES paginateScreenContent:NO];
     2271    [self _setPrinting:[self _isInPrintMode] minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:YES paginateScreenContent:NO];
    22652272}
    22662273
     
    31183125// Do a layout, but set up a new fixed width for the purposes of doing printing layout.
    31193126// minPageWidth==0 implies a non-printing layout
    3120 - (void)layoutToMinimumPageWidth:(float)minPageWidth height:(float)minPageHeight maximumPageWidth:(float)maxPageWidth adjustingViewSize:(BOOL)adjustViewSize
     3127- (void)layoutToMinimumPageWidth:(float)minPageLogicalWidth height:(float)minPageLogicalHeight maximumPageWidth:(float)maxPageLogicalWidth adjustingViewSize:(BOOL)adjustViewSize
    31213128{   
    31223129    if (![self _needsLayout])
     
    31343141
    31353142    if (FrameView* coreView = coreFrame->view()) {
    3136         if (minPageWidth > 0.0)
    3137             coreView->forceLayoutForPagination(FloatSize(minPageWidth, minPageHeight), maxPageWidth / minPageWidth, adjustViewSize ? Frame::AdjustViewSize : Frame::DoNotAdjustViewSize);
    3138         else {
     3143        if (minPageLogicalWidth > 0.0) {
     3144            FloatSize pageSize(minPageLogicalWidth, minPageLogicalHeight);
     3145            if (coreFrame->document() && coreFrame->document()->renderView() && !coreFrame->document()->renderView()->style()->isHorizontalWritingMode())
     3146                pageSize = FloatSize(minPageLogicalHeight, minPageLogicalWidth);
     3147            coreView->forceLayoutForPagination(pageSize, maxPageLogicalWidth / minPageLogicalWidth, adjustViewSize ? Frame::AdjustViewSize : Frame::DoNotAdjustViewSize);
     3148        } else {
    31393149            coreView->forceLayout(!adjustViewSize);
    31403150            if (adjustViewSize)
     
    38783888// Does setNeedsDisplay:NO as a side effect when printing is ending.
    38793889// pageWidth != 0 implies we will relayout to a new width
    3880 - (void)_setPrinting:(BOOL)printing minimumPageWidth:(float)minPageWidth height:(float)minPageHeight maximumPageWidth:(float)maxPageWidth adjustViewSize:(BOOL)adjustViewSize paginateScreenContent:(BOOL)paginateScreenContent
     3890- (void)_setPrinting:(BOOL)printing minimumPageLogicalWidth:(float)minPageLogicalWidth logicalHeight:(float)minPageLogicalHeight maximumPageLogicalWidth:(float)maxPageLogicalWidth adjustViewSize:(BOOL)adjustViewSize paginateScreenContent:(BOOL)paginateScreenContent
    38813891{
    38823892    if (printing == _private->printing && paginateScreenContent == _private->paginateScreenContent)
     
    38913901        WebFrameView *frameView = [subframe frameView];
    38923902        if ([[subframe _dataSource] _isDocumentHTML]) {
    3893             [(WebHTMLView *)[frameView documentView] _setPrinting:printing minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:adjustViewSize paginateScreenContent:paginateScreenContent];
     3903            [(WebHTMLView *)[frameView documentView] _setPrinting:printing minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:adjustViewSize paginateScreenContent:paginateScreenContent];
    38943904        }
    38953905    }
     
    39123922
    39133923    [self setNeedsLayout:YES];
    3914     [self layoutToMinimumPageWidth:minPageWidth height:minPageHeight maximumPageWidth:maxPageWidth adjustingViewSize:adjustViewSize];
     3924    [self layoutToMinimumPageWidth:minPageLogicalWidth height:minPageLogicalHeight maximumPageWidth:maxPageLogicalWidth adjustingViewSize:adjustViewSize];
    39153925    if (!printing) {
    39163926        // Can't do this when starting printing or nested printing won't work, see 3491427.
     
    39323942    BOOL wasInPrintingMode = _private->printing;
    39333943    if (!wasInPrintingMode)
    3934         [self _setPrinting:YES minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
     3944        [self _setPrinting:YES minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
    39353945
    39363946    *newBottom = [self _adjustedBottomOfPageWithTop:oldTop bottom:oldBottom limit:bottomLimit];
     
    39433953        else
    39443954            // not sure if this is actually ever invoked, it probably shouldn't be
    3945             [self _setPrinting:NO minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
     3955            [self _setPrinting:NO minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
    39463956    }
    39473957}
     
    39493959- (float)_scaleFactorForPrintOperation:(NSPrintOperation *)printOperation
    39503960{
    3951     float viewWidth = NSWidth([self bounds]);
    3952     if (viewWidth < 1) {
    3953         LOG_ERROR("%@ has no width when printing", self);
     3961    bool useViewWidth = true;
     3962    Frame* coreFrame = core([self _frame]);
     3963    if (coreFrame) {
     3964        Document* document = coreFrame->document();
     3965        if (document && document->renderView())
     3966            useViewWidth = document->renderView()->style()->isHorizontalWritingMode();
     3967    }
     3968
     3969    float viewLogicalWidth = useViewWidth ? NSWidth([self bounds]) : NSHeight([self bounds]);
     3970    if (viewLogicalWidth < 1) {
     3971        LOG_ERROR("%@ has no logical width when printing", self);
    39543972        return 1.0f;
    39553973    }
     
    39573975    float userScaleFactor = [printOperation _web_pageSetupScaleFactor];
    39583976    float maxShrinkToFitScaleFactor = 1.0f / _WebHTMLViewPrintingMaximumShrinkFactor;
    3959     float shrinkToFitScaleFactor = [printOperation _web_availablePaperWidth] / viewWidth;
     3977    float shrinkToFitScaleFactor = (useViewWidth ? [printOperation _web_availablePaperWidth] :  [printOperation _web_availablePaperHeight]) / viewLogicalWidth;
    39603978    return userScaleFactor * max(maxShrinkToFitScaleFactor, shrinkToFitScaleFactor);
    39613979}
     
    39723990- (void)setPageWidthForPrinting:(float)pageWidth
    39733991{
    3974     [self _setPrinting:NO minimumPageWidth:0 height:0 maximumPageWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
    3975     [self _setPrinting:YES minimumPageWidth:pageWidth height:0 maximumPageWidth:pageWidth adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
     3992    [self _setPrinting:NO minimumPageLogicalWidth:0 logicalHeight:0 maximumPageLogicalWidth:0 adjustViewSize:NO paginateScreenContent:[self _isInScreenPaginationMode]];
     3993    [self _setPrinting:YES minimumPageLogicalWidth:pageWidth logicalHeight:0 maximumPageLogicalWidth:pageWidth adjustViewSize:YES paginateScreenContent:[self _isInScreenPaginationMode]];
    39763994}
    39773995
     
    40374055    float userScaleFactor = [printOperation _web_pageSetupScaleFactor];
    40384056    [_private->pageRects release];
     4057    float fullPageWidth = floorf([printOperation _web_availablePaperWidth] / totalScaleFactor);
    40394058    float fullPageHeight = floorf([printOperation _web_availablePaperHeight] / totalScaleFactor);
    40404059    WebFrame *frame = [self _frame];
    4041     NSArray *newPageRects = [frame _computePageRectsWithPrintWidthScaleFactor:userScaleFactor printHeight:fullPageHeight];
     4060    NSArray *newPageRects = [frame _computePageRectsWithPrintScaleFactor:userScaleFactor pageSize:NSMakeSize(fullPageWidth, fullPageHeight)];
    40424061   
    40434062    // AppKit gets all messed up if you give it a zero-length page count (see 3576334), so if we
  • trunk/Source/WebKit2/ChangeLog

    r77220 r77257  
     12011-02-01  Dave Hyatt  <hyatt@apple.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=46422, make printing and pagination work
     6        with vertical text.
     7
     8        Change printing functions to check writing-mode and properly swap width and height
     9        as needed.
     10
     11        * WebProcess/WebPage/WebPage.cpp:
     12        (WebKit::WebPage::computePagesForPrinting):
     13
    1142011-01-31  Alexey Proskuryakov  <ap@apple.com>
    215
  • trunk/Source/WebKit2/Platform/CoreIPC/Connection.cpp

    r76916 r77257  
    276276    if (messageID == MessageID(CoreIPCMessage::SyncMessageReply)) {
    277277        MutexLocker locker(m_syncReplyStateMutex);
    278         ASSERT(!m_pendingSyncReplies.isEmpty());
    279 
    280         PendingSyncReply& pendingSyncReply = m_pendingSyncReplies.last();
    281         ASSERT(pendingSyncReply.syncRequestID == arguments->destinationID());
    282 
    283         pendingSyncReply.replyDecoder = arguments.leakPtr();
    284         pendingSyncReply.didReceiveReply = true;
    285 
     278        if (!m_pendingSyncReplies.isEmpty()) {
     279            ASSERT(!m_pendingSyncReplies.isEmpty());
     280
     281            PendingSyncReply& pendingSyncReply = m_pendingSyncReplies.last();
     282            ASSERT(pendingSyncReply.syncRequestID == arguments->destinationID());
     283
     284            pendingSyncReply.replyDecoder = arguments.leakPtr();
     285            pendingSyncReply.didReceiveReply = true;
     286        }
    286287        m_waitForSyncReplySemaphore.signal();
    287288        return;
Note: See TracChangeset for help on using the changeset viewer.