Title: [164540] trunk/Source/WebInspectorUI
Revision
164540
Author
grao...@webkit.org
Date
2014-02-22 07:29:13 -0800 (Sat, 22 Feb 2014)

Log Message

Web Inspector: allow drag-to-adjust on angle input of gradients editor
https://bugs.webkit.org/show_bug.cgi?id=129095

Reviewed by Timothy Hatcher.

Rename CodeMirrorDragToAlterNumberController to CodeMirrorDragToAdjustNumberController and move
the core logic of a drag-to-adjust behavior out of it to a new generic class DragToAdjustController.
We use this new class from CodeMirrorGradientEditingController to provide drag-to-adjust behavior
in the angle input field of the gradient editor and also as a supporting object for the CodeMirror-
specific class.

* UserInterface/CodeMirrorDragToAdjustNumberController.css: Renamed from Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.css.
(.CodeMirror.drag-to-adjust .CodeMirror-lines):

* UserInterface/CodeMirrorDragToAdjustNumberController.js: Added.
Removed the UI logic and use the new DragToAdjustController as a supporting object instead. We implement
the various DragToAdjustController delegate methods in order to customize its behavior to work within the
context of a CodeMirror editor, specifically to prevent activation when the editor is read-only and to
prevent adjustment when the hovered token isn't a number.

(WebInspector.CodeMirrorDragToAdjustNumberController):
(WebInspector.CodeMirrorDragToAdjustNumberController.prototype.get enabled):
(WebInspector.CodeMirrorDragToAdjustNumberController.prototype.set enabled):
(WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerActiveStateChanged):
(WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerCanBeActivated):
(WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerCanBeAdjusted):
(WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerWasAdjustedByAmount):
(WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerDidReset):
(WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerCanAdjustObjectAtPoint):

* UserInterface/CodeMirrorGradientEditingController.css:
(.gradient-editing-controller > label.drag-to-adjust > input):

* UserInterface/CodeMirrorGradientEditingController.js:
Adopt the new DragToAdjustController to make the angle input field value adjustable by dragging.

(WebInspector.CodeMirrorGradientEditingController.prototype.popoverWillPresent):
(WebInspector.CodeMirrorGradientEditingController.prototype.dragToAdjustControllerWasAdjustedByAmount):
(WebInspector.CodeMirrorGradientEditingController.prototype._handleInputEvent):
(WebInspector.CodeMirrorGradientEditingController.prototype._angleInputValueDidChange):

* UserInterface/DragToAdjustController.js: Renamed from Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.js.
New DragToAdjustController class exposing only the core UI logic of a drag-to-adjust behavior in the context
of a DOM element, exposing a few delegation methods to customize the controller's behavior:

- dragToAdjustControllerActiveStateChanged() notifies that the .active property has changed, allowing bringup
and cleanup work to be performed.

- dragToAdjustControllerDidReset() notifies that the various tracking states of the controller have been reset
allowing other state objects used by clients to be cleared.

- dragToAdjustControllerCanBeActivated() is used to check whether the controller may enter the active state upon
first hovering the target element.

- dragToAdjustControllerCanBeAdjusted() is used to check whether adjustment can be performed at the moment when
the user actually is about to engage in a drag-to-adjust interaction.

- dragToAdjustControllerCanAdjustObjectAtPoint() is used to check whether the object at the provided point (mouse
location) is an adjustable value.

- dragToAdjustControllerWasAdjustedByAmount() notifies that there is a new amount to add to the current value
following a drag-to-adjust interaction.

(WebInspector.DragToAdjustController):
(WebInspector.DragToAdjustController.prototype.get element):
(WebInspector.DragToAdjustController.prototype.set element):
(WebInspector.DragToAdjustController.prototype.set enabled):
(WebInspector.DragToAdjustController.prototype.get active):
(WebInspector.DragToAdjustController.prototype.set active):
(WebInspector.DragToAdjustController.prototype.reset):
(WebInspector.DragToAdjustController.prototype.handleEvent):
(WebInspector.DragToAdjustController.prototype._setDragging):
(WebInspector.DragToAdjustController.prototype._setTracksMouseClickAndDrag):
(WebInspector.DragToAdjustController.prototype._modifiersDidChange):
(WebInspector.DragToAdjustController.prototype._mouseMoved):
(WebInspector.DragToAdjustController.prototype._mouseWasPressed):
(WebInspector.DragToAdjustController.prototype._mouseWasDragged):
(WebInspector.DragToAdjustController.prototype._mouseWasReleased):

* UserInterface/Main.html:
Link in new source files.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (164539 => 164540)


--- trunk/Source/WebInspectorUI/ChangeLog	2014-02-22 13:58:51 UTC (rev 164539)
+++ trunk/Source/WebInspectorUI/ChangeLog	2014-02-22 15:29:13 UTC (rev 164540)
@@ -1,3 +1,87 @@
+2014-02-22  Antoine Quint  <grao...@webkit.org>
+
+        Web Inspector: allow drag-to-adjust on angle input of gradients editor
+        https://bugs.webkit.org/show_bug.cgi?id=129095
+
+        Reviewed by Timothy Hatcher.
+
+        Rename CodeMirrorDragToAlterNumberController to CodeMirrorDragToAdjustNumberController and move
+        the core logic of a drag-to-adjust behavior out of it to a new generic class DragToAdjustController.
+        We use this new class from CodeMirrorGradientEditingController to provide drag-to-adjust behavior
+        in the angle input field of the gradient editor and also as a supporting object for the CodeMirror-
+        specific class.
+
+        * UserInterface/CodeMirrorDragToAdjustNumberController.css: Renamed from Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.css.
+        (.CodeMirror.drag-to-adjust .CodeMirror-lines):
+
+        * UserInterface/CodeMirrorDragToAdjustNumberController.js: Added.
+        Removed the UI logic and use the new DragToAdjustController as a supporting object instead. We implement
+        the various DragToAdjustController delegate methods in order to customize its behavior to work within the
+        context of a CodeMirror editor, specifically to prevent activation when the editor is read-only and to
+        prevent adjustment when the hovered token isn't a number.
+
+        (WebInspector.CodeMirrorDragToAdjustNumberController):
+        (WebInspector.CodeMirrorDragToAdjustNumberController.prototype.get enabled):
+        (WebInspector.CodeMirrorDragToAdjustNumberController.prototype.set enabled):
+        (WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerActiveStateChanged):
+        (WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerCanBeActivated):
+        (WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerCanBeAdjusted):
+        (WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerWasAdjustedByAmount):
+        (WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerDidReset):
+        (WebInspector.CodeMirrorDragToAdjustNumberController.prototype.dragToAdjustControllerCanAdjustObjectAtPoint):
+
+        * UserInterface/CodeMirrorGradientEditingController.css:
+        (.gradient-editing-controller > label.drag-to-adjust > input):
+
+        * UserInterface/CodeMirrorGradientEditingController.js:
+        Adopt the new DragToAdjustController to make the angle input field value adjustable by dragging.
+
+        (WebInspector.CodeMirrorGradientEditingController.prototype.popoverWillPresent):
+        (WebInspector.CodeMirrorGradientEditingController.prototype.dragToAdjustControllerWasAdjustedByAmount):
+        (WebInspector.CodeMirrorGradientEditingController.prototype._handleInputEvent):
+        (WebInspector.CodeMirrorGradientEditingController.prototype._angleInputValueDidChange):
+
+        * UserInterface/DragToAdjustController.js: Renamed from Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.js.
+        New DragToAdjustController class exposing only the core UI logic of a drag-to-adjust behavior in the context
+        of a DOM element, exposing a few delegation methods to customize the controller's behavior:
+
+        - dragToAdjustControllerActiveStateChanged() notifies that the .active property has changed, allowing bringup
+        and cleanup work to be performed.
+
+        - dragToAdjustControllerDidReset() notifies that the various tracking states of the controller have been reset
+        allowing other state objects used by clients to be cleared.
+
+        - dragToAdjustControllerCanBeActivated() is used to check whether the controller may enter the active state upon
+        first hovering the target element.
+
+        - dragToAdjustControllerCanBeAdjusted() is used to check whether adjustment can be performed at the moment when
+        the user actually is about to engage in a drag-to-adjust interaction.
+
+        - dragToAdjustControllerCanAdjustObjectAtPoint() is used to check whether the object at the provided point (mouse
+        location) is an adjustable value.
+
+        - dragToAdjustControllerWasAdjustedByAmount() notifies that there is a new amount to add to the current value
+        following a drag-to-adjust interaction.
+
+        (WebInspector.DragToAdjustController):
+        (WebInspector.DragToAdjustController.prototype.get element):
+        (WebInspector.DragToAdjustController.prototype.set element):
+        (WebInspector.DragToAdjustController.prototype.set enabled):
+        (WebInspector.DragToAdjustController.prototype.get active):
+        (WebInspector.DragToAdjustController.prototype.set active):
+        (WebInspector.DragToAdjustController.prototype.reset):
+        (WebInspector.DragToAdjustController.prototype.handleEvent):
+        (WebInspector.DragToAdjustController.prototype._setDragging):
+        (WebInspector.DragToAdjustController.prototype._setTracksMouseClickAndDrag):
+        (WebInspector.DragToAdjustController.prototype._modifiersDidChange):
+        (WebInspector.DragToAdjustController.prototype._mouseMoved):
+        (WebInspector.DragToAdjustController.prototype._mouseWasPressed):
+        (WebInspector.DragToAdjustController.prototype._mouseWasDragged):
+        (WebInspector.DragToAdjustController.prototype._mouseWasReleased):
+
+        * UserInterface/Main.html:
+        Link in new source files.
+
 2014-02-21  Chi Wai Lau  <c...@apple.com>
 
         Web Inspector: Replace binarySearch with lowerBound and upperBound functions

Copied: trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAdjustNumberController.css (from rev 164539, trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.css) (0 => 164540)


--- trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAdjustNumberController.css	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAdjustNumberController.css	2014-02-22 15:29:13 UTC (rev 164540)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+.CodeMirror.drag-to-adjust .CodeMirror-lines {
+    cursor: col-resize;
+}

Added: trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAdjustNumberController.js (0 => 164540)


--- trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAdjustNumberController.js	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAdjustNumberController.js	2014-02-22 15:29:13 UTC (rev 164540)
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.CodeMirrorDragToAdjustNumberController = function(codeMirror)
+{
+    this._codeMirror = codeMirror;
+
+    this._dragToAdjustController = new WebInspector.DragToAdjustController(this);
+};
+
+WebInspector.CodeMirrorDragToAdjustNumberController.prototype = {
+    constructor: WebInspector.CodeMirrorDragToAdjustNumberController,
+
+    // Public
+
+    get enabled()
+    {
+        return this._dragToAdjustController.enabled;
+    },
+
+    set enabled(enabled)
+    {
+        if (this.enabled === enabled)
+            return;
+        
+        this._dragToAdjustController.element = this._codeMirror.getWrapperElement();
+        this._dragToAdjustController.enabled = enabled;
+    },
+
+    // Protected
+
+    dragToAdjustControllerActiveStateChanged: function(dragToAdjustController)
+    {
+        if (!dragToAdjustController.active)
+            this._hoveredTokenInfo = null;
+    },
+
+    dragToAdjustControllerCanBeActivated: function(dragToAdjustController)
+    {
+        return !this._codeMirror.getOption("readOnly");
+    },
+
+    dragToAdjustControllerCanBeAdjusted: function(dragToAdjustController)
+    {
+
+        return this._hoveredTokenInfo && this._hoveredTokenInfo.containsNumber;
+    },
+
+    dragToAdjustControllerWasAdjustedByAmount: function(dragToAdjustController, amount)
+    {
+        this._codeMirror.alterNumberInRange(amount, this._hoveredTokenInfo.startPosition, this._hoveredTokenInfo.endPosition, false);
+    },
+
+    dragToAdjustControllerDidReset: function(dragToAdjustController)
+    {
+        this._hoveredTokenInfo = null;
+    },
+
+    dragToAdjustControllerCanAdjustObjectAtPoint: function(dragToAdjustController, point)
+    {
+        var position = this._codeMirror.coordsChar({left: point.x, top: point.y});
+        var token = this._codeMirror.getTokenAt(position);
+
+        if (!token || !token.type || !token.string) {
+            if (this._hoveredTokenInfo)
+                dragToAdjustController.reset();
+            return false;
+        }
+
+        // Stop right here if we're hovering the same token as we were last time.
+        if (this._hoveredTokenInfo && this._hoveredTokenInfo.line === position.line &&
+            this._hoveredTokenInfo.token.start === token.start && this._hoveredTokenInfo.token.end === token.end)
+            return this._hoveredTokenInfo.token.type.indexOf("number") !== -1;
+
+        var containsNumber = token.type.indexOf("number") !== -1;
+        this._hoveredTokenInfo = {
+            token: token,
+            line: position.line,
+            containsNumber: containsNumber,
+            startPosition: {
+                ch: token.start,
+                line: position.line
+            },
+            endPosition: {
+                ch: token.end,
+                line: position.line
+            }
+        };
+        
+        return containsNumber;
+    }
+};
+
+CodeMirror.defineOption("dragToAdjustNumbers", true, function(codeMirror, value, oldValue) {
+    if (!codeMirror.dragToAdjustNumberController)
+        codeMirror.dragToAdjustNumberController = new WebInspector.CodeMirrorDragToAdjustNumberController(codeMirror);
+    codeMirror.dragToAdjustNumberController.enabled = value;
+});

Deleted: trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.css (164539 => 164540)


--- trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.css	2014-02-22 13:58:51 UTC (rev 164539)
+++ trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.css	2014-02-22 15:29:13 UTC (rev 164540)
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-.CodeMirror.drag-to-adjust .CodeMirror-lines {
-    cursor: col-resize;
-}

Deleted: trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.js (164539 => 164540)


--- trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.js	2014-02-22 13:58:51 UTC (rev 164539)
+++ trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.js	2014-02-22 15:29:13 UTC (rev 164540)
@@ -1,234 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-WebInspector.CodeMirrorDragToAlterNumberController = function(codeMirror)
-{
-    this._codeMirror = codeMirror;
-    this._active = false;
-    this._dragging = false;
-    this._enabled = false;
-    this._tracksMouseClickAndDrag = false;
-};
-
-WebInspector.CodeMirrorDragToAlterNumberController.StyleClassName = "drag-to-adjust";
-
-WebInspector.CodeMirrorDragToAlterNumberController.prototype = {
-    constructor: WebInspector.CodeMirrorDragToAlterNumberController,
-
-    // Public
-
-    set enabled(enabled)
-    {
-        if (this._enabled === enabled)
-            return;
-
-        this._element = this._codeMirror.getWrapperElement();
-
-        if (enabled) {
-            this._element.addEventListener("mouseenter", this);
-            this._element.addEventListener("mouseleave", this);
-        } else {
-            this._element.removeEventListener("mouseenter", this);
-            this._element.removeEventListener("mouseleave", this);
-        }
-    },
-
-    // Protected
-
-    handleEvent: function(event)
-    {
-        switch(event.type) {
-        case "mouseenter":
-            if (!this._dragging)
-                this._setActive(true);
-            break;
-        case "mouseleave":
-            if (!this._dragging)
-                this._setActive(false);
-            break;
-        case "mousemove":
-            if (this._dragging)
-                this._mouseWasDragged(event);
-            else
-                this._mouseMoved(event);
-            break;
-        case "mousedown":
-            this._mouseWasPressed(event);
-            break;
-        case "mouseup":
-            this._mouseWasReleased(event);
-            break;
-        case "contextmenu":
-            event.preventDefault();
-            break;
-        }
-    },
-
-    // Private
-
-    _setActive: function(active)
-    {
-        if (this._active === active || this._codeMirror.getOption("readOnly"))
-            return;
-
-        if (active) {
-            WebInspector.notifications.addEventListener(WebInspector.Notification.GlobalModifierKeysDidChange, this._modifiersDidChange, this);
-            this._element.addEventListener("mousemove", this);
-        } else {
-            WebInspector.notifications.removeEventListener(WebInspector.Notification.GlobalModifierKeysDidChange, this._modifiersDidChange, this);
-            this._element.removeEventListener("mousemove", this);
-            this._hoveredTokenInfo = null;
-            this._setTracksMouseClickAndDrag(false);
-        }
-
-        this._active = active;
-    },
-
-    _setDragging: function(dragging)
-    {
-        if (this._dragging === dragging)
-            return;
-        
-        console.assert(window.event);
-        if (dragging)
-            WebInspector.elementDragStart(this._element, this, this, window.event, "col-resize", window);
-        else
-            WebInspector.elementDragEnd(window.event);
-
-        this._dragging = dragging;
-    },
-
-    _setTracksMouseClickAndDrag: function(tracksMouseClickAndDrag)
-    {
-        if (this._tracksMouseClickAndDrag === tracksMouseClickAndDrag)
-            return;
-        
-        if (tracksMouseClickAndDrag) {
-            this._element.classList.add(WebInspector.CodeMirrorDragToAlterNumberController.StyleClassName);
-            window.addEventListener("mousedown", this, true);
-            window.addEventListener("contextmenu", this, true);
-        } else {
-            this._element.classList.remove(WebInspector.CodeMirrorDragToAlterNumberController.StyleClassName);
-            window.removeEventListener("mousedown", this, true);
-            window.removeEventListener("contextmenu", this, true);
-            this._setDragging(false);
-        }
-        
-        this._tracksMouseClickAndDrag = tracksMouseClickAndDrag;
-    },
-
-    _modifiersDidChange: function(event)
-    {
-        this._setTracksMouseClickAndDrag(this._hoveredTokenInfo && this._hoveredTokenInfo.containsNumber && WebInspector.modifierKeys.altKey);
-    },
-    
-    _mouseMoved: function(event)
-    {
-        var position = this._codeMirror.coordsChar({left: event.pageX, top: event.pageY});
-        var token = this._codeMirror.getTokenAt(position);
-
-        if (!token || !token.type || !token.string) {
-            if (this._hoveredTokenInfo)
-                this._reset();
-            return;
-        }
-
-        // Stop right here if we're hovering the same token as we were last time.
-        if (this._hoveredTokenInfo && this._hoveredTokenInfo.line === position.line &&
-            this._hoveredTokenInfo.token.start === token.start && this._hoveredTokenInfo.token.end === token.end)
-            return;
-
-        var containsNumber = token.type.indexOf("number") !== -1;
-        this._hoveredTokenInfo = {
-            token: token,
-            line: position.line,
-            containsNumber: containsNumber,
-            startPosition: {
-                ch: token.start,
-                line: position.line
-            },
-            endPosition: {
-                ch: token.end,
-                line: position.line
-            }
-        };
-
-        this._setTracksMouseClickAndDrag(containsNumber && event.altKey);
-    },
-    
-    _mouseWasPressed: function(event)
-    {
-        this._lastX = event.screenX;
-
-        this._setDragging(true);
-
-        event.preventDefault();
-        event.stopPropagation();
-    },
-
-    _mouseWasDragged: function(event)
-    {
-        var x = event.screenX;
-        var amount = x - this._lastX;
-
-        if (Math.abs(amount) < 1)
-            return;
-
-        this._lastX = x;
-
-        if (event.ctrlKey)
-            amount /= 10;
-        else if (event.shiftKey)
-            amount *= 10;
-
-        this._codeMirror.alterNumberInRange(amount, this._hoveredTokenInfo.startPosition, this._hoveredTokenInfo.endPosition, false);
-
-        event.preventDefault();
-        event.stopPropagation();
-    },
-
-    _mouseWasReleased: function(event)
-    {
-        this._setDragging(false);
-
-        event.preventDefault();
-        event.stopPropagation();
-
-        this._reset();
-    },
-    
-    _reset: function()
-    {
-        this._hoveredTokenInfo = null;
-        this._setTracksMouseClickAndDrag(false);
-        this._element.classList.remove(WebInspector.CodeMirrorDragToAlterNumberController.StyleClassName);
-    }
-};
-
-CodeMirror.defineOption("dragToAdjustNumbers", true, function(codeMirror, value, oldValue) {
-    if (!codeMirror.dragToAlterNumberController)
-        codeMirror.dragToAlterNumberController = new WebInspector.CodeMirrorDragToAlterNumberController(codeMirror);
-    codeMirror.dragToAlterNumberController.enabled = value;
-});

Modified: trunk/Source/WebInspectorUI/UserInterface/CodeMirrorGradientEditingController.css (164539 => 164540)


--- trunk/Source/WebInspectorUI/UserInterface/CodeMirrorGradientEditingController.css	2014-02-22 13:58:51 UTC (rev 164539)
+++ trunk/Source/WebInspectorUI/UserInterface/CodeMirrorGradientEditingController.css	2014-02-22 15:29:13 UTC (rev 164540)
@@ -112,3 +112,8 @@
     font-size: 13px;
     text-align: right;
 }
+
+.gradient-editing-controller > label.drag-to-adjust,
+.gradient-editing-controller > label.drag-to-adjust > input {
+    cursor: col-resize;
+}

Modified: trunk/Source/WebInspectorUI/UserInterface/CodeMirrorGradientEditingController.js (164539 => 164540)


--- trunk/Source/WebInspectorUI/UserInterface/CodeMirrorGradientEditingController.js	2014-02-22 13:58:51 UTC (rev 164539)
+++ trunk/Source/WebInspectorUI/UserInterface/CodeMirrorGradientEditingController.js	2014-02-22 15:29:13 UTC (rev 164540)
@@ -114,6 +114,10 @@
         this._angleInput.addEventListener("input", this);
         angleLabel.appendChild(this._angleInput);
 
+        var dragToAdjustController = new WebInspector.DragToAdjustController(this);
+        dragToAdjustController.element = angleLabel;
+        dragToAdjustController.enabled = true;
+
         this._updateCSSClassForGradientType();
 
         popover.content = this._container;
@@ -167,6 +171,16 @@
         this.popover.update();
     },
 
+    dragToAdjustControllerWasAdjustedByAmount: function(dragToAdjustController, amount)
+    {
+        var angle = parseFloat(this._angleInput.value) + amount;
+        if (Math.round(angle) !== angle)
+            angle = angle.toFixed(1);
+
+        this._angleInput.value = angle;
+        this._angleInputValueDidChange(angle);
+    },
+
     // Private
 
     _handleInputEvent: function(event)
@@ -175,6 +189,11 @@
         if (isNaN(angle))
             return;
 
+        this._angleInputValueDidChange(angle);
+    },
+
+    _angleInputValueDidChange: function(angle)
+    {
         this.value.angle = angle;
         this.text = this.value.toString();
 

Copied: trunk/Source/WebInspectorUI/UserInterface/DragToAdjustController.js (from rev 164539, trunk/Source/WebInspectorUI/UserInterface/CodeMirrorDragToAlterNumberController.js) (0 => 164540)


--- trunk/Source/WebInspectorUI/UserInterface/DragToAdjustController.js	                        (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/DragToAdjustController.js	2014-02-22 15:29:13 UTC (rev 164540)
@@ -0,0 +1,234 @@
+/*
+ * Copyright (C) 2014 Antoine Quint
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.DragToAdjustController = function(delegate)
+{
+    this._delegate = delegate;
+
+    this._element = null;
+    this._active = false;
+    this._enabled = false;
+    this._dragging = false;
+    this._tracksMouseClickAndDrag = false;
+};
+
+WebInspector.DragToAdjustController.StyleClassName = "drag-to-adjust";
+
+WebInspector.DragToAdjustController.prototype = {
+    constructor: WebInspector.DragToAdjustController,
+
+    // Public
+
+    get element()
+    {
+        return this._element;
+    },
+
+    set element(element)
+    {
+        this._element = element;
+    },
+
+    set enabled(enabled)
+    {
+        if (this._enabled === enabled)
+            return;
+
+        if (enabled) {
+            this._element.addEventListener("mouseenter", this);
+            this._element.addEventListener("mouseleave", this);
+        } else {
+            this._element.removeEventListener("mouseenter", this);
+            this._element.removeEventListener("mouseleave", this);
+        }
+    },
+
+    get active()
+    {
+        return this._active;
+    },
+
+    set active(active)
+    {
+        if (!this._element)
+            return;
+        
+        if (this._active === active)
+            return;
+
+        if (active) {
+            WebInspector.notifications.addEventListener(WebInspector.Notification.GlobalModifierKeysDidChange, this._modifiersDidChange, this);
+            this._element.addEventListener("mousemove", this);
+        } else {
+            WebInspector.notifications.removeEventListener(WebInspector.Notification.GlobalModifierKeysDidChange, this._modifiersDidChange, this);
+            this._element.removeEventListener("mousemove", this);
+            this._setTracksMouseClickAndDrag(false);
+        }
+
+        this._active = active;
+
+        if (this._delegate && typeof this._delegate.dragToAdjustControllerActiveStateChanged === "function")
+            this._delegate.dragToAdjustControllerActiveStateChanged(this);
+    },
+
+    reset: function()
+    {
+        this._setTracksMouseClickAndDrag(false);
+        this._element.classList.remove(WebInspector.DragToAdjustController.StyleClassName);
+
+        if (this._delegate && typeof this._delegate.dragToAdjustControllerDidReset === "function")
+            this._delegate.dragToAdjustControllerDidReset(this);
+    },
+
+    // Protected
+
+    handleEvent: function(event)
+    {
+        switch(event.type) {
+        case "mouseenter":
+            if (!this._dragging) {
+                if (this._delegate && typeof this._delegate.dragToAdjustControllerCanBeActivated === "function")
+                    this.active = this._delegate.dragToAdjustControllerCanBeActivated(this);
+                else
+                    this.active = true;
+            }
+            break;
+        case "mouseleave":
+            if (!this._dragging)
+                this.active = false;
+            break;
+        case "mousemove":
+            if (this._dragging)
+                this._mouseWasDragged(event);
+            else
+                this._mouseMoved(event);
+            break;
+        case "mousedown":
+            this._mouseWasPressed(event);
+            break;
+        case "mouseup":
+            this._mouseWasReleased(event);
+            break;
+        case "contextmenu":
+            event.preventDefault();
+            break;
+        }
+    },
+
+    // Private
+
+    _setDragging: function(dragging)
+    {
+        if (this._dragging === dragging)
+            return;
+        
+        console.assert(window.event);
+        if (dragging)
+            WebInspector.elementDragStart(this._element, this, this, window.event, "col-resize", window);
+        else
+            WebInspector.elementDragEnd(window.event);
+
+        this._dragging = dragging;
+    },
+
+    _setTracksMouseClickAndDrag: function(tracksMouseClickAndDrag)
+    {
+        if (this._tracksMouseClickAndDrag === tracksMouseClickAndDrag)
+            return;
+        
+        if (tracksMouseClickAndDrag) {
+            this._element.classList.add(WebInspector.DragToAdjustController.StyleClassName);
+            window.addEventListener("mousedown", this, true);
+            window.addEventListener("contextmenu", this, true);
+        } else {
+            this._element.classList.remove(WebInspector.DragToAdjustController.StyleClassName);
+            window.removeEventListener("mousedown", this, true);
+            window.removeEventListener("contextmenu", this, true);
+            this._setDragging(false);
+        }
+        
+        this._tracksMouseClickAndDrag = tracksMouseClickAndDrag;
+    },
+
+    _modifiersDidChange: function(event)
+    {
+        var canBeAdjusted = WebInspector.modifierKeys.altKey;
+        if (canBeAdjusted && this._delegate && typeof this._delegate.dragToAdjustControllerCanBeAdjusted === "function")
+            canBeAdjusted = this._delegate.dragToAdjustControllerCanBeAdjusted(this);
+
+        this._setTracksMouseClickAndDrag(canBeAdjusted);
+    },
+    
+    _mouseMoved: function(event)
+    {
+        var canBeAdjusted = event.altKey;
+        if (canBeAdjusted && this._delegate && typeof this._delegate.dragToAdjustControllerCanAdjustObjectAtPoint === "function")
+            canBeAdjusted = this._delegate.dragToAdjustControllerCanAdjustObjectAtPoint(this, WebInspector.Point.fromEvent(event));
+
+        this._setTracksMouseClickAndDrag(canBeAdjusted);
+    },
+    
+    _mouseWasPressed: function(event)
+    {
+        this._lastX = event.screenX;
+
+        this._setDragging(true);
+
+        event.preventDefault();
+        event.stopPropagation();
+    },
+
+    _mouseWasDragged: function(event)
+    {
+        var x = event.screenX;
+        var amount = x - this._lastX;
+
+        if (Math.abs(amount) < 1)
+            return;
+
+        this._lastX = x;
+
+        if (event.ctrlKey)
+            amount /= 10;
+        else if (event.shiftKey)
+            amount *= 10;
+
+        if (this._delegate && typeof this._delegate.dragToAdjustControllerWasAdjustedByAmount === "function")
+            this._delegate.dragToAdjustControllerWasAdjustedByAmount(this, amount);
+
+        event.preventDefault();
+        event.stopPropagation();
+    },
+
+    _mouseWasReleased: function(event)
+    {
+        this._setDragging(false);
+
+        event.preventDefault();
+        event.stopPropagation();
+
+        this.reset();
+    }
+};

Modified: trunk/Source/WebInspectorUI/UserInterface/Main.html (164539 => 164540)


--- trunk/Source/WebInspectorUI/UserInterface/Main.html	2014-02-22 13:58:51 UTC (rev 164539)
+++ trunk/Source/WebInspectorUI/UserInterface/Main.html	2014-02-22 15:29:13 UTC (rev 164540)
@@ -129,7 +129,7 @@
     <link rel="stylesheet" href=""
     <link rel="stylesheet" href=""
     <link rel="stylesheet" href=""
-    <link rel="stylesheet" href=""
+    <link rel="stylesheet" href=""
     <link rel="stylesheet" href=""
     <link rel="stylesheet" href=""
     <link rel="stylesheet" href=""
@@ -160,7 +160,8 @@
     <script src=""
     <script src=""
     <script src=""
-    <script src=""
+    <script src=""
+    <script src=""
     <script src=""
     <script src=""
     <script src=""
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to