Skip to content

Commit fc3bc1b

Browse files
OrKoNCommit Bot
authored and
Commit Bot
committed
Fix suggest color for certain color combinations
Some color combinations with low contrast cannot be fixed by changing the luminance alone. This CL adds searching for a color with a different saturation if the luminance search didn't yield results. Fixed: 1120223 Change-Id: I114d0ba7a2941958a1fdab051661b13dd1112e59 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2367935 Reviewed-by: Mathias Bynens <[email protected]> Commit-Queue: Alex Rudenko <[email protected]>
1 parent 27bbbaa commit fc3bc1b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

front_end/common/Color.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,18 @@ export class Color {
460460

461461
const desiredLuminance = Color.desiredLuminance(bgLuminance, requiredContrast, fgIsLighter);
462462

463+
const saturationComponentIndex = 1;
463464
const valueComponentIndex = 2;
464465

465466
if (Color.approachColorValue(candidateHSVA, bgRGBA, valueComponentIndex, desiredLuminance)) {
466467
return Color.fromHSVA(candidateHSVA);
467468
}
468469

470+
candidateHSVA[valueComponentIndex] = 1;
471+
if (Color.approachColorValue(candidateHSVA, bgRGBA, saturationComponentIndex, desiredLuminance)) {
472+
return Color.fromHSVA(candidateHSVA);
473+
}
474+
469475
return null;
470476
}
471477

test/unittests/front_end/common/Color_test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ describe('Color', () => {
309309
contrast: 7.05,
310310
result: 'hsl(120deg 100% 20%)',
311311
},
312+
{
313+
bgColor: 'black',
314+
fgColor: '#b114ff',
315+
contrast: 7.05,
316+
result: 'hsl(280deg 100% 71%)',
317+
},
312318
];
313319
for (const {fgColor, bgColor, contrast, result} of colors) {
314320
const suggestedColor =

0 commit comments

Comments
 (0)