Changeset 199893 in webkit
- Timestamp:
- Apr 22, 2016 12:25:40 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r199890 r199893 1 2016-04-22 Antti Koivisto <antti@apple.com> 2 3 TextAutoSizingKey should use normal refcounting 4 https://bugs.webkit.org/show_bug.cgi?id=156893 5 6 Reviewed by Andreas Kling. 7 8 Get rid of special refcounting of style in favor of RefPtr. It also becomes a move-only type 9 to support future switch to non-refcounted RenderStyle. 10 11 Also general cleanups and modernization. 12 13 * dom/Document.cpp: 14 (WebCore::TextAutoSizingTraits::constructDeletedValue): 15 (WebCore::TextAutoSizingTraits::isDeletedValue): 16 (WebCore::Document::addAutoSizingNode): 17 (WebCore::Document::validateAutoSizingNodes): 18 (WebCore::Document::resetAutoSizingNodes): 19 20 Adopt to being move-only. 21 22 * rendering/TextAutoSizing.cpp: 23 (WebCore::cloneRenderStyleWithState): 24 (WebCore::TextAutoSizingKey::TextAutoSizingKey): 25 26 Clone the style for safety against mutations. Cloning is cheap. 27 28 (WebCore::TextAutoSizingValue::numNodes): 29 (WebCore::TextAutoSizingValue::adjustNodeSizes): 30 (WebCore::TextAutoSizingValue::reset): 31 (WebCore::TextAutoSizingKey::~TextAutoSizingKey): Deleted. 32 (WebCore::TextAutoSizingKey::operator=): Deleted. 33 (WebCore::TextAutoSizingKey::ref): Deleted. 34 (WebCore::TextAutoSizingKey::deref): Deleted. 35 * rendering/TextAutoSizing.h: 36 (WebCore::TextAutoSizingKey::TextAutoSizingKey): 37 (WebCore::TextAutoSizingKey::style): 38 (WebCore::TextAutoSizingKey::isDeleted): 39 (WebCore::operator==): 40 (WebCore::TextAutoSizingKey::doc): Deleted. 41 (WebCore::TextAutoSizingKey::isValidDoc): Deleted. 42 (WebCore::TextAutoSizingKey::isValidStyle): Deleted. 43 (WebCore::TextAutoSizingKey::deletedKeyDoc): Deleted. 44 (WebCore::TextAutoSizingKey::deletedKeyStyle): Deleted. 45 46 m_doc member is not used for anything except deleted value comparisons. Replace it with a bit. 47 1 48 2016-04-22 Chris Dumez <cdumez@apple.com> 2 49 -
trunk/Source/WebCore/dom/Document.cpp
r199882 r199893 429 429 void TextAutoSizingTraits::constructDeletedValue(TextAutoSizingKey& slot) 430 430 { 431 new (&slot) TextAutoSizingKey(TextAutoSizingKey:: deletedKeyStyle(), TextAutoSizingKey::deletedKeyDoc());431 new (&slot) TextAutoSizingKey(TextAutoSizingKey::Deleted); 432 432 } 433 433 434 434 bool TextAutoSizingTraits::isDeletedValue(const TextAutoSizingKey& value) 435 435 { 436 return value. style() == TextAutoSizingKey::deletedKeyStyle() && value.doc() == TextAutoSizingKey::deletedKeyDoc();436 return value.isDeleted(); 437 437 } 438 438 #endif … … 5292 5292 void Document::addAutoSizingNode(Node* node, float candidateSize) 5293 5293 { 5294 TextAutoSizingKey key(&node->renderer()->style() , &document());5295 TextAutoSizingMap::AddResult result = m_textAutoSizedNodes.add(key, nullptr);5296 if (result.isNewEntry)5297 result.iterator->value = TextAutoSizingValue::create();5298 result.iterator->value->addNode(node, candidateSize);5294 TextAutoSizingKey key(&node->renderer()->style()); 5295 auto addResult = m_textAutoSizedNodes.ensure(WTFMove(key), [] { 5296 return TextAutoSizingValue::create(); 5297 }); 5298 addResult.iterator->value->addNode(node, candidateSize); 5299 5299 } 5300 5300 … … 5306 5306 // Update all the nodes in the collection to reflect the new 5307 5307 // candidate size. 5308 if (!value)5309 continue;5310 5311 5308 value->adjustNodeSizes(); 5312 if (!value->numNodes()) 5313 nodesForRemoval.append(keyValuePair.key); 5314 } 5315 for (auto& key : nodesForRemoval) 5316 m_textAutoSizedNodes.remove(key); 5309 } 5310 m_textAutoSizedNodes.removeIf([] (TextAutoSizingMap::KeyValuePairType& keyAndValue) { 5311 return !keyAndValue.value->numNodes(); 5312 }); 5317 5313 } 5318 5314 5319 5315 void Document::resetAutoSizingNodes() 5320 5316 { 5321 for (auto& value : m_textAutoSizedNodes.values()) { 5322 if (value) 5323 value->reset(); 5324 } 5317 for (auto& value : m_textAutoSizedNodes.values()) 5318 value->reset(); 5325 5319 m_textAutoSizedNodes.clear(); 5326 5320 } -
trunk/Source/WebCore/rendering/TextAutoSizing.cpp
r189830 r199893 37 37 namespace WebCore { 38 38 39 static PassRefPtr<RenderStyle> cloneRenderStyleWithState(const RenderStyle& currentStyle)40 { 41 RefPtr<RenderStyle>newStyle = RenderStyle::clone(¤tStyle);39 static Ref<RenderStyle> cloneRenderStyleWithState(const RenderStyle& currentStyle) 40 { 41 auto newStyle = RenderStyle::clone(¤tStyle); 42 42 if (currentStyle.lastChildState()) 43 43 newStyle->setLastChildState(); 44 44 if (currentStyle.firstChildState()) 45 45 newStyle->setFirstChildState(); 46 return newStyle.release(); 47 } 48 49 TextAutoSizingKey::TextAutoSizingKey() 50 : m_style(0) 51 , m_doc(0) 52 { 53 } 54 55 TextAutoSizingKey::TextAutoSizingKey(RenderStyle* style, Document* doc) 56 : m_style(style) 57 , m_doc(doc) 58 { 59 ref(); 60 } 61 62 TextAutoSizingKey::TextAutoSizingKey(const TextAutoSizingKey& other) 63 : m_style(other.m_style) 64 , m_doc(other.m_doc) 65 { 66 ref(); 67 } 68 69 TextAutoSizingKey::~TextAutoSizingKey() 70 { 71 deref(); 72 } 73 74 TextAutoSizingKey& TextAutoSizingKey::operator=(const TextAutoSizingKey& other) 75 { 76 other.ref(); 77 deref(); 78 m_style = other.m_style; 79 m_doc = other.m_doc; 80 return *this; 81 } 82 83 void TextAutoSizingKey::ref() const 84 { 85 if (isValidStyle()) 86 m_style->ref(); 87 } 88 89 void TextAutoSizingKey::deref() const 90 { 91 if (isValidStyle() && isValidDoc()) 92 m_style->deref(); 46 return newStyle; 47 } 48 49 TextAutoSizingKey::TextAutoSizingKey(DeletedTag) 50 : m_isDeleted(true) 51 { 52 } 53 54 TextAutoSizingKey::TextAutoSizingKey(RenderStyle* style) 55 : m_style(RenderStyle::clone(style)) 56 { 93 57 } 94 58 … … 115 79 // collection. Return true indicates we need to do that removal. 116 80 Vector<RefPtr<Node> > nodesForRemoval; 117 HashSet<RefPtr<Node> >::iterator end = m_autoSizedNodes.end(); 118 for (HashSet<RefPtr<Node> >::iterator i = m_autoSizedNodes.begin(); i != end; ++i) { 119 RefPtr<Node> autoSizingNode = *i; 81 for (auto& autoSizingNode : m_autoSizedNodes) { 120 82 RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer()); 121 83 if (!text || !text->style().textSizeAdjust().isAuto() || !text->candidateComputedTextSize()) { … … 126 88 } 127 89 128 unsigned count = nodesForRemoval.size(); 129 for (unsigned i = 0; i < count; i++) 130 m_autoSizedNodes.remove(nodesForRemoval[i]); 90 for (auto& node : nodesForRemoval) 91 m_autoSizedNodes.remove(node); 131 92 132 93 // If we only have one piece of text with the style on the page don't … … 137 98 // Compute average size 138 99 float cumulativeSize = 0; 139 end = m_autoSizedNodes.end(); 140 for (HashSet<RefPtr<Node> >::iterator i = m_autoSizedNodes.begin(); i != end; ++i) { 141 RefPtr<Node> autoSizingNode = *i; 100 for (auto& autoSizingNode : m_autoSizedNodes) { 142 101 RenderText* renderText = static_cast<RenderText*>(autoSizingNode->renderer()); 143 102 cumulativeSize += renderText->candidateComputedTextSize(); … … 148 107 // Adjust sizes 149 108 bool firstPass = true; 150 end = m_autoSizedNodes.end(); 151 for (HashSet<RefPtr<Node> >::iterator i = m_autoSizedNodes.begin(); i != end; ++i) { 152 const RefPtr<Node>& autoSizingNode = *i; 109 for (auto& autoSizingNode : m_autoSizedNodes) { 153 110 RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer()); 154 111 if (text && text->style().fontDescription().computedSize() != averageSize) { … … 161 118 } 162 119 163 RefPtr<RenderStyle>style = cloneRenderStyleWithState(text->style());120 auto style = cloneRenderStyleWithState(text->style()); 164 121 auto fontDescription = style->fontDescription(); 165 122 fontDescription.setComputedSize(averageSize); 166 123 style->setFontDescription(fontDescription); 167 124 style->fontCascade().update(&autoSizingNode->document().fontSelector()); 168 text->parent()->setStyle( style.releaseNonNull());125 text->parent()->setStyle(WTFMove(style)); 169 126 170 127 RenderElement* parentRenderer = text->parent(); … … 175 132 RenderObject* listMarkerRenderer = parentRenderer->firstChild(); 176 133 if (listMarkerRenderer->isListMarker()) { 177 RefPtr<RenderStyle>style = cloneRenderStyleWithState(listMarkerRenderer->style());134 auto style = cloneRenderStyleWithState(listMarkerRenderer->style()); 178 135 style->setFontDescription(fontDescription); 179 136 style->fontCascade().update(&autoSizingNode->document().fontSelector()); 180 downcast<RenderListMarker>(*listMarkerRenderer).setStyle( style.releaseNonNull());137 downcast<RenderListMarker>(*listMarkerRenderer).setStyle(WTFMove(style)); 181 138 } 182 139 … … 193 150 int lineHeight = specifiedLineHeight * scaleChange; 194 151 if (!lineHeightLength.isFixed() || lineHeightLength.value() != lineHeight) { 195 RefPtr<RenderStyle>newParentStyle = cloneRenderStyleWithState(parentStyle);152 auto newParentStyle = cloneRenderStyleWithState(parentStyle); 196 153 newParentStyle->setLineHeight(Length(lineHeight, Fixed)); 197 154 newParentStyle->setSpecifiedLineHeight(lineHeightLength); 198 155 newParentStyle->setFontDescription(fontDescription); 199 156 newParentStyle->fontCascade().update(&autoSizingNode->document().fontSelector()); 200 parentRenderer->setStyle( newParentStyle.releaseNonNull());157 parentRenderer->setStyle(WTFMove(newParentStyle)); 201 158 } 202 159 } … … 208 165 void TextAutoSizingValue::reset() 209 166 { 210 HashSet<RefPtr<Node> >::iterator end = m_autoSizedNodes.end(); 211 for (HashSet<RefPtr<Node> >::iterator i = m_autoSizedNodes.begin(); i != end; ++i) { 212 const RefPtr<Node>& autoSizingNode = *i; 167 for (auto& autoSizingNode : m_autoSizedNodes) { 213 168 RenderText* text = static_cast<RenderText*>(autoSizingNode->renderer()); 214 169 if (!text) … … 219 174 if (fontDescription.computedSize() != originalSize) { 220 175 fontDescription.setComputedSize(originalSize); 221 RefPtr<RenderStyle>style = cloneRenderStyleWithState(text->style());176 auto style = cloneRenderStyleWithState(text->style()); 222 177 style->setFontDescription(fontDescription); 223 178 style->fontCascade().update(&autoSizingNode->document().fontSelector()); 224 text->parent()->setStyle( style.releaseNonNull());179 text->parent()->setStyle(WTFMove(style)); 225 180 } 226 181 // Reset the line height of the parent. … … 235 190 Length originalLineHeight = parentStyle.specifiedLineHeight(); 236 191 if (originalLineHeight != parentStyle.lineHeight()) { 237 RefPtr<RenderStyle>newParentStyle = cloneRenderStyleWithState(parentStyle);192 auto newParentStyle = cloneRenderStyleWithState(parentStyle); 238 193 newParentStyle->setLineHeight(originalLineHeight); 239 194 newParentStyle->setFontDescription(fontDescription); 240 195 newParentStyle->fontCascade().update(&autoSizingNode->document().fontSelector()); 241 parentRenderer->setStyle( newParentStyle.releaseNonNull());196 parentRenderer->setStyle(WTFMove(newParentStyle)); 242 197 } 243 198 } -
trunk/Source/WebCore/rendering/TextAutoSizing.h
r184147 r199893 41 41 class TextAutoSizingKey { 42 42 public: 43 TextAutoSizingKey() ;44 TextAutoSizingKey(RenderStyle*, Document*);45 ~TextAutoSizingKey();46 TextAutoSizingKey(const TextAutoSizingKey&);47 TextAutoSizingKey & operator=(const TextAutoSizingKey&);48 Document* doc() const { return m_doc; } 49 RenderStyle* style() const { return m_style; }50 inline bool isValidDoc() const { return m_doc && m_doc != deletedKeyDoc(); } 51 inline bool isValidStyle() const { return m_style && m_style != deletedKeyStyle(); }52 static Document* deletedKeyDoc() { return reinterpret_cast<Document*>(-1); }53 static RenderStyle* deletedKeyStyle() { return reinterpret_cast<RenderStyle*>(-1); } 43 TextAutoSizingKey() = default; 44 enum DeletedTag { Deleted }; 45 explicit TextAutoSizingKey(DeletedTag); 46 explicit TextAutoSizingKey(RenderStyle*); 47 TextAutoSizingKey(TextAutoSizingKey&&) = default; 48 49 TextAutoSizingKey& operator=(TextAutoSizingKey&&) = default; 50 51 RenderStyle* style() const { return m_style.get(); } 52 inline bool isDeleted() const { return m_isDeleted; } 53 54 54 private: 55 void ref() const; 56 void deref() const; 57 RenderStyle* m_style; 58 Document* m_doc; 55 RefPtr<RenderStyle> m_style; 56 bool m_isDeleted { false }; 59 57 }; 60 58 61 59 inline bool operator==(const TextAutoSizingKey& a, const TextAutoSizingKey& b) 62 60 { 63 if (a.isValidStyle() && b.isValidStyle()) 64 return a.style()->equalForTextAutosizing(b.style()); 65 return a.style() == b.style(); 61 if (a.isDeleted() || b.isDeleted()) 62 return false; 63 if (!a.style() || !b.style()) 64 return a.style() == b.style(); 65 return a.style()->equalForTextAutosizing(b.style()); 66 66 } 67 67
Note: See TracChangeset
for help on using the changeset viewer.