This source file includes following definitions.
- SetSelectedColor
- Open
- End
- OnColorChosen
- OnColorChooserDialogClosed
- ShowColorChooser
#include <windows.h>
#include "chrome/browser/platform_util.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/views/color_chooser_dialog.h"
#include "content/public/browser/color_chooser.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "ui/views/color_chooser/color_chooser_listener.h"
#if defined(USE_ASH)
#include "chrome/browser/ui/views/color_chooser_aura.h"
#endif
class ColorChooserWin : public content::ColorChooser,
public views::ColorChooserListener {
public:
static ColorChooserWin* Open(content::WebContents* web_contents,
SkColor initial_color);
ColorChooserWin(content::WebContents* web_contents,
SkColor initial_color);
~ColorChooserWin();
virtual void End() OVERRIDE;
virtual void SetSelectedColor(SkColor color) OVERRIDE {}
virtual void OnColorChosen(SkColor color);
virtual void OnColorChooserDialogClosed();
private:
static ColorChooserWin* current_color_chooser_;
content::WebContents* web_contents_;
scoped_refptr<ColorChooserDialog> color_chooser_dialog_;
};
ColorChooserWin* ColorChooserWin::current_color_chooser_ = NULL;
ColorChooserWin* ColorChooserWin::Open(content::WebContents* web_contents,
SkColor initial_color) {
if (current_color_chooser_)
return NULL;
current_color_chooser_ = new ColorChooserWin(web_contents, initial_color);
return current_color_chooser_;
}
ColorChooserWin::ColorChooserWin(content::WebContents* web_contents,
SkColor initial_color)
: web_contents_(web_contents) {
gfx::NativeWindow owning_window = platform_util::GetTopLevel(
web_contents->GetRenderViewHost()->GetView()->GetNativeView());
color_chooser_dialog_ = new ColorChooserDialog(this,
initial_color,
owning_window);
}
ColorChooserWin::~ColorChooserWin() {
DCHECK(!color_chooser_dialog_);
}
void ColorChooserWin::End() {
OnColorChooserDialogClosed();
}
void ColorChooserWin::OnColorChosen(SkColor color) {
if (web_contents_)
web_contents_->DidChooseColorInColorChooser(color);
}
void ColorChooserWin::OnColorChooserDialogClosed() {
if (color_chooser_dialog_.get()) {
color_chooser_dialog_->ListenerDestroyed();
color_chooser_dialog_ = NULL;
}
DCHECK(current_color_chooser_ == this);
current_color_chooser_ = NULL;
if (web_contents_)
web_contents_->DidEndColorChooser();
}
namespace chrome {
content::ColorChooser* ShowColorChooser(content::WebContents* web_contents,
SkColor initial_color) {
#if defined(USE_ASH)
gfx::NativeView native_view = web_contents->GetView()->GetNativeView();
if (GetHostDesktopTypeForNativeView(native_view) == HOST_DESKTOP_TYPE_ASH)
return ColorChooserAura::Open(web_contents, initial_color);
#endif
return ColorChooserWin::Open(web_contents, initial_color);
}
}