Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Side by Side Diff: Source/core/inspector/DOMEditor.cpp

Issue 135703002: Update inspector classes to use OVERRIDE / FINAL when needed (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: No change under web/ Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/inspector/AsyncCallStackTracker.cpp ('k') | Source/core/inspector/InjectedScript.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 28 matching lines...) Expand all
39 #include "core/dom/Text.h" 39 #include "core/dom/Text.h"
40 #include "core/editing/markup.h" 40 #include "core/editing/markup.h"
41 #include "core/inspector/DOMPatchSupport.h" 41 #include "core/inspector/DOMPatchSupport.h"
42 #include "core/inspector/InspectorHistory.h" 42 #include "core/inspector/InspectorHistory.h"
43 #include "wtf/RefPtr.h" 43 #include "wtf/RefPtr.h"
44 44
45 using namespace std; 45 using namespace std;
46 46
47 namespace WebCore { 47 namespace WebCore {
48 48
49 class DOMEditor::RemoveChildAction : public InspectorHistory::Action { 49 class DOMEditor::RemoveChildAction FINAL : public InspectorHistory::Action {
50 WTF_MAKE_NONCOPYABLE(RemoveChildAction); 50 WTF_MAKE_NONCOPYABLE(RemoveChildAction);
51 public: 51 public:
52 RemoveChildAction(Node* parentNode, Node* node) 52 RemoveChildAction(Node* parentNode, Node* node)
53 : InspectorHistory::Action("RemoveChild") 53 : InspectorHistory::Action("RemoveChild")
54 , m_parentNode(parentNode) 54 , m_parentNode(parentNode)
55 , m_node(node) 55 , m_node(node)
56 { 56 {
57 } 57 }
58 58
59 virtual bool perform(ExceptionState& exceptionState) 59 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
60 { 60 {
61 m_anchorNode = m_node->nextSibling(); 61 m_anchorNode = m_node->nextSibling();
62 return redo(exceptionState); 62 return redo(exceptionState);
63 } 63 }
64 64
65 virtual bool undo(ExceptionState& exceptionState) 65 virtual bool undo(ExceptionState& exceptionState) OVERRIDE
66 { 66 {
67 m_parentNode->insertBefore(m_node.get(), m_anchorNode.get(), exceptionSt ate); 67 m_parentNode->insertBefore(m_node.get(), m_anchorNode.get(), exceptionSt ate);
68 return !exceptionState.hadException(); 68 return !exceptionState.hadException();
69 } 69 }
70 70
71 virtual bool redo(ExceptionState& exceptionState) 71 virtual bool redo(ExceptionState& exceptionState) OVERRIDE
72 { 72 {
73 m_parentNode->removeChild(m_node.get(), exceptionState); 73 m_parentNode->removeChild(m_node.get(), exceptionState);
74 return !exceptionState.hadException(); 74 return !exceptionState.hadException();
75 } 75 }
76 76
77 private: 77 private:
78 RefPtr<Node> m_parentNode; 78 RefPtr<Node> m_parentNode;
79 RefPtr<Node> m_node; 79 RefPtr<Node> m_node;
80 RefPtr<Node> m_anchorNode; 80 RefPtr<Node> m_anchorNode;
81 }; 81 };
82 82
83 class DOMEditor::InsertBeforeAction : public InspectorHistory::Action { 83 class DOMEditor::InsertBeforeAction FINAL : public InspectorHistory::Action {
84 WTF_MAKE_NONCOPYABLE(InsertBeforeAction); 84 WTF_MAKE_NONCOPYABLE(InsertBeforeAction);
85 public: 85 public:
86 InsertBeforeAction(Node* parentNode, PassRefPtr<Node> node, Node* anchorNode ) 86 InsertBeforeAction(Node* parentNode, PassRefPtr<Node> node, Node* anchorNode )
87 : InspectorHistory::Action("InsertBefore") 87 : InspectorHistory::Action("InsertBefore")
88 , m_parentNode(parentNode) 88 , m_parentNode(parentNode)
89 , m_node(node) 89 , m_node(node)
90 , m_anchorNode(anchorNode) 90 , m_anchorNode(anchorNode)
91 { 91 {
92 } 92 }
93 93
94 virtual bool perform(ExceptionState& exceptionState) 94 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
95 { 95 {
96 if (m_node->parentNode()) { 96 if (m_node->parentNode()) {
97 m_removeChildAction = adoptPtr(new RemoveChildAction(m_node->parentN ode(), m_node.get())); 97 m_removeChildAction = adoptPtr(new RemoveChildAction(m_node->parentN ode(), m_node.get()));
98 if (!m_removeChildAction->perform(exceptionState)) 98 if (!m_removeChildAction->perform(exceptionState))
99 return false; 99 return false;
100 } 100 }
101 m_parentNode->insertBefore(m_node.get(), m_anchorNode.get(), exceptionSt ate); 101 m_parentNode->insertBefore(m_node.get(), m_anchorNode.get(), exceptionSt ate);
102 return !exceptionState.hadException(); 102 return !exceptionState.hadException();
103 } 103 }
104 104
105 virtual bool undo(ExceptionState& exceptionState) 105 virtual bool undo(ExceptionState& exceptionState) OVERRIDE
106 { 106 {
107 m_parentNode->removeChild(m_node.get(), exceptionState); 107 m_parentNode->removeChild(m_node.get(), exceptionState);
108 if (exceptionState.hadException()) 108 if (exceptionState.hadException())
109 return false; 109 return false;
110 if (m_removeChildAction) 110 if (m_removeChildAction)
111 return m_removeChildAction->undo(exceptionState); 111 return m_removeChildAction->undo(exceptionState);
112 return true; 112 return true;
113 } 113 }
114 114
115 virtual bool redo(ExceptionState& exceptionState) 115 virtual bool redo(ExceptionState& exceptionState) OVERRIDE
116 { 116 {
117 if (m_removeChildAction && !m_removeChildAction->redo(exceptionState)) 117 if (m_removeChildAction && !m_removeChildAction->redo(exceptionState))
118 return false; 118 return false;
119 m_parentNode->insertBefore(m_node.get(), m_anchorNode.get(), exceptionSt ate); 119 m_parentNode->insertBefore(m_node.get(), m_anchorNode.get(), exceptionSt ate);
120 return !exceptionState.hadException(); 120 return !exceptionState.hadException();
121 } 121 }
122 122
123 private: 123 private:
124 RefPtr<Node> m_parentNode; 124 RefPtr<Node> m_parentNode;
125 RefPtr<Node> m_node; 125 RefPtr<Node> m_node;
126 RefPtr<Node> m_anchorNode; 126 RefPtr<Node> m_anchorNode;
127 OwnPtr<RemoveChildAction> m_removeChildAction; 127 OwnPtr<RemoveChildAction> m_removeChildAction;
128 }; 128 };
129 129
130 class DOMEditor::RemoveAttributeAction : public InspectorHistory::Action { 130 class DOMEditor::RemoveAttributeAction FINAL : public InspectorHistory::Action {
131 WTF_MAKE_NONCOPYABLE(RemoveAttributeAction); 131 WTF_MAKE_NONCOPYABLE(RemoveAttributeAction);
132 public: 132 public:
133 RemoveAttributeAction(Element* element, const AtomicString& name) 133 RemoveAttributeAction(Element* element, const AtomicString& name)
134 : InspectorHistory::Action("RemoveAttribute") 134 : InspectorHistory::Action("RemoveAttribute")
135 , m_element(element) 135 , m_element(element)
136 , m_name(name) 136 , m_name(name)
137 { 137 {
138 } 138 }
139 139
140 virtual bool perform(ExceptionState& exceptionState) 140 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
141 { 141 {
142 m_value = m_element->getAttribute(m_name); 142 m_value = m_element->getAttribute(m_name);
143 return redo(exceptionState); 143 return redo(exceptionState);
144 } 144 }
145 145
146 virtual bool undo(ExceptionState& exceptionState) 146 virtual bool undo(ExceptionState& exceptionState) OVERRIDE
147 { 147 {
148 m_element->setAttribute(m_name, m_value, exceptionState); 148 m_element->setAttribute(m_name, m_value, exceptionState);
149 return true; 149 return true;
150 } 150 }
151 151
152 virtual bool redo(ExceptionState&) 152 virtual bool redo(ExceptionState&) OVERRIDE
153 { 153 {
154 m_element->removeAttribute(m_name); 154 m_element->removeAttribute(m_name);
155 return true; 155 return true;
156 } 156 }
157 157
158 private: 158 private:
159 RefPtr<Element> m_element; 159 RefPtr<Element> m_element;
160 AtomicString m_name; 160 AtomicString m_name;
161 AtomicString m_value; 161 AtomicString m_value;
162 }; 162 };
163 163
164 class DOMEditor::SetAttributeAction : public InspectorHistory::Action { 164 class DOMEditor::SetAttributeAction FINAL : public InspectorHistory::Action {
165 WTF_MAKE_NONCOPYABLE(SetAttributeAction); 165 WTF_MAKE_NONCOPYABLE(SetAttributeAction);
166 public: 166 public:
167 SetAttributeAction(Element* element, const AtomicString& name, const AtomicS tring& value) 167 SetAttributeAction(Element* element, const AtomicString& name, const AtomicS tring& value)
168 : InspectorHistory::Action("SetAttribute") 168 : InspectorHistory::Action("SetAttribute")
169 , m_element(element) 169 , m_element(element)
170 , m_name(name) 170 , m_name(name)
171 , m_value(value) 171 , m_value(value)
172 , m_hadAttribute(false) 172 , m_hadAttribute(false)
173 { 173 {
174 } 174 }
175 175
176 virtual bool perform(ExceptionState& exceptionState) 176 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
177 { 177 {
178 m_hadAttribute = m_element->hasAttribute(m_name); 178 m_hadAttribute = m_element->hasAttribute(m_name);
179 if (m_hadAttribute) 179 if (m_hadAttribute)
180 m_oldValue = m_element->getAttribute(m_name); 180 m_oldValue = m_element->getAttribute(m_name);
181 return redo(exceptionState); 181 return redo(exceptionState);
182 } 182 }
183 183
184 virtual bool undo(ExceptionState& exceptionState) 184 virtual bool undo(ExceptionState& exceptionState) OVERRIDE
185 { 185 {
186 if (m_hadAttribute) 186 if (m_hadAttribute)
187 m_element->setAttribute(m_name, m_oldValue, exceptionState); 187 m_element->setAttribute(m_name, m_oldValue, exceptionState);
188 else 188 else
189 m_element->removeAttribute(m_name); 189 m_element->removeAttribute(m_name);
190 return true; 190 return true;
191 } 191 }
192 192
193 virtual bool redo(ExceptionState& exceptionState) 193 virtual bool redo(ExceptionState& exceptionState) OVERRIDE
194 { 194 {
195 m_element->setAttribute(m_name, m_value, exceptionState); 195 m_element->setAttribute(m_name, m_value, exceptionState);
196 return true; 196 return true;
197 } 197 }
198 198
199 private: 199 private:
200 RefPtr<Element> m_element; 200 RefPtr<Element> m_element;
201 AtomicString m_name; 201 AtomicString m_name;
202 AtomicString m_value; 202 AtomicString m_value;
203 bool m_hadAttribute; 203 bool m_hadAttribute;
204 AtomicString m_oldValue; 204 AtomicString m_oldValue;
205 }; 205 };
206 206
207 class DOMEditor::SetOuterHTMLAction : public InspectorHistory::Action { 207 class DOMEditor::SetOuterHTMLAction FINAL : public InspectorHistory::Action {
208 WTF_MAKE_NONCOPYABLE(SetOuterHTMLAction); 208 WTF_MAKE_NONCOPYABLE(SetOuterHTMLAction);
209 public: 209 public:
210 SetOuterHTMLAction(Node* node, const String& html) 210 SetOuterHTMLAction(Node* node, const String& html)
211 : InspectorHistory::Action("SetOuterHTML") 211 : InspectorHistory::Action("SetOuterHTML")
212 , m_node(node) 212 , m_node(node)
213 , m_nextSibling(node->nextSibling()) 213 , m_nextSibling(node->nextSibling())
214 , m_html(html) 214 , m_html(html)
215 , m_newNode(0) 215 , m_newNode(0)
216 , m_history(adoptPtr(new InspectorHistory())) 216 , m_history(adoptPtr(new InspectorHistory()))
217 , m_domEditor(adoptPtr(new DOMEditor(m_history.get()))) 217 , m_domEditor(adoptPtr(new DOMEditor(m_history.get())))
218 { 218 {
219 } 219 }
220 220
221 virtual bool perform(ExceptionState& exceptionState) 221 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
222 { 222 {
223 m_oldHTML = createMarkup(m_node.get()); 223 m_oldHTML = createMarkup(m_node.get());
224 ASSERT(m_node->ownerDocument()); 224 ASSERT(m_node->ownerDocument());
225 DOMPatchSupport domPatchSupport(m_domEditor.get(), *m_node->ownerDocumen t()); 225 DOMPatchSupport domPatchSupport(m_domEditor.get(), *m_node->ownerDocumen t());
226 m_newNode = domPatchSupport.patchNode(m_node.get(), m_html, exceptionSta te); 226 m_newNode = domPatchSupport.patchNode(m_node.get(), m_html, exceptionSta te);
227 return !exceptionState.hadException(); 227 return !exceptionState.hadException();
228 } 228 }
229 229
230 virtual bool undo(ExceptionState& exceptionState) 230 virtual bool undo(ExceptionState& exceptionState) OVERRIDE
231 { 231 {
232 return m_history->undo(exceptionState); 232 return m_history->undo(exceptionState);
233 } 233 }
234 234
235 virtual bool redo(ExceptionState& exceptionState) 235 virtual bool redo(ExceptionState& exceptionState) OVERRIDE
236 { 236 {
237 return m_history->redo(exceptionState); 237 return m_history->redo(exceptionState);
238 } 238 }
239 239
240 Node* newNode() 240 Node* newNode()
241 { 241 {
242 return m_newNode; 242 return m_newNode;
243 } 243 }
244 244
245 private: 245 private:
246 RefPtr<Node> m_node; 246 RefPtr<Node> m_node;
247 RefPtr<Node> m_nextSibling; 247 RefPtr<Node> m_nextSibling;
248 String m_html; 248 String m_html;
249 String m_oldHTML; 249 String m_oldHTML;
250 Node* m_newNode; 250 Node* m_newNode;
251 OwnPtr<InspectorHistory> m_history; 251 OwnPtr<InspectorHistory> m_history;
252 OwnPtr<DOMEditor> m_domEditor; 252 OwnPtr<DOMEditor> m_domEditor;
253 }; 253 };
254 254
255 class DOMEditor::ReplaceWholeTextAction : public InspectorHistory::Action { 255 class DOMEditor::ReplaceWholeTextAction FINAL : public InspectorHistory::Action {
256 WTF_MAKE_NONCOPYABLE(ReplaceWholeTextAction); 256 WTF_MAKE_NONCOPYABLE(ReplaceWholeTextAction);
257 public: 257 public:
258 ReplaceWholeTextAction(Text* textNode, const String& text) 258 ReplaceWholeTextAction(Text* textNode, const String& text)
259 : InspectorHistory::Action("ReplaceWholeText") 259 : InspectorHistory::Action("ReplaceWholeText")
260 , m_textNode(textNode) 260 , m_textNode(textNode)
261 , m_text(text) 261 , m_text(text)
262 { 262 {
263 } 263 }
264 264
265 virtual bool perform(ExceptionState& exceptionState) 265 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
266 { 266 {
267 m_oldText = m_textNode->wholeText(); 267 m_oldText = m_textNode->wholeText();
268 return redo(exceptionState); 268 return redo(exceptionState);
269 } 269 }
270 270
271 virtual bool undo(ExceptionState&) 271 virtual bool undo(ExceptionState&) OVERRIDE
272 { 272 {
273 m_textNode->replaceWholeText(m_oldText); 273 m_textNode->replaceWholeText(m_oldText);
274 return true; 274 return true;
275 } 275 }
276 276
277 virtual bool redo(ExceptionState&) 277 virtual bool redo(ExceptionState&) OVERRIDE
278 { 278 {
279 m_textNode->replaceWholeText(m_text); 279 m_textNode->replaceWholeText(m_text);
280 return true; 280 return true;
281 } 281 }
282 282
283 private: 283 private:
284 RefPtr<Text> m_textNode; 284 RefPtr<Text> m_textNode;
285 String m_text; 285 String m_text;
286 String m_oldText; 286 String m_oldText;
287 }; 287 };
288 288
289 class DOMEditor::ReplaceChildNodeAction : public InspectorHistory::Action { 289 class DOMEditor::ReplaceChildNodeAction FINAL : public InspectorHistory::Action {
290 WTF_MAKE_NONCOPYABLE(ReplaceChildNodeAction); 290 WTF_MAKE_NONCOPYABLE(ReplaceChildNodeAction);
291 public: 291 public:
292 ReplaceChildNodeAction(Node* parentNode, PassRefPtr<Node> newNode, Node* old Node) 292 ReplaceChildNodeAction(Node* parentNode, PassRefPtr<Node> newNode, Node* old Node)
293 : InspectorHistory::Action("ReplaceChildNode") 293 : InspectorHistory::Action("ReplaceChildNode")
294 , m_parentNode(parentNode) 294 , m_parentNode(parentNode)
295 , m_newNode(newNode) 295 , m_newNode(newNode)
296 , m_oldNode(oldNode) 296 , m_oldNode(oldNode)
297 { 297 {
298 } 298 }
299 299
300 virtual bool perform(ExceptionState& exceptionState) 300 virtual bool perform(ExceptionState& exceptionState) OVERRIDE
301 { 301 {
302 return redo(exceptionState); 302 return redo(exceptionState);
303 } 303 }
304 304
305 virtual bool undo(ExceptionState& exceptionState) 305 virtual bool undo(ExceptionState& exceptionState) OVERRIDE
306 { 306 {
307 m_parentNode->replaceChild(m_oldNode, m_newNode.get(), exceptionState); 307 m_parentNode->replaceChild(m_oldNode, m_newNode.get(), exceptionState);
308 return !exceptionState.hadException(); 308 return !exceptionState.hadException();
309 } 309 }
310 310
311 virtual bool redo(ExceptionState& exceptionState) 311 virtual bool redo(ExceptionState& exceptionState) OVERRIDE
312 { 312 {
313 m_parentNode->replaceChild(m_newNode, m_oldNode.get(), exceptionState); 313 m_parentNode->replaceChild(m_newNode, m_oldNode.get(), exceptionState);
314 return !exceptionState.hadException(); 314 return !exceptionState.hadException();
315 } 315 }
316 316
317 private: 317 private:
318 RefPtr<Node> m_parentNode; 318 RefPtr<Node> m_parentNode;
319 RefPtr<Node> m_newNode; 319 RefPtr<Node> m_newNode;
320 RefPtr<Node> m_oldNode; 320 RefPtr<Node> m_oldNode;
321 }; 321 };
322 322
323 class DOMEditor::SetNodeValueAction : public InspectorHistory::Action { 323 class DOMEditor::SetNodeValueAction FINAL : public InspectorHistory::Action {
324 WTF_MAKE_NONCOPYABLE(SetNodeValueAction); 324 WTF_MAKE_NONCOPYABLE(SetNodeValueAction);
325 public: 325 public:
326 SetNodeValueAction(Node* node, const String& value) 326 SetNodeValueAction(Node* node, const String& value)
327 : InspectorHistory::Action("SetNodeValue") 327 : InspectorHistory::Action("SetNodeValue")
328 , m_node(node) 328 , m_node(node)
329 , m_value(value) 329 , m_value(value)
330 { 330 {
331 } 331 }
332 332
333 virtual bool perform(ExceptionState&) 333 virtual bool perform(ExceptionState&) OVERRIDE
334 { 334 {
335 m_oldValue = m_node->nodeValue(); 335 m_oldValue = m_node->nodeValue();
336 return redo(IGNORE_EXCEPTION); 336 return redo(IGNORE_EXCEPTION);
337 } 337 }
338 338
339 virtual bool undo(ExceptionState&) 339 virtual bool undo(ExceptionState&) OVERRIDE
340 { 340 {
341 m_node->setNodeValue(m_oldValue); 341 m_node->setNodeValue(m_oldValue);
342 return true; 342 return true;
343 } 343 }
344 344
345 virtual bool redo(ExceptionState&) 345 virtual bool redo(ExceptionState&) OVERRIDE
346 { 346 {
347 m_node->setNodeValue(m_value); 347 m_node->setNodeValue(m_value);
348 return true; 348 return true;
349 } 349 }
350 350
351 private: 351 private:
352 RefPtr<Node> m_node; 352 RefPtr<Node> m_node;
353 String m_value; 353 String m_value;
354 String m_oldValue; 354 String m_oldValue;
355 }; 355 };
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 bool DOMEditor::replaceWholeText(Text* textNode, const String& text, ErrorString * errorString) 452 bool DOMEditor::replaceWholeText(Text* textNode, const String& text, ErrorString * errorString)
453 { 453 {
454 TrackExceptionState exceptionState; 454 TrackExceptionState exceptionState;
455 bool result = replaceWholeText(textNode, text, exceptionState); 455 bool result = replaceWholeText(textNode, text, exceptionState);
456 populateErrorString(exceptionState, errorString); 456 populateErrorString(exceptionState, errorString);
457 return result; 457 return result;
458 } 458 }
459 459
460 } // namespace WebCore 460 } // namespace WebCore
461 461
OLDNEW
« no previous file with comments | « Source/core/inspector/AsyncCallStackTracker.cpp ('k') | Source/core/inspector/InjectedScript.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698