Title: [189210] trunk/Source/WebInspectorUI
Revision
189210
Author
[email protected]
Date
2015-09-01 09:29:30 -0700 (Tue, 01 Sep 2015)

Log Message

Web Inspector: Visual style editor shouldn't allow alpha characters in numeric input fields
https://bugs.webkit.org/show_bug.cgi?id=148580

Reviewed by Brian Burg.

* UserInterface/Views/VisualStyleNumberInputBox.js:
(WebInspector.VisualStyleNumberInputBox):
Added input element "changed" handler, renamed "keyup" handler to match "keydown" handler.
(WebInspector.VisualStyleNumberInputBox.prototype._valueNumberInputChanged):
Validate input in response to changed event.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (189209 => 189210)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-09-01 15:49:33 UTC (rev 189209)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-09-01 16:29:30 UTC (rev 189210)
@@ -1,3 +1,16 @@
+2015-09-01  Matt Baker  <[email protected]>
+
+        Web Inspector: Visual style editor shouldn't allow alpha characters in numeric input fields
+        https://bugs.webkit.org/show_bug.cgi?id=148580
+
+        Reviewed by Brian Burg.
+
+        * UserInterface/Views/VisualStyleNumberInputBox.js:
+        (WebInspector.VisualStyleNumberInputBox):
+        Added input element "changed" handler, renamed "keyup" handler to match "keydown" handler.
+        (WebInspector.VisualStyleNumberInputBox.prototype._valueNumberInputChanged):
+        Validate input in response to changed event.
+
 2015-08-31  Nikita Vasilyev  <[email protected]>
 
         Web Inspector: Command-Enter for selected JS in Debugger/Sources shouldn't change the focus

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleNumberInputBox.js (189209 => 189210)


--- trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleNumberInputBox.js	2015-09-01 15:49:33 UTC (rev 189209)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleNumberInputBox.js	2015-09-01 16:29:30 UTC (rev 189210)
@@ -75,8 +75,9 @@
         this._valueNumberInputElement.spellcheck = false;
         this._valueNumberInputElement.addEventListener("focus", this._focusContentElement.bind(this));
         this._valueNumberInputElement.addEventListener("keydown", this._valueNumberInputKeyDown.bind(this));
-        this._valueNumberInputElement.addEventListener("keyup", this._numberInputChanged.bind(this));
+        this._valueNumberInputElement.addEventListener("keyup", this._valueNumberInputKeyUp.bind(this));
         this._valueNumberInputElement.addEventListener("blur", this._blurContentElement.bind(this));
+        this._valueNumberInputElement.addEventListener("change", this._valueNumberInputChanged.bind(this));
         this._numberUnitsContainer.appendChild(this._valueNumberInputElement);
 
         this._unitsElement = document.createElement("span");
@@ -301,7 +302,7 @@
         this._valueDidChange();
     }
 
-    _numberInputChanged()
+    _valueNumberInputKeyUp(event)
     {
         if (!this._numberInputIsEditable)
             return;
@@ -376,6 +377,19 @@
         this.contentElement.classList.remove("focused");
     }
 
+    _valueNumberInputChanged(event)
+    {
+        let newValue = this.value;
+        if (!newValue && isNaN(newValue))
+            newValue = this.placeholder && !isNaN(this.placeholder) ? parseFloat(this.placeholder) : 0;
+
+        if (!this._allowNegativeValues && newValue < 0)
+            newValue = 0;
+
+        this.value = Math.round(newValue * 100) / 100;
+        this._valueDidChange();
+    }
+
     _toggleTabbingOfSelectableElements(disabled)
     {
         this._keywordSelectElement.tabIndex = disabled ? "-1" : null;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to