Changeset 143318 in webkit


Ignore:
Timestamp:
Feb 19, 2013 4:45:26 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[Text Autosizing] Combine narrow descendants of a cluster into groups that should be autosized with the same multiplier.
https://bugs.webkit.org/show_bug.cgi?id=109825

Source/WebCore:

Enhancement of the approach introduced in https://bugs.webkit.org/show_bug.cgi?id=109573.
Instead of using the same text size multiplier for all narrow descendants of any autosizing
cluster, group the descendants by how much narrower they are than the cluster's
|blockContainingAllText| and process each group separately with a different multiplier for
each one.
For example, we want nested comments on the page to be autosized as a group but separately
from a sidebar on the same page.

Patch by Anton Vayvod <avayvod@chromium.org> on 2013-02-19
Reviewed by Kenneth Rohde Christiansen.

Updated the existing test to verify the patch.

  • rendering/TextAutosizer.cpp:

(WebCore::TextAutosizer::processClusterInternal):

Splits the narrow descendants of the autosizing cluster into groups before processing
each group individually.

(WebCore::TextAutosizer::getNarrowDescendantsGroupedByWidth):

Sorts the narrow descendants of the given cluster into groups, combining them by the
difference between their content widths. If sorted by width, two consecutive nodes
belong to the same group if their width difference is no greater than 100 CSS units.

  • rendering/TextAutosizer.h:

New method definitions.

LayoutTests:

Verify that narrow descendants are grouped and autosized separately according to the
difference between the descendant's width and the width of its enclosing cluster's
|blockContainingAllText|.

Patch by Anton Vayvod <avayvod@chromium.org> on 2013-02-19
Reviewed by Kenneth Rohde Christiansen.

  • fast/text-autosizing/narrow-descendants-combined-expected.html:
  • fast/text-autosizing/narrow-descendants-combined.html:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r143315 r143318  
     12013-02-19  Anton Vayvod  <avayvod@chromium.org>
     2
     3        [Text Autosizing] Combine narrow descendants of a cluster into groups that should be autosized with the same multiplier.
     4        https://bugs.webkit.org/show_bug.cgi?id=109825
     5
     6        Verify that narrow descendants are grouped and autosized separately according to the
     7        difference between the descendant's width and the width of its enclosing cluster's
     8        |blockContainingAllText|.
     9
     10        Reviewed by Kenneth Rohde Christiansen.
     11
     12        * fast/text-autosizing/narrow-descendants-combined-expected.html:
     13        * fast/text-autosizing/narrow-descendants-combined.html:
     14
    1152013-02-19  Takashi Toyoshima  <toyoshim@chromium.org>
    216
  • trunk/LayoutTests/fast/text-autosizing/narrow-descendants-combined-expected.html

    r142866 r143318  
    1313
    1414<div style="font-size: 1.25rem">
     15    <div style="width: 240px">
     16        This text should be autosized to 20px computed font-size as it is combined with the next and the last narrow siblings and the maximum width is 400px.
     17    </div>
    1518    <div style="width: 320px">
    16         This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
     19        This text should be autosized to 20px computed font-size as it is combined with the first and the last narrow siblings and the maximum width is 400px.
     20    </div>
     21    <div style="width: 560px; font-size: 1.75rem">
     22        This text should be autosized to 28px computed font-size as it is combined into a separate group from its two siblings since it's significantly wider.<br>
     23        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    1724    </div>
    1825    <div style="width: 400px">
    19         This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
    20     </div>
    21     <div style="width: 240px">
    22         This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
     26        This text should be autosized to 20px computed font-size as it is combined with the first and the second narrow siblings and the maximum width is 400px.<br>
     27        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    2328    </div>
    2429</div>
  • trunk/LayoutTests/fast/text-autosizing/narrow-descendants-combined.html

    r142866 r143318  
    2222
    2323<div>
     24    <div style="width: 240px">
     25        This text should be autosized to 20px computed font-size as it is combined with the next and the last narrow siblings and the maximum width is 400px.
     26    </div>
    2427    <div style="width: 320px">
    25         This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
     28        This text should be autosized to 20px computed font-size as it is combined with the first and the last narrow siblings and the maximum width is 400px.
     29    </div>
     30    <div style="width: 560px">
     31        This text should be autosized to 28px computed font-size as it is combined into a separate group from its two siblings since it's significantly wider.<br>
     32        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    2633    </div>
    2734    <div style="width: 400px">
    28         This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
    29     </div>
    30     <div style="width: 240px">
    31         This text should be autosized to 20px computed font-size as it is combined with its narrow siblings and the maximum width is 400px.
     35        This text should be autosized to 20px computed font-size as it is combined with the first and the second narrow siblings and the maximum width is 400px.<br>
     36        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    3237    </div>
    3338</div>
  • trunk/Source/WebCore/ChangeLog

    r143317 r143318  
     12013-02-19  Anton Vayvod  <avayvod@chromium.org>
     2
     3        [Text Autosizing] Combine narrow descendants of a cluster into groups that should be autosized with the same multiplier.
     4        https://bugs.webkit.org/show_bug.cgi?id=109825
     5
     6        Enhancement of the approach introduced in https://bugs.webkit.org/show_bug.cgi?id=109573.
     7        Instead of using the same text size multiplier for all narrow descendants of any autosizing
     8        cluster, group the descendants by how much narrower they are than the cluster's
     9        |blockContainingAllText| and process each group separately with a different multiplier for
     10        each one.
     11        For example, we want nested comments on the page to be autosized as a group but separately
     12        from a sidebar on the same page.
     13
     14        Reviewed by Kenneth Rohde Christiansen.
     15
     16        Updated the existing test to verify the patch.
     17
     18        * rendering/TextAutosizer.cpp:
     19        (WebCore::TextAutosizer::processClusterInternal):
     20
     21            Splits the narrow descendants of the autosizing cluster into groups before processing
     22            each group individually.
     23
     24        (WebCore::TextAutosizer::getNarrowDescendantsGroupedByWidth):
     25
     26            Sorts the narrow descendants of the given cluster into groups, combining them by the
     27            difference between their content widths. If sorted by width, two consecutive nodes
     28            belong to the same group if their width difference is no greater than 100 CSS units.
     29
     30        * rendering/TextAutosizer.h:
     31
     32            New method definitions.
     33
    1342013-02-18  Ilya Tikhonovsky  <loislo@chromium.org>
    235
  • trunk/Source/WebCore/rendering/TextAutosizer.cpp

    r143295 r143318  
    150150    processContainer(multiplier, container, clusterInfo, subtreeRoot, windowInfo);
    151151
    152     processCompositeCluster(clusterInfo.narrowDescendants, windowInfo);
     152    Vector<Vector<TextAutosizingClusterInfo> > narrowDescendantsGroups;
     153    getNarrowDescendantsGroupedByWidth(clusterInfo, narrowDescendantsGroups);
     154    for (size_t i = 0; i < narrowDescendantsGroups.size(); ++i)
     155        processCompositeCluster(narrowDescendantsGroups[i], windowInfo);
    153156}
    154157
     
    557560}
    558561
     562namespace {
     563
     564// Compares the width of the specified cluster's roots in descending order.
     565bool clusterWiderThanComparisonFn(const TextAutosizingClusterInfo& first, const TextAutosizingClusterInfo& second)
     566{
     567    return first.root->contentLogicalWidth() > second.root->contentLogicalWidth();
     568}
     569
     570} // namespace
     571
     572void TextAutosizer::getNarrowDescendantsGroupedByWidth(const TextAutosizingClusterInfo& parentClusterInfo, Vector<Vector<TextAutosizingClusterInfo> >& groups)
     573{
     574    ASSERT(parentClusterInfo.blockContainingAllText);
     575    ASSERT(groups.isEmpty());
     576
     577    Vector<TextAutosizingClusterInfo> clusterInfos(parentClusterInfo.narrowDescendants);
     578    if (clusterInfos.isEmpty())
     579        return;
     580
     581    std::sort(clusterInfos.begin(), clusterInfos.end(), &clusterWiderThanComparisonFn);
     582    groups.grow(1);
     583
     584    // If the width difference between two consecutive elements of |clusterInfos| is greater than
     585    // this empirically determined value, the next element should start a new group.
     586    const float maxWidthDifferenceWithinGroup = 100;
     587    for (size_t i = 0; i < clusterInfos.size(); ++i) {
     588        groups.last().append(clusterInfos[i]);
     589
     590        if (i + 1 < clusterInfos.size()) {
     591            float currentWidth = clusterInfos[i].root->contentLogicalWidth();
     592            float nextWidth = clusterInfos[i + 1].root->contentLogicalWidth();
     593            if (currentWidth - nextWidth > maxWidthDifferenceWithinGroup)
     594                groups.grow(groups.size() + 1);
     595        }
     596    }
     597}
     598
    559599} // namespace WebCore
    560600
  • trunk/Source/WebCore/rendering/TextAutosizer.h

    r142866 r143318  
    9292    static const RenderObject* findFirstTextLeafNotInCluster(const RenderObject*, size_t& depth, TraversalDirection);
    9393
     94    // Returns groups of narrow descendants of a given autosizing cluster. The groups are combined
     95    // by the difference between the width of the descendant and the width of the parent cluster's
     96    // |blockContainingAllText|.
     97    static void getNarrowDescendantsGroupedByWidth(const TextAutosizingClusterInfo& parentClusterInfo, Vector<Vector<TextAutosizingClusterInfo> >&);
     98
    9499    Document* m_document;
    95100};
Note: See TracChangeset for help on using the changeset viewer.