Changeset 246348 in webkit


Ignore:
Timestamp:
Jun 11, 2019 9:51:10 PM (5 years ago)
Author:
Wenson Hsieh
Message:

[iOS] Idempotent text autosizing needs to react properly to viewport changes
https://bugs.webkit.org/show_bug.cgi?id=198736
<rdar://problem/50591911>

Reviewed by Zalan Bujtas.

Source/WebCore:

Minor refactoring and some adjustments around StyleResolver::adjustRenderStyleForTextAutosizing. See below for
more details, as well as the WebKit ChangeLog.

Test: fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-after-changing-initial-scale.html

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::adjustRenderStyleForTextAutosizing):

Rewrite this using early return statements, to make it easier to debug why elements fall out of text autosizing.
Additionally, this function currently bails if the initial scale is exactly 1, whereas we can really avoid text
autosizing in the case where the initial scale is at least 1; handle this by making idempotentTextSize return
immediately with the specified size, in the case where the scale is at least 1.

Lastly, remove the null check for element by making this method take an Element&, and only call this from
adjustRenderStyle if the element is nonnull (which matches adjustRenderStyleForSiteSpecificQuirks).

(WebCore::StyleResolver::adjustRenderStyle):

  • css/StyleResolver.h:
  • rendering/style/TextSizeAdjustment.cpp:

(WebCore::AutosizeStatus::idempotentTextSize):

Source/WebKit:

If idempotent text autosizing is enabled, respond to viewport initial scale changes by forcing a style recalc,
since the amount by which idempotent text autosizing boosts font sizes depends on the Page's initial scale.

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::resetIdempotentTextAutosizingIfNeeded):
(WebKit::WebPage::viewportConfigurationChanged):

LayoutTests:

Add a new layout test that programmatically adjusts the meta viewport initial scale, and dumps the resulting
computed sizes of several paragraphs of text, after adjusting for text autosizing.

  • fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-after-changing-initial-scale-expected.txt: Added.
  • fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-after-changing-initial-scale.html: Added.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r246347 r246348  
     12019-06-11  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Idempotent text autosizing needs to react properly to viewport changes
     4        https://bugs.webkit.org/show_bug.cgi?id=198736
     5        <rdar://problem/50591911>
     6
     7        Reviewed by Zalan Bujtas.
     8
     9        Add a new layout test that programmatically adjusts the meta viewport initial scale, and dumps the resulting
     10        computed sizes of several paragraphs of text, after adjusting for text autosizing.
     11
     12        * fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-after-changing-initial-scale-expected.txt: Added.
     13        * fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-after-changing-initial-scale.html: Added.
     14
    1152019-06-11  Zalan Bujtas  <zalan@apple.com>
    216
  • trunk/Source/WebCore/ChangeLog

    r246343 r246348  
     12019-06-11  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Idempotent text autosizing needs to react properly to viewport changes
     4        https://bugs.webkit.org/show_bug.cgi?id=198736
     5        <rdar://problem/50591911>
     6
     7        Reviewed by Zalan Bujtas.
     8
     9        Minor refactoring and some adjustments around StyleResolver::adjustRenderStyleForTextAutosizing. See below for
     10        more details, as well as the WebKit ChangeLog.
     11
     12        Test: fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-after-changing-initial-scale.html
     13
     14        * css/StyleResolver.cpp:
     15        (WebCore::StyleResolver::adjustRenderStyleForTextAutosizing):
     16
     17        Rewrite this using early return statements, to make it easier to debug why elements fall out of text autosizing.
     18        Additionally, this function currently bails if the initial scale is exactly 1, whereas we can really avoid text
     19        autosizing in the case where the initial scale is at least 1; handle this by making idempotentTextSize return
     20        immediately with the specified size, in the case where the scale is at least 1.
     21
     22        Lastly, remove the null check for element by making this method take an Element&, and only call this from
     23        adjustRenderStyle if the element is nonnull (which matches adjustRenderStyleForSiteSpecificQuirks).
     24
     25        (WebCore::StyleResolver::adjustRenderStyle):
     26        * css/StyleResolver.h:
     27        * rendering/style/TextSizeAdjustment.cpp:
     28        (WebCore::AutosizeStatus::idempotentTextSize):
     29
    1302019-06-11  Timothy Hatcher  <timothy@apple.com>
    231
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r246285 r246348  
    878878}
    879879
    880 void StyleResolver::adjustRenderStyleForTextAutosizing(RenderStyle& style, const Element* element)
     880void StyleResolver::adjustRenderStyleForTextAutosizing(RenderStyle& style, const Element& element)
    881881{
    882882    auto newAutosizeStatus = AutosizeStatus::updateStatus(style);
    883     auto pageScale = document().page() ? document().page()->initialScale() : 1.0f;
    884     if (settings().textAutosizingEnabled() && settings().textAutosizingUsesIdempotentMode() && element && !newAutosizeStatus.shouldSkipSubtree() && !style.textSizeAdjust().isNone() && hasTextChildren(*element) && pageScale != 1.0f) {
    885         auto fontDescription = style.fontDescription();
    886         fontDescription.setComputedSize(AutosizeStatus::idempotentTextSize(fontDescription.specifiedSize(), pageScale));
    887         style.setFontDescription(WTFMove(fontDescription));
    888         style.fontCascade().update(&document().fontSelector());
    889     }
     883    if (!settings().textAutosizingEnabled() || !settings().textAutosizingUsesIdempotentMode())
     884        return;
     885
     886    if (!hasTextChildren(element))
     887        return;
     888
     889    if (style.textSizeAdjust().isNone())
     890        return;
     891
     892    if (newAutosizeStatus.shouldSkipSubtree())
     893        return;
     894
     895    float initialScale = document().page() ? document().page()->initialScale() : 1;
     896    auto fontDescription = style.fontDescription();
     897    fontDescription.setComputedSize(AutosizeStatus::idempotentTextSize(fontDescription.specifiedSize(), initialScale));
     898    style.setFontDescription(WTFMove(fontDescription));
     899    style.fontCascade().update(&document().fontSelector());
    890900}
    891901#endif
     
    11411151#endif
    11421152
     1153    if (element) {
    11431154#if ENABLE(TEXT_AUTOSIZING)
    1144     adjustRenderStyleForTextAutosizing(style, element);
     1155        adjustRenderStyleForTextAutosizing(style, *element);
    11451156#endif
    1146 
    1147     if (element)
    11481157        adjustRenderStyleForSiteSpecificQuirks(style, *element);
     1158    }
    11491159}
    11501160
  • trunk/Source/WebCore/css/StyleResolver.h

    r245838 r246348  
    501501    void sweepMatchedPropertiesCache();
    502502
    503     void adjustRenderStyleForTextAutosizing(RenderStyle&, const Element*);
     503    void adjustRenderStyleForTextAutosizing(RenderStyle&, const Element&);
    504504
    505505    typedef HashMap<unsigned, MatchedPropertiesCacheItem> MatchedPropertiesCache;
  • trunk/Source/WebCore/rendering/style/TextSizeAdjustment.cpp

    r245838 r246348  
    7171float AutosizeStatus::idempotentTextSize(float specifiedSize, float pageScale)
    7272{
     73    if (pageScale >= 1)
     74        return specifiedSize;
     75
    7376    // This describes a piecewise curve when the page scale is 2/3.
    7477    FloatPoint points[] = { {0.0f, 0.0f}, {6.0f, 9.0f}, {14.0f, 17.0f} };
  • trunk/Source/WebKit/ChangeLog

    r246347 r246348  
     12019-06-11  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [iOS] Idempotent text autosizing needs to react properly to viewport changes
     4        https://bugs.webkit.org/show_bug.cgi?id=198736
     5        <rdar://problem/50591911>
     6
     7        Reviewed by Zalan Bujtas.
     8
     9        If idempotent text autosizing is enabled, respond to viewport initial scale changes by forcing a style recalc,
     10        since the amount by which idempotent text autosizing boosts font sizes depends on the Page's initial scale.
     11
     12        * WebProcess/WebPage/WebPage.h:
     13        * WebProcess/WebPage/ios/WebPageIOS.mm:
     14        (WebKit::WebPage::resetIdempotentTextAutosizingIfNeeded):
     15        (WebKit::WebPage::viewportConfigurationChanged):
     16
    1172019-06-11  Zalan Bujtas  <zalan@apple.com>
    218
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r246347 r246348  
    12451245    void sendTapHighlightForNodeIfNecessary(uint64_t requestID, WebCore::Node*);
    12461246    void resetTextAutosizing();
     1247    void resetIdempotentTextAutosizingIfNeeded(double previousInitialScale);
    12471248    WebCore::VisiblePosition visiblePositionInFocusedNodeForPoint(const WebCore::Frame&, const WebCore::IntPoint&, bool isInteractingWithFocusedElement);
    12481249    RefPtr<WebCore::Range> rangeForGranularityAtPoint(WebCore::Frame&, const WebCore::IntPoint&, uint32_t granularity, bool isInteractingWithFocusedElement);
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r246347 r246348  
    33343334}
    33353335
     3336void WebPage::resetIdempotentTextAutosizingIfNeeded(double previousInitialScale)
     3337{
     3338    if (!m_page->settings().textAutosizingUsesIdempotentMode())
     3339        return;
     3340
     3341    const float minimumScaleChangeBeforeRecomputingTextAutosizing = 0.01;
     3342    if (std::abs(previousInitialScale - m_page->initialScale()) < minimumScaleChangeBeforeRecomputingTextAutosizing)
     3343        return;
     3344
     3345    if (m_page->initialScale() >= 1 && previousInitialScale >= 1)
     3346        return;
     3347
     3348    m_page->setNeedsRecalcStyleInAllFrames();
     3349}
     3350
    33363351void WebPage::viewportConfigurationChanged(ZoomToInitialScale zoomToInitialScale)
    33373352{
     3353    double previousInitialScale = m_page->initialScale();
    33383354    double initialScale = m_viewportConfiguration.initialScale();
    33393355    m_page->setInitialScale(initialScale);
     3356    resetIdempotentTextAutosizingIfNeeded(previousInitialScale);
    33403357
    33413358    if (setFixedLayoutSize(m_viewportConfiguration.layoutSize()))
Note: See TracChangeset for help on using the changeset viewer.