Skip to content

Commit 2a797fe

Browse files
committed
[css-color] Fix some IDL problems, add CSSColor constructor overloads, define all the constructors in terms of ES code.
--HG-- extra : rebase_source : 3378e9b23bf3ac8be0c14199828368f79c7ffbdc
1 parent ed39457 commit 2a797fe

2 files changed

Lines changed: 843 additions & 593 deletions

File tree

css-color/Overview.bs

Lines changed: 182 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,6 +2525,7 @@ The RGBColor Object</h3>
25252525
<pre class='idl'>
25262526
[Constructor(double r, double g, double b, optional double a=1),
25272527
Constructor(RGBColor rgb),
2528+
Constructor(CSSColor csscolor),
25282529
Constructor(optional RGBColorInit color),
25292530
Constructor(DOMString css)]
25302531
interface RGBColor : CSSColor {
@@ -2571,22 +2572,65 @@ The RGBColor Object</h3>
25712572
<dl dfn-for="RGBColor">
25722573
<dt><dfn constructor title="RGBColor(r, g, b, a) | RGBColor(r, g, b)">RGBColor</dfn>(double r, double g, double b, optional double a=1)
25732574
<dd link-for="RGBColor">
2574-
Constructs an instance of the <a idl for>RGBColor</a> class,
2575-
initializing the <a idl>r</a>, <a idl>g</a>, <a idl>b</a>, and <a idl>a</a> attributes of the instance to the passed arguments of the same name.
2575+
Defined as follows in ECMAScript:
2576+
2577+
<pre>
2578+
function(r, g, b, a) {
2579+
this.r = r;
2580+
this.g = g;
2581+
this.b = b;
2582+
this.a = a === undefined ? 1 : a;
2583+
return this;
2584+
}
2585+
</pre>
25762586

25772587
Note: The <a idl for>RGBColor</a> class's attributes have a normal range of 0 to 1,
25782588
not 0 to 255.
25792589
See the <a idl for>HexColor</a> class if you prefer working in the 0-255 range.
25802590

25812591
<dt><dfn constructor title="RGBColor(rgb)">RGBColor</dfn>(<a idl>RGBColor</a> <dfn argument for="RGBColor(rgb)">rgb</dfn>)
2582-
<dd link-for="RGBColor">
2583-
Constructs an instance of the <a idl for>RGBColor</a> class,
2584-
initializing the <a idl>r</a>, <a idl>g</a>, <a idl>b</a>, and <a idl>a</a> attributes of the instance to the attributes of the same name on the <a argument for="RGBColor(rgb)">rgb</a> argument.
2592+
<dd>
2593+
Defined as follows in ECMAScript:
2594+
2595+
<pre>
2596+
function(rgb) {
2597+
this.r = rgb.r;
2598+
this.g = rgb.g;
2599+
this.b = rgb.b;
2600+
this.a = rgb.a;
2601+
return this;
2602+
}
2603+
</pre>
2604+
2605+
<dt><dfn constructor title="RGBColor(csscolor)">RGBColor</dfn>({{RGBColor}} <dfn argument for="RGBColor(csscolor)">csscolor</dfn>)
2606+
<dd>
2607+
Defined as follows in ECMAScript:
2608+
2609+
<pre>
2610+
function(csscolor) {
2611+
const color = csscolor.toRGB();
2612+
this.r = color.r;
2613+
this.g = color.g;
2614+
this.b = color.b;
2615+
this.a = color.a;
2616+
return this;
2617+
}
2618+
</pre>
25852619

25862620
<dt><dfn constructor title="RGBColor(color) | RGBColor()">RGBColor</dfn>(optional RGBColorInit color)
2587-
<dd link-for="RGBColor">
2588-
Constructs an instance of the <a idl for>RGBColor</a> class,
2589-
initializing the <a idl>r</a>, <a idl>g</a>, <a idl>b</a>, and <a idl>a</a> attributes of the instance to the passed dictionary attributes of the same name (or their defaulted values).
2621+
<dd>
2622+
Defined as follows in ECMAScript:
2623+
2624+
<pre>
2625+
function(color) {
2626+
if(color === undefined) color = {r:0, g:0, b:0, a:1};
2627+
this.r = color.r === undefined ? 0 : color.r;
2628+
this.g = color.g === undefined ? 0 : color.g;
2629+
this.b = color.b === undefined ? 0 : color.b;
2630+
this.a = color.a === undefined ? 1 : color.a;
2631+
return this;
2632+
}
2633+
</pre>
25902634

25912635
<dt><dfn constructor title="RGBColor(css)">RGBColor</dfn>(DOMString css)
25922636
<dd>
@@ -2699,6 +2743,7 @@ The HSLColor Class</h3>
26992743
[Constructor(double h, double s, double l, optional double a=1),
27002744
Constructor(RGBColor rgb),
27012745
Constructor(optional HSLColorInit color),
2746+
Constructor(CSSColor csscolor),
27022747
Constructor(DOMString css)]
27032748
interface HSLColor : CSSColor {
27042749
attribute double h;
@@ -2722,9 +2767,18 @@ The HSLColor Class</h3>
27222767

27232768
<dl dfn-for="HSLColor">
27242769
<dt><dfn constructor title="HSLColor(h, s, l, a) | HSLColor(h, s, l)">HSLColor</dfn>(double h, double s, double l, optional double a=1)
2725-
<dd link-for="HSLColor">
2726-
Constructs an instance of the <a idl for>HSLColor</a> class,
2727-
initializing the <a idl>h</a>, <a idl>s</a>, <a idl>l</a>, and <a idl>a</a> attributes of the instance to the passed arguments of the same name.
2770+
<dd>
2771+
Defined as follows in ECMAScript:
2772+
2773+
<pre>
2774+
function(h, s, l, a) {
2775+
this.h = h;
2776+
this.s = s;
2777+
this.l = l;
2778+
this.a = a === undefined ? 1 : a;
2779+
return this;
2780+
}
2781+
</pre>
27282782

27292783
<dt><dfn constructor title="HSLColor(rgb)">HSLColor</dfn>(<a idl>RGBColor</a> <dfn argument for="HSLColor/HSLColor(rgb)">rgb</dfn>)
27302784
<dd>
@@ -2760,10 +2814,35 @@ The HSLColor Class</h3>
27602814
}
27612815
</pre>
27622816

2817+
<dt><dfn constructor title="HSLColor(csscolor)">HSLColor</dfn>({{CSSColor}} <dfn argument for="HSLColor(csscolor)">csscolor</dfn>)
2818+
<dd>
2819+
Defined as follows in ECMAScript:
2820+
2821+
<pre>
2822+
function(csscolor) {
2823+
const color = csscolor.toHSL();
2824+
this.h = color.h;
2825+
this.s = color.s;
2826+
this.l = color.l;
2827+
this.a = color.a;
2828+
return this;
2829+
}
2830+
</pre>
2831+
27632832
<dt><dfn constructor title="HSLColor(color) | HSLColor()">HSLColor</dfn>(optional HSLColorInit color)
2764-
<dd link-for="HSLColor">
2765-
Constructs an instance of the <a idl for>HSLColor</a> class,
2766-
initializing the <a idl>h</a>, <a idl>s</a>, <a idl>l</a>, and <a idl>a</a> attributes of the instance to the passed dictionary attributes of the same name (or their defaulted values).
2833+
<dd>
2834+
Defined as follows in ECMAScript:
2835+
2836+
<pre>
2837+
function(color) {
2838+
if(color === undefined) color = {h:0, s:0, l:0, a:1};
2839+
this.h = color.h === undefined ? 0 : color.h;
2840+
this.s = color.s === undefined ? 0 : color.s;
2841+
this.l = color.l === undefined ? 0 : color.l;
2842+
this.a = color.a === undefined ? 1 : color.a;
2843+
return this;
2844+
}
2845+
</pre>
27672846

27682847
<dt><dfn constructor title="HSLColor(css)">HSLColor</dfn>(DOMString css)
27692848
<dd>
@@ -2838,6 +2917,8 @@ The HexColor Class</h3>
28382917

28392918
<pre class='idl'>
28402919
[Constructor([Clamp] octet r, [Clamp] octet g, [Clamp] octet b, optional [Clamp] octet a = 255),
2920+
Constructor(RGBColor rgb),
2921+
Constructor(CSSColor csscolor),
28412922
Constructor(optional HexColorInit color),
28422923
Constructor(DOMString css)]
28432924
interface HexColor : CSSColor {
@@ -2862,9 +2943,18 @@ The HexColor Class</h3>
28622943

28632944
<dl dfn-for="HexColor">
28642945
<dt><dfn constructor title="HexColor(r, g, b, a) | HexColor(r, g, b)">HexColor</dfn>([Clamp] octet r, [Clamp] octet g, [Clamp] octet b, optional [Clamp] octet a=255)
2865-
<dd link-for="HexColor">
2866-
Constructs an instance of the <a idl for>HexColor</a> class,
2867-
initializing the <a idl>r</a>, <a idl>g</a>, <a idl>b</a>, and <a idl>a</a> attributes of the instance to the passed arguments of the same name.
2946+
<dd>
2947+
Defined as follows in ECMAScript:
2948+
2949+
<pre>
2950+
function(r, g, b, a) {
2951+
this.r = r;
2952+
this.g = g;
2953+
this.b = b;
2954+
this.a = a === undefined ? 255 : a;
2955+
return this;
2956+
}
2957+
</pre>
28682958

28692959
<dt><dfn constructor title="HexColor(rgb)">HexColor</dfn>(<a idl>RGBColor</a> <dfn argument for="HexColor/HexColor(rgb)">rgb</dfn>)
28702960
<dd>
@@ -2883,10 +2973,35 @@ The HexColor Class</h3>
28832973
}
28842974
</pre>
28852975

2976+
<dt><dfn constructor title="HexColor(csscolor)">HexColor</dfn>({{CSSColor}} <dfn argument for="HexColor(csscolor)">csscolor</dfn>)
2977+
<dd>
2978+
Defined as follows in ECMAScript:
2979+
2980+
<pre>
2981+
function(csscolor) {
2982+
const color = csscolor.toHex();
2983+
this.r = color.r;
2984+
this.g = color.g;
2985+
this.b = color.b;
2986+
this.a = color.a;
2987+
return this;
2988+
}
2989+
</pre>
2990+
28862991
<dt><dfn constructor title="HexColor(color) | HexColor()">HSLColor</dfn>(optional HexColorInit color)
2887-
<dd link-for="HexColor">
2888-
Constructs an instance of the <a idl for>HexColor</a> class,
2889-
initializing the <a idl>r</a>, <a idl>g</a>, <a idl>b</a>, and <a idl>a</a> attributes of the instance to the passed dictionary attributes of the same name (or their defaulted values).
2992+
<dd>
2993+
Defined as follows in ECMAScript:
2994+
2995+
<pre>
2996+
function(color) {
2997+
if(color === undefined) color = {r:0, g:0, b:0, a:255};
2998+
this.r = this.r === undefined ? 0 : this.r;
2999+
this.g = this.g === undefined ? 0 : this.g;
3000+
this.b = this.b === undefined ? 0 : this.b;
3001+
this.a = this.a === undefined ? 255 : this.a;
3002+
return this;
3003+
}
3004+
</pre>
28903005

28913006
<dt><dfn constructor title="HexColor(css)">HexColor</dfn>(DOMString css)
28923007
<dd>
@@ -2946,6 +3061,8 @@ The CMYKColor Class</h3>
29463061

29473062
<pre class='idl'>
29483063
[Constructor(double c, double m, double y, double k, optional double a=1, optional fallback RGBColor?=null),
3064+
Constructor(RGBColor rgb),
3065+
Constructor(CSSColor csscolor),
29493066
Constructor(optional CMYKColorInit color),
29503067
Constructor(DOMString css)]
29513068
interface CMYKColor : CSSColor {
@@ -2974,9 +3091,19 @@ The CMYKColor Class</h3>
29743091

29753092
<dl dfn-for="CMYKColor">
29763093
<dt><dfn constructor title="CMYKColor(c, m, y, k, a, fallback) | CMYKColor(c, m, y, k, a) | CMYKColor(c, m, y, k)">CMYKColor</dfn>(double c, double m, double y, double k, optional double a=1, optional RGBColor? fallback=null)
2977-
<dd link-for="CMYKColor">
2978-
Constructs an instance of the <a idl for>CMYKColor</a> class,
2979-
initializing the <a idl>c</a>, <a idl>m</a>, <a idl>y</a>, <a idl>k</a>, <a idl>a</a>, and <a idl>fallback</a> attributes of the instance to the passed arguments of the same name.
3094+
<dd>
3095+
Defined as follows in ECMAScript:
3096+
3097+
<pre>
3098+
function(c, m, y, k, a, fallback) {
3099+
this.c = c;
3100+
this.m = m;
3101+
this.y = y;
3102+
this.k = k;
3103+
this.a = a === undefined ? 1 : a;
3104+
this.fallback = fallback === undefined ? null : fallback;
3105+
}
3106+
</pre>
29803107

29813108
<dt><dfn constructor title="CMYKColor(rgb)">CMYKColor</dfn>(<a idl>RGBColor</a> <dfn argument for="CMYKColor/CMYKColor(rgb)">rgb</dfn>)
29823109
<dd>
@@ -3006,10 +3133,38 @@ The CMYKColor Class</h3>
30063133
}
30073134
</pre>
30083135

3009-
<dt><dfn constructor title="CMYKColor(color) | CMYKColor()">CMYKColor</dfn>(optional HexColorInit color)
3010-
<dd link-for="CMYKColor">
3011-
Constructs an instance of the <a idl for>CMYKColor</a> class,
3012-
initializing the <a idl>c</a>, <a idl>m</a>, <a idl>y</a>, <a idl>k</a>, <a idl>a</a>, and <a idl>fallback</a> attributes of the instance to the passed dictionary attributes of the same name (or their defaulted values).
3136+
<dt><dfn constructor title="CMYKColor(csscolor)">CMYKColor</dfn>({{CSSColor}} <dfn argument for="CMYKColor(csscolor)">csscolor</dfn>)
3137+
<dd>
3138+
Defined as follows in ECMAScript:
3139+
3140+
<pre>
3141+
function(csscolor) {
3142+
const color = csscolor.toCMYK();
3143+
this.c = color.c;
3144+
this.m = color.m;
3145+
this.y = color.y;
3146+
this.k = color.k;
3147+
this.a = color.a;
3148+
this.fallback = color.fallback;
3149+
return this;
3150+
}
3151+
</pre>
3152+
3153+
<dt><dfn constructor title="CMYKColor(color) | CMYKColor()">CMYKColor</dfn>(optional CMYKColorInit color)
3154+
<dd>
3155+
Defined as follows in ECMAScript:
3156+
3157+
<pre>
3158+
function(color) {
3159+
if(color === undefined) color = {c:0, m:0, y:0, k:0, a:1, fallback:null};
3160+
this.c = color.c === undefined ? 0 : color.c;
3161+
this.m = color.m === undefined ? 0 : color.m;
3162+
this.y = color.y === undefined ? 0 : color.y;
3163+
this.k = color.k === undefined ? 0 : color.k;
3164+
this.a = color.a === undefined ? 1 : color.a;
3165+
this.fallback = color.fallback === undefined ? null : color.fallback;
3166+
}
3167+
</pre>
30133168

30143169
<dt><dfn constructor title="CMYKColor(css)">CMYKColor</dfn>(DOMString css)
30153170
<dd>

0 commit comments

Comments
 (0)