diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-16 11:45:35 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-07-17 08:59:23 +0000 |
commit | 552906b0f222c5d5dd11b9fd73829d510980461a (patch) | |
tree | 3a11e6ed0538a81dd83b20cf3a4783e297f26d91 /chromium/third_party/blink/renderer/core/svg/svg_element.cc | |
parent | 1b05827804eaf047779b597718c03e7d38344261 (diff) | |
download | qtwebengine-chromium-552906b0f222c5d5dd11b9fd73829d510980461a.tar.gz |
BASELINE: Update Chromium to 83.0.4103.122
Change-Id: Ie3a82f5bb0076eec2a7c6a6162326b4301ee291e
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/third_party/blink/renderer/core/svg/svg_element.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/core/svg/svg_element.cc | 100 |
1 files changed, 51 insertions, 49 deletions
diff --git a/chromium/third_party/blink/renderer/core/svg/svg_element.cc b/chromium/third_party/blink/renderer/core/svg/svg_element.cc index 899109d37d5..71de49ebb40 100644 --- a/chromium/third_party/blink/renderer/core/svg/svg_element.cc +++ b/chromium/third_party/blink/renderer/core/svg/svg_element.cc @@ -38,6 +38,7 @@ #include "third_party/blink/renderer/core/css/resolver/style_resolver.h" #include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/element_traversal.h" +#include "third_party/blink/renderer/core/dom/events/add_event_listener_options_resolved.h" #include "third_party/blink/renderer/core/dom/events/event.h" #include "third_party/blink/renderer/core/dom/flat_tree_traversal.h" #include "third_party/blink/renderer/core/dom/node_computed_style.h" @@ -88,13 +89,6 @@ void SVGElement::DetachLayoutTree(bool performing_reattach) { SvgRareData()->ClearOverriddenComputedStyle(); } -TreeScope& SVGElement::TreeScopeForIdResolution() const { - const SVGElement* tree_scope_element = this; - if (const SVGElement* element = CorrespondingUseElement()) - tree_scope_element = element; - return tree_scope_element->GetTreeScope(); -} - void SVGElement::WillRecalcStyle(const StyleRecalcChange change) { if (!HasSVGRareData()) return; @@ -145,10 +139,10 @@ void SVGElement::ReportAttributeParsingError(SVGParsingError error, // Don't report any errors on attribute removal. if (value.IsNull()) return; - GetDocument().AddConsoleMessage( - ConsoleMessage::Create(mojom::ConsoleMessageSource::kRendering, - mojom::ConsoleMessageLevel::kError, - "Error: " + error.Format(tagName(), name, value))); + GetDocument().AddConsoleMessage(MakeGarbageCollected<ConsoleMessage>( + mojom::ConsoleMessageSource::kRendering, + mojom::ConsoleMessageLevel::kError, + "Error: " + error.Format(tagName(), name, value))); } String SVGElement::title() const { @@ -186,7 +180,7 @@ void SVGElement::SetInstanceUpdatesBlocked(bool value) { void SVGElement::SetWebAnimationsPending() { GetDocument().AccessSVGExtensions().AddWebAnimationsPendingSVGElement(*this); EnsureSVGRareData()->SetWebAnimatedAttributesDirty(true); - EnsureUniqueElementData().animated_svg_attributes_are_dirty_ = true; + EnsureUniqueElementData().SetAnimatedSvgAttributesAreDirty(true); } static bool IsSVGAttributeHandle(const PropertyHandle& property_handle) { @@ -302,28 +296,23 @@ AffineTransform SVGElement::CalculateTransform( Node::InsertionNotificationRequest SVGElement::InsertedInto( ContainerNode& root_parent) { Element::InsertedInto(root_parent); + HideNonce(); UpdateRelativeLengthsInformation(); - - const AtomicString& nonce_value = FastGetAttribute(html_names::kNonceAttr); - if (!nonce_value.IsEmpty()) { - setNonce(nonce_value); - if (InActiveDocument() && - GetDocument().GetContentSecurityPolicy()->HasHeaderDeliveredPolicy()) { - setAttribute(html_names::kNonceAttr, g_empty_atom); - } - } return kInsertionDone; } void SVGElement::RemovedFrom(ContainerNode& root_parent) { bool was_in_document = root_parent.isConnected(); - auto* root_parent_svg_element = DynamicTo<SVGElement>(root_parent); + auto* root_parent_svg_element = DynamicTo<SVGElement>( + root_parent.IsShadowRoot() ? root_parent.ParentOrShadowHostElement() + : &root_parent); + if (was_in_document && HasRelativeLengths()) { // The root of the subtree being removed should take itself out from its // parent's relative length set. For the other nodes in the subtree we don't // need to do anything: they will get their own removedFrom() notification // and just clear their sets. - if (root_parent_svg_element && !parentNode()) { + if (root_parent_svg_element && !ParentOrShadowHostElement()) { DCHECK(root_parent_svg_element->elements_with_relative_lengths_.Contains( this)); root_parent_svg_element->UpdateRelativeLengthsInformation(false, this); @@ -332,13 +321,15 @@ void SVGElement::RemovedFrom(ContainerNode& root_parent) { elements_with_relative_lengths_.clear(); } - SECURITY_DCHECK( + DCHECK( !root_parent_svg_element || !root_parent_svg_element->elements_with_relative_lengths_.Contains(this)); Element::RemovedFrom(root_parent); if (was_in_document) { + if (HasSVGRareData() && SvgRareData()->CorrespondingElement()) + SvgRareData()->CorrespondingElement()->RemoveInstanceMapping(this); RebuildAllIncomingReferences(); RemoveAllIncomingReferences(); } @@ -354,6 +345,7 @@ void SVGElement::ChildrenChanged(const ChildrenChange& change) { } CSSPropertyID SVGElement::CssPropertyIdForSVGAttributeName( + const ExecutionContext* execution_context, const QualifiedName& attr_name) { if (!attr_name.NamespaceURI().IsNull()) return CSSPropertyID::kInvalid; @@ -424,7 +416,8 @@ CSSPropertyID SVGElement::CssPropertyIdForSVGAttributeName( &svg_names::kWritingModeAttr, }; for (size_t i = 0; i < base::size(attr_names); i++) { - CSSPropertyID property_id = cssPropertyID(attr_names[i]->LocalName()); + CSSPropertyID property_id = + cssPropertyID(execution_context, attr_names[i]->LocalName()); DCHECK_GT(property_id, CSSPropertyID::kInvalid); property_name_to_id_map->Set(attr_names[i]->LocalName().Impl(), property_id); @@ -446,8 +439,9 @@ void SVGElement::UpdateRelativeLengthsInformation( // disconnected. // If we're not yet in a document, this function will be called again from // insertedInto(). Do nothing now. - for (Node& current_node : NodeTraversal::InclusiveAncestorsOf(*this)) { - if (!current_node.isConnected()) + for (Node* current_node = this; current_node; + current_node = current_node->ParentOrShadowHostNode()) { + if (!current_node->isConnected()) return; } @@ -455,10 +449,12 @@ void SVGElement::UpdateRelativeLengthsInformation( // Register it in the relative length map, and register us in the parent // relative length map. Register the parent in the grandparents map, etc. // Repeat procedure until the root of the SVG tree. - for (Node& current_node : NodeTraversal::InclusiveAncestorsOf(*this)) { + for (Element* current_node = this; current_node; + current_node = current_node->ParentOrShadowHostElement()) { auto* current_element = DynamicTo<SVGElement>(current_node); if (!current_element) break; + #if DCHECK_IS_ON() DCHECK(!current_element->in_relative_length_clients_invalidation_); #endif @@ -558,10 +554,8 @@ void SVGElement::MapInstanceToElement(SVGElement* instance) { void SVGElement::RemoveInstanceMapping(SVGElement* instance) { DCHECK(instance); - DCHECK(instance->InUseShadowTree()); - - if (!HasSVGRareData()) - return; + // Called during instance->RemovedFrom() after removal from shadow tree + DCHECK(!instance->isConnected()); HeapHashSet<WeakMember<SVGElement>>& instances = SvgRareData()->ElementInstances(); @@ -589,7 +583,7 @@ SVGElement* SVGElement::CorrespondingElement() const { return HasSVGRareData() ? SvgRareData()->CorrespondingElement() : nullptr; } -SVGUseElement* SVGElement::CorrespondingUseElement() const { +SVGUseElement* SVGElement::GeneratingUseElement() const { if (ShadowRoot* root = ContainingShadowRoot()) { return DynamicTo<SVGUseElement>(root->host()); } @@ -601,7 +595,7 @@ void SVGElement::SetCorrespondingElement(SVGElement* corresponding_element) { } bool SVGElement::InUseShadowTree() const { - return CorrespondingUseElement(); + return GeneratingUseElement(); } void SVGElement::ParseAttribute(const AttributeModificationParams& params) { @@ -618,6 +612,12 @@ void SVGElement::ParseAttribute(const AttributeModificationParams& params) { return; } + // SVGElement and HTMLElement are handling "nonce" the same way. + if (params.name == html_names::kNonceAttr) { + if (params.new_value != g_empty_atom) + setNonce(params.new_value); + } + const AtomicString& event_name = HTMLElement::EventNameForAttributeName(params.name); if (!event_name.IsNull()) { @@ -735,14 +735,16 @@ bool SVGElement::IsAnimatableCSSProperty(const QualifiedName& attr_name) { bool SVGElement::IsPresentationAttribute(const QualifiedName& name) const { if (const SVGAnimatedPropertyBase* property = PropertyFromAttribute(name)) return property->HasPresentationAttributeMapping(); - return CssPropertyIdForSVGAttributeName(name) > CSSPropertyID::kInvalid; + return CssPropertyIdForSVGAttributeName(GetDocument().ToExecutionContext(), + name) > CSSPropertyID::kInvalid; } void SVGElement::CollectStyleForPresentationAttribute( const QualifiedName& name, const AtomicString& value, MutableCSSPropertyValueSet* style) { - CSSPropertyID property_id = CssPropertyIdForSVGAttributeName(name); + CSSPropertyID property_id = CssPropertyIdForSVGAttributeName( + GetDocument().ToExecutionContext(), name); if (property_id > CSSPropertyID::kInvalid) AddPropertyToPresentationAttributeStyle(style, property_id, value); } @@ -875,8 +877,8 @@ void SVGElement::AttributeChanged(const AttributeModificationParams& params) { } void SVGElement::SvgAttributeChanged(const QualifiedName& attr_name) { - CSSPropertyID prop_id = - SVGElement::CssPropertyIdForSVGAttributeName(attr_name); + CSSPropertyID prop_id = SVGElement::CssPropertyIdForSVGAttributeName( + GetDocument().ToExecutionContext(), attr_name); if (prop_id > CSSPropertyID::kInvalid) { InvalidateInstances(); return; @@ -898,7 +900,7 @@ void SVGElement::SvgAttributeBaseValChanged(const QualifiedName& attribute) { // TODO(alancutter): Only mark attributes as dirty if their animation depends // on the underlying value. SvgRareData()->SetWebAnimatedAttributesDirty(true); - GetElementData()->animated_svg_attributes_are_dirty_ = true; + GetElementData()->SetAnimatedSvgAttributesAreDirty(true); } void SVGElement::EnsureAttributeAnimValUpdated() { @@ -907,8 +909,8 @@ void SVGElement::EnsureAttributeAnimValUpdated() { if ((HasSVGRareData() && SvgRareData()->WebAnimatedAttributesDirty()) || (GetElementAnimations() && - DocumentAnimations::NeedsAnimationTimingUpdate(GetDocument()))) { - DocumentAnimations::UpdateAnimationTimingIfNeeded(GetDocument()); + GetDocument().GetDocumentAnimations().NeedsAnimationTimingUpdate())) { + GetDocument().GetDocumentAnimations().UpdateAnimationTimingIfNeeded(); ApplyActiveWebAnimations(); } } @@ -916,7 +918,7 @@ void SVGElement::EnsureAttributeAnimValUpdated() { void SVGElement::SynchronizeAnimatedSVGAttribute( const QualifiedName& name) const { if (!GetElementData() || - !GetElementData()->animated_svg_attributes_are_dirty_) + !GetElementData()->animated_svg_attributes_are_dirty()) return; // We const_cast here because we have deferred baseVal mutation animation @@ -933,7 +935,7 @@ void SVGElement::SynchronizeAnimatedSVGAttribute( (*it)->SynchronizeAttribute(); } - GetElementData()->animated_svg_attributes_are_dirty_ = false; + GetElementData()->SetAnimatedSvgAttributesAreDirty(false); } else { SVGAnimatedPropertyBase* property = attribute_to_property_map_.at(name); if (property && property->NeedsSynchronizeAttribute()) @@ -1015,9 +1017,9 @@ void SVGElement::InvalidateInstances() { for (SVGElement* instance : set) { instance->SetCorrespondingElement(nullptr); - if (SVGUseElement* element = instance->CorrespondingUseElement()) { - if (element->isConnected()) - element->InvalidateShadowTree(); + if (SVGUseElement* element = instance->GeneratingUseElement()) { + DCHECK(element->isConnected()); + element->InvalidateShadowTree(); } } @@ -1218,17 +1220,17 @@ void SVGElement::RemoveAllOutgoingReferences() { outgoing_references.clear(); } -SVGResourceClient* SVGElement::GetSVGResourceClient() { +SVGElementResourceClient* SVGElement::GetSVGResourceClient() { if (!HasSVGRareData()) return nullptr; return SvgRareData()->GetSVGResourceClient(); } -SVGResourceClient& SVGElement::EnsureSVGResourceClient() { +SVGElementResourceClient& SVGElement::EnsureSVGResourceClient() { return EnsureSVGRareData()->EnsureSVGResourceClient(this); } -void SVGElement::Trace(blink::Visitor* visitor) { +void SVGElement::Trace(Visitor* visitor) { visitor->Trace(elements_with_relative_lengths_); visitor->Trace(attribute_to_property_map_); visitor->Trace(svg_rare_data_); |