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 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 "Element.h" 31 32namespace WebCore { 33 34class Attribute; 35class MutableStylePropertySet; 36class PropertySetCSSStyleDeclaration; 37class StylePropertySet; 38 39struct PresentationAttributeCacheKey; 40 41class StyledElement : public Element { 42public: 43 virtual ~StyledElement(); 44 45 virtual const StylePropertySet* additionalPresentationAttributeStyle() { return 0; } 46 void invalidateStyleAttribute(); 47 48 const StylePropertySet* inlineStyle() const { return elementData() ? elementData()->m_inlineStyle.get() : 0; } 49 50 bool setInlineStyleProperty(CSSPropertyID, int identifier, bool important = false); 51 bool setInlineStyleProperty(CSSPropertyID, double value, CSSPrimitiveValue::UnitTypes, bool important = false); 52 bool setInlineStyleProperty(CSSPropertyID, const String& value, bool important = false); 53 bool removeInlineStyleProperty(CSSPropertyID); 54 void removeAllInlineStyleProperties(); 55 56 void synchronizeStyleAttributeInternal() const; 57 58 virtual CSSStyleDeclaration* style() OVERRIDE FINAL; 59 60 const StylePropertySet* presentationAttributeStyle(); 61 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) { } 62 63protected: 64 StyledElement(const QualifiedName& name, Document* document, ConstructionType type) 65 : Element(name, document, type) 66 { 67 } 68 69 virtual void attributeChanged(const QualifiedName&, const AtomicString&, AttributeModificationReason = ModifiedDirectly) OVERRIDE; 70 71 virtual bool isPresentationAttribute(const QualifiedName&) const { return false; } 72 73 void addPropertyToPresentationAttributeStyle(MutableStylePropertySet*, CSSPropertyID, int identifier); 74 void addPropertyToPresentationAttributeStyle(MutableStylePropertySet*, CSSPropertyID, double value, CSSPrimitiveValue::UnitTypes); 75 void addPropertyToPresentationAttributeStyle(MutableStylePropertySet*, CSSPropertyID, const String& value); 76 77 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; 78 79private: 80 void styleAttributeChanged(const AtomicString& newStyleString, AttributeModificationReason); 81 82 void inlineStyleChanged(); 83 PropertySetCSSStyleDeclaration* inlineStyleCSSOMWrapper(); 84 void setInlineStyleFromString(const AtomicString&); 85 MutableStylePropertySet* ensureMutableInlineStyle(); 86 87 void makePresentationAttributeCacheKey(PresentationAttributeCacheKey&) const; 88 void rebuildPresentationAttributeStyle(); 89}; 90 91inline void StyledElement::invalidateStyleAttribute() 92{ 93 ASSERT(elementData()); 94 elementData()->m_styleAttributeIsDirty = true; 95} 96 97inline const StylePropertySet* StyledElement::presentationAttributeStyle() 98{ 99 if (!elementData()) 100 return 0; 101 if (elementData()->m_presentationAttributeStyleIsDirty) 102 rebuildPresentationAttributeStyle(); 103 return elementData()->presentationAttributeStyle(); 104} 105 106} //namespace 107 108#endif 109