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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..53e72e6ff69744c7e845bec3eac2603c60dd84fa |
--- /dev/null |
+++ b/chrome/browser/ui/gtk/color_chooser_gtk.cc |
@@ -0,0 +1,110 @@ |
+// 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 <gtk/gtk.h> |
+ |
+#include "chrome/browser/ui/color_chooser.h" |
+ |
+#include "content/browser/renderer_host/render_view_host.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 ColorChooser { |
+ public: |
+ ColorChooserGtk(unsigned identifier, RenderViewHost* rvh) |
+ : identifier_(identifier), |
+ render_view_host_(rvh), |
+ color_selecting_dialog_(NULL) {} |
+ virtual ~ColorChooserGtk(); |
+ |
+ virtual void Open(SkColor initial_color); |
Evan Stade
2012/02/06 21:16:25
shouldn't these have OVERRIDE
keishi
2012/02/17 11:31:05
Done.
|
+ virtual void End(); |
+ virtual void SetSelectedColor(SkColor color); |
+ |
+ virtual RenderViewHost* render_view_host() { return render_view_host_; } |
+ virtual unsigned identifier() { return identifier_; } |
+ |
+ private: |
+ GtkColorSelection* colorSelection(); |
Evan Stade
2012/02/06 21:16:25
docs
keishi
2012/02/17 11:31:05
What does docs mean?
|
+ |
+ CHROMEGTK_CALLBACK_0(ColorChooserGtk, void, OnColorChooserOk); |
+ CHROMEGTK_CALLBACK_0(ColorChooserGtk, void, OnColorChooserCancel); |
+ CHROMEGTK_CALLBACK_0(ColorChooserGtk, void, OnColorChooserDestroy); |
+ |
+ unsigned identifier_; |
+ RenderViewHost* render_view_host_; |
+ GtkWidget* color_selecting_dialog_; |
Evan Stade
2012/02/06 21:16:25
why is this not color_selection_dialog_
keishi
2012/02/17 11:31:05
Done.
|
+}; |
+ |
+ColorChooser* ColorChooser::Create(unsigned identifier, RenderViewHost* rvh) { |
+ return new ColorChooserGtk(identifier, rvh); |
+} |
+ |
+ColorChooserGtk::~ColorChooserGtk() { |
+ printf("> ColorChooserGtk::~ColorChooserGtk %p\n", this); |
Evan Stade
2012/02/06 21:16:25
remove debugging line
keishi
2012/02/17 11:31:05
Done.
|
+ if (color_selecting_dialog_) |
+ gtk_widget_destroy(color_selecting_dialog_); |
+} |
+ |
+GtkColorSelection* ColorChooserGtk::colorSelection() { |
Evan Stade
2012/02/06 21:16:25
ColorSelection()
keishi
2012/02/17 11:31:05
Done.
|
+ if (!color_selecting_dialog_) |
+ return NULL; |
Evan Stade
2012/02/06 21:16:25
nit: \n
keishi
2012/02/17 11:31:05
Done.
|
+ return GTK_COLOR_SELECTION( |
+ GTK_COLOR_SELECTION_DIALOG(color_selecting_dialog_)->colorsel); |
+} |
+ |
+void ColorChooserGtk::OnColorChooserOk(GtkWidget* widget) { |
+ GdkColor color; |
+ gtk_color_selection_get_current_color(colorSelection(), &color); |
+ render_view_host_->DidChooseColorInColorChooser( |
+ identifier_, gfx::GdkColorToSkColor(color)); |
+ gtk_widget_destroy(color_selecting_dialog_); |
+} |
+ |
+void ColorChooserGtk::OnColorChooserCancel(GtkWidget* widget) { |
+ gtk_widget_destroy(color_selecting_dialog_); |
+} |
+ |
+void ColorChooserGtk::OnColorChooserDestroy(GtkWidget* widget) { |
+ color_selecting_dialog_ = NULL; |
+ render_view_host_->DidEndColorChooser(identifier_); |
+} |
+ |
+void ColorChooserGtk::Open(SkColor initial_color) { |
+ printf("> ColorChooserGtk::Open %p %d\n", this, !color_selecting_dialog_); |
Evan Stade
2012/02/06 21:16:25
remove debugging line
keishi
2012/02/17 11:31:05
Done.
|
+ if (!color_selecting_dialog_) { |
+ color_selecting_dialog_ = gtk_color_selection_dialog_new( |
+ l10n_util::GetStringUTF8(IDS_SELECT_COLOR_DIALOG_TITLE).c_str()); |
+ gtk_color_selection_set_has_opacity_control(colorSelection(), FALSE); |
+ g_signal_connect(G_OBJECT( |
+ GTK_COLOR_SELECTION_DIALOG(color_selecting_dialog_)->ok_button), |
+ "clicked", G_CALLBACK(OnColorChooserOkThunk), this); |
+ g_signal_connect(G_OBJECT( |
+ GTK_COLOR_SELECTION_DIALOG(color_selecting_dialog_)->cancel_button), |
+ "clicked", G_CALLBACK(OnColorChooserCancelThunk), this); |
+ g_signal_connect(G_OBJECT(color_selecting_dialog_), "destroy", |
+ G_CALLBACK(OnColorChooserDestroyThunk), this); |
Evan Stade
2012/02/06 21:16:25
I think you might also need to worry about delete-
keishi
2012/02/17 11:31:05
Clicking the [x] seems to call "destroy". I looked
|
+ } |
Evan Stade
2012/02/06 21:16:25
nit: \n
keishi
2012/02/17 11:31:05
Done.
|
+ GdkColor gdk_color = gfx::SkColorToGdkColor(initial_color); |
+ gtk_color_selection_set_previous_color(colorSelection(), &gdk_color); |
+ gtk_color_selection_set_current_color(colorSelection(), &gdk_color); |
+ gtk_window_present(GTK_WINDOW(color_selecting_dialog_)); |
+} |
+ |
+void ColorChooserGtk::End() { |
+ printf("> ColorChooserMac::End %p\n", this); |
Evan Stade
2012/02/06 21:16:25
remove debugging line
keishi
2012/02/17 11:31:05
Done.
|
+ if (!color_selecting_dialog_) |
+ return; |
Evan Stade
2012/02/06 21:16:25
nit: \n
keishi
2012/02/17 11:31:05
Done.
|
+ gtk_widget_destroy(color_selecting_dialog_); |
+} |
+ |
+void ColorChooserGtk::SetSelectedColor(SkColor color) { |
+ if (!color_selecting_dialog_) |
+ return; |
Evan Stade
2012/02/06 21:16:25
nit: \n
keishi
2012/02/17 11:31:05
Done.
|
+ GdkColor gdk_color = gfx::SkColorToGdkColor(color); |
+ gtk_color_selection_set_previous_color(colorSelection(), &gdk_color); |
+ gtk_color_selection_set_current_color(colorSelection(), &gdk_color); |
+} |