Changeset 107399 in webkit


Ignore:
Timestamp:
Feb 10, 2012 5:15:12 AM (12 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: implement undo for setOuterHTML via undo-ing nested primitive commands.
https://bugs.webkit.org/show_bug.cgi?id=78346

Reviewed by Yury Semikhatsky.

Source/WebCore:

Tests: inspector/elements/undo-set-outer-html-2.html

inspector/elements/undo-set-outer-html.html

  • inspector/DOMEditor.cpp:

(WebCore::DOMEditor::RemoveChildAction::RemoveChildAction):
(WebCore::DOMEditor::InsertBeforeAction::InsertBeforeAction):
(WebCore::DOMEditor::InsertBeforeAction::undo):
(WebCore::DOMEditor::RemoveAttributeAction::RemoveAttributeAction):
(WebCore::DOMEditor::SetAttributeAction::SetAttributeAction):
(WebCore::DOMEditor::SetOuterHTMLAction::SetOuterHTMLAction):
(WebCore::DOMEditor::SetOuterHTMLAction::perform):
(WebCore::DOMEditor::SetOuterHTMLAction::undo):
(DOMEditor::SetOuterHTMLAction):
(WebCore::DOMEditor::ReplaceWholeTextAction::ReplaceWholeTextAction):
(DOMEditor::ReplaceChildNodeAction):
(WebCore::DOMEditor::ReplaceChildNodeAction::ReplaceChildNodeAction):
(WebCore::DOMEditor::ReplaceChildNodeAction::perform):
(WebCore::DOMEditor::ReplaceChildNodeAction::undo):
(WebCore):
(DOMEditor::SetNodeValueAction):
(WebCore::DOMEditor::SetNodeValueAction::SetNodeValueAction):
(WebCore::DOMEditor::SetNodeValueAction::perform):
(WebCore::DOMEditor::SetNodeValueAction::undo):
(WebCore::DOMEditor::insertBefore):
(WebCore::DOMEditor::removeChild):
(WebCore::DOMEditor::setAttribute):
(WebCore::DOMEditor::removeAttribute):
(WebCore::DOMEditor::setOuterHTML):
(WebCore::DOMEditor::replaceWholeText):
(WebCore::DOMEditor::replaceChild):
(WebCore::DOMEditor::setNodeValue):
(WebCore::populateErrorString):

  • inspector/DOMEditor.h:

(DOMEditor):

  • inspector/DOMPatchSupport.cpp:

(WebCore::DOMPatchSupport::patchDocument):
(WebCore):
(WebCore::DOMPatchSupport::DOMPatchSupport):
(WebCore::DOMPatchSupport::patchNode):
(WebCore::DOMPatchSupport::innerPatchNode):
(WebCore::DOMPatchSupport::innerPatchChildren):
(WebCore::DOMPatchSupport::insertBeforeAndMarkAsUsed):
(WebCore::DOMPatchSupport::removeChildAndMoveToNew):

  • inspector/DOMPatchSupport.h:

(WebCore):
(DOMPatchSupport):

  • inspector/InspectorCSSAgent.cpp:

(WebCore::InspectorCSSAgent::StyleSheetAction::perform):
(WebCore::InspectorCSSAgent::StyleSheetAction::undo):
(InspectorCSSAgent::StyleSheetAction):
(WebCore::InspectorCSSAgent::SetStyleSheetTextAction::perform):
(WebCore::InspectorCSSAgent::SetStyleSheetTextAction::undo):
(WebCore::InspectorCSSAgent::SetPropertyTextAction::perform):
(WebCore::InspectorCSSAgent::SetPropertyTextAction::undo):
(WebCore::InspectorCSSAgent::TogglePropertyAction::perform):
(WebCore::InspectorCSSAgent::TogglePropertyAction::undo):
(WebCore::InspectorCSSAgent::setStyleSheetText):
(WebCore::InspectorCSSAgent::setPropertyText):
(WebCore::InspectorCSSAgent::toggleProperty):
(WebCore::InspectorCSSAgent::assertStyleSheetForId):

  • inspector/InspectorDOMAgent.cpp:

(WebCore::InspectorDOMAgent::toErrorString):
(WebCore):
(WebCore::InspectorDOMAgent::setAttributesAsText):
(WebCore::InspectorDOMAgent::setOuterHTML):
(WebCore::InspectorDOMAgent::undo):

  • inspector/InspectorDOMAgent.h:

(InspectorDOMAgent):

  • inspector/InspectorHistory.cpp:

(WebCore::InspectorHistory::perform):
(WebCore::InspectorHistory::undo):

  • inspector/InspectorHistory.h:

(WebCore):
(Action):
(InspectorHistory):

  • inspector/InspectorPageAgent.cpp:

(WebCore::InspectorPageAgent::setDocumentContent):

  • inspector/InspectorStyleSheet.cpp:

(WebCore::InspectorStyle::setPropertyText):
(WebCore::InspectorStyle::toggleProperty):
(WebCore::InspectorStyleSheet::setPropertyText):
(WebCore::InspectorStyleSheet::toggleProperty):

  • inspector/InspectorStyleSheet.h:

(InspectorStyle):
(InspectorStyleSheet):

LayoutTests:

  • inspector/elements/set-outer-html-2-expected.txt:
  • inspector/elements/set-outer-html-test.js:

(initialize_SetOuterHTMLTest.InspectorTest.patchOuterHTML):
(initialize_SetOuterHTMLTest.InspectorTest.patchOuterHTMLUseUndo):
(initialize_SetOuterHTMLTest.InspectorTest.setOuterHTMLUseUndo.bringBack):
(initialize_SetOuterHTMLTest.InspectorTest.setOuterHTMLUseUndo):
(initialize_SetOuterHTMLTest.InspectorTest.innerSetOuterHTML):
(initialize_SetOuterHTMLTest.InspectorTest._dumpOuterHTML.dumpIdentity):
(initialize_SetOuterHTMLTest.InspectorTest._dumpOuterHTML.callback):
(initialize_SetOuterHTMLTest.InspectorTest._dumpOuterHTML):
(initialize_SetOuterHTMLTest):

  • inspector/elements/undo-dom-edits-expected.txt:
  • inspector/elements/undo-set-outer-html-2-expected.txt: Copied from LayoutTests/inspector/elements/set-outer-html-2-expected.txt.
  • inspector/elements/undo-set-outer-html-2.html: Added.
  • inspector/elements/undo-set-outer-html-expected.txt: Copied from LayoutTests/inspector/elements/set-outer-html-2-expected.txt.
  • inspector/elements/undo-set-outer-html.html: Added.
Location:
trunk
Files:
2 added
17 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r107398 r107399  
     12012-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
    1252012-02-10  Csaba Osztrogonác  <ossy@webkit.org>
    226
  • trunk/LayoutTests/inspector/elements/set-outer-html-2-expected.txt

    r107242 r107399  
    113113Event NodeInserted: H2
    114114Event NodeInserted: P
     115Event NodeInserted: UL
     116Event NodeInserted: UL
    115117Event NodeRemoved: H2
    116118Event NodeRemoved: P
     119Event NodeRemoved: UL
     120Event NodeRemoved: UL
    117121==========8<==========
    118122<div id="container" style="display:none">
     
    176180Wrapper identity: identity
    177181Event NodeInserted: H2
     182Event NodeInserted: H2
     183Event NodeRemoved: H2
    178184==========8<==========
    179185<div id="container" style="display:none">
  • trunk/LayoutTests/inspector/elements/set-outer-html-test.js

    r105262 r107399  
    4545InspectorTest.patchOuterHTML = function(pattern, replacement, next)
    4646{
    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
     51InspectorTest.patchOuterHTMLUseUndo = function(pattern, replacement, next)
     52{
     53    InspectorTest.addResult("Replacing '" + pattern + "' with '" + replacement + "'\n");
     54    InspectorTest.setOuterHTMLUseUndo(InspectorTest.containerText.replace(pattern, replacement), next);
    4955}
    5056
     
    6066}
    6167
     68InspectorTest.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
    6279InspectorTest.innerSetOuterHTML = function(newText, last, next)
    6380{
    64     DOMAgent.setOuterHTML(InspectorTest.containerId, newText, dumpOuterHTML);
     81    DOMAgent.setOuterHTML(InspectorTest.containerId, newText, InspectorTest._dumpOuterHTML.bind(InspectorTest, last, next));
     82}
    6583
    66     function dumpOuterHTML()
     84InspectorTest._dumpOuterHTML = function(last, next)
     85{
     86    RuntimeAgent.evaluate("document.getElementById(\"identity\").wrapperIdentity", dumpIdentity);
     87    function dumpIdentity(error, result)
    6788    {
    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    }
    7795
    78         DOMAgent.getOuterHTML(InspectorTest.containerId, callback);
     96    DOMAgent.getOuterHTML(InspectorTest.containerId, callback);
    7997
    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();
    89106    }
    90107}
  • trunk/LayoutTests/inspector/elements/undo-dom-edits-expected.txt

    r107217 r107399  
    5959Post-undo (initial):
    6060- <div id="testEditAsHTML">
    61     + <div id="node-to-edit-as-html"></div>
     61    + <div id="node-to-edit-as-html"></div>
    6262  </div>
    6363
  • 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
     1Tests undo for the DOMAgent.setOuterHTML protocol method (part 2).
     2
    43
    54Running: testSetUp
     
    3029Event AttrRemoved: H2
    3130Event AttrRemoved: H2
    32 Event ChildNodeCountUpdated: UL
     31Event NodeInserted: UL
     32Event NodeRemoved: UL
    3333==========8<==========
    3434<div id="container" style="display:none">
     
    112112Wrapper identity: identity
    113113Event NodeInserted: H2
    114 Event NodeInserted: P
    115 Event NodeRemoved: H2
    116 Event NodeRemoved: P
     114Event NodeRemoved: H2
    117115==========8<==========
    118116<div id="container" style="display:none">
     
    153151
    154152Wrapper identity: identity
     153Event NodeRemoved: DIV
    155154==========8<==========
    156155<div id="container" style="display:none">
     
    176175Wrapper identity: identity
    177176Event NodeInserted: H2
     177Event NodeInserted: H2
     178Event NodeRemoved: H2
    178179==========8<==========
    179180<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).
     1Tests undo for the DOMAgent.setOuterHTML protocol method.
    22
    3 Additional node
    43
    54Running: testSetUp
    65
    7 Running: testChangeMultipleThings
     6Running: testChangeCharacterData
     7Replacing 'Getting involved' with 'Getting not involved'
     8
    89Wrapper identity: identity
    9 Event AttrModified: H2
    10 Event AttrModified: H2
    11 Event NodeInserted: UL
    12 Event NodeRemoved: UL
     10Event CharacterDataModified:
    1311==========8<==========
    1412<div id="container" style="display:none">
    1513<p>WebKit is used by <a href="http://www.apple.com/safari/">Safari</a>, Dashboard, etc..</p>
    16 <h2 foo="bar" bar="baz">Getting involved</h2>
     14<h2>Getting not involved</h2>
    1715<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>
    2416</div>
    2517==========>8==========
     
    2820
    2921Wrapper identity: identity
    30 Event AttrRemoved: H2
    31 Event AttrRemoved: H2
    32 Event ChildNodeCountUpdated: UL
     22Event CharacterDataModified:
    3323==========8<==========
    3424<div id="container" style="display:none">
     
    3626<h2>Getting involved</h2>
    3727<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>
    4428</div>
    4529==========>8==========
     
    4933
    5034
    51 Running: testChangeNestingLevel
     35Running: testChangeAttributes
     36Replacing '<a href' with '<a foo="bar" href'
     37
    5238Wrapper identity: identity
    53 Event NodeInserted: DIV
    54 Event NodeRemoved: UL
     39Event AttrModified: A
     40Event AttrModified: A
     41Event AttrRemoved: A
    5542==========8<==========
    5643<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>
    5845<h2>Getting involved</h2>
    5946<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>
    6647</div>
    6748==========>8==========
     
    7051
    7152Wrapper identity: identity
    72 Event NodeInserted: UL
    73 Event NodeRemoved: DIV
     53Event AttrModified: A
     54Event AttrRemoved: A
     55Event AttrRemoved: A
    7456==========8<==========
    7557<div id="container" style="display:none">
     
    7759<h2>Getting involved</h2>
    7860<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>
    8561</div>
    8662==========>8==========
     
    9066
    9167
    92 Running: testSwapNodes
     68Running: testRemoveLastChild
     69Replacing 'Getting involved' with ''
     70
    9371Wrapper identity: identity
    94 Event NodeInserted: H2
    95 Event NodeRemoved: H2
     72Event NodeRemoved:
    9673==========8<==========
    9774<div id="container" style="display:none">
    9875<p>WebKit is used by <a href="http://www.apple.com/safari/">Safari</a>, Dashboard, etc..</p>
    99 
     76<h2></h2>
    10077<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>
    10879==========>8==========
    10980
     
    11182
    11283Wrapper identity: identity
    113 Event NodeInserted: H2
    114 Event NodeInserted: P
    115 Event NodeRemoved: H2
    116 Event NodeRemoved: P
     84Event NodeInserted:
    11785==========8<==========
    11886<div id="container" style="display:none">
     
    12088<h2>Getting involved</h2>
    12189<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>
    12890</div>
    12991==========>8==========
     
    13395
    13496
    135 Running: testEditTwoRoots
     97Running: testSplitNode
     98Replacing 'Getting involved' with 'Getting</h2><h2>involved'
     99
    136100Wrapper identity: identity
    137 Event NodeInserted: DIV
     101Event NodeInserted: H2
     102Event NodeInserted: H2
     103Event NodeRemoved: H2
    138104==========8<==========
    139105<div id="container" style="display:none">
    140106<p>WebKit is used by <a href="http://www.apple.com/safari/">Safari</a>, Dashboard, etc..</p>
    141 <h2>Getting involved</h2>
     107<h2>Getting</h2><h2>involved</h2>
    142108<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>
    149109</div>
    150110==========>8==========
     
    153113
    154114Wrapper identity: identity
     115Event NodeInserted: H2
     116Event NodeRemoved: H2
     117Event NodeRemoved: H2
    155118==========8<==========
    156119<div id="container" style="display:none">
     
    158121<h2>Getting involved</h2>
    159122<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>
    166123</div>
    167124==========>8==========
     
    171128
    172129
    173 Running: testDupeNode
    174 Replacing '<h2>Getting involved</h2>' with '<h2>Getting involved</h2><h2>Getting involved</h2>'
     130Running: testChangeNodeName
     131Replacing '<h2>Getting involved</h2>' with '<h3>Getting involved</h3>'
    175132
    176133Wrapper identity: identity
    177 Event NodeInserted: H2
     134Event NodeInserted: H3
     135Event NodeRemoved: H2
    178136==========8<==========
    179137<div id="container" style="display:none">
    180138<p>WebKit is used by <a href="http://www.apple.com/safari/">Safari</a>, Dashboard, etc..</p>
    181 <h2>Getting involved</h2><h2>Getting involved</h2>
     139<h3>Getting involved</h3>
    182140<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>
    189141</div>
    190142==========>8==========
     
    193145
    194146Wrapper identity: identity
    195 Event NodeRemoved: H2
     147Event NodeInserted: H2
     148Event NodeRemoved: H3
    196149==========8<==========
    197150<div id="container" style="display:none">
     
    199152<h2>Getting involved</h2>
    200153<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>
    207154</div>
    208155==========>8==========
  • trunk/Source/WebCore/ChangeLog

    r107396 r107399  
     12012-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
    1942012-02-10  Kentaro Hara  <haraken@chromium.org>
    295
  • trunk/Source/WebCore/inspector/DOMEditor.cpp

    r107257 r107399  
    5050namespace WebCore {
    5151
    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;
     52class DOMEditor::RemoveChildAction : public InspectorHistory::Action {
     53    WTF_MAKE_NONCOPYABLE(RemoveChildAction);
     54public:
     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    }
    8172
    8273private:
     
    8677};
    8778
    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 {
     79class DOMEditor::InsertBeforeAction : public InspectorHistory::Action {
    11680    WTF_MAKE_NONCOPYABLE(InsertBeforeAction);
    11781public:
    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")
    12084        , m_parentNode(parentNode)
    12185        , m_node(node)
     
    136100    virtual bool undo(ExceptionCode& ec)
    137101    {
     102        if (!m_parentNode->removeChild(m_node.get(), ec))
     103            return false;
    138104        if (m_removeChildAction)
    139105            return m_removeChildAction->undo(ec);
    140 
    141         return m_parentNode->removeChild(m_node.get(), ec);
     106        return true;
    142107    }
    143108
     
    149114};
    150115
    151 class DOMEditor::RemoveAttributeAction : public DOMEditor::DOMAction {
     116class DOMEditor::RemoveAttributeAction : public InspectorHistory::Action {
    152117    WTF_MAKE_NONCOPYABLE(RemoveAttributeAction);
    153118public:
    154119    RemoveAttributeAction(Element* element, const String& name)
    155         : DOMEditor::DOMAction("RemoveAttribute")
     120        : InspectorHistory::Action("RemoveAttribute")
    156121        , m_element(element)
    157122        , m_name(name)
     
    178143};
    179144
    180 class DOMEditor::SetAttributeAction : public DOMEditor::DOMAction {
     145class DOMEditor::SetAttributeAction : public InspectorHistory::Action {
    181146    WTF_MAKE_NONCOPYABLE(SetAttributeAction);
    182147public:
    183148    SetAttributeAction(Element* element, const String& name, const String& value)
    184         : DOMEditor::DOMAction("SetAttribute")
     149        : InspectorHistory::Action("SetAttribute")
    185150        , m_element(element)
    186151        , m_name(name)
     
    216181};
    217182
    218 class DOMEditor::SetOuterHTMLAction : public DOMEditor::DOMAction {
     183class DOMEditor::SetOuterHTMLAction : public InspectorHistory::Action {
    219184    WTF_MAKE_NONCOPYABLE(SetOuterHTMLAction);
    220185public:
    221186    SetOuterHTMLAction(Node* node, const String& html)
    222         : DOMEditor::DOMAction("SetOuterHTML")
     187        : InspectorHistory::Action("SetOuterHTML")
    223188        , m_node(node)
    224189        , m_nextSibling(node->nextSibling())
    225190        , m_html(html)
    226191        , m_newNode(0)
     192        , m_history(adoptPtr(new InspectorHistory()))
     193        , m_domEditor(adoptPtr(new DOMEditor(m_history.get())))
    227194    {
    228195    }
     
    231198    {
    232199        m_oldHTML = createMarkup(m_node.get());
    233         DOMPatchSupport domPatchSupport(m_node->ownerDocument());
     200        DOMPatchSupport domPatchSupport(m_domEditor.get(), m_node->ownerDocument());
    234201        m_newNode = domPatchSupport.patchNode(m_node.get(), m_html, ec);
    235202        return !ec;
     
    238205    virtual bool undo(ExceptionCode& ec)
    239206    {
    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);
    253208    }
    254209
     
    264219    String m_oldHTML;
    265220    Node* m_newNode;
    266 };
    267 
    268 class DOMEditor::ReplaceWholeTextAction : public DOMEditor::DOMAction {
     221    OwnPtr<InspectorHistory> m_history;
     222    OwnPtr<DOMEditor> m_domEditor;
     223};
     224
     225class DOMEditor::ReplaceWholeTextAction : public InspectorHistory::Action {
    269226    WTF_MAKE_NONCOPYABLE(ReplaceWholeTextAction);
    270227public:
    271228    ReplaceWholeTextAction(Text* textNode, const String& text)
    272         : DOMAction("ReplaceWholeText")
     229        : InspectorHistory::Action("ReplaceWholeText")
    273230        , m_textNode(textNode)
    274231        , m_text(text)
     
    295252};
    296253
     254class DOMEditor::ReplaceChildNodeAction : public InspectorHistory::Action {
     255    WTF_MAKE_NONCOPYABLE(ReplaceChildNodeAction);
     256public:
     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
     275private:
     276    RefPtr<Node> m_parentNode;
     277    RefPtr<Node> m_newNode;
     278    RefPtr<Node> m_oldNode;
     279};
     280
     281class DOMEditor::SetNodeValueAction : public InspectorHistory::Action {
     282    WTF_MAKE_NONCOPYABLE(SetNodeValueAction);
     283public:
     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
     304private:
     305    RefPtr<Node> m_node;
     306    String m_value;
     307    String m_oldValue;
     308};
     309
    297310DOMEditor::DOMEditor(InspectorHistory* history) : m_history(history) { }
    298311
    299312DOMEditor::~DOMEditor() { }
    300313
    301 bool DOMEditor::insertBefore(Node* parentNode, Node* node, Node* anchorNode, ErrorString* errorString)
    302 {
    303     return m_history->perform(adoptPtr(new InsertBeforeAction(parentNode, node, anchorNode)), errorString);
    304 }
    305 
    306 bool DOMEditor::removeChild(Node* parentNode, Node* node, ErrorString* errorString)
    307 {
    308     return m_history->perform(adoptPtr(new RemoveChildAction(parentNode, node)), errorString);
    309 }
    310 
    311 bool DOMEditor::setAttribute(Element* element, const String& name, const String& value, ErrorString* errorString)
    312 {
    313     return m_history->perform(adoptPtr(new SetAttributeAction(element, name, value)), errorString);
    314 }
    315 
    316 bool DOMEditor::removeAttribute(Element* element, const String& name, ErrorString* errorString)
    317 {
    318     return m_history->perform(adoptPtr(new RemoveAttributeAction(element, name)), errorString);
    319 }
    320 
    321 bool DOMEditor::setOuterHTML(Node* node, const String& html, Node** newNode, ErrorString* errorString)
     314bool 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
     319bool DOMEditor::removeChild(Node* parentNode, Node* node, ExceptionCode& ec)
     320{
     321    return m_history->perform(adoptPtr(new RemoveChildAction(parentNode, node)), ec);
     322}
     323
     324bool 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
     329bool DOMEditor::removeAttribute(Element* element, const String& name, ExceptionCode& ec)
     330{
     331    return m_history->perform(adoptPtr(new RemoveAttributeAction(element, name)), ec);
     332}
     333
     334bool DOMEditor::setOuterHTML(Node* node, const String& html, Node** newNode, ExceptionCode& ec)
    322335{
    323336    OwnPtr<SetOuterHTMLAction> action = adoptPtr(new SetOuterHTMLAction(node, html));
    324337    SetOuterHTMLAction* rawAction = action.get();
    325     bool result = m_history->perform(action.release(), errorString);
     338    bool result = m_history->perform(action.release(), ec);
    326339    if (result)
    327340        *newNode = rawAction->newNode();
     
    329342}
    330343
     344bool DOMEditor::replaceWholeText(Text* textNode, const String& text, ExceptionCode& ec)
     345{
     346    return m_history->perform(adoptPtr(new ReplaceWholeTextAction(textNode, text)), ec);
     347}
     348
     349bool 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
     354bool DOMEditor::setNodeValue(Node* node, const String& value, ExceptionCode& ec)
     355{
     356    return m_history->perform(adoptPtr(new SetNodeValueAction(node, value)), ec);
     357}
     358
     359static void populateErrorString(const ExceptionCode& ec, ErrorString* errorString)
     360{
     361    if (ec) {
     362        ExceptionCodeDescription description(ec);
     363        *errorString = description.name;
     364    }
     365}
     366
     367bool 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
     375bool 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
     383bool 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
     391bool 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
     399bool 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
    331407bool DOMEditor::replaceWholeText(Text* textNode, const String& text, ErrorString* errorString)
    332408{
    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;
    334413}
    335414
  • trunk/Source/WebCore/inspector/DOMEditor.h

    r107257 r107399  
    3232#define DOMEditor_h
    3333
     34#include "ExceptionCode.h"
     35
    3436#include <wtf/text/WTFString.h>
    3537
     
    5153    ~DOMEditor();
    5254
    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*);
    5465    bool removeChild(Node* parentNode, Node*, ErrorString*);
    5566    bool setAttribute(Element*, const String& name, const String& value, ErrorString*);
     
    6677    class SetOuterHTMLAction;
    6778    class ReplaceWholeTextAction;
     79    class ReplaceChildNodeAction;
     80    class SetNodeValueAction;
    6881
    6982    InspectorHistory* m_history;
  • trunk/Source/WebCore/inspector/DOMPatchSupport.cpp

    r107380 r107399  
    3636#include "Attribute.h"
    3737#include "Base64.h"
     38#include "DOMEditor.h"
    3839#include "Document.h"
    3940#include "DocumentFragment.h"
     
    4344#include "HTMLHeadElement.h"
    4445#include "HTMLNames.h"
     46#include "InspectorHistory.h"
    4547#include "Node.h"
    4648
     
    6870};
    6971
    70 DOMPatchSupport::DOMPatchSupport(Document* document) : m_document(document) { }
     72void 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
     80DOMPatchSupport::DOMPatchSupport(DOMEditor* domEditor, Document* document)
     81    : m_domEditor(domEditor)
     82    , m_document(document)
     83{
     84}
    7185
    7286DOMPatchSupport::~DOMPatchSupport() { }
     
    8094    parser->detach();
    8195
    82     ExceptionCode ec = 0;
    8396    OwnPtr<Digest> oldInfo = createDigest(m_document->documentElement(), 0);
    8497    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)) {
    88101        // Fall back to rewrite.
    89102        m_document->write(markup);
     
    126139        newList.append(createDigest(child, 0));
    127140
    128     innerPatchChildren(parentNode, oldList, newList, ec);
    129     if (ec) {
     141    if (!innerPatchChildren(parentNode, oldList, newList, ec)) {
    130142        // Fall back to total replace.
    131143        ec = 0;
    132         parentNode->replaceChild(fragment.release(), node, ec);
    133         if (ec)
     144        if (!m_domEditor->replaceChild(parentNode, fragment.release(), node, ec))
    134145            return 0;
    135146    }
     
    137148}
    138149
    139 void DOMPatchSupport::innerPatchNode(Digest* oldDigest, Digest* newDigest, ExceptionCode& ec)
     150bool DOMPatchSupport::innerPatchNode(Digest* oldDigest, Digest* newDigest, ExceptionCode& ec)
    140151{
    141152    if (oldDigest->m_sha1 == newDigest->m_sha1)
    142         return;
     153        return true;
    143154
    144155    Node* oldNode = oldDigest->m_node;
    145156    Node* newNode = newDigest->m_node;
    146157
    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    }
    156165
    157166    if (oldNode->nodeType() != Node::ELEMENT_NODE)
    158         return;
     167        return true;
    159168
    160169    // Patch attributes
     
    164173        // FIXME: Create a function in Element for removing all properties. Take in account whether did/willModifyAttribute are important.
    165174        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            }
    168180        }
    169181
     
    173185            for (size_t i = 0; i < numAttrs; ++i) {
    174186                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;
    176189            }
    177190        }
    178191    }
    179192
    180     innerPatchChildren(oldElement, oldDigest->m_children, newDigest->m_children, ec);
     193    bool result = innerPatchChildren(oldElement, oldDigest->m_children, newDigest->m_children, ec);
    181194    m_unusedNodesMap.remove(newDigest->m_sha1);
     195    return result;
    182196}
    183197
     
    270284}
    271285
    272 void DOMPatchSupport::innerPatchChildren(ContainerNode* parentNode, const Vector<OwnPtr<Digest> >& oldList, const Vector<OwnPtr<Digest> >& newList, ExceptionCode& ec)
     286bool DOMPatchSupport::innerPatchChildren(ContainerNode* parentNode, const Vector<OwnPtr<Digest> >& oldList, const Vector<OwnPtr<Digest> >& newList, ExceptionCode& ec)
    273287{
    274288    pair<ResultMap, ResultMap> resultMaps = diff(oldList, newList);
     
    310324                merges.set(newList[anchorCandidate].get(), oldList[i].get());
    311325            else {
    312                 removeChild(oldList[i].get(), ec);
    313                 if (ec)
    314                     return;
     326                if (!removeChildAndMoveToNew(oldList[i].get(), ec))
     327                    return false;
    315328            }
    316329        } else {
    317             removeChild(oldList[i].get(), ec);
    318             if (ec)
    319                 return;
     330            if (!removeChildAndMoveToNew(oldList[i].get(), ec))
     331                return false;
    320332        }
    321333    }
     
    349361    // 2. Patch nodes marked for merge.
    350362    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;
    354365    }
    355366
     
    358369        if (newMap[i].first || merges.contains(newList[i].get()))
    359370            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;
    365373    }
    366374
     
    376384            continue; // Never move head or body, move the rest of the nodes around them.
    377385
    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;
    382390}
    383391
     
    432440}
    433441
    434 void DOMPatchSupport::insertBefore(ContainerNode* parentNode, Digest* digest, Node* anchor, ExceptionCode& ec)
    435 {
    436     parentNode->insertBefore(digest->m_node, anchor, ec);
     442bool DOMPatchSupport::insertBeforeAndMarkAsUsed(ContainerNode* parentNode, Digest* digest, Node* anchor, ExceptionCode& ec)
     443{
     444    bool result = m_domEditor->insertBefore(parentNode, digest->m_node, anchor, ec);
    437445    markNodeAsUsed(digest);
    438 }
    439 
    440 void DOMPatchSupport::removeChild(Digest* oldDigest, ExceptionCode& ec)
     446    return result;
     447}
     448
     449bool DOMPatchSupport::removeChildAndMoveToNew(Digest* oldDigest, ExceptionCode& ec)
    441450{
    442451    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;
    444454
    445455    // Diff works within levels. In order not to lose the node identity when user
     
    448458    // with matching sha1. If it does, replace it with the original DOM chunk. Chances are
    449459    // high that it will get merged back into the original DOM during the further patching.
    450 
    451460    UnusedNodesMap::iterator it = m_unusedNodesMap.find(oldDigest->m_sha1);
    452461    if (it != m_unusedNodesMap.end()) {
    453462        Digest* newDigest = it->second;
    454463        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;
    456466        newDigest->m_node = oldNode.get();
    457467        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;
    463476}
    464477
  • trunk/Source/WebCore/inspector/DOMPatchSupport.h

    r107257 r107399  
    4343
    4444class ContainerNode;
     45class DOMEditor;
    4546class Document;
    4647class NamedNodeMap;
     
    5253    WTF_MAKE_NONCOPYABLE(DOMPatchSupport);
    5354public:
    54     explicit DOMPatchSupport(Document*);
     55    static void patchDocument(Document*, const String& markup);
     56
     57    DOMPatchSupport(DOMEditor*, Document*);
    5558    virtual ~DOMPatchSupport();
    5659
     
    6366    typedef HashMap<String, Digest*> UnusedNodesMap;
    6467
    65     void innerPatchNode(Digest* oldNode, Digest* newNode, ExceptionCode&);
     68    bool innerPatchNode(Digest* oldNode, Digest* newNode, ExceptionCode&);
    6669    std::pair<ResultMap, ResultMap> diff(const Vector<OwnPtr<Digest> >& oldChildren, const Vector<OwnPtr<Digest> >& newChildren);
    67     void innerPatchChildren(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&);
    6871    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&);
    7174    void markNodeAsUsed(Digest*);
    7275#ifdef DEBUG_DOM_PATCH_SUPPORT
     
    7477#endif
    7578
     79    DOMEditor* m_domEditor;
    7680    Document* m_document;
    7781
  • trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp

    r107220 r107399  
    229229    }
    230230
    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);
    234235        if (!styleSheet)
    235236            return false;
    236         return perform(styleSheet, errorString);
    237     }
    238 
    239     virtual bool undo(ErrorString* 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);
    242243        if (!styleSheet)
    243244            return false;
    244         return undo(styleSheet, errorString);
    245     }
    246 
    247     virtual bool perform(InspectorStyleSheet*, ErrorString*) = 0;
    248 
    249     virtual bool undo(InspectorStyleSheet*, ErrorString*) = 0;
     245        return undo(styleSheet, ec);
     246    }
     247
     248    virtual bool perform(InspectorStyleSheet*, ExceptionCode&) = 0;
     249
     250    virtual bool undo(InspectorStyleSheet*, ExceptionCode&) = 0;
    250251
    251252protected:
     
    263264    }
    264265
    265     virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ErrorString*)
     266    virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode&)
    266267    {
    267268        if (!inspectorStyleSheet->getText(&m_oldText))
     
    275276    }
    276277
    277     virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ErrorString*)
     278    virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode&)
    278279    {
    279280        if (inspectorStyleSheet->setText(m_oldText)) {
     
    306307    }
    307308
    308     virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ErrorString* errorString)
     309    virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec)
    309310    {
    310311        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);
    312313        m_oldText = oldText.stripWhiteSpace();
    313314        // FIXME: remove this once the model handles this case.
     
    317318    }
    318319
    319     virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ErrorString* errorString)
     320    virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ExceptionCode& ec)
    320321    {
    321322        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);
    323324    }
    324325
     
    355356    }
    356357
    357     virtual bool perform(InspectorStyleSheet* inspectorStyleSheet, ErrorString* errorString)
    358     {
    359         return inspectorStyleSheet->toggleProperty(errorString, m_cssId, m_propertyIndex, m_disable);
    360     }
    361 
    362     virtual bool undo(InspectorStyleSheet* inspectorStyleSheet, ErrorString* 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);
    365366    }
    366367
     
    598599void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String& styleSheetId, const String& text)
    599600{
    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);
    601604    m_domAgent->history()->markUndoableState();
    602605}
     
    611614        return;
    612615
    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);
    614618    if (success)
    615619        result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId));
     620    *errorString = InspectorDOMAgent::toErrorString(ec);
    616621}
    617622
     
    625630        return;
    626631
    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);
    628634    if (success)
    629635        result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId));
     636    *errorString = InspectorDOMAgent::toErrorString(ec);
    630637    m_domAgent->history()->markUndoableState();
    631638}
  • trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp

    r107257 r107399  
    180180}
    181181
     182String InspectorDOMAgent::toErrorString(const ExceptionCode& ec)
     183{
     184    if (ec) {
     185        ExceptionCodeDescription description(ec);
     186        return description.name;
     187    }
     188    return "";
     189}
     190
    182191InspectorDOMAgent::InspectorDOMAgent(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorClient* client, InspectorState* inspectorState, InjectedScriptManager* injectedScriptManager)
    183192    : InspectorBaseAgent<InspectorDOMAgent>("DOM", instrumentingAgents, inspectorState)
     
    542551    RefPtr<Element> parsedElement = element->document()->createElement("span", ec);
    543552    if (ec) {
    544         *errorString = "Internal error: could not set attribute value";
     553        *errorString = InspectorDOMAgent::toErrorString(ec);
    545554        return;
    546555    }
     
    548557    toHTMLElement(parsedElement.get())->setInnerHTML("<span " + text + "></span>", ec);
    549558    if (ec) {
    550         *errorString = "Could not parse value as attributes";
     559        *errorString = InspectorDOMAgent::toErrorString(ec);
    551560        return;
    552561    }
     
    655664{
    656665    if (!nodeId) {
    657         DOMPatchSupport domPatchSupport(m_document.get());
     666        DOMPatchSupport domPatchSupport(m_domEditor.get(), m_document.get());
    658667        domPatchSupport.patchDocument(outerHTML);
    659668        return;
     
    10781087void InspectorDOMAgent::undo(ErrorString* errorString)
    10791088{
    1080     m_history->undo(errorString);
     1089    ExceptionCode ec = 0;
     1090    m_history->undo(ec);
     1091    *errorString = InspectorDOMAgent::toErrorString(ec);
    10811092}
    10821093
  • trunk/Source/WebCore/inspector/InspectorDOMAgent.h

    r107257 r107399  
    107107        return adoptPtr(new InspectorDOMAgent(instrumentingAgents, pageAgent, client, inspectorState, injectedScriptManager));
    108108    }
     109
     110    static String toErrorString(const ExceptionCode&);
    109111
    110112    ~InspectorDOMAgent();
  • trunk/Source/WebCore/inspector/InspectorHistory.cpp

    r106953 r107399  
    4444    UndoableStateMark() : InspectorHistory::Action("[UndoableState]") { }
    4545
    46     virtual bool perform(ErrorString*) { return true; }
     46    virtual bool perform(ExceptionCode&) { return true; }
    4747
    48     virtual bool undo(ErrorString*) { return true; }
     48    virtual bool undo(ExceptionCode&) { return true; }
    4949
    5050    virtual bool isUndoableStateMark() { return true; }
     
    8484InspectorHistory::~InspectorHistory() { }
    8585
    86 bool InspectorHistory::perform(PassOwnPtr<Action> action, ErrorString* errorString)
     86bool InspectorHistory::perform(PassOwnPtr<Action> action, ExceptionCode& ec)
    8787{
    88     if (!action->perform(errorString))
     88    if (!action->perform(ec))
    8989        return false;
    9090
     
    102102}
    103103
    104 bool InspectorHistory::undo(ErrorString* errorString)
     104bool InspectorHistory::undo(ExceptionCode& ec)
    105105{
    106106    while (!m_history.isEmpty() && m_history.first()->isUndoableStateMark())
     
    109109    while (!m_history.isEmpty()) {
    110110        OwnPtr<Action> first = m_history.takeFirst();
    111         if (!first->undo(errorString)) {
     111        if (!first->undo(ec)) {
    112112            m_history.clear();
    113113            return false;
  • trunk/Source/WebCore/inspector/InspectorHistory.h

    r106953 r107399  
    4444class Node;
    4545
    46 typedef String ErrorString;
    47 
    4846#if ENABLE(INSPECTOR)
    4947
     
    6260        virtual void merge(PassOwnPtr<Action>);
    6361
    64         virtual bool perform(ErrorString*) = 0;
    65         virtual bool undo(ErrorString*) = 0;
     62        virtual bool perform(ExceptionCode&) = 0;
     63        virtual bool undo(ExceptionCode&) = 0;
    6664    private:
    6765        String m_name;
     
    7169    virtual ~InspectorHistory();
    7270
    73     bool perform(PassOwnPtr<Action>, ErrorString*);
     71    bool perform(PassOwnPtr<Action>, ExceptionCode&);
    7472    void markUndoableState();
    7573
    76     bool undo(ErrorString*);
     74    bool undo(ExceptionCode&);
    7775    void reset();
    7876
  • trunk/Source/WebCore/inspector/InspectorPageAgent.cpp

    r107257 r107399  
    572572        return;
    573573    }
    574     DOMPatchSupport patcher(document);
    575     patcher.patchDocument(html);
     574    DOMPatchSupport::patchDocument(document, html);
    576575}
    577576
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp

    r106953 r107399  
    281281// The propertyText (if not empty) is checked to be a valid style declaration (containing at least one property). If not,
    282282// the method returns false (denoting an error).
    283 bool InspectorStyle::setPropertyText(ErrorString* errorString, unsigned index, const String& propertyText, bool overwrite, String* oldText)
     283bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText, bool overwrite, String* oldText, ExceptionCode& ec)
    284284{
    285285    ASSERT(m_parentStyleSheet);
     
    287287
    288288    if (!m_parentStyleSheet->ensureParsedDataReady()) {
    289         *errorString = "Internal error: no stylesheet parsed data available";
     289        ec = NOT_FOUND_ERR;
    290290        return false;
    291291    }
     
    304304        // At least one property + the bogus property added just above should be present.
    305305        if (propertyCount < 2) {
    306             *errorString = "Invalid property value";
     306            ec = SYNTAX_ERR;
    307307            return false;
    308308        }
     
    310310        // Check for a proper propertyText termination (the parser could at least restore to the PROPERTY_NAME state).
    311311        if (propertyData.at(propertyCount - 1).name != bogusPropertyName) {
    312             *errorString = "Invalid property value";
     312            ec = SYNTAX_ERR;
    313313            return false;
    314314        }
     
    317317    RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor(m_style.get());
    318318    if (!sourceData) {
    319         *errorString = "Internal error: no CSS rule source found";
     319        ec = NOT_FOUND_ERR;
    320320        return false;
    321321    }
     
    324324    bool success = styleText(&text);
    325325    if (!success) {
    326         *errorString = "Internal error: could not fetch style text";
     326        ec = NOT_FOUND_ERR;
    327327        return false;
    328328    }
     
    338338}
    339339
    340 bool InspectorStyle::toggleProperty(ErrorString* errorString, unsigned index, bool disable)
     340bool InspectorStyle::toggleProperty(unsigned index, bool disable, ExceptionCode& ec)
    341341{
    342342    ASSERT(m_parentStyleSheet);
    343343    if (!m_parentStyleSheet->ensureParsedDataReady()) {
    344         *errorString = "Can toggle only source-based properties";
     344        ec = NO_MODIFICATION_ALLOWED_ERR;
    345345        return false;
    346346    }
     
    348348    RefPtr<CSSRuleSourceData> sourceData = m_parentStyleSheet->ruleSourceDataFor(m_style.get());
    349349    if (!sourceData) {
    350         *errorString = "Internal error: No source data for the style found";
     350        ec = NOT_FOUND_ERR;
    351351        return false;
    352352    }
     
    355355    bool success = styleText(&text);
    356356    if (!success) {
    357         *errorString = "Internal error: could not fetch style text";
     357        ec = NOT_FOUND_ERR;
    358358        return false;
    359359    }
     
    362362    populateAllProperties(&allProperties);
    363363    if (index >= allProperties.size()) {
    364         *errorString = "Property index is outside of property range";
     364        ec = INDEX_SIZE_ERR;
    365365        return false;
    366366    }
     
    869869}
    870870
    871 bool InspectorStyleSheet::setPropertyText(ErrorString* errorString, const InspectorCSSId& id, unsigned propertyIndex, const String& text, bool overwrite, String* oldText)
     871bool InspectorStyleSheet::setPropertyText(const InspectorCSSId& id, unsigned propertyIndex, const String& text, bool overwrite, String* oldText, ExceptionCode& ec)
    872872{
    873873    RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id);
    874874    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
     882bool InspectorStyleSheet::toggleProperty(const InspectorCSSId& id, unsigned propertyIndex, bool disable, ExceptionCode& ec)
    883883{
    884884    RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id);
    885885    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);
    891891    if (success) {
    892892        if (disable)
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.h

    r106953 r107399  
    2727
    2828#include "CSSPropertySourceData.h"
     29#include "ExceptionCode.h"
    2930#include "InspectorStyleTextEditor.h"
    3031#include "InspectorValues.h"
     
    132133    PassRefPtr<InspectorArray> buildArrayForComputedStyle() const;
    133134    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&);
    136137
    137138private:
     
    175176    PassRefPtr<InspectorObject> buildObjectForRule(CSSStyleRule*);
    176177    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&);
    179180
    180181    virtual bool getText(String* result) const;
Note: See TracChangeset for help on using the changeset viewer.