Changeset 137738 in webkit


Ignore:
Timestamp:
Dec 14, 2012 3:58:39 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Text Autosizing: Don't autosize unwrappable blocks
https://bugs.webkit.org/show_bug.cgi?id=104925

Patch by John Mellor <johnme@chromium.org> on 2012-12-14
Reviewed by Julien Chaffraix.

Source/WebCore:

If we autosize an unwrappable block (white-space:nowrap/pre), it'll
expand sideways. This doesn't actually improve its legibility, and it
can often severely break web page layouts. This patch prevents us from
autosizing unwrappable blocks. A follow-up patch will address the more
complex issue of unwrappable inline elements.

Tests: fast/text-autosizing/unwrappable-blocks.html

fast/text-autosizing/unwrappable-inlines.html

  • rendering/TextAutosizer.cpp:

(WebCore::TextAutosizer::processContainer):

Use containerShouldbeAutosized instead of contentHeightIsConstrained.

(WebCore::contentHeightIsConstrained):

Unchanged, just moved lower down the file.

(WebCore::TextAutosizer::containerShouldbeAutosized):

Checks that the block is wrappable, and also that contentHeightIsConstrained is false.

(WebCore::TextAutosizer::measureDescendantTextWidth):

Use containerShouldbeAutosized instead of contentHeightIsConstrained.

  • rendering/TextAutosizer.h:

Declared containerShouldbeAutosized.

LayoutTests:

Added tests verifying that this prevents unwrappable blocks from being
autosized, and that this has no effect on unwrappable inlines.

  • fast/text-autosizing/unwrappable-blocks-expected.html: Added.
  • fast/text-autosizing/unwrappable-blocks.html: Added.
  • fast/text-autosizing/unwrappable-inlines-expected.html: Added.
  • fast/text-autosizing/unwrappable-inlines.html: Added.
Location:
trunk
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r137736 r137738  
     12012-12-14  John Mellor  <johnme@chromium.org>
     2
     3        Text Autosizing: Don't autosize unwrappable blocks
     4        https://bugs.webkit.org/show_bug.cgi?id=104925
     5
     6        Reviewed by Julien Chaffraix.
     7
     8        Added tests verifying that this prevents unwrappable blocks from being
     9        autosized, and that this has no effect on unwrappable inlines.
     10
     11        * fast/text-autosizing/unwrappable-blocks-expected.html: Added.
     12        * fast/text-autosizing/unwrappable-blocks.html: Added.
     13        * fast/text-autosizing/unwrappable-inlines-expected.html: Added.
     14        * fast/text-autosizing/unwrappable-inlines.html: Added.
     15
    1162012-12-14  Kentaro Hara  <haraken@chromium.org>
    217
  • trunk/Source/WebCore/ChangeLog

    r137737 r137738  
     12012-12-14  John Mellor  <johnme@chromium.org>
     2
     3        Text Autosizing: Don't autosize unwrappable blocks
     4        https://bugs.webkit.org/show_bug.cgi?id=104925
     5
     6        Reviewed by Julien Chaffraix.
     7
     8        If we autosize an unwrappable block (white-space:nowrap/pre), it'll
     9        expand sideways. This doesn't actually improve its legibility, and it
     10        can often severely break web page layouts. This patch prevents us from
     11        autosizing unwrappable blocks. A follow-up patch will address the more
     12        complex issue of unwrappable inline elements.
     13
     14        Tests: fast/text-autosizing/unwrappable-blocks.html
     15               fast/text-autosizing/unwrappable-inlines.html
     16
     17        * rendering/TextAutosizer.cpp:
     18        (WebCore::TextAutosizer::processContainer):
     19            Use containerShouldbeAutosized instead of contentHeightIsConstrained.
     20        (WebCore::contentHeightIsConstrained):
     21            Unchanged, just moved lower down the file.
     22        (WebCore::TextAutosizer::containerShouldbeAutosized):
     23            Checks that the block is wrappable, and also that contentHeightIsConstrained is false.
     24        (WebCore::TextAutosizer::measureDescendantTextWidth):
     25            Use containerShouldbeAutosized instead of contentHeightIsConstrained.
     26        * rendering/TextAutosizer.h:
     27            Declared containerShouldbeAutosized.
     28
    1292012-12-14  Vsevolod Vlasov  <vsevik@chromium.org>
    230
  • trunk/Source/WebCore/rendering/TextAutosizer.cpp

    r136411 r137738  
    120120}
    121121
    122 static bool contentHeightIsConstrained(const RenderBlock* container)
    123 {
    124     // FIXME: Propagate constrainedness down the tree, to avoid inefficiently walking back up from each box.
    125     // FIXME: This code needs to take into account vertical writing modes.
    126     // FIXME: Consider additional heuristics, such as ignoring fixed heights if the content is already overflowing before autosizing kicks in.
    127     for (; container; container = container->containingBlock()) {
    128         RenderStyle* style = container->style();
    129         if (style->overflowY() >= OSCROLL)
    130             return false;
    131         if (style->height().isSpecified() || style->maxHeight().isSpecified()) {
    132             // Some sites (e.g. wikipedia) set their html and/or body elements to height:100%,
    133             // without intending to constrain the height of the content within them.
    134             return !container->isRoot() && !container->isBody();
    135         }
    136         if (container->isFloatingOrOutOfFlowPositioned())
    137             return false;
    138     }
    139     return false;
    140 }
    141 
    142122void TextAutosizer::processContainer(float multiplier, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo)
    143123{
    144124    ASSERT(isAutosizingContainer(container));
    145125
    146     float localMultiplier = contentHeightIsConstrained(container) ? 1 : multiplier;
     126    float localMultiplier = containerShouldbeAutosized(container) ? multiplier: 1;
    147127
    148128    RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(subtreeRoot, subtreeRoot);
     
    251231}
    252232
     233static bool contentHeightIsConstrained(const RenderBlock* container)
     234{
     235    // FIXME: Propagate constrainedness down the tree, to avoid inefficiently walking back up from each box.
     236    // FIXME: This code needs to take into account vertical writing modes.
     237    // FIXME: Consider additional heuristics, such as ignoring fixed heights if the content is already overflowing before autosizing kicks in.
     238    for (; container; container = container->containingBlock()) {
     239        RenderStyle* style = container->style();
     240        if (style->overflowY() >= OSCROLL)
     241            return false;
     242        if (style->height().isSpecified() || style->maxHeight().isSpecified()) {
     243            // Some sites (e.g. wikipedia) set their html and/or body elements to height:100%,
     244            // without intending to constrain the height of the content within them.
     245            return !container->isRoot() && !container->isBody();
     246        }
     247        if (container->isFloatingOrOutOfFlowPositioned())
     248            return false;
     249    }
     250    return false;
     251}
     252
     253bool TextAutosizer::containerShouldbeAutosized(const RenderBlock* container)
     254{
     255    // Don't autosize block-level text that can't wrap (as it's likely to
     256    // expand sideways and break the page's layout).
     257    if (!container->style()->autoWrap())
     258        return false;
     259
     260    return !contentHeightIsConstrained(container);
     261}
     262
    253263bool TextAutosizer::clusterShouldBeAutosized(const RenderBlock* lowestCommonAncestor, float commonAncestorWidth)
    254264{
     
    274284void TextAutosizer::measureDescendantTextWidth(const RenderBlock* container, float minTextWidth, float& textWidth)
    275285{
    276     bool skipLocalText = contentHeightIsConstrained(container);
     286    bool skipLocalText = !containerShouldbeAutosized(container);
    277287
    278288    RenderObject* descendant = nextInPreOrderSkippingDescendantsOfContainers(container, container);
  • trunk/Source/WebCore/rendering/TextAutosizer.h

    r136047 r137738  
    7171    static bool isAutosizingCluster(const RenderBlock*);
    7272
     73    static bool containerShouldbeAutosized(const RenderBlock* container);
    7374    static bool clusterShouldBeAutosized(const RenderBlock* lowestCommonAncestor, float commonAncestorWidth);
    7475    static void measureDescendantTextWidth(const RenderBlock* container, float minTextWidth, float& textWidth);
Note: See TracChangeset for help on using the changeset viewer.