Source/WebCore/ChangeLog

 12013-02-07 Anton Vayvod <avayvod@chromium.org>
 2
 3 [Text Autosizing] Refactor isAutosizingCluster.
 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 NOBODY (OOPS!).
 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 Handful 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-06 Tom Sepez <tsepez@chromium.org>
249
350 document.referrer leakage with XSS Auditor page block

Source/WebCore/rendering/TextAutosizer.cpp

@@bool TextAutosizer::processSubtree(RenderObject* layoutRoot)
119119 container = container->containingBlock();
120120
121121 RenderBlock* cluster = container;
122  while (cluster && !isAutosizingCluster(cluster))
 122 while (cluster && (!isAutosizingContainer(cluster) || !isIndependentDescendant(cluster)))
123123 cluster = cluster->containingBlock();
124124
125125 TextAutosizingClusterInfo clusterInfo(cluster);

@@bool TextAutosizer::isAutosizingContainer(const RenderObject* renderer)
235235 return true;
236236}
237237
238 bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
 238bool TextAutosizer::isNarrowDescendant(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
 239{
 240 // Autosizing containers that are significantly narrower than the |blockContainingAllText| of
 241 // their enclosing cluster need to be autosized separately and thus treated the same way as
 242 // autosizing clusters.
 243 // If however the container is only narrower by 200 CSS units or less, it's considered a part of
 244 // the enclosing cluster and this upper limit of 200 units is a
 245 float contentWidth = renderer->contentLogicalWidth();
 246 float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
 247
 248 // The upper limit on how many pixels the difference between the renderer width
 249 // and its parent cluster width can exceed the current maximum difference by
 250 // before the object is considered to be a separate autosizing cluster.
 251 const float differenceFromMaxWidthDifference = 50;
 252
 253 float widthDifference = clusterTextWidth - contentWidth;
 254 if (widthDifference - parentClusterInfo->maxAllowedDifferenceFromTextWidth > differenceFromMaxWidthDifference)
 255 return true;
 256 parentClusterInfo->maxAllowedDifferenceFromTextWidth = std::max(widthDifference, parentClusterInfo->maxAllowedDifferenceFromTextWidth);
 257 return false;
 258}
 259
 260bool TextAutosizer::isWiderDescendant(const RenderBlock* renderer, const TextAutosizingClusterInfo* parentClusterInfo)
 261{
 262 // Autosizing containers that are wider than the |blockContainingAllText| of their enclosing
 263 // cluster are treated the same way as autosizing clusters to be autosized separately.
 264 float contentWidth = renderer->contentLogicalWidth();
 265 float clusterTextWidth = parentClusterInfo->blockContainingAllText->contentLogicalWidth();
 266 return contentWidth > clusterTextWidth;
 267}
 268
 269bool TextAutosizer::isIndependentDescendant(const RenderBlock* renderer)
239270{
240271 // "Autosizing clusters" are special autosizing containers within which we
241272 // want to enforce a uniform text size multiplier, in the hopes of making

@@bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosiz
256287 // from the box's parent (we want to avoid having significantly different
257288 // width blocks within a cluster, since the narrower blocks would end up
258289 // 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 
281290 return renderer->isRenderView()
282291 || renderer->isFloating()
283292 || renderer->isOutOfFlowPositioned()

@@bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosiz
292301 // containers, and probably flexboxes...
293302}
294303
295 bool TextAutosizer::isAutosizingCluster(const RenderObject* object)
 304bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer, TextAutosizingClusterInfo* parentClusterInfo)
296305{
297  TextAutosizingClusterInfo emptyClusterInfo(0);
298  return isAutosizingContainer(object) && isAutosizingCluster(toRenderBlock(object), &emptyClusterInfo);
 306 return isNarrowDescendant(renderer, parentClusterInfo)
 307 || isWiderDescendant(renderer, parentClusterInfo)
 308 || isIndependentDescendant(renderer);
299309}
300310
301311bool TextAutosizer::containerShouldBeAutosized(const RenderBlock* container)

@@const RenderObject* TextAutosizer::findFirstTextLeafNotInCluster(const RenderObj
486496 ++depth;
487497 const RenderObject* child = (direction == FirstToLast) ? parent->firstChild() : parent->lastChild();
488498 while (child) {
489  if (!isAutosizingCluster(child)) {
 499 if (!isAutosizingContainer(child) || !isIndependentDescendant(toRenderBlock(child))) {
490500 const RenderObject* leaf = findFirstTextLeafNotInCluster(child, depth, direction);
491501 if (leaf)
492502 return leaf;

Source/WebCore/rendering/TextAutosizer.h

@@private:
6767 void setMultiplier(RenderObject*, float);
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);
7476 static bool containerContainsOneOfTags(const RenderBlock* cluster, const Vector<QualifiedName>& tags);