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

Side by Side Diff: remoting/host/disconnect_window_gtk.cc

Issue 11886051: Turned UiStrings into a singleton so that the continue window does not depend on ChromotingHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/disconnect_window.h" 5 #include "remoting/host/disconnect_window.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <math.h> 8 #include <math.h>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "remoting/host/ui_strings.h" 14 #include "remoting/host/ui_strings.h"
15 #include "ui/base/gtk/gtk_signal.h" 15 #include "ui/base/gtk/gtk_signal.h"
16 16
17 namespace remoting { 17 namespace remoting {
18 18
19 class DisconnectWindowGtk : public DisconnectWindow { 19 class DisconnectWindowGtk : public DisconnectWindow {
20 public: 20 public:
21 DisconnectWindowGtk(); 21 explicit DisconnectWindowGtk(const UiStrings* ui_strings);
22 virtual ~DisconnectWindowGtk(); 22 virtual ~DisconnectWindowGtk();
23 23
24 virtual bool Show(const UiStrings& ui_strings, 24 virtual bool Show(const base::Closure& disconnect_callback,
25 const base::Closure& disconnect_callback,
26 const std::string& username) OVERRIDE; 25 const std::string& username) OVERRIDE;
27 virtual void Hide() OVERRIDE; 26 virtual void Hide() OVERRIDE;
28 27
29 private: 28 private:
30 CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnDelete, GdkEvent*); 29 CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnDelete, GdkEvent*);
31 CHROMEGTK_CALLBACK_0(DisconnectWindowGtk, void, OnClicked); 30 CHROMEGTK_CALLBACK_0(DisconnectWindowGtk, void, OnClicked);
32 CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnConfigure, 31 CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnConfigure,
33 GdkEventConfigure*); 32 GdkEventConfigure*);
34 CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnButtonPress, 33 CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnButtonPress,
35 GdkEventButton*); 34 GdkEventButton*);
36 35
37 void CreateWindow(const UiStrings& ui_strings); 36 void CreateWindow();
38 37
39 base::Closure disconnect_callback_; 38 base::Closure disconnect_callback_;
40 GtkWidget* disconnect_window_; 39 GtkWidget* disconnect_window_;
41 GtkWidget* message_; 40 GtkWidget* message_;
42 GtkWidget* button_; 41 GtkWidget* button_;
43 42
44 // Used to distinguish resize events from other types of "configure-event" 43 // Used to distinguish resize events from other types of "configure-event"
45 // notifications. 44 // notifications.
46 int current_width_; 45 int current_width_;
47 int current_height_; 46 int current_height_;
48 47
48 // Points to the localized strings.
49 const UiStrings* ui_strings_;
50
49 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowGtk); 51 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowGtk);
50 }; 52 };
51 53
52 DisconnectWindowGtk::DisconnectWindowGtk() 54 DisconnectWindowGtk::DisconnectWindowGtk(const UiStrings* ui_strings)
53 : disconnect_window_(NULL), 55 : disconnect_window_(NULL),
54 current_width_(0), 56 current_width_(0),
55 current_height_(0) { 57 current_height_(0),
58 ui_strings_(ui_strings) {
56 } 59 }
57 60
58 DisconnectWindowGtk::~DisconnectWindowGtk() { 61 DisconnectWindowGtk::~DisconnectWindowGtk() {
59 Hide(); 62 Hide();
60 } 63 }
61 64
62 void DisconnectWindowGtk::CreateWindow(const UiStrings& ui_strings) { 65 void DisconnectWindowGtk::CreateWindow() {
63 if (disconnect_window_) return; 66 if (disconnect_window_)
67 return;
64 68
65 disconnect_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); 69 disconnect_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
66 GtkWindow* window = GTK_WINDOW(disconnect_window_); 70 GtkWindow* window = GTK_WINDOW(disconnect_window_);
67 71
68 g_signal_connect(disconnect_window_, "delete-event", 72 g_signal_connect(disconnect_window_, "delete-event",
69 G_CALLBACK(OnDeleteThunk), this); 73 G_CALLBACK(OnDeleteThunk), this);
70 gtk_window_set_title(window, UTF16ToUTF8(ui_strings.product_name).c_str()); 74 gtk_window_set_title(window, UTF16ToUTF8(ui_strings_->product_name).c_str());
71 gtk_window_set_resizable(window, FALSE); 75 gtk_window_set_resizable(window, FALSE);
72 76
73 // Try to keep the window always visible. 77 // Try to keep the window always visible.
74 gtk_window_stick(window); 78 gtk_window_stick(window);
75 gtk_window_set_keep_above(window, TRUE); 79 gtk_window_set_keep_above(window, TRUE);
76 80
77 // Remove window titlebar. 81 // Remove window titlebar.
78 gtk_window_set_decorated(window, FALSE); 82 gtk_window_set_decorated(window, FALSE);
79 83
80 // In case the titlebar is still there, try to remove some of the buttons. 84 // In case the titlebar is still there, try to remove some of the buttons.
(...skipping 23 matching lines...) Expand all
104 // left and right. The left margin is made larger to accommodate the 108 // left and right. The left margin is made larger to accommodate the
105 // window movement gripper. 109 // window movement gripper.
106 GtkWidget* align = gtk_alignment_new(0, 0, 1, 1); 110 GtkWidget* align = gtk_alignment_new(0, 0, 1, 1);
107 gtk_alignment_set_padding(GTK_ALIGNMENT(align), 8, 8, 24, 12); 111 gtk_alignment_set_padding(GTK_ALIGNMENT(align), 8, 8, 24, 12);
108 gtk_container_add(GTK_CONTAINER(window), align); 112 gtk_container_add(GTK_CONTAINER(window), align);
109 113
110 GtkWidget* button_row = gtk_hbox_new(FALSE, 12); 114 GtkWidget* button_row = gtk_hbox_new(FALSE, 12);
111 gtk_container_add(GTK_CONTAINER(align), button_row); 115 gtk_container_add(GTK_CONTAINER(align), button_row);
112 116
113 button_ = gtk_button_new_with_label( 117 button_ = gtk_button_new_with_label(
114 UTF16ToUTF8(ui_strings.disconnect_button_text).c_str()); 118 UTF16ToUTF8(ui_strings_->disconnect_button_text).c_str());
115 gtk_box_pack_end(GTK_BOX(button_row), button_, FALSE, FALSE, 0); 119 gtk_box_pack_end(GTK_BOX(button_row), button_, FALSE, FALSE, 0);
116 120
117 g_signal_connect(button_, "clicked", G_CALLBACK(OnClickedThunk), this); 121 g_signal_connect(button_, "clicked", G_CALLBACK(OnClickedThunk), this);
118 122
119 message_ = gtk_label_new(NULL); 123 message_ = gtk_label_new(NULL);
120 gtk_box_pack_end(GTK_BOX(button_row), message_, FALSE, FALSE, 0); 124 gtk_box_pack_end(GTK_BOX(button_row), message_, FALSE, FALSE, 0);
121 125
122 // Override any theme setting for the text color, so that the text is 126 // Override any theme setting for the text color, so that the text is
123 // readable against the window's background pixmap. 127 // readable against the window's background pixmap.
124 PangoAttrList* attributes = pango_attr_list_new(); 128 PangoAttrList* attributes = pango_attr_list_new();
125 PangoAttribute* text_color = pango_attr_foreground_new(0, 0, 0); 129 PangoAttribute* text_color = pango_attr_foreground_new(0, 0, 0);
126 pango_attr_list_insert(attributes, text_color); 130 pango_attr_list_insert(attributes, text_color);
127 gtk_label_set_attributes(GTK_LABEL(message_), attributes); 131 gtk_label_set_attributes(GTK_LABEL(message_), attributes);
128 132
129 gtk_widget_show_all(disconnect_window_); 133 gtk_widget_show_all(disconnect_window_);
130 } 134 }
131 135
132 bool DisconnectWindowGtk::Show(const UiStrings& ui_strings, 136 bool DisconnectWindowGtk::Show(const base::Closure& disconnect_callback,
133 const base::Closure& disconnect_callback,
134 const std::string& username) { 137 const std::string& username) {
135 DCHECK(disconnect_callback_.is_null()); 138 DCHECK(disconnect_callback_.is_null());
136 DCHECK(!disconnect_callback.is_null()); 139 DCHECK(!disconnect_callback.is_null());
137 DCHECK(!disconnect_window_); 140 DCHECK(!disconnect_window_);
138 141
139 disconnect_callback_ = disconnect_callback; 142 disconnect_callback_ = disconnect_callback;
140 CreateWindow(ui_strings); 143 CreateWindow();
141 144
142 string16 text = ReplaceStringPlaceholders( 145 string16 text = ReplaceStringPlaceholders(
143 ui_strings.disconnect_message, UTF8ToUTF16(username), NULL); 146 ui_strings_->disconnect_message, UTF8ToUTF16(username), NULL);
144 gtk_label_set_text(GTK_LABEL(message_), UTF16ToUTF8(text).c_str()); 147 gtk_label_set_text(GTK_LABEL(message_), UTF16ToUTF8(text).c_str());
145 gtk_window_present(GTK_WINDOW(disconnect_window_)); 148 gtk_window_present(GTK_WINDOW(disconnect_window_));
146 return true; 149 return true;
147 } 150 }
148 151
149 void DisconnectWindowGtk::Hide() { 152 void DisconnectWindowGtk::Hide() {
150 if (disconnect_window_) { 153 if (disconnect_window_) {
151 gtk_widget_destroy(disconnect_window_); 154 gtk_widget_destroy(disconnect_window_);
152 disconnect_window_ = NULL; 155 disconnect_window_ = NULL;
153 } 156 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 gboolean DisconnectWindowGtk::OnButtonPress(GtkWidget* widget, 275 gboolean DisconnectWindowGtk::OnButtonPress(GtkWidget* widget,
273 GdkEventButton* event) { 276 GdkEventButton* event) {
274 gtk_window_begin_move_drag(GTK_WINDOW(disconnect_window_), 277 gtk_window_begin_move_drag(GTK_WINDOW(disconnect_window_),
275 event->button, 278 event->button,
276 event->x_root, 279 event->x_root,
277 event->y_root, 280 event->y_root,
278 event->time); 281 event->time);
279 return FALSE; 282 return FALSE;
280 } 283 }
281 284
282 scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { 285 scoped_ptr<DisconnectWindow> DisconnectWindow::Create(
283 return scoped_ptr<DisconnectWindow>(new DisconnectWindowGtk()); 286 const UiStrings* ui_strings) {
287 return scoped_ptr<DisconnectWindow>(new DisconnectWindowGtk(ui_strings));
284 } 288 }
285 289
286 } // namespace remoting 290 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698