2011-04-07 Pavel Podivilov <podivilov@chromium.org>

        Reviewed by Pavel Feldman.

        Web Inspector: make SourceFrame TextViewer's delegate for editing operations.
        https://bugs.webkit.org/show_bug.cgi?id=58026

        This is the first step of decoupling TextViewer from SourceFrame.

        * inspector/front-end/SourceFrame.js:
        (WebInspector.SourceFrame):
        (WebInspector.SourceFrame.prototype.show):
        (WebInspector.SourceFrame.prototype.hide):
        (WebInspector.SourceFrame.prototype._ensureContentLoaded):
        (WebInspector.SourceFrame.prototype.contentEditable):
        (WebInspector.SourceFrame.prototype.startEditing):
        (WebInspector.SourceFrame.prototype.endEditing):
        (WebInspector.SourceFrame.prototype._createTextViewer):
        (WebInspector.SourceFrame.prototype._handleSave):
        (WebInspector.SourceFrame.prototype._handleRevertEditing):
        * inspector/front-end/TextViewer.js:
        (WebInspector.TextViewer.prototype._enterInternalTextChangeMode):
        (WebInspector.TextViewer.prototype._exitInternalTextChangeMode):
        (WebInspector.TextViewer.prototype._syncDecorationsForLine):
        (WebInspector.TextViewer.prototype._doubleClick):
        (WebInspector.TextViewerDelegate):
        (WebInspector.TextViewerDelegate.prototype.contentEditable):
        (WebInspector.TextViewerDelegate.prototype.startEditing):
        (WebInspector.TextViewerDelegate.prototype.endEditing):
        (WebInspector.TextEditorMainPanel.prototype._paintScheduledLines):
        (WebInspector.TextEditorMainPanel.prototype._handleDOMUpdates):
        * inspector/front-end/inspector.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@83288 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent fab8862c
......@@ -68,7 +68,7 @@ function test()
function replaceInSource(sourceFrame, string, replacement)
{
sourceFrame._textViewer.readOnly = false;
sourceFrame._startEditing();
sourceFrame.startEditing();
var newText = sourceFrame._textModel.text.replace(string, replacement);
sourceFrame._textModel.setText(null, newText);
sourceFrame._handleSave();
......
2011-04-07 Pavel Podivilov <podivilov@chromium.org>
Reviewed by Pavel Feldman.
Web Inspector: make SourceFrame TextViewer's delegate for editing operations.
https://bugs.webkit.org/show_bug.cgi?id=58026
This is the first step of decoupling TextViewer from SourceFrame.
* inspector/front-end/SourceFrame.js:
(WebInspector.SourceFrame):
(WebInspector.SourceFrame.prototype.show):
(WebInspector.SourceFrame.prototype.hide):
(WebInspector.SourceFrame.prototype._ensureContentLoaded):
(WebInspector.SourceFrame.prototype.contentEditable):
(WebInspector.SourceFrame.prototype.startEditing):
(WebInspector.SourceFrame.prototype.endEditing):
(WebInspector.SourceFrame.prototype._createTextViewer):
(WebInspector.SourceFrame.prototype._handleSave):
(WebInspector.SourceFrame.prototype._handleRevertEditing):
* inspector/front-end/TextViewer.js:
(WebInspector.TextViewer.prototype._enterInternalTextChangeMode):
(WebInspector.TextViewer.prototype._exitInternalTextChangeMode):
(WebInspector.TextViewer.prototype._syncDecorationsForLine):
(WebInspector.TextViewer.prototype._doubleClick):
(WebInspector.TextViewerDelegate):
(WebInspector.TextViewerDelegate.prototype.contentEditable):
(WebInspector.TextViewerDelegate.prototype.startEditing):
(WebInspector.TextViewerDelegate.prototype.endEditing):
(WebInspector.TextEditorMainPanel.prototype._paintScheduledLines):
(WebInspector.TextEditorMainPanel.prototype._handleDOMUpdates):
* inspector/front-end/inspector.html:
2011-04-08 Leandro Gracia Gil <leandrogracia@chromium.org>
Reviewed by Steve Block.
......@@ -30,9 +30,7 @@
WebInspector.SourceFrame = function(delegate, url)
{
WebInspector.View.call(this);
this.element.addStyleClass("script-view");
WebInspector.TextViewerDelegate.call(this);
this._delegate = delegate;
this._url = url;
......@@ -50,7 +48,6 @@ WebInspector.SourceFrame = function(delegate, url)
this._breakpoints = {};
this._registerShortcuts();
this.element.addEventListener("keydown", this._handleKeyDown.bind(this), false);
}
WebInspector.SourceFrame.Events = {
......@@ -61,7 +58,7 @@ WebInspector.SourceFrame.prototype = {
show: function(parentElement)
{
WebInspector.View.prototype.show.call(this, parentElement);
this._parentElement = parentElement;
this._ensureContentLoaded();
......@@ -70,24 +67,39 @@ WebInspector.SourceFrame.prototype = {
this._textViewer.scrollTop = this._scrollTop;
if (this._scrollLeft)
this._textViewer.scrollLeft = this._scrollLeft;
this._textViewer.show(parentElement);
this._textViewer.resize();
}
},
hide: function()
{
delete this._parentElement;
if (this._textViewer) {
this._scrollTop = this._textViewer.scrollTop;
this._scrollLeft = this._textViewer.scrollLeft;
this._textViewer.freeCachedElements();
this._textViewer.hide();
}
WebInspector.View.prototype.hide.call(this);
this._hidePopup();
this._clearLineHighlight();
},
detach: function()
{
delete this._parentElement;
if (this._textViewer)
this._textViewer.detach();
},
get element()
{
return this._textViewer.element;
},
get loaded()
{
return !!this._content;
......@@ -211,7 +223,12 @@ WebInspector.SourceFrame.prototype = {
delete this._viewerState;
},
_startEditing: function()
isContentEditable: function()
{
return this._delegate.canEditScriptSource();
},
startEditing: function()
{
if (!this._viewerState) {
this._saveViewerState();
......@@ -222,7 +239,7 @@ WebInspector.SourceFrame.prototype = {
this.clearMessages();
},
_endEditing: function(oldRange, newRange)
endEditing: function(oldRange, newRange)
{
// Adjust execution line number.
if (typeof this._executionLineNumber === "number") {
......@@ -266,22 +283,17 @@ WebInspector.SourceFrame.prototype = {
this._content = content;
this._textModel.setText(null, content);
this._textViewer = new WebInspector.TextViewer(this._textModel, WebInspector.platform, this._url);
this._textViewer.startEditingListener = this._startEditing.bind(this);
this._textViewer.endEditingListener = this._endEditing.bind(this);
this._textViewer = new WebInspector.TextViewer(this._textModel, WebInspector.platform, this._url, this);
var element = this._textViewer.element;
element.addStyleClass("script-view");
if (this._delegate.debuggingSupported()) {
element.addEventListener("contextmenu", this._contextMenu.bind(this), true);
element.addEventListener("mousedown", this._mouseDown.bind(this), true);
element.addEventListener("mousemove", this._mouseMove.bind(this), true);
element.addEventListener("scroll", this._scroll.bind(this), true);
}
if (this._delegate.canEditScriptSource())
element.addEventListener("dblclick", this._doubleClick.bind(this), true);
this.element.appendChild(element);
element.addEventListener("keydown", this._handleKeyDown.bind(this), false);
this._textViewer.beginUpdates();
......@@ -304,6 +316,9 @@ WebInspector.SourceFrame.prototype = {
this.dispatchEventToListeners(WebInspector.SourceFrame.Events.Loaded);
this._textViewer.endUpdates();
if (this._parentElement)
this.show(this._parentElement)
},
_setTextViewerDecorations: function()
......@@ -891,7 +906,7 @@ WebInspector.SourceFrame.prototype = {
this._viewerState = originalViewerState;
this._textViewer.readOnly = false;
this._delegate.setScriptSourceIsBeingEdited(true);
WebInspector.log(error, WebInspector.ConsoleMessage.MessageLevel.Error);
WebInspector.log(error.data[0], WebInspector.ConsoleMessage.MessageLevel.Error);
WebInspector.showConsole();
}
}
......@@ -908,25 +923,10 @@ WebInspector.SourceFrame.prototype = {
this._textViewer.readOnly = true;
this._delegate.setScriptSourceIsBeingEdited(false);
return true;
},
_doubleClick: function(event)
{
if (!this._delegate.canEditScriptSource())
return;
var lineRow = event.target.enclosingNodeOrSelfWithClass("webkit-line-content");
if (!lineRow)
return; // Do not trigger editing from line numbers.
if (this._textViewer.readOnly) {
this._textViewer.readOnly = false;
window.getSelection().collapseToStart();
}
}
}
WebInspector.SourceFrame.prototype.__proto__ = WebInspector.View.prototype;
WebInspector.SourceFrame.prototype.__proto__ = WebInspector.TextViewerDelegate.prototype;
WebInspector.SourceFrameDelegate = function()
......
......@@ -29,12 +29,14 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
WebInspector.TextViewer = function(textModel, platform, url)
WebInspector.TextViewer = function(textModel, platform, url, delegate)
{
WebInspector.View.call(this);
this._textModel = textModel;
this._textModel.changeListener = this._textChanged.bind(this);
this._delegate = delegate;
this.element = document.createElement("div");
this.element.className = "text-editor monospace";
var enterTextChangeMode = this._enterInternalTextChangeMode.bind(this);
......@@ -49,7 +51,9 @@ WebInspector.TextViewer = function(textModel, platform, url)
// Forward mouse wheel events from the unscrollable gutter to the main panel.
this._gutterPanel.element.addEventListener("mousewheel", function(e) {
this._mainPanel.element.dispatchEvent(e);
}.bind(this), false)
}.bind(this), false);
this.element.addEventListener("dblclick", this._doubleClick.bind(this), true);
}
WebInspector.TextViewer.prototype = {
......@@ -68,16 +72,6 @@ WebInspector.TextViewer.prototype = {
return this._mainPanel.readOnly;
},
set startEditingListener(startEditingListener)
{
this._startEditingListener = startEditingListener;
},
set endEditingListener(endEditingListener)
{
this._endEditingListener = endEditingListener;
},
get textModel()
{
return this._textModel;
......@@ -175,8 +169,7 @@ WebInspector.TextViewer.prototype = {
{
this._internalTextChangeMode = true;
if (this._startEditingListener)
this._startEditingListener();
this._delegate.startEditing();
},
_exitInternalTextChangeMode: function(oldRange, newRange)
......@@ -187,8 +180,7 @@ WebInspector.TextViewer.prototype = {
this._gutterPanel.textChanged(oldRange, newRange);
this._updatePanelOffsets();
if (this._endEditingListener)
this._endEditingListener(oldRange, newRange);
this._delegate.endEditing(oldRange, newRange);
},
_updatePanelOffsets: function()
......@@ -230,9 +222,49 @@ WebInspector.TextViewer.prototype = {
if (gutterChunk.linesCount === 1)
gutterChunk.element.style.removeProperty("height");
}
},
_doubleClick: function(event)
{
if (!this._delegate.isContentEditable())
return;
var lineRow = event.target.enclosingNodeOrSelfWithClass("webkit-line-content");
if (!lineRow)
return; // Do not trigger editing from line numbers.
if (this.readOnly) {
this.readOnly = false;
window.getSelection().collapseToStart();
}
}
}
WebInspector.TextViewer.prototype.__proto__ = WebInspector.View.prototype;
WebInspector.TextViewerDelegate = function()
{
}
WebInspector.TextViewerDelegate.prototype = {
isContentEditable: function()
{
// Should be implemented by subclasses.
},
startEditing: function()
{
// Should be implemented by subclasses.
},
endEditing: function(oldRange, newRange)
{
// Should be implemented by subclasses.
}
}
WebInspector.TextViewerDelegate.prototype.__proto__ = WebInspector.Object.prototype;
WebInspector.TextEditorChunkedPanel = function(textModel)
{
this._textModel = textModel;
......@@ -1269,7 +1301,7 @@ WebInspector.TextEditorMainPanel.prototype = {
// Now this will no longer be valid.
delete lineRow.lineNumber;
}
if (this._dirtyLines) {
this._dirtyLines.start = Math.min(this._dirtyLines.start, startLine);
this._dirtyLines.end = Math.max(this._dirtyLines.end, endLine);
......
......@@ -100,6 +100,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script type="text/javascript" src="ElementsPanel.js"></script>
<script type="text/javascript" src="NetworkPanel.js"></script>
<script type="text/javascript" src="InjectedFakeWorker.js"></script>
<script type="text/javascript" src="TextViewer.js"></script>
<script type="text/javascript" src="SourceFrame.js"></script>
<script type="text/javascript" src="ResourceView.js"></script>
<script type="text/javascript" src="ScriptsPanel.js"></script>
......@@ -126,7 +127,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<script type="text/javascript" src="DOMSyntaxHighlighter.js"></script>
<script type="text/javascript" src="TextEditorModel.js"></script>
<script type="text/javascript" src="TextEditorHighlighter.js"></script>
<script type="text/javascript" src="TextViewer.js"></script>
<script type="text/javascript" src="SourceTokenizer.js"></script>
<script type="text/javascript" src="SourceCSSTokenizer.js"></script>
<script type="text/javascript" src="SourceHTMLTokenizer.js"></script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment