Changeset 98634 in webkit


Ignore:
Timestamp:
Oct 27, 2011 1:53:53 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[Chromium] Need setPrinting
https://bugs.webkit.org/show_bug.cgi?id=46152

Patch by Stephen Chenney <schenney@chromium.org> on 2011-10-27
Reviewed by Hajime Morita.

Source/WebKit/chromium:

  • public/WebFrame.h: Added pure virtual prototype for printPagesWithBoundaries. Added enum

and changed parameters for renderTreeAsText.

  • src/WebFrameImpl.cpp:

(WebKit::ChromePrintContext::spoolAllPagesWithBoundaries): Added this method, based on
the static in PrintContext. This uses Chromium specific page spooling and transforms.
(WebKit::WebFrameImpl::renderTreeAsText): Updated to allow text dump in printed format.
(WebKit::WebFrameImpl::printPagesWithBoundaries): Added method for testing printing page
breaks.

  • src/WebFrameImpl.h: Added prototype.

Tools:

  • DumpRenderTree/chromium/LayoutTestController.cpp:

(LayoutTestController::LayoutTestController): Added logic for handling setPrinting.
(LayoutTestController::reset): Clearing flags for setPrinting.
(LayoutTestController::setPrinting): Set flags for setPrinting.

  • DumpRenderTree/chromium/LayoutTestController.h:

(LayoutTestController::setIsPrinting): Added the setPrinting methods and flags.
(LayoutTestController::isPrinting): Method to return the setPrinting status.

  • DumpRenderTree/chromium/TestShell.cpp:

(dumpFramesAsPrintedText): A method for creating a text dump in printed layout.
(TestShell::dump): Modified to dump setPrinting-specific output.

  • DumpRenderTree/chromium/WebViewHost.cpp:

(WebViewHost::paintPagesWithBoundaries): Handling for pixel tests when setPrinting is
active.

  • DumpRenderTree/chromium/WebViewHost.h: Prototype for paintPagesWithBoundaries.

LayoutTests:

  • platform/chromium/test_expectations.txt: Removing setPrinting tests from the expected failures.
  • platform/chromium-linux/printing/setPrinting-expected.png: Added.
  • platform/chromium-linux/printing/setPrinting-expected.txt: Added.
  • platform/chromium-linux/printing/single-line-must-not-be-split-into-two-pages-expected.png: Added.
  • platform/chromium-linux/printing/single-line-must-not-be-split-into-two-pages-expected.txt: Added.
  • platform/chromium-mac/printing/setPrinting-expected.png: Added.
  • platform/chromium-mac/printing/setPrinting-expected.txt: Added.
  • platform/chromium-mac/printing/single-line-must-not-be-split-into-two-pages-expected.png: Added.
  • platform/chromium-mac/printing/single-line-must-not-be-split-into-two-pages-expected.txt: Added.
  • platform/chromium-win/printing/setPrinting-expected.png: Added.
  • platform/chromium-win/printing/setPrinting-expected.txt: Added.
  • platform/chromium-win/printing/single-line-must-not-be-split-into-two-pages-expected.png: Added.
  • platform/chromium-win/printing/single-line-must-not-be-split-into-two-pages-expected.txt: Added.
  • platform/mac/printing/setPrinting-expected.png: Rebaselined for the change to the test html.
  • platform/mac/printing/setPrinting-expected.txt: Rebaselined for the change to the test html.
  • printing/setPrinting.html: Modified the test to make the box have a colored border instead of the solid background, as the solid background does not print on chromium.
Location:
trunk
Files:
12 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r98632 r98634  
     12011-10-27  Stephen Chenney  <schenney@chromium.org>
     2
     3        [Chromium] Need setPrinting
     4        https://bugs.webkit.org/show_bug.cgi?id=46152
     5
     6        Reviewed by Hajime Morita.
     7
     8        * platform/chromium/test_expectations.txt: Removing setPrinting tests from the expected failures.
     9        * platform/chromium-linux/printing/setPrinting-expected.png: Added.
     10        * platform/chromium-linux/printing/setPrinting-expected.txt: Added.
     11        * platform/chromium-linux/printing/single-line-must-not-be-split-into-two-pages-expected.png: Added.
     12        * platform/chromium-linux/printing/single-line-must-not-be-split-into-two-pages-expected.txt: Added.
     13        * platform/chromium-mac/printing/setPrinting-expected.png: Added.
     14        * platform/chromium-mac/printing/setPrinting-expected.txt: Added.
     15        * platform/chromium-mac/printing/single-line-must-not-be-split-into-two-pages-expected.png: Added.
     16        * platform/chromium-mac/printing/single-line-must-not-be-split-into-two-pages-expected.txt: Added.
     17        * platform/chromium-win/printing/setPrinting-expected.png: Added.
     18        * platform/chromium-win/printing/setPrinting-expected.txt: Added.
     19        * platform/chromium-win/printing/single-line-must-not-be-split-into-two-pages-expected.png: Added.
     20        * platform/chromium-win/printing/single-line-must-not-be-split-into-two-pages-expected.txt: Added.
     21        * platform/mac/printing/setPrinting-expected.png: Rebaselined for the change to the test html.
     22        * platform/mac/printing/setPrinting-expected.txt: Rebaselined for the change to the test html.
     23        * printing/setPrinting.html: Modified the test to make the box have a colored border
     24          instead of the solid background, as the solid background does not print on chromium.
     25
    1262011-10-27  Leandro Pereira  <leandro@profusion.mobi>
    227
  • trunk/LayoutTests/platform/chromium/test_expectations.txt

    r98616 r98634  
    21682168BUGWK42428 LINUX WIN : svg/W3C-SVG-1.1/filters-conv-01-f.svg = IMAGE+TEXT
    21692169
    2170 // Need setPrinting.
    2171 BUGWK20011 : printing/setPrinting.html = FAIL
    2172 BUGWK65005 : printing/single-line-must-not-be-split-into-two-pages.html = FAIL MISSING
    2173 
    21742170// Needs V8 change.
    21752171BUGCR49343 : fast/js/reserved-words-as-property.html = TEXT
     
    23772373BUGCR58936 : fast/js/basic-strict-mode.html = TEXT
    23782374BUGCR58936 : fast/js/numeric-escapes-in-string-literals.html = TEXT
    2379 
    2380 // Started failing at Webkit r69628.
    2381 BUGWK47578 : printing/simultaneous-position-float-change.html = IMAGE+TEXT
    23822375
    23832376// We don't support layoutTestController.nodesFromRect so this test just times out
  • trunk/LayoutTests/platform/mac/printing/setPrinting-expected.txt

    r78910 r98634  
    44  RenderBlock {HTML} at (0,0) size 981x785
    55    RenderBody {BODY} at (0,0) size 981x785
    6       RenderBlock {DIV} at (0,0) size 800x749 [bgcolor=#008000]
    7         RenderText {#text} at (0,0) size 235x18
    8           text run at (0,0) width 235: "This test case should output 2 pages."
     6      RenderBlock {DIV} at (0,0) size 800x749 [border: (1px solid #008000)]
     7        RenderText {#text} at (1,1) size 235x18
     8          text run at (1,1) width 235: "This test case should output 2 pages."
    99      RenderBlock (anonymous) at (0,749) size 981x36
    1010        RenderText {#text} at (0,0) size 957x36
  • trunk/LayoutTests/printing/setPrinting.html

    r63521 r98634  
    88
    99<body style="margin: 0px;">
    10 <div style="width: 800px; height: 749px; background-color: green;">
     10<div style="width: 798px; height: 747px; border: 1px solid green;">
    1111This test case should output 2 pages.
    1212</div>
  • trunk/Source/WebKit/chromium/ChangeLog

    r98630 r98634  
     12011-10-27  Stephen Chenney  <schenney@chromium.org>
     2
     3        [Chromium] Need setPrinting
     4        https://bugs.webkit.org/show_bug.cgi?id=46152
     5
     6        Reviewed by Hajime Morita.
     7
     8        * public/WebFrame.h: Added pure virtual prototype for printPagesWithBoundaries. Added enum
     9        and changed parameters for renderTreeAsText.
     10        * src/WebFrameImpl.cpp:
     11        (WebKit::ChromePrintContext::spoolAllPagesWithBoundaries): Added this method, based on
     12        the static in PrintContext. This uses Chromium specific page spooling and transforms.
     13        (WebKit::WebFrameImpl::renderTreeAsText): Updated to allow text dump in printed format.
     14        (WebKit::WebFrameImpl::printPagesWithBoundaries): Added method for testing printing page
     15        breaks.
     16        * src/WebFrameImpl.h: Added prototype.
     17
    1182011-10-27  Antoine Labour  <piman@chromium.org>
    219
  • trunk/Source/WebKit/chromium/public/WebFrame.h

    r97301 r98634  
    8080class WebFrame {
    8181public:
     82    // Control of renderTreeAsText output
     83    enum RenderAsTextControl {
     84        RenderAsTextNormal = 0,
     85        RenderAsTextDebug = 1 << 0,
     86        RenderAsTextPrinting = 1 << 1
     87    };
     88    typedef unsigned RenderAsTextControls;
     89
    8290    // Returns the number of live WebFrame objects, used for leak checking.
    8391    WEBKIT_EXPORT static int instanceCount();
     
    547555    // Returns a text representation of the render tree.  This method is used
    548556    // to support layout tests.
    549     virtual WebString renderTreeAsText(bool showDebugInfo = false) const = 0;
     557    virtual WebString renderTreeAsText(RenderAsTextControls toShow = RenderAsTextNormal) const = 0;
    550558
    551559    // Returns the counter value for the specified element.  This method is
     
    562570                                         float pageHeightInPixels) const = 0;
    563571
     572    // Prints all of the pages into the canvas, with page boundaries drawn as
     573    // one pixel wide blue lines. This method exists to support layout tests.
     574    virtual void printPagesWithBoundaries(WebCanvas*, const WebSize&) = 0;
     575
    564576    // Returns the bounds rect for current selection. If selection is performed
    565577    // on transformed text, the rect will still bound the selection but will
  • trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp

    r97478 r98634  
    363363    }
    364364
     365    void spoolAllPagesWithBoundaries(GraphicsContext& graphicsContext, const FloatSize& pageSizeInPixels)
     366    {
     367        if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderer())
     368            return;
     369
     370        m_frame->document()->updateLayout();
     371
     372        float pageHeight;
     373        computePageRects(FloatRect(FloatPoint(0, 0), pageSizeInPixels), 0, 0, 1, pageHeight);
     374
     375        const float pageWidth = pageSizeInPixels.width();
     376        size_t numPages = pageRects().size();
     377        int totalHeight = numPages * (pageSizeInPixels.height() + 1) - 1;
     378
     379        // Fill the whole background by white.
     380        graphicsContext.setFillColor(Color(255, 255, 255), ColorSpaceDeviceRGB);
     381        graphicsContext.fillRect(FloatRect(0, 0, pageWidth, totalHeight));
     382
     383        graphicsContext.save();
     384
     385        int currentHeight = 0;
     386        for (size_t pageIndex = 0; pageIndex < numPages; pageIndex++) {
     387            // Draw a line for a page boundary if this isn't the first page.
     388            if (pageIndex > 0) {
     389                graphicsContext.save();
     390                graphicsContext.setStrokeColor(Color(0, 0, 255), ColorSpaceDeviceRGB);
     391                graphicsContext.setFillColor(Color(0, 0, 255), ColorSpaceDeviceRGB);
     392                graphicsContext.drawLine(IntPoint(0, currentHeight),
     393                                         IntPoint(pageWidth, currentHeight));
     394                graphicsContext.restore();
     395            }
     396
     397            graphicsContext.save();
     398
     399            graphicsContext.translate(0, currentHeight);
     400#if !OS(UNIX) || OS(DARWIN)
     401            // Account for the disabling of scaling in spoolPage. In the context
     402            // of spoolAllPagesWithBoundaries the scale HAS NOT been pre-applied.
     403            float scale = getPageShrink(pageIndex);
     404            graphicsContext.scale(WebCore::FloatSize(scale, scale));
     405#endif
     406            spoolPage(graphicsContext, pageIndex);
     407            graphicsContext.restore();
     408
     409            currentHeight += pageSizeInPixels.height() + 1;
     410        }
     411
     412        graphicsContext.restore();
     413    }
     414
    365415    virtual void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight)
    366416    {
     
    17791829}
    17801830
    1781 WebString WebFrameImpl::renderTreeAsText(bool showDebugInfo) const
     1831WebString WebFrameImpl::renderTreeAsText(RenderAsTextControls toShow) const
    17821832{
    17831833    RenderAsTextBehavior behavior = RenderAsTextBehaviorNormal;
    17841834
    1785     if (showDebugInfo) {
     1835    if (toShow & RenderAsTextDebug) {
    17861836        behavior |= RenderAsTextShowCompositedLayers
    17871837            | RenderAsTextShowAddresses
     
    17901840    }
    17911841
     1842    if (toShow & RenderAsTextPrinting)
     1843        behavior |= RenderAsTextPrintingMode;
     1844
    17921845    return externalRepresentation(m_frame, behavior);
    17931846}
     
    18231876    FloatSize pageSize(pageWidthInPixels, pageHeightInPixels);
    18241877    return PrintContext::pageNumberForElement(element, pageSize);
     1878}
     1879
     1880void WebFrameImpl::printPagesWithBoundaries(WebCanvas* canvas, const WebSize& pageSizeInPixels)
     1881{
     1882    ASSERT(m_printContext.get());
     1883
     1884    GraphicsContextBuilder builder(canvas);
     1885    GraphicsContext& graphicsContext = builder.context();
     1886#if WEBKIT_USING_SKIA
     1887    graphicsContext.platformContext()->setPrinting(true);
     1888#endif
     1889
     1890    m_printContext->spoolAllPagesWithBoundaries(graphicsContext,
     1891        FloatSize(pageSizeInPixels.width, pageSizeInPixels.height));
    18251892}
    18261893
  • trunk/Source/WebKit/chromium/src/WebFrameImpl.h

    r97301 r98634  
    179179                                            int& marginBottom,
    180180                                            int& marginLeft);
     181    virtual void printPagesWithBoundaries(WebCanvas*, const WebSize&);
    181182    virtual bool find(
    182183        int identifier, const WebString& searchText, const WebFindOptions&,
     
    192193    virtual WebString contentAsText(size_t maxChars) const;
    193194    virtual WebString contentAsMarkup() const;
    194     virtual WebString renderTreeAsText(bool showDebugInfo = false) const;
     195    virtual WebString renderTreeAsText(RenderAsTextControls toShow = RenderAsTextNormal) const;
    195196    virtual WebString counterValueForElementById(const WebString& id) const;
    196197    virtual WebString markerTextForListItem(const WebElement&) const;
  • trunk/Tools/ChangeLog

    r98622 r98634  
     12011-10-27  Stephen Chenney  <schenney@chromium.org>
     2
     3        [Chromium] Need setPrinting
     4        https://bugs.webkit.org/show_bug.cgi?id=46152
     5
     6        Reviewed by Hajime Morita.
     7
     8        * DumpRenderTree/chromium/LayoutTestController.cpp:
     9        (LayoutTestController::LayoutTestController): Added logic for handling setPrinting.
     10        (LayoutTestController::reset): Clearing flags for setPrinting.
     11        (LayoutTestController::setPrinting): Set flags for setPrinting.
     12        * DumpRenderTree/chromium/LayoutTestController.h:
     13        (LayoutTestController::setIsPrinting): Added the setPrinting methods and flags.
     14        (LayoutTestController::isPrinting): Method to return the setPrinting status.
     15        * DumpRenderTree/chromium/TestShell.cpp:
     16        (dumpFramesAsPrintedText): A method for creating a text dump in printed layout.
     17        (TestShell::dump): Modified to dump setPrinting-specific output.
     18        * DumpRenderTree/chromium/WebViewHost.cpp:
     19        (WebViewHost::paintPagesWithBoundaries): Handling for pixel tests when setPrinting is
     20        active.
     21        * DumpRenderTree/chromium/WebViewHost.h: Prototype for paintPagesWithBoundaries.
     22
    1232011-10-27  Sam Weinig  <sam@webkit.org>
    224
  • trunk/Tools/DumpRenderTree/chromium/LayoutTestController.cpp

    r98559 r98634  
    176176    bindMethod("setPopupBlockingEnabled", &LayoutTestController::setPopupBlockingEnabled);
    177177    bindMethod("setPOSIXLocale", &LayoutTestController::setPOSIXLocale);
     178    bindMethod("setPrinting", &LayoutTestController::setPrinting);
    178179    bindMethod("setScrollbarPolicy", &LayoutTestController::setScrollbarPolicy);
    179180    bindMethod("setSelectTrailingWhitespaceEnabled", &LayoutTestController::setSelectTrailingWhitespaceEnabled);
     
    630631    m_platformName.set("chromium");
    631632    m_userStyleSheetLocation = WebURL();
     633    m_isPrinting = false;
    632634
    633635    webkit_support::SetAcceptAllCookies(false);
     
    15651567}
    15661568
     1569void LayoutTestController::setPrinting(const CppArgumentList& arguments, CppVariant* result)
     1570{
     1571    setIsPrinting(true);
     1572    result->setNull();
     1573}
     1574
    15671575void LayoutTestController::pageNumberForElementById(const CppArgumentList& arguments, CppVariant* result)
    15681576{
  • trunk/Tools/DumpRenderTree/chromium/LayoutTestController.h

    r97716 r98634  
    328328    // Gets the value of the counter in the element specified by its ID.
    329329    void counterValueForElementById(const CppArgumentList&, CppVariant*);
     330
     331    // Causes layout to happen as if targetted to printed pages.
     332    void setPrinting(const CppArgumentList&, CppVariant*);
    330333
    331334    // Gets the number of page where the specified element will be put.
     
    452455    }
    453456
     457    void setIsPrinting(bool value) { m_isPrinting = value; }
     458    bool isPrinting() { return m_isPrinting; }
     459
    454460    bool testRepaint() const { return m_testRepaint; }
    455461    bool sweepHorizontally() const { return m_sweepHorizontally; }
     
    643649    bool m_showDebugLayerTree;
    644650
     651    // If true, layout is to target printed pages.
     652    bool m_isPrinting;
     653
    645654    WorkQueue m_workQueue;
    646655
  • trunk/Tools/DumpRenderTree/chromium/TestShell.cpp

    r98559 r98634  
    372372}
    373373
     374static string dumpFramesAsPrintedText(WebFrame* frame, bool recursive)
     375{
     376    string result;
     377
     378    // Cannot do printed format for anything other than HTML
     379    if (!frame->document().isHTMLDocument())
     380        return string();
     381
     382    // Add header for all but the main frame. Skip empty frames.
     383    if (frame->parent() && !frame->document().documentElement().isNull()) {
     384        result.append("\n--------\nFrame: '");
     385        result.append(frame->name().utf8().data());
     386        result.append("'\n--------\n");
     387    }
     388
     389    result.append(frame->renderTreeAsText(WebFrame::RenderAsTextPrinting).utf8());
     390    result.append("\n");
     391
     392    if (recursive) {
     393        for (WebFrame* child = frame->firstChild(); child; child = child->nextSibling())
     394            result.append(dumpFramesAsPrintedText(child, recursive));
     395    }
     396
     397    return result;
     398}
     399
    374400static void dumpFrameScrollPosition(WebFrame* frame, bool recursive)
    375401{
     
    489515    bool shouldDumpAsAudio = m_layoutTestController->shouldDumpAsAudio();
    490516    bool shouldGeneratePixelResults = m_layoutTestController->shouldGeneratePixelResults();
     517    bool shouldDumpAsPrinted = m_layoutTestController->isPrinting();
    491518    bool dumpedAnything = false;
    492519
    493520    if (shouldDumpAsAudio) {
    494521        m_printer->handleAudioHeader();
    495        
     522
    496523        const WebKit::WebArrayBufferView& webArrayBufferView = m_layoutTestController->audioData();
    497524        printf("Content-Length: %d\n", webArrayBufferView.byteLength());
    498        
     525
    499526        if (fwrite(webArrayBufferView.baseAddress(), 1, webArrayBufferView.byteLength(), stdout) != webArrayBufferView.byteLength())
    500527            FATAL("Short write to stdout, disk full?\n");
    501528        printf("\n");
    502        
     529
    503530        m_printer->handleTestFooter(true);
    504531
     
    523550        if (shouldDumpAsText) {
    524551            bool recursive = m_layoutTestController->shouldDumpChildFramesAsText();
    525             string dataUtf8 = dumpFramesAsText(frame, recursive);
     552            string dataUtf8 = shouldDumpAsPrinted ? dumpFramesAsPrintedText(frame, recursive) : dumpFramesAsText(frame, recursive);
    526553            if (fwrite(dataUtf8.c_str(), 1, dataUtf8.size(), stdout) != dataUtf8.size())
    527554                FATAL("Short write to stdout, disk full?\n");
    528555        } else {
    529             printf("%s", frame->renderTreeAsText(m_params.debugRenderTree).utf8().data());
     556          WebFrame::RenderAsTextControls renderTextBehavior = WebFrame::RenderAsTextNormal;
     557            if (shouldDumpAsPrinted)
     558                renderTextBehavior |= WebFrame::RenderAsTextPrinting;
     559            if (m_params.debugRenderTree)
     560                renderTextBehavior |= WebFrame::RenderAsTextDebug;
     561            printf("%s", frame->renderTreeAsText(renderTextBehavior).utf8().data());
    530562            bool recursive = m_layoutTestController->shouldDumpChildFrameScrollPositions();
    531563            dumpFrameScrollPosition(frame, recursive);
     
    554586                    m_webViewHost->paintRect(line);
    555587            }
    556         } else
     588        } else if (m_layoutTestController->isPrinting())
     589            m_webViewHost->paintPagesWithBoundaries();
     590        else
    557591            m_webViewHost->paintInvalidatedRegion();
    558592
  • trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp

    r97743 r98634  
    15741574}
    15751575
     1576void WebViewHost::paintPagesWithBoundaries()
     1577{
     1578    ASSERT(!m_isPainting);
     1579    ASSERT(canvas());
     1580    m_isPainting = true;
     1581
     1582    WebSize pageSizeInPixels = webWidget()->size();
     1583    WebFrame* webFrame = webView()->mainFrame();
     1584
     1585    int pageCount = webFrame->printBegin(pageSizeInPixels);
     1586    int totalHeight = pageCount * (pageSizeInPixels.height + 1) - 1;
     1587
     1588    SkCanvas* testCanvas = skia::TryCreateBitmapCanvas(pageSizeInPixels.width, totalHeight, true);
     1589    if (testCanvas) {
     1590        discardBackingStore();
     1591        m_canvas = adoptPtr(testCanvas);
     1592    } else {
     1593        webFrame->printEnd();
     1594        return;
     1595    }
     1596
     1597#if WEBKIT_USING_SKIA
     1598    WebCanvas* webCanvas = canvas();
     1599#elif WEBKIT_USING_CG
     1600    const SkBitmap& canvasBitmap = canvas()->getDevice()->accessBitmap(false);
     1601    WebCanvas* webCanvas = CGBitmapContextCreate(canvasBitmap.getPixels(),
     1602                                                 pageSizeInPixels.width, totalHeight,
     1603                                                 8, pageSizeInPixels.width * 4,
     1604                                                 CGColorSpaceCreateDeviceRGB(),
     1605                                                 kCGImageAlphaPremultipliedFirst |
     1606                                                 kCGBitmapByteOrder32Host);
     1607#endif
     1608
     1609    webFrame->printPagesWithBoundaries(webCanvas, pageSizeInPixels);
     1610    webFrame->printEnd();
     1611
     1612    m_isPainting = false;
     1613}
     1614
    15761615SkCanvas* WebViewHost::canvas()
    15771616{
  • trunk/Tools/DumpRenderTree/chromium/WebViewHost.h

    r97743 r98634  
    8989    void updatePaintRect(const WebKit::WebRect&);
    9090    void paintInvalidatedRegion();
     91    void paintPagesWithBoundaries();
    9192    SkCanvas* canvas();
    9293    void displayRepaintMask();
Note: See TracChangeset for help on using the changeset viewer.