Index: chrome/browser/ui/views/color_chooser_dialog_win.cc |
diff --git a/chrome/browser/ui/views/color_chooser_dialog_win.cc b/chrome/browser/ui/views/color_chooser_dialog_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..30bcfa69adf57f06258b71d53a899cc65506772d |
--- /dev/null |
+++ b/chrome/browser/ui/views/color_chooser_dialog_win.cc |
@@ -0,0 +1,98 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/views/color_chooser_dialog_win.h" |
+ |
+#include <commdlg.h> |
+ |
+#include "base/bind.h" |
+#include "base/message_loop.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+using content::BrowserThread; |
+ |
+COLORREF COLORREFFromWebColor(WebKit::WebColor color) { |
+ uint8 r = static_cast<uint8>(color >> 16) & 0xFF; |
+ uint8 g = static_cast<uint8>(color >> 8) & 0xFF; |
+ uint8 b = static_cast<uint8>(color >> 0) & 0xFF; |
+ return RGB(r, g, b); |
+} |
+ |
+WebKit::WebColor WebColorFromCOLORREF(COLORREF color) { |
+ uint8 b = static_cast<uint8>(GetBValue(color)); |
+ uint8 g = static_cast<uint8>(GetGValue(color)); |
+ uint8 r = static_cast<uint8>(GetRValue(color)); |
+ return ((255 << 24) | (r << 16) | (g << 8) | b); |
+} |
+ |
+ColorChooserDialogWin::ColorChooserDialogWin(Listener* listener) |
+ : listener_(listener), |
+ ColorChooserDialog(), |
+ BaseShellDialogImpl() { |
+ DCHECK(listener_); |
+} |
+ |
+ColorChooserDialogWin::~ColorChooserDialogWin() { |
+} |
+ |
+bool ColorChooserDialogWin::IsRunning(HWND owning_hwnd) const { |
+ return listener_ && IsRunningDialogForOwner(owning_hwnd); |
+} |
+ |
+void ColorChooserDialogWin::ListenerDestroyed() { |
+ // Our associated listener has gone away, so we shouldn't call back to it if |
+ // our worker thread returns after the listener is dead. |
+ listener_ = NULL; |
+} |
+ |
+void ColorChooserDialogWin::SelectColor(WebKit::WebColor initial_color, |
+ gfx::NativeWindow owning_window) { |
+ ExecuteOpenParams execute_params(initial_color, BeginRun(owning_window), |
+ owning_window); |
+ execute_params.run_state.dialog_thread->message_loop()->PostTask(FROM_HERE, |
+ base::Bind(&ColorChooserDialogWin::ExecuteOpen, this, execute_params)); |
+} |
+ |
+void ColorChooserDialogWin::ExecuteOpen(const ExecuteOpenParams& params) { |
+ COLORREF color = COLORREFFromWebColor(params.color); |
+ CHOOSECOLOR cc; |
+ cc.lStructSize = sizeof(CHOOSECOLOR); |
+ cc.hwndOwner = params.owner; |
+ cc.rgbResult = color; |
+ cc.lpCustColors = custom_colors_; |
+ cc.Flags = CC_FULLOPEN | CC_RGBINIT; |
+ bool success = !!ChooseColor(&cc); |
+ DisableOwner(cc.hwndOwner); |
+ if (success) { |
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
+ base::Bind(&ColorChooserDialogWin::DidChooseColor, this, |
+ WebColorFromCOLORREF(cc.rgbResult), |
+ params.run_state)); |
+ } else { |
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
+ base::Bind(&ColorChooserDialogWin::DidDetach, this, |
+ params.run_state)); |
+ } |
+} |
+ |
+void ColorChooserDialogWin::DidChooseColor(WebKit::WebColor color, |
+ RunState run_state) { |
+ if (!listener_) |
+ return; |
+ EndRun(run_state); |
+ listener_->DidChooseColor(color); |
+ listener_->DidEnd(); |
+} |
+ |
+void ColorChooserDialogWin::DidDetach(RunState run_state) { |
+ if (!listener_) |
+ return; |
+ EndRun(run_state); |
+ listener_->DidEnd(); |
+} |
+ |
+// static |
+ColorChooserDialog* ColorChooserDialog::Create(Listener* listener) { |
+ return new ColorChooserDialogWin(listener); |
+} |