| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 bool hasRawText() const { return !rawText.isEmpty(); } | 114 bool hasRawText() const { return !rawText.isEmpty(); } |
| 115 | 115 |
| 116 CSSPropertySourceData sourceData; | 116 CSSPropertySourceData sourceData; |
| 117 bool hasSource; | 117 bool hasSource; |
| 118 bool disabled; | 118 bool disabled; |
| 119 String rawText; | 119 String rawText; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 class InspectorStyle : public RefCounted<InspectorStyle> { | 122 class InspectorStyle : public RefCounted<InspectorStyle> { |
| 123 public: | 123 public: |
| 124 static PassRefPtr<InspectorStyle> create(const InspectorCSSId& styleId, CSSS
tyleDeclaration* style, InspectorStyleSheet* parentStyleSheet) | 124 static PassRefPtr<InspectorStyle> create(const InspectorCSSId& styleId, Pass
RefPtr<CSSStyleDeclaration> style, InspectorStyleSheet* parentStyleSheet); |
| 125 { | |
| 126 return adoptRef(new InspectorStyle(styleId, style, parentStyleSheet)); | |
| 127 } | |
| 128 | 125 |
| 129 InspectorStyle(const InspectorCSSId& styleId, CSSStyleDeclaration* style, In
spectorStyleSheet* parentStyleSheet) | 126 CSSStyleDeclaration* cssStyle() const { return m_style.get(); } |
| 130 : m_styleId(styleId) | |
| 131 , m_style(style) | |
| 132 , m_parentStyleSheet(parentStyleSheet) | |
| 133 { | |
| 134 ASSERT(style); | |
| 135 } | |
| 136 | |
| 137 CSSStyleDeclaration* cssStyle() const { return m_style; } | |
| 138 PassRefPtr<InspectorObject> buildObjectForStyle() const; | 127 PassRefPtr<InspectorObject> buildObjectForStyle() const; |
| 139 bool hasDisabledProperties() const { return !m_disabledProperties.isEmpty();
} | 128 bool hasDisabledProperties() const { return !m_disabledProperties.isEmpty();
} |
| 140 bool setPropertyText(unsigned index, const String& text, bool overwrite); | 129 bool setPropertyText(unsigned index, const String& text, bool overwrite); |
| 141 bool toggleProperty(unsigned index, bool disable); | 130 bool toggleProperty(unsigned index, bool disable); |
| 142 | 131 |
| 143 private: | 132 private: |
| 133 InspectorStyle(const InspectorCSSId& styleId, PassRefPtr<CSSStyleDeclaration
> style, InspectorStyleSheet* parentStyleSheet); |
| 134 |
| 144 static unsigned disabledIndexByOrdinal(unsigned ordinal, bool canUseSubseque
nt, Vector<InspectorStyleProperty>& allProperties); | 135 static unsigned disabledIndexByOrdinal(unsigned ordinal, bool canUseSubseque
nt, Vector<InspectorStyleProperty>& allProperties); |
| 145 | 136 |
| 146 bool styleText(String* result) const; | 137 bool styleText(String* result) const; |
| 147 bool disableProperty(unsigned indexToDisable, Vector<InspectorStyleProperty>
& allProperties); | 138 bool disableProperty(unsigned indexToDisable, Vector<InspectorStyleProperty>
& allProperties); |
| 148 bool enableProperty(unsigned indexToEnable, Vector<InspectorStyleProperty>&
allProperties); | 139 bool enableProperty(unsigned indexToEnable, Vector<InspectorStyleProperty>&
allProperties); |
| 149 bool populateAllProperties(Vector<InspectorStyleProperty>* result) const; | 140 bool populateAllProperties(Vector<InspectorStyleProperty>* result) const; |
| 150 void populateObjectWithStyleProperties(InspectorObject* result) const; | 141 void populateObjectWithStyleProperties(InspectorObject* result) const; |
| 151 void shiftDisabledProperties(unsigned fromIndex, long offset); | 142 void shiftDisabledProperties(unsigned fromIndex, long offset); |
| 152 bool replacePropertyInStyleText(const InspectorStyleProperty& property, cons
t String& newText); | 143 bool replacePropertyInStyleText(const InspectorStyleProperty& property, cons
t String& newText); |
| 153 String shorthandValue(const String& shorthandProperty) const; | 144 String shorthandValue(const String& shorthandProperty) const; |
| 154 String shorthandPriority(const String& shorthandProperty) const; | 145 String shorthandPriority(const String& shorthandProperty) const; |
| 155 Vector<String> longhandProperties(const String& shorthandProperty) const; | 146 Vector<String> longhandProperties(const String& shorthandProperty) const; |
| 156 | 147 |
| 157 InspectorCSSId m_styleId; | 148 InspectorCSSId m_styleId; |
| 158 CSSStyleDeclaration* m_style; | 149 RefPtr<CSSStyleDeclaration> m_style; |
| 159 InspectorStyleSheet* m_parentStyleSheet; | 150 InspectorStyleSheet* m_parentStyleSheet; |
| 160 Vector<InspectorStyleProperty> m_disabledProperties; | 151 Vector<InspectorStyleProperty> m_disabledProperties; |
| 161 }; | 152 }; |
| 162 | 153 |
| 163 class InspectorStyleSheet : public RefCounted<InspectorStyleSheet> { | 154 class InspectorStyleSheet : public RefCounted<InspectorStyleSheet> { |
| 164 public: | 155 public: |
| 165 typedef HashMap<CSSStyleDeclaration*, RefPtr<InspectorStyle> > InspectorStyl
eMap; | 156 typedef HashMap<CSSStyleDeclaration*, RefPtr<InspectorStyle> > InspectorStyl
eMap; |
| 166 static PassRefPtr<InspectorStyleSheet> create(const String& id, CSSStyleShee
t* pageStyleSheet, const String& origin, const String& documentURL) | 157 static PassRefPtr<InspectorStyleSheet> create(const String& id, PassRefPtr<C
SSStyleSheet> pageStyleSheet, const String& origin, const String& documentURL); |
| 167 { | |
| 168 return adoptRef(new InspectorStyleSheet(id, pageStyleSheet, origin, docu
mentURL)); | |
| 169 } | |
| 170 | 158 |
| 171 InspectorStyleSheet(const String& id, CSSStyleSheet* pageStyleSheet, const S
tring& origin, const String& documentURL); | |
| 172 virtual ~InspectorStyleSheet(); | 159 virtual ~InspectorStyleSheet(); |
| 173 | 160 |
| 174 String id() const { return m_id; } | 161 String id() const { return m_id; } |
| 175 String finalURL() const; | 162 String finalURL() const; |
| 176 CSSStyleSheet* pageStyleSheet() const { return m_pageStyleSheet; } | 163 CSSStyleSheet* pageStyleSheet() const { return m_pageStyleSheet.get(); } |
| 177 void reparseStyleSheet(const String&); | 164 void reparseStyleSheet(const String&); |
| 178 bool setText(const String&); | 165 bool setText(const String&); |
| 179 bool setRuleSelector(const InspectorCSSId&, const String& selector); | 166 bool setRuleSelector(const InspectorCSSId&, const String& selector); |
| 180 CSSStyleRule* addRule(const String& selector); | 167 CSSStyleRule* addRule(const String& selector); |
| 181 CSSStyleRule* ruleForId(const InspectorCSSId&) const; | 168 CSSStyleRule* ruleForId(const InspectorCSSId&) const; |
| 182 PassRefPtr<InspectorObject> buildObjectForStyleSheet(); | 169 PassRefPtr<InspectorObject> buildObjectForStyleSheet(); |
| 183 PassRefPtr<InspectorObject> buildObjectForRule(CSSStyleRule*); | 170 PassRefPtr<InspectorObject> buildObjectForRule(CSSStyleRule*); |
| 184 PassRefPtr<InspectorObject> buildObjectForStyle(CSSStyleDeclaration*); | 171 PassRefPtr<InspectorObject> buildObjectForStyle(CSSStyleDeclaration*); |
| 185 bool setPropertyText(const InspectorCSSId&, unsigned propertyIndex, const St
ring& text, bool overwrite); | 172 bool setPropertyText(const InspectorCSSId&, unsigned propertyIndex, const St
ring& text, bool overwrite); |
| 186 bool toggleProperty(const InspectorCSSId&, unsigned propertyIndex, bool disa
ble); | 173 bool toggleProperty(const InspectorCSSId&, unsigned propertyIndex, bool disa
ble); |
| 187 | 174 |
| 188 virtual bool text(String* result) const; | 175 virtual bool text(String* result) const; |
| 189 virtual CSSStyleDeclaration* styleForId(const InspectorCSSId&) const; | 176 virtual CSSStyleDeclaration* styleForId(const InspectorCSSId&) const; |
| 190 | 177 |
| 191 protected: | 178 protected: |
| 179 InspectorStyleSheet(const String& id, PassRefPtr<CSSStyleSheet> pageStyleShe
et, const String& origin, const String& documentURL); |
| 180 |
| 192 bool canBind() const { return m_origin != "userAgent" && m_origin != "user";
} | 181 bool canBind() const { return m_origin != "userAgent" && m_origin != "user";
} |
| 193 InspectorCSSId ruleOrStyleId(CSSStyleDeclaration* style) const; | 182 InspectorCSSId ruleOrStyleId(CSSStyleDeclaration* style) const; |
| 194 virtual Document* ownerDocument() const; | 183 virtual Document* ownerDocument() const; |
| 195 virtual RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* sty
le) const; | 184 virtual RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* sty
le) const; |
| 196 virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const; | 185 virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const; |
| 197 virtual bool ensureParsedDataReady(); | 186 virtual bool ensureParsedDataReady(); |
| 198 virtual PassRefPtr<InspectorStyle> inspectorStyleForId(const InspectorCSSId&
); | 187 virtual PassRefPtr<InspectorStyle> inspectorStyleForId(const InspectorCSSId&
); |
| 199 virtual void rememberInspectorStyle(RefPtr<InspectorStyle> inspectorStyle); | 188 virtual void rememberInspectorStyle(RefPtr<InspectorStyle> inspectorStyle); |
| 200 virtual void forgetInspectorStyle(CSSStyleDeclaration* style); | 189 virtual void forgetInspectorStyle(CSSStyleDeclaration* style); |
| 201 | 190 |
| 202 // Also accessed by friend class InspectorStyle. | 191 // Also accessed by friend class InspectorStyle. |
| 203 virtual bool setStyleText(CSSStyleDeclaration*, const String&); | 192 virtual bool setStyleText(CSSStyleDeclaration*, const String&); |
| 204 | 193 |
| 205 private: | 194 private: |
| 206 static void fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const Str
ing& styleSheetText); | 195 static void fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData, const Str
ing& styleSheetText); |
| 207 static void collectFlatRules(PassRefPtr<CSSRuleList>, Vector<CSSStyleRule*>*
result); | 196 static void collectFlatRules(PassRefPtr<CSSRuleList>, Vector<CSSStyleRule*>*
result); |
| 208 bool ensureText() const; | 197 bool ensureText() const; |
| 209 bool ensureSourceData(); | 198 bool ensureSourceData(); |
| 210 void ensureFlatRules() const; | 199 void ensureFlatRules() const; |
| 211 bool styleSheetTextWithChangedStyle(CSSStyleDeclaration*, const String& newS
tyleText, String* result); | 200 bool styleSheetTextWithChangedStyle(CSSStyleDeclaration*, const String& newS
tyleText, String* result); |
| 212 InspectorCSSId ruleId(CSSStyleRule* rule) const; | 201 InspectorCSSId ruleId(CSSStyleRule* rule) const; |
| 213 InspectorCSSId styleId(CSSStyleDeclaration* style) const { return ruleOrStyl
eId(style); } | 202 InspectorCSSId styleId(CSSStyleDeclaration* style) const { return ruleOrStyl
eId(style); } |
| 214 void revalidateStyle(CSSStyleDeclaration*); | 203 void revalidateStyle(CSSStyleDeclaration*); |
| 215 bool originalStyleSheetText(String* result) const; | 204 bool originalStyleSheetText(String* result) const; |
| 216 bool resourceStyleSheetText(String* result) const; | 205 bool resourceStyleSheetText(String* result) const; |
| 217 bool inlineStyleSheetText(String* result) const; | 206 bool inlineStyleSheetText(String* result) const; |
| 218 PassRefPtr<InspectorArray> buildArrayForRuleList(CSSRuleList*); | 207 PassRefPtr<InspectorArray> buildArrayForRuleList(CSSRuleList*); |
| 219 | 208 |
| 220 String m_id; | 209 String m_id; |
| 221 CSSStyleSheet* m_pageStyleSheet; | 210 RefPtr<CSSStyleSheet> m_pageStyleSheet; |
| 222 String m_origin; | 211 String m_origin; |
| 223 String m_documentURL; | 212 String m_documentURL; |
| 224 bool m_isRevalidating; | 213 bool m_isRevalidating; |
| 225 ParsedStyleSheet* m_parsedStyleSheet; | 214 ParsedStyleSheet* m_parsedStyleSheet; |
| 226 InspectorStyleMap m_inspectorStyles; | 215 InspectorStyleMap m_inspectorStyles; |
| 227 mutable Vector<CSSStyleRule*> m_flatRules; | 216 mutable Vector<CSSStyleRule*> m_flatRules; |
| 228 | 217 |
| 229 friend class InspectorStyle; | 218 friend class InspectorStyle; |
| 230 }; | 219 }; |
| 231 | 220 |
| 232 class InspectorStyleSheetForInlineStyle : public InspectorStyleSheet { | 221 class InspectorStyleSheetForInlineStyle : public InspectorStyleSheet { |
| 233 public: | 222 public: |
| 234 static PassRefPtr<InspectorStyleSheetForInlineStyle> create(const String& id
, Element* element, const String& origin) | 223 static PassRefPtr<InspectorStyleSheetForInlineStyle> create(const String& id
, PassRefPtr<Element> element, const String& origin); |
| 235 { | |
| 236 return adoptRef(new InspectorStyleSheetForInlineStyle(id, element, origi
n)); | |
| 237 } | |
| 238 | 224 |
| 239 InspectorStyleSheetForInlineStyle(const String& id, Element* element, const
String& origin); | |
| 240 virtual bool text(String* result) const; | 225 virtual bool text(String* result) const; |
| 241 virtual CSSStyleDeclaration* styleForId(const InspectorCSSId& id) const { AS
SERT_UNUSED(id, !id.ordinal()); return inlineStyle(); } | 226 virtual CSSStyleDeclaration* styleForId(const InspectorCSSId& id) const { AS
SERT_UNUSED(id, !id.ordinal()); return inlineStyle(); } |
| 242 | 227 |
| 243 protected: | 228 protected: |
| 229 InspectorStyleSheetForInlineStyle(const String& id, PassRefPtr<Element> elem
ent, const String& origin); |
| 230 |
| 244 virtual Document* ownerDocument() const; | 231 virtual Document* ownerDocument() const; |
| 245 virtual RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* sty
le) const { ASSERT_UNUSED(style, style == inlineStyle()); return m_ruleSourceDat
a; } | 232 virtual RefPtr<CSSRuleSourceData> ruleSourceDataFor(CSSStyleDeclaration* sty
le) const { ASSERT_UNUSED(style, style == inlineStyle()); return m_ruleSourceDat
a; } |
| 246 virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const { return 0; } | 233 virtual unsigned ruleIndexByStyle(CSSStyleDeclaration*) const { return 0; } |
| 247 virtual bool ensureParsedDataReady(); | 234 virtual bool ensureParsedDataReady(); |
| 248 virtual PassRefPtr<InspectorStyle> inspectorStyleForId(const InspectorCSSId&
); | 235 virtual PassRefPtr<InspectorStyle> inspectorStyleForId(const InspectorCSSId&
); |
| 249 virtual void rememberInspectorStyle(RefPtr<InspectorStyle>) { } | 236 virtual void rememberInspectorStyle(RefPtr<InspectorStyle>) { } |
| 250 virtual void forgetInspectorStyle(CSSStyleDeclaration*) { } | 237 virtual void forgetInspectorStyle(CSSStyleDeclaration*) { } |
| 251 | 238 |
| 252 // Also accessed by friend class InspectorStyle. | 239 // Also accessed by friend class InspectorStyle. |
| 253 virtual bool setStyleText(CSSStyleDeclaration*, const String&); | 240 virtual bool setStyleText(CSSStyleDeclaration*, const String&); |
| 254 | 241 |
| 255 private: | 242 private: |
| 256 CSSStyleDeclaration* inlineStyle() const; | 243 CSSStyleDeclaration* inlineStyle() const; |
| 257 bool getStyleAttributeRanges(RefPtr<CSSStyleSourceData>* result); | 244 bool getStyleAttributeRanges(RefPtr<CSSStyleSourceData>* result); |
| 258 | 245 |
| 259 Element* m_element; | 246 RefPtr<Element> m_element; |
| 260 RefPtr<CSSRuleSourceData> m_ruleSourceData; | 247 RefPtr<CSSRuleSourceData> m_ruleSourceData; |
| 261 RefPtr<InspectorStyle> m_inspectorStyle; | 248 RefPtr<InspectorStyle> m_inspectorStyle; |
| 262 }; | 249 }; |
| 263 | 250 |
| 264 #endif | 251 #endif |
| 265 | 252 |
| 266 } // namespace WebCore | 253 } // namespace WebCore |
| 267 | 254 |
| 268 #endif // !defined(InspectorStyleSheet_h) | 255 #endif // !defined(InspectorStyleSheet_h) |
| OLD | NEW |