Changeset 142866 in webkit


Ignore:
Timestamp:
Feb 14, 2013 4:09:18 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[Text Autosizing] Process narrow descendants with the same multiplier for the font size.
https://bugs.webkit.org/show_bug.cgi?id=109573

Source/WebCore:

Patch by Anton Vayvod <avayvod@chromium.org> on 2013-02-14
Reviewed by Julien Chaffraix.

Combine narrow descendants of the same autosizing cluster into a group that is autosized
with the same multiplier.

For example, on sites with a sidebar, sometimes the paragraphs next to the sidebar will have
a large margin individually applied (via a CSS selector), causing them all to individually
appear narrower than their enclosing blockContainingAllText. Rather than making each of
these paragraphs into a separate cluster, we want them all to share the same multiplier, as
if they were a single cluster.

Test: fast/text-autosizing/narrow-descendants-combined.html

  • rendering/TextAutosizer.cpp:

(WebCore::TextAutosizer::processClusterInternal):

Common implementation for processCluster() and processCompositeCluster that accepts the
text width and whether the cluster should be autosized as parameters instead of
calculating it inline.

(WebCore::TextAutosizer::processCluster):

Calculates the text width for a single cluster and whether it should be autosized, then
calls processClusterInternal() to apply the multiplier and process the cluster's
descendants.

(WebCore::TextAutosizer::processCompositeCluster):

Calculates the text width for a group of renderers and if the group should be autosized,
then calls processClusterInternal() repeatedly with the same multiplier to apply it and
process all the descendants of the group.

(WebCore::TextAutosizer::clusterShouldBeAutosized):

Calls the multiple renderers version to avoid code duplication.

(WebCore::TextAutosizer::compositeClusterShouldBeAutosized):

The multiple renderers version of clusterShouldBeAutosized.

  • rendering/TextAutosizer.h:

Updated method declarations.

LayoutTests:

Test to verify that all narrow descendants of a cluster are autosized with the same
multiplier.

Patch by Anton Vayvod <avayvod@chromium.org> on 2013-02-14
Reviewed by Julien Chaffraix.

  • fast/text-autosizing/narrow-descendants-combined-expected.html: Added.
  • fast/text-autosizing/narrow-descendants-combined.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r142861 r142866  
     12013-02-14  Anton Vayvod  <avayvod@chromium.org>
     2
     3        [Text Autosizing] Process narrow descendants with the same multiplier for the font size.
     4        https://bugs.webkit.org/show_bug.cgi?id=109573
     5
     6        Test to verify that all narrow descendants of a cluster are autosized with the same
     7        multiplier.
     8
     9        Reviewed by Julien Chaffraix.
     10
     11        * fast/text-autosizing/narrow-descendants-combined-expected.html: Added.
     12        * fast/text-autosizing/narrow-descendants-combined.html: Added.
     13
    1142013-02-14  Aivo Paas  <aivopaas@gmail.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r142865 r142866  
     12013-02-14  Anton Vayvod  <avayvod@chromium.org>
     2
     3        [Text Autosizing] Process narrow descendants with the same multiplier for the font size.
     4        https://bugs.webkit.org/show_bug.cgi?id=109573
     5
     6        Reviewed by Julien Chaffraix.
     7
     8        Combine narrow descendants of the same autosizing cluster into a group that is autosized
     9        with the same multiplier.
     10
     11        For example, on sites with a sidebar, sometimes the paragraphs next to the sidebar will have
     12        a large margin individually applied (via a CSS selector), causing them all to individually
     13        appear narrower than their enclosing blockContainingAllText. Rather than making each of
     14        these paragraphs into a separate cluster, we want them all to share the same multiplier, as
     15        if they were a single cluster.
     16
     17        Test: fast/text-autosizing/narrow-descendants-combined.html
     18
     19        * rendering/TextAutosizer.cpp:
     20        (WebCore::TextAutosizer::processClusterInternal):
     21
     22            Common implementation for processCluster() and processCompositeCluster that accepts the
     23            text width and whether the cluster should be autosized as parameters instead of
     24            calculating it inline.
     25
     26        (WebCore::TextAutosizer::processCluster):
     27
     28            Calculates the text width for a single cluster and whether it should be autosized, then
     29            calls processClusterInternal() to apply the multiplier and process the cluster's
     30            descendants.
     31
     32        (WebCore::TextAutosizer::processCompositeCluster):
     33
     34            Calculates the text width for a group of renderers and if the group should be autosized,
     35            then calls processClusterInternal() repeatedly with the same multiplier to apply it and
     36            process all the descendants of the group.
     37
     38        (WebCore::TextAutosizer::clusterShouldBeAutosized):
     39
     40            Calls the multiple renderers version to avoid code duplication.
     41
     42        (WebCore::TextAutosizer::compositeClusterShouldBeAutosized):
     43
     44            The multiple renderers version of clusterShouldBeAutosized.
     45
     46        * rendering/TextAutosizer.h:
     47
     48            Updated method declarations.
     49
    1502013-02-14  Andrey Adaikin  <aandrey@chromium.org>
    251
  • trunk/Source/WebCore/rendering/TextAutosizer.cpp

    r142534 r142866  
    134134}
    135135
    136 void TextAutosizer::processCluster(TextAutosizingClusterInfo& clusterInfo, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo)
    137 {
    138     // Many pages set a max-width on their content. So especially for the
    139     // RenderView, instead of just taking the width of |cluster| we find
    140     // the lowest common ancestor of the first and last descendant text node of
    141     // the cluster (i.e. the deepest wrapper block that contains all the text),
    142     // and use its width instead.
    143     clusterInfo.blockContainingAllText = findDeepestBlockContainingAllText(clusterInfo.root);
    144     float textWidth = clusterInfo.blockContainingAllText->contentLogicalWidth();
    145 
     136void TextAutosizer::processClusterInternal(TextAutosizingClusterInfo& clusterInfo, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo, float textWidth, bool shouldBeAutosized)
     137{
    146138    float multiplier = 1;
    147     if (clusterShouldBeAutosized(clusterInfo, textWidth)) {
     139    if (shouldBeAutosized) {
    148140        int logicalWindowWidth = clusterInfo.root->isHorizontalWritingMode() ? windowInfo.windowSize.width() : windowInfo.windowSize.height();
    149141        int logicalLayoutWidth = clusterInfo.root->isHorizontalWritingMode() ? windowInfo.minLayoutSize.width() : windowInfo.minLayoutSize.height();
     
    158150    processContainer(multiplier, container, clusterInfo, subtreeRoot, windowInfo);
    159151
    160     Vector<TextAutosizingClusterInfo>& narrowDescendants = clusterInfo.narrowDescendants;
    161     for (size_t i = 0; i < narrowDescendants.size(); ++i) {
    162         TextAutosizingClusterInfo& descendantClusterInfo = narrowDescendants[i];
    163         processCluster(descendantClusterInfo, descendantClusterInfo.root, descendantClusterInfo.root, windowInfo);
    164     }
     152    processCompositeCluster(clusterInfo.narrowDescendants, windowInfo);
     153}
     154
     155void TextAutosizer::processCluster(TextAutosizingClusterInfo& clusterInfo, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo& windowInfo)
     156{
     157    // Many pages set a max-width on their content. So especially for the RenderView, instead of
     158    // just taking the width of |cluster| we find the lowest common ancestor of the first and last
     159    // descendant text node of the cluster (i.e. the deepest wrapper block that contains all the
     160    // text), and use its width instead.
     161    clusterInfo.blockContainingAllText = findDeepestBlockContainingAllText(clusterInfo.root);
     162    float textWidth = clusterInfo.blockContainingAllText->contentLogicalWidth();
     163    processClusterInternal(clusterInfo, container, subtreeRoot, windowInfo, textWidth, clusterShouldBeAutosized(clusterInfo, textWidth));
     164}
     165
     166void TextAutosizer::processCompositeCluster(Vector<TextAutosizingClusterInfo>& clusterInfos, const TextAutosizingWindowInfo& windowInfo)
     167{
     168    float maxTextWidth = 0;
     169    for (size_t i = 0; i < clusterInfos.size(); ++i) {
     170        TextAutosizingClusterInfo& clusterInfo = clusterInfos[i];
     171        clusterInfo.blockContainingAllText = findDeepestBlockContainingAllText(clusterInfo.root);
     172        maxTextWidth = max<float>(maxTextWidth, clusterInfo.blockContainingAllText->contentLogicalWidth());
     173    }
     174
     175    bool shouldBeAutosized = compositeClusterShouldBeAutosized(clusterInfos, maxTextWidth);
     176    for (size_t i = 0; i < clusterInfos.size(); ++i)
     177        processClusterInternal(clusterInfos[i], clusterInfos[i].root, clusterInfos[i].root, windowInfo, maxTextWidth, shouldBeAutosized);
    165178}
    166179
     
    429442bool TextAutosizer::clusterShouldBeAutosized(TextAutosizingClusterInfo& clusterInfo, float blockWidth)
    430443{
     444    Vector<TextAutosizingClusterInfo> clusterInfos(1, clusterInfo);
     445    return compositeClusterShouldBeAutosized(clusterInfos, blockWidth);
     446}
     447
     448bool TextAutosizer::compositeClusterShouldBeAutosized(Vector<TextAutosizingClusterInfo>& clusterInfos, float blockWidth)
     449{
    431450    // Don't autosize clusters that contain less than 4 lines of text (in
    432451    // practice less lines are required, since measureDescendantTextWidth
     
    439458    // in and pan from side to side to read each line, since if there are very
    440459    // few lines of text you'll only need to pan across once or twice.
     460    float totalTextWidth = 0;
    441461    const float minLinesOfText = 4;
    442462    float minTextWidth = blockWidth * minLinesOfText;
    443     float textWidth = 0;
    444     measureDescendantTextWidth(clusterInfo.blockContainingAllText, clusterInfo, minTextWidth, textWidth);
    445     if (textWidth >= minTextWidth)
    446         return true;
     463    for (size_t i = 0; i < clusterInfos.size(); ++i) {
     464        measureDescendantTextWidth(clusterInfos[i].blockContainingAllText, clusterInfos[i], minTextWidth, totalTextWidth);
     465        if (totalTextWidth >= minTextWidth)
     466            return true;
     467    }
    447468    return false;
    448469}
  • trunk/Source/WebCore/rendering/TextAutosizer.h

    r142367 r142866  
    6262    explicit TextAutosizer(Document*);
    6363
     64    void processClusterInternal(TextAutosizingClusterInfo&, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&, float textWidth, bool shouldBeAutosized);
    6465    void processCluster(TextAutosizingClusterInfo&, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&);
     66    void processCompositeCluster(Vector<TextAutosizingClusterInfo>&, const TextAutosizingWindowInfo&);
    6567    void processContainer(float multiplier, RenderBlock* container, TextAutosizingClusterInfo&, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&);
    6668
     
    7880    static bool contentHeightIsConstrained(const RenderBlock* container);
    7981    static bool clusterShouldBeAutosized(TextAutosizingClusterInfo&, float blockWidth);
     82    static bool compositeClusterShouldBeAutosized(Vector<TextAutosizingClusterInfo>&, float blockWidth);
    8083    static void measureDescendantTextWidth(const RenderBlock* container, TextAutosizingClusterInfo&, float minTextWidth, float& textWidth);
    8184
Note: See TracChangeset for help on using the changeset viewer.