Changeset 143356 in webkit


Ignore:
Timestamp:
Feb 19, 2013 10:57:31 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Text Autosizing: prevent oscillation of font sizes during autosizing
https://bugs.webkit.org/show_bug.cgi?id=108205

Patch by Tim Volodine <timvolodine@chromium.org> on 2013-02-19
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

On some websites autosized font-sizes oscillate due to layouts caused by
hovering or incremental page loading (and on other sites font sizes do
eventually stabilize, but it takes many layouts before they reach a steady
size). To prevent all these cases, we no longer allow the autosizing
multiplier to change after it has been set (to a value other than 1).

This won't always give exactly the same results, but testing on 2000 top
sites shows that this makes little difference in practice, and it prevents
these very jarring cases. As a happy side-effect, this speeds up layouts
as font sizes change less.

Test: fast/text-autosizing/oscillation-javascript-fontsize-change.html

  • page/FrameView.cpp:

(WebCore::FrameView::setFrameRect):

  • page/Settings.cpp:

(WebCore::Settings::setTextAutosizingFontScaleFactor):

  • rendering/TextAutosizer.cpp:

(WebCore::TextAutosizer::recalculateMultipliers):
(WebCore):
(WebCore::TextAutosizer::processContainer):

  • rendering/TextAutosizer.h:

(TextAutosizer):

LayoutTests:

Added overflow-y:hidden to some existing tests, since previously those tests
would start off with incorrect multipliers (because mainFrame->view()-layoutSize()
is initially 785 instead of 800 as ScrollView wrongly guesses a scrollbar will
be needed), and then the multipliers would get corrected on a subsequent layout.
Now that we don't allow the multiplier to change after being set, it needs to be
right first time.
Also added specific oscillation test triggered by javascript.

  • fast/text-autosizing/constrained-height-body-expected.html:
  • fast/text-autosizing/constrained-height-body.html:
  • fast/text-autosizing/constrained-then-float-ancestors-expected.html:
  • fast/text-autosizing/constrained-then-float-ancestors.html:
  • fast/text-autosizing/constrained-then-position-fixed-ancestors-expected.html:
  • fast/text-autosizing/constrained-then-position-fixed-ancestors.html:
  • fast/text-autosizing/nested-em-line-height-expected.html:
  • fast/text-autosizing/nested-em-line-height.html:
  • fast/text-autosizing/oscillation-javascript-fontsize-change-expected.html: Added.
  • fast/text-autosizing/oscillation-javascript-fontsize-change.html: Added.
  • fast/text-autosizing/simple-paragraph-expected.html:
  • fast/text-autosizing/simple-paragraph.html:
  • fast/text-autosizing/span-child-expected.html:
  • fast/text-autosizing/span-child.html:
  • fast/text-autosizing/unwrappable-blocks-expected.html:
  • fast/text-autosizing/unwrappable-blocks.html:
  • fast/text-autosizing/unwrappable-inlines-expected.html:
  • fast/text-autosizing/unwrappable-inlines.html:
Location:
trunk
Files:
2 added
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r143352 r143356  
     12013-02-19  Tim Volodine  <timvolodine@chromium.org>
     2
     3        Text Autosizing: prevent oscillation of font sizes during autosizing
     4        https://bugs.webkit.org/show_bug.cgi?id=108205
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Added overflow-y:hidden to some existing tests, since previously those tests
     9        would start off with incorrect multipliers (because mainFrame->view()-layoutSize()
     10        is initially 785 instead of 800 as ScrollView wrongly guesses a scrollbar will
     11        be needed), and then the multipliers would get corrected on a subsequent layout.
     12        Now that we don't allow the multiplier to change after being set, it needs to be
     13        right first time.
     14        Also added specific oscillation test triggered by javascript.
     15
     16        * fast/text-autosizing/constrained-height-body-expected.html:
     17        * fast/text-autosizing/constrained-height-body.html:
     18        * fast/text-autosizing/constrained-then-float-ancestors-expected.html:
     19        * fast/text-autosizing/constrained-then-float-ancestors.html:
     20        * fast/text-autosizing/constrained-then-position-fixed-ancestors-expected.html:
     21        * fast/text-autosizing/constrained-then-position-fixed-ancestors.html:
     22        * fast/text-autosizing/nested-em-line-height-expected.html:
     23        * fast/text-autosizing/nested-em-line-height.html:
     24        * fast/text-autosizing/oscillation-javascript-fontsize-change-expected.html: Added.
     25        * fast/text-autosizing/oscillation-javascript-fontsize-change.html: Added.
     26        * fast/text-autosizing/simple-paragraph-expected.html:
     27        * fast/text-autosizing/simple-paragraph.html:
     28        * fast/text-autosizing/span-child-expected.html:
     29        * fast/text-autosizing/span-child.html:
     30        * fast/text-autosizing/unwrappable-blocks-expected.html:
     31        * fast/text-autosizing/unwrappable-blocks.html:
     32        * fast/text-autosizing/unwrappable-inlines-expected.html:
     33        * fast/text-autosizing/unwrappable-inlines.html:
     34
    1352013-02-19  Youenn Fablet  <youennf@gmail.com>
    236
  • trunk/LayoutTests/fast/text-autosizing/constrained-height-body-expected.html

    r129195 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/constrained-height-body.html

    r129195 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/constrained-then-float-ancestors-expected.html

    r129195 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/constrained-then-float-ancestors.html

    r129195 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/constrained-then-position-fixed-ancestors-expected.html

    r129195 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/constrained-then-position-fixed-ancestors.html

    r129195 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/nested-em-line-height-expected.html

    r128500 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/nested-em-line-height.html

    r128500 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/simple-paragraph-expected.html

    r128500 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/simple-paragraph.html

    r128500 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/span-child-expected.html

    r128500 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/span-child.html

    r128500 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99</style>
    1010
  • trunk/LayoutTests/fast/text-autosizing/unwrappable-blocks-expected.html

    r137738 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99pre { margin: 0; }
    1010</style>
  • trunk/LayoutTests/fast/text-autosizing/unwrappable-blocks.html

    r137738 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99pre { margin: 0; }
    1010</style>
  • trunk/LayoutTests/fast/text-autosizing/unwrappable-inlines-expected.html

    r137738 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99pre { margin: 0; }
    1010</style>
  • trunk/LayoutTests/fast/text-autosizing/unwrappable-inlines.html

    r137738 r143356  
    66<style>
    77html { font-size: 16px; }
    8 body { width: 800px; margin: 0; }
     8body { width: 800px; margin: 0; overflow-y: hidden; }
    99pre { margin: 0; }
    1010</style>
  • trunk/Source/WebCore/ChangeLog

    r143352 r143356  
     12013-02-19  Tim Volodine  <timvolodine@chromium.org>
     2
     3        Text Autosizing: prevent oscillation of font sizes during autosizing
     4        https://bugs.webkit.org/show_bug.cgi?id=108205
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        On some websites autosized font-sizes oscillate due to layouts caused by
     9        hovering or incremental page loading (and on other sites font sizes do
     10        eventually stabilize, but it takes many layouts before they reach a steady
     11        size). To prevent all these cases, we no longer allow the autosizing
     12        multiplier to change after it has been set (to a value other than 1).
     13
     14        This won't always give exactly the same results, but testing on 2000 top
     15        sites shows that this makes little difference in practice, and it prevents
     16        these very jarring cases. As a happy side-effect, this speeds up layouts
     17        as font sizes change less.
     18
     19        Test: fast/text-autosizing/oscillation-javascript-fontsize-change.html
     20
     21        * page/FrameView.cpp:
     22        (WebCore::FrameView::setFrameRect):
     23        * page/Settings.cpp:
     24        (WebCore::Settings::setTextAutosizingFontScaleFactor):
     25        * rendering/TextAutosizer.cpp:
     26        (WebCore::TextAutosizer::recalculateMultipliers):
     27        (WebCore):
     28        (WebCore::TextAutosizer::processContainer):
     29        * rendering/TextAutosizer.h:
     30        (TextAutosizer):
     31
    1322013-02-19  Youenn Fablet  <youennf@gmail.com>
    233
  • trunk/Source/WebCore/page/FrameView.cpp

    r143295 r143356  
    445445        return;
    446446
     447#if ENABLE(TEXT_AUTOSIZING)
     448    // Autosized font sizes depend on the width of the viewing area.
     449    if (newRect.width() != oldRect.width()) {
     450        Page* page = m_frame ? m_frame->page() : 0;
     451        if (page && page->mainFrame() == m_frame && page->settings()->textAutosizingEnabled()) {
     452            for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext())
     453                m_frame->document()->textAutosizer()->recalculateMultipliers();
     454        }
     455    }
     456#endif
     457
    447458    ScrollView::setFrameRect(newRect);
    448459
  • trunk/Source/WebCore/page/Settings.cpp

    r142654 r143356  
    4343#include "ResourceHandle.h"
    4444#include "StorageMap.h"
     45#include "TextAutosizer.h"
    4546#include <limits>
    4647
     
    365366{
    366367    m_textAutosizingFontScaleFactor = fontScaleFactor;
     368
     369    // FIXME: I wonder if this needs to traverse frames like in WebViewImpl::resize, or whether there is only one document per Settings instance?
     370    for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext())
     371        frame->document()->textAutosizer()->recalculateMultipliers();
     372
    367373    m_page->setNeedsRecalcStyleInAllFrames();
    368374}
  • trunk/Source/WebCore/rendering/TextAutosizer.cpp

    r143318 r143356  
    9292}
    9393
     94void TextAutosizer::recalculateMultipliers()
     95{
     96    RenderObject* renderer = m_document->renderer();
     97    while (renderer) {
     98        if (renderer->style() && renderer->style()->textAutosizingMultiplier() != 1)
     99            setMultiplier(renderer, 1);
     100        renderer = renderer->nextInPreOrder();
     101    }
     102}
     103
    94104bool TextAutosizer::processSubtree(RenderObject* layoutRoot)
    95105{
     
    190200    while (descendant) {
    191201        if (descendant->isText()) {
    192             if (localMultiplier != descendant->style()->textAutosizingMultiplier()) {
     202            if (localMultiplier != 1 && descendant->style()->textAutosizingMultiplier() == 1) {
    193203                setMultiplier(descendant, localMultiplier);
    194204                setMultiplier(descendant->parent(), localMultiplier); // Parent does line spacing.
  • trunk/Source/WebCore/rendering/TextAutosizer.h

    r143318 r143356  
    5151
    5252    bool processSubtree(RenderObject* layoutRoot);
     53    void recalculateMultipliers();
    5354
    5455    static float computeAutosizedFontSize(float specifiedSize, float multiplier);
Note: See TracChangeset for help on using the changeset viewer.