Changeset 203896 in webkit
- Timestamp:
- Jul 29, 2016 12:21:57 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r203858 r203896 1 2016-07-29 Frederic Wang <fwang@igalia.com> 2 3 Parse the operator text on the MathMLOperatorElement class. 4 https://bugs.webkit.org/show_bug.cgi?id=160241 5 6 Reviewed by Darin Adler. 7 8 The text of the MathML operators is important to determine form or dictionary properties and 9 hence provide default values when no explicit attributes are privided. Since that text only 10 depends on the MathML DOM content, it makes sense to move its parsing into 11 MathMLOperatorElement. Anonymous operators created by the mfenced elements still need to be 12 handled specially and this will be true for all the operator properties that can just be 13 determined in MathMLOperatorElement. Hence in a follow-up patch we will introduce a class 14 to move all the code specific to mfenced in a class derived from RenderMathMLOperator while 15 we continue to move the corresponding code for non-anonymous into MathMLOperatorElement. 16 17 No new tests, behavior is unchanged. 18 19 * mathml/MathMLOperatorElement.cpp: Include header for hyphenMinus/minusSign characters. 20 (WebCore::MathMLOperatorElement::parseOperatorText): Move that code from rebuildTokenContent 21 (WebCore::MathMLOperatorElement::operatorText): Helper function to get the cached text. 22 (WebCore::MathMLOperatorElement::childrenChanged): Make the cached text dirty. 23 * mathml/MathMLOperatorElement.h: Update defitions and add a member for the operator text. 24 * mathml/MathMLTextElement.h: Make childrenChanged overridable. 25 * rendering/mathml/RenderMathMLOperator.cpp: 26 (WebCore::RenderMathMLOperator::element): Helper function to cast to a MathMLOperatorElement. 27 (WebCore::RenderMathMLOperator::textContent): Helper function to call 28 MathMLOperatorElement::operatorText or fallback to m_textContent for anonymous operators. 29 m_textContent and this special case can be moved into a derived class later. 30 (WebCore::RenderMathMLOperator::setOperatorProperties): Call textContent(). 31 (WebCore::RenderMathMLOperator::computePreferredLogicalWidths): Ditto. 32 (WebCore::RenderMathMLOperator::rebuildTokenContent): Remove the string parameter and the 33 parsing of the operator text. 34 (WebCore::RenderMathMLOperator::updateTokenContent): Call textContent(). The special function 35 for anonymous operators also parses the text content but this could be moved into a derived 36 class later. 37 (WebCore::RenderMathMLOperator::shouldAllowStretching): Call textContent(). 38 (WebCore::RenderMathMLOperator::useMathOperator): Ditto. 39 (WebCore::RenderMathMLOperator::RenderMathMLOperator): No need to initialize m_textContent 40 as it is not used anymore for non-anonymous renderers. 41 * rendering/mathml/RenderMathMLOperator.h: Update definitions and call textContent(). 42 1 43 2016-07-28 Youenn Fablet <youenn@apple.com> 2 44 -
trunk/Source/WebCore/mathml/MathMLOperatorElement.cpp
r203688 r203896 31 31 32 32 #include "RenderMathMLOperator.h" 33 #include <wtf/unicode/CharacterNames.h> 33 34 34 35 namespace WebCore { … … 44 45 { 45 46 return adoptRef(*new MathMLOperatorElement(tagName, document)); 47 } 48 49 UChar MathMLOperatorElement::parseOperatorText(const String& string) 50 { 51 // We collapse the whitespace and replace the hyphens by minus signs. 52 AtomicString textContent = string.stripWhiteSpace().simplifyWhiteSpace().replace(hyphenMinus, minusSign).impl(); 53 54 // We verify whether the operator text can be represented by a single UChar. 55 // FIXME: This is a really inefficient way to extract a character from a string (https://webkit.org/b/160241#c7). 56 // FIXME: This does not handle surrogate pairs (https://webkit.org/b/122296). 57 // FIXME: This does not handle <mo> operators with multiple characters (https://webkit.org/b/124828). 58 return textContent.length() == 1 ? textContent[0] : 0; 59 } 60 61 UChar MathMLOperatorElement::operatorText() 62 { 63 if (m_operatorText) 64 return m_operatorText.value(); 65 66 m_operatorText = Optional<UChar>(parseOperatorText(textContent())); 67 return m_operatorText.value(); 68 } 69 70 void MathMLOperatorElement::childrenChanged(const ChildChange& change) 71 { 72 m_operatorText = Optional<UChar>(); 73 MathMLTextElement::childrenChanged(change); 46 74 } 47 75 -
trunk/Source/WebCore/mathml/MathMLOperatorElement.h
r203688 r203896 34 34 public: 35 35 static Ref<MathMLOperatorElement> create(const QualifiedName& tagName, Document&); 36 static UChar parseOperatorText(const String&); 37 UChar operatorText(); 38 36 39 private: 37 40 MathMLOperatorElement(const QualifiedName& tagName, Document&); 38 41 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final; 42 void childrenChanged(const ChildChange&) final; 39 43 void parseAttribute(const QualifiedName&, const AtomicString&) final; 44 45 Optional<UChar> m_operatorText; 40 46 }; 41 47 -
trunk/Source/WebCore/mathml/MathMLTextElement.h
r203688 r203896 40 40 protected: 41 41 MathMLTextElement(const QualifiedName& tagName, Document&); 42 void childrenChanged(const ChildChange&) override; 42 43 void parseAttribute(const QualifiedName&, const AtomicString&) override; 43 44 … … 46 47 bool childShouldCreateRenderer(const Node&) const final; 47 48 48 void childrenChanged(const ChildChange&) final;49 49 void didAttachRenderers() final; 50 50 -
trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp
r203688 r203896 52 52 , m_stretchHeightAboveBaseline(0) 53 53 , m_stretchDepthBelowBaseline(0) 54 , m_textContent(0)55 54 , m_isVertical(true) 56 55 { … … 70 69 } 71 70 71 MathMLOperatorElement& RenderMathMLOperator::element() const 72 { 73 return static_cast<MathMLOperatorElement&>(nodeForNonAnonymous()); 74 } 75 76 UChar RenderMathMLOperator::textContent() const 77 { 78 return isAnonymous() ? m_textContent : element().operatorText(); 79 } 80 72 81 void RenderMathMLOperator::setOperatorFlagFromAttribute(MathMLOperatorDictionary::Flag flag, const QualifiedName& name) 73 82 { … … 102 111 { 103 112 // We determine the stretch direction (default is vertical). 104 m_isVertical = MathMLOperatorDictionary::isVertical( m_textContent);113 m_isVertical = MathMLOperatorDictionary::isVertical(textContent()); 105 114 106 115 // We determine the form of the operator. … … 138 147 m_maxSize = intMaxForLayoutUnit; // This sets maxsize to "infinity". 139 148 140 if ( m_textContent) {149 if (textContent()) { 141 150 // Then we try to find the default values from the operator dictionary. 142 if (const MathMLOperatorDictionary::Entry* entry = MathMLOperatorDictionary::getEntry( m_textContent, m_operatorForm))151 if (const MathMLOperatorDictionary::Entry* entry = MathMLOperatorDictionary::getEntry(textContent(), m_operatorForm)) 143 152 setOperatorPropertiesFromOpDictEntry(entry); 144 153 else if (!explicitForm) { 145 154 // If we did not find the desired operator form and if it was not set explicitely, we use the first one in the following order: Infix, Prefix, Postfix. 146 155 // This is to handle bad MathML markup without explicit <mrow> delimiters like "<mo>(</mo><mi>a</mi><mo>)</mo><mo>(</mo><mi>b</mi><mo>)</mo>" where the inner parenthesis should not be considered infix. 147 if (const MathMLOperatorDictionary::Entry* entry = MathMLOperatorDictionary::getEntry( m_textContent)) {156 if (const MathMLOperatorDictionary::Entry* entry = MathMLOperatorDictionary::getEntry(textContent())) { 148 157 m_operatorForm = static_cast<MathMLOperatorDictionary::Form>(entry->form); // We override the form previously determined. 149 158 setOperatorPropertiesFromOpDictEntry(entry); … … 247 256 if (isInvisibleOperator()) { 248 257 // In some fonts, glyphs for invisible operators have nonzero width. Consequently, we subtract that width here to avoid wide gaps. 249 GlyphData data = style().fontCascade().glyphDataForCharacter( m_textContent, false);258 GlyphData data = style().fontCascade().glyphDataForCharacter(textContent(), false); 250 259 float glyphWidth = data.font ? data.font->widthForGlyph(data.glyph) : 0; 251 260 ASSERT(glyphWidth <= preferredWidth); … … 293 302 } 294 303 295 void RenderMathMLOperator::rebuildTokenContent(const String& operatorString) 296 { 297 // We collapse the whitespace and replace the hyphens by minus signs. 298 AtomicString textContent = operatorString.stripWhiteSpace().simplifyWhiteSpace().replace(hyphenMinus, minusSign).impl(); 299 300 // We verify whether the operator text can be represented by a single UChar. 301 // FIXME: This does not handle surrogate pairs (https://bugs.webkit.org/show_bug.cgi?id=122296). 302 // FIXME: This does not handle <mo> operators with multiple characters (https://bugs.webkit.org/show_bug.cgi?id=124828). 303 m_textContent = textContent.length() == 1 ? textContent[0] : 0; 304 void RenderMathMLOperator::rebuildTokenContent() 305 { 304 306 setOperatorProperties(); 305 307 … … 312 314 else 313 315 type = m_isVertical ? MathOperator::Type::VerticalOperator : MathOperator::Type::HorizontalOperator; 314 m_mathOperator.setOperator(style(), m_textContent, type);316 m_mathOperator.setOperator(style(), textContent(), type); 315 317 } 316 318 … … 321 323 { 322 324 ASSERT(isAnonymous()); 323 rebuildTokenContent(operatorString); 325 m_textContent = MathMLOperatorElement::parseOperatorText(operatorString); 326 rebuildTokenContent(); 324 327 } 325 328 … … 328 331 ASSERT(!isAnonymous()); 329 332 RenderMathMLToken::updateTokenContent(); 330 rebuildTokenContent( element().textContent());333 rebuildTokenContent(); 331 334 } 332 335 … … 344 347 bool RenderMathMLOperator::shouldAllowStretching() const 345 348 { 346 return m_textContent&& (hasOperatorFlag(MathMLOperatorDictionary::Stretchy) || isLargeOperatorInDisplayStyle());349 return textContent() && (hasOperatorFlag(MathMLOperatorDictionary::Stretchy) || isLargeOperatorInDisplayStyle()); 347 350 } 348 351 … … 353 356 // 2) The minus sign, since it can be obtained from a hyphen in the DOM. 354 357 // 3) The anonymous operators created by mfenced, since they do not have text content in the DOM. 355 return shouldAllowStretching() || m_textContent== minusSign || isAnonymous();358 return shouldAllowStretching() || textContent() == minusSign || isAnonymous(); 356 359 } 357 360 -
trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.h
r203688 r203896 41 41 RenderMathMLOperator(MathMLOperatorElement&, RenderStyle&&); 42 42 RenderMathMLOperator(Document&, RenderStyle&&, const String& operatorString, MathMLOperatorDictionary::Form, unsigned short flags = 0); 43 MathMLOperatorElement& element() const; 43 44 44 45 void stretchTo(LayoutUnit heightAboveBaseline, LayoutUnit depthBelowBaseline); … … 57 58 void updateOperatorProperties(); 58 59 void updateFromElement() final; 59 UChar textContent() const { return m_textContent; }60 UChar textContent() const; 60 61 61 62 private: … … 73 74 bool isRenderMathMLOperator() const final { return true; } 74 75 // The following operators are invisible: U+2061 FUNCTION APPLICATION, U+2062 INVISIBLE TIMES, U+2063 INVISIBLE SEPARATOR, U+2064 INVISIBLE PLUS. 75 bool isInvisibleOperator() const { return 0x2061 <= m_textContent && m_textContent<= 0x2064; }76 bool isInvisibleOperator() { return 0x2061 <= textContent() && textContent() <= 0x2064; } 76 77 77 78 Optional<int> firstLineBaseline() const final; 78 79 RenderMathMLOperator* unembellishedOperator() final { return this; } 79 void rebuildTokenContent( const String& operatorString);80 void rebuildTokenContent(); 80 81 81 82 bool shouldAllowStretching() const;
Note: See TracChangeset
for help on using the changeset viewer.