Closed Bug 160550 Opened 22 years ago Closed 21 years ago

[FIXr][RFE] Implement CSS3 Color module's hsl() and hsla() color types

Categories

(Core :: CSS Parsing and Computation, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla1.5alpha

People

(Reporter: jasonkarldavis, Assigned: bzbarsky)

References

Details

Attachments

(3 files, 6 obsolete files)

The CSS3 color module (currently in last call working draft) implements an hsl()
color value:
http://www.w3.org/TR/2002/WD-css3-color-20020418/#hsl-color
which is trivial to convert to rgb().

It also specifies an hsla() color value:
http://www.w3.org/TR/2002/WD-css3-color-20020418/#hsla-color
which is simply hsl() with an alpha channel.

Since CSS color values are converted to rgb() format, with the addition of the
alpha channel it seems that they should be converted to rgba() instead, in which
case this RFE would be dependent on
http://bugzilla.mozilla.org/show_bug.cgi?id=147017 (Support rgba colors in CSS).

Since the specs are still in working draft, the values would have to be
implemented as -moz-hsl() and -moz-hsla(), but nonetheless this is still an
incredibly powerful design ability. hsl() is much better for guessing and
checking values (makes it easier for the web page designers, or to quickly find
matching colors for XUL skins for example), and an alpha channel makes it much
more convenient than having to create a 1*1 PNG image for each different background.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Attached file testcase for -moz-hsl support (obsolete) —
Attached patch rough patch (obsolete) — Splinter Review
This is unfortunately entangled with the patch to bug 154755.  This just
implements -moz-hsl(), since we don't yet support alpha for CSS colors....
[RFE] is deprecated in favor of severity: enhancement.  They have the same meaning.
Severity: trivial → enhancement
glazou, do you have any interest in this?  Or should we wait till this draft is
in something resembling CR?
boris: yes, we should implement this. And forget about -moz- whatever is the
status of the spec, please.
taking.

Daniel, why forget about -moz-?  Is this stable enough that it will not change?
Assignee: dbaron → bzbarsky
Priority: -- → P3
Summary: [RFE] Implement CSS3 Color module's hsl() and hsla() color types → [FIX][RFE] Implement CSS3 Color module's hsl() and hsla() color types
Target Milestone: --- → mozilla1.4alpha
Attachment #98273 - Attachment is obsolete: true
Attached file testcase (obsolete) —
Attached patch proposed patch (obsolete) — Splinter Review
Attachment #98274 - Attachment is obsolete: true
Comment on attachment 114441 [details] [diff] [review]
proposed patch

I had to put the HSL code in nsColor because the parser does not get to see
nsCSSColorUtils.  Perhaps the code could just live entirely within the parser,
but this seems like it could be generally useful...
Attachment #114441 - Flags: superreview?(dbaron)
Attachment #114441 - Flags: review?(glazman)
This must be -moz-hsl until css3-color is in CR. Only by strictly adhering to
this convention can we ensure we never cause interoperability problems.
OK.  That's a 2-line change to that patch; if people want I can post a new
patch, of course....
sometime.
Target Milestone: mozilla1.4alpha → mozilla1.5alpha
Attached file updated testcase (using -moz-hsl) (obsolete) —
Attachment #114440 - Attachment is obsolete: true
Attached file -moz-hsla testcase
Comment on attachment 114441 [details] [diff] [review]
proposed patch

I'll be updating this to do -moz-hsl and also -moz-hsla and -moz-rgba.	roc is
working on the GFX impl of the latter and it'd make life easier for him if the
style system were to actually support them....
Attachment #114441 - Attachment is obsolete: true
Attachment #114441 - Flags: superreview?(dbaron)
Attachment #114441 - Flags: review?(glazman)
Blocks: 147017
Comment on attachment 117117 [details] [diff] [review]
updated patch -- does -moz-hsl, -moz-rgba, -moz-hsla

I'm not too happy with adding this much code, but I couldn't see a smaller way
to do it...
Attachment #117117 - Flags: superreview?(dbaron)
Attachment #117117 - Flags: review?(dbaron)
+  while (h < 0.0f) {
+    h += 360.0f;
+  }
+  while (h >= 360.0f) {
+    h -= 360.0f;
+  }

Hello denial of service! How about
  h = h - 360.0*floor(h/360.0);

+  float value = mToken.mNumber;
+  if (value < 0.0f) {
+    value = 0.0f;
+  }
+  if (value > 1.0f) {
+    value = 1.0f;
+  }
...
+  aOpacity = (PRUint8)value;

You have to multiply by 255, and I worry a little about rounding. So
I think this should be
  PRUint32 value = (PRUint32)rint(mToken.mNumber*255);
  if (value < 0) value = 0;
  if (value > 255) value = 255;
  aOpacity = (PRUint8)value;
Doh.  Good catch on both of those.  I've made those changes.  (I should have
thought a bit more about doing the wraparound well... ;))
Could you attach the latest version of the patch?  Everything seems pretty good,
except I didn't look closely at the part roc commented on, and I didn't check
your nsColor math.

Also, note that roc's floor expression could be simplified further if you divide
by 360 first (since you do it right below).
This includes the "divide by 360 first" thing; the code in nsColor is just
copied and pasted from the pseudocode at
http://www.w3.org/TR/2003/WD-css3-color-20030214/#hsl-color
Attachment #117117 - Attachment is obsolete: true
Attachment #117440 - Flags: superreview?(dbaron)
Attachment #117440 - Flags: review?(dbaron)
Attachment #117117 - Flags: superreview?(dbaron)
Attachment #117117 - Flags: review?(dbaron)
Comment on attachment 117440 [details] [diff] [review]
Sure thing; patch against tonight's trunk.

>+  h = h - floor(h);

floorf seems like it would be better, but is it as portable?

>+  PRUint32 value = (PRUint32)rint(mToken.mNumber*255);

What does rint do, exactly?  (Why don't you want floorf, ceilf, or round, or
straight conversion?  What's the difference?)


>+// helper
>+static float
>+HSL_HueToRGB(float m1, float m2, float h)
>+{
>+  if (h < 1.0f)

h < 0.0f
??

>+    h += 1.0f;
>+  if (h > 1.0f)
>+    h -= 1.0f;
>+  if (h * 6.0f < 1.0f)

how about
if (h < 1.0f/6.0f)
to ensure constant folding?
(and similar for the next two -- or might "(float)(1.0/6.0)" be more accurate?)

>+    return m1 + (m2 - m1)*h*6.0f;
>+  if (h*2.0f < 1.0f)
>+    return m2;
>+  if (h*3.0f < 2.0f)
>+    return m1 + (m2 - m1)*(2.0f/3.0f - h)*6.0f;
>+  return m1;      
>+}
Attachment #117440 - Flags: superreview?(dbaron)
Attachment #117440 - Flags: superreview+
Attachment #117440 - Flags: review?(dbaron)
Attachment #117440 - Flags: review+
To be truthful, I don't know how portable floorf is.  I could check it in with
floorf and see if anything breaks.  ;)

rint() seems to round based on what the "current rounding mode" is, so it's not
quite equivalent to "floor" or "ceil".  I don't know how it differs from round()
or just straight conversion, if at all.  roc?

> h < 0.0f
> ??

Eeep, yes.

Made the constant-folding changes; (float)(1.0/2.0) seems best to me.

roc?  Comments on the rounding stuff?
Summary: [FIX][RFE] Implement CSS3 Color module's hsl() and hsla() color types → [FIXr][RFE] Implement CSS3 Color module's hsl() and hsla() color types
Just call round(), I guess. It doesn't really matter what we do with the corner
case opacity values. I wouldn't use ceil() or floor() or trunc() because we do
want values "near" 0 or 1 to become 0 or 255 respectively.
checked in, with round() and floorf().
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Change round() to NSToIntRound(), due to bustage...
AIX and Solaris failed to deal with floorf(), so I went back to floor()
The CSS3 Color module has been moved to Candidate Recommendation. Is it now safe
to rename -moz-hsl, -moz-hsla, and -moz-rgba to the corresponding properties in
the CSS3 specs?
-moz-hsl() certainly; we shouldn't rename -moz-rgba() and -moz-hsla() unless we
support painting with RGBA colours. (It would appear that we do not. Is there a
bug number for that?)
In answer to my last question, that's bug 147017, which I should have known, I'm
the QA contact and have commented on it. Ahem. Moving on...
As -moz-hsl() has been renamed into hsl() and doesn't work anymore, I've
attached a hsl testcase. Someone should mark the -moz-hsl testcase obsolete.
Comment on attachment 116941 [details]
updated testcase (using -moz-hsl)

Actaully, the second testcase attached to this bug was already for hsl()...
Attachment #116941 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: