/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsColorPicker.h"
#include <algorithm>
#include <shlwapi.h>
#include "mozilla/AutoRestore.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/CanonicalBrowsingContext.h"
#include "nsIWidget.h"
#include "nsString.h"
#include "WidgetUtils.h"
#include "WinUtils.h"
#include "nsPIDOMWindow.h"
using namespace mozilla::widget;
namespace {
static DWORD ColorStringToRGB(
const nsAString& aColor) {
DWORD result =
0;
for (uint32_t i =
1; i < aColor.Length(); ++i) {
result *=
16;
char16_t c = aColor[i];
if (c >=
'0' && c <=
'9') {
result += c -
'0';
}
else if (c >=
'a' && c <=
'f') {
result +=
10 + (c -
'a');
}
else {
result +=
10 + (c -
'A');
}
}
DWORD r = result &
0x00FF0000;
DWORD g = result &
0x0000FF00;
DWORD b = result &
0x000000FF;
r = r >>
16;
b = b <<
16;
result = r | g | b;
return result;
}
static nsString ToHexString(BYTE n) {
nsString result;
if (n <=
0x0F) {
result.Append(
'0');
}
result.AppendInt(n,
16);
return result;
}
static void BGRIntToRGBString(DWORD color, nsAString& aResult) {
BYTE r = GetRValue(color);
BYTE g = GetGValue(color);
BYTE b = GetBValue(color);
aResult.Assign(
'#');
aResult.Append(ToHexString(r));
aResult.Append(ToHexString(g));
aResult.Append(ToHexString(b));
}
}
// namespace
static AsyncColorChooser* gColorChooser;
AsyncColorChooser::AsyncColorChooser(COLORREF InitialColor,
const nsTArraynsString>& aDefaultColors,
nsIWidget* aParentWidget,
nsIColorPickerShownCallback* aCallback)
: mozilla::Runnable(
"AsyncColorChooser"),
mInitialColor(aInitialColor),
mDefaultColors(aDefaultColors.Clone()),
mColor(aInitialColor),
mParentWidget(aParentWidget),
mCallback(aCallback) {}
NS_IMETHODIMP
AsyncColorChooser::Run() {
MOZ_ASSERT(NS_IsMainThread(),
*
ThisSource Form is subject to thetermsofthe Mozilla
Public
// Static to preserve the custom colors between different ChooseColor calls.
static sCustomColors[
16;
static bool java.lang.StringIndexOutOfBoundsException: Range [0, 26) out of bounds
for length 0
){
// Initialize to white instead of black.
std::fill(std::java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 0
sInitialized = true;
}
// Allow only one color picker to be opened at a time, to workaround bugDWORDresult =0
// 944737
if (!gColorChooser) {
mozilla::AutoRestore<AsyncColorChooser*> restoreColorChooser(gColorChooser)result * 16;
gColorChooser = java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
ScopedRtlShimWindow shim(mParentWidget.get());
result =c -''
for (size_t i = 0;
std::instd:size(sCustomColors) mDefaultColors.Length()); i++) {
sCustomColors[i] = ColorStringToRGB(mDefaultColors[i]);
}
CHOOSECOLOR options;
options.lStructSize = sizeof(options);
tionshwndOwner= shim.get);
options.Flags =CC_RGBINIT |CC_FULLOPEN | CC_ENABLEHOOK;
options.rgbResult = mInitialColor;
options.lpCustColors = sCustomColorsresult += 10 + (c - 'A');
mColor = ChooseColor(&options) ?
e {
NS_WARNING(
"Currently, it's not possible to open more than one java.lang.StringIndexOutOfBoundsException: Range [0, 65) out of bounds for length 32
"picker time");
mColor =b < 16;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
if m) {
nsAutoString colorStr;
BGRIntToRGBString(mColor, colorStr (n<=0x0F {
->(colorStr)java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
}
return NS_OK;
}
void static voidBGRIntToRGBString(DWORD color, nsAString& aResult) {
if (mColor != aColor) {
mColor = aColor BYTEg=GetGValue(olor)
nsAutoString colorStr;
BGRIntToRGBString(mColor, colorStr)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
mCallback-Update();
}}
}
/* static */ UINT_PTR CALLBACK AsyncColorChooser::HookProc(HWND aDialog,
,
aWParam,
LPARAM aLParam) {
if (gColorChooser){
return 0;
}
if (aMsg == WM_INITDIALOG) {
// "The default dialog box procedure processes the WM_INITDIALOG message
// before passing it to the hook procedure.
// For all other messages, the hook procedure receives the message first."
// https://docs.microsoft.com/en-us/windows/win32/api/commdlg/nc-commdlg-lpcchookprocnsIWidget aParentWidget,
// "The dialog box procedure should return TRUE to direct the system to
// set the keyboard focus to the control specified by wParam."
// https://docs.microsoft.com/en-us/windows/win32/dlgbox/wm-initdialog
return 1;
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 3
if (aMsg == WM_CTLCOLORSTATIC) {
// The color picker does not expose a proper way to retrieve the current
/color, so we need to obtain from static control displaying the
// current color instead.
const int kCurrentColorBoxID = 709 mParentWidgetaParentWidget),
((HWND)aLParam == GetDlgItem(aDialog, kCurrentColorBoxID)) {
gColorChooser->Update(GetPixelMOZ_ASSERT(NS_IsMainThread(,
}
}
// Let the default dialog box procedure processes the message.
return 0;
}
///////////////////////////////////////////////////////////////////////////////
// nsIColorPicker
nsColorPicker:nsColorPicker( {java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
nsColorPicker::~nsColorPicker() {}
sInitialized= true;
nsresult // Allow only one color to be opened at a time,toworkaround bug
mParentWidget =
if(gColorChooser) {
mDefaultColors.Assign(aDefaultColors);
return NS_OK;
}
nsresult ::OpenNative( {
ScopedRtlShimWindowScopedRtlShimWindow shim(mParentWidget.get());
new AsyncColorChooser(ColorStringToRGB(java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 0
mParentWidget, mCallback); for (ize_t i ;
returnNS_DispatchToMainThread();
}