From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/mathml/MathMLSelectElement.cpp | 111 +++++++++++++++----------- 1 file changed, 66 insertions(+), 45 deletions(-) (limited to 'Source/WebCore/mathml/MathMLSelectElement.cpp') 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::create(const QualifiedName& tagName, Document& document) +Ref MathMLSelectElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new MathMLSelectElement(tagName, document)); + return adoptRef(*new MathMLSelectElement(tagName, document)); } -RenderPtr MathMLSelectElement::createElementRenderer(PassRef style) +RenderPtr MathMLSelectElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) { - return createRenderer(*this, std::move(style)); + return createRenderer(*this, WTFMove(style)); +} + +// We recognize the following values for the encoding attribute of the 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(*child) || !downcast(*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(*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 or 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(*child)) continue; - if (child->hasLocalName(MathMLNames::annotationTag)) { + if (child->hasTagName(MathMLNames::annotationTag)) { // If the 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 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 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 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)); } } -- cgit v1.2.1