WebKit Bugzilla
Attachment 370290 Details for
Bug 197808
: Move idempotent text autosizing to StyleTreeResolver
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP
bug-197808-20190520185224.patch (text/plain), 20.29 KB, created by
Myles C. Maxfield
on 2019-05-20 18:52:24 PDT
(
hide
)
Description:
WIP
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2019-05-20 18:52:24 PDT
Size:
20.29 KB
patch
obsolete
>Subversion Revision: 245541 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 7a302d330abfe72ab2175a524657d064c1ddcf04..7fe40258d7aa0eba83a1df2cd1ab48161ba00c2b 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,29 @@ >+2019-05-20 Myles C. Maxfield <mmaxfield@apple.com> >+ >+ Move idempotent text autosizing to StyleTreeResolver >+ https://bugs.webkit.org/show_bug.cgi?id=197808 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ No new tests (OOPS!). >+ >+ * css/CSSComputedStyleDeclaration.cpp: >+ (WebCore::ComputedStyleExtractor::valueForPropertyinStyle): >+ * css/CSSProperties.json: >+ * css/StyleResolver.cpp: >+ (WebCore::applyStyleToAutosizeStatus): >+ (WebCore::idempotentTextSize): >+ (WebCore::StyleResolver::adjustRenderStyle): >+ * page/FrameViewLayoutContext.cpp: >+ (WebCore::FrameViewLayoutContext::applyTextSizingIfNeeded): >+ * rendering/style/RenderStyle.cpp: >+ (WebCore::RenderStyle::RenderStyle): >+ * rendering/style/RenderStyle.h: >+ (WebCore::RenderStyle::autosizeStatus const): >+ (WebCore::RenderStyle::setAutosizeStatus): >+ * rendering/style/TextSizeAdjustment.h: >+ (WebCore::AutosizeStatus::shouldSkipSubtree const): >+ > 2019-05-20 Jer Noble <jer.noble@apple.com> > > Provide an explicit UIModalPresentation style when creating an AVPlayerViewController for fullscreen. >diff --git a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp >index f2dc6b7bd26c55972f83597191f6fb9b9b75a8bd..c9f82fb8791404c9c19f2986d20be0e337c6a1ff 100644 >--- a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp >+++ b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp >@@ -2785,6 +2785,7 @@ RefPtr<CSSValue> ComputedStyleExtractor::valueForPropertyinStyle(const RenderSty > > switch (propertyID) { > case CSSPropertyInvalid: >+ case CSSPropertyWebkitTextAutosizingStatus: > break; > > case CSSPropertyBackgroundColor: >diff --git a/Source/WebCore/css/CSSProperties.json b/Source/WebCore/css/CSSProperties.json >index 8a4ef594286ef6103f8b76351e8210831fd5afce..9a7dd947d64b1d1bbd71bd5473d928c2a48ee5be 100644 >--- a/Source/WebCore/css/CSSProperties.json >+++ b/Source/WebCore/css/CSSProperties.json >@@ -6228,6 +6228,14 @@ > }, > "status": "non-standard" > }, >+ "-webkit-text-autosizing-status": { >+ "inherited": true, >+ "codegen-properties": { >+ "skip-builder": true, >+ "enable-if": "ENABLE_TEXT_AUTOSIZING" >+ }, >+ "status": "non-standard" >+ }, > "-webkit-text-emphasis": { > "inherited": true, > "codegen-properties": { >diff --git a/Source/WebCore/css/StyleResolver.cpp b/Source/WebCore/css/StyleResolver.cpp >index 4e8113f5cdc195e9c897edb2221baa94077ef6ed..380844739a879c54c8054956c4101ee9bf850cf2 100644 >--- a/Source/WebCore/css/StyleResolver.cpp >+++ b/Source/WebCore/css/StyleResolver.cpp >@@ -874,6 +874,61 @@ static OptionSet<TouchAction> computeEffectiveTouchActions(const RenderStyle& st > } > #endif > >+#if ENABLE(TEXT_AUTOSIZING) >+static AutosizeStatus applyStyleToAutosizeStatus(AutosizeStatus result, const RenderStyle& style) >+{ >+ if (style.hasOutOfFlowPosition()) >+ result.foundOutOfFlowPosition = true; >+ if (style.floating() != Float::No) >+ result.foundFloat = true; >+ switch (style.display()) { >+ case DisplayType::InlineBlock: >+ result.foundInlineBlock = true; >+ break; >+ case DisplayType::None: >+ result.foundDisplayNone = true; >+ break; >+ default: // FIXME: Add more cases. >+ break; >+ } >+ if (style.height().isFixed()) >+ result.foundFixedHeight = true; >+ return result; >+} >+ >+static inline float idempotentTextSize(float specifiedSize, float pageScale) >+{ >+ // This describes a piecewise curve when the page scale is 2/3. >+ FloatPoint points[] = { {0.0f, 0.0f}, {6.0f, 12.0f}, {12.0f, 18.0f} }; >+ >+ // When the page scale is 1, the curve should be the identity. >+ // Linearly interpolate between the curve above and identity based on the page scale. >+ // Beware that depending on the specific values picked in the curve, this interpolation might change the shape of the curve for very small pageScales. >+ pageScale = std::min(std::max(pageScale, 0.5f), 1.0f); >+ auto scalePoint = [&](FloatPoint point) { >+ float fraction = 3.0f - 3.0f * pageScale; >+ point.setY(point.x() + (point.y() - point.x()) * fraction); >+ return point; >+ }; >+ >+ if (specifiedSize <= 0) >+ return 0; >+ >+ float result = scalePoint(points[WTF_ARRAY_LENGTH(points) - 1]).y(); >+ for (size_t i = 1; i < WTF_ARRAY_LENGTH(points); ++i) { >+ if (points[i].x() < specifiedSize) >+ continue; >+ auto leftPoint = scalePoint(points[i - 1]); >+ auto rightPoint = scalePoint(points[i]); >+ float fraction = (specifiedSize - leftPoint.x()) / (rightPoint.x() - leftPoint.x()); >+ result = leftPoint.y() + fraction * (rightPoint.y() - leftPoint.y()); >+ break; >+ } >+ >+ return std::max(result, specifiedSize); >+} >+#endif >+ > void StyleResolver::adjustRenderStyle(RenderStyle& style, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element* element) > { > // If the composed tree parent has display:contents, the parent box style will be different from the parent style. >@@ -1124,6 +1179,27 @@ void StyleResolver::adjustRenderStyle(RenderStyle& style, const RenderStyle& par > style.setEffectiveTouchActions(computeEffectiveTouchActions(style, parentStyle.effectiveTouchActions())); > #endif > >+#if ENABLE(TEXT_AUTOSIZING) >+ auto newAutosizeStatus = applyStyleToAutosizeStatus(style.autosizeStatus(), style); >+ style.setAutosizeStatus(newAutosizeStatus); >+ if (settings().textAutosizingEnabled() && settings().textAutosizingUsesIdempotentMode() && element && !newAutosizeStatus.shouldSkipSubtree()) { >+ bool hasTextChildren = false; >+ for (auto* child = element->firstChild(); child; child = child->nextSibling()) { >+ if (is<Text>(child)) { >+ hasTextChildren = true; >+ break; >+ } >+ } >+ if (hasTextChildren) { >+ auto fontDescription = style.fontDescription(); >+ auto pageScale = document().page() ? document().page()->initialScale() : 1.0f; >+ fontDescription.setComputedSize(idempotentTextSize(fontDescription.computedSize(), pageScale)); >+ style.setFontDescription(WTFMove(fontDescription)); >+ style.fontCascade().update(&document().fontSelector()); >+ } >+ } >+#endif >+ > if (element) > adjustRenderStyleForSiteSpecificQuirks(style, *element); > } >diff --git a/Source/WebCore/page/FrameViewLayoutContext.cpp b/Source/WebCore/page/FrameViewLayoutContext.cpp >index c61085c476383f0c4b3920b0d9b083475d411eff..84f37b13b5f787ef5d6be08b8b167d15f7b41aea 100644 >--- a/Source/WebCore/page/FrameViewLayoutContext.cpp >+++ b/Source/WebCore/page/FrameViewLayoutContext.cpp >@@ -491,9 +491,9 @@ bool FrameViewLayoutContext::canPerformLayout() const > void FrameViewLayoutContext::applyTextSizingIfNeeded(RenderElement& layoutRoot) > { > auto& settings = layoutRoot.settings(); >- if (!settings.textAutosizingEnabled() || renderView()->printing()) >- return; > bool idempotentMode = settings.textAutosizingUsesIdempotentMode(); >+ if (!settings.textAutosizingEnabled() || idempotentMode || renderView()->printing()) >+ return; > auto minimumZoomFontSize = settings.minimumZoomFontSize(); > if (!idempotentMode && !minimumZoomFontSize) > return; >diff --git a/Source/WebCore/rendering/RenderBlockFlow.cpp b/Source/WebCore/rendering/RenderBlockFlow.cpp >index 766591cc9fecaa23e56374524c81f75c79097510..bc85c704459e66d3f46ac2b2172e5374d3a7f462 100644 >--- a/Source/WebCore/rendering/RenderBlockFlow.cpp >+++ b/Source/WebCore/rendering/RenderBlockFlow.cpp >@@ -3723,44 +3723,12 @@ static inline float textMultiplier(RenderObject& renderer, float specifiedSize) > return std::max((1.0f / log10f(specifiedSize) * coefficient), 1.0f); > } > >-static inline float idempotentTextSize(float specifiedSize, float pageScale) >-{ >- // This describes a piecewise curve when the page scale is 2/3. >- FloatPoint points[] = { {0.0f, 0.0f}, {6.0f, 12.0f}, {12.0f, 18.0f} }; >- >- // When the page scale is 1, the curve should be the identity. >- // Linearly interpolate between the curve above and identity based on the page scale. >- // Beware that depending on the specific values picked in the curve, this interpolation might change the shape of the curve for very small pageScales. >- pageScale = std::min(std::max(pageScale, 0.5f), 1.0f); >- auto scalePoint = [&](FloatPoint point) { >- float fraction = 3.0f - 3.0f * pageScale; >- point.setY(point.x() + (point.y() - point.x()) * fraction); >- return point; >- }; >- >- if (specifiedSize <= 0) >- return 0; >- >- float result = scalePoint(points[WTF_ARRAY_LENGTH(points) - 1]).y(); >- for (size_t i = 1; i < WTF_ARRAY_LENGTH(points); ++i) { >- if (points[i].x() < specifiedSize) >- continue; >- auto leftPoint = scalePoint(points[i - 1]); >- auto rightPoint = scalePoint(points[i]); >- float fraction = (specifiedSize - leftPoint.x()) / (rightPoint.x() - leftPoint.x()); >- result = leftPoint.y() + fraction * (rightPoint.y() - leftPoint.y()); >- break; >- } >- >- return std::max(result, specifiedSize); >-} >- >-void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth, float pageScale, bool idempotentMode) >+void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth) > { > LOG(TextAutosizing, "RenderBlockFlow %p adjustComputedFontSizes, size=%f visibleWidth=%f, width()=%f. Bailing: %d", this, size, visibleWidth, width().toFloat(), visibleWidth >= width()); > > // Don't do any work if the block is smaller than the visible area. >- if (!idempotentMode && visibleWidth >= width()) >+ if (visibleWidth >= width()) > return; > > unsigned lineCount; >@@ -3798,7 +3766,7 @@ void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth, fl > auto& fontDescription = oldStyle.fontDescription(); > float specifiedSize = fontDescription.specifiedSize(); > float scaledSize = roundf(specifiedSize * scale); >- if (idempotentMode || (scaledSize > 0 && scaledSize < minFontSize)) { >+ if (scaledSize > 0 && scaledSize < minFontSize) { > // Record the width of the block and the line count the first time we resize text and use it from then on for text resizing. > // This makes text resizing consistent even if the block's width or line count changes (which can be caused by text resizing itself 5159915). > if (m_lineCountForTextAutosizing == NOT_SET) >@@ -3806,14 +3774,8 @@ void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth, fl > if (m_widthForTextAutosizing == -1) > m_widthForTextAutosizing = actualWidth; > >- float candidateNewSize; >- if (idempotentMode) { >- float lineTextSize = idempotentTextSize(specifiedSize, pageScale); >- candidateNewSize = roundf(lineTextSize); >- } else { >- float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(text, specifiedSize) : textMultiplier(text, specifiedSize); >- candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier)); >- } >+ float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(text, specifiedSize) : textMultiplier(text, specifiedSize); >+ float candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier)); > > if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto()) > document().textAutoSizing().addTextNode(*text.textNode(), candidateNewSize); >diff --git a/Source/WebCore/rendering/RenderBlockFlow.h b/Source/WebCore/rendering/RenderBlockFlow.h >index c4ce223aec575476f44008c81a1ae7940619b78c..bdbbe3ceb5f7fb6450a16819ced5669ce13c7410 100644 >--- a/Source/WebCore/rendering/RenderBlockFlow.h >+++ b/Source/WebCore/rendering/RenderBlockFlow.h >@@ -604,7 +604,7 @@ public: > > #if ENABLE(TEXT_AUTOSIZING) > int lineCountForTextAutosizing(); >- void adjustComputedFontSizes(float size, float visibleWidth, float pageScale, bool idempotentMode); >+ void adjustComputedFontSizes(float size, float visibleWidth); > void resetComputedFontSize() > { > m_widthForTextAutosizing = -1; >diff --git a/Source/WebCore/rendering/RenderElement.cpp b/Source/WebCore/rendering/RenderElement.cpp >index 6ee67c52b9f3f69df0da832346532cd3b0ffb96d..5e5203f8cde3e6ed31699abd5235dba72d6b04b4 100644 >--- a/Source/WebCore/rendering/RenderElement.cpp >+++ b/Source/WebCore/rendering/RenderElement.cpp >@@ -2124,8 +2124,6 @@ static RenderObject::BlockContentHeightType includeNonFixedHeight(const RenderOb > } > return RenderObject::FixedHeight; > } >- if (renderer.document().settings().textAutosizingUsesIdempotentMode() && style.maxHeight().type() == Fixed && is<RenderBlock>(renderer) && style.maxHeight().value() <= downcast<RenderBlock>(renderer).layoutOverflowRect().maxY()) >- return RenderObject::FixedHeight; > return RenderObject::FlexibleHeight; > } > >@@ -2135,12 +2133,9 @@ void RenderElement::adjustComputedFontSizesOnBlocks(float size, float visibleWid > if (!document) > return; > >- auto pageScale = document->page() ? document->page()->initialScale() : 1.0f; >- > Vector<int> depthStack; > int currentDepth = 0; > int newFixedDepth = 0; >- auto idempotentMode = document->settings().textAutosizingUsesIdempotentMode(); > > // We don't apply autosizing to nodes with fixed height normally. > // But we apply it to nodes which are located deep enough >@@ -2153,8 +2148,8 @@ void RenderElement::adjustComputedFontSizesOnBlocks(float size, float visibleWid > depthStack.append(newFixedDepth); > > int stackSize = depthStack.size(); >- if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && (idempotentMode || !stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth)) >- downcast<RenderBlockFlow>(*descendent).adjustComputedFontSizes(size, visibleWidth, pageScale, idempotentMode); >+ if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && (!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth)) >+ downcast<RenderBlockFlow>(*descendent).adjustComputedFontSizes(size, visibleWidth); > newFixedDepth = 0; > } > >@@ -2175,7 +2170,6 @@ void RenderElement::resetTextAutosizing() > Vector<int> depthStack; > int currentDepth = 0; > int newFixedDepth = 0; >- auto idempotentMode = document->settings().textAutosizingUsesIdempotentMode(); > > for (RenderObject* descendent = traverseNext(this, includeNonFixedHeight, currentDepth, newFixedDepth); descendent; descendent = descendent->traverseNext(this, includeNonFixedHeight, currentDepth, newFixedDepth)) { > while (depthStack.size() > 0 && currentDepth <= depthStack[depthStack.size() - 1]) >@@ -2184,7 +2178,7 @@ void RenderElement::resetTextAutosizing() > depthStack.append(newFixedDepth); > > int stackSize = depthStack.size(); >- if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && (idempotentMode || !stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth)) >+ if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && (!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth)) > downcast<RenderBlockFlow>(*descendent).resetComputedFontSize(); > newFixedDepth = 0; > } >diff --git a/Source/WebCore/rendering/style/RenderStyle.cpp b/Source/WebCore/rendering/style/RenderStyle.cpp >index feeb708b2fb825c96850e13b4803a94b4067e211..c090fbcc8d1353e9c7c3160f6c62636a158bb883 100644 >--- a/Source/WebCore/rendering/style/RenderStyle.cpp >+++ b/Source/WebCore/rendering/style/RenderStyle.cpp >@@ -165,6 +165,13 @@ RenderStyle::RenderStyle(CreateDefaultStyleTag) > m_inheritedFlags.insideLink = static_cast<unsigned>(InsideLink::NotInside); > m_inheritedFlags.insideDefaultButton = false; > m_inheritedFlags.writingMode = initialWritingMode(); >+#if ENABLE(TEXT_AUTOSIZING) >+ m_inheritedFlags.textAutosizingFoundOutOfFlowPosition = false; >+ m_inheritedFlags.textAutosizingFoundFloat = false; >+ m_inheritedFlags.textAutosizingFoundInlineBlock = false; >+ m_inheritedFlags.textAutosizingFoundFixedHeight = false; >+ m_inheritedFlags.textAutosizingFoundDisplayNone = false; >+#endif > > m_nonInheritedFlags.effectiveDisplay = static_cast<unsigned>(initialDisplay()); > m_nonInheritedFlags.originalDisplay = static_cast<unsigned>(initialDisplay()); >diff --git a/Source/WebCore/rendering/style/RenderStyle.h b/Source/WebCore/rendering/style/RenderStyle.h >index 68576ac4caf2fa7607649cc99aaaf9551c3a65a2..93982be530467bc84d939944c02a6104362a8687 100644 >--- a/Source/WebCore/rendering/style/RenderStyle.h >+++ b/Source/WebCore/rendering/style/RenderStyle.h >@@ -744,6 +744,15 @@ public: > > #if ENABLE(TEXT_AUTOSIZING) > TextSizeAdjustment textSizeAdjust() const { return m_rareInheritedData->textSizeAdjust; } >+ AutosizeStatus autosizeStatus() const >+ { >+ return { >+ static_cast<bool>(m_inheritedFlags.textAutosizingFoundOutOfFlowPosition), >+ static_cast<bool>(m_inheritedFlags.textAutosizingFoundFloat), >+ static_cast<bool>(m_inheritedFlags.textAutosizingFoundInlineBlock), >+ static_cast<bool>(m_inheritedFlags.textAutosizingFoundFixedHeight), >+ static_cast<bool>(m_inheritedFlags.textAutosizingFoundDisplayNone) }; >+ } > #endif > > TextSecurity textSecurity() const { return static_cast<TextSecurity>(m_rareInheritedData->textSecurity); } >@@ -1258,6 +1267,14 @@ public: > > #if ENABLE(TEXT_AUTOSIZING) > void setTextSizeAdjust(TextSizeAdjustment adjustment) { SET_VAR(m_rareInheritedData, textSizeAdjust, adjustment); } >+ void setAutosizeStatus(AutosizeStatus autosizeStatus) >+ { >+ m_inheritedFlags.textAutosizingFoundOutOfFlowPosition = autosizeStatus.foundOutOfFlowPosition; >+ m_inheritedFlags.textAutosizingFoundFloat = autosizeStatus.foundFloat; >+ m_inheritedFlags.textAutosizingFoundInlineBlock = autosizeStatus.foundInlineBlock; >+ m_inheritedFlags.textAutosizingFoundFixedHeight = autosizeStatus.foundFixedHeight; >+ m_inheritedFlags.textAutosizingFoundDisplayNone = autosizeStatus.foundDisplayNone; >+ } > #endif > > void setTextSecurity(TextSecurity security) { SET_VAR(m_rareInheritedData, textSecurity, static_cast<unsigned>(security)); } >@@ -1845,6 +1862,16 @@ private: > // CSS Text Layout Module Level 3: Vertical writing support > unsigned writingMode : 2; // WritingMode > // 48 bits >+ >+#if ENABLE(TEXT_AUTOSIZING) >+ // This is the state that the text autosizing code uses to determine whether or not to apply autosizing. >+ unsigned textAutosizingFoundOutOfFlowPosition : 1; >+ unsigned textAutosizingFoundFloat : 1; >+ unsigned textAutosizingFoundInlineBlock : 1; >+ unsigned textAutosizingFoundFixedHeight : 1; >+ unsigned textAutosizingFoundDisplayNone : 1; >+#endif >+ // 53 bits > }; > > // This constructor is used to implement the replace operation. >diff --git a/Source/WebCore/rendering/style/TextSizeAdjustment.h b/Source/WebCore/rendering/style/TextSizeAdjustment.h >index f37c30146bec604df7fddb57c92c7eb66caee401..8ae7925e3d443431064eac4ceacc615d09919376 100644 >--- a/Source/WebCore/rendering/style/TextSizeAdjustment.h >+++ b/Source/WebCore/rendering/style/TextSizeAdjustment.h >@@ -45,6 +45,19 @@ private: > float m_value; > }; > >+struct AutosizeStatus { >+ bool foundOutOfFlowPosition { false }; >+ bool foundFloat { false }; >+ bool foundInlineBlock { false }; >+ bool foundFixedHeight { false }; >+ bool foundDisplayNone { false }; >+ >+ bool shouldSkipSubtree() const >+ { >+ return foundOutOfFlowPosition || foundFloat || foundInlineBlock || foundFixedHeight || foundDisplayNone; >+ } >+}; >+ > } // namespace WebCore > > #endif // ENABLE(TEXT_AUTOSIZING)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 197808
:
369628
|
369753
|
369914
|
369915
|
370290
|
370498
|
370542
|
370543
|
370558
|
370591
|
370606
|
370615
|
370617