aura: Add color chooser dialog

This commit is contained in:
Cheng Zhao 2014-10-31 23:06:50 +08:00
parent 14c9a2a087
commit de49498102
3 changed files with 129 additions and 0 deletions

View file

@ -304,6 +304,8 @@
'chromium_src/chrome/browser/speech/tts_win.cc',
'chromium_src/chrome/browser/ui/browser_dialogs.h',
'chromium_src/chrome/browser/ui/cocoa/color_chooser_mac.mm',
'chromium_src/chrome/browser/ui/views/color_chooser_aura.cc',
'chromium_src/chrome/browser/ui/views/color_chooser_aura.h',
'chromium_src/chrome/browser/ui/libgtk2ui/app_indicator_icon_menu.cc',
'chromium_src/chrome/browser/ui/libgtk2ui/app_indicator_icon_menu.h',
'chromium_src/chrome/browser/ui/libgtk2ui/gtk2_status_icon.cc',

View file

@ -0,0 +1,69 @@
// 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_aura.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "content/public/browser/web_contents.h"
#include "ui/views/color_chooser/color_chooser_view.h"
#include "ui/views/widget/widget.h"
ColorChooserAura::ColorChooserAura(content::WebContents* web_contents,
SkColor initial_color)
: web_contents_(web_contents) {
view_ = new views::ColorChooserView(this, initial_color);
widget_ = views::Widget::CreateWindowWithParent(
view_, web_contents->GetTopLevelNativeWindow());
widget_->Show();
}
void ColorChooserAura::OnColorChosen(SkColor color) {
if (web_contents_)
web_contents_->DidChooseColorInColorChooser(color);
}
void ColorChooserAura::OnColorChooserDialogClosed() {
view_ = NULL;
widget_ = NULL;
DidEndColorChooser();
}
void ColorChooserAura::End() {
if (widget_) {
view_->set_listener(NULL);
widget_->Close();
view_ = NULL;
widget_ = NULL;
// DidEndColorChooser will invoke Browser::DidEndColorChooser, which deletes
// this. Take care of the call order.
DidEndColorChooser();
}
}
void ColorChooserAura::DidEndColorChooser() {
if (web_contents_)
web_contents_->DidEndColorChooser();
}
void ColorChooserAura::SetSelectedColor(SkColor color) {
if (view_)
view_->OnColorChanged(color);
}
// static
ColorChooserAura* ColorChooserAura::Open(
content::WebContents* web_contents, SkColor initial_color) {
return new ColorChooserAura(web_contents, initial_color);
}
#if !defined(OS_WIN)
namespace chrome {
content::ColorChooser* ShowColorChooser(content::WebContents* web_contents,
SkColor initial_color) {
return ColorChooserAura::Open(web_contents, initial_color);
}
} // namespace chrome
#endif // OS_WIN

View file

@ -0,0 +1,58 @@
// Copyright 2013 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.
#ifndef CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_AURA_H_
#define CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_AURA_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "content/public/browser/color_chooser.h"
#include "ui/views/color_chooser/color_chooser_listener.h"
namespace content {
class WebContents;
}
namespace views {
class ColorChooserView;
class Widget;
}
// TODO(mukai): rename this as -Ash and move to c/b/ui/ash after Linux-aura
// switches to its native color chooser.
class ColorChooserAura : public content::ColorChooser,
public views::ColorChooserListener {
public:
static ColorChooserAura* Open(content::WebContents* web_contents,
SkColor initial_color);
private:
ColorChooserAura(content::WebContents* web_contents, SkColor initial_color);
// content::ColorChooser overrides:
virtual void End() OVERRIDE;
virtual void SetSelectedColor(SkColor color) OVERRIDE;
// views::ColorChooserListener overrides:
virtual void OnColorChosen(SkColor color) OVERRIDE;
virtual void OnColorChooserDialogClosed() OVERRIDE;
void DidEndColorChooser();
// The actual view of the color chooser. No ownership because its parent
// view will take care of its lifetime.
views::ColorChooserView* view_;
// The widget for the color chooser. No ownership because it's released
// automatically when closed.
views::Widget* widget_;
// The web contents invoking the color chooser. No ownership because it will
// outlive this class.
content::WebContents* web_contents_;
DISALLOW_COPY_AND_ASSIGN(ColorChooserAura);
};
#endif // CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_AURA_H_