Diff
Modified: trunk/Source/WebCore/ChangeLog (225474 => 225475)
--- trunk/Source/WebCore/ChangeLog 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/ChangeLog 2017-12-04 11:30:10 UTC (rev 225475)
@@ -1,3 +1,76 @@
+2017-12-04 Frederic Wang <fw...@igalia.com>
+
+ Bug 161300 - Move RenderMathMLRoot:RootType and RenderMathMLScripts:ScriptsType to element classes
+ https://bugs.webkit.org/show_bug.cgi?id=161300
+
+ Reviewed by Darin Adler.
+
+ RenderMathMLRoot::m_kind and RenderMathMLScripts::m_scriptType are initialized in the
+ constructors of the renderer classes from the tag name of the corresponding elements.
+ This patch moves them into the corresponding element classes and makes them const members
+ parsed in the constructors. It also introduces a MathMLRootElement class deriving from
+ MathMLRowElement to store the new member. Finally, the types are redefined as enum classes.
+
+ No new tests, behavior unchanged and already covered by existing tests.
+
+ * Sources.txt: Add MathMLRootElement files.
+ * WebCore.xcodeproj/project.pbxproj: Ditto.
+ * mathml/MathMLAllInOne.cpp: Ditto.
+ * mathml/MathMLRootElement.cpp:
+ (WebCore::element): Override this function to downcast to MathMLRootElement.
+ (WebCore::rootTypeOf): Helper function to parse the root type, moved from RenderMathMLRoot.
+ (WebCore::MathMLRootElement::MathMLRootElement): Initialize the root type.
+ (WebCore::MathMLRootElement::create):
+ (WebCore::MathMLRootElement::createElementRenderer): Moved from MathMLRowElement.
+ * mathml/MathMLRootElement.h: New class deriving from MathMLRowElement, with a RootType
+ member exposed to the renderer class.
+ * mathml/MathMLRowElement.cpp: Remove header for RenderMathMLRoot.h.
+ (WebCore::MathMLRowElement::createElementRenderer): Moved to MathMLRootElement.
+ * mathml/MathMLScriptsElement.cpp: Introduce a script type.
+ (WebCore::scriptTypeOf): Helper function to parse the script type, moved from
+ RenerMathMLScripts.
+ (WebCore::MathMLScriptsElement::MathMLScriptsElement): Initialize the script type.
+ * mathml/MathMLScriptsElement.h: Add new script type member.
+ (WebCore::MathMLScriptsElement::scriptType const): Expose the script type to the renderer
+ class.
+ * mathml/mathtags.in: Map <msqrt> and <mroot> to MathMLRootElement.
+ * rendering/mathml/RenderMathMLRoot.cpp:
+ (WebCore::RenderMathMLRoot::RenderMathMLRoot): Use MathMLRootElement and remove parsing of
+ the root type.
+ (WebCore::RenderMathMLRoot::rootType const): Helper function to access the root type from
+ the element class.
+ (WebCore::RenderMathMLRoot::isValid const): Use rootType() and add prefix for enum class
+ values.
+ (WebCore::RenderMathMLRoot::getBase const): Ditto.
+ (WebCore::RenderMathMLRoot::getIndex const): Ditto.
+ (WebCore::RenderMathMLRoot::horizontalParameters): Ditto.
+ (WebCore::RenderMathMLRoot::verticalParameters): Ditto.
+ (WebCore::RenderMathMLRoot::computePreferredLogicalWidths): Ditto.
+ (WebCore::RenderMathMLRoot::layoutBlock): Ditto.
+ (WebCore::RenderMathMLRoot::paint): Ditto.
+ * rendering/mathml/RenderMathMLRoot.h: Define root type as an enum class, replace
+ MathMLRowElement with MathMLRootElement, declare and use new rootType() function and remove
+ the m_kind member.
+ * rendering/mathml/RenderMathMLScripts.cpp:
+ (WebCore::RenderMathMLScripts::RenderMathMLScripts): Remove parsing of script type.
+ (WebCore::RenderMathMLScripts::scriptType const): Helper function to access the script type
+ from the element class.
+ (WebCore::RenderMathMLScripts::validateAndGetReferenceChildren): Use scriptType() and add
+ prefix for enum class values.
+ (WebCore::RenderMathMLScripts::computePreferredLogicalWidths): Ditto.
+ (WebCore::RenderMathMLScripts::verticalMetrics): Ditto.
+ (WebCore::RenderMathMLScripts::layoutBlock): Ditto.
+ * rendering/mathml/RenderMathMLScripts.h: Define root type as an enum class, declare the
+ scriptType() function and remove the m_scriptType member.
+ * rendering/mathml/RenderMathMLUnderOver.cpp:
+ (WebCore::RenderMathMLUnderOver::isValid const): Use scriptType() and add prefix for enum
+ class values.
+ (WebCore::RenderMathMLUnderOver::under const): Ditto.
+ (WebCore::RenderMathMLUnderOver::over const): Ditto.
+ (WebCore::RenderMathMLUnderOver::computePreferredLogicalWidths): Ditto.
+ (WebCore::RenderMathMLUnderOver::hasAccent const): Ditto.
+ (WebCore::RenderMathMLUnderOver::layoutBlock): Ditto.
+
2017-12-04 Carlos Garcia Campos <cgar...@igalia.com>
[GStreamer] More leaks in TextCombinerGStreamer
Modified: trunk/Source/WebCore/Sources.txt (225474 => 225475)
--- trunk/Source/WebCore/Sources.txt 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/Sources.txt 2017-12-04 11:30:10 UTC (rev 225475)
@@ -1254,6 +1254,7 @@
mathml/MathMLOperatorElement.cpp
mathml/MathMLPaddedElement.cpp
mathml/MathMLPresentationElement.cpp
+mathml/MathMLRootElement.cpp
mathml/MathMLRowElement.cpp
mathml/MathMLScriptsElement.cpp
mathml/MathMLSelectElement.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (225474 => 225475)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-12-04 11:30:10 UTC (rev 225475)
@@ -4664,6 +4664,7 @@
FA654A6C1108ABED002615E0 /* MathMLTokenElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FA654A6A1108ABED002615E0 /* MathMLTokenElement.h */; };
FA654A6C1108ABED002616F1 /* MathMLOperatorElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FA654A6A1108ABED002616F1 /* MathMLOperatorElement.h */; };
FA654A6C1108ABED002626F1 /* MathMLUnderOverElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FA654A6A1108ABED002626F1 /* MathMLUnderOverElement.h */; };
+ FA765A6C1108ABED00782A5C /* MathMLRootElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FA765A6A1108ABED00782A5C /* MathMLRootElement.h */; };
FA765A6C1108ABED002615E0 /* MathMLRowElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FA765A6A1108ABED002615E0 /* MathMLRowElement.h */; };
FABE72F51059C1EB00D888CC /* MathMLAnnotationElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FABE72EE1059C1EB00D888CC /* MathMLAnnotationElement.h */; };
FABE72F51059C1EB00D999DD /* MathMLElement.h in Headers */ = {isa = PBXBuildFile; fileRef = FABE72EE1059C1EB00D999DD /* MathMLElement.h */; };
@@ -14079,6 +14080,8 @@
FA654A6A1108ABED002616F1 /* MathMLOperatorElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLOperatorElement.h; sourceTree = "<group>"; };
FA654A6A1108ABED002626F1 /* MathMLUnderOverElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLUnderOverElement.h; sourceTree = "<group>"; };
FA6E466FCD0418A9966A5B60 /* DNSResolveQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNSResolveQueue.h; sourceTree = "<group>"; };
+ FA765A691108ABED00782A5C /* MathMLRootElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLRootElement.cpp; sourceTree = "<group>"; };
+ FA765A6A1108ABED00782A5C /* MathMLRootElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLRootElement.h; sourceTree = "<group>"; };
FA765A691108ABED002615E0 /* MathMLRowElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLRowElement.cpp; sourceTree = "<group>"; };
FA765A6A1108ABED002615E0 /* MathMLRowElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathMLRowElement.h; sourceTree = "<group>"; };
FABE72ED1059C1EB00D888CC /* MathMLAnnotationElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLAnnotationElement.cpp; sourceTree = "<group>"; };
@@ -25545,6 +25548,8 @@
B59CA849D41E6F65D81198BC /* MathMLPaddedElement.h */,
FABE72EF1059C1EB00D999DD /* MathMLPresentationElement.cpp */,
FABE72F01059C1EB00D999DD /* MathMLPresentationElement.h */,
+ FA765A691108ABED00782A5C /* MathMLRootElement.cpp */,
+ FA765A6A1108ABED00782A5C /* MathMLRootElement.h */,
FA765A691108ABED002615E0 /* MathMLRowElement.cpp */,
FA765A6A1108ABED002615E0 /* MathMLRowElement.h */,
B59CA59AF170D8FAA5B8C9AD /* MathMLScriptsElement.cpp */,
@@ -28191,6 +28196,7 @@
44A28AAF12DFB8BF00AE923B /* MathMLNames.h in Headers */,
FA654A6C1108ABED002616F1 /* MathMLOperatorElement.h in Headers */,
FABE72F71059C1EB00D999DD /* MathMLPresentationElement.h in Headers */,
+ FA765A6C1108ABED00782A5C /* MathMLRootElement.h in Headers */,
FA765A6C1108ABED002615E0 /* MathMLRowElement.h in Headers */,
4FA65A6C1108ABED002615E0 /* MathMLSpaceElement.h in Headers */,
439176E012DA25E17BAF80A2 /* MathMLStyle.h in Headers */,
Modified: trunk/Source/WebCore/mathml/MathMLAllInOne.cpp (225474 => 225475)
--- trunk/Source/WebCore/mathml/MathMLAllInOne.cpp 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/mathml/MathMLAllInOne.cpp 2017-12-04 11:30:10 UTC (rev 225475)
@@ -34,6 +34,7 @@
#include "MathMLOperatorElement.cpp"
#include "MathMLPaddedElement.cpp"
#include "MathMLPresentationElement.cpp"
+#include "MathMLRootElement.cpp"
#include "MathMLRowElement.cpp"
#include "MathMLScriptsElement.cpp"
#include "MathMLSelectElement.cpp"
Copied: trunk/Source/WebCore/mathml/MathMLRootElement.cpp (from rev 225473, trunk/Source/WebCore/mathml/MathMLScriptsElement.h) (0 => 225475)
--- trunk/Source/WebCore/mathml/MathMLRootElement.cpp (rev 0)
+++ trunk/Source/WebCore/mathml/MathMLRootElement.cpp 2017-12-04 11:30:10 UTC (rev 225475)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2017 Igalia S.L. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "config.h"
+#include "MathMLRootElement.h"
+
+#if ENABLE(MATHML)
+
+#include "RenderMathMLRoot.h"
+
+namespace WebCore {
+
+using namespace MathMLNames;
+
+static RootType rootTypeOf(const QualifiedName& tagName)
+{
+ if (tagName == msqrtTag)
+ return RootType::SquareRoot;
+ ASSERT(tagName == mrootTag);
+ return RootType::RootWithIndex;
+}
+
+inline MathMLRootElement::MathMLRootElement(const QualifiedName& tagName, Document& document)
+ : MathMLRowElement(tagName, document)
+ , m_rootType(rootTypeOf(tagName))
+{
+}
+
+Ref<MathMLRootElement> MathMLRootElement::create(const QualifiedName& tagName, Document& document)
+{
+ return adoptRef(*new MathMLRootElement(tagName, document));
+}
+
+RenderPtr<RenderElement> MathMLRootElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
+{
+ ASSERT(hasTagName(msqrtTag) || hasTagName(mrootTag));
+ return createRenderer<RenderMathMLRoot>(*this, WTFMove(style));
+}
+
+}
+
+#endif // ENABLE(MATHML)
Copied: trunk/Source/WebCore/mathml/MathMLRootElement.h (from rev 225473, trunk/Source/WebCore/mathml/MathMLScriptsElement.h) (0 => 225475)
--- trunk/Source/WebCore/mathml/MathMLRootElement.h (rev 0)
+++ trunk/Source/WebCore/mathml/MathMLRootElement.h 2017-12-04 11:30:10 UTC (rev 225475)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2017 Igalia S.L. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(MATHML)
+
+#include "MathMLRowElement.h"
+
+namespace WebCore {
+
+enum class RootType;
+
+class MathMLRootElement final : public MathMLRowElement {
+public:
+ static Ref<MathMLRootElement> create(const QualifiedName& tagName, Document&);
+ RootType rootType() const { return m_rootType; }
+
+private:
+ MathMLRootElement(const QualifiedName& tagName, Document&);
+ RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
+
+ const RootType m_rootType;
+};
+
+}
+
+#endif // ENABLE(MATHML)
Modified: trunk/Source/WebCore/mathml/MathMLRowElement.cpp (225474 => 225475)
--- trunk/Source/WebCore/mathml/MathMLRowElement.cpp 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/mathml/MathMLRowElement.cpp 2017-12-04 11:30:10 UTC (rev 225475)
@@ -32,7 +32,6 @@
#include "MathMLOperatorElement.h"
#include "RenderMathMLFenced.h"
#include "RenderMathMLMenclose.h"
-#include "RenderMathMLRoot.h"
#include "RenderMathMLRow.h"
namespace WebCore {
@@ -61,9 +60,6 @@
RenderPtr<RenderElement> MathMLRowElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
{
- if (hasTagName(msqrtTag) || hasTagName(mrootTag))
- return createRenderer<RenderMathMLRoot>(*this, WTFMove(style));
-
if (hasTagName(mfencedTag))
return createRenderer<RenderMathMLFenced>(*this, WTFMove(style));
Modified: trunk/Source/WebCore/mathml/MathMLScriptsElement.cpp (225474 => 225475)
--- trunk/Source/WebCore/mathml/MathMLScriptsElement.cpp 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/mathml/MathMLScriptsElement.cpp 2017-12-04 11:30:10 UTC (rev 225475)
@@ -35,8 +35,27 @@
using namespace MathMLNames;
+static ScriptType scriptTypeOf(const QualifiedName& tagName)
+{
+ if (tagName == msubTag)
+ return ScriptType::Sub;
+ if (tagName == msupTag)
+ return ScriptType::Super;
+ if (tagName == msubsupTag)
+ return ScriptType::SubSup;
+ if (tagName == munderTag)
+ return ScriptType::Under;
+ if (tagName == moverTag)
+ return ScriptType::Over;
+ if (tagName == munderoverTag)
+ return ScriptType::UnderOver;
+ ASSERT(tagName == mmultiscriptsTag);
+ return ScriptType::Multiscripts;
+}
+
MathMLScriptsElement::MathMLScriptsElement(const QualifiedName& tagName, Document& document)
: MathMLPresentationElement(tagName, document)
+ , m_scriptType(scriptTypeOf(tagName))
{
}
Modified: trunk/Source/WebCore/mathml/MathMLScriptsElement.h (225474 => 225475)
--- trunk/Source/WebCore/mathml/MathMLScriptsElement.h 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/mathml/MathMLScriptsElement.h 2017-12-04 11:30:10 UTC (rev 225475)
@@ -31,9 +31,12 @@
namespace WebCore {
+enum class ScriptType;
+
class MathMLScriptsElement : public MathMLPresentationElement {
public:
static Ref<MathMLScriptsElement> create(const QualifiedName& tagName, Document&);
+ ScriptType scriptType() const { return m_scriptType; }
const Length& subscriptShift();
const Length& superscriptShift();
@@ -44,6 +47,7 @@
RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
void parseAttribute(const QualifiedName&, const AtomicString&) override;
+ const ScriptType m_scriptType;
std::optional<Length> m_subscriptShift;
std::optional<Length> m_superscriptShift;
};
Modified: trunk/Source/WebCore/mathml/mathtags.in (225474 => 225475)
--- trunk/Source/WebCore/mathml/mathtags.in 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/mathml/mathtags.in 2017-12-04 11:30:10 UTC (rev 225475)
@@ -18,8 +18,8 @@
mover interfaceName=MathMLUnderOverElement
munder interfaceName=MathMLUnderOverElement
munderover interfaceName=MathMLUnderOverElement
-msqrt interfaceName=MathMLRowElement
-mroot interfaceName=MathMLRowElement
+msqrt interfaceName=MathMLRootElement
+mroot interfaceName=MathMLRootElement
mi interfaceName=MathMLTokenElement
mn interfaceName=MathMLTokenElement
mo interfaceName=MathMLOperatorElement
Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp (225474 => 225475)
--- trunk/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp 2017-12-04 11:30:10 UTC (rev 225475)
@@ -33,7 +33,7 @@
#include "FontCache.h"
#include "GraphicsContext.h"
#include "MathMLNames.h"
-#include "MathMLRowElement.h"
+#include "MathMLRootElement.h"
#include "PaintInfo.h"
#include "RenderIterator.h"
#include "RenderMathMLMenclose.h"
@@ -46,27 +46,31 @@
WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMathMLRoot);
-RenderMathMLRoot::RenderMathMLRoot(MathMLRowElement& element, RenderStyle&& style)
+RenderMathMLRoot::RenderMathMLRoot(MathMLRootElement& element, RenderStyle&& style)
: RenderMathMLRow(element, WTFMove(style))
{
- // Determine what kind of _expression_ we have by element name
- if (element.hasTagName(MathMLNames::msqrtTag))
- m_kind = SquareRoot;
- else if (element.hasTagName(MathMLNames::mrootTag))
- m_kind = RootWithIndex;
-
m_radicalOperator.setOperator(RenderMathMLRoot::style(), gRadicalCharacter, MathOperator::Type::VerticalOperator);
}
+MathMLRootElement& RenderMathMLRoot::element() const
+{
+ return static_cast<MathMLRootElement&>(nodeForNonAnonymous());
+}
+
+RootType RenderMathMLRoot::rootType() const
+{
+ return element().rootType();
+}
+
bool RenderMathMLRoot::isValid() const
{
// Verify whether the list of children is valid:
// <msqrt> child1 child2 ... childN </msqrt>
// <mroot> base index </mroot>
- if (m_kind == SquareRoot)
+ if (rootType() == RootType::SquareRoot)
return true;
- ASSERT(m_kind == RootWithIndex);
+ ASSERT(rootType() == RootType::RootWithIndex);
auto* child = firstChildBox();
if (!child)
return false;
@@ -77,7 +81,7 @@
RenderBox& RenderMathMLRoot::getBase() const
{
ASSERT(isValid());
- ASSERT(m_kind == RootWithIndex);
+ ASSERT(rootType() == RootType::RootWithIndex);
return *firstChildBox();
}
@@ -84,7 +88,7 @@
RenderBox& RenderMathMLRoot::getIndex() const
{
ASSERT(isValid());
- ASSERT(m_kind == RootWithIndex);
+ ASSERT(rootType() == RootType::RootWithIndex);
return *firstChildBox()->nextSiblingBox();
}
@@ -99,7 +103,7 @@
HorizontalParameters parameters;
// Square roots do not require horizontal parameters.
- if (m_kind == SquareRoot)
+ if (rootType() == RootType::SquareRoot)
return parameters;
// We try and read constants to draw the radical from the OpenType MATH and use fallback values otherwise.
@@ -125,7 +129,7 @@
parameters.ruleThickness = mathData->getMathConstant(primaryFont, OpenTypeMathData::RadicalRuleThickness);
parameters.verticalGap = mathData->getMathConstant(primaryFont, mathMLStyle().displayStyle() ? OpenTypeMathData::RadicalDisplayStyleVerticalGap : OpenTypeMathData::RadicalVerticalGap);
parameters.extraAscender = mathData->getMathConstant(primaryFont, OpenTypeMathData::RadicalExtraAscender);
- if (m_kind == RootWithIndex)
+ if (rootType() == RootType::RootWithIndex)
parameters.degreeBottomRaisePercent = mathData->getMathConstant(primaryFont, OpenTypeMathData::RadicalDegreeBottomRaisePercent);
} else {
// RadicalVerticalGap: Suggested value is 5/4 default rule thickness.
@@ -139,7 +143,7 @@
else
parameters.verticalGap = 5 * parameters.ruleThickness / 4;
- if (m_kind == RootWithIndex) {
+ if (rootType() == RootType::RootWithIndex) {
parameters.extraAscender = parameters.ruleThickness;
parameters.degreeBottomRaisePercent = 0.6f;
}
@@ -158,13 +162,13 @@
}
LayoutUnit preferredWidth = 0;
- if (m_kind == SquareRoot) {
+ if (rootType() == RootType::SquareRoot) {
preferredWidth += m_radicalOperator.maxPreferredWidth();
setPreferredLogicalWidthsDirty(true);
RenderMathMLRow::computePreferredLogicalWidths();
preferredWidth += m_maxPreferredLogicalWidth;
} else {
- ASSERT(m_kind == RootWithIndex);
+ ASSERT(rootType() == RootType::RootWithIndex);
auto horizontal = horizontalParameters();
preferredWidth += horizontal.kernBeforeDegree;
preferredWidth += getIndex().maxPreferredLogicalWidth();
@@ -196,7 +200,7 @@
// Note: Per the MathML specification, the children of <msqrt> are wrapped in an inferred <mrow>, which is the desired base.
LayoutUnit baseAscent, baseDescent;
recomputeLogicalWidth();
- if (m_kind == SquareRoot) {
+ if (rootType() == RootType::SquareRoot) {
baseAscent = baseDescent;
RenderMathMLRow::computeLineVerticalStretch(baseAscent, baseDescent);
RenderMathMLRow::layoutRowItems(baseAscent, baseDescent);
@@ -223,16 +227,16 @@
LayoutUnit ascent = radicalAscent;
// We set the logical width.
- if (m_kind == SquareRoot)
+ if (rootType() == RootType::SquareRoot)
setLogicalWidth(m_radicalOperator.width() + m_baseWidth);
else {
- ASSERT(m_kind == RootWithIndex);
+ ASSERT(rootType() == RootType::RootWithIndex);
setLogicalWidth(horizontal.kernBeforeDegree + getIndex().logicalWidth() + horizontal.kernAfterDegree + m_radicalOperator.width() + m_baseWidth);
}
// For <mroot>, we update the metrics to take into account the index.
LayoutUnit indexAscent, indexDescent;
- if (m_kind == RootWithIndex) {
+ if (rootType() == RootType::RootWithIndex) {
indexAscent = ascentForChild(getIndex());
indexDescent = getIndex().logicalHeight() - indexAscent;
ascent = std::max<LayoutUnit>(radicalAscent, indexBottomRaise + indexDescent + indexAscent - descent);
@@ -241,14 +245,14 @@
// We set the final position of children.
m_radicalOperatorTop = ascent - radicalAscent + vertical.extraAscender;
LayoutUnit horizontalOffset = m_radicalOperator.width();
- if (m_kind == RootWithIndex)
+ if (rootType() == RootType::RootWithIndex)
horizontalOffset += horizontal.kernBeforeDegree + getIndex().logicalWidth() + horizontal.kernAfterDegree;
LayoutPoint baseLocation(mirrorIfNeeded(horizontalOffset, m_baseWidth), ascent - baseAscent);
- if (m_kind == SquareRoot) {
+ if (rootType() == RootType::SquareRoot) {
for (auto* child = firstChildBox(); child; child = child->nextSiblingBox())
child->setLocation(child->location() + baseLocation);
} else {
- ASSERT(m_kind == RootWithIndex);
+ ASSERT(rootType() == RootType::RootWithIndex);
getBase().setLocation(baseLocation);
LayoutPoint indexLocation(mirrorIfNeeded(horizontal.kernBeforeDegree, getIndex()), ascent + descent - indexBottomRaise - indexDescent - indexAscent);
getIndex().setLocation(indexLocation);
@@ -271,7 +275,7 @@
// We draw the radical operator.
LayoutPoint radicalOperatorTopLeft = paintOffset + location();
LayoutUnit horizontalOffset = 0;
- if (m_kind == RootWithIndex) {
+ if (rootType() == RootType::RootWithIndex) {
auto horizontal = horizontalParameters();
horizontalOffset = horizontal.kernBeforeDegree + getIndex().logicalWidth() + horizontal.kernAfterDegree;
}
Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLRoot.h (225474 => 225475)
--- trunk/Source/WebCore/rendering/mathml/RenderMathMLRoot.h 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLRoot.h 2017-12-04 11:30:10 UTC (rev 225475)
@@ -33,13 +33,15 @@
namespace WebCore {
-class MathMLRowElement;
+class MathMLRootElement;
+enum class RootType { SquareRoot, RootWithIndex };
+
// Render base^(1/index), or sqrt(base) using radical notation.
class RenderMathMLRoot final : public RenderMathMLRow {
WTF_MAKE_ISO_ALLOCATED(RenderMathMLRoot);
public:
- RenderMathMLRoot(MathMLRowElement&, RenderStyle&&);
+ RenderMathMLRoot(MathMLRootElement&, RenderStyle&&);
void updateStyle();
private:
@@ -48,6 +50,8 @@
RenderBox& getIndex() const;
bool isRenderMathMLRoot() const final { return true; }
const char* renderName() const final { return "RenderMathMLRoot"; }
+ MathMLRootElement& element() const;
+ RootType rootType() const;
void styleDidChange(StyleDifference, const RenderStyle* oldStyle) final;
@@ -72,9 +76,7 @@
LayoutUnit m_radicalOperatorTop;
LayoutUnit m_baseWidth;
- enum RootType { SquareRoot, RootWithIndex };
- RootType m_kind;
- bool isRenderMathMLSquareRoot() const final { return m_kind == SquareRoot; }
+ bool isRenderMathMLSquareRoot() const final { return rootType() == RootType::SquareRoot; }
};
} // namespace WebCore
Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.cpp (225474 => 225475)
--- trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.cpp 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.cpp 2017-12-04 11:30:10 UTC (rev 225475)
@@ -47,23 +47,6 @@
RenderMathMLScripts::RenderMathMLScripts(MathMLScriptsElement& element, RenderStyle&& style)
: RenderMathMLBlock(element, WTFMove(style))
{
- // Determine what kind of sub/sup _expression_ we have by element name
- if (element.hasTagName(MathMLNames::msubTag))
- m_scriptType = Sub;
- else if (element.hasTagName(MathMLNames::msupTag))
- m_scriptType = Super;
- else if (element.hasTagName(MathMLNames::msubsupTag))
- m_scriptType = SubSup;
- else if (element.hasTagName(MathMLNames::munderTag))
- m_scriptType = Under;
- else if (element.hasTagName(MathMLNames::moverTag))
- m_scriptType = Over;
- else if (element.hasTagName(MathMLNames::munderoverTag))
- m_scriptType = UnderOver;
- else {
- ASSERT(element.hasTagName(MathMLNames::mmultiscriptsTag));
- m_scriptType = Multiscripts;
- }
}
MathMLScriptsElement& RenderMathMLScripts::element() const
@@ -71,6 +54,11 @@
return static_cast<MathMLScriptsElement&>(nodeForNonAnonymous());
}
+ScriptType RenderMathMLScripts::scriptType() const
+{
+ return element().scriptType();
+}
+
RenderMathMLOperator* RenderMathMLScripts::unembellishedOperator()
{
auto base = firstChildBox();
@@ -93,11 +81,11 @@
reference.firstPreScript = nullptr;
reference.prescriptDelimiter = nullptr;
- switch (m_scriptType) {
- case Sub:
- case Super:
- case Under:
- case Over: {
+ switch (scriptType()) {
+ case ScriptType::Sub:
+ case ScriptType::Super:
+ case ScriptType::Under:
+ case ScriptType::Over: {
// These elements must have exactly two children.
// The second child is a postscript and there are no prescripts.
// <msub> base subscript </msub>
@@ -110,8 +98,8 @@
reference.firstPostScript = script;
return reference;
}
- case SubSup:
- case UnderOver: {
+ case ScriptType::SubSup:
+ case ScriptType::UnderOver: {
// These elements must have exactly three children.
// The second and third children are postscripts and there are no prescripts.
// <msubsup> base subscript superscript </msubsup>
@@ -125,7 +113,7 @@
reference.firstPostScript = subScript;
return reference;
}
- case Multiscripts: {
+ case ScriptType::Multiscripts: {
// This element accepts the following syntax:
//
// <mmultiscripts>
@@ -200,20 +188,20 @@
LayoutUnit baseItalicCorrection = std::min(reference.base->maxPreferredLogicalWidth(), italicCorrection(reference));
LayoutUnit space = spaceAfterScript();
- switch (m_scriptType) {
- case Sub:
- case Under:
+ switch (scriptType()) {
+ case ScriptType::Sub:
+ case ScriptType::Under:
m_maxPreferredLogicalWidth += reference.base->maxPreferredLogicalWidth();
m_maxPreferredLogicalWidth += std::max(LayoutUnit(0), reference.firstPostScript->maxPreferredLogicalWidth() - baseItalicCorrection + space);
break;
- case Super:
- case Over:
+ case ScriptType::Super:
+ case ScriptType::Over:
m_maxPreferredLogicalWidth += reference.base->maxPreferredLogicalWidth();
m_maxPreferredLogicalWidth += std::max(LayoutUnit(0), reference.firstPostScript->maxPreferredLogicalWidth() + space);
break;
- case SubSup:
- case UnderOver:
- case Multiscripts: {
+ case ScriptType::SubSup:
+ case ScriptType::UnderOver:
+ case ScriptType::Multiscripts: {
auto subScript = reference.firstPreScript;
while (subScript) {
auto supScript = subScript->nextSiblingBox();
@@ -273,7 +261,7 @@
LayoutUnit baseAscent = ascentForChild(*reference.base);
LayoutUnit baseDescent = reference.base->logicalHeight() - baseAscent;
- if (m_scriptType == Sub || m_scriptType == SubSup || m_scriptType == Multiscripts || m_scriptType == Under || m_scriptType == UnderOver) {
+ if (scriptType() == ScriptType::Sub || scriptType() == ScriptType::SubSup || scriptType() == ScriptType::Multiscripts || scriptType() == ScriptType::Under || scriptType() == ScriptType::UnderOver) {
metrics.subShift = std::max(parameters.subscriptShiftDown, baseDescent + parameters.subscriptBaselineDropMin);
if (!isRenderMathMLUnderOver()) {
// It is not clear how to interpret the default shift and it is not available yet anyway.
@@ -282,7 +270,7 @@
metrics.subShift = std::max(metrics.subShift, specifiedMinSubShift);
}
}
- if (m_scriptType == Super || m_scriptType == SubSup || m_scriptType == Multiscripts || m_scriptType == Over || m_scriptType == UnderOver) {
+ if (scriptType() == ScriptType::Super || scriptType() == ScriptType::SubSup || scriptType() == ScriptType::Multiscripts || scriptType() == ScriptType::Over || scriptType() == ScriptType::UnderOver) {
metrics.supShift = std::max(parameters.superscriptShiftUp, baseAscent - parameters.superScriptBaselineDropMax);
if (!isRenderMathMLUnderOver()) {
// It is not clear how to interpret the default shift and it is not available yet anyway.
@@ -292,9 +280,9 @@
}
}
- switch (m_scriptType) {
- case Sub:
- case Under: {
+ switch (scriptType()) {
+ case ScriptType::Sub:
+ case ScriptType::Under: {
LayoutUnit subAscent = ascentForChild(*reference.firstPostScript);
LayoutUnit subDescent = reference.firstPostScript->logicalHeight() - subAscent;
metrics.descent = subDescent;
@@ -301,8 +289,8 @@
metrics.subShift = std::max(metrics.subShift, subAscent - parameters.subscriptTopMax);
}
break;
- case Super:
- case Over: {
+ case ScriptType::Super:
+ case ScriptType::Over: {
LayoutUnit supAscent = ascentForChild(*reference.firstPostScript);
LayoutUnit supDescent = reference.firstPostScript->logicalHeight() - supAscent;
metrics.ascent = supAscent;
@@ -309,9 +297,9 @@
metrics.supShift = std::max(metrics.supShift, parameters.superscriptBottomMin + supDescent);
}
break;
- case SubSup:
- case UnderOver:
- case Multiscripts: {
+ case ScriptType::SubSup:
+ case ScriptType::UnderOver:
+ case ScriptType::Multiscripts: {
// FIXME: We should move the code updating VerticalMetrics for each sub/sup pair in a helper
// function. That way, SubSup/UnderOver can just make one call and the loop for Multiscripts
// can be rewritten in a more readable.
@@ -389,9 +377,9 @@
LayoutUnit descent = std::max(baseDescent, metrics.descent + metrics.subShift);
setLogicalHeight(ascent + descent);
- switch (m_scriptType) {
- case Sub:
- case Under: {
+ switch (scriptType()) {
+ case ScriptType::Sub:
+ case ScriptType::Under: {
setLogicalWidth(reference.base->logicalWidth() + std::max(LayoutUnit(0), reference.firstPostScript->logicalWidth() - baseItalicCorrection + space));
LayoutPoint baseLocation(mirrorIfNeeded(horizontalOffset, *reference.base), ascent - baseAscent);
reference.base->setLocation(baseLocation);
@@ -401,8 +389,8 @@
reference.firstPostScript->setLocation(scriptLocation);
}
break;
- case Super:
- case Over: {
+ case ScriptType::Super:
+ case ScriptType::Over: {
setLogicalWidth(reference.base->logicalWidth() + std::max(LayoutUnit(0), reference.firstPostScript->logicalWidth() + space));
LayoutPoint baseLocation(mirrorIfNeeded(horizontalOffset, *reference.base), ascent - baseAscent);
reference.base->setLocation(baseLocation);
@@ -412,9 +400,9 @@
reference.firstPostScript->setLocation(scriptLocation);
}
break;
- case SubSup:
- case UnderOver:
- case Multiscripts: {
+ case ScriptType::SubSup:
+ case ScriptType::UnderOver:
+ case ScriptType::Multiscripts: {
// Calculate the logical width.
LayoutUnit logicalWidth = 0;
auto subScript = reference.firstPreScript;
Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.h (225474 => 225475)
--- trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.h 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLScripts.h 2017-12-04 11:30:10 UTC (rev 225475)
@@ -35,6 +35,8 @@
class MathMLScriptsElement;
+enum class ScriptType { Sub, Super, SubSup, Multiscripts, Under, Over, UnderOver };
+
// Render a base with scripts.
class RenderMathMLScripts : public RenderMathMLBlock {
WTF_MAKE_ISO_ALLOCATED(RenderMathMLScripts);
@@ -45,12 +47,10 @@
protected:
bool isRenderMathMLScripts() const override { return true; }
const char* renderName() const override { return "RenderMathMLScripts"; }
+ ScriptType scriptType() const;
void computePreferredLogicalWidths() override;
void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) override;
- enum ScriptsType { Sub, Super, SubSup, Multiscripts, Under, Over, UnderOver };
- ScriptsType m_scriptType;
-
private:
MathMLScriptsElement& element() const;
std::optional<int> firstLineBaseline() const final;
Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp (225474 => 225475)
--- trunk/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp 2017-12-04 11:29:29 UTC (rev 225474)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp 2017-12-04 11:30:10 UTC (rev 225475)
@@ -92,11 +92,11 @@
if (!child)
return false;
child = child->nextSiblingBox();
- switch (m_scriptType) {
- case Over:
- case Under:
+ switch (scriptType()) {
+ case ScriptType::Over:
+ case ScriptType::Under:
return !child;
- case UnderOver:
+ case ScriptType::UnderOver:
return child && !child->nextSiblingBox();
default:
ASSERT_NOT_REACHED();
@@ -120,7 +120,7 @@
RenderBox& RenderMathMLUnderOver::under() const
{
ASSERT(isValid());
- ASSERT(m_scriptType == Under || m_scriptType == UnderOver);
+ ASSERT(scriptType() == ScriptType::Under || scriptType() == ScriptType::UnderOver);
return *firstChildBox()->nextSiblingBox();
}
@@ -127,9 +127,9 @@
RenderBox& RenderMathMLUnderOver::over() const
{
ASSERT(isValid());
- ASSERT(m_scriptType == Over || m_scriptType == UnderOver);
+ ASSERT(scriptType() == ScriptType::Over || scriptType() == ScriptType::UnderOver);
auto* secondChild = firstChildBox()->nextSiblingBox();
- return m_scriptType == Over ? *secondChild : *secondChild->nextSiblingBox();
+ return scriptType() == ScriptType::Over ? *secondChild : *secondChild->nextSiblingBox();
}
@@ -150,10 +150,10 @@
LayoutUnit preferredWidth = base().maxPreferredLogicalWidth();
- if (m_scriptType == Under || m_scriptType == UnderOver)
+ if (scriptType() == ScriptType::Under || scriptType() == ScriptType::UnderOver)
preferredWidth = std::max(preferredWidth, under().maxPreferredLogicalWidth());
- if (m_scriptType == Over || m_scriptType == UnderOver)
+ if (scriptType() == ScriptType::Over || scriptType() == ScriptType::UnderOver)
preferredWidth = std::max(preferredWidth, over().maxPreferredLogicalWidth());
m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = preferredWidth;
@@ -168,7 +168,7 @@
bool RenderMathMLUnderOver::hasAccent(bool accentUnder) const
{
- ASSERT(m_scriptType == UnderOver || (accentUnder && m_scriptType == Under) || (!accentUnder && m_scriptType == Over));
+ ASSERT(scriptType() == ScriptType::UnderOver || (accentUnder && scriptType() == ScriptType::Under) || (!accentUnder && scriptType() == ScriptType::Over));
const MathMLElement::BooleanValue& attributeValue = accentUnder ? element().accentUnder() : element().accent();
if (attributeValue == MathMLElement::BooleanValue::True)
@@ -264,19 +264,19 @@
stretchHorizontalOperatorsAndLayoutChildren();
ASSERT(!base().needsLayout());
- ASSERT(m_scriptType == Over || !under().needsLayout());
- ASSERT(m_scriptType == Under || !over().needsLayout());
+ ASSERT(scriptType() == ScriptType::Over || !under().needsLayout());
+ ASSERT(scriptType() == ScriptType::Under || !over().needsLayout());
LayoutUnit logicalWidth = base().logicalWidth();
- if (m_scriptType == Under || m_scriptType == UnderOver)
+ if (scriptType() == ScriptType::Under || scriptType() == ScriptType::UnderOver)
logicalWidth = std::max(logicalWidth, under().logicalWidth());
- if (m_scriptType == Over || m_scriptType == UnderOver)
+ if (scriptType() == ScriptType::Over || scriptType() == ScriptType::UnderOver)
logicalWidth = std::max(logicalWidth, over().logicalWidth());
setLogicalWidth(logicalWidth);
VerticalParameters parameters = verticalParameters();
LayoutUnit verticalOffset = 0;
- if (m_scriptType == Over || m_scriptType == UnderOver) {
+ if (scriptType() == ScriptType::Over || scriptType() == ScriptType::UnderOver) {
verticalOffset += parameters.overExtraAscender;
over().setLocation(LayoutPoint(horizontalOffset(over()), verticalOffset));
if (parameters.useUnderOverBarFallBack) {
@@ -294,7 +294,7 @@
}
base().setLocation(LayoutPoint(horizontalOffset(base()), verticalOffset));
verticalOffset += base().logicalHeight();
- if (m_scriptType == Under || m_scriptType == UnderOver) {
+ if (scriptType() == ScriptType::Under || scriptType() == ScriptType::UnderOver) {
if (parameters.useUnderOverBarFallBack) {
if (!hasAccentUnder())
verticalOffset += parameters.underGapMin;