diff --git a/widget/windows/nsColorPicker.cpp b/widget/windows/nsColorPicker.cpp index 5074b620f54e..a754fb222a5c 100644 --- a/widget/windows/nsColorPicker.cpp +++ b/widget/windows/nsColorPicker.cpp @@ -6,6 +6,7 @@ #include "nsColorPicker.h" +#include #include #include "mozilla/ArrayUtils.h" @@ -86,6 +87,15 @@ AsyncColorChooser::Run() { MOZ_ASSERT(NS_IsMainThread(), "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 // 944737 if (!gColorChooser) { @@ -94,13 +104,11 @@ AsyncColorChooser::Run() { ScopedRtlShimWindow shim(mParentWidget.get()); - COLORREF customColors[16]; - for (size_t i = 0; i < mozilla::ArrayLength(customColors); i++) { - if (i < mDefaultColors.Length()) { - customColors[i] = ColorStringToRGB(mDefaultColors[i]); - } else { - customColors[i] = 0x00FFFFFF; - } + // This will overwrite custom colors if default colors were defined. + for (size_t i = 0; i < std::min(mozilla::ArrayLength(sCustomColors), + mDefaultColors.Length()); + i++) { + sCustomColors[i] = ColorStringToRGB(mDefaultColors[i]); } CHOOSECOLOR options; @@ -108,7 +116,7 @@ AsyncColorChooser::Run() { options.hwndOwner = shim.get(); options.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ENABLEHOOK; options.rgbResult = mInitialColor; - options.lpCustColors = customColors; + options.lpCustColors = sCustomColors; options.lpfnHook = HookProc; mColor = ChooseColor(&options) ? options.rgbResult : mInitialColor;