| OLD | NEW |
| 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 29 matching lines...) Expand all Loading... |
| 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 namespace blink { | 45 namespace blink { |
| 46 | 46 |
| 47 class DOMEditor::RemoveChildAction final : public InspectorHistory::Action { | 47 class DOMEditor::RemoveChildAction final : public InspectorHistory::Action { |
| 48 WTF_MAKE_NONCOPYABLE(RemoveChildAction); | 48 WTF_MAKE_NONCOPYABLE(RemoveChildAction); |
| 49 public: | 49 public: |
| 50 RemoveChildAction(Node* parentNode, Node* node) | 50 RemoveChildAction(ContainerNode* parentNode, Node* node) |
| 51 : InspectorHistory::Action("RemoveChild") | 51 : InspectorHistory::Action("RemoveChild") |
| 52 , m_parentNode(parentNode) | 52 , m_parentNode(parentNode) |
| 53 , m_node(node) | 53 , m_node(node) |
| 54 { | 54 { |
| 55 } | 55 } |
| 56 | 56 |
| 57 virtual bool perform(ExceptionState& exceptionState) override | 57 virtual bool perform(ExceptionState& exceptionState) override |
| 58 { | 58 { |
| 59 m_anchorNode = m_node->nextSibling(); | 59 m_anchorNode = m_node->nextSibling(); |
| 60 return redo(exceptionState); | 60 return redo(exceptionState); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 74 | 74 |
| 75 virtual void trace(Visitor* visitor) override | 75 virtual void trace(Visitor* visitor) override |
| 76 { | 76 { |
| 77 visitor->trace(m_parentNode); | 77 visitor->trace(m_parentNode); |
| 78 visitor->trace(m_node); | 78 visitor->trace(m_node); |
| 79 visitor->trace(m_anchorNode); | 79 visitor->trace(m_anchorNode); |
| 80 InspectorHistory::Action::trace(visitor); | 80 InspectorHistory::Action::trace(visitor); |
| 81 } | 81 } |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 RefPtrWillBeMember<Node> m_parentNode; | 84 RefPtrWillBeMember<ContainerNode> m_parentNode; |
| 85 RefPtrWillBeMember<Node> m_node; | 85 RefPtrWillBeMember<Node> m_node; |
| 86 RefPtrWillBeMember<Node> m_anchorNode; | 86 RefPtrWillBeMember<Node> m_anchorNode; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 class DOMEditor::InsertBeforeAction final : public InspectorHistory::Action { | 89 class DOMEditor::InsertBeforeAction final : public InspectorHistory::Action { |
| 90 WTF_MAKE_NONCOPYABLE(InsertBeforeAction); | 90 WTF_MAKE_NONCOPYABLE(InsertBeforeAction); |
| 91 public: | 91 public: |
| 92 InsertBeforeAction(Node* parentNode, PassRefPtrWillBeRawPtr<Node> node, Node
* anchorNode) | 92 InsertBeforeAction(ContainerNode* parentNode, PassRefPtrWillBeRawPtr<Node> n
ode, Node* anchorNode) |
| 93 : InspectorHistory::Action("InsertBefore") | 93 : InspectorHistory::Action("InsertBefore") |
| 94 , m_parentNode(parentNode) | 94 , m_parentNode(parentNode) |
| 95 , m_node(node) | 95 , m_node(node) |
| 96 , m_anchorNode(anchorNode) | 96 , m_anchorNode(anchorNode) |
| 97 { | 97 { |
| 98 } | 98 } |
| 99 | 99 |
| 100 virtual bool perform(ExceptionState& exceptionState) override | 100 virtual bool perform(ExceptionState& exceptionState) override |
| 101 { | 101 { |
| 102 if (m_node->parentNode()) { | 102 if (m_node->parentNode()) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 129 virtual void trace(Visitor* visitor) override | 129 virtual void trace(Visitor* visitor) override |
| 130 { | 130 { |
| 131 visitor->trace(m_parentNode); | 131 visitor->trace(m_parentNode); |
| 132 visitor->trace(m_node); | 132 visitor->trace(m_node); |
| 133 visitor->trace(m_anchorNode); | 133 visitor->trace(m_anchorNode); |
| 134 visitor->trace(m_removeChildAction); | 134 visitor->trace(m_removeChildAction); |
| 135 InspectorHistory::Action::trace(visitor); | 135 InspectorHistory::Action::trace(visitor); |
| 136 } | 136 } |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 RefPtrWillBeMember<Node> m_parentNode; | 139 RefPtrWillBeMember<ContainerNode> m_parentNode; |
| 140 RefPtrWillBeMember<Node> m_node; | 140 RefPtrWillBeMember<Node> m_node; |
| 141 RefPtrWillBeMember<Node> m_anchorNode; | 141 RefPtrWillBeMember<Node> m_anchorNode; |
| 142 RefPtrWillBeMember<RemoveChildAction> m_removeChildAction; | 142 RefPtrWillBeMember<RemoveChildAction> m_removeChildAction; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 class DOMEditor::RemoveAttributeAction final : public InspectorHistory::Action { | 145 class DOMEditor::RemoveAttributeAction final : public InspectorHistory::Action { |
| 146 WTF_MAKE_NONCOPYABLE(RemoveAttributeAction); | 146 WTF_MAKE_NONCOPYABLE(RemoveAttributeAction); |
| 147 public: | 147 public: |
| 148 RemoveAttributeAction(Element* element, const AtomicString& name) | 148 RemoveAttributeAction(Element* element, const AtomicString& name) |
| 149 : InspectorHistory::Action("RemoveAttribute") | 149 : InspectorHistory::Action("RemoveAttribute") |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 326 |
| 327 private: | 327 private: |
| 328 RefPtrWillBeMember<Text> m_textNode; | 328 RefPtrWillBeMember<Text> m_textNode; |
| 329 String m_text; | 329 String m_text; |
| 330 String m_oldText; | 330 String m_oldText; |
| 331 }; | 331 }; |
| 332 | 332 |
| 333 class DOMEditor::ReplaceChildNodeAction final : public InspectorHistory::Action
{ | 333 class DOMEditor::ReplaceChildNodeAction final : public InspectorHistory::Action
{ |
| 334 WTF_MAKE_NONCOPYABLE(ReplaceChildNodeAction); | 334 WTF_MAKE_NONCOPYABLE(ReplaceChildNodeAction); |
| 335 public: | 335 public: |
| 336 ReplaceChildNodeAction(Node* parentNode, PassRefPtrWillBeRawPtr<Node> newNod
e, Node* oldNode) | 336 ReplaceChildNodeAction(ContainerNode* parentNode, PassRefPtrWillBeRawPtr<Nod
e> newNode, Node* oldNode) |
| 337 : InspectorHistory::Action("ReplaceChildNode") | 337 : InspectorHistory::Action("ReplaceChildNode") |
| 338 , m_parentNode(parentNode) | 338 , m_parentNode(parentNode) |
| 339 , m_newNode(newNode) | 339 , m_newNode(newNode) |
| 340 , m_oldNode(oldNode) | 340 , m_oldNode(oldNode) |
| 341 { | 341 { |
| 342 } | 342 } |
| 343 | 343 |
| 344 virtual bool perform(ExceptionState& exceptionState) override | 344 virtual bool perform(ExceptionState& exceptionState) override |
| 345 { | 345 { |
| 346 return redo(exceptionState); | 346 return redo(exceptionState); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 360 | 360 |
| 361 virtual void trace(Visitor* visitor) override | 361 virtual void trace(Visitor* visitor) override |
| 362 { | 362 { |
| 363 visitor->trace(m_parentNode); | 363 visitor->trace(m_parentNode); |
| 364 visitor->trace(m_newNode); | 364 visitor->trace(m_newNode); |
| 365 visitor->trace(m_oldNode); | 365 visitor->trace(m_oldNode); |
| 366 InspectorHistory::Action::trace(visitor); | 366 InspectorHistory::Action::trace(visitor); |
| 367 } | 367 } |
| 368 | 368 |
| 369 private: | 369 private: |
| 370 RefPtrWillBeMember<Node> m_parentNode; | 370 RefPtrWillBeMember<ContainerNode> m_parentNode; |
| 371 RefPtrWillBeMember<Node> m_newNode; | 371 RefPtrWillBeMember<Node> m_newNode; |
| 372 RefPtrWillBeMember<Node> m_oldNode; | 372 RefPtrWillBeMember<Node> m_oldNode; |
| 373 }; | 373 }; |
| 374 | 374 |
| 375 class DOMEditor::SetNodeValueAction final : public InspectorHistory::Action { | 375 class DOMEditor::SetNodeValueAction final : public InspectorHistory::Action { |
| 376 WTF_MAKE_NONCOPYABLE(SetNodeValueAction); | 376 WTF_MAKE_NONCOPYABLE(SetNodeValueAction); |
| 377 public: | 377 public: |
| 378 SetNodeValueAction(Node* node, const String& value) | 378 SetNodeValueAction(Node* node, const String& value) |
| 379 : InspectorHistory::Action("SetNodeValue") | 379 : InspectorHistory::Action("SetNodeValue") |
| 380 , m_node(node) | 380 , m_node(node) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 407 } | 407 } |
| 408 | 408 |
| 409 private: | 409 private: |
| 410 RefPtrWillBeMember<Node> m_node; | 410 RefPtrWillBeMember<Node> m_node; |
| 411 String m_value; | 411 String m_value; |
| 412 String m_oldValue; | 412 String m_oldValue; |
| 413 }; | 413 }; |
| 414 | 414 |
| 415 DOMEditor::DOMEditor(InspectorHistory* history) : m_history(history) { } | 415 DOMEditor::DOMEditor(InspectorHistory* history) : m_history(history) { } |
| 416 | 416 |
| 417 bool DOMEditor::insertBefore(Node* parentNode, PassRefPtrWillBeRawPtr<Node> node
, Node* anchorNode, ExceptionState& exceptionState) | 417 bool DOMEditor::insertBefore(ContainerNode* parentNode, PassRefPtrWillBeRawPtr<N
ode> node, Node* anchorNode, ExceptionState& exceptionState) |
| 418 { | 418 { |
| 419 return m_history->perform(adoptRefWillBeNoop(new InsertBeforeAction(parentNo
de, node, anchorNode)), exceptionState); | 419 return m_history->perform(adoptRefWillBeNoop(new InsertBeforeAction(parentNo
de, node, anchorNode)), exceptionState); |
| 420 } | 420 } |
| 421 | 421 |
| 422 bool DOMEditor::removeChild(Node* parentNode, Node* node, ExceptionState& except
ionState) | 422 bool DOMEditor::removeChild(ContainerNode* parentNode, Node* node, ExceptionStat
e& exceptionState) |
| 423 { | 423 { |
| 424 return m_history->perform(adoptRefWillBeNoop(new RemoveChildAction(parentNod
e, node)), exceptionState); | 424 return m_history->perform(adoptRefWillBeNoop(new RemoveChildAction(parentNod
e, node)), exceptionState); |
| 425 } | 425 } |
| 426 | 426 |
| 427 bool DOMEditor::setAttribute(Element* element, const String& name, const String&
value, ExceptionState& exceptionState) | 427 bool DOMEditor::setAttribute(Element* element, const String& name, const String&
value, ExceptionState& exceptionState) |
| 428 { | 428 { |
| 429 return m_history->perform(adoptRefWillBeNoop(new SetAttributeAction(element,
AtomicString(name), AtomicString(value))), exceptionState); | 429 return m_history->perform(adoptRefWillBeNoop(new SetAttributeAction(element,
AtomicString(name), AtomicString(value))), exceptionState); |
| 430 } | 430 } |
| 431 | 431 |
| 432 bool DOMEditor::removeAttribute(Element* element, const String& name, ExceptionS
tate& exceptionState) | 432 bool DOMEditor::removeAttribute(Element* element, const String& name, ExceptionS
tate& exceptionState) |
| 433 { | 433 { |
| 434 return m_history->perform(adoptRefWillBeNoop(new RemoveAttributeAction(eleme
nt, AtomicString(name))), exceptionState); | 434 return m_history->perform(adoptRefWillBeNoop(new RemoveAttributeAction(eleme
nt, AtomicString(name))), exceptionState); |
| 435 } | 435 } |
| 436 | 436 |
| 437 bool DOMEditor::setOuterHTML(Node* node, const String& html, Node** newNode, Exc
eptionState& exceptionState) | 437 bool DOMEditor::setOuterHTML(Node* node, const String& html, Node** newNode, Exc
eptionState& exceptionState) |
| 438 { | 438 { |
| 439 RefPtrWillBeRawPtr<SetOuterHTMLAction> action = adoptRefWillBeNoop(new SetOu
terHTMLAction(node, html)); | 439 RefPtrWillBeRawPtr<SetOuterHTMLAction> action = adoptRefWillBeNoop(new SetOu
terHTMLAction(node, html)); |
| 440 bool result = m_history->perform(action, exceptionState); | 440 bool result = m_history->perform(action, exceptionState); |
| 441 if (result) | 441 if (result) |
| 442 *newNode = action->newNode(); | 442 *newNode = action->newNode(); |
| 443 return result; | 443 return result; |
| 444 } | 444 } |
| 445 | 445 |
| 446 bool DOMEditor::replaceWholeText(Text* textNode, const String& text, ExceptionSt
ate& exceptionState) | 446 bool DOMEditor::replaceWholeText(Text* textNode, const String& text, ExceptionSt
ate& exceptionState) |
| 447 { | 447 { |
| 448 return m_history->perform(adoptRefWillBeNoop(new ReplaceWholeTextAction(text
Node, text)), exceptionState); | 448 return m_history->perform(adoptRefWillBeNoop(new ReplaceWholeTextAction(text
Node, text)), exceptionState); |
| 449 } | 449 } |
| 450 | 450 |
| 451 bool DOMEditor::replaceChild(Node* parentNode, PassRefPtrWillBeRawPtr<Node> newN
ode, Node* oldNode, ExceptionState& exceptionState) | 451 bool DOMEditor::replaceChild(ContainerNode* parentNode, PassRefPtrWillBeRawPtr<N
ode> newNode, Node* oldNode, ExceptionState& exceptionState) |
| 452 { | 452 { |
| 453 return m_history->perform(adoptRefWillBeNoop(new ReplaceChildNodeAction(pare
ntNode, newNode, oldNode)), exceptionState); | 453 return m_history->perform(adoptRefWillBeNoop(new ReplaceChildNodeAction(pare
ntNode, newNode, oldNode)), exceptionState); |
| 454 } | 454 } |
| 455 | 455 |
| 456 bool DOMEditor::setNodeValue(Node* node, const String& value, ExceptionState& ex
ceptionState) | 456 bool DOMEditor::setNodeValue(Node* node, const String& value, ExceptionState& ex
ceptionState) |
| 457 { | 457 { |
| 458 return m_history->perform(adoptRefWillBeNoop(new SetNodeValueAction(node, va
lue)), exceptionState); | 458 return m_history->perform(adoptRefWillBeNoop(new SetNodeValueAction(node, va
lue)), exceptionState); |
| 459 } | 459 } |
| 460 | 460 |
| 461 static void populateErrorString(ExceptionState& exceptionState, ErrorString* err
orString) | 461 static void populateErrorString(ExceptionState& exceptionState, ErrorString* err
orString) |
| 462 { | 462 { |
| 463 if (exceptionState.hadException()) | 463 if (exceptionState.hadException()) |
| 464 *errorString = DOMException::getErrorName(exceptionState.code()); | 464 *errorString = DOMException::getErrorName(exceptionState.code()); |
| 465 } | 465 } |
| 466 | 466 |
| 467 bool DOMEditor::insertBefore(Node* parentNode, PassRefPtrWillBeRawPtr<Node> node
, Node* anchorNode, ErrorString* errorString) | 467 bool DOMEditor::insertBefore(ContainerNode* parentNode, PassRefPtrWillBeRawPtr<N
ode> node, Node* anchorNode, ErrorString* errorString) |
| 468 { | 468 { |
| 469 TrackExceptionState exceptionState; | 469 TrackExceptionState exceptionState; |
| 470 bool result = insertBefore(parentNode, node, anchorNode, exceptionState); | 470 bool result = insertBefore(parentNode, node, anchorNode, exceptionState); |
| 471 populateErrorString(exceptionState, errorString); | 471 populateErrorString(exceptionState, errorString); |
| 472 return result; | 472 return result; |
| 473 } | 473 } |
| 474 | 474 |
| 475 bool DOMEditor::removeChild(Node* parentNode, Node* node, ErrorString* errorStri
ng) | 475 bool DOMEditor::removeChild(ContainerNode* parentNode, Node* node, ErrorString*
errorString) |
| 476 { | 476 { |
| 477 TrackExceptionState exceptionState; | 477 TrackExceptionState exceptionState; |
| 478 bool result = removeChild(parentNode, node, exceptionState); | 478 bool result = removeChild(parentNode, node, exceptionState); |
| 479 populateErrorString(exceptionState, errorString); | 479 populateErrorString(exceptionState, errorString); |
| 480 return result; | 480 return result; |
| 481 } | 481 } |
| 482 | 482 |
| 483 bool DOMEditor::setAttribute(Element* element, const String& name, const String&
value, ErrorString* errorString) | 483 bool DOMEditor::setAttribute(Element* element, const String& name, const String&
value, ErrorString* errorString) |
| 484 { | 484 { |
| 485 TrackExceptionState exceptionState; | 485 TrackExceptionState exceptionState; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 512 return result; | 512 return result; |
| 513 } | 513 } |
| 514 | 514 |
| 515 void DOMEditor::trace(Visitor* visitor) | 515 void DOMEditor::trace(Visitor* visitor) |
| 516 { | 516 { |
| 517 visitor->trace(m_history); | 517 visitor->trace(m_history); |
| 518 } | 518 } |
| 519 | 519 |
| 520 } // namespace blink | 520 } // namespace blink |
| 521 | 521 |
| OLD | NEW |