1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
|
/*
* Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
* Copyright (C) 2009, 2014 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_ELEMENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_ELEMENT_H_
#include "base/macros.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/events/simulated_click_options.h"
#include "third_party/blink/renderer/core/svg/properties/svg_property_info.h"
#include "third_party/blink/renderer/core/svg/svg_parsing_error.h"
#include "third_party/blink/renderer/core/svg_names.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
namespace blink {
class AffineTransform;
class Document;
class ElementSMILAnimations;
class ExecutionContext;
class SVGAnimatedPropertyBase;
class SubtreeLayoutScope;
class SVGAnimatedString;
class SVGElement;
class SVGElementRareData;
class SVGElementResourceClient;
class SVGPropertyBase;
class SVGSVGElement;
class SVGUseElement;
typedef HeapHashSet<Member<SVGElement>> SVGElementSet;
class CORE_EXPORT SVGElement : public Element {
DEFINE_WRAPPERTYPEINFO();
public:
~SVGElement() override;
bool SupportsFocus() const override { return false; }
bool IsOutermostSVGSVGElement() const;
bool HasTagName(const SVGQualifiedName& name) const {
return HasLocalName(name.LocalName());
}
String title() const override;
bool HasRelativeLengths() const {
return !elements_with_relative_lengths_.IsEmpty();
}
static bool IsAnimatableCSSProperty(const QualifiedName&);
enum ApplyMotionTransform {
kExcludeMotionTransform,
kIncludeMotionTransform
};
bool HasTransform(ApplyMotionTransform) const;
AffineTransform CalculateTransform(ApplyMotionTransform) const;
enum CTMScope {
kNearestViewportScope, // Used by SVGGraphicsElement::getCTM()
kScreenScope, // Used by SVGGraphicsElement::getScreenCTM()
kAncestorScope // Used by SVGSVGElement::get{Enclosure|Intersection}List()
};
virtual AffineTransform LocalCoordinateSpaceTransform(CTMScope) const;
bool InstanceUpdatesBlocked() const;
void SetInstanceUpdatesBlocked(bool);
// Records the SVG element as having a Web Animation on an SVG attribute that
// needs applying.
void SetWebAnimationsPending();
void ApplyActiveWebAnimations();
void BaseValueChanged(const SVGAnimatedPropertyBase&);
void EnsureAttributeAnimValUpdated();
void SetWebAnimatedAttribute(const QualifiedName& attribute,
SVGPropertyBase*);
void ClearWebAnimatedAttributes();
ElementSMILAnimations* GetSMILAnimations() const;
ElementSMILAnimations& EnsureSMILAnimations();
const ComputedStyle* BaseComputedStyleForSMIL();
void SetAnimatedAttribute(const QualifiedName&, SVGPropertyBase*);
void ClearAnimatedAttribute(const QualifiedName&);
void SetAnimatedMotionTransform(const AffineTransform&);
void ClearAnimatedMotionTransform();
bool HasNonCSSPropertyAnimations() const;
SVGSVGElement* ownerSVGElement() const;
SVGElement* viewportElement() const;
virtual bool IsSVGGeometryElement() const { return false; }
virtual bool IsSVGGraphicsElement() const { return false; }
virtual bool IsFilterEffect() const { return false; }
virtual bool IsTextContent() const { return false; }
virtual bool IsTextPositioning() const { return false; }
virtual bool IsStructurallyExternal() const { return false; }
// For SVGTests
virtual bool IsValid() const { return true; }
struct SvgAttributeChangedParams {
STACK_ALLOCATED();
public:
SvgAttributeChangedParams(const QualifiedName& qname,
AttributeModificationReason reason)
: name(qname), reason(reason) {}
const QualifiedName& name;
const AttributeModificationReason reason;
};
virtual void SvgAttributeChanged(const SvgAttributeChangedParams&);
SVGAnimatedPropertyBase* PropertyFromAttribute(
const QualifiedName& attribute_name) const;
static AnimatedPropertyType AnimatedPropertyTypeForCSSAttribute(
const QualifiedName& attribute_name);
void SendSVGLoadEventToSelfAndAncestorChainIfPossible();
bool SendSVGLoadEventIfPossible();
virtual AffineTransform* AnimateMotionTransform() { return nullptr; }
void InvalidateSVGPresentationAttributeStyle() {
EnsureUniqueElementData().SetPresentationAttributeStyleIsDirty(true);
}
const HeapHashSet<WeakMember<SVGElement>>& InstancesForElement() const;
void MapInstanceToElement(SVGElement*);
void RemoveInstanceMapping(SVGElement*);
SVGElement* CorrespondingElement() const;
void SetCorrespondingElement(SVGElement*);
SVGUseElement* GeneratingUseElement() const;
void SynchronizeSVGAttribute(const QualifiedName&) const;
void CollectExtraStyleForPresentationAttribute(
MutableCSSPropertyValueSet*) override;
scoped_refptr<ComputedStyle> CustomStyleForLayoutObject(
const StyleRecalcContext&) final;
bool LayoutObjectIsNeeded(const ComputedStyle&) const override;
#if DCHECK_IS_ON()
virtual bool IsAnimatableAttribute(const QualifiedName&) const;
#endif
MutableCSSPropertyValueSet* AnimatedSMILStyleProperties() const;
MutableCSSPropertyValueSet* EnsureAnimatedSMILStyleProperties();
virtual bool HaveLoadedRequiredResources();
void InvalidateRelativeLengthClients(SubtreeLayoutScope* = nullptr);
void AddToPropertyMap(SVGAnimatedPropertyBase*);
SVGAnimatedString* className() { return class_name_.Get(); }
bool InUseShadowTree() const;
void AddReferenceTo(SVGElement*);
template <typename InvalidationFunction>
void NotifyIncomingReferences(InvalidationFunction&&);
void RebuildAllIncomingReferences();
void RemoveAllIncomingReferences();
void RemoveAllOutgoingReferences();
SVGElementResourceClient* GetSVGResourceClient();
SVGElementResourceClient& EnsureSVGResourceClient();
class InvalidationGuard {
STACK_ALLOCATED();
public:
InvalidationGuard(SVGElement* element) : element_(element) {}
~InvalidationGuard() { element_->InvalidateInstances(); }
private:
SVGElement* element_;
DISALLOW_COPY_AND_ASSIGN(InvalidationGuard);
};
class InstanceUpdateBlocker {
STACK_ALLOCATED();
public:
InstanceUpdateBlocker(SVGElement* target_element);
~InstanceUpdateBlocker();
private:
SVGElement* target_element_;
DISALLOW_COPY_AND_ASSIGN(InstanceUpdateBlocker);
};
void InvalidateInstances();
void SetNeedsStyleRecalcForInstances(StyleChangeType,
const StyleChangeReasonForTracing&);
void Trace(Visitor*) const override;
static const AtomicString& EventParameterName();
bool IsPresentationAttribute(const QualifiedName&) const override;
bool HasSVGParent() const;
protected:
SVGElement(const QualifiedName&,
Document&,
ConstructionType = kCreateSVGElement);
void ParseAttribute(const AttributeModificationParams&) override;
void AttributeChanged(const AttributeModificationParams&) override;
void CollectStyleForPresentationAttribute(
const QualifiedName&,
const AtomicString&,
MutableCSSPropertyValueSet*) override;
InsertionNotificationRequest InsertedInto(ContainerNode&) override;
void RemovedFrom(ContainerNode&) override;
void ChildrenChanged(const ChildrenChange&) override;
void DetachLayoutTree(bool performing_reattach) override;
static CSSPropertyID CssPropertyIdForSVGAttributeName(const ExecutionContext*,
const QualifiedName&);
void UpdateRelativeLengthsInformation() {
UpdateRelativeLengthsInformation(SelfHasRelativeLengths(), this);
}
void UpdateRelativeLengthsInformation(bool has_relative_lengths, SVGElement*);
static void MarkForLayoutAndParentResourceInvalidation(LayoutObject&);
virtual bool SelfHasRelativeLengths() const { return false; }
SVGElementSet* SetOfIncomingReferences() const;
SVGElementRareData* EnsureSVGRareData();
inline bool HasSVGRareData() const { return svg_rare_data_; }
inline SVGElementRareData* SvgRareData() const {
DCHECK(svg_rare_data_);
return svg_rare_data_.Get();
}
void ReportAttributeParsingError(SVGParsingError,
const QualifiedName&,
const AtomicString&);
bool HasFocusEventListeners() const;
void AddedEventListener(const AtomicString& event_type,
RegisteredEventListener&) override;
void RemovedEventListener(const AtomicString& event_type,
const RegisteredEventListener&) final;
void AccessKeyAction(SimulatedClickCreationScope creation_scope) override;
private:
bool IsSVGElement() const =
delete; // This will catch anyone doing an unnecessary check.
bool IsStyledElement() const =
delete; // This will catch anyone doing an unnecessary check.
void WillRecalcStyle(const StyleRecalcChange) override;
static SVGElementSet& GetDependencyTraversalVisitedSet();
void UpdateWebAnimatedAttributeOnBaseValChange(const QualifiedName&);
HeapHashSet<WeakMember<SVGElement>> elements_with_relative_lengths_;
typedef HeapHashMap<QualifiedName, Member<SVGAnimatedPropertyBase>>
AttributeToPropertyMap;
AttributeToPropertyMap attribute_to_property_map_;
#if DCHECK_IS_ON()
bool in_relative_length_clients_invalidation_ = false;
#endif
Member<SVGElementRareData> svg_rare_data_;
Member<SVGAnimatedString> class_name_;
};
template <typename InvalidationFunction>
void SVGElement::NotifyIncomingReferences(
InvalidationFunction&& invalidation_function) {
SVGElementSet* dependencies = SetOfIncomingReferences();
if (!dependencies)
return;
// We allow cycles in the reference graph in order to avoid expensive
// adjustments on changes, so we need to break possible cycles here.
SVGElementSet& invalidating_dependencies = GetDependencyTraversalVisitedSet();
for (SVGElement* element : *dependencies) {
if (!element->GetLayoutObject())
continue;
if (UNLIKELY(!invalidating_dependencies.insert(element).is_new_entry)) {
// Reference cycle: we are in process of invalidating this dependant.
continue;
}
invalidation_function(*element);
invalidating_dependencies.erase(element);
}
}
struct SVGAttributeHashTranslator {
STATIC_ONLY(SVGAttributeHashTranslator);
static unsigned GetHash(const QualifiedName& key) {
if (key.HasPrefix()) {
QualifiedNameComponents components = {g_null_atom.Impl(),
key.LocalName().Impl(),
key.NamespaceURI().Impl()};
return HashComponents(components);
}
return DefaultHash<QualifiedName>::Hash::GetHash(key);
}
static bool Equal(const QualifiedName& a, const QualifiedName& b) {
return a.Matches(b);
}
};
template <typename T>
bool IsElementOfType(const SVGElement&);
template <>
inline bool IsElementOfType<const SVGElement>(const SVGElement&) {
return true;
}
template <>
inline bool IsElementOfType<const SVGElement>(const Node& node) {
return IsA<SVGElement>(node);
}
template <>
struct DowncastTraits<SVGElement> {
static bool AllowFrom(const Node& node) { return node.IsSVGElement(); }
};
inline bool Node::HasTagName(const SVGQualifiedName& name) const {
auto* svg_element = DynamicTo<SVGElement>(this);
return svg_element && svg_element->HasTagName(name);
}
} // namespace blink
#include "third_party/blink/renderer/core/svg_element_type_helpers.h"
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_SVG_SVG_ELEMENT_H_
|