blob: e6b0df2021fc10fffa7babd1fd2734874a1ab766 [file] [log] [blame]
eseidel40eb1b92006-03-25 22:20:36 +00001/*
eseidel40eb1b92006-03-25 22:20:36 +00002 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org)
fpizlo@apple.com197cd322018-03-17 06:11:00 +00006 * Copyright (C) 2003-2018 Apple Inc. All rights reserved.
eseidel40eb1b92006-03-25 22:20:36 +00007 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
ddkilzerc8eccec2007-09-26 02:29:57 +000020 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
eseidel40eb1b92006-03-25 22:20:36 +000022 *
23 */
24
commit-queue@webkit.orgd862d772016-10-31 22:07:53 +000025#pragma once
eseidel40eb1b92006-03-25 22:20:36 +000026
akling@apple.com179f7df2013-02-25 15:49:25 +000027#include "CSSPrimitiveValue.h"
28#include "CSSPropertyNames.h"
alexis@webkit.org71873a02013-06-19 22:07:23 +000029#include "CSSValueKeywords.h"
darina51de912007-04-29 20:32:51 +000030#include "Element.h"
eseidel40eb1b92006-03-25 22:20:36 +000031
32namespace WebCore {
33
weinig@apple.comc3608932010-05-19 17:48:06 +000034class Attribute;
antti@apple.come5428c52013-11-28 20:53:22 +000035class MutableStyleProperties;
akling@apple.com179f7df2013-02-25 15:49:25 +000036class PropertySetCSSStyleDeclaration;
antti@apple.come5428c52013-11-28 20:53:22 +000037class StyleProperties;
justin_michaud@apple.com51c20fe2018-12-18 18:51:05 +000038class StylePropertyMap;
akling@apple.com179f7df2013-02-25 15:49:25 +000039
darina51de912007-04-29 20:32:51 +000040class StyledElement : public Element {
fpizlo@apple.com197cd322018-03-17 06:11:00 +000041 WTF_MAKE_ISO_ALLOCATED(StyledElement);
eseidel40eb1b92006-03-25 22:20:36 +000042public:
kling@webkit.org1d8f6e12012-06-29 17:20:19 +000043 virtual ~StyledElement();
eseidel40eb1b92006-03-25 22:20:36 +000044
antti@apple.com0f60f382016-03-08 18:11:17 +000045 virtual const StyleProperties* additionalPresentationAttributeStyle() const { return nullptr; }
eseidel40eb1b92006-03-25 22:20:36 +000046 void invalidateStyleAttribute();
darin@apple.comcf9dd0f2009-08-23 06:55:57 +000047
hs85.jeong@samsung.coma08a0ad2015-11-03 18:24:34 +000048 const StyleProperties* inlineStyle() const { return elementData() ? elementData()->m_inlineStyle.get() : nullptr; }
antti@apple.com85635f02012-02-16 07:39:17 +000049
alexis@webkit.org71873a02013-06-19 22:07:23 +000050 bool setInlineStyleProperty(CSSPropertyID, CSSValueID identifier, bool important = false);
51 bool setInlineStyleProperty(CSSPropertyID, CSSPropertyID identifier, bool important = false);
simon.fraser@apple.com094a8742019-11-13 04:41:17 +000052 WEBCORE_EXPORT bool setInlineStyleProperty(CSSPropertyID, double value, CSSUnitType, bool important = false);
achristensen@apple.com985685e2014-08-22 04:21:18 +000053 WEBCORE_EXPORT bool setInlineStyleProperty(CSSPropertyID, const String& value, bool important = false);
alexis.menard@openbossa.org51f64bf2012-04-03 14:18:19 +000054 bool removeInlineStyleProperty(CSSPropertyID);
tasak@google.com5d471852012-11-06 11:33:07 +000055 void removeAllInlineStyleProperties();
akling@apple.com82cfd352013-02-16 23:34:22 +000056
benjamin@webkit.org99a1aad2014-02-11 02:41:00 +000057 static void synchronizeStyleAttributeInternal(StyledElement*);
58 void synchronizeStyleAttributeInternal() const { StyledElement::synchronizeStyleAttributeInternal(const_cast<StyledElement*>(this)); }
antti@apple.com85635f02012-02-16 07:39:17 +000059
cdumez@apple.comea20d742017-05-08 16:50:46 +000060 WEBCORE_EXPORT CSSStyleDeclaration& cssomStyle();
justin_michaud@apple.com51c20fe2018-12-18 18:51:05 +000061#if ENABLE(CSS_TYPED_OM)
62 StylePropertyMap& ensureAttributeStyleMap();
63#endif
kling@webkit.org557087f2011-12-01 22:22:41 +000064
antti@apple.com0f60f382016-03-08 18:11:17 +000065 const StyleProperties* presentationAttributeStyle() const;
darin@apple.com0ce67df2019-06-17 01:48:13 +000066 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomString&, MutableStyleProperties&) { }
kling@webkit.org737834a2012-03-12 18:51:32 +000067
darin@apple.comcf9dd0f2009-08-23 06:55:57 +000068protected:
weinig@apple.comdedf67e2013-09-15 05:23:01 +000069 StyledElement(const QualifiedName& name, Document& document, ConstructionType type)
weinig@apple.comc4616822013-09-15 17:10:27 +000070 : Element(name, document, type)
akling@apple.com5032c672012-11-18 20:25:01 +000071 {
72 }
darin@apple.comcf9dd0f2009-08-23 06:55:57 +000073
darin@apple.com0ce67df2019-06-17 01:48:13 +000074 void attributeChanged(const QualifiedName&, const AtomString& oldValue, const AtomString& newValue, AttributeModificationReason = ModifiedDirectly) override;
bdakine2a4f1a2006-12-20 00:32:37 +000075
kling@webkit.org44bc0dd2012-02-28 22:21:02 +000076 virtual bool isPresentationAttribute(const QualifiedName&) const { return false; }
kling@webkit.org8b0e8432012-02-11 19:29:49 +000077
antti@apple.come5428c52013-11-28 20:53:22 +000078 void addPropertyToPresentationAttributeStyle(MutableStyleProperties&, CSSPropertyID, CSSValueID identifier);
simon.fraser@apple.com094a8742019-11-13 04:41:17 +000079 void addPropertyToPresentationAttributeStyle(MutableStyleProperties&, CSSPropertyID, double value, CSSUnitType);
antti@apple.come5428c52013-11-28 20:53:22 +000080 void addPropertyToPresentationAttributeStyle(MutableStyleProperties&, CSSPropertyID, const String& value);
antti@apple.com708a2782012-02-21 13:49:15 +000081
darin@apple.com11ff47c2016-03-04 16:47:55 +000082 void addSubresourceAttributeURLs(ListHashSet<URL>&) const override;
ddkilzer@apple.come9a55042008-12-23 00:00:14 +000083
darin@apple.comcf9dd0f2009-08-23 06:55:57 +000084private:
darin@apple.com0ce67df2019-06-17 01:48:13 +000085 void styleAttributeChanged(const AtomString& newStyleString, AttributeModificationReason);
akling@apple.com191b9bc2012-11-17 01:34:36 +000086
antti@apple.com85635f02012-02-16 07:39:17 +000087 void inlineStyleChanged();
kling@webkit.orgd3ce8af2012-11-14 05:39:17 +000088 PropertySetCSSStyleDeclaration* inlineStyleCSSOMWrapper();
darin@apple.com0ce67df2019-06-17 01:48:13 +000089 void setInlineStyleFromString(const AtomString&);
antti@apple.come5428c52013-11-28 20:53:22 +000090 MutableStyleProperties& ensureMutableInlineStyle();
leviw@chromium.org8bf28cc2012-01-29 23:41:33 +000091
kling@webkit.org569556d2012-11-12 23:52:12 +000092 void rebuildPresentationAttributeStyle();
eseidel40eb1b92006-03-25 22:20:36 +000093};
94
antti@apple.com0f60f382016-03-08 18:11:17 +000095inline const StyleProperties* StyledElement::presentationAttributeStyle() const
kling@webkit.org8b0e8432012-02-11 19:29:49 +000096{
akling@apple.com72dde2a32013-02-13 21:48:40 +000097 if (!elementData())
cdumez@apple.comebb5c272014-09-29 17:35:28 +000098 return nullptr;
benjamin@webkit.org23ab9cf2014-01-18 22:17:09 +000099 if (elementData()->presentationAttributeStyleIsDirty())
antti@apple.com0f60f382016-03-08 18:11:17 +0000100 const_cast<StyledElement&>(*this).rebuildPresentationAttributeStyle();
akling@apple.com72dde2a32013-02-13 21:48:40 +0000101 return elementData()->presentationAttributeStyle();
kling@webkit.org8b0e8432012-02-11 19:29:49 +0000102}
103
cdumez@apple.com3e58f0f2014-09-30 21:32:55 +0000104} // namespace WebCore
weinig@apple.com65ea5f32013-10-06 19:18:54 +0000105
cdumez@apple.com3e58f0f2014-09-30 21:32:55 +0000106SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::StyledElement)
107 static bool isType(const WebCore::Node& node) { return node.isStyledElement(); }
108SPECIALIZE_TYPE_TRAITS_END()