1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_DIALOG_H_ 6#define CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_DIALOG_H_ 7 8#include "base/memory/ref_counted.h" 9#include "chrome/browser/ui/views/color_chooser_dialog.h" 10#include "third_party/skia/include/core/SkColor.h" 11#include "ui/shell_dialogs/base_shell_dialog.h" 12#include "ui/shell_dialogs/base_shell_dialog_win.h" 13 14namespace views { 15class ColorChooserListener; 16} 17 18class ColorChooserDialog 19 : public base::RefCountedThreadSafe<ColorChooserDialog>, 20 public ui::BaseShellDialog, 21 public ui::BaseShellDialogImpl { 22 public: 23 ColorChooserDialog(views::ColorChooserListener* listener, 24 SkColor initial_color, 25 gfx::NativeWindow owning_window); 26 virtual ~ColorChooserDialog(); 27 28 // BaseShellDialog: 29 virtual bool IsRunning(gfx::NativeWindow owning_window) const OVERRIDE; 30 virtual void ListenerDestroyed() OVERRIDE; 31 32 private: 33 struct ExecuteOpenParams { 34 ExecuteOpenParams(SkColor color, RunState run_state, HWND owner); 35 SkColor color; 36 RunState run_state; 37 HWND owner; 38 }; 39 40 // Called on the dialog thread to show the actual color chooser. This is 41 // shown modal to |params.owner|. Once it's closed, calls back to 42 // DidCloseDialog() on the UI thread. 43 void ExecuteOpen(const ExecuteOpenParams& params); 44 45 // Called on the UI thread when a color chooser is closed. |chose_color| is 46 // true if the user actually chose a color, in which case |color| is the 47 // chosen color. Calls back to the |listener_| (if applicable) to notify it 48 // of the results, and copies the modified array of |custom_colors_| back to 49 // |g_custom_colors| so future dialogs will see the changes. 50 void DidCloseDialog(bool chose_color, SkColor color, RunState run_state); 51 52 // Copies the array of colors in |src| to |dst|. 53 void CopyCustomColors(COLORREF*, COLORREF*); 54 55 // The user's custom colors. Kept process-wide so that they can be persisted 56 // from one dialog invocation to the next. 57 static COLORREF g_custom_colors[16]; 58 59 // A copy of the custom colors for the current dialog to display and modify. 60 // This allows us to safely access the colors even if multiple windows are 61 // simultaneously showing color choosers (which would cause thread safety 62 // problems if we gave them direct handles to |g_custom_colors|). 63 COLORREF custom_colors_[16]; 64 65 // The listener to notify when the user closes the dialog. This may be set to 66 // NULL before the color chooser is closed, signalling that the listener no 67 // longer cares about the outcome. 68 views::ColorChooserListener* listener_; 69 70 DISALLOW_COPY_AND_ASSIGN(ColorChooserDialog); 71}; 72 73#endif // CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_DIALOG_H_ 74