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

Unified Diff: chrome/browser/ui/gtk/color_chooser_gtk.cc

Issue 13150004: Support color chooser inside extesions, apps, chrome frame, dev tool (Closed) Base URL: http://git.chromium.org/chromium/src.git@ngcolor
Patch Set: Fixed android build Created 7 years, 7 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
« no previous file with comments | « chrome/browser/ui/extensions/shell_window.cc ('k') | chrome/browser/ui/views/color_chooser_aura.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/gtk/color_chooser_gtk.cc
diff --git a/chrome/browser/ui/gtk/color_chooser_gtk.cc b/chrome/browser/ui/gtk/color_chooser_gtk.cc
index 8b9384fec66bf755c767fe424fa16e9b9fb79f4c..3a9cb10e4a3675a63f5af0d13164bd56d8a862e1 100644
--- a/chrome/browser/ui/gtk/color_chooser_gtk.cc
+++ b/chrome/browser/ui/gtk/color_chooser_gtk.cc
@@ -4,42 +4,52 @@
#include <gtk/gtk.h>
+#include "chrome/browser/ui/browser_dialogs.h"
#include "content/public/browser/color_chooser.h"
-
#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_observer.h"
#include "grit/generated_resources.h"
#include "ui/base/gtk/gtk_signal.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/skia_utils_gtk.h"
-class ColorChooserGtk : public content::ColorChooser,
- public content::WebContentsObserver {
+class ColorChooserGtk : public content::ColorChooser {
public:
- ColorChooserGtk(
- int identifier, content::WebContents* tab, SkColor initial_color);
+ static ColorChooserGtk* Open(content::WebContents* web_contents,
+ SkColor initial_color);
+
+ ColorChooserGtk(content::WebContents* web_contents, SkColor initial_color);
virtual ~ColorChooserGtk();
virtual void End() OVERRIDE;
virtual void SetSelectedColor(SkColor color) OVERRIDE;
private:
+ static ColorChooserGtk* current_color_chooser_;
+
CHROMEGTK_CALLBACK_0(ColorChooserGtk, void, OnColorChooserOk);
CHROMEGTK_CALLBACK_0(ColorChooserGtk, void, OnColorChooserCancel);
CHROMEGTK_CALLBACK_0(ColorChooserGtk, void, OnColorChooserDestroy);
+ // The web contents invoking the color chooser. No ownership because it will
+ // outlive this class.
+ content::WebContents* web_contents_;
GtkWidget* color_selection_dialog_;
};
-content::ColorChooser* content::ColorChooser::Create(
- int identifier, content::WebContents* tab, SkColor initial_color) {
- return new ColorChooserGtk(identifier, tab, initial_color);
+ColorChooserGtk* ColorChooserGtk::current_color_chooser_ = NULL;
+
+ColorChooserGtk* ColorChooserGtk::Open(content::WebContents* web_contents,
+ SkColor initial_color) {
+ if (current_color_chooser_)
+ current_color_chooser_->End();
+ DCHECK(!current_color_chooser_);
+ current_color_chooser_ = new ColorChooserGtk(web_contents, initial_color);
+ return current_color_chooser_;
}
-ColorChooserGtk::ColorChooserGtk(
- int identifier, content::WebContents* tab, SkColor initial_color)
- : content::ColorChooser(identifier),
- content::WebContentsObserver(tab) {
+ColorChooserGtk::ColorChooserGtk(content::WebContents* web_contents,
+ SkColor initial_color)
+ : web_contents_(web_contents) {
color_selection_dialog_ = gtk_color_selection_dialog_new(
l10n_util::GetStringUTF8(IDS_SELECT_COLOR_DIALOG_TITLE).c_str());
GtkWidget* cancel_button;
@@ -77,8 +87,8 @@ void ColorChooserGtk::OnColorChooserOk(GtkWidget* widget) {
g_object_get(color_selection_dialog_,
"color-selection", &color_selection, NULL);
gtk_color_selection_get_current_color(color_selection, &color);
- web_contents()->DidChooseColorInColorChooser(identifier(),
- gfx::GdkColorToSkColor(color));
+ if (web_contents_)
+ web_contents_->DidChooseColorInColorChooser(gfx::GdkColorToSkColor(color));
g_object_unref(color_selection);
gtk_widget_destroy(color_selection_dialog_);
}
@@ -89,8 +99,10 @@ void ColorChooserGtk::OnColorChooserCancel(GtkWidget* widget) {
void ColorChooserGtk::OnColorChooserDestroy(GtkWidget* widget) {
color_selection_dialog_ = NULL;
- if (web_contents())
- web_contents()->DidEndColorChooser(identifier());
+ DCHECK(current_color_chooser_ == this);
+ current_color_chooser_ = NULL;
+ if (web_contents_)
+ web_contents_->DidEndColorChooser();
}
void ColorChooserGtk::End() {
@@ -112,3 +124,12 @@ void ColorChooserGtk::SetSelectedColor(SkColor color) {
gtk_color_selection_set_current_color(color_selection, &gdk_color);
g_object_unref(color_selection);
}
+
+namespace chrome {
+
+content::ColorChooser* ShowColorChooser(content::WebContents* web_contents,
+ SkColor initial_color) {
+ return ColorChooserGtk::Open(web_contents, initial_color);
+}
+
+} // namespace chrome
« no previous file with comments | « chrome/browser/ui/extensions/shell_window.cc ('k') | chrome/browser/ui/views/color_chooser_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698