18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/*
2dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * Copyright (C) 2004, 2005, 2007, 2008 Rob Buis <buis@kde.org>
4dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch *
5dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * This library is free software; you can redistribute it and/or
6dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * modify it under the terms of the GNU Library General Public
7dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * License as published by the Free Software Foundation; either
8dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * version 2 of the License, or (at your option) any later version.
9dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch *
10dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * This library is distributed in the hope that it will be useful,
11dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * but WITHOUT ANY WARRANTY; without even the implied warranty of
12dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * Library General Public License for more details.
14dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch *
15dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * You should have received a copy of the GNU Library General Public License
16dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * along with this library; see the file COPYING.LIB.  If not, write to
17dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch * Boston, MA 02110-1301, USA.
19dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch */
208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "config.h"
225f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#if ENABLE(SVG)
248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "SVGStyledElement.h"
258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "Attr.h"
278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "CSSParser.h"
288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "CSSStyleSelector.h"
298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "Document.h"
308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "HTMLNames.h"
318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "PlatformString.h"
325f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#include "RenderObject.h"
33692e5dbf12901edacf14812a6fae25462920af42Steve Block#include "RenderSVGResource.h"
34dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include "RenderSVGResourceClipper.h"
35dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include "RenderSVGResourceFilter.h"
36692e5dbf12901edacf14812a6fae25462920af42Steve Block#include "RenderSVGResourceMasker.h"
378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "SVGElement.h"
388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "SVGElementInstance.h"
39d0825bca7fe65beaee391d30da42e937db621564Steve Block#include "SVGElementRareData.h"
408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "SVGNames.h"
418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "SVGRenderStyle.h"
42dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include "SVGRenderSupport.h"
438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "SVGSVGElement.h"
4421939df44de1705786c545cd1bf519d47250322dBen Murdoch#include "SVGUseElement.h"
458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include <wtf/Assertions.h>
462fc2651226baac27029e38c9d6ef883fa32084dbSteve Block#include <wtf/HashMap.h>
478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
50f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch// Animated property definitions
51f05b935882198ccf7d81675736e3aeb089c5113aBen MurdochDEFINE_ANIMATED_STRING(SVGStyledElement, HTMLNames::classAttr, ClassName, className)
52f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch
538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectusing namespace SVGNames;
548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
55d0825bca7fe65beaee391d30da42e937db621564Steve Blockvoid mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, int>* propertyNameToIdMap, const QualifiedName& attrName)
56d0825bca7fe65beaee391d30da42e937db621564Steve Block{
57d0825bca7fe65beaee391d30da42e937db621564Steve Block    int propertyId = cssPropertyID(attrName.localName());
58d0825bca7fe65beaee391d30da42e937db621564Steve Block    ASSERT(propertyId > 0);
59d0825bca7fe65beaee391d30da42e937db621564Steve Block    propertyNameToIdMap->set(attrName.localName().impl(), propertyId);
60d0825bca7fe65beaee391d30da42e937db621564Steve Block}
618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
625ddde30071f639962dd557c453f2ad01f8f0fd00Kristian MonsenSVGStyledElement::SVGStyledElement(const QualifiedName& tagName, Document* document)
635ddde30071f639962dd557c453f2ad01f8f0fd00Kristian Monsen    : SVGElement(tagName, document)
648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
6521939df44de1705786c545cd1bf519d47250322dBen Murdoch}
6621939df44de1705786c545cd1bf519d47250322dBen Murdoch
67a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochSVGStyledElement::~SVGStyledElement()
68a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch{
69a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch}
70a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
7121939df44de1705786c545cd1bf519d47250322dBen MurdochString SVGStyledElement::title() const
7221939df44de1705786c545cd1bf519d47250322dBen Murdoch{
73e14391e94c850b8bd03680c23b38978db68687a8John Reck    // According to spec, we should not return titles when hovering over root <svg> elements (those
7421939df44de1705786c545cd1bf519d47250322dBen Murdoch    // <title> elements are the title of the document, not a tooltip) so we instantly return.
75e14391e94c850b8bd03680c23b38978db68687a8John Reck    if (hasTagName(SVGNames::svgTag)) {
76e14391e94c850b8bd03680c23b38978db68687a8John Reck        const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(this);
77e14391e94c850b8bd03680c23b38978db68687a8John Reck        if (svg->isOutermostSVG())
78e14391e94c850b8bd03680c23b38978db68687a8John Reck            return String();
79e14391e94c850b8bd03680c23b38978db68687a8John Reck    }
8021939df44de1705786c545cd1bf519d47250322dBen Murdoch
8121939df44de1705786c545cd1bf519d47250322dBen Murdoch    // Walk up the tree, to find out whether we're inside a <use> shadow tree, to find the right title.
8221939df44de1705786c545cd1bf519d47250322dBen Murdoch    Node* parent = const_cast<SVGStyledElement*>(this);
8321939df44de1705786c545cd1bf519d47250322dBen Murdoch    while (parent) {
842daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        if (!parent->isSVGShadowRoot()) {
85f05b935882198ccf7d81675736e3aeb089c5113aBen Murdoch            parent = parent->parentNodeGuaranteedHostFree();
8621939df44de1705786c545cd1bf519d47250322dBen Murdoch            continue;
8721939df44de1705786c545cd1bf519d47250322dBen Murdoch        }
8821939df44de1705786c545cd1bf519d47250322dBen Murdoch
8921939df44de1705786c545cd1bf519d47250322dBen Murdoch        // Get the <use> element.
902daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        Element* shadowParent = parent->svgShadowHost();
9121939df44de1705786c545cd1bf519d47250322dBen Murdoch        if (shadowParent && shadowParent->isSVGElement() && shadowParent->hasTagName(SVGNames::useTag)) {
9221939df44de1705786c545cd1bf519d47250322dBen Murdoch            SVGUseElement* useElement = static_cast<SVGUseElement*>(shadowParent);
9321939df44de1705786c545cd1bf519d47250322dBen Murdoch            // If the <use> title is not empty we found the title to use.
9421939df44de1705786c545cd1bf519d47250322dBen Murdoch            String useTitle(useElement->title());
9521939df44de1705786c545cd1bf519d47250322dBen Murdoch            if (useTitle.isEmpty())
9621939df44de1705786c545cd1bf519d47250322dBen Murdoch                break;
9721939df44de1705786c545cd1bf519d47250322dBen Murdoch            return useTitle;
9821939df44de1705786c545cd1bf519d47250322dBen Murdoch        }
9921939df44de1705786c545cd1bf519d47250322dBen Murdoch        parent = parent->parentNode();
10021939df44de1705786c545cd1bf519d47250322dBen Murdoch    }
10121939df44de1705786c545cd1bf519d47250322dBen Murdoch
10221939df44de1705786c545cd1bf519d47250322dBen Murdoch    // If we aren't an instance in a <use> or the <use> title was not found, then find the first
10321939df44de1705786c545cd1bf519d47250322dBen Murdoch    // <title> child of this element.
10421939df44de1705786c545cd1bf519d47250322dBen Murdoch    Element* titleElement = firstElementChild();
10521939df44de1705786c545cd1bf519d47250322dBen Murdoch    for (; titleElement; titleElement = titleElement->nextElementSibling()) {
10621939df44de1705786c545cd1bf519d47250322dBen Murdoch        if (titleElement->hasTagName(SVGNames::titleTag) && titleElement->isSVGElement())
10721939df44de1705786c545cd1bf519d47250322dBen Murdoch            break;
10821939df44de1705786c545cd1bf519d47250322dBen Murdoch    }
10921939df44de1705786c545cd1bf519d47250322dBen Murdoch
11021939df44de1705786c545cd1bf519d47250322dBen Murdoch    // If a title child was found, return the text contents.
11121939df44de1705786c545cd1bf519d47250322dBen Murdoch    if (titleElement)
11221939df44de1705786c545cd1bf519d47250322dBen Murdoch        return titleElement->innerText();
11321939df44de1705786c545cd1bf519d47250322dBen Murdoch
11421939df44de1705786c545cd1bf519d47250322dBen Murdoch    // Otherwise return a null/empty string.
11521939df44de1705786c545cd1bf519d47250322dBen Murdoch    return String();
1168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectbool SVGStyledElement::rendererIsNeeded(RenderStyle* style)
1198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
1208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // http://www.w3.org/TR/SVG/extend.html#PrivateData
1218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // Prevent anything other than SVG renderers from appearing in our render tree
1228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // Spec: SVG allows inclusion of elements from foreign namespaces anywhere
1238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // with the SVG content. In general, the SVG user agent will include the unknown
1248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // elements in the DOM but will otherwise ignore unknown elements.
1258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (!parentNode() || parentNode()->isSVGElement())
1268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return StyledElement::rendererIsNeeded(style);
1278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return false;
1298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectint SVGStyledElement::cssPropertyIdForSVGAttributeName(const QualifiedName& attrName)
1328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
1338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (!attrName.namespaceURI().isNull())
1348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return 0;
1358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    static HashMap<AtomicStringImpl*, int>* propertyNameToIdMap = 0;
1378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (!propertyNameToIdMap) {
1388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        propertyNameToIdMap = new HashMap<AtomicStringImpl*, int>;
1398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        // This is a list of all base CSS and SVG CSS properties which are exposed as SVG XML attributes
1408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, alignment_baselineAttr);
1418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, baseline_shiftAttr);
1428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, clipAttr);
1438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, clip_pathAttr);
1448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, clip_ruleAttr);
145d0825bca7fe65beaee391d30da42e937db621564Steve Block        mapAttributeToCSSProperty(propertyNameToIdMap, SVGNames::colorAttr);
1468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, color_interpolationAttr);
1478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, color_interpolation_filtersAttr);
1488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, color_profileAttr);
1498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, color_renderingAttr);
1508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, cursorAttr);
151d0825bca7fe65beaee391d30da42e937db621564Steve Block        mapAttributeToCSSProperty(propertyNameToIdMap, SVGNames::directionAttr);
1528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, displayAttr);
1538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, dominant_baselineAttr);
1548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, enable_backgroundAttr);
1558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, fillAttr);
1568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, fill_opacityAttr);
1578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, fill_ruleAttr);
1588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, filterAttr);
1598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, flood_colorAttr);
1608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, flood_opacityAttr);
1618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, font_familyAttr);
1628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, font_sizeAttr);
1638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, font_stretchAttr);
1648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, font_styleAttr);
1658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, font_variantAttr);
1668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, font_weightAttr);
1678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, glyph_orientation_horizontalAttr);
1688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, glyph_orientation_verticalAttr);
1698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, image_renderingAttr);
1708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, kerningAttr);
1718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, letter_spacingAttr);
1728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, lighting_colorAttr);
1738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, marker_endAttr);
1748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, marker_midAttr);
1758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, marker_startAttr);
1768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, maskAttr);
1778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, opacityAttr);
1788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, overflowAttr);
1798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, pointer_eventsAttr);
1808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, shape_renderingAttr);
1818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, stop_colorAttr);
1828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, stop_opacityAttr);
1838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, strokeAttr);
1848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, stroke_dasharrayAttr);
1858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, stroke_dashoffsetAttr);
1868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, stroke_linecapAttr);
1878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, stroke_linejoinAttr);
1888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, stroke_miterlimitAttr);
1898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, stroke_opacityAttr);
1908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, stroke_widthAttr);
1918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, text_anchorAttr);
1928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, text_decorationAttr);
1938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, text_renderingAttr);
1948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, unicode_bidiAttr);
195545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch        mapAttributeToCSSProperty(propertyNameToIdMap, vector_effectAttr);
1968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, visibilityAttr);
1978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, word_spacingAttr);
1988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        mapAttributeToCSSProperty(propertyNameToIdMap, writing_modeAttr);
1998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
2008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return propertyNameToIdMap->get(attrName.localName().impl());
2028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
2038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
2042fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockstatic inline AttributeToPropertyTypeMap& cssPropertyToTypeMap()
2052fc2651226baac27029e38c9d6ef883fa32084dbSteve Block{
2062fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_cssPropertyMap, ());
2072fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
2082fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    if (!s_cssPropertyMap.isEmpty())
2092fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        return s_cssPropertyMap;
2102fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
2112fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    // Fill the map for the first use.
2122fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(alignment_baselineAttr, AnimatedString);
2132fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(baseline_shiftAttr, AnimatedString);
2142fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(clipAttr, AnimatedRect);
2152fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(clip_pathAttr, AnimatedString);
2162fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(clip_ruleAttr, AnimatedString);
2172fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(SVGNames::colorAttr, AnimatedColor);
2182fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(color_interpolationAttr, AnimatedString);
2192fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(color_interpolation_filtersAttr, AnimatedString);
2202fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(color_profileAttr, AnimatedString);
2212fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(color_renderingAttr, AnimatedString);
2222fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(cursorAttr, AnimatedString);
2232fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(displayAttr, AnimatedString);
2242fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(dominant_baselineAttr, AnimatedString);
2252fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(fillAttr, AnimatedColor);
2262fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(fill_opacityAttr, AnimatedNumber);
2272fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(fill_ruleAttr, AnimatedString);
2282fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(filterAttr, AnimatedString);
2292fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(flood_colorAttr, AnimatedColor);
2302fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(flood_opacityAttr, AnimatedNumber);
2312fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(font_familyAttr, AnimatedString);
2322fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(font_sizeAttr, AnimatedLength);
2332fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(font_stretchAttr, AnimatedString);
2342fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(font_styleAttr, AnimatedString);
2352fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(font_variantAttr, AnimatedString);
2362fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(font_weightAttr, AnimatedString);
2372fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(image_renderingAttr, AnimatedString);
2382fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(kerningAttr, AnimatedLength);
2392fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(letter_spacingAttr, AnimatedLength);
2402fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(lighting_colorAttr, AnimatedColor);
2412fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(marker_endAttr, AnimatedString);
2422fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(marker_midAttr, AnimatedString);
2432fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(marker_startAttr, AnimatedString);
2442fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(maskAttr, AnimatedString);
2452fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(opacityAttr, AnimatedNumber);
2462fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(overflowAttr, AnimatedString);
2472fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(pointer_eventsAttr, AnimatedString);
2482fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(shape_renderingAttr, AnimatedString);
2492fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(stop_colorAttr, AnimatedColor);
2502fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(stop_opacityAttr, AnimatedNumber);
2512fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(strokeAttr, AnimatedColor);
2522fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(stroke_dasharrayAttr, AnimatedLengthList);
2532fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(stroke_dashoffsetAttr, AnimatedLength);
2542fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(stroke_linecapAttr, AnimatedString);
2552fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(stroke_linejoinAttr, AnimatedString);
2562fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(stroke_miterlimitAttr, AnimatedNumber);
2572fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(stroke_opacityAttr, AnimatedNumber);
2582fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(stroke_widthAttr, AnimatedLength);
2592fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(text_anchorAttr, AnimatedString);
2602fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(text_decorationAttr, AnimatedString);
2612fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(text_renderingAttr, AnimatedString);
2622fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(vector_effectAttr, AnimatedString);
2632fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(visibilityAttr, AnimatedString);
2642fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    s_cssPropertyMap.set(word_spacingAttr, AnimatedLength);
2652fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    return s_cssPropertyMap;
2662fc2651226baac27029e38c9d6ef883fa32084dbSteve Block}
2672fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
2682fc2651226baac27029e38c9d6ef883fa32084dbSteve BlockAnimatedAttributeType SVGStyledElement::animatedPropertyTypeForCSSProperty(const QualifiedName& attrName)
2692fc2651226baac27029e38c9d6ef883fa32084dbSteve Block{
2702fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    AttributeToPropertyTypeMap& cssPropertyTypeMap = cssPropertyToTypeMap();
2712fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    if (cssPropertyTypeMap.contains(attrName))
2722fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        return cssPropertyTypeMap.get(attrName);
2732fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    return AnimatedUnknown;
2742fc2651226baac27029e38c9d6ef883fa32084dbSteve Block}
2752fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
27681bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdochbool SVGStyledElement::isAnimatableCSSProperty(const QualifiedName& attrName)
27781bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch{
27881bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch    return cssPropertyToTypeMap().contains(attrName);
27981bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch}
28081bc750723a18f21cd17d1b173cd2a4dda9cea6eBen Murdoch
2812fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockvoid SVGStyledElement::fillPassedAttributeToPropertyTypeMap(AttributeToPropertyTypeMap& attributeToPropertyTypeMap)
2822fc2651226baac27029e38c9d6ef883fa32084dbSteve Block{
2832fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    attributeToPropertyTypeMap.set(HTMLNames::classAttr, AnimatedString);
2842fc2651226baac27029e38c9d6ef883fa32084dbSteve Block}
2852fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
2868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectbool SVGStyledElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
2878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
2888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (SVGStyledElement::cssPropertyIdForSVGAttributeName(attrName) > 0) {
2898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        result = eSVG;
2908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return false;
2918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
2928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return SVGElement::mapToEntry(attrName, result);
2938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
2948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
295e78cbe89e6f337f2f1fe40315be88f742b547151Steve Blockvoid SVGStyledElement::parseMappedAttribute(Attribute* attr)
2968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
2978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    const QualifiedName& attrName = attr->name();
2988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // NOTE: Any subclass which overrides parseMappedAttribute for a property handled by
2998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // cssPropertyIdForSVGAttributeName will also have to override mapToEntry to disable the default eSVG mapping
3008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int propId = SVGStyledElement::cssPropertyIdForSVGAttributeName(attrName);
3018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (propId > 0) {
3028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        addCSSProperty(attr, propId, attr->value());
3035f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        setNeedsStyleRecalc();
3048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return;
3058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
3068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // SVG animation has currently requires special storage of values so we set
3088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // the className here.  svgAttributeChanged actually causes the resulting
3098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // style updates (instead of StyledElement::parseMappedAttribute). We don't
3108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // tell StyledElement about the change to avoid parsing the class list twice
3118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (attrName.matches(HTMLNames::classAttr))
312d0825bca7fe65beaee391d30da42e937db621564Steve Block        setClassNameBaseValue(attr->value());
3138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    else
3148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        // id is handled by StyledElement which SVGElement inherits from
3158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        SVGElement::parseMappedAttribute(attr);
3168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
3178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectbool SVGStyledElement::isKnownAttribute(const QualifiedName& attrName)
3198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
32006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    return isIdAttributeName(attrName);
3218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
3228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid SVGStyledElement::svgAttributeChanged(const QualifiedName& attrName)
3248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
3258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    SVGElement::svgAttributeChanged(attrName);
3268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (attrName.matches(HTMLNames::classAttr))
3288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        classAttributeChanged(className());
3298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
33021939df44de1705786c545cd1bf519d47250322dBen Murdoch    RenderObject* object = renderer();
33121939df44de1705786c545cd1bf519d47250322dBen Murdoch
332545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    if (isIdAttributeName(attrName)) {
333dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        // Notify resources about id changes, this is important as we cache resources by id in SVGDocumentExtensions
33421939df44de1705786c545cd1bf519d47250322dBen Murdoch        if (object && object->isSVGResourceContainer())
33521939df44de1705786c545cd1bf519d47250322dBen Murdoch            object->toRenderSVGResourceContainer()->idChanged();
336dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    }
337dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
3388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // Invalidate all SVGElementInstances associated with us
3398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    SVGElementInstance::invalidateAllInstancesOfElement(this);
3408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
3418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
342d0825bca7fe65beaee391d30da42e937db621564Steve Blockvoid SVGStyledElement::synchronizeProperty(const QualifiedName& attrName)
343d0825bca7fe65beaee391d30da42e937db621564Steve Block{
344d0825bca7fe65beaee391d30da42e937db621564Steve Block    SVGElement::synchronizeProperty(attrName);
345d0825bca7fe65beaee391d30da42e937db621564Steve Block
346d0825bca7fe65beaee391d30da42e937db621564Steve Block    if (attrName == anyQName() || attrName.matches(HTMLNames::classAttr))
347d0825bca7fe65beaee391d30da42e937db621564Steve Block        synchronizeClassName();
348d0825bca7fe65beaee391d30da42e937db621564Steve Block}
349d0825bca7fe65beaee391d30da42e937db621564Steve Block
350db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Blockvoid SVGStyledElement::attach()
3518a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block{
352db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block    SVGElement::attach();
353692e5dbf12901edacf14812a6fae25462920af42Steve Block
354db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block    if (RenderObject* object = renderer())
355db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block        object->updateFromElement();
3568a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block}
3578a0914b749bbe7da7768e07a7db5c6d4bb09472bSteve Block
358ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Blockvoid SVGStyledElement::insertedIntoDocument()
359ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block{
360ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    SVGElement::insertedIntoDocument();
361ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    updateRelativeLengthsInformation();
362ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block}
363ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
364ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Blockvoid SVGStyledElement::removedFromDocument()
365ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block{
366ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    updateRelativeLengthsInformation(false, this);
367ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    SVGElement::removedFromDocument();
368ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block}
369ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
3708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid SVGStyledElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
3718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
3728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
3738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // Invalidate all SVGElementInstances associated with us
37521939df44de1705786c545cd1bf519d47250322dBen Murdoch    if (!changedByParser)
37621939df44de1705786c545cd1bf519d47250322dBen Murdoch        SVGElementInstance::invalidateAllInstancesOfElement(this);
3778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
3788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectPassRefPtr<RenderStyle> SVGStyledElement::resolveStyle(RenderStyle* parentStyle)
3808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
3818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (renderer())
3828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return renderer()->style();
3838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return document()->styleSelector()->styleForElement(this, parentStyle);
3848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
3858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
3868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectPassRefPtr<CSSValue> SVGStyledElement::getPresentationAttribute(const String& name)
3878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
388e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    if (!attributeMap())
3895f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        return 0;
3905f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
391cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block    QualifiedName attributeName(nullAtom, name, nullAtom);
392e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    Attribute* attr = attributeMap()->getAttributeItem(attributeName);
3938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    if (!attr || !attr->isMappedAttribute() || !attr->style())
3948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return 0;
3958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
396e78cbe89e6f337f2f1fe40315be88f742b547151Steve Block    Attribute* cssSVGAttr = attr;
397cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block    // This function returns a pointer to a CSSValue which can be mutated from JavaScript.
398cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block    // If the associated MappedAttribute uses the same CSSMappedAttributeDeclaration
399cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block    // as StyledElement's mappedAttributeDecls cache, create a new CSSMappedAttributeDeclaration
400cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block    // before returning so that any modifications to the CSSValue will not affect other attributes.
401cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block    MappedAttributeEntry entry;
402cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block    mapToEntry(attributeName, entry);
403cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block    if (getMappedAttributeDecl(entry, cssSVGAttr) == cssSVGAttr->decl()) {
4048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        cssSVGAttr->setDecl(0);
4058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        int propId = SVGStyledElement::cssPropertyIdForSVGAttributeName(cssSVGAttr->name());
4068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        addCSSProperty(cssSVGAttr, propId, cssSVGAttr->value());
4078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
4088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return cssSVGAttr->style()->getPropertyCSSValue(name);
4098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
4108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
411d0825bca7fe65beaee391d30da42e937db621564Steve Blockbool SVGStyledElement::instanceUpdatesBlocked() const
4128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
413d0825bca7fe65beaee391d30da42e937db621564Steve Block    return hasRareSVGData() && rareSVGData()->instanceUpdatesBlocked();
4148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
415d0825bca7fe65beaee391d30da42e937db621564Steve Block
416d0825bca7fe65beaee391d30da42e937db621564Steve Blockvoid SVGStyledElement::setInstanceUpdatesBlocked(bool value)
417d0825bca7fe65beaee391d30da42e937db621564Steve Block{
418d0825bca7fe65beaee391d30da42e937db621564Steve Block    if (hasRareSVGData())
419d0825bca7fe65beaee391d30da42e937db621564Steve Block        rareSVGData()->setInstanceUpdatesBlocked(value);
420d0825bca7fe65beaee391d30da42e937db621564Steve Block}
421d0825bca7fe65beaee391d30da42e937db621564Steve Block
422dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve BlockAffineTransform SVGStyledElement::localCoordinateSpaceTransform(SVGLocatable::CTMScope) const
423dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block{
424dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    // To be overriden by SVGStyledLocatableElement/SVGStyledTransformableElement (or as special case SVGTextElement)
425dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    ASSERT_NOT_REACHED();
426dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block    return AffineTransform();
427dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block}
428dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
429e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarkevoid SVGStyledElement::updateRelativeLengthsInformation(bool hasRelativeLengths, SVGStyledElement* element)
430ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block{
431e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    // If we're not yet in a document, this function will be called again from insertedIntoDocument(). Do nothing now.
432e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    if (!inDocument())
433e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        return;
434e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
435e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    // An element wants to notify us that its own relative lengths state changed.
436e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    // Register it in the relative length map, and register us in the parent relative length map.
437e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    // Register the parent in the grandparents map, etc. Repeat procedure until the root of the SVG tree.
438e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
439e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    if (hasRelativeLengths)
440e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        m_elementsWithRelativeLengths.add(element);
441e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    else {
442e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        if (!m_elementsWithRelativeLengths.contains(element)) {
443e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke            // We were never registered. Do nothing.
444e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke            return;
445e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        }
446e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
447e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        m_elementsWithRelativeLengths.remove(element);
448e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    }
449e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
450e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    // Find first styled parent node, and notify it that we've changed our relative length state.
4516b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner    ContainerNode* node = parentNode();
452e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    while (node) {
453e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        if (!node->isSVGElement())
454e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke            break;
455e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
456e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        SVGElement* element = static_cast<SVGElement*>(node);
457e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        if (!element->isStyled()) {
4586b70adc33054f8aee8c54d0f460458a9df11b8a5Russell Brenner            node = node->parentNode();
459e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke            continue;
460e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        }
461e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
462e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        // Register us in the parent element map.
463e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        static_cast<SVGStyledElement*>(element)->updateRelativeLengthsInformation(hasRelativeLengths, this);
464e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke        break;
465e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke    }
466ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block}
467ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
4688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
4698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
4708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif // ENABLE(SVG)
471