Commit 70fe1a5
committed
Web Inspector: Adding color contrast information within Color Picker
https://bugs.webkit.org/show_bug.cgi?id=260101
rdar://113887185
Reviewed by Devin Rousso (OOPS\!).
Add contrast ratio threshold lines to the color picker overlay when editing text color
properties. Two lines indicate AA and AAA WCAG compliance thresholds, helping developers
pick accessible colors without leaving the picker.
All contrast calculations happen in the frontend using the WCAG 2.0 relative luminance
formula (https://www.w3.org/TR/WCAG20/#relativeluminancedef) and contrast ratio formula
(https://www.w3.org/TR/WCAG20/#contrast-ratiodef). This avoids backend round-trips and
provides instant feedback as users drag within the color square. The implementation uses
binary search to find brightness values that achieve target luminance at each saturation
level, rendering results as SVG polylines.
Semi-transparent foreground colors are blended over the background before calculating
contrast, ensuring accurate ratios for colors with alpha < 1.
WCAG defines relaxed thresholds for "large text" (≥18pt or ≥14pt bold). Normal text requires
4.5:1 for AA and 7:1 for AAA. Large text only requires 3:1 for AA and 4.5:1 for AAA. The
implementation reads computed font-size and font-weight to detect large text and adjusts
the threshold lines accordingly.
A contrast info section below the picker displays the current ratio and
compliance badge (AAA/AA/Fail) alongside the background color swatch.
* Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js:
* Source/WebInspectorUI/UserInterface/Models/Color.js:
(WI.Color.prototype.contrastComplianceForRatio):
(WI.Color.prototype.relativeLuminance):
(WI.Color.prototype.contrastRatio):
(WI.Color.prototype.contrastCompliance):
(WI.Color.prototype.blendOverBackground):
(WI.Color):
* Source/WebInspectorUI/UserInterface/Views/ColorPicker.css:
(.color-picker > .contrast-info + .variable-color-swatches):
(.color-picker > .variable-color-swatches > h2):
(.color-picker > .contrast-info):
(.color-picker > .contrast-info > .contrast-label):
(.color-picker > .contrast-info > .contrast-ratio):
(.color-picker > .contrast-info > .compliance-badge):
(.color-picker > .contrast-info > .compliance-badge.contrast-aaa):
(@media (prefers-color-scheme: dark) .color-picker > .contrast-info > .compliance-badge.contrast-aaa):
(.color-picker > .contrast-info > .compliance-badge.contrast-aa):
(@media (prefers-color-scheme: dark) .color-picker > .contrast-info > .compliance-badge.contrast-aa):
(.color-picker > .contrast-info > .compliance-badge.contrast-fail):
(@media (prefers-color-scheme: dark) .color-picker > .contrast-info > .compliance-badge.contrast-fail):
(.color-picker > .contrast-info > .contrast-separator):
(.color-picker > .contrast-info > .inline-swatch):
* Source/WebInspectorUI/UserInterface/Views/ColorPicker.js:
(WI.ColorPicker.prototype.async colorInputsWrapperElement):
(WI.ColorPicker.prototype.set opacity):
(WI.ColorPicker.prototype.set color):
(WI.ColorPicker.prototype._updateColor):
(WI.ColorPicker.prototype._createContrastInfoSection):
(WI.ColorPicker.prototype._updateContrastInfo):
(WI.ColorPicker):
* Source/WebInspectorUI/UserInterface/Views/ColorSquare.css:
(.color-square > .contrast-lines-svg):
(.color-square > .contrast-lines-svg > .contrast-line):
(.color-square > .contrast-lines-svg > .contrast-line.contrast-aa-threshold):
(.color-square > .contrast-lines-svg > .contrast-line.contrast-aaa-threshold):
(.color-square > .contrast-label):
(.color-square > .contrast-label.contrast-aa-label):
(.color-square > .contrast-label.contrast-aaa-label):
(@media (prefers-color-scheme: dark) .color-square > .contrast-label):
* Source/WebInspectorUI/UserInterface/Views/ColorSquare.js:
(WI.ColorSquare):
(WI.ColorSquare.prototype.get contrastBackgroundColor):
(WI.ColorSquare.prototype.set contrastBackgroundColor):
(WI.ColorSquare.prototype.get opacity):
(WI.ColorSquare.prototype.set opacity):
(WI.ColorSquare.prototype.get isLargeText):
(WI.ColorSquare.prototype.set isLargeText):
(WI.ColorSquare.prototype._updateBaseColor):
(WI.ColorSquare.prototype._drawSRGBOutline):
(WI.ColorSquare.prototype._drawContrastLines):
(WI.ColorSquare.prototype._calculateContrastLinePoints):
(WI.ColorSquare.prototype._findBrightnessForLuminance):
(WI.ColorSquare.prototype._updatePolylinePoints):
(WI.ColorSquare.prototype._updateContrastLabel):
* Source/WebInspectorUI/UserInterface/Views/InlineSwatch.js:
* Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:
(WI.SpreadsheetStyleProperty.prototype.inlineSwatchGetContrastInfo):
Canonical link: https://commits.webkit.org/308318@main1 parent 7ff8905 commit 70fe1a5
File tree
8 files changed
+532
-14
lines changed- Source/WebInspectorUI
- Localizations/en.lproj
- UserInterface
- Models
- Views
8 files changed
+532
-14
lines changedLines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
443 | 443 | | |
444 | 444 | | |
445 | 445 | | |
| 446 | + | |
| 447 | + | |
446 | 448 | | |
447 | 449 | | |
448 | 450 | | |
| |||
1943 | 1945 | | |
1944 | 1946 | | |
1945 | 1947 | | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
1946 | 1956 | | |
1947 | 1957 | | |
1948 | 1958 | | |
| |||
2140 | 2150 | | |
2141 | 2151 | | |
2142 | 2152 | | |
| 2153 | + | |
| 2154 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
539 | 552 | | |
540 | 553 | | |
541 | 554 | | |
| |||
919 | 932 | | |
920 | 933 | | |
921 | 934 | | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
922 | 982 | | |
923 | 983 | | |
924 | 984 | | |
| |||
949 | 1009 | | |
950 | 1010 | | |
951 | 1011 | | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
952 | 1024 | | |
953 | 1025 | | |
954 | 1026 | | |
| |||
Lines changed: 74 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
116 | 122 | | |
117 | 123 | | |
118 | 124 | | |
| |||
137 | 143 | | |
138 | 144 | | |
139 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
140 | 214 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
35 | 40 | | |
36 | 41 | | |
37 | 42 | | |
| |||
92 | 97 | | |
93 | 98 | | |
94 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
95 | 104 | | |
96 | 105 | | |
97 | 106 | | |
| |||
103 | 112 | | |
104 | 113 | | |
105 | 114 | | |
106 | | - | |
| 115 | + | |
107 | 116 | | |
108 | 117 | | |
109 | 118 | | |
| |||
236 | 245 | | |
237 | 246 | | |
238 | 247 | | |
| 248 | + | |
239 | 249 | | |
240 | 250 | | |
241 | 251 | | |
| |||
253 | 263 | | |
254 | 264 | | |
255 | 265 | | |
| 266 | + | |
256 | 267 | | |
257 | 268 | | |
258 | 269 | | |
| |||
261 | 272 | | |
262 | 273 | | |
263 | 274 | | |
| 275 | + | |
264 | 276 | | |
265 | 277 | | |
266 | 278 | | |
| |||
318 | 330 | | |
319 | 331 | | |
320 | 332 | | |
| 333 | + | |
321 | 334 | | |
322 | 335 | | |
323 | 336 | | |
| |||
494 | 507 | | |
495 | 508 | | |
496 | 509 | | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
497 | 561 | | |
498 | 562 | | |
499 | 563 | | |
| |||
Lines changed: 53 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
0 commit comments