1/*
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#pragma once
21
22#include "StyleProperties.h"
23#include "StyleResolver.h"
24#include <wtf/HashSet.h>
25#include <wtf/Noncopyable.h>
26#include <wtf/StdLibExtras.h>
27
28namespace WebCore {
29
30class CSSCursorImageValue;
31class SVGCursorElement;
32class SVGElement;
33
34class SVGElementRareData {
35 WTF_MAKE_NONCOPYABLE(SVGElementRareData); WTF_MAKE_FAST_ALLOCATED;
36public:
37 SVGElementRareData()
38 : m_instancesUpdatesBlocked(false)
39 , m_useOverrideComputedStyle(false)
40 , m_needsOverrideComputedStyleUpdate(false)
41 {
42 }
43
44 HashSet<SVGElement*>& instances() { return m_instances; }
45 const HashSet<SVGElement*>& instances() const { return m_instances; }
46
47 bool instanceUpdatesBlocked() const { return m_instancesUpdatesBlocked; }
48 void setInstanceUpdatesBlocked(bool value) { m_instancesUpdatesBlocked = value; }
49
50 SVGElement* correspondingElement() { return m_correspondingElement; }
51 void setCorrespondingElement(SVGElement* correspondingElement) { m_correspondingElement = correspondingElement; }
52
53 MutableStyleProperties* animatedSMILStyleProperties() const { return m_animatedSMILStyleProperties.get(); }
54 MutableStyleProperties& ensureAnimatedSMILStyleProperties()
55 {
56 if (!m_animatedSMILStyleProperties)
57 m_animatedSMILStyleProperties = MutableStyleProperties::create(SVGAttributeMode);
58 return *m_animatedSMILStyleProperties;
59 }
60
61 const RenderStyle* overrideComputedStyle(Element& element, const RenderStyle* parentStyle)
62 {
63 if (!m_useOverrideComputedStyle)
64 return nullptr;
65 if (!m_overrideComputedStyle || m_needsOverrideComputedStyleUpdate) {
66 // The style computed here contains no CSS Animations/Transitions or SMIL induced rules - this is needed to compute the "base value" for the SMIL animation sandwhich model.
67 m_overrideComputedStyle = element.styleResolver().styleForElement(element, parentStyle, nullptr, RuleMatchingBehavior::MatchAllRulesExcludingSMIL).renderStyle;
68 m_needsOverrideComputedStyleUpdate = false;
69 }
70 ASSERT(m_overrideComputedStyle);
71 return m_overrideComputedStyle.get();
72 }
73
74 bool useOverrideComputedStyle() const { return m_useOverrideComputedStyle; }
75 void setUseOverrideComputedStyle(bool value) { m_useOverrideComputedStyle = value; }
76 void setNeedsOverrideComputedStyleUpdate() { m_needsOverrideComputedStyleUpdate = true; }
77
78private:
79 HashSet<SVGElement*> m_instances;
80 SVGElement* m_correspondingElement { nullptr };
81 bool m_instancesUpdatesBlocked : 1;
82 bool m_useOverrideComputedStyle : 1;
83 bool m_needsOverrideComputedStyleUpdate : 1;
84 RefPtr<MutableStyleProperties> m_animatedSMILStyleProperties;
85 std::unique_ptr<RenderStyle> m_overrideComputedStyle;
86};
87
88} // namespace WebCore
89