Chromium Code Reviews| Index: chrome/browser/ui/views/color_chooser_dialog.cc |
| diff --git a/chrome/browser/ui/views/color_chooser_dialog.cc b/chrome/browser/ui/views/color_chooser_dialog.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..545bb85591dfd21f77595653acc39760befd4baa |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/color_chooser_dialog.cc |
| @@ -0,0 +1,88 @@ |
| +// Copyright (c) 2012 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.h" |
| + |
| +#include <commdlg.h> |
| + |
| +#include "base/bind.h" |
| +#include "base/message_loop.h" |
| +#include "base/threading/thread.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "skia/ext/skia_utils_win.h" |
| + |
| +using content::BrowserThread; |
| + |
| +ColorChooserDialog::ExecuteOpenParams::ExecuteOpenParams(SkColor color, |
| + RunState run_state, |
| + HWND owner) |
| + : color(color), |
| + run_state(run_state), |
| + owner(owner) { |
| +} |
| + |
| +ColorChooserDialog::ColorChooserDialog(Listener* listener, |
| + SkColor initial_color, |
| + gfx::NativeWindow owning_window) |
| + : listener_(listener), |
| + BaseShellDialogImpl() { |
|
Peter Kasting
2012/02/29 01:40:07
Nit: If you're going to explicitly call a supercla
keishi
2012/02/29 13:05:22
Done.
|
| + DCHECK(listener_); |
| + ExecuteOpenParams execute_params(initial_color, |
| + BeginRun(owning_window), |
|
Peter Kasting
2012/02/29 01:40:07
Nit: This can go on the previous line
keishi
2012/02/29 13:05:22
Done.
|
| + owning_window); |
| + execute_params.run_state.dialog_thread->message_loop()->PostTask(FROM_HERE, |
| + base::Bind(&ColorChooserDialog::ExecuteOpen, this, execute_params)); |
| +} |
| + |
| +ColorChooserDialog::~ColorChooserDialog() { |
| +} |
| + |
| +bool ColorChooserDialog::IsRunning(HWND owning_hwnd) const { |
| + return listener_ && IsRunningDialogForOwner(owning_hwnd); |
| +} |
| + |
| +void ColorChooserDialog::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 ColorChooserDialog::ExecuteOpen(const ExecuteOpenParams& params) { |
| + static COLORREF custom_colors[16]; |
|
Peter Kasting
2012/02/29 01:40:07
Don't do this here. This creates process-wide sto
keishi
2012/02/29 13:05:22
Done.
|
| + COLORREF color = skia::SkColorToCOLORREF(params.color); |
|
Peter Kasting
2012/02/29 01:40:07
Nit: Roll this into the assignment statement below
keishi
2012/02/29 13:05:22
Done.
|
| + CHOOSECOLOR cc; |
| + cc.lStructSize = sizeof(CHOOSECOLOR); |
| + cc.hwndOwner = params.owner; |
| + cc.rgbResult = color; |
| + cc.lpCustColors = custom_colors; |
| + cc.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT; |
| + bool success = !!ChooseColor(&cc); |
| + DisableOwner(cc.hwndOwner); |
| + if (success) { |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&ColorChooserDialog::DidChooseColor, this, |
| + skia::COLORREFToSkColor(cc.rgbResult), |
| + params.run_state)); |
| + } else { |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&ColorChooserDialog::DidDetach, this, |
| + params.run_state)); |
| + } |
| +} |
| + |
| +void ColorChooserDialog::DidChooseColor(SkColor color, |
| + RunState run_state) { |
| + if (!listener_) |
| + return; |
| + EndRun(run_state); |
| + listener_->DidChooseColor(color); |
| + listener_->DidEnd(); |
| +} |
| + |
| +void ColorChooserDialog::DidDetach(RunState run_state) { |
| + if (!listener_) |
| + return; |
| + EndRun(run_state); |
| + listener_->DidEnd(); |
| +} |