-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Customize Chrome: Replace native color picker with custom hue slider
This CL replaces the native color picker with a hue slider for CR2023 as saturation and brightness do not impact themeing in CR2023. The hue slider uses cr-action-menu to position itself since cr-action-menu already handles anchored and off-screen positioning, but is styled like a dialog. Follow-up CLs will clean up positioning, focus states, and update how and when the dialog closes. Bug: 1449969 Change-Id: I93db77fd9eb0f9d72cbe4bc1f8b00d2e18690adf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4705429 Reviewed-by: Thomas Lukaszewicz <tluk@chromium.org> Reviewed-by: Will Harris <wfh@chromium.org> Reviewed-by: Riley Tatum <rtatum@google.com> Commit-Queue: John Lee <johntlee@chromium.org> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Cr-Commit-Position: refs/heads/main@{#1184766}
- Loading branch information
John Lee
authored and
Chromium LUCI CQ
committed
Aug 17, 2023
1 parent
a1f62c9
commit 8b23153
Showing
21 changed files
with
378 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
chrome/app/generated_resources_grd/IDS_NTP_CUSTOMIZE_COLOR_HUE_SLIDER_TITLE.png.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
f46ec53121d483c0aa87c2991b9b8bb907f326a6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
chrome/test/data/webui/cr_components/theme_hue_slider_dialog_test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'chrome://customize-chrome-side-panel.top-chrome/app.js'; | ||
|
||
import {ThemeHueSliderDialogElement} from 'chrome://resources/cr_components/theme_color_picker/theme_hue_slider_dialog.js'; | ||
import {assertEquals, assertFalse, assertTrue} from 'chrome://webui-test/chai_assert.js'; | ||
import {eventToPromise} from 'chrome://webui-test/test_util.js'; | ||
|
||
suite('CrComponentsThemeHueSliderDialogTest', () => { | ||
let element: ThemeHueSliderDialogElement; | ||
|
||
setup(() => { | ||
document.body.innerHTML = window.trustedTypes!.emptyHTML; | ||
element = document.createElement('cr-theme-hue-slider-dialog'); | ||
document.body.appendChild(element); | ||
}); | ||
|
||
test('SetsUpCrSliderValues', () => { | ||
assertEquals(0, element.$.slider.min); | ||
assertEquals(359, element.$.slider.max); | ||
|
||
element.selectedHue = 200; | ||
assertEquals(200, element.$.slider.value); | ||
}); | ||
|
||
test('UpdatesCrSliderUi', () => { | ||
const knobStyle = window.getComputedStyle(element.$.slider.$.knob); | ||
element.$.slider.value = 200; | ||
element.$.slider.dispatchEvent(new CustomEvent('cr-slider-value-changed')); | ||
|
||
// window.getComputedStyle only returns color values in rgb format, so | ||
// rgb(0, 170, 255) is manually converted from hsl(200, 100%, 50%). | ||
assertEquals('rgb(0, 170, 255)', knobStyle.backgroundColor); | ||
|
||
element.$.slider.value = 300; | ||
element.$.slider.dispatchEvent(new CustomEvent('cr-slider-value-changed')); | ||
// rgb(255, 0, 255) is manually converted from hsl(300, 100%, 50%). | ||
assertEquals('rgb(255, 0, 255)', knobStyle.backgroundColor); | ||
}); | ||
|
||
test('UpdatesSelectedHue', () => { | ||
element.selectedHue = 0; | ||
|
||
// Changing the slider itself should not update selected hue. | ||
element.$.slider.value = 100; | ||
element.$.slider.dispatchEvent(new CustomEvent('cr-slider-value-changed')); | ||
assertEquals(0, element.selectedHue); | ||
|
||
// Only on pointerup should the selectedHue change. | ||
element.$.slider.dispatchEvent(new PointerEvent('pointerup')); | ||
assertEquals(100, element.selectedHue); | ||
|
||
// Changing the slider itself should not update selected hue. | ||
element.$.slider.value = 250; | ||
element.$.slider.dispatchEvent(new CustomEvent('cr-slider-value-changed')); | ||
assertEquals(100, element.selectedHue); | ||
|
||
// Only on keyup should the selectedHue change. | ||
element.$.slider.dispatchEvent(new KeyboardEvent('keyup')); | ||
assertEquals(250, element.selectedHue); | ||
}); | ||
|
||
test('DispatchesSelectedHueChangedEvent', async () => { | ||
const selectedHueChangedEvent = | ||
eventToPromise('selected-hue-changed', element); | ||
element.$.slider.value = 100; | ||
element.$.slider.dispatchEvent(new PointerEvent('pointerup')); | ||
const e = await selectedHueChangedEvent; | ||
assertEquals(100, e.detail.selectedHue); | ||
}); | ||
|
||
test('ShowsAndHides', () => { | ||
const anchor = document.createElement('div'); | ||
document.body.appendChild(anchor); | ||
element.showAt(anchor); | ||
assertTrue(element.$.crActionMenu.getDialog().open); | ||
element.hide(); | ||
assertFalse(element.$.crActionMenu.getDialog().open); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.