Changeset 126058 in webkit


Ignore:
Timestamp:
Aug 20, 2012 1:23:31 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Text Autosizing: Only take into account block width <= document layout width.
https://bugs.webkit.org/show_bug.cgi?id=93862

Patch by John Mellor <johnme@chromium.org> on 2012-08-20
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Instead of calculating the textAutosizingMultiplier purely based on the
width of each block, we now work out the maximum width of the block
that could be displayed onscreen at any one time, and use that value.
This avoids excessive text size multiplication (there's no point making
text bigger than this, since you wouldn't be able to zoom out far
enough to read it!).

To determine the maximum onscreen block width, we take the minimum of
the block width and the layoutWidth of the narrowest non-flattened
ancestor frame. Flattened frames are ignored since they don't impose a
hard limit on the maximum width that can be displayed, instead they can
stretch to fit their contents. Note that on mobile the layoutWidth of
the main frame is the fixed layout width aka viewport width.

In practice this caps the maximum multiplier to a value that depends
on the metrics of the device. For example on a Nexus S (480 x 800px
and 1.5x devicePixelRatio) with a 980px default fixed layout width,
this limits the multiplier to: 980 / (480/1.5) = 3.0625

Most pages won't have blocks that actually hit this cap, or they will
only slightly exceed it (so their multiplier will only be slightly
reduced). For example it's not uncommon for desktop pages to be
slightly wider than 980px, but they would have to additionally have
text that spans the full width of the page for this to affect them, and
even then it would merely slightly decrease their multiplier).

This will have more dramatic effects on the rare desktop pages which
give a width=device-width (or similar) mobile viewport tag (on ports
which support viewports). A follow-up patch will hopefully address this
by wrapping the text in such excessively wide blocks to the layoutWidth.

Tests: fast/text-autosizing/narrow-iframe-flattened.html

fast/text-autosizing/narrow-iframe.html
fast/text-autosizing/wide-block.html
fast/text-autosizing/wide-iframe.html

  • page/FrameView.cpp:

(WebCore::FrameView::isInChildFrameWithFrameFlattening):

Made public and const, so can be used from TextAutosizer.

  • rendering/TextAutosizer.cpp:

(WebCore::TextAutosizer::processSubtree):

Computes the minimum layout width of the parent frames, as described
above.

(WebCore::TextAutosizer::processBlock):

Limits used block width to this min layout width.

LayoutTests:

Added 4 tests: a block wider than the main frame, iframes both narrower
than and wider than the main frame, both also containing wide blocks,
and a narrow iframe expanded by frame flattening.

I verified experimentally that narrow-iframe-flattened.html passes, by
enabling frame flattening in Settings.cpp, but unfortunately it won't
get run by any bots since the only platform which currently enables
Text Autosizing (Chromium), doesn't enable frame flattening (or have
the DRT methods required to test it).

  • fast/text-autosizing/font-scale-factor-expected.html:
  • fast/text-autosizing/font-scale-factor.html:
  • fast/text-autosizing/narrow-iframe-expected.html: Added.
  • fast/text-autosizing/narrow-iframe-flattened-expected.html: Added.
  • fast/text-autosizing/narrow-iframe-flattened.html: Added.
  • fast/text-autosizing/narrow-iframe.html: Added.
  • fast/text-autosizing/wide-block-expected.html: Added.
  • fast/text-autosizing/wide-block.html: Added.
  • fast/text-autosizing/wide-iframe-expected.html: Added.
  • fast/text-autosizing/wide-iframe.html: Added.
  • platform/chromium/TestExpectations:
  • platform/win/Skipped:
  • platform/wincairo/Skipped:
Location:
trunk
Files:
8 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r126054 r126058  
     12012-08-20  John Mellor  <johnme@chromium.org>
     2
     3        Text Autosizing: Only take into account block width <= document layout width.
     4        https://bugs.webkit.org/show_bug.cgi?id=93862
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Added 4 tests: a block wider than the main frame, iframes both narrower
     9        than and wider than the main frame, both also containing wide blocks,
     10        and a narrow iframe expanded by frame flattening.
     11
     12        I verified experimentally that narrow-iframe-flattened.html passes, by
     13        enabling frame flattening in Settings.cpp, but unfortunately it won't
     14        get run by any bots since the only platform which currently enables
     15        Text Autosizing (Chromium), doesn't enable frame flattening (or have
     16        the DRT methods required to test it).
     17
     18        * fast/text-autosizing/font-scale-factor-expected.html:
     19        * fast/text-autosizing/font-scale-factor.html:
     20        * fast/text-autosizing/narrow-iframe-expected.html: Added.
     21        * fast/text-autosizing/narrow-iframe-flattened-expected.html: Added.
     22        * fast/text-autosizing/narrow-iframe-flattened.html: Added.
     23        * fast/text-autosizing/narrow-iframe.html: Added.
     24        * fast/text-autosizing/wide-block-expected.html: Added.
     25        * fast/text-autosizing/wide-block.html: Added.
     26        * fast/text-autosizing/wide-iframe-expected.html: Added.
     27        * fast/text-autosizing/wide-iframe.html: Added.
     28        * platform/chromium/TestExpectations:
     29        * platform/win/Skipped:
     30        * platform/wincairo/Skipped:
     31
    1322012-08-20  Bruno de Oliveira Abinader  <bruno.abinader@basyskom.com>
    233
  • trunk/LayoutTests/fast/text-autosizing/font-scale-factor-expected.html

    r125925 r126058  
    77        width: 800px;
    88        margin: 0px;
     9        overflow: hidden;
    910      }
    1011    </style>
  • trunk/LayoutTests/fast/text-autosizing/font-scale-factor.html

    r125925 r126058  
    77        width: 800px;
    88        margin: 0px;
     9        overflow: hidden; /* Vertical scrollbar makes it harder to write expected.html */
    910      }
    1011    </style>
  • trunk/LayoutTests/platform/chromium/TestExpectations

    r126051 r126058  
    765765// Tests for frameset flattening. Relevant only on mobile browsers.
    766766WONTFIX SKIP : fast/frames/flattening = TIMEOUT
     767WONTFIX SKIP : fast/text-autosizing/narrow-iframe-flattened.html = IMAGE
    767768WONTFIX SKIP : http/tests/misc/iframe-flattening-3level-nesting-with-blocking-resource.html = TIMEOUT
    768769
  • trunk/LayoutTests/platform/win/Skipped

    r125794 r126058  
    960960# https://bugs.webkit.org/show_bug.cgi?id=32717
    961961fast/frames/flattening/
     962fast/text-autosizing/narrow-iframe-flattened.html
    962963
    963964# https://bugs.webkit.org/show_bug.cgi?id=34933
  • trunk/LayoutTests/platform/wincairo/Skipped

    r125794 r126058  
    14771477# https://bugs.webkit.org/show_bug.cgi?id=32717
    14781478fast/frames/flattening/
     1479fast/text-autosizing/narrow-iframe-flattened.html
    14791480
    14801481# https://bugs.webkit.org/show_bug.cgi?id=34933
  • trunk/Source/WebCore/ChangeLog

    r126057 r126058  
     12012-08-20  John Mellor  <johnme@chromium.org>
     2
     3        Text Autosizing: Only take into account block width <= document layout width.
     4        https://bugs.webkit.org/show_bug.cgi?id=93862
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Instead of calculating the textAutosizingMultiplier purely based on the
     9        width of each block, we now work out the maximum width of the block
     10        that could be displayed onscreen at any one time, and use that value.
     11        This avoids excessive text size multiplication (there's no point making
     12        text bigger than this, since you wouldn't be able to zoom out far
     13        enough to read it!).
     14
     15        To determine the maximum onscreen block width, we take the minimum of
     16        the block width and the layoutWidth of the narrowest non-flattened
     17        ancestor frame. Flattened frames are ignored since they don't impose a
     18        hard limit on the maximum width that can be displayed, instead they can
     19        stretch to fit their contents. Note that on mobile the layoutWidth of
     20        the main frame is the fixed layout width aka viewport width.
     21
     22        In practice this caps the maximum multiplier to a value that depends
     23        on the metrics of the device. For example on a Nexus S (480 x 800px
     24        and 1.5x devicePixelRatio) with a 980px default fixed layout width,
     25        this limits the multiplier to: 980 / (480/1.5) = 3.0625
     26
     27        Most pages won't have blocks that actually hit this cap, or they will
     28        only slightly exceed it (so their multiplier will only be slightly
     29        reduced). For example it's not uncommon for desktop pages to be
     30        slightly wider than 980px, but they would have to additionally have
     31        text that spans the full width of the page for this to affect them, and
     32        even then it would merely slightly decrease their multiplier).
     33
     34        This will have more dramatic effects on the rare desktop pages which
     35        give a width=device-width (or similar) mobile viewport tag (on ports
     36        which support viewports). A follow-up patch will hopefully address this
     37        by wrapping the text in such excessively wide blocks to the layoutWidth.
     38
     39        Tests: fast/text-autosizing/narrow-iframe-flattened.html
     40               fast/text-autosizing/narrow-iframe.html
     41               fast/text-autosizing/wide-block.html
     42               fast/text-autosizing/wide-iframe.html
     43
     44        * page/FrameView.cpp:
     45        (WebCore::FrameView::isInChildFrameWithFrameFlattening):
     46
     47            Made public and const, so can be used from TextAutosizer.
     48
     49        * rendering/TextAutosizer.cpp:
     50        (WebCore::TextAutosizer::processSubtree):
     51
     52            Computes the minimum layout width of the parent frames, as described
     53            above.
     54
     55        (WebCore::TextAutosizer::processBlock):
     56
     57            Limits used block width to this min layout width.
     58
    1592012-08-20  Hans Wennborg  <hans@chromium.org>
    260
  • trunk/Source/WebCore/page/FrameView.cpp

    r125700 r126058  
    29332933}
    29342934
    2935 bool FrameView::isInChildFrameWithFrameFlattening()
     2935bool FrameView::isInChildFrameWithFrameFlattening() const
    29362936{
    29372937    if (!parent() || !m_frame->ownerElement())
  • trunk/Source/WebCore/page/FrameView.h

    r125700 r126058  
    256256
    257257    Color documentBackgroundColor() const;
     258
     259    bool isInChildFrameWithFrameFlattening() const;
    258260
    259261    static double currentPaintTimeStamp() { return sCurrentPaintTimeStamp; } // returns 0 if not painting
     
    431433    FrameView* parentFrameView() const;
    432434
    433     bool isInChildFrameWithFrameFlattening();
    434435    bool doLayoutWithFrameFlattening(bool allowSubtree);
    435436
  • trunk/Source/WebCore/rendering/TextAutosizer.cpp

    r125925 r126058  
    5151        return false;
    5252
     53    Frame* mainFrame = m_document->page()->mainFrame();
     54
     55    // Window area, in logical (density-independent) pixels.
    5356    IntSize windowSize = m_document->settings()->textAutosizingWindowSizeOverride();
    5457    if (windowSize.isEmpty()) {
    55         Frame* mainFrame = m_document->page()->mainFrame();
    5658        bool includeScrollbars = !InspectorInstrumentation::shouldApplyScreenWidthOverride(mainFrame);
    5759        windowSize = mainFrame->view()->visibleContentRect(includeScrollbars).size(); // FIXME: Check that this is always in logical (density-independent) pixels (see wkbug.com/87440).
     60    }
     61
     62    // Largest area of block that can be visible at once (assuming the main
     63    // frame doesn't get scaled to less than overview scale), in CSS pixels.
     64    IntSize minLayoutSize = mainFrame->view()->layoutSize();
     65    for (Frame* frame = m_document->frame(); frame; frame = frame->tree()->parent()) {
     66        if (!frame->view()->isInChildFrameWithFrameFlattening())
     67            minLayoutSize = minLayoutSize.shrunkTo(frame->view()->layoutSize());
    5868    }
    5969
     
    6171        if (isNotAnAutosizingContainer(descendant))
    6272            continue;
    63         processBox(toRenderBox(descendant), windowSize);
     73        processBox(toRenderBox(descendant), windowSize, minLayoutSize);
    6474    }
    6575
     
    6777}
    6878
    69 void TextAutosizer::processBox(RenderBox* box, const IntSize& windowSize)
     79void TextAutosizer::processBox(RenderBox* box, const IntSize& windowSize, const IntSize& layoutSize)
    7080{
    71     int windowLogicalWidth = box->isHorizontalWritingMode() ? windowSize.width() : windowSize.height();
    72     float multiplier = static_cast<float>(box->logicalWidth()) / windowLogicalWidth; // FIXME: This is overly simplistic.
     81    int logicalWindowWidth = box->isHorizontalWritingMode() ? windowSize.width() : windowSize.height();
     82    int logicalLayoutWidth = box->isHorizontalWritingMode() ? layoutSize.width() : layoutSize.height();
     83    // Ignore box width in excess of the layout width, to avoid extreme multipliers.
     84    float logicalBoxWidth = std::min<float>(box->logicalWidth(), logicalLayoutWidth);
     85
     86    float multiplier = logicalBoxWidth / logicalWindowWidth;
    7387    multiplier *= m_document->settings()->textAutosizingFontScaleFactor();
    7488
  • trunk/Source/WebCore/rendering/TextAutosizer.h

    r125925 r126058  
    5555    explicit TextAutosizer(Document*);
    5656
    57     void processBox(RenderBox*, const IntSize& windowSize);
     57    void processBox(RenderBox*, const IntSize& windowSize, const IntSize& layoutSize);
    5858    void setMultiplier(RenderObject*, float);
    5959
Note: See TracChangeset for help on using the changeset viewer.