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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 case CSSRule::PAGE_RULE: | 124 case CSSRule::PAGE_RULE: |
125 default: | 125 default: |
126 return 0; | 126 return 0; |
127 } | 127 } |
128 | 128 |
129 return result.release(); | 129 return result.release(); |
130 } | 130 } |
131 return 0; | 131 return 0; |
132 } | 132 } |
133 | 133 |
| 134 PassRefPtr<InspectorStyle> InspectorStyle::create(const InspectorCSSId& styleId,
PassRefPtr<CSSStyleDeclaration> style, InspectorStyleSheet* parentStyleSheet) |
| 135 { |
| 136 return adoptRef(new InspectorStyle(styleId, style, parentStyleSheet)); |
| 137 } |
| 138 |
| 139 InspectorStyle::InspectorStyle(const InspectorCSSId& styleId, PassRefPtr<CSSStyl
eDeclaration> style, InspectorStyleSheet* parentStyleSheet) |
| 140 : m_styleId(styleId) |
| 141 , m_style(style) |
| 142 , m_parentStyleSheet(parentStyleSheet) |
| 143 { |
| 144 ASSERT(m_style); |
| 145 } |
| 146 |
134 PassRefPtr<InspectorObject> InspectorStyle::buildObjectForStyle() const | 147 PassRefPtr<InspectorObject> InspectorStyle::buildObjectForStyle() const |
135 { | 148 { |
136 RefPtr<InspectorObject> result = InspectorObject::create(); | 149 RefPtr<InspectorObject> result = InspectorObject::create(); |
137 if (!m_styleId.isEmpty()) | 150 if (!m_styleId.isEmpty()) |
138 result->setValue("styleId", m_styleId.asInspectorValue()); | 151 result->setValue("styleId", m_styleId.asInspectorValue()); |
139 | 152 |
140 RefPtr<InspectorObject> propertiesObject = InspectorObject::create(); | 153 RefPtr<InspectorObject> propertiesObject = InspectorObject::create(); |
141 propertiesObject->setString("width", m_style->getPropertyValue("width")); | 154 propertiesObject->setString("width", m_style->getPropertyValue("width")); |
142 propertiesObject->setString("height", m_style->getPropertyValue("height")); | 155 propertiesObject->setString("height", m_style->getPropertyValue("height")); |
143 | 156 |
144 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet ? m_parentStyleShe
et->ruleSourceDataFor(m_style) : 0; | 157 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet ? m_parentStyleShe
et->ruleSourceDataFor(m_style.get()) : 0; |
145 if (sourceData) { | 158 if (sourceData) { |
146 propertiesObject->setNumber("startOffset", sourceData->styleSourceData->
styleBodyRange.start); | 159 propertiesObject->setNumber("startOffset", sourceData->styleSourceData->
styleBodyRange.start); |
147 propertiesObject->setNumber("endOffset", sourceData->styleSourceData->st
yleBodyRange.end); | 160 propertiesObject->setNumber("endOffset", sourceData->styleSourceData->st
yleBodyRange.end); |
148 } | 161 } |
149 result->setObject("properties", propertiesObject); | 162 result->setObject("properties", propertiesObject); |
150 | 163 |
151 populateObjectWithStyleProperties(result.get()); | 164 populateObjectWithStyleProperties(result.get()); |
152 | 165 |
153 return result.release(); | 166 return result.release(); |
154 } | 167 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } else { | 221 } else { |
209 // Patch disabled property text. | 222 // Patch disabled property text. |
210 m_disabledProperties.at(disabledIndex).rawText = propertyText; | 223 m_disabledProperties.at(disabledIndex).rawText = propertyText; |
211 } | 224 } |
212 | 225 |
213 // We should not shift subsequent disabled properties when altering
a disabled property. | 226 // We should not shift subsequent disabled properties when altering
a disabled property. |
214 return true; | 227 return true; |
215 } | 228 } |
216 } else { | 229 } else { |
217 // Insert at index. | 230 // Insert at index. |
218 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDat
aFor(m_style); | 231 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDat
aFor(m_style.get()); |
219 if (!sourceData) | 232 if (!sourceData) |
220 return false; | 233 return false; |
221 String text; | 234 String text; |
222 bool success = styleText(&text); | 235 bool success = styleText(&text); |
223 if (!success) | 236 if (!success) |
224 return false; | 237 return false; |
225 propertyLengthDelta = propertyText.length(); | 238 propertyLengthDelta = propertyText.length(); |
226 | 239 |
227 bool insertLast = true; | 240 bool insertLast = true; |
228 if (index < allProperties.size()) { | 241 if (index < allProperties.size()) { |
(...skipping 19 matching lines...) Expand all Loading... |
248 // the last property has no trailing ";". | 261 // the last property has no trailing ";". |
249 textToSet.insert("; ", 0); | 262 textToSet.insert("; ", 0); |
250 } else if (!isHTMLSpace(characters[propertyStart - 1])) { | 263 } else if (!isHTMLSpace(characters[propertyStart - 1])) { |
251 // Prepend a " " if the last declaration character is not an
HTML space. | 264 // Prepend a " " if the last declaration character is not an
HTML space. |
252 textToSet.insert(" ", 0); | 265 textToSet.insert(" ", 0); |
253 } | 266 } |
254 } | 267 } |
255 } | 268 } |
256 | 269 |
257 text.insert(textToSet, propertyStart); | 270 text.insert(textToSet, propertyStart); |
258 m_parentStyleSheet->setStyleText(m_style, text); | 271 m_parentStyleSheet->setStyleText(m_style.get(), text); |
259 } | 272 } |
260 | 273 |
261 // Recompute subsequent disabled property ranges if acting on a non-disabled
property. | 274 // Recompute subsequent disabled property ranges if acting on a non-disabled
property. |
262 shiftDisabledProperties(disabledIndexByOrdinal(index, true, allProperties),
propertyLengthDelta); | 275 shiftDisabledProperties(disabledIndexByOrdinal(index, true, allProperties),
propertyLengthDelta); |
263 | 276 |
264 return true; | 277 return true; |
265 } | 278 } |
266 | 279 |
267 bool InspectorStyle::toggleProperty(unsigned index, bool disable) | 280 bool InspectorStyle::toggleProperty(unsigned index, bool disable) |
268 { | 281 { |
269 ASSERT(m_parentStyleSheet); | 282 ASSERT(m_parentStyleSheet); |
270 if (!m_parentStyleSheet->ensureParsedDataReady()) | 283 if (!m_parentStyleSheet->ensureParsedDataReady()) |
271 return false; // Can toggle only source-based properties. | 284 return false; // Can toggle only source-based properties. |
272 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor
(m_style); | 285 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor
(m_style.get()); |
273 if (!sourceData) | 286 if (!sourceData) |
274 return false; // No source data for the style. | 287 return false; // No source data for the style. |
275 | 288 |
276 Vector<InspectorStyleProperty> allProperties; | 289 Vector<InspectorStyleProperty> allProperties; |
277 populateAllProperties(&allProperties); | 290 populateAllProperties(&allProperties); |
278 if (index >= allProperties.size()) | 291 if (index >= allProperties.size()) |
279 return false; // Outside of property range. | 292 return false; // Outside of property range. |
280 | 293 |
281 InspectorStyleProperty& property = allProperties.at(index); | 294 InspectorStyleProperty& property = allProperties.at(index); |
282 if (property.disabled == disable) | 295 if (property.disabled == disable) |
(...skipping 20 matching lines...) Expand all Loading... |
303 ++disabledIndex; | 316 ++disabledIndex; |
304 } | 317 } |
305 } | 318 } |
306 | 319 |
307 return UINT_MAX; | 320 return UINT_MAX; |
308 } | 321 } |
309 | 322 |
310 bool InspectorStyle::styleText(String* result) const | 323 bool InspectorStyle::styleText(String* result) const |
311 { | 324 { |
312 // Precondition: m_parentStyleSheet->ensureParsedDataReady() has been called
successfully. | 325 // Precondition: m_parentStyleSheet->ensureParsedDataReady() has been called
successfully. |
313 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor
(m_style); | 326 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor
(m_style.get()); |
314 if (!sourceData) | 327 if (!sourceData) |
315 return false; | 328 return false; |
316 | 329 |
317 String styleSheetText; | 330 String styleSheetText; |
318 bool success = m_parentStyleSheet->text(&styleSheetText); | 331 bool success = m_parentStyleSheet->text(&styleSheetText); |
319 if (!success) | 332 if (!success) |
320 return false; | 333 return false; |
321 | 334 |
322 SourceRange& bodyRange = sourceData->styleSourceData->styleBodyRange; | 335 SourceRange& bodyRange = sourceData->styleSourceData->styleBodyRange; |
323 *result = styleSheetText.substring(bodyRange.start, bodyRange.end - bodyRang
e.start); | 336 *result = styleSheetText.substring(bodyRange.start, bodyRange.end - bodyRang
e.start); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 bool InspectorStyle::populateAllProperties(Vector<InspectorStyleProperty>* resul
t) const | 385 bool InspectorStyle::populateAllProperties(Vector<InspectorStyleProperty>* resul
t) const |
373 { | 386 { |
374 HashSet<String> foundShorthands; | 387 HashSet<String> foundShorthands; |
375 HashSet<String> sourcePropertyNames; | 388 HashSet<String> sourcePropertyNames; |
376 unsigned disabledIndex = 0; | 389 unsigned disabledIndex = 0; |
377 unsigned disabledLength = m_disabledProperties.size(); | 390 unsigned disabledLength = m_disabledProperties.size(); |
378 InspectorStyleProperty disabledProperty; | 391 InspectorStyleProperty disabledProperty; |
379 if (disabledIndex < disabledLength) | 392 if (disabledIndex < disabledLength) |
380 disabledProperty = m_disabledProperties.at(disabledIndex); | 393 disabledProperty = m_disabledProperties.at(disabledIndex); |
381 | 394 |
382 RefPtr<CSSRuleSourceData> sourceData = (m_parentStyleSheet && m_parentStyleS
heet->ensureParsedDataReady()) ? m_parentStyleSheet->ruleSourceDataFor(m_style)
: 0; | 395 RefPtr<CSSRuleSourceData> sourceData = (m_parentStyleSheet && m_parentStyleS
heet->ensureParsedDataReady()) ? m_parentStyleSheet->ruleSourceDataFor(m_style.g
et()) : 0; |
383 Vector<CSSPropertySourceData>* sourcePropertyData = sourceData ? &(sourceDat
a->styleSourceData->propertyData) : 0; | 396 Vector<CSSPropertySourceData>* sourcePropertyData = sourceData ? &(sourceDat
a->styleSourceData->propertyData) : 0; |
384 if (sourcePropertyData) { | 397 if (sourcePropertyData) { |
385 String styleDeclaration; | 398 String styleDeclaration; |
386 bool isStyleTextKnown = styleText(&styleDeclaration); | 399 bool isStyleTextKnown = styleText(&styleDeclaration); |
387 ASSERT_UNUSED(isStyleTextKnown, isStyleTextKnown); | 400 ASSERT_UNUSED(isStyleTextKnown, isStyleTextKnown); |
388 for (Vector<CSSPropertySourceData>::const_iterator it = sourcePropertyDa
ta->begin(); it != sourcePropertyData->end(); ++it) { | 401 for (Vector<CSSPropertySourceData>::const_iterator it = sourcePropertyDa
ta->begin(); it != sourcePropertyData->end(); ++it) { |
389 while (disabledIndex < disabledLength && disabledProperty.sourceData
.range.start <= it->range.start) { | 402 while (disabledIndex < disabledLength && disabledProperty.sourceData
.range.start <= it->range.start) { |
390 result->append(disabledProperty); | 403 result->append(disabledProperty); |
391 if (++disabledIndex < disabledLength) | 404 if (++disabledIndex < disabledLength) |
392 disabledProperty = m_disabledProperties.at(disabledIndex); | 405 disabledProperty = m_disabledProperties.at(disabledIndex); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 | 512 |
500 bool InspectorStyle::replacePropertyInStyleText(const InspectorStyleProperty& pr
operty, const String& newText) | 513 bool InspectorStyle::replacePropertyInStyleText(const InspectorStyleProperty& pr
operty, const String& newText) |
501 { | 514 { |
502 // Precondition: m_parentStyleSheet->ensureParsedDataReady() has been called
successfully. | 515 // Precondition: m_parentStyleSheet->ensureParsedDataReady() has been called
successfully. |
503 String text; | 516 String text; |
504 bool success = styleText(&text); | 517 bool success = styleText(&text); |
505 if (!success) | 518 if (!success) |
506 return false; | 519 return false; |
507 const SourceRange& range = property.sourceData.range; | 520 const SourceRange& range = property.sourceData.range; |
508 text.replace(range.start, range.end - range.start, newText); | 521 text.replace(range.start, range.end - range.start, newText); |
509 success = m_parentStyleSheet->setStyleText(m_style, text); | 522 success = m_parentStyleSheet->setStyleText(m_style.get(), text); |
510 return success; | 523 return success; |
511 } | 524 } |
512 | 525 |
513 String InspectorStyle::shorthandValue(const String& shorthandProperty) const | 526 String InspectorStyle::shorthandValue(const String& shorthandProperty) const |
514 { | 527 { |
515 String value = m_style->getPropertyValue(shorthandProperty); | 528 String value = m_style->getPropertyValue(shorthandProperty); |
516 if (value.isEmpty()) { | 529 if (value.isEmpty()) { |
517 for (unsigned i = 0; i < m_style->length(); ++i) { | 530 for (unsigned i = 0; i < m_style->length(); ++i) { |
518 String individualProperty = m_style->item(i); | 531 String individualProperty = m_style->item(i); |
519 if (m_style->getPropertyShorthand(individualProperty) != shorthandPr
operty) | 532 if (m_style->getPropertyShorthand(individualProperty) != shorthandPr
operty) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 String individualProperty = m_style->item(i); | 567 String individualProperty = m_style->item(i); |
555 if (foundProperties.contains(individualProperty) || m_style->getProperty
Shorthand(individualProperty) != shorthandProperty) | 568 if (foundProperties.contains(individualProperty) || m_style->getProperty
Shorthand(individualProperty) != shorthandProperty) |
556 continue; | 569 continue; |
557 | 570 |
558 foundProperties.add(individualProperty); | 571 foundProperties.add(individualProperty); |
559 properties.append(individualProperty); | 572 properties.append(individualProperty); |
560 } | 573 } |
561 return properties; | 574 return properties; |
562 } | 575 } |
563 | 576 |
564 InspectorStyleSheet::InspectorStyleSheet(const String& id, CSSStyleSheet* pageSt
yleSheet, const String& origin, const String& documentURL) | 577 PassRefPtr<InspectorStyleSheet> InspectorStyleSheet::create(const String& id, Pa
ssRefPtr<CSSStyleSheet> pageStyleSheet, const String& origin, const String& docu
mentURL) |
| 578 { |
| 579 return adoptRef(new InspectorStyleSheet(id, pageStyleSheet, origin, document
URL)); |
| 580 } |
| 581 |
| 582 InspectorStyleSheet::InspectorStyleSheet(const String& id, PassRefPtr<CSSStyleSh
eet> pageStyleSheet, const String& origin, const String& documentURL) |
565 : m_id(id) | 583 : m_id(id) |
566 , m_pageStyleSheet(pageStyleSheet) | 584 , m_pageStyleSheet(pageStyleSheet) |
567 , m_origin(origin) | 585 , m_origin(origin) |
568 , m_documentURL(documentURL) | 586 , m_documentURL(documentURL) |
569 , m_isRevalidating(false) | 587 , m_isRevalidating(false) |
570 { | 588 { |
571 m_parsedStyleSheet = new ParsedStyleSheet(); | 589 m_parsedStyleSheet = new ParsedStyleSheet(); |
572 } | 590 } |
573 | 591 |
574 InspectorStyleSheet::~InspectorStyleSheet() | 592 InspectorStyleSheet::~InspectorStyleSheet() |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 if (styleRule) | 1101 if (styleRule) |
1084 result->append(styleRule); | 1102 result->append(styleRule); |
1085 else { | 1103 else { |
1086 RefPtr<CSSRuleList> childRuleList = asCSSRuleList(rule); | 1104 RefPtr<CSSRuleList> childRuleList = asCSSRuleList(rule); |
1087 if (childRuleList) | 1105 if (childRuleList) |
1088 collectFlatRules(childRuleList, result); | 1106 collectFlatRules(childRuleList, result); |
1089 } | 1107 } |
1090 } | 1108 } |
1091 } | 1109 } |
1092 | 1110 |
1093 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const Strin
g& id, Element* element, const String& origin) | 1111 PassRefPtr<InspectorStyleSheetForInlineStyle> InspectorStyleSheetForInlineStyle:
:create(const String& id, PassRefPtr<Element> element, const String& origin) |
| 1112 { |
| 1113 return adoptRef(new InspectorStyleSheetForInlineStyle(id, element, origin)); |
| 1114 } |
| 1115 |
| 1116 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const Strin
g& id, PassRefPtr<Element> element, const String& origin) |
1094 : InspectorStyleSheet(id, 0, origin, "") | 1117 : InspectorStyleSheet(id, 0, origin, "") |
1095 , m_element(element) | 1118 , m_element(element) |
1096 , m_ruleSourceData(0) | 1119 , m_ruleSourceData(0) |
1097 { | 1120 { |
1098 ASSERT(element); | 1121 ASSERT(m_element); |
1099 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id, 0), inlineStyle
(), this); | 1122 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id, 0), inlineStyle
(), this); |
1100 } | 1123 } |
1101 | 1124 |
1102 bool InspectorStyleSheetForInlineStyle::text(String* result) const | 1125 bool InspectorStyleSheetForInlineStyle::text(String* result) const |
1103 { | 1126 { |
1104 *result = m_element->getAttribute("style"); | 1127 *result = m_element->getAttribute("style"); |
1105 return true; | 1128 return true; |
1106 } | 1129 } |
1107 | 1130 |
1108 bool InspectorStyleSheetForInlineStyle::setStyleText(CSSStyleDeclaration* style,
const String& text) | 1131 bool InspectorStyleSheetForInlineStyle::setStyleText(CSSStyleDeclaration* style,
const String& text) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 | 1184 |
1162 RefPtr<CSSMutableStyleDeclaration> tempDeclaration = CSSMutableStyleDeclarat
ion::create(); | 1185 RefPtr<CSSMutableStyleDeclaration> tempDeclaration = CSSMutableStyleDeclarat
ion::create(); |
1163 CSSParser p; | 1186 CSSParser p; |
1164 p.parseDeclaration(tempDeclaration.get(), styleText, result); | 1187 p.parseDeclaration(tempDeclaration.get(), styleText, result); |
1165 return true; | 1188 return true; |
1166 } | 1189 } |
1167 | 1190 |
1168 } // namespace WebCore | 1191 } // namespace WebCore |
1169 | 1192 |
1170 #endif // ENABLE(INSPECTOR) | 1193 #endif // ENABLE(INSPECTOR) |
OLD | NEW |