Changeset 90619 in webkit
- Timestamp:
- Jul 8, 2011 4:32:40 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r90617 r90619 1 2011-07-07 Alexander Pavlov <apavlov@chromium.org> 2 3 Web Inspector: Adding CSS properties results in messy style rules 4 https://bugs.webkit.org/show_bug.cgi?id=63622 5 6 Reviewed by Pavel Feldman. 7 8 * inspector/styles/styles-formatting-expected.txt: Added. 9 * inspector/styles/styles-formatting.html: Added. 10 * inspector/styles/styles-new-API-expected.txt: 11 * inspector/styles/styles-new-API.html: 12 1 13 2011-07-08 Alexander Pavlov <apavlov@chromium.org> 2 14 -
trunk/LayoutTests/inspector/styles/styles-new-API-expected.txt
r86754 r90619 311 311 === After style text set === 312 312 313 StyleSheet: 'html *, body[foo="bar"] { color: white; background: black;}body { text-align: justify;}' 313 StyleSheet: 'html *, body[foo="bar"] { 314 color: white; background: black; 315 }body { text-align: justify;}' 314 316 315 317 rule 316 318 html *, body[foo="bar"]: [] 317 ['color':'white'] @[ 8-21] active318 ['background':'black'] @[ 22-40] active319 ['color':'white'] @[5-18] active 320 ['background':'black'] @[19-37] active 319 321 ['background-image':'initial'] @[undefined-undefined] style 320 322 ['background-repeat-x':'initial'] @[undefined-undefined] style … … 363 365 rule 364 366 html *, body[foo="bar"]: [] 365 ['color':'white'] @[ 8-21] active366 ['background':'black'] @[ 22-40] active367 ['color':'white'] @[5-18] active 368 ['background':'black'] @[19-37] active 367 369 ['background-image':'initial'] @[undefined-undefined] style 368 370 ['background-repeat-x':'initial'] @[undefined-undefined] style … … 381 383 rule 382 384 body: [inspector] 383 ['font-family':'serif'] @[ 0-19] active385 ['font-family':'serif'] @[5-24] active 384 386 385 387 rule … … 401 403 ['background-color':'green' is-important] @[undefined-undefined] style 402 404 403 === After two properties disabled, one property added, one property removed===405 === After property manipulations === 404 406 405 407 style 406 408 raw style 407 409 [text='height : 100% ;'] disabled 408 ['border':'1px solid'] @[ 6-24] active409 ['border-width':'2px'] @[2 5-43] inactive410 ['googles':'abra' non-parsed] @[4 5-59] active411 ['foo':'.bar' non-parsed] @[ 60-70] active412 ['-moz-goog':'1***' non-parsed] @[ 71-87] active410 ['border':'1px solid'] @[1-19] active 411 ['border-width':'2px'] @[20-38] inactive 412 ['googles':'abra' non-parsed] @[40-54] active 413 ['foo':'.bar' non-parsed] @[55-65] active 414 ['-moz-goog':'1***' non-parsed] @[66-82] active 413 415 ['font-size':'12px'] @[88-104] active 414 ['border-width':'1px'] @[10 4-122] active416 ['border-width':'1px'] @[109-127] active 415 417 [text='font-size: 14px;'] disabled 416 418 ['border-top-style':'solid'] @[undefined-undefined] style … … 429 431 raw style 430 432 [text='height : 100% ;'] disabled 431 ['border':'1px solid'] @[ 6-24] active432 ['border-width':'2px'] @[2 5-43] inactive433 ['googles':'abra' non-parsed] @[4 5-59] active434 ['foo':'.bar' non-parsed] @[ 60-70] active435 ['-moz-goog':'1***' non-parsed] @[ 71-87] active433 ['border':'1px solid'] @[1-19] active 434 ['border-width':'2px'] @[20-38] inactive 435 ['googles':'abra' non-parsed] @[40-54] active 436 ['foo':'.bar' non-parsed] @[55-65] active 437 ['-moz-goog':'1***' non-parsed] @[66-82] active 436 438 ['font-size':'12px'] @[88-104] inactive 437 ['border-width':'1px'] @[10 4-122] active438 ['font-size':'14px'] @[1 23-139] active439 ['border-width':'1px'] @[109-127] active 440 ['font-size':'14px'] @[132-148] active 439 441 ['border-top-style':'solid'] @[undefined-undefined] style 440 442 ['border-right-style':'solid'] @[undefined-undefined] style -
trunk/LayoutTests/inspector/styles/styles-new-API.html
r89922 r90619 199 199 } 200 200 InspectorTest.addResult(""); 201 InspectorTest.addResult("=== After two properties disabled, one property added, one property removed===");201 InspectorTest.addResult("=== After property manipulations ==="); 202 202 dumpRuleOrStyle(style); 203 203 test_enableProperty(style.styleId); … … 219 219 // border-width: 0px; 220 220 221 var style = styles.matchedCSSRules[1].style;222 CSSAgent.toggleProperty(style .styleId, 0, true); // height: 100%223 CSSAgent.toggleProperty(style .styleId, 7, true); // border-width: 0px224 CSSAgent.setPropertyText(style .styleId, 7, "font-size: 12px;", false);225 CSSAgent.setPropertyText(style .styleId, 9, "font-size: 14px;", false);226 CSSAgent.toggleProperty(style .styleId, 9, true); // font-size: 14px227 CSSAgent.setPropertyText(style .styleId, 8, "border-width: 1px;", true);228 CSSAgent.toggleProperty(style .styleId, 8, false); // border-width: 1px221 var styleId = styles.matchedCSSRules[1].style.styleId; 222 CSSAgent.toggleProperty(styleId, 0, true); // height: 100% 223 CSSAgent.toggleProperty(styleId, 7, true); // border-width: 0px 224 CSSAgent.setPropertyText(styleId, 7, "font-size: 12px;", false); 225 CSSAgent.setPropertyText(styleId, 9, "font-size: 14px;", false); 226 CSSAgent.toggleProperty(styleId, 9, true); // font-size: 14px 227 CSSAgent.setPropertyText(styleId, 8, "border-width: 1px;", true); 228 CSSAgent.toggleProperty(styleId, 8, false); // border-width: 1px 229 229 // height : 100% ; [d] 230 230 // border: 1px solid; … … 238 238 // font-size: 14px; [d] 239 239 240 CSSAgent.setPropertyText(style .styleId, 3, "", true, didDisableProperty);240 CSSAgent.setPropertyText(styleId, 3, "", true, didDisableProperty); 241 241 } 242 242 -
trunk/Source/WebCore/CMakeLists.txt
r90531 r90619 883 883 inspector/InspectorState.cpp 884 884 inspector/InspectorStyleSheet.cpp 885 inspector/InspectorStyleTextEditor.cpp 885 886 inspector/InspectorTimelineAgent.cpp 886 887 inspector/InspectorValues.cpp -
trunk/Source/WebCore/ChangeLog
r90617 r90619 1 2011-07-07 Alexander Pavlov <apavlov@chromium.org> 2 3 Web Inspector: Adding CSS properties results in messy style rules 4 https://bugs.webkit.org/show_bug.cgi?id=63622 5 6 Reviewed by Pavel Feldman. 7 8 Test: inspector/styles/styles-formatting.html 9 10 * CMakeLists.txt: 11 * GNUmakefile.list.am: 12 * WebCore.gypi: 13 * WebCore.pro: 14 * WebCore.vcproj/WebCore.vcproj: 15 * WebCore.xcodeproj/project.pbxproj: 16 * css/CSSPropertySourceData.cpp: 17 (WebCore::SourceRange::length): 18 * css/CSSPropertySourceData.h: 19 * inspector/InspectorStyleSheet.cpp: 20 (WebCore::InspectorStyle::InspectorStyle): 21 (WebCore::InspectorStyle::setPropertyText): 22 (WebCore::InspectorStyle::toggleProperty): 23 (WebCore::InspectorStyle::applyStyleText): 24 (WebCore::InspectorStyle::newLineAndWhitespaceDelimiters): 25 * inspector/InspectorStyleSheet.h: 26 * inspector/InspectorStyleTextEditor.cpp: Added. 27 (WebCore::InspectorStyleTextEditor::InspectorStyleTextEditor): 28 (WebCore::InspectorStyleTextEditor::insertProperty): 29 (WebCore::InspectorStyleTextEditor::replaceProperty): 30 (WebCore::InspectorStyleTextEditor::removeProperty): 31 (WebCore::InspectorStyleTextEditor::enableProperty): 32 (WebCore::InspectorStyleTextEditor::disableProperty): 33 (WebCore::InspectorStyleTextEditor::disabledIndexByOrdinal): 34 (WebCore::InspectorStyleTextEditor::shiftDisabledProperties): 35 (WebCore::InspectorStyleTextEditor::internalReplaceProperty): 36 * inspector/InspectorStyleTextEditor.h: Added. 37 (WebCore::InspectorStyleTextEditor::styleText): 38 1 39 2011-07-08 Alexander Pavlov <apavlov@chromium.org> 2 40 -
trunk/Source/WebCore/GNUmakefile.list.am
r90269 r90619 2006 2006 Source/WebCore/inspector/InspectorStyleSheet.cpp \ 2007 2007 Source/WebCore/inspector/InspectorStyleSheet.h \ 2008 Source/WebCore/inspector/InspectorStyleTextEditor.cpp \ 2009 Source/WebCore/inspector/InspectorStyleTextEditor.h \ 2008 2010 Source/WebCore/inspector/InspectorTimelineAgent.cpp \ 2009 2011 Source/WebCore/inspector/InspectorTimelineAgent.h \ -
trunk/Source/WebCore/WebCore.gypi
r90397 r90619 3318 3318 'inspector/InspectorStyleSheet.cpp', 3319 3319 'inspector/InspectorStyleSheet.h', 3320 'inspector/InspectorStyleTextEditor.cpp', 3321 'inspector/InspectorStyleTextEditor.h', 3320 3322 'inspector/InspectorTimelineAgent.cpp', 3321 3323 'inspector/InspectorTimelineAgent.h', -
trunk/Source/WebCore/WebCore.pro
r90450 r90619 836 836 inspector/InspectorState.cpp \ 837 837 inspector/InspectorStyleSheet.cpp \ 838 inspector/InspectorStyleTextEditor.cpp \ 838 839 inspector/InspectorTimelineAgent.cpp \ 839 840 inspector/InspectorValues.cpp \ … … 1795 1796 inspector/InspectorState.h \ 1796 1797 inspector/InspectorStyleSheet.h \ 1798 inspector/InspectorStyleTextEditor.h \ 1797 1799 inspector/InspectorTimelineAgent.h \ 1798 1800 inspector/InspectorWorkerAgent.h \ -
trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj
r90365 r90619 67755 67755 </File> 67756 67756 <File 67757 RelativePath="..\inspector\InspectorStyleTextEditor.cpp" 67758 > 67759 </File> 67760 <File 67761 RelativePath="..\inspector\InspectorStyleTextEditor.h" 67762 > 67763 </File> 67764 <File 67757 67765 RelativePath="..\inspector\InspectorTimelineAgent.cpp" 67758 67766 > -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r90269 r90619 1761 1761 81BE20D311F4BC3200915DFA /* JSIDBCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 81BE20A811F4B66F00915DFA /* JSIDBCursor.h */; }; 1762 1762 81F65FF613788FAA00FF6F2D /* DragState.h in Headers */ = {isa = PBXBuildFile; fileRef = 81F65FF513788FAA00FF6F2D /* DragState.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1763 82889B4C13C62392009A6156 /* InspectorStyleTextEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82889B4A13C62392009A6156 /* InspectorStyleTextEditor.cpp */; }; 1764 82889B4D13C62392009A6156 /* InspectorStyleTextEditor.h in Headers */ = {isa = PBXBuildFile; fileRef = 82889B4B13C62392009A6156 /* InspectorStyleTextEditor.h */; }; 1763 1765 82AB1743124B99EC00C5069D /* InspectorCSSAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */; }; 1764 1766 82AB1744124B99EC00C5069D /* InspectorCSSAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */; }; … … 8329 8331 81BE20A811F4B66F00915DFA /* JSIDBCursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSIDBCursor.h; sourceTree = "<group>"; }; 8330 8332 81F65FF513788FAA00FF6F2D /* DragState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragState.h; sourceTree = "<group>"; }; 8333 82889B4A13C62392009A6156 /* InspectorStyleTextEditor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorStyleTextEditor.cpp; sourceTree = "<group>"; }; 8334 82889B4B13C62392009A6156 /* InspectorStyleTextEditor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorStyleTextEditor.h; sourceTree = "<group>"; }; 8331 8335 82AB1741124B99EC00C5069D /* InspectorCSSAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorCSSAgent.cpp; sourceTree = "<group>"; }; 8332 8336 82AB1742124B99EC00C5069D /* InspectorCSSAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorCSSAgent.h; sourceTree = "<group>"; }; … … 13417 13421 82AB176F125C826700C5069D /* InspectorStyleSheet.cpp */, 13418 13422 82AB1770125C826700C5069D /* InspectorStyleSheet.h */, 13423 82889B4A13C62392009A6156 /* InspectorStyleTextEditor.cpp */, 13424 82889B4B13C62392009A6156 /* InspectorStyleTextEditor.h */, 13419 13425 754133A9102E00F400075D00 /* InspectorTimelineAgent.cpp */, 13420 13426 754133A7102E00E800075D00 /* InspectorTimelineAgent.h */, … … 23089 23095 431A2F9C13B6F2B0007791E4 /* SVGAnimatedNumberOptionalNumber.h in Headers */, 23090 23096 A5ABB78713B904BC00F197E3 /* LineBreakIteratorPoolICU.h in Headers */, 23097 82889B4D13C62392009A6156 /* InspectorStyleTextEditor.h in Headers */, 23091 23098 ); 23092 23099 runOnlyForDeploymentPostprocessing = 0; … … 25856 25863 431A308813B8F978007791E4 /* SVGAnimatedBoolean.cpp in Sources */, 25857 25864 43F6FD9613BCD0B100224052 /* SVGAnimatedInteger.cpp in Sources */, 25865 82889B4C13C62392009A6156 /* InspectorStyleTextEditor.cpp in Sources */, 25858 25866 ); 25859 25867 runOnlyForDeploymentPostprocessing = 0; -
trunk/Source/WebCore/css/CSSPropertySourceData.cpp
r69196 r90619 53 53 , end(end) 54 54 { 55 } 56 57 unsigned SourceRange::length() const 58 { 59 return end - start; 55 60 } 56 61 -
trunk/Source/WebCore/css/CSSPropertySourceData.h
r69196 r90619 45 45 SourceRange(); 46 46 SourceRange(unsigned start, unsigned end); 47 unsigned length() const; 47 48 48 49 unsigned start; -
trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp
r89449 r90619 149 149 , m_style(style) 150 150 , m_parentStyleSheet(parentStyleSheet) 151 , m_formatAcquired(false) 151 152 { 152 153 ASSERT(m_style); … … 176 177 177 178 // This method does the following preprocessing of |propertyText| with |overwrite| == false and |index| past the last active property: 178 // - If the last property (if present) has no subsequent whitespace in the style declaration, a space is prepended to |propertyText|.179 179 // - If the last property (if present) has no closing ";", the ";" is prepended to the current |propertyText| value. 180 // - A heuristic formatting is attempted to retain the style structure. 180 181 // 181 182 // The propertyText (if not empty) is checked to be a valid style declaration (containing at least one property). If not, … … 184 185 { 185 186 ASSERT(m_parentStyleSheet); 187 DEFINE_STATIC_LOCAL(String, bogusPropertyName, ("-webkit-boguz-propertee")); 188 186 189 if (!m_parentStyleSheet->ensureParsedDataReady()) { 187 190 *errorString = "Internal error: no stylesheet parsed data available"; … … 191 194 Vector<InspectorStyleProperty> allProperties; 192 195 populateAllProperties(&allProperties); 193 194 unsigned propertyStart = 0; // Need to initialize to make the compiler happy.195 long propertyLengthDelta;196 196 197 197 if (propertyText.stripWhiteSpace().length()) { … … 199 199 CSSParser p; 200 200 RefPtr<CSSStyleSourceData> sourceData = CSSStyleSourceData::create(); 201 p.parseDeclaration(tempMutableStyle.get(), propertyText + " -webkit-boguz-propertee: none", &sourceData);201 p.parseDeclaration(tempMutableStyle.get(), propertyText + " " + bogusPropertyName + ": none", &sourceData); 202 202 Vector<CSSPropertySourceData>& propertyData = sourceData->propertyData; 203 203 unsigned propertyCount = propertyData.size(); … … 210 210 211 211 // Check for a proper propertyText termination (the parser could at least restore to the PROPERTY_NAME state). 212 if (propertyData.at(propertyCount - 1).name != "-webkit-boguz-propertee") {212 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) { 213 213 *errorString = "Invalid property value"; 214 214 return false; … … 216 216 } 217 217 218 if (overwrite) { 219 ASSERT(index < allProperties.size()); 220 InspectorStyleProperty& property = allProperties.at(index); 221 propertyStart = property.sourceData.range.start; 222 unsigned propertyEnd = property.sourceData.range.end; 223 unsigned oldLength = propertyEnd - propertyStart; 224 unsigned newLength = propertyText.length(); 225 propertyLengthDelta = newLength - oldLength; 226 227 if (!property.disabled) { 228 bool success = replacePropertyInStyleText(property, propertyText); 229 if (!success) { 230 *errorString = "Internal error: could not replace property value"; 231 return false; 232 } 233 } else { 234 unsigned textLength = propertyText.length(); 235 unsigned disabledIndex = disabledIndexByOrdinal(index, false, allProperties); 236 if (!textLength) { 237 // Delete disabled property. 238 m_disabledProperties.remove(disabledIndex); 239 } else { 240 // Patch disabled property text. 241 m_disabledProperties.at(disabledIndex).rawText = propertyText; 242 } 243 244 // We should not shift subsequent disabled properties when altering a disabled property. 245 return true; 246 } 247 } else { 248 // Insert at index. 249 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor(m_style.get()); 250 if (!sourceData) { 251 *errorString = "Internal error: no CSS rule source found"; 252 return false; 253 } 254 String text; 255 bool success = styleText(&text); 256 if (!success) { 257 *errorString = "Internal error: could not fetch style text"; 258 return false; 259 } 260 propertyLengthDelta = propertyText.length(); 261 262 bool insertLast = true; 263 if (index < allProperties.size()) { 264 InspectorStyleProperty& property = allProperties.at(index); 265 if (property.hasSource) { 266 propertyStart = property.sourceData.range.start; 267 // If inserting before a disabled property, it should be shifted, too. 268 insertLast = false; 269 } 270 } 271 272 String textToSet = propertyText; 273 if (insertLast) { 274 propertyStart = sourceData->styleSourceData->styleBodyRange.end - sourceData->styleSourceData->styleBodyRange.start; 275 if (propertyStart && propertyText.length()) { 276 const UChar* characters = text.characters(); 277 278 unsigned curPos = propertyStart - 1; // The last position of style declaration, since propertyStart points past one. 279 while (curPos && isHTMLSpace(characters[curPos])) 280 --curPos; 281 if (curPos && characters[curPos] != ';') { 282 // Prepend a ";" to the property text if appending to a style declaration where 283 // the last property has no trailing ";". 284 textToSet.insert("; ", 0); 285 } else if (!isHTMLSpace(characters[propertyStart - 1])) { 286 // Prepend a " " if the last declaration character is not an HTML space. 287 textToSet.insert(" ", 0); 288 } 289 } 290 } 291 292 text.insert(textToSet, propertyStart); 293 m_parentStyleSheet->setStyleText(m_style.get(), text); 294 } 295 296 // Recompute subsequent disabled property ranges if acting on a non-disabled property. 297 shiftDisabledProperties(disabledIndexByOrdinal(index, true, allProperties), propertyLengthDelta); 298 299 return true; 218 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor(m_style.get()); 219 if (!sourceData) { 220 *errorString = "Internal error: no CSS rule source found"; 221 return false; 222 } 223 224 String text; 225 bool success = styleText(&text); 226 if (!success) { 227 *errorString = "Internal error: could not fetch style text"; 228 return false; 229 } 230 231 InspectorStyleTextEditor editor(&allProperties, &m_disabledProperties, text, newLineAndWhitespaceDelimiters()); 232 if (overwrite) 233 editor.replaceProperty(index, propertyText); 234 else 235 editor.insertProperty(index, propertyText, sourceData->styleSourceData->styleBodyRange.length()); 236 237 return applyStyleText(editor.styleText()); 300 238 } 301 239 … … 307 245 return false; 308 246 } 247 309 248 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor(m_style.get()); 310 249 if (!sourceData) { 311 250 *errorString = "Internal error: No source data for the style found"; 251 return false; 252 } 253 254 String text; 255 bool success = styleText(&text); 256 if (!success) { 257 *errorString = "Internal error: could not fetch style text"; 312 258 return false; 313 259 } … … 324 270 return true; // Idempotent operation. 325 271 326 bool success;327 if ( !disable)328 success = enableProperty(index, allProperties);272 InspectorStyleTextEditor editor(&allProperties, &m_disabledProperties, text, newLineAndWhitespaceDelimiters()); 273 if (disable) 274 editor.disableProperty(index); 329 275 else 330 success = disableProperty(index, allProperties); 331 332 return success; 333 } 334 335 // static 336 unsigned InspectorStyle::disabledIndexByOrdinal(unsigned ordinal, bool canUseSubsequent, Vector<InspectorStyleProperty>& allProperties) 337 { 338 unsigned disabledIndex = 0; 339 for (unsigned i = 0, size = allProperties.size(); i < size; ++i) { 340 InspectorStyleProperty& property = allProperties.at(i); 341 if (property.disabled) { 342 if (i == ordinal || (canUseSubsequent && i > ordinal)) 343 return disabledIndex; 344 ++disabledIndex; 345 } 346 } 347 348 return UINT_MAX; 276 editor.enableProperty(index); 277 278 return applyStyleText(editor.styleText()); 349 279 } 350 280 … … 364 294 *result = styleSheetText.substring(bodyRange.start, bodyRange.end - bodyRange.start); 365 295 return true; 366 }367 368 bool InspectorStyle::disableProperty(unsigned indexToDisable, Vector<InspectorStyleProperty>& allProperties)369 {370 // Precondition: |indexToEnable| points to an enabled property.371 const InspectorStyleProperty& property = allProperties.at(indexToDisable);372 unsigned propertyStart = property.sourceData.range.start;373 InspectorStyleProperty disabledProperty(property);374 String oldStyleText;375 bool success = styleText(&oldStyleText);376 if (!success)377 return false;378 disabledProperty.setRawTextFromStyleDeclaration(oldStyleText);379 disabledProperty.disabled = true;380 disabledProperty.sourceData.range.end = propertyStart;381 // This may have to be negated below.382 long propertyLength = property.sourceData.range.end - propertyStart;383 success = replacePropertyInStyleText(property, "");384 if (!success)385 return false;386 387 // Add disabled property at correct position.388 unsigned insertionIndex = disabledIndexByOrdinal(indexToDisable, true, allProperties);389 if (insertionIndex == UINT_MAX)390 m_disabledProperties.append(disabledProperty);391 else {392 m_disabledProperties.insert(insertionIndex, disabledProperty);393 shiftDisabledProperties(insertionIndex + 1, -propertyLength); // Property removed from text - shift these back.394 }395 return true;396 }397 398 bool InspectorStyle::enableProperty(unsigned indexToEnable, Vector<InspectorStyleProperty>& allProperties)399 {400 // Precondition: |indexToEnable| points to a disabled property.401 unsigned disabledIndex = disabledIndexByOrdinal(indexToEnable, false, allProperties);402 if (disabledIndex == UINT_MAX)403 return false;404 405 InspectorStyleProperty disabledProperty = m_disabledProperties.at(disabledIndex);406 m_disabledProperties.remove(disabledIndex);407 bool success = replacePropertyInStyleText(disabledProperty, disabledProperty.rawText);408 if (success)409 shiftDisabledProperties(disabledIndex, disabledProperty.rawText.length());410 return success;411 296 } 412 297 … … 547 432 } 548 433 549 550 void InspectorStyle::shiftDisabledProperties(unsigned fromIndex, long delta) 551 { 552 for (unsigned i = fromIndex, size = m_disabledProperties.size(); i < size; ++i) { 553 SourceRange& range = m_disabledProperties.at(i).sourceData.range; 554 range.start += delta; 555 range.end += delta; 556 } 557 } 558 559 bool InspectorStyle::replacePropertyInStyleText(const InspectorStyleProperty& property, const String& newText) 560 { 561 // Precondition: m_parentStyleSheet->ensureParsedDataReady() has been called successfully. 562 String text; 563 bool success = styleText(&text); 564 if (!success) 565 return false; 566 const SourceRange& range = property.sourceData.range; 567 text.replace(range.start, range.end - range.start, newText); 568 success = m_parentStyleSheet->setStyleText(m_style.get(), text); 569 return success; 434 bool InspectorStyle::applyStyleText(const String& text) 435 { 436 return m_parentStyleSheet->setStyleText(m_style.get(), text); 570 437 } 571 438 … … 621 488 } 622 489 490 NewLineAndWhitespace& InspectorStyle::newLineAndWhitespaceDelimiters() const 491 { 492 DEFINE_STATIC_LOCAL(String, defaultPrefix, (" ")); 493 494 if (m_formatAcquired) 495 return m_format; 496 497 RefPtr<CSSRuleSourceData> sourceData = (m_parentStyleSheet && m_parentStyleSheet->ensureParsedDataReady()) ? m_parentStyleSheet->ruleSourceDataFor(m_style.get()) : 0; 498 Vector<CSSPropertySourceData>* sourcePropertyData = sourceData ? &(sourceData->styleSourceData->propertyData) : 0; 499 int propertyCount; 500 if (!sourcePropertyData || !(propertyCount = sourcePropertyData->size())) { 501 m_format.first = "\n"; 502 m_format.second = defaultPrefix; 503 return m_format; // Do not remember the default formatting and attempt to acquire it later. 504 } 505 506 String text; 507 bool success = styleText(&text); 508 ASSERT_UNUSED(success, success); 509 510 m_formatAcquired = true; 511 512 String formatLineFeed = ""; 513 String formatPropertyPrefix = ""; 514 String prefix; 515 String candidatePrefix = defaultPrefix; 516 int scanStart = 0; 517 int propertyIndex = 0; 518 bool isFullPrefixScanned = false; 519 bool lineFeedTerminated = false; 520 const UChar* characters = text.characters(); 521 while (propertyIndex < propertyCount) { 522 const WebCore::CSSPropertySourceData& currentProperty = sourcePropertyData->at(propertyIndex++); 523 524 bool processNextProperty = false; 525 int scanEnd = currentProperty.range.start; 526 for (int i = scanStart; i < scanEnd; ++i) { 527 UChar ch = characters[i]; 528 bool isLineFeed = isHTMLLineBreak(ch); 529 if (isLineFeed) { 530 if (!lineFeedTerminated) 531 formatLineFeed.append(ch); 532 } else if (isHTMLSpace(ch)) 533 prefix.append(ch); 534 else { 535 candidatePrefix = prefix; 536 prefix = ""; 537 scanStart = currentProperty.range.end; 538 ++propertyIndex; 539 processNextProperty = true; 540 break; 541 } 542 if (!isLineFeed && formatLineFeed.length()) 543 lineFeedTerminated = true; 544 } 545 if (!processNextProperty) { 546 isFullPrefixScanned = true; 547 break; 548 } 549 } 550 551 m_format.first = formatLineFeed; 552 m_format.second = isFullPrefixScanned ? prefix : candidatePrefix; 553 return m_format; 554 } 555 623 556 PassRefPtr<InspectorStyleSheet> InspectorStyleSheet::create(const String& id, PassRefPtr<CSSStyleSheet> pageStyleSheet, const String& origin, const String& documentURL) 624 557 { -
trunk/Source/WebCore/inspector/InspectorStyleSheet.h
r89224 r90619 27 27 28 28 #include "CSSPropertySourceData.h" 29 #include "InspectorStyleTextEditor.h" 29 30 #include "InspectorValues.h" 30 31 #include "PlatformString.h" … … 136 137 InspectorStyle(const InspectorCSSId& styleId, PassRefPtr<CSSStyleDeclaration> style, InspectorStyleSheet* parentStyleSheet); 137 138 138 static unsigned disabledIndexByOrdinal(unsigned ordinal, bool canUseSubsequent, Vector<InspectorStyleProperty>& allProperties);139 140 139 bool styleText(String* result) const; 141 bool disableProperty(unsigned indexToDisable, Vector<InspectorStyleProperty>& allProperties);142 bool enableProperty(unsigned indexToEnable, Vector<InspectorStyleProperty>& allProperties);143 140 bool populateAllProperties(Vector<InspectorStyleProperty>* result) const; 144 141 void populateObjectWithStyleProperties(InspectorObject* result) const; 145 void shiftDisabledProperties(unsigned fromIndex, long offset); 146 bool replacePropertyInStyleText(const InspectorStyleProperty& property, const String& newText); 142 bool applyStyleText(const String&); 147 143 String shorthandValue(const String& shorthandProperty) const; 148 144 String shorthandPriority(const String& shorthandProperty) const; 149 145 Vector<String> longhandProperties(const String& shorthandProperty) const; 146 NewLineAndWhitespace& newLineAndWhitespaceDelimiters() const; 150 147 151 148 InspectorCSSId m_styleId; … … 153 150 InspectorStyleSheet* m_parentStyleSheet; 154 151 Vector<InspectorStyleProperty> m_disabledProperties; 152 mutable std::pair<String, String> m_format; 153 mutable bool m_formatAcquired; 155 154 }; 156 155
Note: See TracChangeset
for help on using the changeset viewer.