Skip to content

Commit

Permalink
Text Autosizing: Only take into account block width <= document layou…
Browse files Browse the repository at this point in the history
…t width.

https://bugs.webkit.org/show_bug.cgi?id=93862

Patch by John Mellor <johnme@chromium.org> on 2012-08-20
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Instead of calculating the textAutosizingMultiplier purely based on the
width of each block, we now work out the maximum width of the block
that could be displayed onscreen at any one time, and use that value.
This avoids excessive text size multiplication (there's no point making
text bigger than this, since you wouldn't be able to zoom out far
enough to read it!).

To determine the maximum onscreen block width, we take the minimum of
the block width and the layoutWidth of the narrowest non-flattened
ancestor frame. Flattened frames are ignored since they don't impose a
hard limit on the maximum width that can be displayed, instead they can
stretch to fit their contents. Note that on mobile the layoutWidth of
the main frame is the fixed layout width aka viewport width.

In practice this caps the maximum multiplier to a value that depends
on the metrics of the device. For example on a Nexus S (480 x 800px
and 1.5x devicePixelRatio) with a 980px default fixed layout width,
this limits the multiplier to: 980 / (480/1.5) = 3.0625

Most pages won't have blocks that actually hit this cap, or they will
only slightly exceed it (so their multiplier will only be slightly
reduced). For example it's not uncommon for desktop pages to be
slightly wider than 980px, but they would have to additionally have
text that spans the full width of the page for this to affect them, and
even then it would merely slightly decrease their multiplier).

This will have more dramatic effects on the rare desktop pages which
give a width=device-width (or similar) mobile viewport tag (on ports
which support viewports). A follow-up patch will hopefully address this
by wrapping the text in such excessively wide blocks to the layoutWidth.

Tests: fast/text-autosizing/narrow-iframe-flattened.html
       fast/text-autosizing/narrow-iframe.html
       fast/text-autosizing/wide-block.html
       fast/text-autosizing/wide-iframe.html

* page/FrameView.cpp:
(WebCore::FrameView::isInChildFrameWithFrameFlattening):

    Made public and const, so can be used from TextAutosizer.

* rendering/TextAutosizer.cpp:
(WebCore::TextAutosizer::processSubtree):

    Computes the minimum layout width of the parent frames, as described
    above.

(WebCore::TextAutosizer::processBlock):

    Limits used block width to this min layout width.

LayoutTests:

Added 4 tests: a block wider than the main frame, iframes both narrower
than and wider than the main frame, both also containing wide blocks,
and a narrow iframe expanded by frame flattening.

I verified experimentally that narrow-iframe-flattened.html passes, by
enabling frame flattening in Settings.cpp, but unfortunately it won't
get run by any bots since the only platform which currently enables
Text Autosizing (Chromium), doesn't enable frame flattening (or have
the DRT methods required to test it).

* fast/text-autosizing/font-scale-factor-expected.html:
* fast/text-autosizing/font-scale-factor.html:
* fast/text-autosizing/narrow-iframe-expected.html: Added.
* fast/text-autosizing/narrow-iframe-flattened-expected.html: Added.
* fast/text-autosizing/narrow-iframe-flattened.html: Added.
* fast/text-autosizing/narrow-iframe.html: Added.
* fast/text-autosizing/wide-block-expected.html: Added.
* fast/text-autosizing/wide-block.html: Added.
* fast/text-autosizing/wide-iframe-expected.html: Added.
* fast/text-autosizing/wide-iframe.html: Added.
* platform/chromium/TestExpectations:
* platform/win/Skipped:
* platform/wincairo/Skipped:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@126058 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
webkit-commit-queue committed Aug 20, 2012
1 parent 341acfe commit bb4668f
Show file tree
Hide file tree
Showing 19 changed files with 305 additions and 8 deletions.
31 changes: 31 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,34 @@
2012-08-20 John Mellor <johnme@chromium.org>

Text Autosizing: Only take into account block width <= document layout width.
https://bugs.webkit.org/show_bug.cgi?id=93862

Reviewed by Kenneth Rohde Christiansen.

Added 4 tests: a block wider than the main frame, iframes both narrower
than and wider than the main frame, both also containing wide blocks,
and a narrow iframe expanded by frame flattening.

I verified experimentally that narrow-iframe-flattened.html passes, by
enabling frame flattening in Settings.cpp, but unfortunately it won't
get run by any bots since the only platform which currently enables
Text Autosizing (Chromium), doesn't enable frame flattening (or have
the DRT methods required to test it).

* fast/text-autosizing/font-scale-factor-expected.html:
* fast/text-autosizing/font-scale-factor.html:
* fast/text-autosizing/narrow-iframe-expected.html: Added.
* fast/text-autosizing/narrow-iframe-flattened-expected.html: Added.
* fast/text-autosizing/narrow-iframe-flattened.html: Added.
* fast/text-autosizing/narrow-iframe.html: Added.
* fast/text-autosizing/wide-block-expected.html: Added.
* fast/text-autosizing/wide-block.html: Added.
* fast/text-autosizing/wide-iframe-expected.html: Added.
* fast/text-autosizing/wide-iframe.html: Added.
* platform/chromium/TestExpectations:
* platform/win/Skipped:
* platform/wincairo/Skipped:

2012-08-20 Bruno de Oliveira Abinader <bruno.abinader@basyskom.com>

[css3-text] Add parsing support for -webkit-text-decoration-style
Expand Down
Expand Up @@ -6,6 +6,7 @@
body {
width: 800px;
margin: 0px;
overflow: hidden;
}
</style>
</head>
Expand Down
1 change: 1 addition & 0 deletions LayoutTests/fast/text-autosizing/font-scale-factor.html
Expand Up @@ -6,6 +6,7 @@
body {
width: 800px;
margin: 0px;
overflow: hidden; /* Vertical scrollbar makes it harder to write expected.html */
}
</style>
<script>
Expand Down
19 changes: 19 additions & 0 deletions LayoutTests/fast/text-autosizing/narrow-iframe-expected.html
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=800">
<style type="text/css">
body { width: 800px; margin: 0; overflow-y: hidden; }
</style>

</head>
<body>

<iframe style="width: 50%; height: 50%; border: 0" src='data:text/html,
<html><body style="margin: 0; overflow-y: hidden"><div style="width: 1600px; font-size: 1.25rem">
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>'>

</body>
</html>
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=800">
<style type="text/css">
body { width: 800px; margin: 0; overflow-y: hidden; }
</style>

</head>
<body>

<iframe style="width: 100%; height: 50%; border: 0" src='data:text/html,
<html><body style="margin: 0; overflow-y: hidden"><div style="width: 1600px; font-size: 2.5rem">
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>'>

</body>
</html>
30 changes: 30 additions & 0 deletions LayoutTests/fast/text-autosizing/narrow-iframe-flattened.html
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=800">
<style type="text/css">
body { width: 800px; margin: 0; overflow-y: hidden; }
</style>

<script type="text/javascript">
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.");
}
if (window.testRunner)
testRunner.setFrameFlatteningEnabled(true);
</script>

</head>
<body>

<iframe style="width: 50%; height: 50%; border: 0" src='data:text/html,
<html><body style="margin: 0; overflow-y: hidden"><div style="width: 1600px">
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>'>

</body>
</html>
28 changes: 28 additions & 0 deletions LayoutTests/fast/text-autosizing/narrow-iframe.html
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=800">
<style type="text/css">
body { width: 800px; margin: 0; overflow-y: hidden; }
</style>

<script type="text/javascript">
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>

<iframe style="width: 50%; height: 50%; border: 0" src='data:text/html,
<html><body style="margin: 0; overflow-y: hidden"><div style="width: 1600px">
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>'>

</body>
</html>
18 changes: 18 additions & 0 deletions LayoutTests/fast/text-autosizing/wide-block-expected.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=800">
<style type="text/css">
body { width: 800px; margin: 0; overflow-y: hidden; }
</style>

</head>
<body>

<div style="width: 1600px; font-size: 2.5rem">
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>
27 changes: 27 additions & 0 deletions LayoutTests/fast/text-autosizing/wide-block.html
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=800">
<style type="text/css">
body { width: 800px; margin: 0; overflow-y: hidden; }
</style>

<script type="text/javascript">
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: 1600px">
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>
19 changes: 19 additions & 0 deletions LayoutTests/fast/text-autosizing/wide-iframe-expected.html
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=800">
<style type="text/css">
body { width: 800px; margin: 0; overflow-y: hidden; }
</style>

</head>
<body>

<iframe style="width: 3200px; height: 50%; border: 0" src='data:text/html,
<html><body style="margin: 0; overflow-y: hidden"><div style="width: 1600px; font-size: 2.5rem">
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>'>

</body>
</html>
28 changes: 28 additions & 0 deletions LayoutTests/fast/text-autosizing/wide-iframe.html
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=800">
<style type="text/css">
body { width: 800px; margin: 0; overflow-y: hidden; }
</style>

<script type="text/javascript">
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>

<iframe style="width: 3200px; height: 50%; border: 0" src='data:text/html,
<html><body style="margin: 0; overflow-y: hidden"><div style="width: 1600px">
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>'>

</body>
</html>
1 change: 1 addition & 0 deletions LayoutTests/platform/chromium/TestExpectations
Expand Up @@ -764,6 +764,7 @@ WONTFIX SKIP : fast/fast-mobile-scrolling/no-fixed-position-elements.html = IMAG

// Tests for frameset flattening. Relevant only on mobile browsers.
WONTFIX SKIP : fast/frames/flattening = TIMEOUT
WONTFIX SKIP : fast/text-autosizing/narrow-iframe-flattened.html = IMAGE
WONTFIX SKIP : http/tests/misc/iframe-flattening-3level-nesting-with-blocking-resource.html = TIMEOUT

// This should be tested differently (see discussion on https://bugs.webkit.org/show_bug.cgi?id=35063).
Expand Down
1 change: 1 addition & 0 deletions LayoutTests/platform/win/Skipped
Expand Up @@ -959,6 +959,7 @@ http/tests/security/xss-DENIED-window-open-javascript-url.html
# Skip frame flattening tests until it can be tested by this DRT
# https://bugs.webkit.org/show_bug.cgi?id=32717
fast/frames/flattening/
fast/text-autosizing/narrow-iframe-flattened.html

# https://bugs.webkit.org/show_bug.cgi?id=34933
media/video-display-aspect-ratio.html
Expand Down
1 change: 1 addition & 0 deletions LayoutTests/platform/wincairo/Skipped
Expand Up @@ -1476,6 +1476,7 @@ http/tests/security/xss-DENIED-window-open-javascript-url.html
# Skip frame flattening tests until it can be tested by this DRT
# https://bugs.webkit.org/show_bug.cgi?id=32717
fast/frames/flattening/
fast/text-autosizing/narrow-iframe-flattened.html

# https://bugs.webkit.org/show_bug.cgi?id=34933
media/video-display-aspect-ratio.html
Expand Down
58 changes: 58 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,61 @@
2012-08-20 John Mellor <johnme@chromium.org>

Text Autosizing: Only take into account block width <= document layout width.
https://bugs.webkit.org/show_bug.cgi?id=93862

Reviewed by Kenneth Rohde Christiansen.

Instead of calculating the textAutosizingMultiplier purely based on the
width of each block, we now work out the maximum width of the block
that could be displayed onscreen at any one time, and use that value.
This avoids excessive text size multiplication (there's no point making
text bigger than this, since you wouldn't be able to zoom out far
enough to read it!).

To determine the maximum onscreen block width, we take the minimum of
the block width and the layoutWidth of the narrowest non-flattened
ancestor frame. Flattened frames are ignored since they don't impose a
hard limit on the maximum width that can be displayed, instead they can
stretch to fit their contents. Note that on mobile the layoutWidth of
the main frame is the fixed layout width aka viewport width.

In practice this caps the maximum multiplier to a value that depends
on the metrics of the device. For example on a Nexus S (480 x 800px
and 1.5x devicePixelRatio) with a 980px default fixed layout width,
this limits the multiplier to: 980 / (480/1.5) = 3.0625

Most pages won't have blocks that actually hit this cap, or they will
only slightly exceed it (so their multiplier will only be slightly
reduced). For example it's not uncommon for desktop pages to be
slightly wider than 980px, but they would have to additionally have
text that spans the full width of the page for this to affect them, and
even then it would merely slightly decrease their multiplier).

This will have more dramatic effects on the rare desktop pages which
give a width=device-width (or similar) mobile viewport tag (on ports
which support viewports). A follow-up patch will hopefully address this
by wrapping the text in such excessively wide blocks to the layoutWidth.

Tests: fast/text-autosizing/narrow-iframe-flattened.html
fast/text-autosizing/narrow-iframe.html
fast/text-autosizing/wide-block.html
fast/text-autosizing/wide-iframe.html

* page/FrameView.cpp:
(WebCore::FrameView::isInChildFrameWithFrameFlattening):

Made public and const, so can be used from TextAutosizer.

* rendering/TextAutosizer.cpp:
(WebCore::TextAutosizer::processSubtree):

Computes the minimum layout width of the parent frames, as described
above.

(WebCore::TextAutosizer::processBlock):

Limits used block width to this min layout width.

2012-08-20 Hans Wennborg <hans@chromium.org>

Respect runtime flags for Device Orientation and Device Motion
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/page/FrameView.cpp
Expand Up @@ -2932,7 +2932,7 @@ FrameView* FrameView::parentFrameView() const
return 0;
}

bool FrameView::isInChildFrameWithFrameFlattening()
bool FrameView::isInChildFrameWithFrameFlattening() const
{
if (!parent() || !m_frame->ownerElement())
return false;
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/page/FrameView.h
Expand Up @@ -256,6 +256,8 @@ class FrameView : public ScrollView {

Color documentBackgroundColor() const;

bool isInChildFrameWithFrameFlattening() const;

static double currentPaintTimeStamp() { return sCurrentPaintTimeStamp; } // returns 0 if not painting

void updateLayoutAndStyleIfNeededRecursive();
Expand Down Expand Up @@ -430,7 +432,6 @@ class FrameView : public ScrollView {

FrameView* parentFrameView() const;

bool isInChildFrameWithFrameFlattening();
bool doLayoutWithFrameFlattening(bool allowSubtree);

virtual AXObjectCache* axObjectCache() const;
Expand Down

0 comments on commit bb4668f

Please sign in to comment.