Chromium Code Reviews| 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..fddb39c091947b0f397bfeefabeb23b783e2e8f6 |
| --- /dev/null |
| +++ b/chrome/browser/ui/gtk/color_chooser_gtk.cc |
| @@ -0,0 +1,129 @@ |
| +// 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 "content/public/browser/render_view_host_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 ColorChooser, |
| + public content::RenderViewHostObserver { |
| + public: |
| + ColorChooserGtk( |
| + int identifier, RenderViewHost* rvh, SkColor initial_color); |
| + virtual ~ColorChooserGtk(); |
| + |
| + virtual void End() OVERRIDE; |
| + virtual void SetSelectedColor(SkColor color) OVERRIDE; |
| + |
| + virtual RenderViewHost* render_view_host() const OVERRIDE; |
| + virtual int identifier() const OVERRIDE { return identifier_; } |
| + |
| + private: |
| + virtual void RenderViewHostDestroyed( |
| + RenderViewHost* render_view_host) OVERRIDE; |
| + |
| + GtkColorSelection* ColorSelection(); |
|
Evan Stade
2012/02/21 20:16:54
docs
keishi
2012/02/24 14:38:54
Done.
|
| + |
| + CHROMEGTK_CALLBACK_0(ColorChooserGtk, void, OnColorChooserOk); |
| + CHROMEGTK_CALLBACK_0(ColorChooserGtk, void, OnColorChooserCancel); |
| + CHROMEGTK_CALLBACK_0(ColorChooserGtk, void, OnColorChooserDestroy); |
| + |
| + int identifier_; |
|
Evan Stade
2012/02/21 20:16:54
docs
keishi
2012/02/24 14:38:54
Done.
|
| + GtkWidget* color_selection_dialog_; |
| + bool is_render_view_host_being_destroyed; |
|
Evan Stade
2012/02/21 20:16:54
docs
keishi
2012/02/24 14:38:54
This was left over code. Removed.
|
| +}; |
| + |
| +ColorChooser* ColorChooser::Create( |
| + int identifier, RenderViewHost* rvh, SkColor initial_color) { |
| + return new ColorChooserGtk(identifier, rvh, initial_color); |
| +} |
| + |
| +ColorChooserGtk::ColorChooserGtk( |
| + int identifier, RenderViewHost* rvh, SkColor initial_color) |
| + : content::RenderViewHostObserver(rvh), |
| + identifier_(identifier), |
| + color_selection_dialog_(NULL) { |
| + if (!color_selection_dialog_) { |
| + color_selection_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_selection_dialog_)->ok_button), |
| + "clicked", G_CALLBACK(OnColorChooserOkThunk), this); |
| + g_signal_connect(G_OBJECT( |
| + GTK_COLOR_SELECTION_DIALOG(color_selection_dialog_)->cancel_button), |
| + "clicked", G_CALLBACK(OnColorChooserCancelThunk), this); |
| + g_signal_connect(G_OBJECT(color_selection_dialog_), "destroy", |
| + G_CALLBACK(OnColorChooserDestroyThunk), this); |
| + } |
| + |
| + 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_selection_dialog_)); |
| +} |
| + |
| +ColorChooserGtk::~ColorChooserGtk() { |
| + if (color_selection_dialog_) |
| + gtk_widget_destroy(color_selection_dialog_); |
| +} |
| + |
| +GtkColorSelection* ColorChooserGtk::ColorSelection() { |
| + if (!color_selection_dialog_) |
| + return NULL; |
| + |
| + return GTK_COLOR_SELECTION( |
| + GTK_COLOR_SELECTION_DIALOG(color_selection_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_selection_dialog_); |
| +} |
| + |
| +void ColorChooserGtk::OnColorChooserCancel(GtkWidget* widget) { |
| + gtk_widget_destroy(color_selection_dialog_); |
| +} |
| + |
| +void ColorChooserGtk::OnColorChooserDestroy(GtkWidget* widget) { |
| + color_selection_dialog_ = NULL; |
| + if (render_view_host()) |
| + render_view_host()->DidEndColorChooser(identifier_); |
| +} |
| + |
| +void ColorChooserGtk::End() { |
| + if (!color_selection_dialog_) |
| + return; |
| + |
| + gtk_widget_destroy(color_selection_dialog_); |
| +} |
| + |
| +void ColorChooserGtk::SetSelectedColor(SkColor color) { |
| + if (!color_selection_dialog_) |
| + return; |
| + |
| + GdkColor gdk_color = gfx::SkColorToGdkColor(color); |
| + gtk_color_selection_set_previous_color(ColorSelection(), &gdk_color); |
| + gtk_color_selection_set_current_color(ColorSelection(), &gdk_color); |
| +} |
| + |
| +RenderViewHost* ColorChooserGtk::render_view_host() const { |
| + return content::RenderViewHostObserver::render_view_host(); |
|
Evan Stade
2012/02/21 20:16:54
too much indent
keishi
2012/02/24 14:38:54
Done.
|
| +} |
| + |
| +void ColorChooserGtk::RenderViewHostDestroyed( |
| + RenderViewHost* render_view_host) { |
| + if (color_selection_dialog_) |
| + gtk_widget_destroy(color_selection_dialog_); |
| +} |