Changeset 107399 in webkit
- Timestamp:
- Feb 10, 2012 5:15:12 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 17 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r107398 r107399 1 2012-02-10 Pavel Feldman <pfeldman@google.com> 2 3 Web Inspector: implement undo for setOuterHTML via undo-ing nested primitive commands. 4 https://bugs.webkit.org/show_bug.cgi?id=78346 5 6 Reviewed by Yury Semikhatsky. 7 8 * inspector/elements/set-outer-html-2-expected.txt: 9 * inspector/elements/set-outer-html-test.js: 10 (initialize_SetOuterHTMLTest.InspectorTest.patchOuterHTML): 11 (initialize_SetOuterHTMLTest.InspectorTest.patchOuterHTMLUseUndo): 12 (initialize_SetOuterHTMLTest.InspectorTest.setOuterHTMLUseUndo.bringBack): 13 (initialize_SetOuterHTMLTest.InspectorTest.setOuterHTMLUseUndo): 14 (initialize_SetOuterHTMLTest.InspectorTest.innerSetOuterHTML): 15 (initialize_SetOuterHTMLTest.InspectorTest._dumpOuterHTML.dumpIdentity): 16 (initialize_SetOuterHTMLTest.InspectorTest._dumpOuterHTML.callback): 17 (initialize_SetOuterHTMLTest.InspectorTest._dumpOuterHTML): 18 (initialize_SetOuterHTMLTest): 19 * inspector/elements/undo-dom-edits-expected.txt: 20 * inspector/elements/undo-set-outer-html-2-expected.txt: Copied from LayoutTests/inspector/elements/set-outer-html-2-expected.txt. 21 * inspector/elements/undo-set-outer-html-2.html: Added. 22 * inspector/elements/undo-set-outer-html-expected.txt: Copied from LayoutTests/inspector/elements/set-outer-html-2-expected.txt. 23 * inspector/elements/undo-set-outer-html.html: Added. 24 1 25 2012-02-10 Csaba Osztrogonác <ossy@webkit.org> 2 26 -
trunk/LayoutTests/inspector/elements/set-outer-html-2-expected.txt
r107242 r107399 113 113 Event NodeInserted: H2 114 114 Event NodeInserted: P 115 Event NodeInserted: UL 116 Event NodeInserted: UL 115 117 Event NodeRemoved: H2 116 118 Event NodeRemoved: P 119 Event NodeRemoved: UL 120 Event NodeRemoved: UL 117 121 ==========8<========== 118 122 <div id="container" style="display:none"> … … 176 180 Wrapper identity: identity 177 181 Event NodeInserted: H2 182 Event NodeInserted: H2 183 Event NodeRemoved: H2 178 184 ==========8<========== 179 185 <div id="container" style="display:none"> -
trunk/LayoutTests/inspector/elements/set-outer-html-test.js
r105262 r107399 45 45 InspectorTest.patchOuterHTML = function(pattern, replacement, next) 46 46 { 47 InspectorTest.addResult("Replacing '" + pattern + "' with '" + replacement + "'\n"); 48 InspectorTest.setOuterHTML(InspectorTest.containerText.replace(pattern, replacement), next); 47 InspectorTest.addResult("Replacing '" + pattern + "' with '" + replacement + "'\n"); 48 InspectorTest.setOuterHTML(InspectorTest.containerText.replace(pattern, replacement), next); 49 } 50 51 InspectorTest.patchOuterHTMLUseUndo = function(pattern, replacement, next) 52 { 53 InspectorTest.addResult("Replacing '" + pattern + "' with '" + replacement + "'\n"); 54 InspectorTest.setOuterHTMLUseUndo(InspectorTest.containerText.replace(pattern, replacement), next); 49 55 } 50 56 … … 60 66 } 61 67 68 InspectorTest.setOuterHTMLUseUndo = function(newText, next) 69 { 70 InspectorTest.innerSetOuterHTML(newText, false, bringBack); 71 72 function bringBack() 73 { 74 InspectorTest.addResult("\nBringing things back\n"); 75 DOMAgent.undo(InspectorTest._dumpOuterHTML.bind(InspectorTest, true, next)); 76 } 77 } 78 62 79 InspectorTest.innerSetOuterHTML = function(newText, last, next) 63 80 { 64 DOMAgent.setOuterHTML(InspectorTest.containerId, newText, dumpOuterHTML); 81 DOMAgent.setOuterHTML(InspectorTest.containerId, newText, InspectorTest._dumpOuterHTML.bind(InspectorTest, last, next)); 82 } 65 83 66 function dumpOuterHTML() 84 InspectorTest._dumpOuterHTML = function(last, next) 85 { 86 RuntimeAgent.evaluate("document.getElementById(\"identity\").wrapperIdentity", dumpIdentity); 87 function dumpIdentity(error, result) 67 88 { 68 RuntimeAgent.evaluate("document.getElementById(\"identity\").wrapperIdentity", dumpIdentity); 69 function dumpIdentity(error, result) 70 { 71 InspectorTest.addResult("Wrapper identity: " + result.value); 72 InspectorTest.events.sort(); 73 for (var i = 0; i < InspectorTest.events.length; ++i) 74 InspectorTest.addResult(InspectorTest.events[i]); 75 InspectorTest.events = []; 76 } 89 InspectorTest.addResult("Wrapper identity: " + result.value); 90 InspectorTest.events.sort(); 91 for (var i = 0; i < InspectorTest.events.length; ++i) 92 InspectorTest.addResult(InspectorTest.events[i]); 93 InspectorTest.events = []; 94 } 77 95 78 96 DOMAgent.getOuterHTML(InspectorTest.containerId, callback); 79 97 80 function callback(error, text) 81 { 82 InspectorTest.addResult("==========8<=========="); 83 InspectorTest.addResult(text); 84 InspectorTest.addResult("==========>8=========="); 85 if (last) 86 InspectorTest.addResult("\n\n\n"); 87 next(); 88 } 98 function callback(error, text) 99 { 100 InspectorTest.addResult("==========8<=========="); 101 InspectorTest.addResult(text); 102 InspectorTest.addResult("==========>8=========="); 103 if (last) 104 InspectorTest.addResult("\n\n\n"); 105 next(); 89 106 } 90 107 } -
trunk/LayoutTests/inspector/elements/undo-dom-edits-expected.txt
r107217 r107399 59 59 Post-undo (initial): 60 60 - <div id="testEditAsHTML"> 61 + <div id="node-to-edit-as-html"> </div>61 + <div id="node-to-edit-as-html">…</div> 62 62 </div> 63 63 -
trunk/LayoutTests/inspector/elements/undo-set-outer-html-2-expected.txt
r107398 r107399 1 Tests DOMAgent.setOuterHTML protocol method (part 2). 2 3 Additional node 1 Tests undo for the DOMAgent.setOuterHTML protocol method (part 2). 2 4 3 5 4 Running: testSetUp … … 30 29 Event AttrRemoved: H2 31 30 Event AttrRemoved: H2 32 Event ChildNodeCountUpdated: UL 31 Event NodeInserted: UL 32 Event NodeRemoved: UL 33 33 ==========8<========== 34 34 <div id="container" style="display:none"> … … 112 112 Wrapper identity: identity 113 113 Event NodeInserted: H2 114 Event NodeInserted: P 115 Event NodeRemoved: H2 116 Event NodeRemoved: P 114 Event NodeRemoved: H2 117 115 ==========8<========== 118 116 <div id="container" style="display:none"> … … 153 151 154 152 Wrapper identity: identity 153 Event NodeRemoved: DIV 155 154 ==========8<========== 156 155 <div id="container" style="display:none"> … … 176 175 Wrapper identity: identity 177 176 Event NodeInserted: H2 177 Event NodeInserted: H2 178 Event NodeRemoved: H2 178 179 ==========8<========== 179 180 <div id="container" style="display:none"> -
trunk/LayoutTests/inspector/elements/undo-set-outer-html-expected.txt
r107398 r107399 1 Tests DOMAgent.setOuterHTML protocol method (part 2).1 Tests undo for the DOMAgent.setOuterHTML protocol method. 2 2 3 Additional node4 3 5 4 Running: testSetUp 6 5 7 Running: testChangeMultipleThings 6 Running: testChangeCharacterData 7 Replacing 'Getting involved' with 'Getting not involved' 8 8 9 Wrapper identity: identity 9 Event AttrModified: H2 10 Event AttrModified: H2 11 Event NodeInserted: UL 12 Event NodeRemoved: UL 10 Event CharacterDataModified: 13 11 ==========8<========== 14 12 <div id="container" style="display:none"> 15 13 <p>WebKit is used by <a href="http://www.apple.com/safari/">Safari</a>, Dashboard, etc..</p> 16 <h2 foo="bar" bar="baz">Gettinginvolved</h2>14 <h2>Getting not involved</h2> 17 15 <p id="identity">There are many ways to get involved. You can:</p> 18 <ul>19 20 </ul>21 <ul>22 <li></li>23 </ul>24 16 </div> 25 17 ==========>8========== … … 28 20 29 21 Wrapper identity: identity 30 Event AttrRemoved: H2 31 Event AttrRemoved: H2 32 Event ChildNodeCountUpdated: UL 22 Event CharacterDataModified: 33 23 ==========8<========== 34 24 <div id="container" style="display:none"> … … 36 26 <h2>Getting involved</h2> 37 27 <p id="identity">There are many ways to get involved. You can:</p> 38 <ul>39 <li></li>40 </ul>41 <ul>42 <li></li>43 </ul>44 28 </div> 45 29 ==========>8========== … … 49 33 50 34 51 Running: testChangeNestingLevel 35 Running: testChangeAttributes 36 Replacing '<a href' with '<a foo="bar" href' 37 52 38 Wrapper identity: identity 53 Event NodeInserted: DIV 54 Event NodeRemoved: UL 39 Event AttrModified: A 40 Event AttrModified: A 41 Event AttrRemoved: A 55 42 ==========8<========== 56 43 <div id="container" style="display:none"> 57 <p>WebKit is used by <a href="http://www.apple.com/safari/">Safari</a>, Dashboard, etc..</p>44 <p>WebKit is used by <a foo="bar" href="http://www.apple.com/safari/">Safari</a>, Dashboard, etc..</p> 58 45 <h2>Getting involved</h2> 59 46 <p id="identity">There are many ways to get involved. You can:</p> 60 <div><ul>61 <li></li>62 </ul></div>63 <ul>64 <li></li>65 </ul>66 47 </div> 67 48 ==========>8========== … … 70 51 71 52 Wrapper identity: identity 72 Event NodeInserted: UL 73 Event NodeRemoved: DIV 53 Event AttrModified: A 54 Event AttrRemoved: A 55 Event AttrRemoved: A 74 56 ==========8<========== 75 57 <div id="container" style="display:none"> … … 77 59 <h2>Getting involved</h2> 78 60 <p id="identity">There are many ways to get involved. You can:</p> 79 <ul>80 <li></li>81 </ul>82 <ul>83 <li></li>84 </ul>85 61 </div> 86 62 ==========>8========== … … 90 66 91 67 92 Running: testSwapNodes 68 Running: testRemoveLastChild 69 Replacing 'Getting involved' with '' 70 93 71 Wrapper identity: identity 94 Event NodeInserted: H2 95 Event NodeRemoved: H2 72 Event NodeRemoved: 96 73 ==========8<========== 97 74 <div id="container" style="display:none"> 98 75 <p>WebKit is used by <a href="http://www.apple.com/safari/">Safari</a>, Dashboard, etc..</p> 99 76 <h2></h2> 100 77 <p id="identity">There are many ways to get involved. You can:</p> 101 <ul> 102 <li></li> 103 </ul> 104 <ul> 105 <li></li> 106 </ul> 107 <h2>Getting involved</h2></div> 78 </div> 108 79 ==========>8========== 109 80 … … 111 82 112 83 Wrapper identity: identity 113 Event NodeInserted: H2 114 Event NodeInserted: P 115 Event NodeRemoved: H2 116 Event NodeRemoved: P 84 Event NodeInserted: 117 85 ==========8<========== 118 86 <div id="container" style="display:none"> … … 120 88 <h2>Getting involved</h2> 121 89 <p id="identity">There are many ways to get involved. You can:</p> 122 <ul>123 <li></li>124 </ul>125 <ul>126 <li></li>127 </ul>128 90 </div> 129 91 ==========>8========== … … 133 95 134 96 135 Running: testEditTwoRoots 97 Running: testSplitNode 98 Replacing 'Getting involved' with 'Getting</h2><h2>involved' 99 136 100 Wrapper identity: identity 137 Event NodeInserted: DIV 101 Event NodeInserted: H2 102 Event NodeInserted: H2 103 Event NodeRemoved: H2 138 104 ==========8<========== 139 105 <div id="container" style="display:none"> 140 106 <p>WebKit is used by <a href="http://www.apple.com/safari/">Safari</a>, Dashboard, etc..</p> 141 <h2>Getting 107 <h2>Getting</h2><h2>involved</h2> 142 108 <p id="identity">There are many ways to get involved. You can:</p> 143 <ul>144 <li></li>145 </ul>146 <ul>147 <li></li>148 </ul>149 109 </div> 150 110 ==========>8========== … … 153 113 154 114 Wrapper identity: identity 115 Event NodeInserted: H2 116 Event NodeRemoved: H2 117 Event NodeRemoved: H2 155 118 ==========8<========== 156 119 <div id="container" style="display:none"> … … 158 121 <h2>Getting involved</h2> 159 122 <p id="identity">There are many ways to get involved. You can:</p> 160 <ul>161 <li></li>162 </ul>163 <ul>164 <li></li>165 </ul>166 123 </div> 167 124 ==========>8========== … … 171 128 172 129 173 Running: test DupeNode174 Replacing '<h2>Getting involved</h2>' with '<h 2>Getting involved</h2><h2>Getting involved</h2>'130 Running: testChangeNodeName 131 Replacing '<h2>Getting involved</h2>' with '<h3>Getting involved</h3>' 175 132 176 133 Wrapper identity: identity 177 Event NodeInserted: H2 134 Event NodeInserted: H3 135 Event NodeRemoved: H2 178 136 ==========8<========== 179 137 <div id="container" style="display:none"> 180 138 <p>WebKit is used by <a href="http://www.apple.com/safari/">Safari</a>, Dashboard, etc..</p> 181 <h 2>Getting involved</h2><h2>Getting involved</h2>139 <h3>Getting involved</h3> 182 140 <p id="identity">There are many ways to get involved. You can:</p> 183 <ul>184 <li></li>185 </ul>186 <ul>187 <li></li>188 </ul>189 141 </div> 190 142 ==========>8========== … … 193 145 194 146 Wrapper identity: identity 195 Event NodeRemoved: H2 147 Event NodeInserted: H2 148 Event NodeRemoved: H3 196 149 ==========8<========== 197 150 <div id="container" style="display:none"> … … 199 152 <h2>Getting involved</h2> 200 153 <p id="identity">There are many ways to get involved. You can:</p> 201 <ul>202 <li></li>203 </ul>204 <ul>205 <li></li>206 </ul>207 154 </div> 208 155 ==========>8========== -
trunk/Source/WebCore/ChangeLog
r107396 r107399 1 2012-02-10 Pavel Feldman <pfeldman@google.com> 2 3 Web Inspector: implement undo for setOuterHTML via undo-ing nested primitive commands. 4 https://bugs.webkit.org/show_bug.cgi?id=78346 5 6 Reviewed by Yury Semikhatsky. 7 8 Tests: inspector/elements/undo-set-outer-html-2.html 9 inspector/elements/undo-set-outer-html.html 10 11 * inspector/DOMEditor.cpp: 12 (WebCore::DOMEditor::RemoveChildAction::RemoveChildAction): 13 (WebCore::DOMEditor::InsertBeforeAction::InsertBeforeAction): 14 (WebCore::DOMEditor::InsertBeforeAction::undo): 15 (WebCore::DOMEditor::RemoveAttributeAction::RemoveAttributeAction): 16 (WebCore::DOMEditor::SetAttributeAction::SetAttributeAction): 17 (WebCore::DOMEditor::SetOuterHTMLAction::SetOuterHTMLAction): 18 (WebCore::DOMEditor::SetOuterHTMLAction::perform): 19 (WebCore::DOMEditor::SetOuterHTMLAction::undo): 20 (DOMEditor::SetOuterHTMLAction): 21 (WebCore::DOMEditor::ReplaceWholeTextAction::ReplaceWholeTextAction): 22 (DOMEditor::ReplaceChildNodeAction): 23 (WebCore::DOMEditor::ReplaceChildNodeAction::ReplaceChildNodeAction): 24 (WebCore::DOMEditor::ReplaceChildNodeAction::perform): 25 (WebCore::DOMEditor::ReplaceChildNodeAction::undo): 26 (WebCore): 27 (DOMEditor::SetNodeValueAction): 28 (WebCore::DOMEditor::SetNodeValueAction::SetNodeValueAction): 29 (WebCore::DOMEditor::SetNodeValueAction::perform): 30 (WebCore::DOMEditor::SetNodeValueAction::undo): 31 (WebCore::DOMEditor::insertBefore): 32 (WebCore::DOMEditor::removeChild): 33 (WebCore::DOMEditor::setAttribute): 34 (WebCore::DOMEditor::removeAttribute): 35 (WebCore::DOMEditor::setOuterHTML): 36 (WebCore::DOMEditor::replaceWholeText): 37 (WebCore::DOMEditor::replaceChild): 38 (WebCore::DOMEditor::setNodeValue): 39 (WebCore::populateErrorString): 40 * inspector/DOMEditor.h: 41 (DOMEditor): 42 * inspector/DOMPatchSupport.cpp: 43 (WebCore::DOMPatchSupport::patchDocument): 44 (WebCore): 45 (WebCore::DOMPatchSupport::DOMPatchSupport): 46 (WebCore::DOMPatchSupport::patchNode): 47 (WebCore::DOMPatchSupport::innerPatchNode): 48 (WebCore::DOMPatchSupport::innerPatchChildren): 49 (WebCore::DOMPatchSupport::insertBeforeAndMarkAsUsed): 50 (WebCore::DOMPatchSupport::removeChildAndMoveToNew): 51 * inspector/DOMPatchSupport.h: 52 (WebCore): 53 (DOMPatchSupport): 54 * inspector/InspectorCSSAgent.cpp: 55 (WebCore::InspectorCSSAgent::StyleSheetAction::perform): 56 (WebCore::InspectorCSSAgent::StyleSheetAction::undo): 57 (InspectorCSSAgent::StyleSheetAction): 58 (WebCore::InspectorCSSAgent::SetStyleSheetTextAction::perform): 59 (WebCore::InspectorCSSAgent::SetStyleSheetTextAction::undo): 60 (WebCore::InspectorCSSAgent::SetPropertyTextAction::perform): 61 (WebCore::InspectorCSSAgent::SetPropertyTextAction::undo): 62 (WebCore::InspectorCSSAgent::TogglePropertyAction::perform): 63 (WebCore::InspectorCSSAgent::TogglePropertyAction::undo): 64 (WebCore::InspectorCSSAgent::setStyleSheetText): 65 (WebCore::InspectorCSSAgent::setPropertyText): 66 (WebCore::InspectorCSSAgent::toggleProperty): 67 (WebCore::InspectorCSSAgent::assertStyleSheetForId): 68 * inspector/InspectorDOMAgent.cpp: 69 (WebCore::InspectorDOMAgent::toErrorString): 70 (WebCore): 71 (WebCore::InspectorDOMAgent::setAttributesAsText): 72 (WebCore::InspectorDOMAgent::setOuterHTML): 73 (WebCore::InspectorDOMAgent::undo): 74 * inspector/InspectorDOMAgent.h: 75 (InspectorDOMAgent): 76 * inspector/InspectorHistory.cpp: 77 (WebCore::InspectorHistory::perform): 78 (WebCore::InspectorHistory::undo): 79 * inspector/InspectorHistory.h: 80 (WebCore): 81 (Action): 82 (InspectorHistory): 83 * inspector/InspectorPageAgent.cpp: 84 (WebCore::InspectorPageAgent::setDocumentContent): 85 * inspector/InspectorStyleSheet.cpp: 86 (WebCore::InspectorStyle::setPropertyText): 87 (WebCore::InspectorStyle::toggleProperty): 88 (WebCore::InspectorStyleSheet::setPropertyText): 89 (WebCore::InspectorStyleSheet::toggleProperty): 90 * inspector/InspectorStyleSheet.h: 91 (InspectorStyle): 92 (InspectorStyleSheet): 93 1 94 2012-02-10 Kentaro Hara <haraken@chromium.org> 2 95 -
trunk/Source/WebCore/inspector/DOMEditor.cpp
r107257 r107399 50 50 namespace WebCore { 51 51 52 class DOMEditor::DOMAction : public InspectorHistory::Action { 53 public: 54 DOMAction(const String& name) : InspectorHistory::Action(name) { } 55 56 virtual bool perform(ErrorString* errorString) 57 { 58 ExceptionCode ec = 0; 59 bool result = perform(ec); 60 if (ec) { 61 ExceptionCodeDescription description(ec); 62 *errorString = description.name; 63 } 64 return result && !ec; 65 } 66 67 virtual bool undo(ErrorString* errorString) 68 { 69 ExceptionCode ec = 0; 70 bool result = undo(ec); 71 if (ec) { 72 ExceptionCodeDescription description(ec); 73 *errorString = description.name; 74 } 75 return result && !ec; 76 } 77 78 virtual bool perform(ExceptionCode&) = 0; 79 80 virtual bool undo(ExceptionCode&) = 0; 52 class DOMEditor::RemoveChildAction : public InspectorHistory::Action { 53 WTF_MAKE_NONCOPYABLE(RemoveChildAction); 54 public: 55 RemoveChildAction(Node* parentNode, Node* node) 56 : InspectorHistory::Action("RemoveChild") 57 , m_parentNode(parentNode) 58 , m_node(node) 59 { 60 } 61 62 virtual bool perform(ExceptionCode& ec) 63 { 64 m_anchorNode = m_node->nextSibling(); 65 return m_parentNode->removeChild(m_node.get(), ec); 66 } 67 68 virtual bool undo(ExceptionCode& ec) 69 { 70 return m_parentNode->insertBefore(m_node.get(), m_anchorNode.get(), ec); 71 } 81 72 82 73 private: … … 86 77 }; 87 78 88 class DOMEditor::RemoveChildAction : public DOMEditor::DOMAction { 89 WTF_MAKE_NONCOPYABLE(RemoveChildAction); 90 public: 91 RemoveChildAction(Node* parentNode, Node* node) 92 : DOMEditor::DOMAction("RemoveChild") 93 , m_parentNode(parentNode) 94 , m_node(node) 95 { 96 } 97 98 virtual bool perform(ExceptionCode& ec) 99 { 100 m_anchorNode = m_node->nextSibling(); 101 return m_parentNode->removeChild(m_node.get(), ec); 102 } 103 104 virtual bool undo(ExceptionCode& ec) 105 { 106 return m_parentNode->insertBefore(m_node.get(), m_anchorNode.get(), ec); 107 } 108 109 private: 110 RefPtr<Node> m_parentNode; 111 RefPtr<Node> m_node; 112 RefPtr<Node> m_anchorNode; 113 }; 114 115 class DOMEditor::InsertBeforeAction : public DOMEditor::DOMAction { 79 class DOMEditor::InsertBeforeAction : public InspectorHistory::Action { 116 80 WTF_MAKE_NONCOPYABLE(InsertBeforeAction); 117 81 public: 118 InsertBeforeAction(Node* parentNode, Node*node, Node* anchorNode)119 : DOMEditor::DOMAction("InsertBefore")82 InsertBeforeAction(Node* parentNode, PassRefPtr<Node> node, Node* anchorNode) 83 : InspectorHistory::Action("InsertBefore") 120 84 , m_parentNode(parentNode) 121 85 , m_node(node) … … 136 100 virtual bool undo(ExceptionCode& ec) 137 101 { 102 if (!m_parentNode->removeChild(m_node.get(), ec)) 103 return false; 138 104 if (m_removeChildAction) 139 105 return m_removeChildAction->undo(ec); 140 141 return m_parentNode->removeChild(m_node.get(), ec); 106 return true; 142 107 } 143 108 … … 149 114 }; 150 115 151 class DOMEditor::RemoveAttributeAction : public DOMEditor::DOMAction {116 class DOMEditor::RemoveAttributeAction : public InspectorHistory::Action { 152 117 WTF_MAKE_NONCOPYABLE(RemoveAttributeAction); 153 118 public: 154 119 RemoveAttributeAction(Element* element, const String& name) 155 : DOMEditor::DOMAction("RemoveAttribute")120 : InspectorHistory::Action("RemoveAttribute") 156 121 , m_element(element) 157 122 , m_name(name) … … 178 143 }; 179 144 180 class DOMEditor::SetAttributeAction : public DOMEditor::DOMAction {145 class DOMEditor::SetAttributeAction : public InspectorHistory::Action { 181 146 WTF_MAKE_NONCOPYABLE(SetAttributeAction); 182 147 public: 183 148 SetAttributeAction(Element* element, const String& name, const String& value) 184 : DOMEditor::DOMAction("SetAttribute")149 : InspectorHistory::Action("SetAttribute") 185 150 , m_element(element) 186 151 , m_name(name) … … 216 181 }; 217 182 218 class DOMEditor::SetOuterHTMLAction : public DOMEditor::DOMAction {183 class DOMEditor::SetOuterHTMLAction : public InspectorHistory::Action { 219 184 WTF_MAKE_NONCOPYABLE(SetOuterHTMLAction); 220 185 public: 221 186 SetOuterHTMLAction(Node* node, const String& html) 222 : DOMEditor::DOMAction("SetOuterHTML")187 : InspectorHistory::Action("SetOuterHTML") 223 188 , m_node(node) 224 189 , m_nextSibling(node->nextSibling()) 225 190 , m_html(html) 226 191 , m_newNode(0) 192 , m_history(adoptPtr(new InspectorHistory())) 193 , m_domEditor(adoptPtr(new DOMEditor(m_history.get()))) 227 194 { 228 195 } … … 231 198 { 232 199 m_oldHTML = createMarkup(m_node.get()); 233 DOMPatchSupport domPatchSupport(m_ node->ownerDocument());200 DOMPatchSupport domPatchSupport(m_domEditor.get(), m_node->ownerDocument()); 234 201 m_newNode = domPatchSupport.patchNode(m_node.get(), m_html, ec); 235 202 return !ec; … … 238 205 virtual bool undo(ExceptionCode& ec) 239 206 { 240 DOMPatchSupport domPatchSupport(m_newNode->ownerDocument()); 241 Node* node = domPatchSupport.patchNode(m_newNode, m_oldHTML, ec); 242 if (ec || !node) 243 return false; 244 // HTML editing could have produced extra nodes. Remove them if necessary. 245 node = node->nextSibling(); 246 247 while (!ec && node && node != m_nextSibling.get()) { 248 Node* nodeToRemove = node; 249 node = node->nextSibling(); 250 nodeToRemove->remove(ec); 251 } 252 return !ec; 207 return m_history->undo(ec); 253 208 } 254 209 … … 264 219 String m_oldHTML; 265 220 Node* m_newNode; 266 }; 267 268 class DOMEditor::ReplaceWholeTextAction : public DOMEditor::DOMAction { 221 OwnPtr<InspectorHistory> m_history; 222 OwnPtr<DOMEditor> m_domEditor; 223 }; 224 225 class DOMEditor::ReplaceWholeTextAction : public InspectorHistory::Action { 269 226 WTF_MAKE_NONCOPYABLE(ReplaceWholeTextAction); 270 227 public: 271 228 ReplaceWholeTextAction(Text* textNode, const String& text) 272 : DOMAction("ReplaceWholeText")229 : InspectorHistory::Action("ReplaceWholeText") 273 230 , m_textNode(textNode) 274 231 , m_text(text) … … 295 252 }; 296 253 254 class DOMEditor::ReplaceChildNodeAction : public InspectorHistory::Action { 255 WTF_MAKE_NONCOPYABLE(ReplaceChildNodeAction); 256 public: 257 ReplaceChildNodeAction(Node* parentNode, PassRefPtr<Node> newNode, Node* oldNode) 258 : InspectorHistory::Action("ReplaceChildNode") 259 , m_parentNode(parentNode) 260 , m_newNode(newNode) 261 , m_oldNode(oldNode) 262 { 263 } 264 265 virtual bool perform(ExceptionCode& ec) 266 { 267 return m_parentNode->replaceChild(m_newNode, m_oldNode.get(), ec); 268 } 269 270 virtual bool undo(ExceptionCode& ec) 271 { 272 return m_parentNode->replaceChild(m_oldNode, m_newNode.get(), ec); 273 } 274 275 private: 276 RefPtr<Node> m_parentNode; 277 RefPtr<Node> m_newNode; 278 RefPtr<Node> m_oldNode; 279 }; 280 281 class DOMEditor::SetNodeValueAction : public InspectorHistory::Action { 282 WTF_MAKE_NONCOPYABLE(SetNodeValueAction); 283 public: 284 SetNodeValueAction(Node* node, const String& value) 285 : InspectorHistory::Action("SetNodeValue") 286 , m_node(node) 287 , m_value(value) 288 { 289 } 290 291 virtual bool perform(ExceptionCode& ec) 292 { 293 m_oldValue = m_node->nodeValue(); 294 m_node->setNodeValue(m_value, ec); 295 return !ec; 296 } 297 298 virtual bool undo(ExceptionCode& ec) 299 { 300 m_node->setNodeValue(m_oldValue, ec); 301 return !ec; 302 } 303 304 private: 305 RefPtr<Node> m_node; 306 String m_value; 307 String m_oldValue; 308 }; 309 297 310 DOMEditor::DOMEditor(InspectorHistory* history) : m_history(history) { } 298 311 299 312 DOMEditor::~DOMEditor() { } 300 313 301 bool DOMEditor::insertBefore(Node* parentNode, Node* node, Node* anchorNode, ErrorString* errorString)302 { 303 return m_history->perform(adoptPtr(new InsertBeforeAction(parentNode, node, anchorNode)), e rrorString);304 } 305 306 bool DOMEditor::removeChild(Node* parentNode, Node* node, E rrorString* errorString)307 { 308 return m_history->perform(adoptPtr(new RemoveChildAction(parentNode, node)), e rrorString);309 } 310 311 bool DOMEditor::setAttribute(Element* element, const String& name, const String& value, E rrorString* errorString)312 { 313 return m_history->perform(adoptPtr(new SetAttributeAction(element, name, value)), e rrorString);314 } 315 316 bool DOMEditor::removeAttribute(Element* element, const String& name, E rrorString* errorString)317 { 318 return m_history->perform(adoptPtr(new RemoveAttributeAction(element, name)), e rrorString);319 } 320 321 bool DOMEditor::setOuterHTML(Node* node, const String& html, Node** newNode, E rrorString* errorString)314 bool DOMEditor::insertBefore(Node* parentNode, PassRefPtr<Node> node, Node* anchorNode, ExceptionCode& ec) 315 { 316 return m_history->perform(adoptPtr(new InsertBeforeAction(parentNode, node, anchorNode)), ec); 317 } 318 319 bool DOMEditor::removeChild(Node* parentNode, Node* node, ExceptionCode& ec) 320 { 321 return m_history->perform(adoptPtr(new RemoveChildAction(parentNode, node)), ec); 322 } 323 324 bool DOMEditor::setAttribute(Element* element, const String& name, const String& value, ExceptionCode& ec) 325 { 326 return m_history->perform(adoptPtr(new SetAttributeAction(element, name, value)), ec); 327 } 328 329 bool DOMEditor::removeAttribute(Element* element, const String& name, ExceptionCode& ec) 330 { 331 return m_history->perform(adoptPtr(new RemoveAttributeAction(element, name)), ec); 332 } 333 334 bool DOMEditor::setOuterHTML(Node* node, const String& html, Node** newNode, ExceptionCode& ec) 322 335 { 323 336 OwnPtr<SetOuterHTMLAction> action = adoptPtr(new SetOuterHTMLAction(node, html)); 324 337 SetOuterHTMLAction* rawAction = action.get(); 325 bool result = m_history->perform(action.release(), e rrorString);338 bool result = m_history->perform(action.release(), ec); 326 339 if (result) 327 340 *newNode = rawAction->newNode(); … … 329 342 } 330 343 344 bool DOMEditor::replaceWholeText(Text* textNode, const String& text, ExceptionCode& ec) 345 { 346 return m_history->perform(adoptPtr(new ReplaceWholeTextAction(textNode, text)), ec); 347 } 348 349 bool DOMEditor::replaceChild(Node* parentNode, PassRefPtr<Node> newNode, Node* oldNode, ExceptionCode& ec) 350 { 351 return m_history->perform(adoptPtr(new ReplaceChildNodeAction(parentNode, newNode, oldNode)), ec); 352 } 353 354 bool DOMEditor::setNodeValue(Node* node, const String& value, ExceptionCode& ec) 355 { 356 return m_history->perform(adoptPtr(new SetNodeValueAction(node, value)), ec); 357 } 358 359 static void populateErrorString(const ExceptionCode& ec, ErrorString* errorString) 360 { 361 if (ec) { 362 ExceptionCodeDescription description(ec); 363 *errorString = description.name; 364 } 365 } 366 367 bool DOMEditor::insertBefore(Node* parentNode, PassRefPtr<Node> node, Node* anchorNode, ErrorString* errorString) 368 { 369 ExceptionCode ec = 0; 370 bool result = insertBefore(parentNode, node, anchorNode, ec); 371 populateErrorString(ec, errorString); 372 return result; 373 } 374 375 bool DOMEditor::removeChild(Node* parentNode, Node* node, ErrorString* errorString) 376 { 377 ExceptionCode ec = 0; 378 bool result = removeChild(parentNode, node, ec); 379 populateErrorString(ec, errorString); 380 return result; 381 } 382 383 bool DOMEditor::setAttribute(Element* element, const String& name, const String& value, ErrorString* errorString) 384 { 385 ExceptionCode ec = 0; 386 bool result = setAttribute(element, name, value, ec); 387 populateErrorString(ec, errorString); 388 return result; 389 } 390 391 bool DOMEditor::removeAttribute(Element* element, const String& name, ErrorString* errorString) 392 { 393 ExceptionCode ec = 0; 394 bool result = removeAttribute(element, name, ec); 395 populateErrorString(ec, errorString); 396 return result; 397 } 398 399 bool DOMEditor::setOuterHTML(Node* node, const String& html, Node** newNode, ErrorString* errorString) 400 { 401 ExceptionCode ec = 0; 402 bool result = setOuterHTML(node, html, newNode, ec); 403 populateErrorString(ec, errorString); 404 return result; 405 } 406 331 407 bool DOMEditor::replaceWholeText(Text* textNode, const String& text, ErrorString* errorString) 332 408 { 333 return m_history->perform(adoptPtr(new ReplaceWholeTextAction(textNode, text)), errorString); 409 ExceptionCode ec = 0; 410 bool result = replaceWholeText(textNode, text, ec); 411 populateErrorString(ec, errorString); 412 return result; 334 413 } 335 414 -
trunk/Source/WebCore/inspector/DOMEditor.h
r107257 r107399 32 32 #define DOMEditor_h 33 33 34 #include "ExceptionCode.h" 35 34 36 #include <wtf/text/WTFString.h> 35 37 … … 51 53 ~DOMEditor(); 52 54 53 bool insertBefore(Node* parentNode, Node*, Node* anchorNode, ErrorString*); 55 bool insertBefore(Node* parentNode, PassRefPtr<Node>, Node* anchorNode, ExceptionCode&); 56 bool removeChild(Node* parentNode, Node*, ExceptionCode&); 57 bool setAttribute(Element*, const String& name, const String& value, ExceptionCode&); 58 bool removeAttribute(Element*, const String& name, ExceptionCode&); 59 bool setOuterHTML(Node*, const String& html, Node** newNode, ExceptionCode&); 60 bool replaceWholeText(Text*, const String& text, ExceptionCode&); 61 bool replaceChild(Node* parentNode, PassRefPtr<Node> newNode, Node* oldNode, ExceptionCode&); 62 bool setNodeValue(Node* parentNode, const String& value, ExceptionCode&); 63 64 bool insertBefore(Node* parentNode, PassRefPtr<Node>, Node* anchorNode, ErrorString*); 54 65 bool removeChild(Node* parentNode, Node*, ErrorString*); 55 66 bool setAttribute(Element*, const String& name, const String& value, ErrorString*); … … 66 77 class SetOuterHTMLAction; 67 78 class ReplaceWholeTextAction; 79 class ReplaceChildNodeAction; 80 class SetNodeValueAction; 68 81 69 82 InspectorHistory* m_history; -
trunk/Source/WebCore/inspector/DOMPatchSupport.cpp
r107380 r107399 36 36 #include "Attribute.h" 37 37 #include "Base64.h" 38 #include "DOMEditor.h" 38 39 #include "Document.h" 39 40 #include "DocumentFragment.h" … … 43 44 #include "HTMLHeadElement.h" 44 45 #include "HTMLNames.h" 46 #include "InspectorHistory.h" 45 47 #include "Node.h" 46 48 … … 68 70 }; 69 71 70 DOMPatchSupport::DOMPatchSupport(Document* document) : m_document(document) { } 72 void DOMPatchSupport::patchDocument(Document* document, const String& markup) 73 { 74 InspectorHistory history; 75 DOMEditor domEditor(&history); 76 DOMPatchSupport patchSupport(&domEditor, document); 77 patchSupport.patchDocument(markup); 78 } 79 80 DOMPatchSupport::DOMPatchSupport(DOMEditor* domEditor, Document* document) 81 : m_domEditor(domEditor) 82 , m_document(document) 83 { 84 } 71 85 72 86 DOMPatchSupport::~DOMPatchSupport() { } … … 80 94 parser->detach(); 81 95 82 ExceptionCode ec = 0;83 96 OwnPtr<Digest> oldInfo = createDigest(m_document->documentElement(), 0); 84 97 OwnPtr<Digest> newInfo = createDigest(newDocument->documentElement(), &m_unusedNodesMap); 85 innerPatchNode(oldInfo.get(), newInfo.get(), ec); 86 87 if ( ec) {98 99 ExceptionCode ec = 0; 100 if (!innerPatchNode(oldInfo.get(), newInfo.get(), ec)) { 88 101 // Fall back to rewrite. 89 102 m_document->write(markup); … … 126 139 newList.append(createDigest(child, 0)); 127 140 128 innerPatchChildren(parentNode, oldList, newList, ec); 129 if (ec) { 141 if (!innerPatchChildren(parentNode, oldList, newList, ec)) { 130 142 // Fall back to total replace. 131 143 ec = 0; 132 parentNode->replaceChild(fragment.release(), node, ec); 133 if (ec) 144 if (!m_domEditor->replaceChild(parentNode, fragment.release(), node, ec)) 134 145 return 0; 135 146 } … … 137 148 } 138 149 139 voidDOMPatchSupport::innerPatchNode(Digest* oldDigest, Digest* newDigest, ExceptionCode& ec)150 bool DOMPatchSupport::innerPatchNode(Digest* oldDigest, Digest* newDigest, ExceptionCode& ec) 140 151 { 141 152 if (oldDigest->m_sha1 == newDigest->m_sha1) 142 return ;153 return true; 143 154 144 155 Node* oldNode = oldDigest->m_node; 145 156 Node* newNode = newDigest->m_node; 146 157 147 if (newNode->nodeType() != oldNode->nodeType() || newNode->nodeName() != oldNode->nodeName()) { 148 oldNode->parentNode()->replaceChild(newNode, oldNode, ec); 149 return; 150 } 151 152 if (oldNode->nodeValue() != newNode->nodeValue()) 153 oldNode->setNodeValue(newNode->nodeValue(), ec); 154 if (ec) 155 return; 158 if (newNode->nodeType() != oldNode->nodeType() || newNode->nodeName() != oldNode->nodeName()) 159 return m_domEditor->replaceChild(oldNode->parentNode(), newNode, oldNode, ec); 160 161 if (oldNode->nodeValue() != newNode->nodeValue()) { 162 if (!m_domEditor->setNodeValue(oldNode, newNode->nodeValue(), ec)) 163 return false; 164 } 156 165 157 166 if (oldNode->nodeType() != Node::ELEMENT_NODE) 158 return ;167 return true; 159 168 160 169 // Patch attributes … … 164 173 // FIXME: Create a function in Element for removing all properties. Take in account whether did/willModifyAttribute are important. 165 174 if (oldElement->hasAttributesWithoutUpdate()) { 166 while (oldElement->attributeCount()) 167 oldElement->removeAttribute(0); 175 while (oldElement->attributeCount()) { 176 Attribute* attr = oldElement->attributeItem(0); 177 if (!m_domEditor->removeAttribute(oldElement, attr->localName(), ec)) 178 return false; 179 } 168 180 } 169 181 … … 173 185 for (size_t i = 0; i < numAttrs; ++i) { 174 186 const Attribute* attribute = newElement->attributeItem(i); 175 oldElement->setAttribute(attribute->name(), attribute->value()); 187 if (!m_domEditor->setAttribute(oldElement, attribute->name().localName(), attribute->value(), ec)) 188 return false; 176 189 } 177 190 } 178 191 } 179 192 180 innerPatchChildren(oldElement, oldDigest->m_children, newDigest->m_children, ec);193 bool result = innerPatchChildren(oldElement, oldDigest->m_children, newDigest->m_children, ec); 181 194 m_unusedNodesMap.remove(newDigest->m_sha1); 195 return result; 182 196 } 183 197 … … 270 284 } 271 285 272 voidDOMPatchSupport::innerPatchChildren(ContainerNode* parentNode, const Vector<OwnPtr<Digest> >& oldList, const Vector<OwnPtr<Digest> >& newList, ExceptionCode& ec)286 bool DOMPatchSupport::innerPatchChildren(ContainerNode* parentNode, const Vector<OwnPtr<Digest> >& oldList, const Vector<OwnPtr<Digest> >& newList, ExceptionCode& ec) 273 287 { 274 288 pair<ResultMap, ResultMap> resultMaps = diff(oldList, newList); … … 310 324 merges.set(newList[anchorCandidate].get(), oldList[i].get()); 311 325 else { 312 removeChild(oldList[i].get(), ec); 313 if (ec) 314 return; 326 if (!removeChildAndMoveToNew(oldList[i].get(), ec)) 327 return false; 315 328 } 316 329 } else { 317 removeChild(oldList[i].get(), ec); 318 if (ec) 319 return; 330 if (!removeChildAndMoveToNew(oldList[i].get(), ec)) 331 return false; 320 332 } 321 333 } … … 349 361 // 2. Patch nodes marked for merge. 350 362 for (HashMap<Digest*, Digest*>::iterator it = merges.begin(); it != merges.end(); ++it) { 351 innerPatchNode(it->second, it->first, ec); 352 if (ec) 353 return; 363 if (!innerPatchNode(it->second, it->first, ec)) 364 return false; 354 365 } 355 366 … … 358 369 if (newMap[i].first || merges.contains(newList[i].get())) 359 370 continue; 360 361 ExceptionCode ec = 0; 362 insertBefore(parentNode, newList[i].get(), parentNode->childNode(i), ec); 363 if (ec) 364 return; 371 if (!insertBeforeAndMarkAsUsed(parentNode, newList[i].get(), parentNode->childNode(i), ec)) 372 return false; 365 373 } 366 374 … … 376 384 continue; // Never move head or body, move the rest of the nodes around them. 377 385 378 parentNode->insertBefore(node, anchorNode, ec);379 if (ec)380 return;381 }386 if (!m_domEditor->insertBefore(parentNode, node.release(), anchorNode, ec)) 387 return false; 388 } 389 return true; 382 390 } 383 391 … … 432 440 } 433 441 434 void DOMPatchSupport::insertBefore(ContainerNode* parentNode, Digest* digest, Node* anchor, ExceptionCode& ec)435 { 436 parentNode->insertBefore(digest->m_node, anchor, ec);442 bool DOMPatchSupport::insertBeforeAndMarkAsUsed(ContainerNode* parentNode, Digest* digest, Node* anchor, ExceptionCode& ec) 443 { 444 bool result = m_domEditor->insertBefore(parentNode, digest->m_node, anchor, ec); 437 445 markNodeAsUsed(digest); 438 } 439 440 void DOMPatchSupport::removeChild(Digest* oldDigest, ExceptionCode& ec) 446 return result; 447 } 448 449 bool DOMPatchSupport::removeChildAndMoveToNew(Digest* oldDigest, ExceptionCode& ec) 441 450 { 442 451 RefPtr<Node> oldNode = oldDigest->m_node; 443 oldNode->parentNode()->removeChild(oldNode.get(), ec); 452 if (!m_domEditor->removeChild(oldNode->parentNode(), oldNode.get(), ec)) 453 return false; 444 454 445 455 // Diff works within levels. In order not to lose the node identity when user … … 448 458 // with matching sha1. If it does, replace it with the original DOM chunk. Chances are 449 459 // high that it will get merged back into the original DOM during the further patching. 450 451 460 UnusedNodesMap::iterator it = m_unusedNodesMap.find(oldDigest->m_sha1); 452 461 if (it != m_unusedNodesMap.end()) { 453 462 Digest* newDigest = it->second; 454 463 Node* newNode = newDigest->m_node; 455 newNode->parentNode()->replaceChild(oldNode, newNode, ec); 464 if (!m_domEditor->replaceChild(newNode->parentNode(), oldNode, newNode, ec)) 465 return false; 456 466 newDigest->m_node = oldNode.get(); 457 467 markNodeAsUsed(newDigest); 458 return; 459 } 460 461 for (size_t i = 0; i < oldDigest->m_children.size(); ++i) 462 removeChild(oldDigest->m_children[i].get(), ec); 468 return true; 469 } 470 471 for (size_t i = 0; i < oldDigest->m_children.size(); ++i) { 472 if (!removeChildAndMoveToNew(oldDigest->m_children[i].get(), ec)) 473 return false; 474 } 475 return true; 463 476 } 464 477 -
trunk/Source/WebCore/inspector/DOMPatchSupport.h
r107257 r107399 43 43 44 44 class ContainerNode; 45 class DOMEditor; 45 46 class Document; 46 47 class NamedNodeMap; … … 52 53 WTF_MAKE_NONCOPYABLE(DOMPatchSupport); 53 54 public: 54 explicit DOMPatchSupport(Document*); 55 static void patchDocument(Document*, const String& markup); 56 57 DOMPatchSupport(DOMEditor*, Document*); 55 58 virtual ~DOMPatchSupport(); 56 59 … … 63 66 typedef HashMap<String, Digest*> UnusedNodesMap; 64 67 65 voidinnerPatchNode(Digest* oldNode, Digest* newNode, ExceptionCode&);68 bool innerPatchNode(Digest* oldNode, Digest* newNode, ExceptionCode&); 66 69 std::pair<ResultMap, ResultMap> diff(const Vector<OwnPtr<Digest> >& oldChildren, const Vector<OwnPtr<Digest> >& newChildren); 67 voidinnerPatchChildren(ContainerNode*, const Vector<OwnPtr<Digest> >& oldChildren, const Vector<OwnPtr<Digest> >& newChildren, ExceptionCode&);70 bool innerPatchChildren(ContainerNode*, const Vector<OwnPtr<Digest> >& oldChildren, const Vector<OwnPtr<Digest> >& newChildren, ExceptionCode&); 68 71 PassOwnPtr<Digest> createDigest(Node*, UnusedNodesMap*); 69 void insertBefore(ContainerNode*, Digest*, Node* anchor, ExceptionCode&);70 void removeChild(Digest*, ExceptionCode&);72 bool insertBeforeAndMarkAsUsed(ContainerNode*, Digest*, Node* anchor, ExceptionCode&); 73 bool removeChildAndMoveToNew(Digest*, ExceptionCode&); 71 74 void markNodeAsUsed(Digest*); 72 75 #ifdef DEBUG_DOM_PATCH_SUPPORT … … 74 77 #endif 75 78 79 DOMEditor* m_domEditor; 76 80 Document* m_document; 77 81 -
trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp
r107220 r107399 229 229 } 230 230 231 virtual bool perform(ErrorString* errorString) 232 { 233 InspectorStyleSheet* styleSheet = m_cssAgent->assertStyleSheetForId(errorString, m_styleSheetId); 231 virtual bool perform(ExceptionCode& ec) 232 { 233 ErrorString errorString; 234 InspectorStyleSheet* styleSheet = m_cssAgent->assertStyleSheetForId(&errorString, m_styleSheetId); 234 235 if (!styleSheet) 235 236 return false; 236 return perform(styleSheet, e rrorString);237 } 238 239 virtual bool undo(E rrorString* errorString)240 { 241 InspectorStyleSheet* styleSheet = m_cssAgent->assertStyleSheetForId( errorString, m_styleSheetId);237 return perform(styleSheet, ec); 238 } 239 240 virtual bool undo(ExceptionCode& ec) 241 { 242 InspectorStyleSheet* styleSheet = m_cssAgent->assertStyleSheetForId(0, m_styleSheetId); 242 243 if (!styleSheet) 243 244 return false; 244 return undo(styleSheet, e rrorString);245 } 246 247 virtual bool perform(InspectorStyleSheet*, E rrorString*) = 0;248 249 virtual bool undo(InspectorStyleSheet*, E rrorString*) = 0;245 return undo(styleSheet, ec); 246 } 247 248 virtual bool perform(InspectorStyleSheet*, ExceptionCode&) = 0; 249 250 virtual bool undo(InspectorStyleSheet*, ExceptionCode&) = 0; 250 251 251 252 protected: … … 263 264 } 264 265 265 virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, E rrorString*)266 virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode&) 266 267 { 267 268 if (!inspectorStyleSheet->getText(&m_oldText)) … … 275 276 } 276 277 277 virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, E rrorString*)278 virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode&) 278 279 { 279 280 if (inspectorStyleSheet->setText(m_oldText)) { … … 306 307 } 307 308 308 virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, E rrorString* errorString)309 virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec) 309 310 { 310 311 String oldText; 311 bool result = inspectorStyleSheet->setPropertyText( errorString, m_cssId, m_propertyIndex, m_text, m_overwrite, &oldText);312 bool result = inspectorStyleSheet->setPropertyText(m_cssId, m_propertyIndex, m_text, m_overwrite, &oldText, ec); 312 313 m_oldText = oldText.stripWhiteSpace(); 313 314 // FIXME: remove this once the model handles this case. … … 317 318 } 318 319 319 virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, E rrorString* errorString)320 virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec) 320 321 { 321 322 String placeholder; 322 return inspectorStyleSheet->setPropertyText( errorString, m_cssId, m_propertyIndex, m_overwrite ? m_oldText : "", true, &placeholder);323 return inspectorStyleSheet->setPropertyText(m_cssId, m_propertyIndex, m_overwrite ? m_oldText : "", true, &placeholder, ec); 323 324 } 324 325 … … 355 356 } 356 357 357 virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, E rrorString* errorString)358 { 359 return inspectorStyleSheet->toggleProperty( errorString, m_cssId, m_propertyIndex, m_disable);360 } 361 362 virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, E rrorString* errorString)363 { 364 return inspectorStyleSheet->toggleProperty(errorString, m_cssId, m_propertyIndex, !m_disable);358 virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec) 359 { 360 return inspectorStyleSheet->toggleProperty(m_cssId, m_propertyIndex, m_disable, ec); 361 } 362 363 virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec) 364 { 365 return inspectorStyleSheet->toggleProperty(m_cssId, m_propertyIndex, !m_disable, ec); 365 366 } 366 367 … … 598 599 void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String& styleSheetId, const String& text) 599 600 { 600 m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(this, styleSheetId, text)), errorString); 601 ExceptionCode ec = 0; 602 m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(this, styleSheetId, text)), ec); 603 *errorString = InspectorDOMAgent::toErrorString(ec); 601 604 m_domAgent->history()->markUndoableState(); 602 605 } … … 611 614 return; 612 615 613 bool success = m_domAgent->history()->perform(adoptPtr(new SetPropertyTextAction(this, compoundId.styleSheetId(), compoundId, propertyIndex, text, overwrite)), errorString); 616 ExceptionCode ec = 0; 617 bool success = m_domAgent->history()->perform(adoptPtr(new SetPropertyTextAction(this, compoundId.styleSheetId(), compoundId, propertyIndex, text, overwrite)), ec); 614 618 if (success) 615 619 result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId)); 620 *errorString = InspectorDOMAgent::toErrorString(ec); 616 621 } 617 622 … … 625 630 return; 626 631 627 bool success = m_domAgent->history()->perform(adoptPtr(new TogglePropertyAction(this, compoundId.styleSheetId(), compoundId, propertyIndex, disable)), errorString); 632 ExceptionCode ec = 0; 633 bool success = m_domAgent->history()->perform(adoptPtr(new TogglePropertyAction(this, compoundId.styleSheetId(), compoundId, propertyIndex, disable)), ec); 628 634 if (success) 629 635 result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId)); 636 *errorString = InspectorDOMAgent::toErrorString(ec); 630 637 m_domAgent->history()->markUndoableState(); 631 638 } -
trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp
r107257 r107399 180 180 } 181 181 182 String InspectorDOMAgent::toErrorString(const ExceptionCode& ec) 183 { 184 if (ec) { 185 ExceptionCodeDescription description(ec); 186 return description.name; 187 } 188 return ""; 189 } 190 182 191 InspectorDOMAgent::InspectorDOMAgent(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorClient* client, InspectorState* inspectorState, InjectedScriptManager* injectedScriptManager) 183 192 : InspectorBaseAgent<InspectorDOMAgent>("DOM", instrumentingAgents, inspectorState) … … 542 551 RefPtr<Element> parsedElement = element->document()->createElement("span", ec); 543 552 if (ec) { 544 *errorString = "Internal error: could not set attribute value";553 *errorString = InspectorDOMAgent::toErrorString(ec); 545 554 return; 546 555 } … … 548 557 toHTMLElement(parsedElement.get())->setInnerHTML("<span " + text + "></span>", ec); 549 558 if (ec) { 550 *errorString = "Could not parse value as attributes";559 *errorString = InspectorDOMAgent::toErrorString(ec); 551 560 return; 552 561 } … … 655 664 { 656 665 if (!nodeId) { 657 DOMPatchSupport domPatchSupport(m_do cument.get());666 DOMPatchSupport domPatchSupport(m_domEditor.get(), m_document.get()); 658 667 domPatchSupport.patchDocument(outerHTML); 659 668 return; … … 1078 1087 void InspectorDOMAgent::undo(ErrorString* errorString) 1079 1088 { 1080 m_history->undo(errorString); 1089 ExceptionCode ec = 0; 1090 m_history->undo(ec); 1091 *errorString = InspectorDOMAgent::toErrorString(ec); 1081 1092 } 1082 1093 -
trunk/Source/WebCore/inspector/InspectorDOMAgent.h
r107257 r107399 107 107 return adoptPtr(new InspectorDOMAgent(instrumentingAgents, pageAgent, client, inspectorState, injectedScriptManager)); 108 108 } 109 110 static String toErrorString(const ExceptionCode&); 109 111 110 112 ~InspectorDOMAgent(); -
trunk/Source/WebCore/inspector/InspectorHistory.cpp
r106953 r107399 44 44 UndoableStateMark() : InspectorHistory::Action("[UndoableState]") { } 45 45 46 virtual bool perform(E rrorString*) { return true; }46 virtual bool perform(ExceptionCode&) { return true; } 47 47 48 virtual bool undo(E rrorString*) { return true; }48 virtual bool undo(ExceptionCode&) { return true; } 49 49 50 50 virtual bool isUndoableStateMark() { return true; } … … 84 84 InspectorHistory::~InspectorHistory() { } 85 85 86 bool InspectorHistory::perform(PassOwnPtr<Action> action, E rrorString* errorString)86 bool InspectorHistory::perform(PassOwnPtr<Action> action, ExceptionCode& ec) 87 87 { 88 if (!action->perform(e rrorString))88 if (!action->perform(ec)) 89 89 return false; 90 90 … … 102 102 } 103 103 104 bool InspectorHistory::undo(E rrorString* errorString)104 bool InspectorHistory::undo(ExceptionCode& ec) 105 105 { 106 106 while (!m_history.isEmpty() && m_history.first()->isUndoableStateMark()) … … 109 109 while (!m_history.isEmpty()) { 110 110 OwnPtr<Action> first = m_history.takeFirst(); 111 if (!first->undo(e rrorString)) {111 if (!first->undo(ec)) { 112 112 m_history.clear(); 113 113 return false; -
trunk/Source/WebCore/inspector/InspectorHistory.h
r106953 r107399 44 44 class Node; 45 45 46 typedef String ErrorString;47 48 46 #if ENABLE(INSPECTOR) 49 47 … … 62 60 virtual void merge(PassOwnPtr<Action>); 63 61 64 virtual bool perform(E rrorString*) = 0;65 virtual bool undo(E rrorString*) = 0;62 virtual bool perform(ExceptionCode&) = 0; 63 virtual bool undo(ExceptionCode&) = 0; 66 64 private: 67 65 String m_name; … … 71 69 virtual ~InspectorHistory(); 72 70 73 bool perform(PassOwnPtr<Action>, E rrorString*);71 bool perform(PassOwnPtr<Action>, ExceptionCode&); 74 72 void markUndoableState(); 75 73 76 bool undo(E rrorString*);74 bool undo(ExceptionCode&); 77 75 void reset(); 78 76 -
trunk/Source/WebCore/inspector/InspectorPageAgent.cpp
r107257 r107399 572 572 return; 573 573 } 574 DOMPatchSupport patcher(document); 575 patcher.patchDocument(html); 574 DOMPatchSupport::patchDocument(document, html); 576 575 } 577 576 -
trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp
r106953 r107399 281 281 // The propertyText (if not empty) is checked to be a valid style declaration (containing at least one property). If not, 282 282 // the method returns false (denoting an error). 283 bool InspectorStyle::setPropertyText( ErrorString* errorString, unsigned index, const String& propertyText, bool overwrite, String* oldText)283 bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText, bool overwrite, String* oldText, ExceptionCode& ec) 284 284 { 285 285 ASSERT(m_parentStyleSheet); … … 287 287 288 288 if (!m_parentStyleSheet->ensureParsedDataReady()) { 289 *errorString = "Internal error: no stylesheet parsed data available";289 ec = NOT_FOUND_ERR; 290 290 return false; 291 291 } … … 304 304 // At least one property + the bogus property added just above should be present. 305 305 if (propertyCount < 2) { 306 *errorString = "Invalid property value";306 ec = SYNTAX_ERR; 307 307 return false; 308 308 } … … 310 310 // Check for a proper propertyText termination (the parser could at least restore to the PROPERTY_NAME state). 311 311 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) { 312 *errorString = "Invalid property value";312 ec = SYNTAX_ERR; 313 313 return false; 314 314 } … … 317 317 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor(m_style.get()); 318 318 if (!sourceData) { 319 *errorString = "Internal error: no CSS rule source found";319 ec = NOT_FOUND_ERR; 320 320 return false; 321 321 } … … 324 324 bool success = styleText(&text); 325 325 if (!success) { 326 *errorString = "Internal error: could not fetch style text";326 ec = NOT_FOUND_ERR; 327 327 return false; 328 328 } … … 338 338 } 339 339 340 bool InspectorStyle::toggleProperty( ErrorString* errorString, unsigned index, bool disable)340 bool InspectorStyle::toggleProperty(unsigned index, bool disable, ExceptionCode& ec) 341 341 { 342 342 ASSERT(m_parentStyleSheet); 343 343 if (!m_parentStyleSheet->ensureParsedDataReady()) { 344 *errorString = "Can toggle only source-based properties";344 ec = NO_MODIFICATION_ALLOWED_ERR; 345 345 return false; 346 346 } … … 348 348 RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor(m_style.get()); 349 349 if (!sourceData) { 350 *errorString = "Internal error: No source data for the style found";350 ec = NOT_FOUND_ERR; 351 351 return false; 352 352 } … … 355 355 bool success = styleText(&text); 356 356 if (!success) { 357 *errorString = "Internal error: could not fetch style text";357 ec = NOT_FOUND_ERR; 358 358 return false; 359 359 } … … 362 362 populateAllProperties(&allProperties); 363 363 if (index >= allProperties.size()) { 364 *errorString = "Property index is outside of property range";364 ec = INDEX_SIZE_ERR; 365 365 return false; 366 366 } … … 869 869 } 870 870 871 bool InspectorStyleSheet::setPropertyText( ErrorString* errorString, const InspectorCSSId& id, unsigned propertyIndex, const String& text, bool overwrite, String* oldText)871 bool InspectorStyleSheet::setPropertyText(const InspectorCSSId& id, unsigned propertyIndex, const String& text, bool overwrite, String* oldText, ExceptionCode& ec) 872 872 { 873 873 RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); 874 874 if (!inspectorStyle) { 875 *errorString = "No style found for given id";876 return false; 877 } 878 879 return inspectorStyle->setPropertyText( errorString, propertyIndex, text, overwrite, oldText);880 } 881 882 bool InspectorStyleSheet::toggleProperty( ErrorString* errorString, const InspectorCSSId& id, unsigned propertyIndex, bool disable)875 ec = NOT_FOUND_ERR; 876 return false; 877 } 878 879 return inspectorStyle->setPropertyText(propertyIndex, text, overwrite, oldText, ec); 880 } 881 882 bool InspectorStyleSheet::toggleProperty(const InspectorCSSId& id, unsigned propertyIndex, bool disable, ExceptionCode& ec) 883 883 { 884 884 RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); 885 885 if (!inspectorStyle) { 886 *errorString = "No style found for given id";887 return false; 888 } 889 890 bool success = inspectorStyle->toggleProperty( errorString, propertyIndex, disable);886 ec = NOT_FOUND_ERR; 887 return false; 888 } 889 890 bool success = inspectorStyle->toggleProperty(propertyIndex, disable, ec); 891 891 if (success) { 892 892 if (disable) -
trunk/Source/WebCore/inspector/InspectorStyleSheet.h
r106953 r107399 27 27 28 28 #include "CSSPropertySourceData.h" 29 #include "ExceptionCode.h" 29 30 #include "InspectorStyleTextEditor.h" 30 31 #include "InspectorValues.h" … … 132 133 PassRefPtr<InspectorArray> buildArrayForComputedStyle() const; 133 134 bool hasDisabledProperties() const { return !m_disabledProperties.isEmpty(); } 134 bool setPropertyText( ErrorString*, unsigned index, const String& text, bool overwrite, String* oldText);135 bool toggleProperty( ErrorString*, unsigned index, bool disable);135 bool setPropertyText(unsigned index, const String& text, bool overwrite, String* oldText, ExceptionCode&); 136 bool toggleProperty(unsigned index, bool disable, ExceptionCode&); 136 137 137 138 private: … … 175 176 PassRefPtr<InspectorObject> buildObjectForRule(CSSStyleRule*); 176 177 PassRefPtr<InspectorObject> buildObjectForStyle(CSSStyleDeclaration*); 177 bool setPropertyText( ErrorString*, const InspectorCSSId&, unsigned propertyIndex, const String& text, bool overwrite, String* oldPropertyText);178 bool toggleProperty( ErrorString*, const InspectorCSSId&, unsigned propertyIndex, bool disable);178 bool setPropertyText(const InspectorCSSId&, unsigned propertyIndex, const String& text, bool overwrite, String* oldPropertyText, ExceptionCode&); 179 bool toggleProperty(const InspectorCSSId&, unsigned propertyIndex, bool disable, ExceptionCode&); 179 180 180 181 virtual bool getText(String* result) const;
Note: See TracChangeset
for help on using the changeset viewer.