w3c / input-events

Input Events
https://w3c.github.io/input-events/
Other
24 stars 16 forks source link

Declare more detail of `data` value of `formatBackColor` and `formatFontColor` #94

Closed masayuki-nakano closed 5 years ago

masayuki-nakano commented 5 years ago

Currently, no browser sets data attribute to "RGB function call" declared by Input Events even when inputType is either formatBackColor or formatFontColor.

Additionally, these inputType are used only when execCommand is used. Finally, the definition, "RGB function call" is too unclear, for example, rgb() vs. rgba, using int vs. percentage to each component, etc.

So, I think that if we don't have any reasonable reasons to set data attribute for them, null is better value.

Otherwise, please declare the detail of "RGB function call" for compatibility between browsers.

whsieh commented 5 years ago

Safari on macOS sets the data attribute of input/beforeinput events when using the Touch Bar to change font color. Currently, this data is of the format "rgb(x, y, z)".

masayuki-nakano commented 5 years ago

Safari on macOS sets the data attribute of input/beforeinput events when using the Touch Bar to change font color. Currently, this data is of the format "rgb(x, y, z)".

Thanks, then, Firefox will follow it. On the other hand, the unclear definition is a problem for me. Input Events should declare browses should use whether rgb or rgba, should use whether number or percentage for each component, should insert a whitespace before each component or not.

masayuki-nakano commented 5 years ago

(I like rgba for the forward compatibility, integer for avoiding struggling with float percentage values, and inserting a whitespace before component for easier to read.)

masayuki-nakano commented 5 years ago

And if initial, inherit, currentColor or transparent are specified by execCommand, what value should be set to? The first 3 require to access style system...

I think that when browser sets color, rgba function (or rgb function) should be used, but data value of input event caused by execCommand, setting specified value as-is is reasonable.

rniwa commented 5 years ago

We should probably just follow what CSS OM does, which switches between rgb(~) and rgba(~) based on the alpha value: https://drafts.csswg.org/cssom/#serialize-a-css-component-value

masayuki-nakano commented 5 years ago

We should probably just follow what CSS OM does, which switches between rgb(~) and rgba(~) based on the alpha value: https://drafts.csswg.org/cssom/#serialize-a-css-component-value

Makes sense!

masayuki-nakano commented 5 years ago

There are two problems:

  1. It requires more cost to implement/compute serialized color value if execCommand is called with currentColor (Level 3, in Level 4, declared as currentcolor), inherit or initial.
  2. If given value of evecCommand, cannot be computed good serialized value.

I suggest that in those cases, given value should be set to data as-is. If CSS color value will be extended in the future, even older browsers can run with any values.

rniwa commented 5 years ago

Do browsers even support invoking execCommand with currentColor?

masayuki-nakano commented 5 years ago

Do browsers even support invoking execCommand with currentColor?

Firefox works as usual colors, e.g., if you select some text and call execCommand("backColor", false, "currentColor"), Firefox wraps it with <span style="background-color: currentcolor"> and </span>.

Edge works similarly. But using <font> element and does not fire input event.

Blink does nothing except dispatching input event with empty inputType.

masayuki-nakano commented 5 years ago

FYI: I implemented InputEvent.data on Firefox (shipped in 67 if we don't get any "break the web" reports). At that time, we use same serialization of CSS computed style (as @rniwa -san said in comment). And we use given values as-is if we the given value cannot be represented with rgb() nor rgba(). For example, inherit, currentcolor.

johanneswilm commented 5 years ago

I don't remember how I arrived at the wording "RGB function call", but searching the internet a bit, it basically covers rgb() and rgba(). I agree with @rniwa that we should follow CSS OM, and it seems everyone else does too, so I will update accordingly.

@masayuki-nakano Are you saying that you will accept something other than "rgb()" and "rgba()"? As far as I know, the only place this shows up are special menus on Safari. Will Firefox also implement those menus? Will Firefox then have a menu where you can switch the color of a text to "inherit"?

execCommand is not covered by this spec - things related to execCommand should be discussed at https://github.com/w3c/editing . Although that spec has a big disclaimer saying that it's likely never getting finished and browser don't follow it, if Firefox has decided to change course and work more on execCommand, that's where that should go, and we can make a special section about input event related things in there as well.

masayuki-nakano commented 5 years ago

@masayuki-nakano Are you saying that you will accept something other than "rgb()" and "rgba()"? As far as I know, the only place this shows up are special menus on Safari. Will Firefox also implement those menus? Will Firefox then have a menu where you can switch the color of a text to "inherit"?

No, Firefox does not have such interface. However, execCommand can cause firing input event with data value having color value. I think that if execCommand does not allow to use inherit etc as the color value, Firefox would stop handling such value (currently, Firefox just sets color or background-color property to coming value even if it's invalid value).