| Index: chrome/browser/ui/gtk/screen_capture_notification_ui_gtk.cc
|
| diff --git a/remoting/host/disconnect_window_gtk.cc b/chrome/browser/ui/gtk/screen_capture_notification_ui_gtk.cc
|
| similarity index 65%
|
| copy from remoting/host/disconnect_window_gtk.cc
|
| copy to chrome/browser/ui/gtk/screen_capture_notification_ui_gtk.cc
|
| index 3cdf58d7636cd0bf1994c10605f16f40f8aa6777..012ce25e9311d51e59daaddcb19f119dcac8ad0d 100644
|
| --- a/remoting/host/disconnect_window_gtk.cc
|
| +++ b/chrome/browser/ui/gtk/screen_capture_notification_ui_gtk.cc
|
| @@ -1,8 +1,8 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// 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.
|
|
|
| -#include "remoting/host/disconnect_window.h"
|
| +#include "chrome/browser/ui/screen_capture_notification_ui.h"
|
|
|
| #include <gtk/gtk.h>
|
| #include <math.h>
|
| @@ -11,32 +11,33 @@
|
| #include "base/logging.h"
|
| #include "base/string_util.h"
|
| #include "base/utf_string_conversions.h"
|
| -#include "remoting/host/ui_strings.h"
|
| +#include "grit/generated_resources.h"
|
| #include "ui/base/gtk/gtk_signal.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
|
|
| -namespace remoting {
|
| -
|
| -class DisconnectWindowGtk : public DisconnectWindow {
|
| +class ScreenCaptureNotificationUIGtk : public ScreenCaptureNotificationUI {
|
| public:
|
| - explicit DisconnectWindowGtk(const UiStrings* ui_strings);
|
| - virtual ~DisconnectWindowGtk();
|
| + ScreenCaptureNotificationUIGtk();
|
| + virtual ~ScreenCaptureNotificationUIGtk();
|
|
|
| - virtual bool Show(const base::Closure& disconnect_callback,
|
| - const std::string& username) OVERRIDE;
|
| - virtual void Hide() OVERRIDE;
|
| + // ScreenCaptureNotificationUI interface
|
| + virtual bool Show(const base::Closure& stop_callback,
|
| + const string16& page_title) OVERRIDE;
|
|
|
| private:
|
| - CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnDelete, GdkEvent*);
|
| - CHROMEGTK_CALLBACK_0(DisconnectWindowGtk, void, OnClicked);
|
| - CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnConfigure,
|
| + CHROMEGTK_CALLBACK_1(ScreenCaptureNotificationUIGtk, gboolean, OnDelete,
|
| + GdkEvent*);
|
| + CHROMEGTK_CALLBACK_0(ScreenCaptureNotificationUIGtk, void, OnClicked);
|
| + CHROMEGTK_CALLBACK_1(ScreenCaptureNotificationUIGtk, gboolean, OnConfigure,
|
| GdkEventConfigure*);
|
| - CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnButtonPress,
|
| + CHROMEGTK_CALLBACK_1(ScreenCaptureNotificationUIGtk, gboolean, OnButtonPress,
|
| GdkEventButton*);
|
|
|
| - void CreateWindow();
|
| + void CreateWindow(const string16& title);
|
| + void HideWindow();
|
|
|
| - base::Closure disconnect_callback_;
|
| - GtkWidget* disconnect_window_;
|
| + base::Closure stop_callback_;
|
| + GtkWidget* window_;
|
| GtkWidget* message_;
|
| GtkWidget* button_;
|
|
|
| @@ -45,33 +46,31 @@ class DisconnectWindowGtk : public DisconnectWindow {
|
| int current_width_;
|
| int current_height_;
|
|
|
| - // Points to the localized strings.
|
| - const UiStrings* ui_strings_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(DisconnectWindowGtk);
|
| + DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUIGtk);
|
| };
|
|
|
| -DisconnectWindowGtk::DisconnectWindowGtk(const UiStrings* ui_strings)
|
| - : disconnect_window_(NULL),
|
| +ScreenCaptureNotificationUIGtk::ScreenCaptureNotificationUIGtk()
|
| + : window_(NULL),
|
| current_width_(0),
|
| - current_height_(0),
|
| - ui_strings_(ui_strings) {
|
| + current_height_(0) {
|
| }
|
|
|
| -DisconnectWindowGtk::~DisconnectWindowGtk() {
|
| - Hide();
|
| +ScreenCaptureNotificationUIGtk::~ScreenCaptureNotificationUIGtk() {
|
| + HideWindow();
|
| }
|
|
|
| -void DisconnectWindowGtk::CreateWindow() {
|
| - if (disconnect_window_)
|
| +void ScreenCaptureNotificationUIGtk::CreateWindow(const string16& title) {
|
| + if (window_)
|
| return;
|
|
|
| - disconnect_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
| - GtkWindow* window = GTK_WINDOW(disconnect_window_);
|
| + window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
| + GtkWindow* window = GTK_WINDOW(window_);
|
|
|
| - g_signal_connect(disconnect_window_, "delete-event",
|
| - G_CALLBACK(OnDeleteThunk), this);
|
| - gtk_window_set_title(window, UTF16ToUTF8(ui_strings_->product_name).c_str());
|
| + g_signal_connect(window_, "delete-event", G_CALLBACK(OnDeleteThunk), this);
|
| + std::string window_title =
|
| + l10n_util::GetStringFUTF8(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_TITLE,
|
| + title);
|
| + gtk_window_set_title(window, window_title.c_str());
|
| gtk_window_set_resizable(window, FALSE);
|
|
|
| // Try to keep the window always visible.
|
| @@ -87,7 +86,7 @@ void DisconnectWindowGtk::CreateWindow() {
|
| gtk_window_set_deletable(window, FALSE);
|
|
|
| // Allow custom rendering of the background pixmap.
|
| - gtk_widget_set_app_paintable(disconnect_window_, TRUE);
|
| + gtk_widget_set_app_paintable(window_, TRUE);
|
|
|
| // Handle window resizing, to regenerate the background pixmap and window
|
| // shape bitmap. The stored width & height need to be initialized here
|
| @@ -95,12 +94,12 @@ void DisconnectWindowGtk::CreateWindow() {
|
| // window would be remembered, preventing the generation of bitmaps for the
|
| // new window).
|
| current_height_ = current_width_ = 0;
|
| - g_signal_connect(disconnect_window_, "configure-event",
|
| + g_signal_connect(window_, "configure-event",
|
| G_CALLBACK(OnConfigureThunk), this);
|
|
|
| // Handle mouse events to allow the user to drag the window around.
|
| - gtk_widget_set_events(disconnect_window_, GDK_BUTTON_PRESS_MASK);
|
| - g_signal_connect(disconnect_window_, "button-press-event",
|
| + gtk_widget_set_events(window_, GDK_BUTTON_PRESS_MASK);
|
| + g_signal_connect(window_, "button-press-event",
|
| G_CALLBACK(OnButtonPressThunk), this);
|
|
|
| // All magic numbers taken from screen shots provided by UX.
|
| @@ -114,8 +113,9 @@ void DisconnectWindowGtk::CreateWindow() {
|
| GtkWidget* button_row = gtk_hbox_new(FALSE, 12);
|
| gtk_container_add(GTK_CONTAINER(align), button_row);
|
|
|
| - button_ = gtk_button_new_with_label(
|
| - UTF16ToUTF8(ui_strings_->disconnect_button_text).c_str());
|
| + std::string button_label =
|
| + l10n_util::GetStringUTF8(IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP);
|
| + button_ = gtk_button_new_with_label(button_label.c_str());
|
| gtk_box_pack_end(GTK_BOX(button_row), button_, FALSE, FALSE, 0);
|
|
|
| g_signal_connect(button_, "clicked", G_CALLBACK(OnClickedThunk), this);
|
| @@ -130,42 +130,44 @@ void DisconnectWindowGtk::CreateWindow() {
|
| pango_attr_list_insert(attributes, text_color);
|
| gtk_label_set_attributes(GTK_LABEL(message_), attributes);
|
|
|
| - gtk_widget_show_all(disconnect_window_);
|
| + std::string text = l10n_util::GetStringFUTF8(
|
| + IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_TEXT, title);
|
| + gtk_label_set_text(GTK_LABEL(message_), text.c_str());
|
| +
|
| + gtk_widget_show_all(window_);
|
| + gtk_window_present(GTK_WINDOW(window_));
|
| }
|
|
|
| -bool DisconnectWindowGtk::Show(const base::Closure& disconnect_callback,
|
| - const std::string& username) {
|
| - DCHECK(disconnect_callback_.is_null());
|
| - DCHECK(!disconnect_callback.is_null());
|
| - DCHECK(!disconnect_window_);
|
| +bool ScreenCaptureNotificationUIGtk::Show(const base::Closure& stop_callback,
|
| + const string16& title) {
|
| + DCHECK(stop_callback_.is_null());
|
| + DCHECK(!stop_callback.is_null());
|
| + DCHECK(!window_);
|
|
|
| - disconnect_callback_ = disconnect_callback;
|
| - CreateWindow();
|
| + stop_callback_ = stop_callback;
|
| + CreateWindow(title);
|
|
|
| - string16 text = ReplaceStringPlaceholders(
|
| - ui_strings_->disconnect_message, UTF8ToUTF16(username), NULL);
|
| - gtk_label_set_text(GTK_LABEL(message_), UTF16ToUTF8(text).c_str());
|
| - gtk_window_present(GTK_WINDOW(disconnect_window_));
|
| return true;
|
| }
|
|
|
| -void DisconnectWindowGtk::Hide() {
|
| - if (disconnect_window_) {
|
| - gtk_widget_destroy(disconnect_window_);
|
| - disconnect_window_ = NULL;
|
| +void ScreenCaptureNotificationUIGtk::HideWindow() {
|
| + if (window_) {
|
| + gtk_widget_destroy(window_);
|
| + window_ = NULL;
|
| }
|
|
|
| - disconnect_callback_.Reset();
|
| + stop_callback_.Reset();
|
| }
|
|
|
| -void DisconnectWindowGtk::OnClicked(GtkWidget* button) {
|
| - disconnect_callback_.Run();
|
| - Hide();
|
| +void ScreenCaptureNotificationUIGtk::OnClicked(GtkWidget* button) {
|
| + stop_callback_.Run();
|
| + HideWindow();
|
| }
|
|
|
| -gboolean DisconnectWindowGtk::OnDelete(GtkWidget* window, GdkEvent* event) {
|
| - disconnect_callback_.Run();
|
| - Hide();
|
| +gboolean ScreenCaptureNotificationUIGtk::OnDelete(
|
| + GtkWidget* window, GdkEvent* event) {
|
| + stop_callback_.Run();
|
| + HideWindow();
|
|
|
| return TRUE;
|
| }
|
| @@ -186,8 +188,8 @@ void AddRoundRectPath(cairo_t* cairo_context, int width, int height,
|
|
|
| } // namespace
|
|
|
| -gboolean DisconnectWindowGtk::OnConfigure(GtkWidget* widget,
|
| - GdkEventConfigure* event) {
|
| +gboolean ScreenCaptureNotificationUIGtk::OnConfigure(GtkWidget* widget,
|
| + GdkEventConfigure* event) {
|
| // Only generate bitmaps if the size has actually changed.
|
| if (event->width == current_width_ && event->height == current_height_)
|
| return FALSE;
|
| @@ -196,8 +198,8 @@ gboolean DisconnectWindowGtk::OnConfigure(GtkWidget* widget,
|
| current_height_ = event->height;
|
|
|
| // Create the depth 1 pixmap for the window shape.
|
| - GdkPixmap* shape_mask = gdk_pixmap_new(NULL, current_width_, current_height_,
|
| - 1);
|
| + GdkPixmap* shape_mask =
|
| + gdk_pixmap_new(NULL, current_width_, current_height_, 1);
|
| cairo_t* cairo_context = gdk_cairo_create(shape_mask);
|
|
|
| // Set the arc radius for the corners.
|
| @@ -221,8 +223,8 @@ gboolean DisconnectWindowGtk::OnConfigure(GtkWidget* widget,
|
| g_object_unref(shape_mask);
|
|
|
| // Create a full-color pixmap for the window background image.
|
| - GdkPixmap* background = gdk_pixmap_new(NULL, current_width_, current_height_,
|
| - 24);
|
| + GdkPixmap* background =
|
| + gdk_pixmap_new(NULL, current_width_, current_height_, 24);
|
| cairo_context = gdk_cairo_create(background);
|
|
|
| // Paint the whole bitmap one color.
|
| @@ -272,9 +274,9 @@ gboolean DisconnectWindowGtk::OnConfigure(GtkWidget* widget,
|
| return FALSE;
|
| }
|
|
|
| -gboolean DisconnectWindowGtk::OnButtonPress(GtkWidget* widget,
|
| +gboolean ScreenCaptureNotificationUIGtk::OnButtonPress(GtkWidget* widget,
|
| GdkEventButton* event) {
|
| - gtk_window_begin_move_drag(GTK_WINDOW(disconnect_window_),
|
| + gtk_window_begin_move_drag(GTK_WINDOW(window_),
|
| event->button,
|
| event->x_root,
|
| event->y_root,
|
| @@ -282,9 +284,7 @@ gboolean DisconnectWindowGtk::OnButtonPress(GtkWidget* widget,
|
| return FALSE;
|
| }
|
|
|
| -scoped_ptr<DisconnectWindow> DisconnectWindow::Create(
|
| - const UiStrings* ui_strings) {
|
| - return scoped_ptr<DisconnectWindow>(new DisconnectWindowGtk(ui_strings));
|
| +scoped_ptr<ScreenCaptureNotificationUI> ScreenCaptureNotificationUI::Create() {
|
| + return scoped_ptr<ScreenCaptureNotificationUI>(
|
| + new ScreenCaptureNotificationUIGtk());
|
| }
|
| -
|
| -} // namespace remoting
|
|
|