Changeset 56454 in webkit


Ignore:
Timestamp:
Mar 24, 2010 1:38:05 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-03-24 Hayato Ito <hayato@chromium.org>

Reviewed by NOBODY (Need!).

Refactor computePageRects so that Mac can make use of it.
https://bugs.webkit.org/show_bug.cgi?id=36159

Refactoring only, so no new tests.

  • WebCore.base.exp:
  • page/PrintContext.cpp: (WebCore::PrintContext::computePageRects): (WebCore::PrintContext::computePageRectsWithPageSize): (WebCore::PrintContext::computePageRectsWithPageSizeInternal): (WebCore::PrintContext::pageNumberForElement): (WebCore::PrintContext::numberOfPages):
  • page/PrintContext.h:

2010-03-24 Hayato Ito <hayato@chromium.org>

Reviewed by Shinichiro Hamaji.

Refactor computePageRects so that Mac can make use of it.
https://bugs.webkit.org/show_bug.cgi?id=36159

Refactoring only, so no new tests.

  • WebView/WebFrame.mm: (-[WebFrame _computePageRectsWithPrintWidthScaleFactor:printHeight:]):
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56453 r56454  
     12010-03-24  Hayato Ito  <hayato@chromium.org>
     2
     3        Reviewed by NOBODY (Need!).
     4
     5        Refactor computePageRects so that Mac can make use of it.
     6        https://bugs.webkit.org/show_bug.cgi?id=36159
     7
     8        Refactoring only, so no new tests.
     9
     10        * WebCore.base.exp:
     11        * page/PrintContext.cpp:
     12        (WebCore::PrintContext::computePageRects):
     13        (WebCore::PrintContext::computePageRectsWithPageSize):
     14        (WebCore::PrintContext::computePageRectsWithPageSizeInternal):
     15        (WebCore::PrintContext::pageNumberForElement):
     16        (WebCore::PrintContext::numberOfPages):
     17        * page/PrintContext.h:
     18
    1192010-03-24  Jeremy Moskovich  <jeremy@chromium.org>
    220
  • trunk/WebCore/WebCore.base.exp

    r56439 r56454  
    253253__ZN7WebCore12PrintContext13numberOfPagesEPNS_5FrameERKNS_9FloatSizeE
    254254__ZN7WebCore12PrintContext20pageNumberForElementEPNS_7ElementERKNS_9FloatSizeE
     255__ZN7WebCore12PrintContext28computePageRectsWithPageSizeERKNS_9FloatSizeEb
     256__ZN7WebCore12PrintContextC1EPNS_5FrameE
     257__ZN7WebCore12PrintContextD1Ev
    255258__ZN7WebCore12RenderObject16repaintRectangleERKNS_7IntRectEb
    256259__ZN7WebCore12RenderWidget19showSubstituteImageEN3WTF10PassRefPtrINS_5ImageEEE
  • trunk/WebCore/page/PrintContext.cpp

    r55988 r56454  
    5959        return;
    6060
     61    if (userScaleFactor <= 0) {
     62        LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor);
     63        return;
     64    }
     65
    6166    RenderView* root = toRenderView(m_frame->document()->renderer());
    62 
    63     if (!root) {
    64         LOG_ERROR("document to be printed has no renderer");
    65         return;
    66     }
    6767
    6868    float ratio = printRect.height() / printRect.width();
     
    7070    float pageWidth  = (float)root->rightLayoutOverflow();
    7171    float pageHeight = pageWidth * ratio;
    72     outPageHeight = pageHeight;   // this is the height of the page adjusted by margins
     72    outPageHeight = pageHeight; // this is the height of the page adjusted by margins
    7373    pageHeight -= headerHeight + footerHeight;
    7474
     
    7878    }
    7979
    80     computePageRectsWithPageSize(FloatSize(pageWidth, pageHeight), userScaleFactor);
    81 }
    82 
    83 void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, float userScaleFactor)
    84 {
     80    computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor), false);
     81}
     82
     83void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages)
     84{
     85    m_pageRects.clear();
     86    computePageRectsWithPageSizeInternal(pageSizeInPixels, allowHorizontalMultiPages);
     87}
     88
     89void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages)
     90{
     91    if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderer())
     92        return;
    8593    RenderView* root = toRenderView(m_frame->document()->renderer());
    8694
    87     if (!root) {
    88         LOG_ERROR("document to be printed has no renderer");
    89         return;
    90     }
    91 
    92     if (userScaleFactor <= 0) {
    93         LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor);
    94         return;
    95     }
    96 
    97     float currPageHeight = pageSizeInPixels.height() / userScaleFactor;
    98     float docHeight = root->layer()->height();
    99     float currPageWidth = pageSizeInPixels.width() / userScaleFactor;
     95    const float pageWidth = pageSizeInPixels.width();
     96    const float docWidth = root->layer()->width();
     97    const float docHeight = root->layer()->height();
     98    float currPageHeight = pageSizeInPixels.height();
    10099
    101100    // always return at least one page, since empty files should print a blank page
     
    105104        m_frame->view()->adjustPageHeight(&proposedBottom, printedPagesHeight, proposedBottom, printedPagesHeight);
    106105        currPageHeight = max(1.0f, proposedBottom - printedPagesHeight);
    107 
    108         m_pageRects.append(IntRect(0, (int)printedPagesHeight, (int)currPageWidth, (int)currPageHeight));
     106        if (allowHorizontalMultiPages) {
     107            for (float curWidth = 0; curWidth < docWidth; curWidth += pageWidth)
     108                m_pageRects.append(IntRect(curWidth, (int)printedPagesHeight, (int)pageWidth, (int)currPageHeight));
     109        } else
     110            m_pageRects.append(IntRect(0, (int)printedPagesHeight, (int)pageWidth, (int)currPageHeight));
    109111        printedPagesHeight += currPageHeight;
    110112    } while (printedPagesHeight < docHeight);
     
    176178    PrintContext printContext(frame);
    177179    printContext.begin(pageRect.width());
    178     printContext.computePageRectsWithPageSize(pageSizeInPixels, 1);
     180    printContext.computePageRectsWithPageSize(pageSizeInPixels, false);
    179181
    180182    int top = box->offsetTop();
     
    197199    PrintContext printContext(frame);
    198200    printContext.begin(pageRect.width());
    199     printContext.computePageRectsWithPageSize(pageSizeInPixels, 1);
     201    printContext.computePageRectsWithPageSize(pageSizeInPixels, false);
    200202    printContext.end();
    201203    return printContext.pageCount();
  • trunk/WebCore/page/PrintContext.h

    r54533 r56454  
    4343
    4444    void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight);
     45    void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages);
    4546
    4647    // TODO: eliminate width param
     
    5758
    5859protected:
    59     void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, float userScaleFactor);
    60 
    6160    Frame* m_frame;
    6261    Vector<IntRect> m_pageRects;
     62
     63private:
     64    void computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalMultiPages);
    6365};
    6466
  • trunk/WebKit/mac/ChangeLog

    r56439 r56454  
     12010-03-24  Hayato Ito  <hayato@chromium.org>
     2
     3        Reviewed by Shinichiro Hamaji.
     4
     5        Refactor computePageRects so that Mac can make use of it.
     6        https://bugs.webkit.org/show_bug.cgi?id=36159
     7
     8        Refactoring only, so no new tests.
     9
     10        * WebView/WebFrame.mm:
     11        (-[WebFrame _computePageRectsWithPrintWidthScaleFactor:printHeight:]):
     12
    1132010-03-24  Kent Tamura  <tkent@chromium.org>
    214
  • trunk/WebKit/mac/WebView/WebFrame.mm

    r55997 r56454  
    7575#import <WebCore/Page.h>
    7676#import <WebCore/PluginData.h>
     77#import <WebCore/PrintContext.h>
    7778#import <WebCore/RenderLayer.h>
    7879#import <WebCore/RenderPart.h>
     
    583584        return pages;
    584585
    585     float currPageHeight = printHeight;
    586     float docHeight = root->layer()->height();
    587586    float docWidth = root->layer()->width();
    588     float printWidth = docWidth/printWidthScaleFactor;
    589    
    590     // We need to give the part the opportunity to adjust the page height at each step.
    591     for (float i = 0; i < docHeight; i += currPageHeight) {
    592         float proposedBottom = min(docHeight, i + printHeight);
    593         view->adjustPageHeight(&proposedBottom, i, proposedBottom, i);
    594         currPageHeight = max(1.0f, proposedBottom - i);
    595         for (float j = 0; j < docWidth; j += printWidth) {
    596             NSValue* val = [NSValue valueWithRect: NSMakeRect(j, i, printWidth, currPageHeight)];
    597             [pages addObject: val];
    598         }
    599     }
    600    
     587    float printWidth = docWidth / printWidthScaleFactor;
     588
     589    PrintContext printContext(_private->coreFrame);
     590    printContext.computePageRectsWithPageSize(FloatSize(printWidth, printHeight), true);
     591
     592    const Vector<IntRect>& pageRects = printContext.pageRects();
     593    const size_t pageCount = pageRects.size();
     594    for (size_t pageNumber = 0; pageNumber < pageCount; ++pageNumber)
     595        [pages addObject: [NSValue valueWithRect: NSRect(pageRects[pageNumber])]];
    601596    return pages;
    602597}
Note: See TracChangeset for help on using the changeset viewer.