summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcommit-queue@webkit.org <commit-queue@webkit.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538>2012-11-28 21:02:30 +0000
committercommit-queue@webkit.org <commit-queue@webkit.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538>2012-11-28 21:02:30 +0000
commita4501ae8a98659171abad404e06f4ad755becd8a (patch)
tree30e071620c1014428d8344deb3c58946f5d8d395
parent839162960d6ad5ff54b2b4775264c55e58deb990 (diff)
downloadchromium_src-a4501ae8a98659171abad404e06f4ad755becd8a.zip
chromium_src-a4501ae8a98659171abad404e06f4ad755becd8a.tar.gz
chromium_src-a4501ae8a98659171abad404e06f4ad755becd8a.tar.bz2
Text Autosizing: Clusters should use width of LCA of their text nodes
https://bugs.webkit.org/show_bug.cgi?id=102562 Patch by Anton Vayvod <avayvod@chromium.org> on 2012-11-28 Reviewed by Kenneth Rohde Christiansen. Source/WebCore: Many pages set a max-width on their content. So especially for the RenderView, instead of just taking the width of |cluster| we find the lowest common ancestor of the first and last descendant text node of the cluster (i.e. the deepest wrapper block that contains all the text), and use its width instead. Tests: fast/text-autosizing/cluster-with-narrow-lca-and-cluster.html fast/text-autosizing/cluster-with-narrow-lca.html fast/text-autosizing/cluster-with-wide-lca.html fast/text-autosizing/list-item-out-of-flow.html fast/text-autosizing/wide-in-narrow-overflow-scroll.html * rendering/TextAutosizer.cpp: (WebCore::TextAutosizer::processCluster): use text nodes LCA instead of cluster for width calculation (WebCore::TextAutosizer::isAutosizingContainer): list items that are out of parent list element's flow are valid containers (that therefore become clusters in isAutosizingCluster) (WebCore::TextAutosizer::findDeepestBlockContainingAllText): searches for LCA of text nodes ignoring descendant clusters (WebCore::TextAutosizer::findFirstTextLeafNotInCluster): searches for the first or the last (depending on specified direction) text leaf node in-order ignoring any descendant clusters * rendering/TextAutosizer.h: new private methods declarations and an enum for tree traversal direction. LayoutTests: Many pages set a max-width on their content. So especially for the RenderView, instead of just taking the width of |cluster| we find the lowest common ancestor of the first and last descendant text node of the cluster (i.e. the deepest wrapper block that contains all the text), and use its width instead. Had to update a couple of existing tests since the actual width for font size multiplier calculation has been changed by the patch. * fast/text-autosizing/cluster-wide-in-narrow-expected.html: * fast/text-autosizing/cluster-wide-in-narrow.html: * fast/text-autosizing/cluster-with-narrow-lca-and-cluster-expected.html: Added. * fast/text-autosizing/cluster-with-narrow-lca-and-cluster.html: Added. * fast/text-autosizing/cluster-with-narrow-lca-expected.html: Added. * fast/text-autosizing/cluster-with-narrow-lca.html: Added. * fast/text-autosizing/cluster-with-wide-lca-expected.html: Added. * fast/text-autosizing/cluster-with-wide-lca.html: Added. * fast/text-autosizing/em-margin-border-padding-expected.html: * fast/text-autosizing/em-margin-border-padding.html: * fast/text-autosizing/list-item-out-of-flow-expected.html: Added. * fast/text-autosizing/list-item-out-of-flow.html: Added. * fast/text-autosizing/wide-child-expected.html: * fast/text-autosizing/wide-child.html: * fast/text-autosizing/wide-in-narrow-overflow-scroll-expected.html: Added. * fast/text-autosizing/wide-in-narrow-overflow-scroll.html: Added. git-svn-id: svn://svn.chromium.org/blink/trunk@136047 bbb929c8-8fbe-4397-9dbb-9b2b20218538
-rw-r--r--third_party/WebKit/LayoutTests/ChangeLog32
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-and-cluster-expected.html30
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-and-cluster.html39
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-expected.html25
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca.html34
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-wide-lca-expected.html30
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-wide-lca.html39
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/em-margin-border-padding-expected.html4
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/em-margin-border-padding.html4
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/list-item-out-of-flow-expected.html29
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/list-item-out-of-flow.html38
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/wide-child-expected.html10
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/wide-child.html6
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/wide-in-narrow-overflow-scroll-expected.html30
-rw-r--r--third_party/WebKit/LayoutTests/fast/text-autosizing/wide-in-narrow-overflow-scroll.html39
-rw-r--r--third_party/WebKit/Source/WebCore/ChangeLog26
-rw-r--r--third_party/WebKit/Source/WebCore/rendering/TextAutosizer.cpp84
-rw-r--r--third_party/WebKit/Source/WebCore/rendering/TextAutosizer.h13
18 files changed, 495 insertions, 17 deletions
diff --git a/third_party/WebKit/LayoutTests/ChangeLog b/third_party/WebKit/LayoutTests/ChangeLog
index d2077c6..7bf0c0c 100644
--- a/third_party/WebKit/LayoutTests/ChangeLog
+++ b/third_party/WebKit/LayoutTests/ChangeLog
@@ -1,3 +1,35 @@
+2012-11-28 Anton Vayvod <avayvod@chromium.org>
+
+ Text Autosizing: Clusters should use width of LCA of their text nodes
+ https://bugs.webkit.org/show_bug.cgi?id=102562
+
+ Reviewed by Kenneth Rohde Christiansen.
+
+ Many pages set a max-width on their content. So especially for the
+ RenderView, instead of just taking the width of |cluster| we find
+ the lowest common ancestor of the first and last descendant text node of
+ the cluster (i.e. the deepest wrapper block that contains all the text),
+ and use its width instead.
+ Had to update a couple of existing tests since the actual width for font
+ size multiplier calculation has been changed by the patch.
+
+ * fast/text-autosizing/cluster-wide-in-narrow-expected.html:
+ * fast/text-autosizing/cluster-wide-in-narrow.html:
+ * fast/text-autosizing/cluster-with-narrow-lca-and-cluster-expected.html: Added.
+ * fast/text-autosizing/cluster-with-narrow-lca-and-cluster.html: Added.
+ * fast/text-autosizing/cluster-with-narrow-lca-expected.html: Added.
+ * fast/text-autosizing/cluster-with-narrow-lca.html: Added.
+ * fast/text-autosizing/cluster-with-wide-lca-expected.html: Added.
+ * fast/text-autosizing/cluster-with-wide-lca.html: Added.
+ * fast/text-autosizing/em-margin-border-padding-expected.html:
+ * fast/text-autosizing/em-margin-border-padding.html:
+ * fast/text-autosizing/list-item-out-of-flow-expected.html: Added.
+ * fast/text-autosizing/list-item-out-of-flow.html: Added.
+ * fast/text-autosizing/wide-child-expected.html:
+ * fast/text-autosizing/wide-child.html:
+ * fast/text-autosizing/wide-in-narrow-overflow-scroll-expected.html: Added.
+ * fast/text-autosizing/wide-in-narrow-overflow-scroll.html: Added.
+
2012-11-28 Alexandru Chiculita <achicu@adobe.com>
[CSS Regions] Crash when using hover and first-letter inside a flow-thread
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-and-cluster-expected.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-and-cluster-expected.html
new file mode 100644
index 0000000..a514ea2
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-and-cluster-expected.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; overflow-y: hidden; }
+</style>
+
+</head>
+<body>
+
+<div style="width: 400px">
+ <div style="font-size: 1.25rem">
+ This text should be autosized to just 20px computed font size (16 * 400/320), since the width of the least common ancestor of the cluster's text descendants is used for multiplier calculation.
+ </div>
+
+ <div style="font-size: 1.25rem">
+ This text should be similarly autosized to 20px.
+ </div>
+</div>
+<div style="float: left; width: 800px; font-size: 2.5rem">
+ This text should be autosized to 40px computed font size (16 * 800/320). It should not affect autosizing for text above though since it's another cluster.<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+</div>
+
+</body>
+</html>
+
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-and-cluster.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-and-cluster.html
new file mode 100644
index 0000000..cbf9fe9
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-and-cluster.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; overflow-y: hidden; }
+</style>
+
+<script>
+if (window.internals) {
+ window.internals.settings.setTextAutosizingEnabled(true);
+ window.internals.settings.setTextAutosizingWindowSizeOverride(320, 480);
+} else if (window.console && console.warn) {
+ console.warn("This test depends on the Text Autosizing setting being true, so run it in DumpRenderTree, or manually enable Text Autosizing, and either use a mobile device with 320px device-width (like Nexus S or iPhone), or define HACK_FORCE_TEXT_AUTOSIZING_ON_DESKTOP.");
+}
+</script>
+
+</head>
+<body>
+
+<div style="width: 400px">
+ <div>
+ This text should be autosized to just 20px computed font size (16 * 400/320), since the width of the least common ancestor of the cluster's text descendants is used for multiplier calculation.
+ </div>
+
+ <div>
+ This text should be similarly autosized to 20px.
+ </div>
+</div>
+<div style="float: left; width: 800px">
+ This text should be autosized to 40px computed font size (16 * 800/320). It should not affect autosizing for text above though since it's another cluster.<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+</div>
+
+</body>
+</html>
+
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-expected.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-expected.html
new file mode 100644
index 0000000..58c793c
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca-expected.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; overflow-y: hidden; }
+</style>
+
+</head>
+<body>
+
+<div style="width: 400px">
+ <div style="font-size: 1.25rem">
+ This text should be autosized to just 20px computed font size (16 * 400/320), since the width of the least common ancestor of the cluster's text descendants is used for multiplier calculation.
+ </div>
+
+ <div style="font-size: 1.25rem">
+ This text should be similarly autosized to 20px.
+ </div>
+</div>
+</body>
+</html>
+
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca.html
new file mode 100644
index 0000000..6b8eddd
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-narrow-lca.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; overflow-y: hidden; }
+</style>
+
+<script>
+if (window.internals) {
+ window.internals.settings.setTextAutosizingEnabled(true);
+ window.internals.settings.setTextAutosizingWindowSizeOverride(320, 480);
+} else if (window.console && console.warn) {
+ console.warn("This test depends on the Text Autosizing setting being true, so run it in DumpRenderTree, or manually enable Text Autosizing, and either use a mobile device with 320px device-width (like Nexus S or iPhone), or define HACK_FORCE_TEXT_AUTOSIZING_ON_DESKTOP.");
+}
+</script>
+
+</head>
+<body>
+
+<div style="width: 400px">
+ <div>
+ This text should be autosized to just 20px computed font size (16 * 400/320), since the width of the least common ancestor of the cluster's text descendants is used for multiplier calculation.
+ </div>
+
+ <div>
+ This text should be similarly autosized to 20px.
+ </div>
+</div>
+</body>
+</html>
+
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-wide-lca-expected.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-wide-lca-expected.html
new file mode 100644
index 0000000..b27254d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-wide-lca-expected.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; overflow-y: hidden; }
+</style>
+
+</head>
+<body>
+
+<div style="width: 400px">
+ <div style="font-size: 2.5rem">
+ This text should be autosized to 40px computed font size (16 * 800/320) since the least common ancestor of all the cluster's text descendants is the BODY tag.
+ </div>
+
+ <div style="font-size: 2.5rem">
+ This text should be similarly autosized to 40px.
+ </div>
+</div>
+<div style="width: 800px; font-size: 2.5rem">
+ This text should be autosized to 40px computed font size (16 * 800/320).
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+</div>
+
+</body>
+</html>
+
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-wide-lca.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-wide-lca.html
new file mode 100644
index 0000000..01a0be5
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/cluster-with-wide-lca.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; overflow-y: hidden; }
+</style>
+
+<script>
+if (window.internals) {
+ window.internals.settings.setTextAutosizingEnabled(true);
+ window.internals.settings.setTextAutosizingWindowSizeOverride(320, 480);
+} else if (window.console && console.warn) {
+ console.warn("This test depends on the Text Autosizing setting being true, so run it in DumpRenderTree, or manually enable Text Autosizing, and either use a mobile device with 320px device-width (like Nexus S or iPhone), or define HACK_FORCE_TEXT_AUTOSIZING_ON_DESKTOP.");
+}
+</script>
+
+</head>
+<body>
+
+<div style="width: 400px">
+ <div>
+ This text should be autosized to 40px computed font size (16 * 800/320) since the least common ancestor of all the cluster's text descendants is the BODY tag.
+ </div>
+
+ <div>
+ This text should be similarly autosized to 40px.
+ </div>
+</div>
+<div style="width: 800px">
+ This text should be autosized to 40px computed font size (16 * 800/320).
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
+</div>
+
+</body>
+</html>
+
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/em-margin-border-padding-expected.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/em-margin-border-padding-expected.html
index 43bd1c0..5429ce3 100644
--- a/third_party/WebKit/LayoutTests/fast/text-autosizing/em-margin-border-padding-expected.html
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/em-margin-border-padding-expected.html
@@ -5,14 +5,14 @@
<meta name="viewport" content="width=800">
<style>
html { font-size: 16px; }
-body { width: 800px; margin: 0; overflow-y: hidden; }
+body { width: 896px; margin: 0; overflow-y: hidden; }
</style>
</head>
<body>
<p style="font-size: 2.5rem; margin: 1rem; border: 1rem solid blue; padding: 1rem">
- This text should get autosized to 40px computed font size, but the 1em margins, borders and padding should remain just 16px. While debatable, this generally looks more consistent than having them be scaled.<br>
+ This text should get autosized to 40px computed font size (16 * 800/320), but the 1em margins, borders and padding should remain just 16px. While debatable, this generally looks more consistent than having them be scaled.<br>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/em-margin-border-padding.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/em-margin-border-padding.html
index 395e814..10d3a96 100644
--- a/third_party/WebKit/LayoutTests/fast/text-autosizing/em-margin-border-padding.html
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/em-margin-border-padding.html
@@ -5,7 +5,7 @@
<meta name="viewport" content="width=800">
<style>
html { font-size: 16px; }
-body { width: 800px; margin: 0; overflow-y: hidden; }
+body { width: 896px; margin: 0; overflow-y: hidden; }
</style>
<script>
@@ -21,7 +21,7 @@ if (window.internals) {
<body>
<p style="margin: 1em; border: 1em solid blue; padding: 1em">
- This text should get autosized to 40px computed font size, but the 1em margins, borders and padding should remain just 16px. While debatable, this generally looks more consistent than having them be scaled.<br>
+ This text should get autosized to 40px computed font size (16 * 800/320), but the 1em margins, borders and padding should remain just 16px. While debatable, this generally looks more consistent than having them be scaled.<br>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/list-item-out-of-flow-expected.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/list-item-out-of-flow-expected.html
new file mode 100644
index 0000000..bc48f3d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/list-item-out-of-flow-expected.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; margin: 0; overflow-y: hidden; }
+</style>
+
+</head>
+<body>
+
+<ul style="width: 400px">
+ <li style="width: 600px; font-size: 1.25rem">
+ This element is only autosized to 20px computed font size (16 * 400/320), since we don't want list items to be autosized differently from each other, and the width of UL tag is used for autosizing.<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ </li>
+ <li style="position: absolute; width: 800px; font-size: 2.5rem">
+ This list element becomes a separate autosizing cluster since it's positioned out of the list flow. Hence its computed font size is 40px (16 * 400 / 320).<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ </li>
+ <li style="font-size: 1.25rem">
+ This element is autosized to computed font size of 20px similarly to the first list item.<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ </li>
+</ul>
+</body>
+</head> \ No newline at end of file
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/list-item-out-of-flow.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/list-item-out-of-flow.html
new file mode 100644
index 0000000..60e46d8
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/list-item-out-of-flow.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; margin: 0; overflow-y: hidden; }
+</style>
+
+<script>
+if (window.internals) {
+ window.internals.settings.setTextAutosizingEnabled(true);
+ window.internals.settings.setTextAutosizingWindowSizeOverride(320, 480);
+} else if (window.console && console.warn) {
+ console.warn("This test depends on the Text Autosizing setting being true, so run it in DumpRenderTree, or manually enable Text Autosizing, and either use a mobile device with 320px device-width (like Nexus S or iPhone), or define HACK_FORCE_TEXT_AUTOSIZING_ON_DESKTOP.");
+}
+</script>
+
+</head>
+<body>
+
+<ul style="width: 400px">
+ <li style="width: 600px">
+ This element is only autosized to 20px computed font size (16 * 400/320), since we don't want list items to be autosized differently from each other, and the width of UL tag is used for autosizing.<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ </li>
+ <li style="position: absolute; width: 800px">
+ This list element becomes a separate autosizing cluster since it's positioned out of the list flow. Hence its computed font size is 40px (16 * 400 / 320).<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ </li>
+ <li>
+ This element is autosized to computed font size of 20px similarly to the first list item.<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ </li>
+</ul>
+</body>
+</head> \ No newline at end of file
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-child-expected.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-child-expected.html
index 4b000f6..a90a013 100644
--- a/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-child-expected.html
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-child-expected.html
@@ -11,12 +11,14 @@ body { width: 800px; margin: 0; overflow-y: hidden; }
</head>
<body>
-<div style="width: 320px; font-size: 2.5rem">
- This text should all be autosized to 40px computed font-size, since although this block is narrow, it has a wide child block, so the cluster will be wide and need autosizing.
- <div style="width: 800px">
+<div style="width: 320px; font-size: 1rem">
+ This text should not be autosized, as this div is the lowest common ancestor of the root cluster, and this div is narrow.<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ <div style="width: 800px">
+ This text should not be autosized since it doesn't affect the width of the parent block which is used to calculate the autosizing multiplier.<br>
+ FIXME: Ideally this text should be autosized. Will need to be fixed later.<br>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</body>
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-child.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-child.html
index 0a5b1214f..454ea61 100644
--- a/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-child.html
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-child.html
@@ -21,11 +21,13 @@ if (window.internals) {
<body>
<div style="width: 320px">
- This text should all be autosized to 40px computed font-size, since although this block is narrow, it has a wide child block, so the cluster will be wide and need autosizing.
+ This text should not be autosized, as this div is the lowest common ancestor of the root cluster, and this div is narrow.<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<div style="width: 800px">
+ This text should not be autosized since it doesn't affect the width of the parent block which is used to calculate the autosizing multiplier.<br>
+ FIXME: Ideally this text should be autosized. Will need to be fixed later.<br>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</body>
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-in-narrow-overflow-scroll-expected.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-in-narrow-overflow-scroll-expected.html
new file mode 100644
index 0000000..4b7a777
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-in-narrow-overflow-scroll-expected.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; margin: 0; overflow-y: hidden; }
+</style>
+
+</head>
+<body>
+
+<div style="width: 400px">
+ <div style="overflow-x: scroll">
+ <div style="width: 800px; font-size: 1.25rem">
+ This text should be autosized to 20px computed font size (16 * 400/320), since this is part of the root cluster, whose text descendants are all contained within the 400px wide grandparent of this div.<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ </div>
+ </div>
+
+ <div style="font-size: 1.25rem">
+ This text should be autosized to 20px computed font size (16 * 400/320).<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ </div>
+</div>
+
+</body>
+</html>
+
diff --git a/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-in-narrow-overflow-scroll.html b/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-in-narrow-overflow-scroll.html
new file mode 100644
index 0000000..f74a7a2
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/text-autosizing/wide-in-narrow-overflow-scroll.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+
+<meta name="viewport" content="width=800">
+<style>
+html { font-size: 16px; }
+body { width: 800px; margin: 0; overflow-y: hidden; }
+</style>
+
+<script>
+if (window.internals) {
+ window.internals.settings.setTextAutosizingEnabled(true);
+ window.internals.settings.setTextAutosizingWindowSizeOverride(320, 480);
+} else if (window.console && console.warn) {
+ console.warn("This test depends on the Text Autosizing setting being true, so run it in DumpRenderTree, or manually enable Text Autosizing, and either use a mobile device with 320px device-width (like Nexus S or iPhone), or define HACK_FORCE_TEXT_AUTOSIZING_ON_DESKTOP.");
+}
+</script>
+
+</head>
+<body>
+
+<div style="width: 400px">
+ <div style="overflow-x: scroll">
+ <div style="width: 800px">
+ This text should be autosized to 20px computed font size (16 * 400/320), since this is part of the root cluster, whose text descendants are all contained within the 400px wide grandparent of this div.<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ </div>
+ </div>
+
+ <div>
+ This text should be autosized to 20px computed font size (16 * 400/320).<br>
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+ </div>
+</div>
+
+</body>
+</html>
+
diff --git a/third_party/WebKit/Source/WebCore/ChangeLog b/third_party/WebKit/Source/WebCore/ChangeLog
index 2d97c52..d5801a0 100644
--- a/third_party/WebKit/Source/WebCore/ChangeLog
+++ b/third_party/WebKit/Source/WebCore/ChangeLog
@@ -1,3 +1,29 @@
+2012-11-28 Anton Vayvod <avayvod@chromium.org>
+
+ Text Autosizing: Clusters should use width of LCA of their text nodes
+ https://bugs.webkit.org/show_bug.cgi?id=102562
+
+ Reviewed by Kenneth Rohde Christiansen.
+
+ Many pages set a max-width on their content. So especially for the
+ RenderView, instead of just taking the width of |cluster| we find
+ the lowest common ancestor of the first and last descendant text node of
+ the cluster (i.e. the deepest wrapper block that contains all the text),
+ and use its width instead.
+
+ Tests: fast/text-autosizing/cluster-with-narrow-lca-and-cluster.html
+ fast/text-autosizing/cluster-with-narrow-lca.html
+ fast/text-autosizing/cluster-with-wide-lca.html
+ fast/text-autosizing/list-item-out-of-flow.html
+ fast/text-autosizing/wide-in-narrow-overflow-scroll.html
+
+ * rendering/TextAutosizer.cpp:
+ (WebCore::TextAutosizer::processCluster): use text nodes LCA instead of cluster for width calculation
+ (WebCore::TextAutosizer::isAutosizingContainer): list items that are out of parent list element's flow are valid containers (that therefore become clusters in isAutosizingCluster)
+ (WebCore::TextAutosizer::findDeepestBlockContainingAllText): searches for LCA of text nodes ignoring descendant clusters
+ (WebCore::TextAutosizer::findFirstTextLeafNotInCluster): searches for the first or the last (depending on specified direction) text leaf node in-order ignoring any descendant clusters
+ * rendering/TextAutosizer.h: new private methods declarations and an enum for tree traversal direction.
+
2012-11-28 Sadrul Habib Chowdhury <sadrul@chromium.org>
cleanup: Change some code to be cleaner, more readable and style conforming
diff --git a/third_party/WebKit/Source/WebCore/rendering/TextAutosizer.cpp b/third_party/WebKit/Source/WebCore/rendering/TextAutosizer.cpp
index 36067fd..358840d 100644
--- a/third_party/WebKit/Source/WebCore/rendering/TextAutosizer.cpp
+++ b/third_party/WebKit/Source/WebCore/rendering/TextAutosizer.cpp
@@ -33,6 +33,8 @@
#include "Settings.h"
#include "StyleInheritedData.h"
+#include <algorithm>
+
namespace WebCore {
struct TextAutosizingWindowInfo {
@@ -94,11 +96,12 @@ void TextAutosizer::processCluster(RenderBlock* cluster, RenderBlock* container,
{
ASSERT(isAutosizingCluster(cluster));
- // FIXME: Many pages set a max-width on their content. So especially for the RenderView,
- // instead of just taking the width of |cluster| we should find the lowest common ancestor of
- // the first and last descendant text node of the cluster (i.e. the deepest wrapper block that
- // contains all the text), and use its width instead.
- RenderBlock* lowestCommonAncestor = cluster;
+ // Many pages set a max-width on their content. So especially for the
+ // RenderView, instead of just taking the width of |cluster| we find
+ // the lowest common ancestor of the first and last descendant text node of
+ // the cluster (i.e. the deepest wrapper block that contains all the text),
+ // and use its width instead.
+ const RenderBlock* lowestCommonAncestor = findDeepestBlockContainingAllText(cluster);
float commonAncestorWidth = lowestCommonAncestor->contentLogicalWidth();
float multiplier = 1;
@@ -201,8 +204,11 @@ bool TextAutosizer::isAutosizingContainer(const RenderObject* renderer)
// "Autosizing containers" are the smallest unit for which we can
// enable/disable Text Autosizing.
// - Must not be inline, as different multipliers on one line looks terrible.
- // - Must not be list items, as items in the same list should look consistent.
- return renderer->isRenderBlock() && !renderer->isInline() && !renderer->isListItem();
+ // - Must not be list items, as items in the same list should look consistent (*).
+ // * except for those list items positioned out of the list's flow.
+ return renderer->isRenderBlock()
+ && !renderer->isInline()
+ && (!renderer->isListItem() || renderer->isOutOfFlowPositioned());
}
bool TextAutosizer::isAutosizingCluster(const RenderBlock* renderer)
@@ -297,6 +303,70 @@ RenderObject* TextAutosizer::nextInPreOrderSkippingDescendantsOfContainers(const
return 0;
}
+const RenderBlock* TextAutosizer::findDeepestBlockContainingAllText(const RenderBlock* cluster)
+{
+ ASSERT(isAutosizingCluster(cluster));
+
+ size_t firstDepth = 0;
+ const RenderObject* firstTextLeaf = findFirstTextLeafNotInCluster(cluster, firstDepth, FirstToLast);
+ if (!firstTextLeaf)
+ return cluster;
+
+ size_t lastDepth = 0;
+ const RenderObject* lastTextLeaf = findFirstTextLeafNotInCluster(cluster, lastDepth, LastToFirst);
+ ASSERT(lastTextLeaf);
+
+ // Equalize the depths if necessary. Only one of the while loops below will get executed.
+ const RenderObject* firstNode = firstTextLeaf;
+ const RenderObject* lastNode = lastTextLeaf;
+ while (firstDepth > lastDepth) {
+ firstNode = firstNode->parent();
+ --firstDepth;
+ }
+ while (lastDepth > firstDepth) {
+ lastNode = lastNode->parent();
+ --lastDepth;
+ }
+
+ // Go up from both nodes until the parent is the same. Both pointers will point to the LCA then.
+ while (firstNode != lastNode) {
+ firstNode = firstNode->parent();
+ lastNode = lastNode->parent();
+ }
+
+ if (firstNode->isRenderBlock())
+ return toRenderBlock(firstNode);
+
+ // containingBlock() should never leave the cluster, since it only skips ancestors when finding the
+ // container of position:absolute/fixed blocks, and those cannot exist between a cluster and its text
+ // nodes lowest common ancestor as isAutosizingCluster would have made them into their own independent
+ // cluster.
+ RenderBlock* containingBlock = firstNode->containingBlock();
+ ASSERT(containingBlock->isDescendantOf(cluster));
+
+ return containingBlock;
+}
+
+const RenderObject* TextAutosizer::findFirstTextLeafNotInCluster(const RenderObject* parent, size_t& depth, TraversalDirection direction)
+{
+ if (parent->isEmpty())
+ return parent->isText() ? parent : 0;
+
+ ++depth;
+ const RenderObject* child = (direction == FirstToLast) ? parent->firstChild() : parent->lastChild();
+ while (child) {
+ if (!isAutosizingContainer(child) || !isAutosizingCluster(toRenderBlock(child))) {
+ const RenderObject* leaf = findFirstTextLeafNotInCluster(child, depth, direction);
+ if (leaf)
+ return leaf;
+ }
+ child = (direction == FirstToLast) ? child->nextSibling() : child->previousSibling();
+ }
+ --depth;
+
+ return 0;
+}
+
} // namespace WebCore
#endif // ENABLE(TEXT_AUTOSIZING)
diff --git a/third_party/WebKit/Source/WebCore/rendering/TextAutosizer.h b/third_party/WebKit/Source/WebCore/rendering/TextAutosizer.h
index 2e2e70e..a709b11 100644
--- a/third_party/WebKit/Source/WebCore/rendering/TextAutosizer.h
+++ b/third_party/WebKit/Source/WebCore/rendering/TextAutosizer.h
@@ -55,6 +55,11 @@ public:
static float computeAutosizedFontSize(float specifiedSize, float multiplier);
private:
+ enum TraversalDirection {
+ FirstToLast,
+ LastToFirst
+ };
+
explicit TextAutosizer(Document*);
void processCluster(RenderBlock* cluster, RenderBlock* container, RenderObject* subtreeRoot, const TextAutosizingWindowInfo&);
@@ -71,6 +76,14 @@ private:
// Use to traverse the tree of descendants, excluding descendants of containers (but returning the containers themselves).
static RenderObject* nextInPreOrderSkippingDescendantsOfContainers(const RenderObject* current, const RenderObject* stayWithin);
+ // Finds the lowest common ancestor of the first and the last descendant
+ // text node (excluding those belonging to other autosizing clusters).
+ static const RenderBlock* findDeepestBlockContainingAllText(const RenderBlock* cluster);
+
+ // Depending on the traversal direction specified, finds the first or the last leaf text node child that doesn't
+ // belong to any cluster.
+ static const RenderObject* findFirstTextLeafNotInCluster(const RenderObject*, size_t& depth, TraversalDirection);
+
Document* m_document;
};