Source/WebCore/ChangeLog

 12017-11-29 Frederic Wang <fwang@igalia.com>
 2
 3 Improve initialization of script/root type of MathML renderers
 4 https://bugs.webkit.org/show_bug.cgi?id=180161
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 RenderMathMLRoot::m_kind and RenderMathMLScripts::m_scriptType are initialized in the
 9 constructors and remained unchanged. This patch refactors a bit the initialization so that
 10 these members are changed to const in order to guarantee they are not modified during the
 11 life time of the renderer. The patch also includes minor stylistic improvements.
 12
 13 No new tests, behavior unchanged.
 14
 15 * rendering/mathml/RenderMathMLRoot.cpp: Add "using" statement for MathMLNames namespace.
 16 (WebCore::RenderMathMLRoot::RenderMathMLRoot): Use rootTypeOf() to initialize the m_rootType.
 17 (WebCore::RenderMathMLRoot::rootTypeOf): New helper function to determine the kind of root
 18 expression from the tag name. Make the comment a real sentence, add an ASSERT and remove the
 19 MathMLNames:: namespace.
 20 (WebCore::RenderMathMLRoot::isValid const): Rename m_kind to m_rootType.
 21 (WebCore::RenderMathMLRoot::getBase const): Ditto.
 22 (WebCore::RenderMathMLRoot::getIndex const): Ditto.
 23 (WebCore::RenderMathMLRoot::horizontalParameters): Ditto.
 24 (WebCore::RenderMathMLRoot::verticalParameters): Ditto.
 25 (WebCore::RenderMathMLRoot::computePreferredLogicalWidths): Ditto.
 26 (WebCore::RenderMathMLRoot::layoutBlock): Ditto.
 27 (WebCore::RenderMathMLRoot::paint): Ditto.
 28 * rendering/mathml/RenderMathMLRoot.h: Ditto, make m_rootType a const and declare the
 29 rootTypeOf() helper function.
 30 * rendering/mathml/RenderMathMLScripts.cpp: Add "using" statement for MathMLNames namespace.
 31 (WebCore::isPrescriptDelimiter): Remove the MathMLNames:: namespace.
 32 (WebCore::RenderMathMLScripts::RenderMathMLScripts): Use scriptTypeOf() to initialize m_scriptType.
 33 (WebCore::RenderMathMLScripts::scriptTypeOf): New helper function to determine the kind of
 34 scripted expression from the tag name. Make the comment a real sentence and remove the
 35 MathMLNames:: namespace.
 36 * rendering/mathml/RenderMathMLScripts.h: Make m_scriptType a const and declare the
 37 scriptTypeOf() helper function.
 38
1392017-11-29 Youenn Fablet <youenn@apple.com>
240
341 LibWebRTCPeerConnectionBackend should clean its stats promises when being cleaned

Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp

@@static const UChar gRadicalCharacter = 0x221A;
4444
4545namespace WebCore {
4646
 47using namespace MathMLNames;
 48
4749WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMathMLRoot);
4850
4951RenderMathMLRoot::RenderMathMLRoot(MathMLRowElement& element, RenderStyle&& style)
5052 : RenderMathMLRow(element, WTFMove(style))
 53 , m_rootType(rootTypeOf(element))
5154{
52  // Determine what kind of expression we have by element name
53  if (element.hasTagName(MathMLNames::msqrtTag))
54  m_kind = SquareRoot;
55  else if (element.hasTagName(MathMLNames::mrootTag))
56  m_kind = RootWithIndex;
57 
5855 m_radicalOperator.setOperator(RenderMathMLRoot::style(), gRadicalCharacter, MathOperator::Type::VerticalOperator);
5956}
6057
 58RenderMathMLRoot::RootType RenderMathMLRoot::rootTypeOf(const MathMLRowElement& element)
 59{
 60 // The kind of root expression is determined from the element name.
 61 if (element.hasTagName(msqrtTag))
 62 return SquareRoot;
 63 ASSERT(element.hasTagName(mrootTag));
 64 return RootWithIndex;
 65}
 66
6167bool RenderMathMLRoot::isValid() const
6268{
6369 // Verify whether the list of children is valid:
6470 // <msqrt> child1 child2 ... childN </msqrt>
6571 // <mroot> base index </mroot>
66  if (m_kind == SquareRoot)
 72 if (m_rootType == SquareRoot)
6773 return true;
6874
69  ASSERT(m_kind == RootWithIndex);
 75 ASSERT(m_rootType == RootWithIndex);
7076 auto* child = firstChildBox();
7177 if (!child)
7278 return false;

@@bool RenderMathMLRoot::isValid() const
7783RenderBox& RenderMathMLRoot::getBase() const
7884{
7985 ASSERT(isValid());
80  ASSERT(m_kind == RootWithIndex);
 86 ASSERT(m_rootType == RootWithIndex);
8187 return *firstChildBox();
8288}
8389
8490RenderBox& RenderMathMLRoot::getIndex() const
8591{
8692 ASSERT(isValid());
87  ASSERT(m_kind == RootWithIndex);
 93 ASSERT(m_rootType == RootWithIndex);
8894 return *firstChildBox()->nextSiblingBox();
8995}
9096

@@RenderMathMLRoot::HorizontalParameters RenderMathMLRoot::horizontalParameters()
99105 HorizontalParameters parameters;
100106
101107 // Square roots do not require horizontal parameters.
102  if (m_kind == SquareRoot)
 108 if (m_rootType == SquareRoot)
103109 return parameters;
104110
105111 // We try and read constants to draw the radical from the OpenType MATH and use fallback values otherwise.

@@RenderMathMLRoot::VerticalParameters RenderMathMLRoot::verticalParameters()
125131 parameters.ruleThickness = mathData->getMathConstant(primaryFont, OpenTypeMathData::RadicalRuleThickness);
126132 parameters.verticalGap = mathData->getMathConstant(primaryFont, mathMLStyle().displayStyle() ? OpenTypeMathData::RadicalDisplayStyleVerticalGap : OpenTypeMathData::RadicalVerticalGap);
127133 parameters.extraAscender = mathData->getMathConstant(primaryFont, OpenTypeMathData::RadicalExtraAscender);
128  if (m_kind == RootWithIndex)
 134 if (m_rootType == RootWithIndex)
129135 parameters.degreeBottomRaisePercent = mathData->getMathConstant(primaryFont, OpenTypeMathData::RadicalDegreeBottomRaisePercent);
130136 } else {
131137 // RadicalVerticalGap: Suggested value is 5/4 default rule thickness.

@@RenderMathMLRoot::VerticalParameters RenderMathMLRoot::verticalParameters()
139145 else
140146 parameters.verticalGap = 5 * parameters.ruleThickness / 4;
141147
142  if (m_kind == RootWithIndex) {
 148 if (m_rootType == RootWithIndex) {
143149 parameters.extraAscender = parameters.ruleThickness;
144150 parameters.degreeBottomRaisePercent = 0.6f;
145151 }

@@void RenderMathMLRoot::computePreferredLogicalWidths()
158164 }
159165
160166 LayoutUnit preferredWidth = 0;
161  if (m_kind == SquareRoot) {
 167 if (m_rootType == SquareRoot) {
162168 preferredWidth += m_radicalOperator.maxPreferredWidth();
163169 setPreferredLogicalWidthsDirty(true);
164170 RenderMathMLRow::computePreferredLogicalWidths();
165171 preferredWidth += m_maxPreferredLogicalWidth;
166172 } else {
167  ASSERT(m_kind == RootWithIndex);
 173 ASSERT(m_rootType == RootWithIndex);
168174 auto horizontal = horizontalParameters();
169175 preferredWidth += horizontal.kernBeforeDegree;
170176 preferredWidth += getIndex().maxPreferredLogicalWidth();

@@void RenderMathMLRoot::layoutBlock(bool relayoutChildren, LayoutUnit)
196202 // Note: Per the MathML specification, the children of <msqrt> are wrapped in an inferred <mrow>, which is the desired base.
197203 LayoutUnit baseAscent, baseDescent;
198204 recomputeLogicalWidth();
199  if (m_kind == SquareRoot) {
 205 if (m_rootType == SquareRoot) {
200206 baseAscent = baseDescent;
201207 RenderMathMLRow::computeLineVerticalStretch(baseAscent, baseDescent);
202208 RenderMathMLRow::layoutRowItems(baseAscent, baseDescent);

@@void RenderMathMLRoot::layoutBlock(bool relayoutChildren, LayoutUnit)
223229 LayoutUnit ascent = radicalAscent;
224230
225231 // We set the logical width.
226  if (m_kind == SquareRoot)
 232 if (m_rootType == SquareRoot)
227233 setLogicalWidth(m_radicalOperator.width() + m_baseWidth);
228234 else {
229  ASSERT(m_kind == RootWithIndex);
 235 ASSERT(m_rootType == RootWithIndex);
230236 setLogicalWidth(horizontal.kernBeforeDegree + getIndex().logicalWidth() + horizontal.kernAfterDegree + m_radicalOperator.width() + m_baseWidth);
231237 }
232238
233239 // For <mroot>, we update the metrics to take into account the index.
234240 LayoutUnit indexAscent, indexDescent;
235  if (m_kind == RootWithIndex) {
 241 if (m_rootType == RootWithIndex) {
236242 indexAscent = ascentForChild(getIndex());
237243 indexDescent = getIndex().logicalHeight() - indexAscent;
238244 ascent = std::max<LayoutUnit>(radicalAscent, indexBottomRaise + indexDescent + indexAscent - descent);

@@void RenderMathMLRoot::layoutBlock(bool relayoutChildren, LayoutUnit)
241247 // We set the final position of children.
242248 m_radicalOperatorTop = ascent - radicalAscent + vertical.extraAscender;
243249 LayoutUnit horizontalOffset = m_radicalOperator.width();
244  if (m_kind == RootWithIndex)
 250 if (m_rootType == RootWithIndex)
245251 horizontalOffset += horizontal.kernBeforeDegree + getIndex().logicalWidth() + horizontal.kernAfterDegree;
246252 LayoutPoint baseLocation(mirrorIfNeeded(horizontalOffset, m_baseWidth), ascent - baseAscent);
247  if (m_kind == SquareRoot) {
 253 if (m_rootType == SquareRoot) {
248254 for (auto* child = firstChildBox(); child; child = child->nextSiblingBox())
249255 child->setLocation(child->location() + baseLocation);
250256 } else {
251  ASSERT(m_kind == RootWithIndex);
 257 ASSERT(m_rootType == RootWithIndex);
252258 getBase().setLocation(baseLocation);
253259 LayoutPoint indexLocation(mirrorIfNeeded(horizontal.kernBeforeDegree, getIndex()), ascent + descent - indexBottomRaise - indexDescent - indexAscent);
254260 getIndex().setLocation(indexLocation);

@@void RenderMathMLRoot::paint(PaintInfo& info, const LayoutPoint& paintOffset)
271277 // We draw the radical operator.
272278 LayoutPoint radicalOperatorTopLeft = paintOffset + location();
273279 LayoutUnit horizontalOffset = 0;
274  if (m_kind == RootWithIndex) {
 280 if (m_rootType == RootWithIndex) {
275281 auto horizontal = horizontalParameters();
276282 horizontalOffset = horizontal.kernBeforeDegree + getIndex().logicalWidth() + horizontal.kernAfterDegree;
277283 }

Source/WebCore/rendering/mathml/RenderMathMLRoot.h

@@private:
7373 LayoutUnit m_baseWidth;
7474
7575 enum RootType { SquareRoot, RootWithIndex };
76  RootType m_kind;
77  bool isRenderMathMLSquareRoot() const final { return m_kind == SquareRoot; }
 76 const RootType m_rootType;
 77 static RootType rootTypeOf(const MathMLRowElement&);
 78 bool isRenderMathMLSquareRoot() const final { return m_rootType == SquareRoot; }
7879};
7980
8081} // namespace WebCore

Source/WebCore/rendering/mathml/RenderMathMLScripts.cpp

3737
3838namespace WebCore {
3939
 40using namespace MathMLNames;
 41
4042WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMathMLScripts);
4143
4244static bool isPrescriptDelimiter(const RenderObject& renderObject)
4345{
44  return renderObject.node() && renderObject.node()->hasTagName(MathMLNames::mprescriptsTag);
 46 return renderObject.node() && renderObject.node()->hasTagName(mprescriptsTag);
4547}
4648
4749RenderMathMLScripts::RenderMathMLScripts(MathMLScriptsElement& element, RenderStyle&& style)
4850 : RenderMathMLBlock(element, WTFMove(style))
 51 , m_scriptType(scriptTypeOf(element))
4952{
50  // Determine what kind of sub/sup expression we have by element name
51  if (element.hasTagName(MathMLNames::msubTag))
52  m_scriptType = Sub;
53  else if (element.hasTagName(MathMLNames::msupTag))
54  m_scriptType = Super;
55  else if (element.hasTagName(MathMLNames::msubsupTag))
56  m_scriptType = SubSup;
57  else if (element.hasTagName(MathMLNames::munderTag))
58  m_scriptType = Under;
59  else if (element.hasTagName(MathMLNames::moverTag))
60  m_scriptType = Over;
61  else if (element.hasTagName(MathMLNames::munderoverTag))
62  m_scriptType = UnderOver;
63  else {
64  ASSERT(element.hasTagName(MathMLNames::mmultiscriptsTag));
65  m_scriptType = Multiscripts;
66  }
 53}
 54
 55RenderMathMLScripts::ScriptsType RenderMathMLScripts::scriptTypeOf(const MathMLScriptsElement& element)
 56{
 57 // The kind of scripted expression is determined from the element name.
 58 if (element.hasTagName(msubTag))
 59 return Sub;
 60 if (element.hasTagName(msupTag))
 61 return Super;
 62 if (element.hasTagName(msubsupTag))
 63 return SubSup;
 64 if (element.hasTagName(munderTag))
 65 return Under;
 66 if (element.hasTagName(moverTag))
 67 return Over;
 68 if (element.hasTagName(munderoverTag))
 69 return UnderOver;
 70 ASSERT(element.hasTagName(mmultiscriptsTag));
 71 return Multiscripts;
6772}
6873
6974MathMLScriptsElement& RenderMathMLScripts::element() const

Source/WebCore/rendering/mathml/RenderMathMLScripts.h

@@protected:
4949 void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) override;
5050
5151 enum ScriptsType { Sub, Super, SubSup, Multiscripts, Under, Over, UnderOver };
52  ScriptsType m_scriptType;
 52 const ScriptsType m_scriptType;
5353
5454private:
 55 static ScriptsType scriptTypeOf(const MathMLScriptsElement&);
5556 MathMLScriptsElement& element() const;
5657 std::optional<int> firstLineBaseline() const final;
5758 struct ReferenceChildren {