Changeset 83962 in webkit
- Timestamp:
- Apr 15, 2011 5:39:32 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/inspector/styles/get-set-stylesheet-text.html
r83843 r83962 40 40 function testSetText(next) 41 41 { 42 function callback( success)42 function callback(error) 43 43 { 44 if ( !success) {45 InspectorTest.add Error("Failed to set stylesheet text");44 if (error) { 45 InspectorTest.addResult("Failed to set stylesheet text: " + error); 46 46 return; 47 47 } … … 60 60 { 61 61 if (error) { 62 InspectorTest.add Error("error: " + error);62 InspectorTest.addResult("error: " + error); 63 63 return; 64 64 } -
trunk/LayoutTests/inspector/styles/styles-new-API.html
r82578 r83962 18 18 { 19 19 if (error) { 20 InspectorTest.add Error("error: " + error);20 InspectorTest.addResult("error: " + error); 21 21 return; 22 22 } … … 298 298 { 299 299 if (error) { 300 InspectorTest.add Error("error: " + error);300 InspectorTest.addResult("error: " + error); 301 301 return; 302 302 } … … 305 305 { 306 306 if (error) { 307 InspectorTest.add Error("error: " + error);307 InspectorTest.addResult("error: " + error); 308 308 return; 309 309 } -
trunk/Source/WebCore/ChangeLog
r83960 r83962 1 2011-04-15 Pavel Feldman <pfeldman@google.com> 2 3 Reviewed by Yury Semikhatsky. 4 5 Web Inspector: refactor resource setContent / revisions infrastructure to get 6 rid of onRevert callback. 7 https://bugs.webkit.org/show_bug.cgi?id=58649 8 9 Instead, we will have DomainModel/Resource binding responsible for changing 10 underlying model upon resource changes and vice versa. 11 12 * inspector/Inspector.json: 13 * inspector/InspectorCSSAgent.cpp: 14 (WebCore::InspectorCSSAgent::getStyleSheet): 15 (WebCore::InspectorCSSAgent::getStyleSheetText): 16 (WebCore::InspectorCSSAgent::setStyleSheetText): 17 (WebCore::InspectorCSSAgent::setPropertyText): 18 (WebCore::InspectorCSSAgent::toggleProperty): 19 (WebCore::InspectorCSSAgent::setRuleSelector): 20 (WebCore::InspectorCSSAgent::assertStyleSheetForId): 21 * inspector/InspectorCSSAgent.h: 22 * inspector/front-end/CSSStyleModel.js: 23 (WebInspector.CSSStyleModel): 24 (WebInspector.CSSStyleModel.prototype.setRuleSelector): 25 (WebInspector.CSSStyleModel.prototype.addRule): 26 (WebInspector.CSSStyleModel.prototype._fireStyleSheetChanged.callback): 27 (WebInspector.CSSStyleModel.prototype._fireStyleSheetChanged): 28 (WebInspector.CSSStyleModel.prototype.setStyleSheetText): 29 (WebInspector.CSSStyleDeclaration.prototype.insertPropertyAt): 30 (WebInspector.CSSProperty.prototype.setText): 31 (WebInspector.CSSProperty.prototype.setText.callback): 32 (WebInspector.CSSProperty.prototype.setDisabled.callback): 33 (WebInspector.CSSProperty.prototype.setDisabled): 34 (WebInspector.CSSStyleSheet.prototype.setText): 35 (WebInspector.CSSStyleModelResourceBinding): 36 (WebInspector.CSSStyleModelResourceBinding.prototype.setContent): 37 (WebInspector.CSSStyleModelResourceBinding.prototype._frameNavigated): 38 (WebInspector.CSSStyleModelResourceBinding.prototype._innerSetContent): 39 (WebInspector.CSSStyleModelResourceBinding.prototype._loadStyleSheetHeaders): 40 (WebInspector.CSSStyleModelResourceBinding.prototype._styleSheetChanged.setContent): 41 (WebInspector.CSSStyleModelResourceBinding.prototype._styleSheetChanged): 42 * inspector/front-end/DebuggerPresentationModel.js: 43 (WebInspector.DebuggerPresentationModel): 44 (WebInspector.DebuggerPresentationModel.prototype.editScriptSource.didEditScriptSource): 45 (WebInspector.DebuggerPresentationModel.prototype.editScriptSource.didReceiveSource): 46 (WebInspector.DebuggerPresentationModel.prototype.editScriptSource): 47 (WebInspector.DebuggerPresentationModelResourceBinding): 48 (WebInspector.DebuggerPresentationModelResourceBinding.prototype.canSetContent): 49 (WebInspector.DebuggerPresentationModelResourceBinding.prototype.setContent): 50 * inspector/front-end/Object.js: 51 (WebInspector.Object.prototype.hasEventListeners): 52 * inspector/front-end/Resource.js: 53 (WebInspector.Resource): 54 (WebInspector.Resource.registerDomainModelBinding): 55 (WebInspector.Resource.prototype.isEditable): 56 (WebInspector.Resource.prototype.setContent): 57 (WebInspector.Resource.prototype.addRevision): 58 (WebInspector.Resource.prototype.revertToThis.callback): 59 (WebInspector.Resource.prototype.revertToThis): 60 (WebInspector.ResourceDomainModelBinding): 61 (WebInspector.ResourceDomainModelBinding.prototype.canSetContent): 62 (WebInspector.ResourceDomainModelBinding.prototype.setContent): 63 * inspector/front-end/ResourceView.js: 64 (WebInspector.ResourceView.createResourceView): 65 (WebInspector.ResourceView.resourceViewTypeMatchesResource): 66 (WebInspector.ResourceSourceFrame.prototype.isContentEditable): 67 (WebInspector.ResourceSourceFrame.prototype.editContent): 68 (WebInspector.ResourceSourceFrame.prototype.endEditing): 69 (WebInspector.ResourceSourceFrame.prototype._clearIncrementalUpdateTimer): 70 (WebInspector.ResourceSourceFrame.prototype._requestContent): 71 * inspector/front-end/ResourcesPanel.js: 72 (WebInspector.ResourcesPanel.prototype._resourceAdded): 73 (WebInspector.FrameResourceTreeElement): 74 (WebInspector.FrameResourceTreeElement.prototype._populateRevisions): 75 (WebInspector.FrameResourceTreeElement.prototype._revisionAdded): 76 (WebInspector.FrameResourceTreeElement.prototype._appendRevision): 77 * inspector/front-end/inspector.html: 78 1 79 2011-04-15 Andrey Kosyakov <caseq@chromium.org> 2 80 -
trunk/Source/WebCore/inspector/Inspector.json
r83950 r83962 1166 1166 ], 1167 1167 "returns": [ 1168 { "name": "url", "type": "string", "description": "The stylesheet resource URL." },1169 1168 { "name": "text", "type": "string", "description": "The stylesheet text." } 1170 1169 ], … … 1176 1175 { "name": "styleSheetId", "type": "string" }, 1177 1176 { "name": "text", "type": "string" } 1178 ],1179 "returns": [1180 { "name": "success", "type": "boolean", "description": "Whether the modification was successful." }1181 1177 ], 1182 1178 "description": "Sets the new stylesheet text, thereby invalidating all existing <code>CSSStyleId</code>'s and <code>CSSRuleId</code>'s contained by this stylesheet." -
trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp
r82581 r83962 278 278 void InspectorCSSAgent::getStyleSheet(ErrorString* errorString, const String& styleSheetId, RefPtr<InspectorObject>* styleSheetObject) 279 279 { 280 InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, styleSheetId);280 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId); 281 281 if (!inspectorStyleSheet) 282 282 return; … … 285 285 } 286 286 287 void InspectorCSSAgent::getStyleSheetText(ErrorString* errorString, const String& styleSheetId, String* url, String*result)288 { 289 InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, styleSheetId);290 if (!inspectorStyleSheet) 291 return; 292 *url = inspectorStyleSheet->finalURL(); 287 void InspectorCSSAgent::getStyleSheetText(ErrorString* errorString, const String& styleSheetId, String* result) 288 { 289 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId); 290 if (!inspectorStyleSheet) 291 return; 292 293 293 inspectorStyleSheet->text(result); 294 294 } 295 295 296 void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String& styleSheetId, const String& text, bool* success) 297 { 298 InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, styleSheetId); 299 if (!inspectorStyleSheet) { 300 *success = false; 301 return; 302 } 303 304 *success = inspectorStyleSheet->setText(text); 305 if (*success) 296 void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String& styleSheetId, const String& text) 297 { 298 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId); 299 if (!inspectorStyleSheet) 300 return; 301 302 if (inspectorStyleSheet->setText(text)) 306 303 inspectorStyleSheet->reparseStyleSheet(text); 304 else 305 *errorString = "Internal error setting style sheet text."; 307 306 } 308 307 … … 312 311 ASSERT(!compoundId.isEmpty()); 313 312 314 InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, compoundId.styleSheetId());313 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, compoundId.styleSheetId()); 315 314 if (!inspectorStyleSheet) 316 315 return; … … 326 325 ASSERT(!compoundId.isEmpty()); 327 326 328 InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, compoundId.styleSheetId());327 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, compoundId.styleSheetId()); 329 328 if (!inspectorStyleSheet) 330 329 return; … … 340 339 ASSERT(!compoundId.isEmpty()); 341 340 342 InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, compoundId.styleSheetId());341 InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, compoundId.styleSheetId()); 343 342 if (!inspectorStyleSheet) 344 343 return; … … 472 471 } 473 472 474 InspectorStyleSheet* InspectorCSSAgent:: styleSheetForId(ErrorString* errorString, const String& styleSheetId)473 InspectorStyleSheet* InspectorCSSAgent::assertStyleSheetForId(ErrorString* errorString, const String& styleSheetId) 475 474 { 476 475 IdToInspectorStyleSheet::iterator it = m_idToInspectorStyleSheet.find(styleSheetId); -
trunk/Source/WebCore/inspector/InspectorCSSAgent.h
r82433 r83962 67 67 void getAllStyleSheets(ErrorString*, RefPtr<InspectorArray>* styleSheetInfos); 68 68 void getStyleSheet(ErrorString*, const String& styleSheetId, RefPtr<InspectorObject>* result); 69 void getStyleSheetText(ErrorString*, const String& styleSheetId, String* url, String*result);70 void setStyleSheetText(ErrorString*, const String& styleSheetId, const String& text , bool* success);69 void getStyleSheetText(ErrorString*, const String& styleSheetId, String* result); 70 void setStyleSheetText(ErrorString*, const String& styleSheetId, const String& text); 71 71 void setPropertyText(ErrorString*, const RefPtr<InspectorObject>& styleId, int propertyIndex, const String& text, bool overwrite, RefPtr<InspectorObject>* result); 72 72 void toggleProperty(ErrorString*, const RefPtr<InspectorObject>& styleId, int propertyIndex, bool disable, RefPtr<InspectorObject>* result); … … 88 88 InspectorStyleSheet* bindStyleSheet(CSSStyleSheet*); 89 89 InspectorStyleSheet* viaInspectorStyleSheet(Document*, bool createIfAbsent); 90 InspectorStyleSheet* styleSheetForId(ErrorString*, const String&);90 InspectorStyleSheet* assertStyleSheetForId(ErrorString*, const String&); 91 91 String detectOrigin(CSSStyleSheet* pageStyleSheet, Document* ownerDocument); 92 92 -
trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js
r83843 r83962 31 31 WebInspector.CSSStyleModel = function() 32 32 { 33 new WebInspector.CSSStyleModelResourceBinding(this); 33 34 } 34 35 … … 39 40 result.push(WebInspector.CSSRule.parsePayload(ruleArray[i])); 40 41 return result; 42 } 43 44 WebInspector.CSSStyleModel.Events = { 45 StyleSheetChanged: 0 41 46 } 42 47 … … 125 130 var rule = WebInspector.CSSRule.parsePayload(rulePayload); 126 131 successCallback(rule, doesAffectSelectedNode); 127 this._ styleSheetChanged(rule.id.styleSheetId, true);132 this._fireStyleSheetChanged(rule.id.styleSheetId, true); 128 133 } 129 134 … … 147 152 var rule = WebInspector.CSSRule.parsePayload(rulePayload); 148 153 successCallback(rule, doesAffectSelectedNode); 149 this._ styleSheetChanged(rule.id.styleSheetId, true);154 this._fireStyleSheetChanged(rule.id.styleSheetId, true); 150 155 } 151 156 … … 162 167 }, 163 168 164 _ styleSheetChanged: function(styleSheetId, majorChange)169 _fireStyleSheetChanged: function(styleSheetId, majorChange) 165 170 { 166 171 if (!majorChange || !styleSheetId) 167 172 return; 168 173 169 function callback(error, href,content)174 function callback(error, content) 170 175 { 171 176 if (error) 172 177 return; 173 var resource = WebInspector.resourceForURL(href); 174 if (resource && resource.type === WebInspector.Resource.Type.Stylesheet) {175 resource.setContent(content, this._onRevert.bind(this, styleSheetId));176 this.dispatchEventToListeners("stylesheet changed");177 }178 }179 CSSAgent.getStyleSheetText(styleSheetId, callback.bind(this)); 180 },181 182 _onRevert: function(styleSheetId, contentToRevertTo)183 {184 function callback(error, success)185 {186 if (error) 187 return;188 this._styleSheetChanged(styleSheetId, true);189 } 190 CSSAgent.setStyleSheetText(styleSheetId, contentToRevertTo, callback.bind(this));178 179 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleSheetChanged, { styleSheetId: styleSheetId, content: content, majorChange: majorChange }); 180 } 181 if (this.hasEventListeners(WebInspector.CSSStyleModel.Events.StyleSheetChanged)) 182 CSSAgent.getStyleSheetText(styleSheetId, callback.bind(this)); 183 }, 184 185 setStyleSheetText: function(styleSheetId, newText, majorChange, userCallback) 186 { 187 function callback(error) 188 { 189 if (!error) 190 this._fireStyleSheetChanged(this.id, majorChange); 191 192 if (userCallback) 193 userCallback(error); 194 } 195 CSSAgent.setStyleSheetText(styleSheetId, newText, callback.bind(this)); 191 196 } 192 197 } … … 366 371 else { 367 372 userCallback(WebInspector.CSSStyleDeclaration.parsePayload(payload)); 368 WebInspector.cssModel._ styleSheetChanged(this.id.styleSheetId, true);373 WebInspector.cssModel._fireStyleSheetChanged(this.id.styleSheetId, true); 369 374 } 370 375 } … … 487 492 { 488 493 if (style) 489 WebInspector.cssModel._ styleSheetChanged(style.id.styleSheetId, majorChange);494 WebInspector.cssModel._fireStyleSheetChanged(style.id.styleSheetId, majorChange); 490 495 if (userCallback) 491 496 userCallback(style); … … 503 508 return; 504 509 } else 505 WebInspector.cssModel._ styleSheetChanged(style.id.styleSheetId, majorChange);510 WebInspector.cssModel._fireStyleSheetChanged(style.id.styleSheetId, majorChange); 506 511 if (userCallback) 507 512 userCallback(style); … … 541 546 var style = WebInspector.CSSStyleDeclaration.parsePayload(stylePayload); 542 547 userCallback(style); 543 WebInspector.cssModel._ styleSheetChanged(this.ownerStyle.id.styleSheetId, false);548 WebInspector.cssModel._fireStyleSheetChanged(this.ownerStyle.id.styleSheetId, false); 544 549 } 545 550 } … … 584 589 setText: function(newText, majorChange, userCallback) 585 590 { 586 function callback(error , isChangeSuccessful)591 function callback(error) 587 592 { 588 593 if (userCallback) 589 userCallback( isChangeSuccessful);590 if ( isChangeSuccessful)591 WebInspector.cssModel._ styleSheetChanged(this.id, majorChange);594 userCallback(error); 595 if (!error) 596 WebInspector.cssModel._fireStyleSheetChanged(this.id, majorChange); 592 597 } 593 598 … … 595 600 } 596 601 } 602 603 WebInspector.CSSStyleModelResourceBinding = function(cssModel) 604 { 605 this._cssModel = cssModel; 606 this._urlToStyleSheetId = {}; 607 this._styleSheetIdToURL = {}; 608 this._cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this._styleSheetChanged, this); 609 WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this); 610 WebInspector.Resource.registerDomainModelBinding(WebInspector.Resource.Type.Stylesheet, this); 611 } 612 613 WebInspector.CSSStyleModelResourceBinding.prototype = { 614 setContent: function(resource, content, majorChange, userCallback) 615 { 616 if (this._urlToStyleSheetId[resource.url]) { 617 this._innerSetContent(resource.url, content, majorChange, userCallback); 618 return; 619 } 620 this._loadStyleSheetHeaders(this._innerSetContent.bind(this, resource.url, content, majorChange, userCallback)); 621 }, 622 623 _frameNavigated: function(event) 624 { 625 var frameId = event.data; 626 if (!frameId) { 627 // Main frame navigation - clear history. 628 this._urlToStyleSheetId = {}; 629 this._styleSheetIdToURL = {}; 630 } 631 }, 632 633 _innerSetContent: function(url, content, majorChange, userCallback, error) 634 { 635 if (error) { 636 userCallback(error); 637 return; 638 } 639 640 var styleSheetId = this._urlToStyleSheetId[url]; 641 if (!styleSheetId) { 642 if (userCallback) 643 userCallback("No stylesheet found: " + url); 644 return; 645 } 646 this._cssModel.setStyleSheetText(styleSheetId, content, majorChange, userCallback); 647 }, 648 649 _loadStyleSheetHeaders: function(callback) 650 { 651 function didGetAllStyleSheets(error, infos) 652 { 653 if (error) { 654 callback(error); 655 return; 656 } 657 658 for (var i = 0; i < infos.length; ++i) { 659 var info = infos[i]; 660 this._urlToStyleSheetId[info.sourceURL] = info.styleSheetId; 661 this._styleSheetIdToURL[info.styleSheetId] = info.sourceURL; 662 } 663 callback(); 664 } 665 CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this)); 666 }, 667 668 _styleSheetChanged: function(event) 669 { 670 var styleSheetId = event.data.styleSheetId; 671 function setContent() 672 { 673 var url = this._styleSheetIdToURL[styleSheetId]; 674 if (!url) 675 return; 676 677 var resource = WebInspector.resourceForURL(url); 678 if (!resource) 679 return; 680 681 var majorChange = event.data.majorChange; 682 if (majorChange) 683 resource.addRevision(event.data.content); 684 } 685 686 if (!this._styleSheetIdToURL[styleSheetId]) { 687 this._loadStyleSheetHeaders(setContent.bind(this)); 688 return; 689 } 690 setContent.call(this); 691 } 692 } 693 694 WebInspector.CSSStyleModelResourceBinding.prototype.__proto__ = WebInspector.ResourceDomainModelBinding.prototype; -
trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js
r83719 r83962 46 46 WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this); 47 47 WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.Reset, this._debuggerReset, this); 48 49 new WebInspector.DebuggerPresentationModelResourceBinding(this); 48 50 } 49 51 … … 141 143 var script = this._scriptForSourceFileId(sourceFileId); 142 144 var sourceFile = this._sourceFiles[sourceFileId]; 143 var oldSource = sourceFile.content; 144 function didEditScriptSource( error)145 146 function didEditScriptSource(oldSource, error) 145 147 { 146 148 if (!error) { 147 149 sourceFile.content = newSource; 148 this._updateResourceContent(sourceFile, oldSource, newSource); 150 151 var resource = WebInspector.resourceForURL(sourceFile.url); 152 if (resource) 153 resource.addRevision(newSource); 149 154 } 150 155 … … 154 159 this._debuggerPaused(); 155 160 } 156 WebInspector.debuggerModel.editScriptSource(script.sourceID, newSource, didEditScriptSource.bind(this)); 157 }, 158 159 _updateResourceContent: function(sourceFile, oldSource, newSource) 160 { 161 var resource = WebInspector.resourceForURL(sourceFile.url); 162 if (!resource) 163 return; 164 165 function didEditScriptSource(error) 166 { 167 this._updateBreakpointsAfterLiveEdit(sourceFile.id, oldSource, newSource); 168 sourceFile.reload(); 169 } 170 var revertHandle = this.editScriptSource.bind(this, sourceFile.id, oldSource, didEditScriptSource.bind(this)); 171 resource.setContent(newSource, revertHandle); 161 162 var oldSource = sourceFile.requestContent(didReceiveSource.bind(this)); 163 function didReceiveSource(oldSource) 164 { 165 WebInspector.debuggerModel.editScriptSource(script.sourceID, newSource, didEditScriptSource.bind(this, oldSource)); 166 } 172 167 }, 173 168 … … 713 708 } 714 709 } 710 711 WebInspector.DebuggerPresentationModelResourceBinding = function(model) 712 { 713 this._presentationModel = model; 714 WebInspector.Resource.registerDomainModelBinding(WebInspector.Resource.Type.Script, this); 715 } 716 717 WebInspector.DebuggerPresentationModelResourceBinding.prototype = { 718 canSetContent: function(resource) 719 { 720 var sourceFile = this._presentationModel._sourceFileForScript(resource.url) 721 if (!sourceFile) 722 return false; 723 return this._presentationModel.canEditScriptSource(sourceFile.id); 724 }, 725 726 setContent: function(resource, content, majorChange, userCallback) 727 { 728 if (!majorChange) 729 return; 730 731 var sourceFile = this._presentationModel._sourceFileForScript(resource.url); 732 if (!sourceFile) { 733 userCallback("Resource is not editable"); 734 return; 735 } 736 737 resource.requestContent(this._setContentWithInitialContent.bind(this, sourceFile, content, userCallback)); 738 }, 739 740 _setContentWithInitialContent: function(sourceFile, content, userCallback, oldContent) 741 { 742 function callback(error) 743 { 744 if (userCallback) 745 userCallback(error); 746 if (!error) { 747 this._presentationModel._updateBreakpointsAfterLiveEdit(sourceFile.id, oldContent, content); 748 sourceFile.reload(); 749 } 750 } 751 this._presentationModel.editScriptSource(sourceFile.id, content, callback.bind(this)); 752 } 753 } 754 755 WebInspector.DebuggerPresentationModelResourceBinding.prototype.__proto__ = WebInspector.ResourceDomainModelBinding.prototype; -
trunk/Source/WebCore/inspector/front-end/Object.js
r61954 r83962 58 58 }, 59 59 60 hasEventListeners: function(eventType) 61 { 62 if (!("_listeners" in this) || !(eventType in this._listeners)) 63 return false; 64 return true; 65 }, 66 60 67 dispatchEventToListeners: function(eventType, eventData) 61 68 { -
trunk/Source/WebCore/inspector/front-end/Resource.js
r83950 r83962 34 34 this._category = WebInspector.resourceCategories.other; 35 35 this._pendingContentCallbacks = []; 36 this.history = []; 36 37 } 37 38 … … 99 100 } 100 101 } 102 } 103 104 WebInspector.Resource._domainModelBindings = []; 105 106 WebInspector.Resource.registerDomainModelBinding = function(type, binding) 107 { 108 WebInspector.Resource._domainModelBindings[type] = binding; 109 } 110 111 WebInspector.Resource.Events = { 112 RevisionAdded: 0 101 113 } 102 114 … … 691 703 }, 692 704 693 isResourceRevision: function() 694 { 695 return !!this._actualResource; 696 }, 697 698 setContent: function(newContent, onRevert) 705 isEditable: function() 706 { 707 if (this._actualResource) 708 return false; 709 var binding = WebInspector.Resource._domainModelBindings[this.type]; 710 return binding && binding.canSetContent(this); 711 }, 712 713 setContent: function(newContent, majorChange, callback) 714 { 715 if (!this.isEditable(this)) { 716 if (callback) 717 callback("Resource is not editable"); 718 return; 719 } 720 var binding = WebInspector.Resource._domainModelBindings[this.type]; 721 binding.setContent(this, newContent, majorChange, callback); 722 }, 723 724 addRevision: function(newContent) 699 725 { 700 726 var revisionResource = new WebInspector.Resource(null, this.url); 727 revisionResource.frameId = this.frameId; 728 revisionResource.loaderId = this.loaderId; 729 revisionResource.documentURL = this.documentURL; 701 730 revisionResource.type = this.type; 702 731 revisionResource.loader = this.loader; … … 704 733 revisionResource._content = this._content; 705 734 revisionResource._actualResource = this; 706 revisionResource._fireOnRevert = onRevert;707 735 708 736 if (this.finished) … … 722 750 revisionResource._baseRevision = this._baseRevision; 723 751 724 var data = { revision: revisionResource };725 752 this._content = newContent; 726 753 this.timestamp = new Date(); 727 754 728 this.dispatchEventToListeners("content-changed", data); 755 this.history.push(revisionResource); 756 this.dispatchEventToListeners(WebInspector.Resource.Events.RevisionAdded, revisionResource); 729 757 }, 730 758 731 759 revertToThis: function() 732 760 { 733 if (!this._actualResource || !this._fireOnRevert)761 if (!this._actualResource) 734 762 return; 735 763 … … 737 765 { 738 766 if (content) 739 this._ fireOnRevert(content);767 this._actualResource.setContent(content, true); 740 768 } 741 769 this.requestContent(callback.bind(this)); … … 814 842 815 843 WebInspector.Resource.prototype.__proto__ = WebInspector.Object.prototype; 844 845 846 WebInspector.ResourceDomainModelBinding = function() 847 { 848 } 849 850 WebInspector.ResourceDomainModelBinding.prototype = { 851 canSetContent: function() 852 { 853 // Implemented by the domains. 854 return true; 855 }, 856 857 setContent: function(resource, content, majorChange, callback) 858 { 859 // Implemented by the domains. 860 } 861 } -
trunk/Source/WebCore/inspector/front-end/ResourceView.js
r83843 r83962 50 50 case WebInspector.resourceCategories.scripts: 51 51 case WebInspector.resourceCategories.xhr: 52 case WebInspector.resourceCategories.stylesheets: 52 53 return new WebInspector.ResourceSourceFrame(resource); 53 case WebInspector.resourceCategories.stylesheets:54 return new WebInspector.CSSSourceFrame(resource);55 54 case WebInspector.resourceCategories.images: 56 55 return new WebInspector.ImageView(resource); … … 69 68 case WebInspector.resourceCategories.scripts: 70 69 case WebInspector.resourceCategories.xhr: 70 case WebInspector.resourceCategories.stylesheets: 71 71 return resourceView.__proto__ === WebInspector.ResourceSourceFrame.prototype; 72 case WebInspector.resourceCategories.stylesheets:73 return resourceView.__proto__ === WebInspector.CSSSourceFrame.prototype;74 72 case WebInspector.resourceCategories.images: 75 73 return resourceView.__proto__ === WebInspector.ImageView.prototype; … … 141 139 isContentEditable: function() 142 140 { 143 return false; 141 return this._resource.isEditable(); 142 }, 143 144 editContent: function(newText, callback) 145 { 146 this._clearIncrementalUpdateTimer(); 147 var majorChange = true; 148 this._resource.setContent(newText, majorChange, callback); 149 }, 150 151 endEditing: function(oldRange, newRange) 152 { 153 function commitIncrementalEdit() 154 { 155 var majorChange = false; 156 this._resource.setContent(this._textModel.text, majorChange, function() {}); 157 } 158 const updateTimeout = 200; 159 this._incrementalUpdateTimer = setTimeout(commitIncrementalEdit.bind(this), updateTimeout); 160 }, 161 162 _clearIncrementalUpdateTimer: function() 163 { 164 if (this._incrementalUpdateTimer) 165 clearTimeout(this._incrementalUpdateTimer); 166 delete this._incrementalUpdateTimer; 144 167 }, 145 168 … … 156 179 157 180 WebInspector.ResourceSourceFrame.prototype.__proto__ = WebInspector.SourceFrame.prototype; 158 159 160 WebInspector.CSSSourceFrame = function(resource)161 {162 WebInspector.ResourceSourceFrame.call(this, resource);163 this._loadStyleSheet();164 }165 166 WebInspector.CSSSourceFrame.prototype = {167 isContentEditable: function()168 {169 return !!this._styleSheet && !this._resource.isResourceRevision();170 },171 172 _loadStyleSheet: function()173 {174 function didGetAllStyleSheets(error, infos)175 {176 if (error)177 return;178 179 var stylesheetId;180 for (var i = 0; i < infos.length; ++i) {181 var info = infos[i];182 if (info.sourceURL === this._resource.url) {183 stylesheetId = info.styleSheetId;184 break;185 }186 }187 if (!stylesheetId)188 return;189 190 function didCreateForId(styleSheet)191 {192 this._styleSheet = styleSheet;193 }194 WebInspector.CSSStyleSheet.createForId(stylesheetId, didCreateForId.bind(this));195 }196 CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this));197 },198 199 editContent: function(newText, callback)200 {201 if (!this._styleSheet) {202 callback("Stylesheet not found.");203 return;204 }205 206 this._resetIncrementalUpdateTimer();207 208 function didSetText(success)209 {210 var error;211 if (!success)212 error = "Failed to save modified stylesheet " + this._resource.url;213 callback(error);214 }215 this._styleSheet.setText(newText, true, didSetText.bind(this));216 },217 218 endEditing: function(oldRange, newRange)219 {220 function commitIncrementalEdit()221 {222 var majorChange = false;223 this._styleSheet.setText(this._textModel.text, majorChange);224 }225 const updateTimeout = 200;226 this._incrementalUpdateTimer = setTimeout(commitIncrementalEdit.bind(this), updateTimeout);227 },228 229 _resetIncrementalUpdateTimer: function()230 {231 if (this._incrementalUpdateTimer)232 clearTimeout(this._incrementalUpdateTimer);233 delete this._incrementalUpdateTimer;234 }235 }236 237 WebInspector.CSSSourceFrame.prototype.__proto__ = WebInspector.ResourceSourceFrame.prototype; -
trunk/Source/WebCore/inspector/front-end/ResourcesPanel.js
r83845 r83962 261 261 // Insert in the alphabetical order, first frames, then resources. Document resource goes first. 262 262 var children = frameTreeElement.children; 263 for (var i = 0; i < children.length; ++i) { 263 var i; 264 for (i = 0; i < children.length; ++i) { 264 265 var child = children[i]; 265 266 if (!(child instanceof WebInspector.FrameResourceTreeElement)) 266 267 continue; 267 268 268 if (resource.type === WebInspector.Resource.Type.Document || 269 (child._resource.type !== WebInspector.Resource.Type.Document && child._resource.displayName.localeCompare(resource.displayName) > 0)) { 270 frameTreeElement.insertChild(resourceTreeElement, i); 271 return; 272 } 273 } 274 frameTreeElement.appendChild(resourceTreeElement); 269 if (resource.type === WebInspector.Resource.Type.Document || (child._resource.type !== WebInspector.Resource.Type.Document && child._resource.displayName.localeCompare(resource.displayName) > 0)) 270 break; 271 } 272 frameTreeElement.insertChild(resourceTreeElement, i); 273 resourceTreeElement._populateRevisions(); 275 274 }, 276 275 … … 992 991 this._resource = resource; 993 992 this._resource.addEventListener("errors-warnings-updated", this._errorsWarningsUpdated, this); 994 this._resource.addEventListener( "content-changed", this._contentChanged, this);993 this._resource.addEventListener(WebInspector.Resource.Events.RevisionAdded, this._revisionAdded, this); 995 994 this.tooltip = resource.url; 996 995 } … … 1104 1103 }, 1105 1104 1106 _contentChanged: function(event) 1107 { 1108 this.insertChild(new WebInspector.ResourceRevisionTreeElement(this._storagePanel, event.data.revision), 0); 1105 _populateRevisions: function() 1106 { 1107 for (var i = 0; i < this._resource.history.length; ++i) 1108 this._appendRevision(this._resource.history[i]); 1109 }, 1110 1111 _revisionAdded: function(event) 1112 { 1113 this._appendRevision(event.data); 1114 }, 1115 1116 _appendRevision: function(revision) 1117 { 1118 this.insertChild(new WebInspector.ResourceRevisionTreeElement(this._storagePanel, revision), 0); 1109 1119 var oldView = WebInspector.ResourceView.existingResourceViewForResource(this._resource); 1110 1120 if (oldView) { -
trunk/Source/WebCore/inspector/front-end/inspector.html
r83864 r83962 47 47 <script type="text/javascript" src="Object.js"></script> 48 48 <script type="text/javascript" src="Settings.js"></script> 49 <script type="text/javascript" src="CSSStyleModel.js"></script>50 49 <script type="text/javascript" src="Checkbox.js"></script> 51 50 <script type="text/javascript" src="ContextMenu.js"></script> … … 62 61 <script type="text/javascript" src="TimelineGrid.js"></script> 63 62 <script type="text/javascript" src="Resource.js"></script> 63 <script type="text/javascript" src="CSSStyleModel.js"></script> 64 64 <script type="text/javascript" src="NetworkManager.js"></script> 65 65 <script type="text/javascript" src="ResourceTreeModel.js"></script>
Note: See TracChangeset
for help on using the changeset viewer.