+2013-02-08 Anton Vayvod <avayvod@chromium.org>
+
+ [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.
+
+ 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.
+
2013-02-08 Vsevolod Vlasov <vsevik@chromium.org>
Web Inspector: Extension sever should use Workspace.projectForType() instead of Workspace.project()
container = container->containingBlock();
RenderBlock* cluster = container;
- while (cluster && !isAutosizingCluster(cluster))
+ while (cluster && (!isAutosizingContainer(cluster) || !isIndependentDescendant(cluster)))
cluster = cluster->containingBlock();
TextAutosizingClusterInfo clusterInfo(cluster);
return true;
}
-bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
+bool TextAutosizer::isNarrowDescendant(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
+{
+ ASSERT(isAutosizingContainer(renderer));
+
+ // Autosizing containers that are significantly narrower than the |blockContainingAllText| of
+ // their enclosing cluster may be acting as separate columns, hence must be autosized
+ // separately. For example the 2nd div in:
+ // <body>
+ // <div style="float: right; width: 50%"></div>
+ // <div style="width: 50%"></div>
+ // <body>
+ // is the left column, and should be autosized differently from the body.
+ // If however the container is only narrower by 150px or less, it's considered part of
+ // the enclosing cluster. This 150px limit is adjusted whenever a descendant container is
+ // less than 50px narrower than the current limit.
+ const float differenceFromMaxWidthDifference = 50;
+ float contentWidth = renderer->contentLogicalWidth();
+ float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
+ float widthDifference = clusterTextWidth - contentWidth;
+
+ if (widthDifference - parentClusterInfo->maxAllowedDifferenceFromTextWidth > differenceFromMaxWidthDifference)
+ return true;
+
+ parentClusterInfo->maxAllowedDifferenceFromTextWidth = std::max(widthDifference, parentClusterInfo->maxAllowedDifferenceFromTextWidth);
+ return false;
+}
+
+bool TextAutosizer::isWiderDescendant(const RenderBlock* renderer, const TextAutosizingClusterInfo* parentClusterInfo)
{
+ ASSERT(isAutosizingContainer(renderer));
+
+ // Autosizing containers that are wider than the |blockContainingAllText| of their enclosing
+ // cluster are treated the same way as autosizing clusters to be autosized separately.
+ float contentWidth = renderer->contentLogicalWidth();
+ float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
+ return contentWidth > clusterTextWidth;
+}
+
+bool TextAutosizer::isIndependentDescendant(const RenderBlock* renderer)
+{
+ ASSERT(isAutosizingContainer(renderer));
+
// "Autosizing clusters" are special autosizing containers within which we
// want to enforce a uniform text size multiplier, in the hopes of making
// the major sections of the page look internally consistent.
// from the box's parent (we want to avoid having significantly different
// width blocks within a cluster, since the narrower blocks would end up
// larger than would otherwise be necessary).
- // Additionally, any containers that are wider or at least 200px narrower than
- // the |blockContainingAllText| of their enclosing cluster also become clusters,
- // since they need special treatment due to their width.
- ASSERT(isAutosizingContainer(renderer));
-
- if (parentClusterInfo->blockContainingAllText) {
- float contentWidth = renderer->contentLogicalWidth();
- float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
- if (contentWidth > clusterTextWidth)
- return true;
-
- // The upper limit on how many pixels the difference between the renderer width
- // and its parent cluster width can exceed the current maximum difference by
- // before the object is considered to be a separate autosizing cluster.
- const float differenceFromMaxWidthDifference = 50;
-
- float widthDifference = clusterTextWidth - contentWidth;
- if (widthDifference - parentClusterInfo->maxAllowedDifferenceFromTextWidth > differenceFromMaxWidthDifference)
- return true;
- parentClusterInfo->maxAllowedDifferenceFromTextWidth = std::max(widthDifference, parentClusterInfo->maxAllowedDifferenceFromTextWidth);
- }
-
return renderer->isRenderView()
|| renderer->isFloating()
|| renderer->isOutOfFlowPositioned()
// containers, and probably flexboxes...
}
-bool TextAutosizer::isAutosizingCluster(const RenderObject* object)
+bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
{
- TextAutosizingClusterInfo emptyClusterInfo(0);
- return isAutosizingContainer(object) && isAutosizingCluster(toRenderBlock(object), &emptyClusterInfo);
+ ASSERT(isAutosizingContainer(renderer));
+
+ return isNarrowDescendant(renderer, parentClusterInfo)
+ || isWiderDescendant(renderer, parentClusterInfo)
+ || isIndependentDescendant(renderer);
}
bool TextAutosizer::containerShouldBeAutosized(const RenderBlock* container)
++depth;
const RenderObject* child = (direction == FirstToLast) ? parent->firstChild() : parent->lastChild();
while (child) {
- if (!isAutosizingCluster(child)) {
+ if (!isAutosizingContainer(child) || !isIndependentDescendant(toRenderBlock(child))) {
const RenderObject* leaf = findFirstTextLeafNotInCluster(child, depth, direction);
if (leaf)
return leaf;