forked from mirrors/gecko-dev
Bug 1896960 - Preserve the user's custom colors between multiple color pickers. r=emilio
I think there is no good way of combining support for datalists and whatever the user picked. So I just treat the datalist colors as an overwrite. Differential Revision: https://phabricator.services.mozilla.com/D210891
This commit is contained in:
parent
c26f9795d5
commit
8945a03562
1 changed files with 16 additions and 8 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "nsColorPicker.h"
|
#include "nsColorPicker.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
|
|
||||||
#include "mozilla/ArrayUtils.h"
|
#include "mozilla/ArrayUtils.h"
|
||||||
|
|
@ -86,6 +87,15 @@ AsyncColorChooser::Run() {
|
||||||
MOZ_ASSERT(NS_IsMainThread(),
|
MOZ_ASSERT(NS_IsMainThread(),
|
||||||
"Color pickers can only be opened from main thread currently");
|
"Color pickers can only be opened from main thread currently");
|
||||||
|
|
||||||
|
// Static to preserve the custom colors between different ChooseColor calls.
|
||||||
|
static COLORREF sCustomColors[16];
|
||||||
|
static bool sInitialized = false;
|
||||||
|
if (!sInitialized) {
|
||||||
|
// Initialize to white instead of black.
|
||||||
|
std::fill(std::begin(sCustomColors), std::end(sCustomColors), 0x00FFFFFF);
|
||||||
|
sInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Allow only one color picker to be opened at a time, to workaround bug
|
// Allow only one color picker to be opened at a time, to workaround bug
|
||||||
// 944737
|
// 944737
|
||||||
if (!gColorChooser) {
|
if (!gColorChooser) {
|
||||||
|
|
@ -94,13 +104,11 @@ AsyncColorChooser::Run() {
|
||||||
|
|
||||||
ScopedRtlShimWindow shim(mParentWidget.get());
|
ScopedRtlShimWindow shim(mParentWidget.get());
|
||||||
|
|
||||||
COLORREF customColors[16];
|
// This will overwrite custom colors if default colors were defined.
|
||||||
for (size_t i = 0; i < mozilla::ArrayLength(customColors); i++) {
|
for (size_t i = 0; i < std::min(mozilla::ArrayLength(sCustomColors),
|
||||||
if (i < mDefaultColors.Length()) {
|
mDefaultColors.Length());
|
||||||
customColors[i] = ColorStringToRGB(mDefaultColors[i]);
|
i++) {
|
||||||
} else {
|
sCustomColors[i] = ColorStringToRGB(mDefaultColors[i]);
|
||||||
customColors[i] = 0x00FFFFFF;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CHOOSECOLOR options;
|
CHOOSECOLOR options;
|
||||||
|
|
@ -108,7 +116,7 @@ AsyncColorChooser::Run() {
|
||||||
options.hwndOwner = shim.get();
|
options.hwndOwner = shim.get();
|
||||||
options.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ENABLEHOOK;
|
options.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ENABLEHOOK;
|
||||||
options.rgbResult = mInitialColor;
|
options.rgbResult = mInitialColor;
|
||||||
options.lpCustColors = customColors;
|
options.lpCustColors = sCustomColors;
|
||||||
options.lpfnHook = HookProc;
|
options.lpfnHook = HookProc;
|
||||||
|
|
||||||
mColor = ChooseColor(&options) ? options.rgbResult : mInitialColor;
|
mColor = ChooseColor(&options) ? options.rgbResult : mInitialColor;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue