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

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

Issue 10386181: Fix remoting_unittests compilation with aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/continue_window_linux.cc ('k') | remoting/host/disconnect_window_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/chromoting_host.h" 14 #include "remoting/host/chromoting_host.h"
15 #include "remoting/host/ui_strings.h" 15 #include "remoting/host/ui_strings.h"
16 #include "ui/base/gtk/gtk_signal.h" 16 #include "ui/base/gtk/gtk_signal.h"
17 17
18 namespace remoting { 18 namespace remoting {
19 19
20 class DisconnectWindowLinux : public DisconnectWindow { 20 class DisconnectWindowGtk : public DisconnectWindow {
21 public: 21 public:
22 DisconnectWindowLinux(); 22 DisconnectWindowGtk();
23 virtual ~DisconnectWindowLinux(); 23 virtual ~DisconnectWindowGtk();
24 24
25 virtual void Show(ChromotingHost* host, 25 virtual void Show(ChromotingHost* host,
26 const DisconnectCallback& disconnect_callback, 26 const DisconnectCallback& disconnect_callback,
27 const std::string& username) OVERRIDE; 27 const std::string& username) OVERRIDE;
28 virtual void Hide() OVERRIDE; 28 virtual void Hide() OVERRIDE;
29 29
30 private: 30 private:
31 CHROMEGTK_CALLBACK_1(DisconnectWindowLinux, gboolean, OnDelete, GdkEvent*); 31 CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnDelete, GdkEvent*);
32 CHROMEGTK_CALLBACK_0(DisconnectWindowLinux, void, OnClicked); 32 CHROMEGTK_CALLBACK_0(DisconnectWindowGtk, void, OnClicked);
33 CHROMEGTK_CALLBACK_1(DisconnectWindowLinux, gboolean, OnConfigure, 33 CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnConfigure,
34 GdkEventConfigure*); 34 GdkEventConfigure*);
35 CHROMEGTK_CALLBACK_1(DisconnectWindowLinux, gboolean, OnButtonPress, 35 CHROMEGTK_CALLBACK_1(DisconnectWindowGtk, gboolean, OnButtonPress,
36 GdkEventButton*); 36 GdkEventButton*);
37 37
38 void CreateWindow(const UiStrings& ui_strings); 38 void CreateWindow(const UiStrings& ui_strings);
39 39
40 DisconnectCallback disconnect_callback_; 40 DisconnectCallback disconnect_callback_;
41 GtkWidget* disconnect_window_; 41 GtkWidget* disconnect_window_;
42 GtkWidget* message_; 42 GtkWidget* message_;
43 GtkWidget* button_; 43 GtkWidget* button_;
44 44
45 // Used to distinguish resize events from other types of "configure-event" 45 // Used to distinguish resize events from other types of "configure-event"
46 // notifications. 46 // notifications.
47 int current_width_; 47 int current_width_;
48 int current_height_; 48 int current_height_;
49 49
50 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowLinux); 50 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowGtk);
51 }; 51 };
52 52
53 DisconnectWindowLinux::DisconnectWindowLinux() 53 DisconnectWindowGtk::DisconnectWindowGtk()
54 : disconnect_window_(NULL), 54 : disconnect_window_(NULL),
55 current_width_(0), 55 current_width_(0),
56 current_height_(0) { 56 current_height_(0) {
57 } 57 }
58 58
59 DisconnectWindowLinux::~DisconnectWindowLinux() { 59 DisconnectWindowGtk::~DisconnectWindowGtk() {
60 } 60 }
61 61
62 void DisconnectWindowLinux::CreateWindow(const UiStrings& ui_strings) { 62 void DisconnectWindowGtk::CreateWindow(const UiStrings& ui_strings) {
63 if (disconnect_window_) return; 63 if (disconnect_window_) return;
64 64
65 disconnect_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); 65 disconnect_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
66 GtkWindow* window = GTK_WINDOW(disconnect_window_); 66 GtkWindow* window = GTK_WINDOW(disconnect_window_);
67 67
68 g_signal_connect(disconnect_window_, "delete-event", 68 g_signal_connect(disconnect_window_, "delete-event",
69 G_CALLBACK(OnDeleteThunk), this); 69 G_CALLBACK(OnDeleteThunk), this);
70 gtk_window_set_title(window, UTF16ToUTF8(ui_strings.product_name).c_str()); 70 gtk_window_set_title(window, UTF16ToUTF8(ui_strings.product_name).c_str());
71 gtk_window_set_resizable(window, FALSE); 71 gtk_window_set_resizable(window, FALSE);
72 72
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Override any theme setting for the text color, so that the text is 122 // Override any theme setting for the text color, so that the text is
123 // readable against the window's background pixmap. 123 // readable against the window's background pixmap.
124 PangoAttrList* attributes = pango_attr_list_new(); 124 PangoAttrList* attributes = pango_attr_list_new();
125 PangoAttribute* text_color = pango_attr_foreground_new(0, 0, 0); 125 PangoAttribute* text_color = pango_attr_foreground_new(0, 0, 0);
126 pango_attr_list_insert(attributes, text_color); 126 pango_attr_list_insert(attributes, text_color);
127 gtk_label_set_attributes(GTK_LABEL(message_), attributes); 127 gtk_label_set_attributes(GTK_LABEL(message_), attributes);
128 128
129 gtk_widget_show_all(disconnect_window_); 129 gtk_widget_show_all(disconnect_window_);
130 } 130 }
131 131
132 void DisconnectWindowLinux::Show(ChromotingHost* host, 132 void DisconnectWindowGtk::Show(ChromotingHost* host,
133 const DisconnectCallback& disconnect_callback, 133 const DisconnectCallback& disconnect_callback,
134 const std::string& username) { 134 const std::string& username) {
135 disconnect_callback_ = disconnect_callback; 135 disconnect_callback_ = disconnect_callback;
136 CreateWindow(host->ui_strings()); 136 CreateWindow(host->ui_strings());
137 137
138 string16 text = ReplaceStringPlaceholders( 138 string16 text = ReplaceStringPlaceholders(
139 host->ui_strings().disconnect_message, UTF8ToUTF16(username), NULL); 139 host->ui_strings().disconnect_message, UTF8ToUTF16(username), NULL);
140 gtk_label_set_text(GTK_LABEL(message_), UTF16ToUTF8(text).c_str()); 140 gtk_label_set_text(GTK_LABEL(message_), UTF16ToUTF8(text).c_str());
141 gtk_window_present(GTK_WINDOW(disconnect_window_)); 141 gtk_window_present(GTK_WINDOW(disconnect_window_));
142 } 142 }
143 143
144 void DisconnectWindowLinux::Hide() { 144 void DisconnectWindowGtk::Hide() {
145 if (disconnect_window_) { 145 if (disconnect_window_) {
146 gtk_widget_destroy(disconnect_window_); 146 gtk_widget_destroy(disconnect_window_);
147 disconnect_window_ = NULL; 147 disconnect_window_ = NULL;
148 } 148 }
149 } 149 }
150 150
151 void DisconnectWindowLinux::OnClicked(GtkWidget* button) { 151 void DisconnectWindowGtk::OnClicked(GtkWidget* button) {
152 CHECK(!disconnect_callback_.is_null()); 152 CHECK(!disconnect_callback_.is_null());
153 153
154 disconnect_callback_.Run(); 154 disconnect_callback_.Run();
155 Hide(); 155 Hide();
156 } 156 }
157 157
158 gboolean DisconnectWindowLinux::OnDelete(GtkWidget* window, GdkEvent* event) { 158 gboolean DisconnectWindowGtk::OnDelete(GtkWidget* window, GdkEvent* event) {
159 CHECK(!disconnect_callback_.is_null()); 159 CHECK(!disconnect_callback_.is_null());
160 160
161 disconnect_callback_.Run(); 161 disconnect_callback_.Run();
162 Hide(); 162 Hide();
163 163
164 return TRUE; 164 return TRUE;
165 } 165 }
166 166
167 namespace { 167 namespace {
168 // Helper function for creating a rectangular path with rounded corners, as 168 // Helper function for creating a rectangular path with rounded corners, as
169 // Cairo doesn't have this facility. |radius| is the arc-radius of each 169 // Cairo doesn't have this facility. |radius| is the arc-radius of each
170 // corner. The bounding rectangle extends from (0, 0) to (width, height). 170 // corner. The bounding rectangle extends from (0, 0) to (width, height).
171 void AddRoundRectPath(cairo_t* cairo_context, int width, int height, 171 void AddRoundRectPath(cairo_t* cairo_context, int width, int height,
172 int radius) { 172 int radius) {
173 cairo_new_sub_path(cairo_context); 173 cairo_new_sub_path(cairo_context);
174 cairo_arc(cairo_context, width - radius, radius, radius, -M_PI_2, 0); 174 cairo_arc(cairo_context, width - radius, radius, radius, -M_PI_2, 0);
175 cairo_arc(cairo_context, width - radius, height - radius, radius, 0, M_PI_2); 175 cairo_arc(cairo_context, width - radius, height - radius, radius, 0, M_PI_2);
176 cairo_arc(cairo_context, radius, height - radius, radius, M_PI_2, 2 * M_PI_2); 176 cairo_arc(cairo_context, radius, height - radius, radius, M_PI_2, 2 * M_PI_2);
177 cairo_arc(cairo_context, radius, radius, radius, 2 * M_PI_2, 3 * M_PI_2); 177 cairo_arc(cairo_context, radius, radius, radius, 2 * M_PI_2, 3 * M_PI_2);
178 cairo_close_path(cairo_context); 178 cairo_close_path(cairo_context);
179 } 179 }
180 180
181 } // namespace 181 } // namespace
182 182
183 gboolean DisconnectWindowLinux::OnConfigure(GtkWidget* widget, 183 gboolean DisconnectWindowGtk::OnConfigure(GtkWidget* widget,
184 GdkEventConfigure* event) { 184 GdkEventConfigure* event) {
185 // Only generate bitmaps if the size has actually changed. 185 // Only generate bitmaps if the size has actually changed.
186 if (event->width == current_width_ && event->height == current_height_) 186 if (event->width == current_width_ && event->height == current_height_)
187 return FALSE; 187 return FALSE;
188 188
189 current_width_ = event->width; 189 current_width_ = event->width;
190 current_height_ = event->height; 190 current_height_ = event->height;
191 191
192 // Create the depth 1 pixmap for the window shape. 192 // Create the depth 1 pixmap for the window shape.
193 GdkPixmap* shape_mask = gdk_pixmap_new(NULL, current_width_, current_height_, 193 GdkPixmap* shape_mask = gdk_pixmap_new(NULL, current_width_, current_height_,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 259
260 cairo_destroy(cairo_context); 260 cairo_destroy(cairo_context);
261 261
262 gdk_window_set_back_pixmap(widget->window, background, FALSE); 262 gdk_window_set_back_pixmap(widget->window, background, FALSE);
263 g_object_unref(background); 263 g_object_unref(background);
264 gdk_window_invalidate_rect(widget->window, NULL, TRUE); 264 gdk_window_invalidate_rect(widget->window, NULL, TRUE);
265 265
266 return FALSE; 266 return FALSE;
267 } 267 }
268 268
269 gboolean DisconnectWindowLinux::OnButtonPress(GtkWidget* widget, 269 gboolean DisconnectWindowGtk::OnButtonPress(GtkWidget* widget,
270 GdkEventButton* event) { 270 GdkEventButton* event) {
271 gtk_window_begin_move_drag(GTK_WINDOW(disconnect_window_), 271 gtk_window_begin_move_drag(GTK_WINDOW(disconnect_window_),
272 event->button, 272 event->button,
273 event->x_root, 273 event->x_root,
274 event->y_root, 274 event->y_root,
275 event->time); 275 event->time);
276 return FALSE; 276 return FALSE;
277 } 277 }
278 278
279 scoped_ptr<DisconnectWindow> DisconnectWindow::Create() { 279 scoped_ptr<DisconnectWindow> DisconnectWindow::Create() {
280 return scoped_ptr<DisconnectWindow>(new DisconnectWindowLinux()); 280 return scoped_ptr<DisconnectWindow>(new DisconnectWindowGtk());
281 } 281 }
282 282
283 } // namespace remoting 283 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/continue_window_linux.cc ('k') | remoting/host/disconnect_window_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698