Title: [138164] trunk/Source/WebCore
Revision
138164
Author
commit-qu...@webkit.org
Date
2012-12-19 08:07:10 -0800 (Wed, 19 Dec 2012)

Log Message

Web Inspector: refactor DefaultTextEditor's |expanded| setters
https://bugs.webkit.org/show_bug.cgi?id=105415

Patch by Andrey Lushnikov <lushni...@chromium.com> on 2012-12-19
Reviewed by Pavel Feldman.

Refactor |expanded| setters and getters into |collapse()|, |expand()|
and |expanded()| methods

* inspector/front-end/DefaultTextEditor.js:
(WebInspector.TextEditorChunkedPanel.prototype._splitChunkOnALine):
(WebInspector.TextEditorChunkedPanel.prototype._expandChunks):
(WebInspector.TextEditorGutterPanel.prototype.textChanged):
(WebInspector.TextEditorGutterChunk.prototype.expanded): Added.
(WebInspector.TextEditorGutterChunk.prototype.collapse): Added.
(WebInspector.TextEditorGutterChunk.prototype.expand): Added.
(WebInspector.TextEditorMainPanel.prototype.markAndRevealRange):
(WebInspector.TextEditorMainPanel.prototype._updateHighlightsForRange):
(WebInspector.TextEditorMainChunk.prototype.expanded): Added.
(WebInspector.TextEditorMainChunk.prototype.collapse): Added.
(WebInspector.TextEditorMainChunk.prototype.expand): Added.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (138163 => 138164)


--- trunk/Source/WebCore/ChangeLog	2012-12-19 15:43:16 UTC (rev 138163)
+++ trunk/Source/WebCore/ChangeLog	2012-12-19 16:07:10 UTC (rev 138164)
@@ -1,3 +1,26 @@
+2012-12-19  Andrey Lushnikov  <lushni...@chromium.com>
+
+        Web Inspector: refactor DefaultTextEditor's |expanded| setters
+        https://bugs.webkit.org/show_bug.cgi?id=105415
+
+        Reviewed by Pavel Feldman.
+
+        Refactor |expanded| setters and getters into |collapse()|, |expand()|
+        and |expanded()| methods
+
+        * inspector/front-end/DefaultTextEditor.js:
+        (WebInspector.TextEditorChunkedPanel.prototype._splitChunkOnALine):
+        (WebInspector.TextEditorChunkedPanel.prototype._expandChunks):
+        (WebInspector.TextEditorGutterPanel.prototype.textChanged):
+        (WebInspector.TextEditorGutterChunk.prototype.expanded): Added.
+        (WebInspector.TextEditorGutterChunk.prototype.collapse): Added.
+        (WebInspector.TextEditorGutterChunk.prototype.expand): Added.
+        (WebInspector.TextEditorMainPanel.prototype.markAndRevealRange):
+        (WebInspector.TextEditorMainPanel.prototype._updateHighlightsForRange):
+        (WebInspector.TextEditorMainChunk.prototype.expanded): Added.
+        (WebInspector.TextEditorMainChunk.prototype.collapse): Added.
+        (WebInspector.TextEditorMainChunk.prototype.expand): Added.
+
 2012-12-19  Pan Deng  <pan.d...@intel.com>
 
         Web Inspector: Use Document* as argument in WebSocket Instrumentation.

Modified: trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js (138163 => 138164)


--- trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2012-12-19 15:43:16 UTC (rev 138163)
+++ trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2012-12-19 16:07:10 UTC (rev 138164)
@@ -778,8 +778,8 @@
         this.beginDomUpdates();
 
         var oldChunk = this._textChunks[chunkNumber];
-        var wasExpanded = oldChunk.expanded;
-        oldChunk.expanded = false;
+        var wasExpanded = oldChunk.expanded();
+        oldChunk.collapse();
 
         var insertIndex = chunkNumber + 1;
 
@@ -809,10 +809,10 @@
 
         if (wasExpanded) {
             if (prefixChunk)
-                prefixChunk.expanded = true;
-            lineChunk.expanded = true;
+                prefixChunk.expand();
+            lineChunk.expand();
             if (suffixChunk)
-                suffixChunk.expanded = true;
+                suffixChunk.expand();
         }
 
         this.endDomUpdates();
@@ -910,7 +910,7 @@
     _findFirstVisibleLineNumber: function(visibleFrom)
     {
         var chunk = this._textChunks[this._findFirstVisibleChunkNumber(visibleFrom)];
-        if (!chunk.expanded)
+        if (!chunk.expanded())
             return chunk.startLine;
 
         var lineNumbers = [];
@@ -961,11 +961,11 @@
     {
         // First collapse chunks to collect the DOM elements into a cache to reuse them later.
         for (var i = 0; i < fromIndex; ++i)
-            this._textChunks[i].expanded = false;
+            this._textChunks[i].collapse();
         for (var i = toIndex; i < this._textChunks.length; ++i)
-            this._textChunks[i].expanded = false;
+            this._textChunks[i].collapse();
         for (var i = fromIndex; i < toIndex; ++i)
-            this._textChunks[i].expanded = true;
+            this._textChunks[i].expand();
     },
 
     /**
@@ -1052,7 +1052,7 @@
                 var chunk = this._textChunks[chunkNumber];
                 if (chunk.startLine + chunk.linesCount <= this._textModel.linesCount)
                     break;
-                chunk.expanded = false;
+                chunk.collapse();
                 this._container.removeChild(chunk.element);
             }
             this._textChunks.length = chunkNumber + 1;
@@ -1215,52 +1215,68 @@
     /**
      * @return {boolean}
      */
-    get expanded()
+    expanded: function()
     {
         return this._expanded;
     },
 
-    set expanded(expanded)
+    expand: function()
     {
         if (this.linesCount === 1)
             this._textEditor._syncDecorationsForLineListener(this.startLine);
 
-        if (this._expanded === expanded)
+        if (this._expanded)
             return;
 
-        this._expanded = expanded;
+        this._expanded = true;
 
         if (this.linesCount === 1)
             return;
 
         this._textEditor.beginDomUpdates();
 
-        if (expanded) {
-            this._expandedLineRows = [];
-            var parentElement = this.element.parentElement;
-            for (var i = this.startLine; i < this.startLine + this.linesCount; ++i) {
-                var lineRow = this._createRow(i);
-                parentElement.insertBefore(lineRow, this.element);
-                this._expandedLineRows.push(lineRow);
-            }
-            parentElement.removeChild(this.element);
-            this._textEditor._syncLineHeightListener(this._expandedLineRows[0]);
-        } else {
-            var elementInserted = false;
-            for (var i = 0; i < this._expandedLineRows.length; ++i) {
-                var lineRow = this._expandedLineRows[i];
-                var parentElement = lineRow.parentElement;
-                if (parentElement) {
-                    if (!elementInserted) {
-                        elementInserted = true;
-                        parentElement.insertBefore(this.element, lineRow);
-                    }
-                    parentElement.removeChild(lineRow);
+        this._expandedLineRows = [];
+        var parentElement = this.element.parentElement;
+        for (var i = this.startLine; i < this.startLine + this.linesCount; ++i) {
+            var lineRow = this._createRow(i);
+            parentElement.insertBefore(lineRow, this.element);
+            this._expandedLineRows.push(lineRow);
+        }
+        parentElement.removeChild(this.element);
+        this._textEditor._syncLineHeightListener(this._expandedLineRows[0]);
+
+        this._textEditor.endDomUpdates();
+    },
+
+    collapse: function()
+    {
+        if (this.linesCount === 1)
+            this._textEditor._syncDecorationsForLineListener(this.startLine);
+
+        if (!this._expanded)
+            return;
+
+        this._expanded = false;
+
+        if (this.linesCount === 1)
+            return;
+
+        this._textEditor.beginDomUpdates();
+
+        var elementInserted = false;
+        for (var i = 0; i < this._expandedLineRows.length; ++i) {
+            var lineRow = this._expandedLineRows[i];
+            var parentElement = lineRow.parentElement;
+            if (parentElement) {
+                if (!elementInserted) {
+                    elementInserted = true;
+                    parentElement.insertBefore(this.element, lineRow);
                 }
-                this._textEditor._cachedRows.push(lineRow);
+                parentElement.removeChild(lineRow);
             }
-            delete this._expandedLineRows;
+            this._textEditor._cachedRows.push(lineRow);
         }
+        delete this._expandedLineRows;
 
         this._textEditor.endDomUpdates();
     },
@@ -1452,10 +1468,11 @@
             // Remove the marked region immediately.
             this.beginDomUpdates();
             var chunk = this.chunkForLine(markedLine);
-            var wasExpanded = chunk.expanded;
-            chunk.expanded = false;
+            var wasExpanded = chunk.expanded();
+            chunk.collapse();
             chunk.updateCollapsedLineRow();
-            chunk.expanded = wasExpanded;
+            if (wasExpanded)
+                chunk.expand();
             this.endDomUpdates();
         }
 
@@ -2476,7 +2493,7 @@
         if (!updated) {
             // Highlights for the chunks below are invalid, so just collapse them.
             for (var i = this._chunkNumberForLine(range.startLine); i < this._textChunks.length; ++i)
-                this._textChunks[i].expanded = false;
+                this._textChunks[i].collapse();
         }
 
         this._repaintAll();
@@ -2629,52 +2646,63 @@
     /**
      * @return {boolean}
      */
-    get expanded()
+    expanded: function()
     {
         return this._expanded;
     },
 
-    set expanded(expanded)
+    expand: function()
     {
-        if (this._expanded === expanded)
+        if (this._expanded)
             return;
 
-        this._expanded = expanded;
+        this._expanded = true;
 
         if (this.linesCount === 1) {
-            if (expanded)
-                this._chunkedPanel._paintLine(this.element);
+            this._chunkedPanel._paintLine(this.element);
             return;
         }
 
         this._chunkedPanel.beginDomUpdates();
 
-        if (expanded) {
-            this._expandedLineRows = [];
-            var parentElement = this.element.parentElement;
-            for (var i = this.startLine; i < this.startLine + this.linesCount; ++i) {
-                var lineRow = this._createRow(i);
-                parentElement.insertBefore(lineRow, this.element);
-                this._expandedLineRows.push(lineRow);
-            }
-            parentElement.removeChild(this.element);
-            this._chunkedPanel._paintLines(this.startLine, this.startLine + this.linesCount);
-        } else {
-            var elementInserted = false;
-            for (var i = 0; i < this._expandedLineRows.length; ++i) {
-                var lineRow = this._expandedLineRows[i];
-                var parentElement = lineRow.parentElement;
-                if (parentElement) {
-                    if (!elementInserted) {
-                        elementInserted = true;
-                        parentElement.insertBefore(this.element, lineRow);
-                    }
-                    parentElement.removeChild(lineRow);
+        this._expandedLineRows = [];
+        var parentElement = this.element.parentElement;
+        for (var i = this.startLine; i < this.startLine + this.linesCount; ++i) {
+            var lineRow = this._createRow(i);
+            parentElement.insertBefore(lineRow, this.element);
+            this._expandedLineRows.push(lineRow);
+        }
+        parentElement.removeChild(this.element);
+        this._chunkedPanel._paintLines(this.startLine, this.startLine + this.linesCount);
+
+        this._chunkedPanel.endDomUpdates();
+    },
+
+    collapse: function()
+    {
+        if (!this._expanded)
+            return;
+
+        this._expanded = false;
+        if (this.linesCount === 1)
+            return;
+
+        this._chunkedPanel.beginDomUpdates();
+
+        var elementInserted = false;
+        for (var i = 0; i < this._expandedLineRows.length; ++i) {
+            var lineRow = this._expandedLineRows[i];
+            var parentElement = lineRow.parentElement;
+            if (parentElement) {
+                if (!elementInserted) {
+                    elementInserted = true;
+                    parentElement.insertBefore(this.element, lineRow);
                 }
-                this._chunkedPanel._releaseLinesHighlight(lineRow);
+                parentElement.removeChild(lineRow);
             }
-            delete this._expandedLineRows;
+            this._chunkedPanel._releaseLinesHighlight(lineRow);
         }
+        delete this._expandedLineRows;
 
         this._chunkedPanel.endDomUpdates();
     },
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to