Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: chrome/browser/ui/views/shell_dialogs_win.cc

Issue 7690004: Implement input type=color UI (win part) (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebased Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/shell_dialogs_win.cc
diff --git a/chrome/browser/ui/views/shell_dialogs_win.cc b/chrome/browser/ui/views/shell_dialogs_win.cc
index 0ce04a0d25dd4a3499c2be7fa07e519c61d5b043..f69a1c2355cdb6eb11e19246ec7474550a73df9b 100644
--- a/chrome/browser/ui/views/shell_dialogs_win.cc
+++ b/chrome/browser/ui/views/shell_dialogs_win.cc
@@ -21,6 +21,7 @@
#include "base/win/registry.h"
#include "base/win/scoped_comptr.h"
#include "base/win/windows_version.h"
+#include "chrome/browser/ui/color_chooser_dialog.h"
#include "content/browser/browser_thread.h"
#include "grit/generated_resources.h"
#include "grit/ui_strings.h"
@@ -940,3 +941,113 @@ bool SelectFileDialogImpl::RunOpenMultiFileDialog(
SelectFileDialog* SelectFileDialog::Create(Listener* listener) {
return new SelectFileDialogImpl(listener);
}
+
+#if defined(ENABLE_INPUT_COLOR)
+
+COLORREF COLORREFFromWebColor(WebKit::WebColor color) {
+ uint8 r = (color >> 16) & 0xFF;
yosin_UTC9 2011/12/06 07:31:50 Could you use static_cast<uint8>(color >> 16) inst
+ uint8 g = (color >> 8) & 0xFF;
+ uint8 b = (color >> 0) & 0xFF;
+ return RGB(r, g, b);
+}
+
+WebKit::WebColor WebColorFromCOLORREF(COLORREF color) {
+ uint8 b = (color >> 16) & 0xFF;
yosin_UTC9 2011/12/06 07:31:50 It is better to use BYTE GetBValue(COLORREF), GetG
+ uint8 g = (color >> 8) & 0xFF;
+ uint8 r = (color >> 0) & 0xFF;
+ return ((255 << 24) | (r << 16) | (g << 8) | b);
+}
+
+class ColorChooserDialogImpl
+ : public ColorChooserDialog,
+ public BaseShellDialogImpl {
+ public:
+ explicit ColorChooserDialogImpl(Listener* listener);
+
+ virtual bool IsRunning(HWND owning_hwnd) const;
yosin_UTC9 2011/12/06 07:31:50 Please put "OVERRIDE" before semi-colon for overri
+ virtual void ListenerDestroyed();
+
+ virtual void SelectColor(WebKit::WebColor initial_color,
+ gfx::NativeWindow owning_window);
+
+ private:
+ virtual ~ColorChooserDialogImpl();
+
+ struct ExecuteOpenParams {
+ ExecuteOpenParams(WebKit::WebColor color,
+ RunState run_state,
+ HWND owner)
+ : color(color),
+ run_state(run_state),
+ owner(owner) {
+ }
+ WebKit::WebColor color;
+ RunState run_state;
+ HWND owner;
+ };
+ void ExecuteOpen(const ExecuteOpenParams& params);
+ void DidChooseColor(WebKit::WebColor color, RunState run_state);
+
+ COLORREF custom_colors_[16];
yosin_UTC9 2011/12/06 07:31:50 Where does number 16 come from? We may want to hav
+ Listener* listener_;
+};
+
+ColorChooserDialogImpl::ColorChooserDialogImpl(Listener* listener)
+ : listener_(listener),
+ BaseShellDialogImpl() {
+ DCHECK(listener_);
+}
+
+ColorChooserDialogImpl::~ColorChooserDialogImpl() {
+}
+
+bool ColorChooserDialogImpl::IsRunning(HWND owning_hwnd) const {
+ return listener_ && IsRunningDialogForOwner(owning_hwnd);
+}
+
+void ColorChooserDialogImpl::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 ColorChooserDialogImpl::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,
+ NewRunnableMethod(this, &ColorChooserDialogImpl::ExecuteOpen,
+ execute_params));
+}
+
+void ColorChooserDialogImpl::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);
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &ColorChooserDialogImpl::DidChooseColor,
+ WebColorFromCOLORREF(cc.rgbResult),
+ params.run_state));
+}
+
+void ColorChooserDialogImpl::DidChooseColor(WebKit::WebColor color,
+ RunState run_state) {
+ if (!listener_)
+ return;
+ listener_->DidChooseColor(color);
+ EndRun(run_state);
+}
+
+// static
+ColorChooserDialog* ColorChooserDialog::Create(Listener* listener) {
+ return new ColorChooserDialogImpl(listener);
+}
+
+#endif // defined(ENABLE_INPUT_COLOR)
+

Powered by Google App Engine
This is Rietveld 408576698