Changeset 142287 in webkit


Ignore:
Timestamp:
Feb 8, 2013 8:40:52 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[Text Autosizing] Split isAutosizingCluster into three independent checks
https://bugs.webkit.org/show_bug.cgi?id=109093

Refactoring to create more flexible version of isAutosizingCluster since there're more types
of autosizing cluster now: narrower than the parent cluster, wider than the parent cluster
and the one that doesn't depend on the parent cluster.

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

Refactoring, no test changes.

  • rendering/TextAutosizer.cpp:

(WebCore::TextAutosizer::isNarrowDescendant):

Separate check for the container to be of the narrow-descendant type. Was a part of
isAutosizingCluster().

(WebCore::TextAutosizer::isWiderDescendant):

Separate check for the container to be of the wider-descendant type. Was a part of
isAutosizingCluster().

(WebCore::TextAutosizer::isIndependentDescendant):

Separate check for the container to be autosized separately from the ancestor cluster.
Checks for conditions independent of the aforementioned cluster.

(WebCore::TextAutosizer::isAutosizingCluster):

Handy method to check all separate conditions together.

(WebCore::TextAutosizer::processSubtree):
(WebCore::TextAutosizer::processCluster):
(WebCore::TextAutosizer::processContainer):
(WebCore::TextAutosizer::clusterShouldBeAutosized):
(WebCore::TextAutosizer::measureDescendantTextWidth):
(WebCore::TextAutosizer::findFirstTextLeafNotInCluster):

The methods above were updated to use new functions/arguments.

  • rendering/TextAutosizer.h:

Updated/added method definitions.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r142283 r142287  
     12013-02-08  Anton Vayvod  <avayvod@chromium.org>
     2
     3        [Text Autosizing] Split isAutosizingCluster into three independent checks
     4        https://bugs.webkit.org/show_bug.cgi?id=109093
     5
     6        Refactoring to create more flexible version of isAutosizingCluster since there're more types
     7        of autosizing cluster now: narrower than the parent cluster, wider than the parent cluster
     8        and the one that doesn't depend on the parent cluster.
     9
     10        Reviewed by Kenneth Rohde Christiansen.
     11
     12        Refactoring, no test changes.
     13
     14        * rendering/TextAutosizer.cpp:
     15
     16        (WebCore::TextAutosizer::isNarrowDescendant):
     17
     18            Separate check for the container to be of the narrow-descendant type. Was a part of
     19            isAutosizingCluster().
     20
     21        (WebCore::TextAutosizer::isWiderDescendant):
     22
     23            Separate check for the container to be of the wider-descendant type. Was a part of
     24            isAutosizingCluster().
     25
     26        (WebCore::TextAutosizer::isIndependentDescendant):
     27
     28            Separate check for the container to be autosized separately from the ancestor cluster.
     29            Checks for conditions independent of the aforementioned cluster.
     30
     31        (WebCore::TextAutosizer::isAutosizingCluster):
     32
     33            Handy method to check all separate conditions together.
     34
     35        (WebCore::TextAutosizer::processSubtree):
     36        (WebCore::TextAutosizer::processCluster):
     37        (WebCore::TextAutosizer::processContainer):
     38        (WebCore::TextAutosizer::clusterShouldBeAutosized):
     39        (WebCore::TextAutosizer::measureDescendantTextWidth):
     40        (WebCore::TextAutosizer::findFirstTextLeafNotInCluster):
     41
     42            The methods above were updated to use new functions/arguments.
     43
     44        * rendering/TextAutosizer.h:
     45
     46            Updated/added method definitions.
     47
    1482013-02-08  Vsevolod Vlasov  <vsevik@chromium.org>
    249
  • trunk/Source/WebCore/rendering/TextAutosizer.cpp

    r141901 r142287  
    120120
    121121    RenderBlock* cluster = container;
    122     while (cluster && !isAutosizingCluster(cluster))
     122    while (cluster && (!isAutosizingContainer(cluster) || !isIndependentDescendant(cluster)))
    123123        cluster = cluster->containingBlock();
    124124
     
    236236}
    237237
    238 bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
    239 {
     238bool TextAutosizer::isNarrowDescendant(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
     239{
     240    ASSERT(isAutosizingContainer(renderer));
     241
     242    // Autosizing containers that are significantly narrower than the |blockContainingAllText| of
     243    // their enclosing cluster may be acting as separate columns, hence must be autosized
     244    // separately. For example the 2nd div in:
     245    // <body>
     246    //     <div style="float: right; width: 50%"></div>
     247    //     <div style="width: 50%"></div>
     248    // <body>
     249    // is the left column, and should be autosized differently from the body.
     250    // If however the container is only narrower by 150px or less, it's considered part of
     251    // the enclosing cluster. This 150px limit is adjusted whenever a descendant container is
     252    // less than 50px narrower than the current limit.
     253    const float differenceFromMaxWidthDifference = 50;
     254    float contentWidth = renderer->contentLogicalWidth();
     255    float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
     256    float widthDifference = clusterTextWidth - contentWidth;
     257
     258    if (widthDifference - parentClusterInfo->maxAllowedDifferenceFromTextWidth > differenceFromMaxWidthDifference)
     259        return true;
     260
     261    parentClusterInfo->maxAllowedDifferenceFromTextWidth = std::max(widthDifference, parentClusterInfo->maxAllowedDifferenceFromTextWidth);
     262    return false;
     263}
     264
     265bool TextAutosizer::isWiderDescendant(const RenderBlock* renderer, const TextAutosizingClusterInfo* parentClusterInfo)
     266{
     267    ASSERT(isAutosizingContainer(renderer));
     268
     269    // Autosizing containers that are wider than the |blockContainingAllText| of their enclosing
     270    // cluster are treated the same way as autosizing clusters to be autosized separately.
     271    float contentWidth = renderer->contentLogicalWidth();
     272    float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
     273    return contentWidth > clusterTextWidth;
     274}
     275
     276bool TextAutosizer::isIndependentDescendant(const RenderBlock* renderer)
     277{
     278    ASSERT(isAutosizingContainer(renderer));
     279
    240280    // "Autosizing clusters" are special autosizing containers within which we
    241281    // want to enforce a uniform text size multiplier, in the hopes of making
     
    257297    // width blocks within a cluster, since the narrower blocks would end up
    258298    // larger than would otherwise be necessary).
    259     // Additionally, any containers that are wider or at least 200px narrower than
    260     // the |blockContainingAllText| of their enclosing cluster also become clusters,
    261     // since they need special treatment due to their width.
    262     ASSERT(isAutosizingContainer(renderer));
    263 
    264     if (parentClusterInfo->blockContainingAllText) {
    265         float contentWidth = renderer->contentLogicalWidth();
    266         float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
    267         if (contentWidth > clusterTextWidth)
    268             return true;
    269 
    270         // The upper limit on how many pixels the difference between the renderer width
    271         // and its parent cluster width can exceed the current maximum difference by
    272         // before the object is considered to be a separate autosizing cluster.
    273         const float differenceFromMaxWidthDifference = 50;
    274 
    275         float widthDifference = clusterTextWidth - contentWidth;
    276         if (widthDifference - parentClusterInfo->maxAllowedDifferenceFromTextWidth > differenceFromMaxWidthDifference)
    277             return true;
    278         parentClusterInfo->maxAllowedDifferenceFromTextWidth = std::max(widthDifference, parentClusterInfo->maxAllowedDifferenceFromTextWidth);
    279     }
    280 
    281299    return renderer->isRenderView()
    282300        || renderer->isFloating()
     
    293311}
    294312
    295 bool TextAutosizer::isAutosizingCluster(const RenderObject* object)
    296 {
    297     TextAutosizingClusterInfo emptyClusterInfo(0);
    298     return isAutosizingContainer(object) && isAutosizingCluster(toRenderBlock(object), &emptyClusterInfo);
     313bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
     314{
     315    ASSERT(isAutosizingContainer(renderer));
     316
     317    return isNarrowDescendant(renderer, parentClusterInfo)
     318        || isWiderDescendant(renderer, parentClusterInfo)
     319        || isIndependentDescendant(renderer);
    299320}
    300321
     
    487508    const RenderObject* child = (direction == FirstToLast) ? parent->firstChild() : parent->lastChild();
    488509    while (child) {
    489         if (!isAutosizingCluster(child)) {
     510        if (!isAutosizingContainer(child) || !isIndependentDescendant(toRenderBlock(child))) {
    490511            const RenderObject* leaf = findFirstTextLeafNotInCluster(child, depth, direction);
    491512            if (leaf)
  • trunk/Source/WebCore/rendering/TextAutosizer.h

    r141901 r142287  
    6868
    6969    static bool isAutosizingContainer(const RenderObject*);
     70    static bool isNarrowDescendant(const RenderBlock*, TextAutosizingClusterInfo* parentClusterInfo);
     71    static bool isWiderDescendant(const RenderBlock*, const TextAutosizingClusterInfo* parentClusterInfo);
     72    static bool isIndependentDescendant(const RenderBlock*);
    7073    static bool isAutosizingCluster(const RenderBlock*, TextAutosizingClusterInfo* parentClusterInfo);
    71     static bool isAutosizingCluster(const RenderObject*);
    7274
    7375    static bool containerShouldBeAutosized(const RenderBlock* container);
Note: See TracChangeset for help on using the changeset viewer.