Changeset 30931 in webkit
- Timestamp:
- Mar 10, 2008 9:17:38 AM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r30930 r30931 1 2008-03-09 Adam Roben <aroben@apple.com> 2 3 Refactor CSS editing code so we can share it with DOM editing 4 5 Add WebInspector.startEditing, which takes the element to be edited, a 6 committedCallback, a cancelledCallback, and a context parameter. This 7 function takes care of setting up the element for editing, and calls 8 either the cancelledCallback or committedCallback when editing ends. 9 10 Reviewed by Tim. 11 12 * page/inspector/StylesSidebarPane.js: 13 (WebInspector.StylePropertyTreeElement.startEditing): 14 - Call WebInspector.isBeingEdited and WebInspector.startEditing 15 - Removed code now handled by WebInspector.startEditing 16 (WebInspector.StylePropertyTreeElement.editingEnded): 17 - Renamed from endEditing 18 - Removed code now handled by WebInspector.startEditing 19 (WebInspector.StylePropertyTreeElement.editingCancelled): 20 - Renamed from cancelEditing 21 - Changed parameters to match WebInspector.startEditing's 22 cancelledCallback 23 (WebInspector.StylePropertyTreeElement.editingCommitted): 24 - Renamed from commitEditing 25 - Changed parameters to match WebInspector.startEditing's 26 committedCallback 27 * page/inspector/inspector.js: 28 (WebInspector.changeFocus): Changed a call to firstParentWithClassName 29 to firstParentOrSelfWithClassName so that if the focusable element 30 itself is the target it will be recognized. I don't know why this 31 change wasn't needed before this. 32 (WebInspector.isBeingEdited): Added. 33 (WebInspector.startEditing): Added. 34 1 35 2008-03-10 Adam Roben <aroben@apple.com> 2 36 -
trunk/WebCore/page/inspector/StylesSidebarPane.js
r30654 r30931 542 542 return; 543 543 544 if (this.editing || (this.treeOutline.section && !this.treeOutline.section.editable)) 545 return; 546 547 this.editing = true; 548 this.previousTextContent = this.listItemElement.textContent; 549 550 this.listItemElement.addStyleClass("focusable"); 551 this.listItemElement.addStyleClass("editing"); 552 this.wasExpanded = this.expanded; 544 if (WebInspector.isBeingEdited(this.listItemElement) || (this.treeOutline.section && !this.treeOutline.section.editable)) 545 return; 546 547 var wasExpanded = this.expanded; 553 548 this.collapse(); 554 549 // Lie about out children to prevent toggling on click. … … 560 555 window.getSelection().setBaseAndExtent(selectElement, 0, selectElement, 1); 561 556 562 var treeElement = this; 563 this.listItemElement.blurred = function() { treeElement.commitEditing() }; 564 this.listItemElement.handleKeyEvent = function(event) { 565 if (event.keyIdentifier === "Enter") { 566 treeElement.commitEditing(); 567 event.preventDefault(); 568 } else if (event.keyCode === 27) { // Escape key 569 treeElement.cancelEditing(); 570 event.preventDefault(); 571 } 572 }; 573 574 this.previousFocusElement = WebInspector.currentFocusElement; 575 WebInspector.currentFocusElement = this.listItemElement; 576 }, 577 578 endEditing: function() 579 { 580 // Revert the changes done in startEditing(). 581 delete this.listItemElement.blurred; 582 delete this.listItemElement.handleKeyEvent; 583 584 WebInspector.currentFocusElement = this.previousFocusElement; 585 delete this.previousFocusElement; 586 587 delete this.previousTextContent; 588 delete this.editing; 589 590 this.listItemElement.removeStyleClass("focusable"); 591 this.listItemElement.removeStyleClass("editing"); 557 WebInspector.startEditing(this.listItemElement, this.editingCommitted.bind(this), this.editingCancelled.bind(this), wasExpanded); 558 }, 559 560 editingEnded: function(wasExpanded) 561 { 592 562 this.hasChildren = (this.children.length ? true : false); 593 if (this.wasExpanded) { 594 delete this.wasExpanded; 563 if (wasExpanded) 595 564 this.expand(); 596 } 597 }, 598 599 cancelEditing: function() 600 { 601 this.endEditing(); 565 }, 566 567 editingCancelled: function(e, wasExpanded) 568 { 569 this.editingEnded(wasExpanded); 602 570 this.updateTitle(); 603 571 }, 604 572 605 commitEditing: function() 606 { 607 var previousContent = this.previousTextContent; 608 609 this.endEditing(); 610 611 var userInput = this.listItemElement.textContent; 573 editingCommitted: function(e, userInput, previousContent, wasExpanded) 574 { 575 this.editingEnded(); 576 612 577 if (userInput === previousContent) 613 578 return; // nothing changed, so do nothing else -
trunk/WebCore/page/inspector/inspector.js
r30607 r30931 321 321 322 322 if (!nextFocusElement) 323 nextFocusElement = event.target.firstParent WithClass("focusable");323 nextFocusElement = event.target.firstParentOrSelfWithClass("focusable"); 324 324 325 325 this.currentFocusElement = nextFocusElement; … … 1052 1052 1053 1053 return String.vsprintf(string, Array.prototype.slice.call(arguments, 1)); 1054 } 1055 1056 WebInspector.isBeingEdited = function(element) 1057 { 1058 return element.__editing; 1059 } 1060 1061 WebInspector.startEditing = function(element, committedCallback, cancelledCallback, context) 1062 { 1063 if (element.__editing) 1064 return; 1065 element.__editing = true; 1066 1067 var oldText = element.textContent; 1068 var handleKeyEvent = element.handleKeyEvent; 1069 var blurred = element.blurred; 1070 1071 element.addStyleClass("editing"); 1072 element.addStyleClass("focusable"); 1073 1074 var previousFocusElement = WebInspector.currentFocusElement; 1075 1076 function cleanUpAfterEditing() { 1077 delete this.__editing; 1078 1079 this.removeStyleClass("editing"); 1080 this.removeStyleClass("focusable"); 1081 1082 this.handleKeyEvent = handleKeyEvent; 1083 this.blurred = blurred; 1084 1085 WebInspector.currentFocusElement = previousFocusElement; 1086 } 1087 1088 function editingCancelled() { 1089 this.innerText = oldText; 1090 1091 cleanUpAfterEditing.call(this); 1092 1093 cancelledCallback(this, context); 1094 } 1095 1096 function editingCommitted() { 1097 cleanUpAfterEditing.call(this); 1098 1099 committedCallback(this, this.textContent, oldText, context); 1100 } 1101 1102 element.handleKeyEvent = function(event) { 1103 if (event.keyIdentifier === "Enter") { 1104 editingCommitted.call(element); 1105 event.preventDefault(); 1106 } else if (event.keyCode === 27) { // Escape key 1107 editingCancelled.call(element); 1108 event.preventDefault(); 1109 } 1110 } 1111 1112 element.blurred = function() { editingCancelled.call(element); } 1113 1114 WebInspector.currentFocusElement = element; 1054 1115 } 1055 1116
Note: See TracChangeset
for help on using the changeset viewer.