1/* 2 * 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) 6 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2014 Apple Inc. All rights reserved. 7 * 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 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 * 23 */ 24 25#ifndef StyledElement_h 26#define StyledElement_h 27 28#include "CSSPrimitiveValue.h" 29#include "CSSPropertyNames.h" 30#include "CSSValueKeywords.h" 31#include "Element.h" 32 33namespace WebCore { 34 35class Attribute; 36class MutableStyleProperties; 37class PropertySetCSSStyleDeclaration; 38class StyleProperties; 39 40struct PresentationAttributeCacheKey; 41 42class StyledElement : public Element { 43public: 44 virtual ~StyledElement(); 45 46 virtual const StyleProperties* additionalPresentationAttributeStyle() { return 0; } 47 void invalidateStyleAttribute(); 48 49 const StyleProperties* inlineStyle() const { return elementData() ? elementData()->m_inlineStyle.get() : 0; } 50 51 bool setInlineStyleProperty(CSSPropertyID, CSSValueID identifier, bool important = false); 52 bool setInlineStyleProperty(CSSPropertyID, CSSPropertyID identifier, bool important = false); 53 bool setInlineStyleProperty(CSSPropertyID, double value, CSSPrimitiveValue::UnitTypes, bool important = false); 54 bool setInlineStyleProperty(CSSPropertyID, const String& value, bool important = false); 55 bool removeInlineStyleProperty(CSSPropertyID); 56 void removeAllInlineStyleProperties(); 57 58 static void synchronizeStyleAttributeInternal(StyledElement*); 59 void synchronizeStyleAttributeInternal() const { StyledElement::synchronizeStyleAttributeInternal(const_cast<StyledElement*>(this)); } 60 61 virtual CSSStyleDeclaration* style() override final; 62 63 const StyleProperties* presentationAttributeStyle(); 64 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) { } 65 66protected: 67 StyledElement(const QualifiedName& name, Document& document, ConstructionType type) 68 : Element(name, document, type) 69 { 70 } 71 72 virtual void attributeChanged(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason = ModifiedDirectly) override; 73 74 virtual bool isPresentationAttribute(const QualifiedName&) const { return false; } 75 76 void addPropertyToPresentationAttributeStyle(MutableStyleProperties&, CSSPropertyID, CSSValueID identifier); 77 void addPropertyToPresentationAttributeStyle(MutableStyleProperties&, CSSPropertyID, double value, CSSPrimitiveValue::UnitTypes); 78 void addPropertyToPresentationAttributeStyle(MutableStyleProperties&, CSSPropertyID, const String& value); 79 80 virtual void addSubresourceAttributeURLs(ListHashSet<URL>&) const override; 81 82private: 83 void styleAttributeChanged(const AtomicString& newStyleString, AttributeModificationReason); 84 85 void inlineStyleChanged(); 86 PropertySetCSSStyleDeclaration* inlineStyleCSSOMWrapper(); 87 void setInlineStyleFromString(const AtomicString&); 88 MutableStyleProperties& ensureMutableInlineStyle(); 89 90 void makePresentationAttributeCacheKey(PresentationAttributeCacheKey&) const; 91 void rebuildPresentationAttributeStyle(); 92}; 93 94inline void StyledElement::invalidateStyleAttribute() 95{ 96 ASSERT(elementData()); 97 elementData()->setStyleAttributeIsDirty(true); 98} 99 100inline const StyleProperties* StyledElement::presentationAttributeStyle() 101{ 102 if (!elementData()) 103 return 0; 104 if (elementData()->presentationAttributeStyleIsDirty()) 105 rebuildPresentationAttributeStyle(); 106 return elementData()->presentationAttributeStyle(); 107} 108 109inline bool isStyledElement(const Node& node) { return node.isStyledElement(); } 110 111NODE_TYPE_CASTS(StyledElement) 112 113} //namespace 114 115#endif 116