summaryrefslogtreecommitdiff
path: root/Source/WebCore/mathml/MathMLSelectElement.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/mathml/MathMLSelectElement.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/mathml/MathMLSelectElement.cpp')
-rw-r--r--Source/WebCore/mathml/MathMLSelectElement.cpp111
1 files changed, 66 insertions, 45 deletions
diff --git a/Source/WebCore/mathml/MathMLSelectElement.cpp b/Source/WebCore/mathml/MathMLSelectElement.cpp
index a127bfd85..bab957a09 100644
--- a/Source/WebCore/mathml/MathMLSelectElement.cpp
+++ b/Source/WebCore/mathml/MathMLSelectElement.cpp
@@ -29,27 +29,55 @@
#if ENABLE(MATHML)
#include "Event.h"
+#include "EventNames.h"
+#include "HTMLElement.h"
+#include "HTMLNames.h"
#include "MathMLNames.h"
#include "RenderMathMLRow.h"
+#include "RenderTreeUpdater.h"
+#include "SVGElement.h"
namespace WebCore {
using namespace MathMLNames;
MathMLSelectElement::MathMLSelectElement(const QualifiedName& tagName, Document& document)
- : MathMLInlineContainerElement(tagName, document)
+ : MathMLRowElement(tagName, document)
, m_selectedChild(nullptr)
{
}
-PassRefPtr<MathMLSelectElement> MathMLSelectElement::create(const QualifiedName& tagName, Document& document)
+Ref<MathMLSelectElement> MathMLSelectElement::create(const QualifiedName& tagName, Document& document)
{
- return adoptRef(new MathMLSelectElement(tagName, document));
+ return adoptRef(*new MathMLSelectElement(tagName, document));
}
-RenderPtr<RenderElement> MathMLSelectElement::createElementRenderer(PassRef<RenderStyle> style)
+RenderPtr<RenderElement> MathMLSelectElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
{
- return createRenderer<RenderMathMLRow>(*this, std::move(style));
+ return createRenderer<RenderMathMLRow>(*this, WTFMove(style));
+}
+
+// We recognize the following values for the encoding attribute of the <semantics> element:
+//
+// - "MathML-Presentation", which is mentioned in the MathML 3 recommendation.
+// - "SVG1.1" which is mentioned in the W3C note.
+// http://www.w3.org/Math/Documents/Notes/graphics.xml
+// - Other MIME Content-Types for MathML, SVG and HTML.
+//
+// We exclude "application/mathml+xml" which is ambiguous about whether it is Presentation or Content MathML. Authors must use a more explicit encoding value.
+bool MathMLSelectElement::isMathMLEncoding(const AtomicString& value)
+{
+ return value == "application/mathml-presentation+xml" || value == "MathML-Presentation";
+}
+
+bool MathMLSelectElement::isSVGEncoding(const AtomicString& value)
+{
+ return value == "image/svg+xml" || value == "SVG1.1";
+}
+
+bool MathMLSelectElement::isHTMLEncoding(const AtomicString& value)
+{
+ return value == "application/xhtml+xml" || value == "text/html";
}
bool MathMLSelectElement::childShouldCreateRenderer(const Node& child) const
@@ -60,36 +88,36 @@ bool MathMLSelectElement::childShouldCreateRenderer(const Node& child) const
void MathMLSelectElement::finishParsingChildren()
{
updateSelectedChild();
- MathMLInlineContainerElement::finishParsingChildren();
+ MathMLRowElement::finishParsingChildren();
}
void MathMLSelectElement::childrenChanged(const ChildChange& change)
{
updateSelectedChild();
- MathMLInlineContainerElement::childrenChanged(change);
+ MathMLRowElement::childrenChanged(change);
}
void MathMLSelectElement::attributeChanged(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason reason)
{
- if (hasLocalName(mactionTag) && (name == MathMLNames::actiontypeAttr || name == MathMLNames::selectionAttr))
+ if (hasTagName(mactionTag) && (name == MathMLNames::actiontypeAttr || name == MathMLNames::selectionAttr))
updateSelectedChild();
- MathMLInlineContainerElement::attributeChanged(name, oldValue, newValue, reason);
+ MathMLRowElement::attributeChanged(name, oldValue, newValue, reason);
}
int MathMLSelectElement::getSelectedActionChildAndIndex(Element*& selectedChild)
{
- ASSERT(hasLocalName(mactionTag));
+ ASSERT(hasTagName(mactionTag));
// We "round up or down to the closest allowable value" of the selection attribute, as suggested by the MathML specification.
selectedChild = firstElementChild();
if (!selectedChild)
return 1;
- int selection = fastGetAttribute(MathMLNames::selectionAttr).toInt();
+ int selection = attributeWithoutSynchronization(MathMLNames::selectionAttr).toInt();
int i;
for (i = 1; i < selection; i++) {
- Element* nextChild = selectedChild->nextElementSibling();
+ auto* nextChild = selectedChild->nextElementSibling();
if (!nextChild)
break;
selectedChild = nextChild;
@@ -100,14 +128,14 @@ int MathMLSelectElement::getSelectedActionChildAndIndex(Element*& selectedChild)
Element* MathMLSelectElement::getSelectedActionChild()
{
- ASSERT(hasLocalName(mactionTag));
+ ASSERT(hasTagName(mactionTag));
- Element* child = firstElementChild();
+ auto* child = firstElementChild();
if (!child)
return child;
// The value of the actiontype attribute is case-sensitive.
- const AtomicString& actiontype = fastGetAttribute(MathMLNames::actiontypeAttr);
+ auto& actiontype = attributeWithoutSynchronization(MathMLNames::actiontypeAttr);
if (actiontype == "statusline")
// FIXME: implement user interaction for the "statusline" action type (http://wkbug/124922).
{ }
@@ -124,47 +152,40 @@ Element* MathMLSelectElement::getSelectedActionChild()
Element* MathMLSelectElement::getSelectedSemanticsChild()
{
- ASSERT(hasLocalName(semanticsTag));
+ ASSERT(hasTagName(semanticsTag));
- Element* child = firstElementChild();
+ auto* child = firstElementChild();
if (!child)
- return child;
+ return nullptr;
- if (!child->isMathMLElement() || !toMathMLElement(child)->isPresentationMathML()) {
+ if (!is<MathMLElement>(*child) || !downcast<MathMLElement>(*child).isPresentationMathML()) {
// The first child is not a presentation MathML element. Hence we move to the second child and start searching an annotation child that could be displayed.
child = child->nextElementSibling();
- } else if (!toMathMLElement(child)->isSemanticAnnotation()) {
+ } else if (!downcast<MathMLElement>(*child).isSemanticAnnotation()) {
// The first child is a presentation MathML but not an annotation, so we can just display it.
return child;
}
// Otherwise, the first child is an <annotation> or <annotation-xml> element. This is invalid, but some people use this syntax so we take care of this case too and start the search from this first child.
for ( ; child; child = child->nextElementSibling()) {
- if (!child->isMathMLElement())
+ if (!is<MathMLElement>(*child))
continue;
- if (child->hasLocalName(MathMLNames::annotationTag)) {
+ if (child->hasTagName(MathMLNames::annotationTag)) {
// If the <annotation> element has an src attribute then it is a reference to arbitrary binary data and it is not clear whether we can display it. Hence we just ignore the annotation.
- if (child->hasAttribute(MathMLNames::srcAttr))
+ if (child->hasAttributeWithoutSynchronization(MathMLNames::srcAttr))
continue;
// Otherwise, we assume it is a text annotation that can always be displayed and we stop here.
return child;
}
- if (child->hasLocalName(MathMLNames::annotation_xmlTag)) {
+ if (child->hasTagName(MathMLNames::annotation_xmlTag)) {
// If the <annotation-xml> element has an src attribute then it is a reference to arbitrary binary data and it is not clear whether we can display it. Hence we just ignore the annotation.
- if (child->hasAttribute(MathMLNames::srcAttr))
+ if (child->hasAttributeWithoutSynchronization(MathMLNames::srcAttr))
continue;
- // If the <annotation-xml> element has an encoding attribute describing presentation MathML, SVG or HTML we assume the content can be displayed and we stop here. We recognize the following encoding values:
- //
- // - "MathML-Presentation", which is mentioned in the MathML 3 recommendation.
- // - "SVG1.1" which is mentioned in the W3C note.
- // http://www.w3.org/Math/Documents/Notes/graphics.xml
- // - Other MIME Content-Types for SVG and HTML.
- //
- // We exclude "application/mathml+xml" which is ambiguous about whether it is Presentation or Content MathML. Authors must use a more explicit encoding value.
- const AtomicString& value = child->fastGetAttribute(MathMLNames::encodingAttr);
- if (value == "application/mathml-presentation+xml" || value == "MathML-Presentation" || value == "image/svg+xml" || value == "SVG1.1" || value == "application/xhtml+xml" || value == "text/html")
+ // If the <annotation-xml> element has an encoding attribute describing presentation MathML, SVG or HTML we assume the content can be displayed and we stop here.
+ auto& value = child->attributeWithoutSynchronization(MathMLNames::encodingAttr);
+ if (isMathMLEncoding(value) || isSVGEncoding(value) || isHTMLEncoding(value))
return child;
}
}
@@ -175,34 +196,34 @@ Element* MathMLSelectElement::getSelectedSemanticsChild()
void MathMLSelectElement::updateSelectedChild()
{
- Element* newSelectedChild = hasLocalName(mactionTag) ? getSelectedActionChild() : getSelectedSemanticsChild();
+ auto* newSelectedChild = hasTagName(mactionTag) ? getSelectedActionChild() : getSelectedSemanticsChild();
if (m_selectedChild == newSelectedChild)
return;
if (m_selectedChild && m_selectedChild->renderer())
- Style::detachRenderTree(*m_selectedChild);
+ RenderTreeUpdater::tearDownRenderers(*m_selectedChild);
m_selectedChild = newSelectedChild;
- setNeedsStyleRecalc();
+ invalidateStyleForSubtree();
}
-void MathMLSelectElement::defaultEventHandler(Event* event)
+void MathMLSelectElement::defaultEventHandler(Event& event)
{
- if (event->type() == eventNames().clickEvent) {
- if (fastGetAttribute(MathMLNames::actiontypeAttr) == "toggle") {
+ if (event.type() == eventNames().clickEvent) {
+ if (attributeWithoutSynchronization(MathMLNames::actiontypeAttr) == "toggle") {
toggle();
- event->setDefaultHandled();
+ event.setDefaultHandled();
return;
}
}
- MathMLInlineContainerElement::defaultEventHandler(event);
+ MathMLRowElement::defaultEventHandler(event);
}
bool MathMLSelectElement::willRespondToMouseClickEvents()
{
- return fastGetAttribute(MathMLNames::actiontypeAttr) == "toggle";
+ return attributeWithoutSynchronization(MathMLNames::actiontypeAttr) == "toggle" || MathMLRowElement::willRespondToMouseClickEvents();
}
void MathMLSelectElement::toggle()
@@ -216,7 +237,7 @@ void MathMLSelectElement::toggle()
// We update the attribute value of the selection attribute.
// This will also call MathMLSelectElement::attributeChanged to update the selected child.
- setAttribute(MathMLNames::selectionAttr, AtomicString::number(newSelectedChildIndex));
+ setAttributeWithoutSynchronization(MathMLNames::selectionAttr, AtomicString::number(newSelectedChildIndex));
}
}