Changeset 245838 in webkit
- Timestamp:
- May 28, 2019 7:27:20 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 2 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r245837 r245838 1 2019-05-28 Myles C. Maxfield <mmaxfield@apple.com> 2 3 Move idempotent text autosizing to StyleTreeResolver 4 https://bugs.webkit.org/show_bug.cgi?id=197808 5 <rdar://problem/50283983> 6 7 Reviewed by Antti Koivisto. 8 9 * fast/text-autosizing/ios/idempotentmode/css-exposure-expected.txt: Added. 10 * fast/text-autosizing/ios/idempotentmode/css-exposure.html: Added. 11 * fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip-expected.html: Added. 12 * fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip.html: Added. 13 * platform/ipad/fast/text-autosizing/text-size-adjust-inline-style-expected.html: Removed. 14 * platform/ipad/fast/text-autosizing/text-size-adjust-inline-style.html: Removed. 15 We're intentionally not honoring percentages, because this is the most common way that 16 text autosizing is disabled (by setting it to 100%) on the Web today. However, Web authors 17 that have done this did it without knowing the full extent of the behavior change, and 18 the new idempotent text autosizing code path seems to be a progression in most cases 19 we've seen. 20 1 21 2019-05-28 Simon Fraser <simon.fraser@apple.com> 2 22 -
trunk/Source/WebCore/ChangeLog
r245837 r245838 1 2019-05-28 Myles C. Maxfield <mmaxfield@apple.com> 2 3 Move idempotent text autosizing to StyleTreeResolver 4 https://bugs.webkit.org/show_bug.cgi?id=197808 5 <rdar://problem/50283983> 6 7 Reviewed by Antti Koivisto. 8 9 This patch migrates the idempotent text autosizing code to live inside style resolution. This is almost 10 the same as the algorithm that uses the result of layout to calculate autosizing, but this version only 11 operates on style (and thus doesn't require double layouts). Because it is being run in an environment 12 with less information, autosizing is occurring in more places, so the curves have been adjusted to make 13 autosizing not boost as much as the previous implementation did. The new algorithm is modelled after 14 text-decorations-in-effect. I've claimed 4 of the unused bits in RenderStyle to contain the state of the 15 autosizing algorithm. StyleResolver::adjustRenderStyle() is where the algorithm is implemented: 16 - Look at the inherited bits 17 - Interogate the element's RenderStyle 18 - Compute new bits for the element, and set them in its RenderStyle 19 - Based on the newly computed bits, determine whether we should increase the text size 20 - If so, determine how much using the specified font size, and apply the result to the computed font size 21 22 This works because StyleBuilderCustom::applyInheritFontSize() inherits from the specified font size, not 23 the computed font size. 24 25 This patch also will disable autosizing using the other methods (so there aren't two methods of autosizing 26 fighting each other) and will honor text-size-adjust:none. However, it won't honor text-size-adjust:100%. 27 If content says text-size-adjust:100%, we will disregard it and take this code path. 28 29 Tests: fast/text-autosizing/ios/idempotentmode/css-exposure.html 30 fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-skip.html 31 fast/text-autosizing/ios/idempotentmode/idempotent-autosizing-identity.html 32 fast/text-autosizing/ios/idempotentmode/idempotent-autosizing.html 33 34 * Sources.txt: 35 * WebCore.xcodeproj/project.pbxproj: 36 * css/CSSComputedStyleDeclaration.cpp: 37 (WebCore::ComputedStyleExtractor::valueForPropertyinStyle): 38 * css/CSSProperties.json: 39 * css/StyleBuilderCustom.h: 40 (WebCore::computeBaseSpecifiedFontSize): 41 (WebCore::computeLineHeightMultiplierDueToFontSize): 42 * css/StyleResolver.cpp: 43 (WebCore::idempotentTextSize): 44 (WebCore::hasTextChildren): 45 (WebCore::StyleResolver::adjustRenderStyle): 46 (WebCore::StyleResolver::checkForTextSizeAdjust): 47 * page/FrameViewLayoutContext.cpp: 48 (WebCore::FrameViewLayoutContext::applyTextSizingIfNeeded): 49 * rendering/RenderBlockFlow.cpp: 50 (WebCore::RenderBlockFlow::adjustComputedFontSizes): 51 (WebCore::idempotentTextSize): Deleted. 52 * rendering/RenderBlockFlow.h: 53 * rendering/RenderElement.cpp: 54 (WebCore::includeNonFixedHeight): 55 (WebCore::RenderElement::adjustComputedFontSizesOnBlocks): 56 (WebCore::RenderElement::resetTextAutosizing): 57 * rendering/style/RenderStyle.cpp: 58 (WebCore::RenderStyle::RenderStyle): 59 (WebCore::RenderStyle::autosizeStatus const): 60 (WebCore::RenderStyle::setAutosizeStatus): 61 * rendering/style/RenderStyle.h: 62 * rendering/style/TextSizeAdjustment.cpp: Added. 63 (WebCore::AutosizeStatus::AutosizeStatus): 64 (WebCore::AutosizeStatus::contains const): 65 (WebCore::AutosizeStatus::modifiedStatus const): 66 (WebCore::AutosizeStatus::shouldSkipSubtree const): 67 * rendering/style/TextSizeAdjustment.h: 68 1 69 2019-05-28 Simon Fraser <simon.fraser@apple.com> 2 70 -
trunk/Source/WebCore/Sources.txt
r245798 r245838 2145 2145 rendering/style/StyleTransformData.cpp 2146 2146 rendering/style/StyleVisualData.cpp 2147 rendering/style/TextSizeAdjustment.cpp 2147 2148 rendering/style/WillChangeData.cpp 2148 2149 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r245798 r245838 6438 6438 1CECB3C621F59C8700F44542 /* WHLSLNativeTypeWriter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLNativeTypeWriter.cpp; sourceTree = "<group>"; }; 6439 6439 1CECB3C721F59C8700F44542 /* WHLSLNativeTypeWriter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLNativeTypeWriter.h; sourceTree = "<group>"; }; 6440 1CF0BFD42298706800ED2074 /* TextSizeAdjustment.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TextSizeAdjustment.cpp; sourceTree = "<group>"; }; 6440 6441 1CFAE3220A6D6A3F0032593D /* libobjc.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libobjc.dylib; path = /usr/lib/libobjc.dylib; sourceTree = "<absolute>"; }; 6441 6442 1DC553FD211BA12A004B780E /* NavigatorShare.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NavigatorShare.idl; sourceTree = "<group>"; }; … … 24931 24932 BC2274770E8366E200E7F975 /* SVGRenderStyleDefs.h */, 24932 24933 1CB6B4F8217B83930093B9CD /* TextDecorationThickness.h */, 24934 1CF0BFD42298706800ED2074 /* TextSizeAdjustment.cpp */, 24933 24935 448B1B780F3A2F9B0047A9E2 /* TextSizeAdjustment.h */, 24934 24936 1CB6B4FB217B83940093B9CD /* TextUnderlineOffset.h */, -
trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
r245823 r245838 2786 2786 switch (propertyID) { 2787 2787 case CSSPropertyInvalid: 2788 #if ENABLE(TEXT_AUTOSIZING) 2789 case CSSPropertyInternalTextAutosizingStatus: 2790 #endif 2788 2791 break; 2789 2792 -
trunk/Source/WebCore/css/CSSProperties.json
r245276 r245838 6229 6229 "status": "non-standard" 6230 6230 }, 6231 "-internal-text-autosizing-status": { 6232 "inherited": true, 6233 "codegen-properties": { 6234 "skip-builder": true, 6235 "enable-if": "ENABLE_TEXT_AUTOSIZING" 6236 }, 6237 "status": "non-standard" 6238 }, 6231 6239 "-webkit-text-emphasis": { 6232 6240 "inherited": true, -
trunk/Source/WebCore/css/StyleBuilderCustom.h
r244408 r245838 670 670 result *= frame->textZoomFactor(); 671 671 result *= style.effectiveZoom(); 672 if (percentageAutosizingEnabled )672 if (percentageAutosizingEnabled && !document.settings().textAutosizingUsesIdempotentMode()) 673 673 result *= style.textSizeAdjust().multiplier(); 674 674 return result; … … 702 702 } 703 703 704 if (percentageAutosizingEnabled )704 if (percentageAutosizingEnabled && !document.settings().textAutosizingUsesIdempotentMode()) 705 705 return style.textSizeAdjust().multiplier(); 706 706 return 1; -
trunk/Source/WebCore/css/StyleResolver.cpp
r245494 r245838 875 875 #endif 876 876 877 #if ENABLE(TEXT_AUTOSIZING) 878 static bool hasTextChildren(const Element& element) 879 { 880 for (auto* child = element.firstChild(); child; child = child->nextSibling()) { 881 if (is<Text>(child)) 882 return true; 883 } 884 return false; 885 } 886 887 void StyleResolver::adjustRenderStyleForTextAutosizing(RenderStyle& style, const Element* element) 888 { 889 auto newAutosizeStatus = AutosizeStatus::updateStatus(style); 890 auto pageScale = document().page() ? document().page()->initialScale() : 1.0f; 891 if (settings().textAutosizingEnabled() && settings().textAutosizingUsesIdempotentMode() && element && !newAutosizeStatus.shouldSkipSubtree() && !style.textSizeAdjust().isNone() && hasTextChildren(*element) && pageScale != 1.0f) { 892 auto fontDescription = style.fontDescription(); 893 fontDescription.setComputedSize(AutosizeStatus::idempotentTextSize(fontDescription.specifiedSize(), pageScale)); 894 style.setFontDescription(WTFMove(fontDescription)); 895 style.fontCascade().update(&document().fontSelector()); 896 } 897 } 898 #endif 899 877 900 void StyleResolver::adjustRenderStyle(RenderStyle& style, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element* element) 878 901 { … … 1123 1146 #if ENABLE(POINTER_EVENTS) 1124 1147 style.setEffectiveTouchActions(computeEffectiveTouchActions(style, parentStyle.effectiveTouchActions())); 1148 #endif 1149 1150 #if ENABLE(TEXT_AUTOSIZING) 1151 adjustRenderStyleForTextAutosizing(style, element); 1125 1152 #endif 1126 1153 … … 1821 1848 void StyleResolver::checkForTextSizeAdjust(RenderStyle* style) 1822 1849 { 1823 if (style->textSizeAdjust().isAuto()) 1850 ASSERT(style); 1851 if (style->textSizeAdjust().isAuto() || (settings().textAutosizingUsesIdempotentMode() && !style->textSizeAdjust().isNone())) 1824 1852 return; 1825 1853 -
trunk/Source/WebCore/css/StyleResolver.h
r244904 r245838 501 501 void sweepMatchedPropertiesCache(); 502 502 503 void adjustRenderStyleForTextAutosizing(RenderStyle&, const Element*); 504 503 505 typedef HashMap<unsigned, MatchedPropertiesCacheItem> MatchedPropertiesCache; 504 506 MatchedPropertiesCache m_matchedPropertiesCache; -
trunk/Source/WebCore/page/FrameViewLayoutContext.cpp
r245716 r245838 492 492 { 493 493 auto& settings = layoutRoot.settings(); 494 if (!settings.textAutosizingEnabled() || renderView()->printing())495 return;496 494 bool idempotentMode = settings.textAutosizingUsesIdempotentMode(); 495 if (!settings.textAutosizingEnabled() || idempotentMode || renderView()->printing()) 496 return; 497 497 auto minimumZoomFontSize = settings.minimumZoomFontSize(); 498 498 if (!idempotentMode && !minimumZoomFontSize) -
trunk/Source/WebCore/rendering/RenderBlockFlow.cpp
r245543 r245838 3724 3724 } 3725 3725 3726 static inline float idempotentTextSize(float specifiedSize, float pageScale) 3727 { 3728 // This describes a piecewise curve when the page scale is 2/3. 3729 FloatPoint points[] = { {0.0f, 0.0f}, {6.0f, 12.0f}, {12.0f, 18.0f} }; 3730 3731 // When the page scale is 1, the curve should be the identity. 3732 // Linearly interpolate between the curve above and identity based on the page scale. 3733 // Beware that depending on the specific values picked in the curve, this interpolation might change the shape of the curve for very small pageScales. 3734 pageScale = std::min(std::max(pageScale, 0.5f), 1.0f); 3735 auto scalePoint = [&](FloatPoint point) { 3736 float fraction = 3.0f - 3.0f * pageScale; 3737 point.setY(point.x() + (point.y() - point.x()) * fraction); 3738 return point; 3739 }; 3740 3741 if (specifiedSize <= 0) 3742 return 0; 3743 3744 float result = scalePoint(points[WTF_ARRAY_LENGTH(points) - 1]).y(); 3745 for (size_t i = 1; i < WTF_ARRAY_LENGTH(points); ++i) { 3746 if (points[i].x() < specifiedSize) 3747 continue; 3748 auto leftPoint = scalePoint(points[i - 1]); 3749 auto rightPoint = scalePoint(points[i]); 3750 float fraction = (specifiedSize - leftPoint.x()) / (rightPoint.x() - leftPoint.x()); 3751 result = leftPoint.y() + fraction * (rightPoint.y() - leftPoint.y()); 3752 break; 3753 } 3754 3755 return std::max(result, specifiedSize); 3756 } 3757 3758 void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth, float pageScale, bool idempotentMode) 3726 void RenderBlockFlow::adjustComputedFontSizes(float size, float visibleWidth) 3759 3727 { 3760 3728 LOG(TextAutosizing, "RenderBlockFlow %p adjustComputedFontSizes, size=%f visibleWidth=%f, width()=%f. Bailing: %d", this, size, visibleWidth, width().toFloat(), visibleWidth >= width()); 3761 3729 3762 3730 // Don't do any work if the block is smaller than the visible area. 3763 if ( !idempotentMode &&visibleWidth >= width())3731 if (visibleWidth >= width()) 3764 3732 return; 3765 3733 … … 3799 3767 float specifiedSize = fontDescription.specifiedSize(); 3800 3768 float scaledSize = roundf(specifiedSize * scale); 3801 if ( idempotentMode || (scaledSize > 0 && scaledSize < minFontSize)) {3769 if (scaledSize > 0 && scaledSize < minFontSize) { 3802 3770 // 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. 3803 3771 // This makes text resizing consistent even if the block's width or line count changes (which can be caused by text resizing itself 5159915). … … 3807 3775 m_widthForTextAutosizing = actualWidth; 3808 3776 3809 float candidateNewSize; 3810 if (idempotentMode) { 3811 float lineTextSize = idempotentTextSize(specifiedSize, pageScale); 3812 candidateNewSize = roundf(lineTextSize); 3813 } else { 3814 float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(text, specifiedSize) : textMultiplier(text, specifiedSize); 3815 candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier)); 3816 } 3777 float lineTextMultiplier = lineCount == ONE_LINE ? oneLineTextMultiplier(text, specifiedSize) : textMultiplier(text, specifiedSize); 3778 float candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier)); 3817 3779 3818 3780 if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto()) -
trunk/Source/WebCore/rendering/RenderBlockFlow.h
r244682 r245838 605 605 #if ENABLE(TEXT_AUTOSIZING) 606 606 int lineCountForTextAutosizing(); 607 void adjustComputedFontSizes(float size, float visibleWidth , float pageScale, bool idempotentMode);607 void adjustComputedFontSizes(float size, float visibleWidth); 608 608 void resetComputedFontSize() 609 609 { -
trunk/Source/WebCore/rendering/RenderElement.cpp
r245543 r245838 2126 2126 return RenderObject::FixedHeight; 2127 2127 } 2128 if (renderer.document().settings().textAutosizingUsesIdempotentMode() && style.maxHeight().type() == Fixed && is<RenderBlock>(renderer) && style.maxHeight().value() <= downcast<RenderBlock>(renderer).layoutOverflowRect().maxY())2129 return RenderObject::FixedHeight;2130 2128 return RenderObject::FlexibleHeight; 2131 2129 } … … 2136 2134 if (!document) 2137 2135 return; 2138 2139 auto pageScale = document->page() ? document->page()->initialScale() : 1.0f;2140 2136 2141 2137 Vector<int> depthStack; 2142 2138 int currentDepth = 0; 2143 2139 int newFixedDepth = 0; 2144 auto idempotentMode = document->settings().textAutosizingUsesIdempotentMode();2145 2140 2146 2141 // We don't apply autosizing to nodes with fixed height normally. … … 2155 2150 2156 2151 int stackSize = depthStack.size(); 2157 if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && ( idempotentMode ||!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth))2158 downcast<RenderBlockFlow>(*descendent).adjustComputedFontSizes(size, visibleWidth , pageScale, idempotentMode);2152 if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && (!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth)) 2153 downcast<RenderBlockFlow>(*descendent).adjustComputedFontSizes(size, visibleWidth); 2159 2154 newFixedDepth = 0; 2160 2155 } … … 2177 2172 int currentDepth = 0; 2178 2173 int newFixedDepth = 0; 2179 auto idempotentMode = document->settings().textAutosizingUsesIdempotentMode();2180 2174 2181 2175 for (RenderObject* descendent = traverseNext(this, includeNonFixedHeight, currentDepth, newFixedDepth); descendent; descendent = descendent->traverseNext(this, includeNonFixedHeight, currentDepth, newFixedDepth)) { … … 2186 2180 2187 2181 int stackSize = depthStack.size(); 2188 if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && ( idempotentMode ||!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth))2182 if (is<RenderBlockFlow>(*descendent) && !descendent->isListItem() && (!stackSize || currentDepth - depthStack[stackSize - 1] > TextAutoSizingFixedHeightDepth)) 2189 2183 downcast<RenderBlockFlow>(*descendent).resetComputedFontSize(); 2190 2184 newFixedDepth = 0; -
trunk/Source/WebCore/rendering/style/RenderStyle.cpp
r245543 r245838 166 166 m_inheritedFlags.insideDefaultButton = false; 167 167 m_inheritedFlags.writingMode = initialWritingMode(); 168 #if ENABLE(TEXT_AUTOSIZING) 169 m_inheritedFlags.autosizeStatus = 0; 170 #endif 168 171 169 172 m_nonInheritedFlags.effectiveDisplay = static_cast<unsigned>(initialDisplay()); … … 490 493 } 491 494 495 AutosizeStatus RenderStyle::autosizeStatus() const 496 { 497 return OptionSet<AutosizeStatus::Fields>::fromRaw(m_inheritedFlags.autosizeStatus); 498 } 499 500 void RenderStyle::setAutosizeStatus(AutosizeStatus autosizeStatus) 501 { 502 m_inheritedFlags.autosizeStatus = autosizeStatus.fields().toRaw(); 503 } 504 492 505 #endif // ENABLE(TEXT_AUTOSIZING) 493 506 -
trunk/Source/WebCore/rendering/style/RenderStyle.h
r245543 r245838 745 745 #if ENABLE(TEXT_AUTOSIZING) 746 746 TextSizeAdjustment textSizeAdjust() const { return m_rareInheritedData->textSizeAdjust; } 747 AutosizeStatus autosizeStatus() const; 747 748 #endif 748 749 … … 1259 1260 #if ENABLE(TEXT_AUTOSIZING) 1260 1261 void setTextSizeAdjust(TextSizeAdjustment adjustment) { SET_VAR(m_rareInheritedData, textSizeAdjust, adjustment); } 1262 void setAutosizeStatus(AutosizeStatus); 1261 1263 #endif 1262 1264 … … 1846 1848 unsigned writingMode : 2; // WritingMode 1847 1849 // 48 bits 1850 1851 #if ENABLE(TEXT_AUTOSIZING) 1852 unsigned autosizeStatus : 4; 1853 #endif 1854 // 52 bits 1848 1855 }; 1849 1856 -
trunk/Source/WebCore/rendering/style/TextSizeAdjustment.h
r208668 r245838 23 23 #if ENABLE(TEXT_AUTOSIZING) 24 24 25 #include <wtf/OptionSet.h> 26 25 27 namespace WebCore { 28 29 class RenderStyle; 26 30 27 31 enum TextSizeAdjustmentType { AutoTextSizeAdjustment = -1, NoTextSizeAdjustment = -2 }; … … 46 50 }; 47 51 52 class AutosizeStatus { 53 public: 54 enum class Fields : uint8_t { 55 FoundOutOfFlowPosition = 1 << 0, 56 FoundInlineBlock = 1 << 1, 57 FoundFixedHeight = 1 << 2, 58 FoundDisplayNone = 1 << 3 59 // Adding new values requires giving RenderStyle::InheritedFlags::autosizeStatus additional bits. 60 }; 61 62 AutosizeStatus(OptionSet<Fields>); 63 OptionSet<Fields> fields() const { return m_fields; } 64 65 bool contains(Fields) const; 66 bool shouldSkipSubtree() const; 67 68 static float idempotentTextSize(float specifiedSize, float pageScale); 69 static AutosizeStatus updateStatus(RenderStyle&); 70 71 private: 72 OptionSet<Fields> m_fields; 73 }; 74 75 48 76 } // namespace WebCore 49 77
Note: See TracChangeset
for help on using the changeset viewer.