Changeset 220685 in webkit
- Timestamp:
- Aug 14, 2017 6:20:47 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r220646 r220685 1 2017-08-14 Antti Koivisto <antti@apple.com> 2 3 Factor text autosizing into a class 4 https://bugs.webkit.org/show_bug.cgi?id=175530 5 6 Reviewed by Andreas Kling. 7 8 Move the remaining parts out of Document. 9 10 * css/StyleBuilderCustom.h: 11 (WebCore::computeLineHeightMultiplierDueToFontSize): 12 * dom/Document.cpp: 13 (WebCore::Document::destroyRenderTree): 14 (WebCore::Document::textAutoSizing): 15 (WebCore::TextAutoSizingTraits::constructDeletedValue): Deleted. 16 (WebCore::TextAutoSizingTraits::isDeletedValue): Deleted. 17 (WebCore::Document::addAutoSizedNode): Deleted. 18 (WebCore::Document::updateAutoSizedNodes): Deleted. 19 (WebCore::Document::clearAutoSizedNodes): Deleted. 20 * dom/Document.h: 21 * rendering/RenderBlockFlow.cpp: 22 (WebCore::RenderBlockFlow::adjustComputedFontSizes): 23 * rendering/RenderElement.cpp: 24 (WebCore::RenderElement::adjustComputedFontSizesOnBlocks): 25 (WebCore::RenderElement::resetTextAutosizing): 26 * rendering/TextAutoSizing.cpp: 27 (WebCore::TextAutoSizingTraits::constructDeletedValue): 28 (WebCore::TextAutoSizingTraits::isDeletedValue): 29 (WebCore::TextAutoSizing::addTextNode): 30 (WebCore::TextAutoSizing::updateRenderTree): 31 (WebCore::TextAutoSizing::reset): 32 * rendering/TextAutoSizing.h: 33 1 34 2017-08-14 Antti Koivisto <antti@apple.com> 2 35 -
trunk/Source/WebCore/css/StyleBuilderCustom.h
r219665 r220685 681 681 682 682 // This calculation matches the line-height computed size calculation in 683 // TextAutoSizing Value::adjustTextNodeSizes().683 // TextAutoSizing::Value::adjustTextNodeSizes(). 684 684 auto scaleChange = minimumFontSize / specifiedFontSize; 685 685 return scaleChange; -
trunk/Source/WebCore/dom/Document.cpp
r220539 r220685 428 428 } 429 429 430 #if ENABLE(TEXT_AUTOSIZING)431 432 void TextAutoSizingTraits::constructDeletedValue(TextAutoSizingKey& slot)433 {434 new (NotNull, &slot) TextAutoSizingKey(TextAutoSizingKey::Deleted);435 }436 437 bool TextAutoSizingTraits::isDeletedValue(const TextAutoSizingKey& value)438 {439 return value.isDeleted();440 }441 442 #endif443 444 430 uint64_t Document::s_globalTreeVersion = 0; 445 431 … … 2265 2251 2266 2252 #if ENABLE(TEXT_AUTOSIZING) 2267 // Do this before the arena is cleared, which is needed to deref the RenderStyle on TextAutoSizingKey. 2268 m_textAutoSizedNodes.clear(); 2253 m_textAutoSizing = nullptr; 2269 2254 #endif 2270 2255 … … 5559 5544 5560 5545 #if ENABLE(TEXT_AUTOSIZING) 5561 5562 void Document::addAutoSizedNode(Text& node, float candidateSize) 5563 { 5564 LOG(TextAutosizing, " addAutoSizedNode %p candidateSize=%f", &node, candidateSize); 5565 auto addResult = m_textAutoSizedNodes.add<TextAutoSizingHashTranslator>(node.renderer()->style(), nullptr); 5566 if (addResult.isNewEntry) 5567 addResult.iterator->value = std::make_unique<TextAutoSizingValue>(); 5568 addResult.iterator->value->addTextNode(node, candidateSize); 5569 } 5570 5571 void Document::updateAutoSizedNodes() 5572 { 5573 m_textAutoSizedNodes.removeIf([](auto& keyAndValue) { 5574 return keyAndValue.value->adjustTextNodeSizes() == TextAutoSizingValue::StillHasNodes::No; 5575 }); 5576 } 5577 5578 void Document::clearAutoSizedNodes() 5579 { 5580 m_textAutoSizedNodes.clear(); 5581 } 5582 5546 TextAutoSizing& Document::textAutoSizing() 5547 { 5548 if (!m_textAutoSizing) 5549 m_textAutoSizing = std::make_unique<TextAutoSizing>(); 5550 return *m_textAutoSizing; 5551 } 5583 5552 #endif // ENABLE(TEXT_AUTOSIZING) 5584 5553 -
trunk/Source/WebCore/dom/Document.h
r220539 r220685 208 208 209 209 #if ENABLE(TEXT_AUTOSIZING) 210 struct TextAutoSizingHash; 211 class TextAutoSizingKey; 212 class TextAutoSizingValue; 213 214 struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> { 215 static const bool emptyValueIsZero = true; 216 static void constructDeletedValue(TextAutoSizingKey& slot); 217 static bool isDeletedValue(const TextAutoSizingKey& value); 218 }; 210 class TextAutoSizing; 219 211 #endif 220 212 … … 1363 1355 void releaseEvents() { } 1364 1356 1357 #if ENABLE(TEXT_AUTOSIZING) 1358 TextAutoSizing& textAutoSizing(); 1359 #endif 1360 1365 1361 protected: 1366 1362 enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 }; … … 1666 1662 1667 1663 #if ENABLE(TEXT_AUTOSIZING) 1668 public: 1669 void addAutoSizedNode(Text&, float size); 1670 void updateAutoSizedNodes(); 1671 void clearAutoSizedNodes(); 1672 1673 private: 1674 using TextAutoSizingMap = HashMap<TextAutoSizingKey, std::unique_ptr<TextAutoSizingValue>, TextAutoSizingHash, TextAutoSizingTraits>; 1675 TextAutoSizingMap m_textAutoSizedNodes; 1664 std::unique_ptr<TextAutoSizing> m_textAutoSizing; 1676 1665 #endif 1677 1666 -
trunk/Source/WebCore/rendering/RenderBlockFlow.cpp
r220535 r220685 54 54 #include "SimpleLineLayoutFunctions.h" 55 55 #include "SimpleLineLayoutPagination.h" 56 #include "TextAutoSizing.h" 56 57 #include "VerticalPositionCache.h" 57 58 #include "VisiblePosition.h" … … 3907 3908 float candidateNewSize = roundf(std::min(minFontSize, specifiedSize * lineTextMultiplier)); 3908 3909 if (candidateNewSize > specifiedSize && candidateNewSize != fontDescription.computedSize() && text.textNode() && oldStyle.textSizeAdjust().isAuto()) 3909 document(). addAutoSizedNode(*text.textNode(), candidateNewSize);3910 document().textAutoSizing().addTextNode(*text.textNode(), candidateNewSize); 3910 3911 } 3911 3912 -
trunk/Source/WebCore/rendering/RenderElement.cpp
r220073 r220685 75 75 #include "StylePendingResources.h" 76 76 #include "StyleResolver.h" 77 #include "TextAutoSizing.h" 77 78 #include <wtf/MathExtras.h> 78 79 #include <wtf/StackStats.h> … … 2315 2316 2316 2317 // Remove style from auto-sizing table that are no longer valid. 2317 document-> updateAutoSizedNodes();2318 document->textAutoSizing().updateRenderTree(); 2318 2319 } 2319 2320 … … 2326 2327 LOG(TextAutosizing, "RenderElement::resetTextAutosizing()"); 2327 2328 2328 document-> clearAutoSizedNodes();2329 document->textAutoSizing().reset(); 2329 2330 2330 2331 Vector<int> depthStack; -
trunk/Source/WebCore/rendering/TextAutoSizing.cpp
r220646 r220685 216 216 } 217 217 218 void TextAutoSizing::addTextNode(Text& node, float candidateSize) 219 { 220 LOG(TextAutosizing, " addAutoSizedNode %p candidateSize=%f", &node, candidateSize); 221 auto addResult = m_textNodes.add<TextAutoSizingHashTranslator>(node.renderer()->style(), nullptr); 222 if (addResult.isNewEntry) 223 addResult.iterator->value = std::make_unique<TextAutoSizingValue>(); 224 addResult.iterator->value->addTextNode(node, candidateSize); 225 } 226 227 void TextAutoSizing::updateRenderTree() 228 { 229 m_textNodes.removeIf([](auto& keyAndValue) { 230 return keyAndValue.value->adjustTextNodeSizes() == TextAutoSizingValue::StillHasNodes::No; 231 }); 232 } 233 234 void TextAutoSizing::reset() 235 { 236 m_textNodes.clear(); 237 } 238 218 239 } // namespace WebCore 219 240 -
trunk/Source/WebCore/rendering/TextAutoSizing.h
r206395 r220685 29 29 30 30 #include "RenderStyle.h" 31 #include <wtf/HashMap.h> 31 32 #include <wtf/HashSet.h> 32 33 #include <wtf/RefCounted.h> … … 108 109 }; 109 110 111 struct TextAutoSizingTraits : WTF::GenericHashTraits<TextAutoSizingKey> { 112 static const bool emptyValueIsZero = true; 113 static void constructDeletedValue(TextAutoSizingKey& slot) { new (NotNull, &slot) TextAutoSizingKey(TextAutoSizingKey::Deleted); } 114 static bool isDeletedValue(const TextAutoSizingKey& value) { return value.isDeleted(); } 115 }; 116 117 class TextAutoSizing { 118 WTF_MAKE_FAST_ALLOCATED; 119 public: 120 TextAutoSizing() = default; 121 122 void addTextNode(Text&, float size); 123 void updateRenderTree(); 124 void reset(); 125 126 private: 127 HashMap<TextAutoSizingKey, std::unique_ptr<TextAutoSizingValue>, TextAutoSizingHash, TextAutoSizingTraits> m_textNodes; 128 }; 129 110 130 } // namespace WebCore 111 131
Note: See TracChangeset
for help on using the changeset viewer.