Changeset 235273 in webkit


Ignore:
Timestamp:
Aug 23, 2018 9:55:28 PM (6 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Color picker: can't enter decimal numbers for opacity
https://bugs.webkit.org/show_bug.cgi?id=187026
<rdar://problem/41446500>

Reviewed by Brian Burg.

After every "input" event, we update the color value of the WI.ColorPicker based on a
generated string using the values of the various <input>. The issue with this approach is
that adding a decimal point (e.g. "0.") would still be construed as 0, meaning that the
color wouldn't change and would instead be reset back to it's old value. This patch adds an
early return if the newly generated color has the same value as the current color, thereby
meaning that the color wouldn't change when changing from "0" to "0.".

  • UserInterface/Views/ColorPicker.js:

(WI.ColorPicker):
(WI.ColorPicker.createColorInput):
(WI.ColorPicker.prototype._handleColorInputInput):

Location:
trunk/Source/WebInspectorUI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r235271 r235273  
     12018-08-23  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Color picker: can't enter decimal numbers for opacity
     4        https://bugs.webkit.org/show_bug.cgi?id=187026
     5        <rdar://problem/41446500>
     6
     7        Reviewed by Brian Burg.
     8
     9        After every "input" event, we update the `color` value of the `WI.ColorPicker` based on a
     10        generated string using the values of the various <input>. The issue with this approach is
     11        that adding a decimal point (e.g. "0.") would still be construed as 0, meaning that the
     12        color wouldn't change and would instead be reset back to it's old value. This patch adds an
     13        early return if the newly generated color has the same value as the current color, thereby
     14        meaning that the `color` wouldn't change when changing from "0" to "0.".
     15
     16        * UserInterface/Views/ColorPicker.js:
     17        (WI.ColorPicker):
     18        (WI.ColorPicker.createColorInput):
     19        (WI.ColorPicker.prototype._handleColorInputInput):
     20
    1212018-08-23  Simon Fraser  <simon.fraser@apple.com>
    222
  • trunk/Source/WebInspectorUI/UserInterface/Views/ColorPicker.js

    r220119 r235273  
    4545        colorInputsContainerElement.classList.add("color-inputs");
    4646
    47         function createColorInput(label, {min: min = 0, max: max = 100, step: step = 1, units} = {}) {
     47        let createColorInput = (label, {min, max, step, units} = {}) => {
    4848            let containerElement = colorInputsContainerElement.createChild("div");
    4949
     
    5252            let numberInputElement = containerElement.createChild("input");
    5353            numberInputElement.type = "number";
    54             numberInputElement.min = min;
    55             numberInputElement.max = max;
    56             numberInputElement.step = step;
     54            numberInputElement.min = min || 0;
     55            numberInputElement.max = max || 100;
     56            numberInputElement.step = step || 1;
    5757            numberInputElement.addEventListener("input", this._handleColorInputInput.bind(this));
    5858
     
    6161
    6262            return {containerElement, numberInputElement};
    63         }
     63        };
    6464
    6565        this._colorInputs = new Map([
    66             ["R", createColorInput.call(this, "R", {max: 255})],
    67             ["G", createColorInput.call(this, "G", {max: 255})],
    68             ["B", createColorInput.call(this, "B", {max: 255})],
    69             ["H", createColorInput.call(this, "H", {max: 360})],
    70             ["S", createColorInput.call(this, "S", {units: "%"})],
    71             ["L", createColorInput.call(this, "L", {units: "%"})],
    72             ["A", createColorInput.call(this, "A"), {max: 1, step: 0.01}]
     66            ["R", createColorInput("R", {max: 255})],
     67            ["G", createColorInput("G", {max: 255})],
     68            ["B", createColorInput("B", {max: 255})],
     69            ["H", createColorInput("H", {max: 360})],
     70            ["S", createColorInput("S", {units: "%"})],
     71            ["L", createColorInput("L", {units: "%"})],
     72            ["A", createColorInput("A", {max: 1, step: 0.01})]
    7373        ]);
    7474
     
    325325        }
    326326
    327         this.color = WI.Color.fromString(colorString);
     327        let newColor = WI.Color.fromString(colorString);
     328        if (newColor.toString() === this._color.toString())
     329            return;
     330
     331        this.color = newColor;
    328332        this._color.format = oldFormat;
    329333
Note: See TracChangeset for help on using the changeset viewer.