OLD | NEW |
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 <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
6 #include <math.h> | 6 #include <math.h> |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 int radius) { | 59 int radius) { |
60 cairo_new_sub_path(cairo_context); | 60 cairo_new_sub_path(cairo_context); |
61 cairo_arc(cairo_context, width - radius, radius, radius, -M_PI_2, 0); | 61 cairo_arc(cairo_context, width - radius, radius, radius, -M_PI_2, 0); |
62 cairo_arc(cairo_context, width - radius, height - radius, radius, 0, M_PI_2); | 62 cairo_arc(cairo_context, width - radius, height - radius, radius, 0, M_PI_2); |
63 cairo_arc(cairo_context, radius, height - radius, radius, M_PI_2, 2 * M_PI_2); | 63 cairo_arc(cairo_context, radius, height - radius, radius, M_PI_2, 2 * M_PI_2); |
64 cairo_arc(cairo_context, radius, radius, radius, 2 * M_PI_2, 3 * M_PI_2); | 64 cairo_arc(cairo_context, radius, radius, radius, 2 * M_PI_2, 3 * M_PI_2); |
65 cairo_close_path(cairo_context); | 65 cairo_close_path(cairo_context); |
66 } | 66 } |
67 | 67 |
68 DisconnectWindowGtk::DisconnectWindowGtk() | 68 DisconnectWindowGtk::DisconnectWindowGtk() |
69 : disconnect_window_(NULL), | 69 : disconnect_window_(nullptr), |
70 current_width_(0), | 70 current_width_(0), |
71 current_height_(0) { | 71 current_height_(0) { |
72 } | 72 } |
73 | 73 |
74 DisconnectWindowGtk::~DisconnectWindowGtk() { | 74 DisconnectWindowGtk::~DisconnectWindowGtk() { |
75 DCHECK(CalledOnValidThread()); | 75 DCHECK(CalledOnValidThread()); |
76 | 76 |
77 if (disconnect_window_) { | 77 if (disconnect_window_) { |
78 gtk_widget_destroy(disconnect_window_); | 78 gtk_widget_destroy(disconnect_window_); |
79 disconnect_window_ = NULL; | 79 disconnect_window_ = nullptr; |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 void DisconnectWindowGtk::Start( | 83 void DisconnectWindowGtk::Start( |
84 const base::WeakPtr<ClientSessionControl>& client_session_control) { | 84 const base::WeakPtr<ClientSessionControl>& client_session_control) { |
85 DCHECK(CalledOnValidThread()); | 85 DCHECK(CalledOnValidThread()); |
86 DCHECK(!client_session_control_.get()); | 86 DCHECK(!client_session_control_.get()); |
87 DCHECK(client_session_control.get()); | 87 DCHECK(client_session_control.get()); |
88 DCHECK(!disconnect_window_); | 88 DCHECK(!disconnect_window_); |
89 | 89 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 GtkWidget* button_row = gtk_hbox_new(FALSE, 12); | 139 GtkWidget* button_row = gtk_hbox_new(FALSE, 12); |
140 gtk_container_add(GTK_CONTAINER(align), button_row); | 140 gtk_container_add(GTK_CONTAINER(align), button_row); |
141 | 141 |
142 button_ = gtk_button_new_with_label( | 142 button_ = gtk_button_new_with_label( |
143 l10n_util::GetStringUTF8(IDS_STOP_SHARING_BUTTON).c_str()); | 143 l10n_util::GetStringUTF8(IDS_STOP_SHARING_BUTTON).c_str()); |
144 gtk_box_pack_end(GTK_BOX(button_row), button_, FALSE, FALSE, 0); | 144 gtk_box_pack_end(GTK_BOX(button_row), button_, FALSE, FALSE, 0); |
145 | 145 |
146 g_signal_connect(button_, "clicked", G_CALLBACK(OnClickedThunk), this); | 146 g_signal_connect(button_, "clicked", G_CALLBACK(OnClickedThunk), this); |
147 | 147 |
148 message_ = gtk_label_new(NULL); | 148 message_ = gtk_label_new(nullptr); |
149 gtk_box_pack_end(GTK_BOX(button_row), message_, FALSE, FALSE, 0); | 149 gtk_box_pack_end(GTK_BOX(button_row), message_, FALSE, FALSE, 0); |
150 | 150 |
151 // Override any theme setting for the text color, so that the text is | 151 // Override any theme setting for the text color, so that the text is |
152 // readable against the window's background pixmap. | 152 // readable against the window's background pixmap. |
153 PangoAttrList* attributes = pango_attr_list_new(); | 153 PangoAttrList* attributes = pango_attr_list_new(); |
154 PangoAttribute* text_color = pango_attr_foreground_new(0, 0, 0); | 154 PangoAttribute* text_color = pango_attr_foreground_new(0, 0, 0); |
155 pango_attr_list_insert(attributes, text_color); | 155 pango_attr_list_insert(attributes, text_color); |
156 gtk_label_set_attributes(GTK_LABEL(message_), attributes); | 156 gtk_label_set_attributes(GTK_LABEL(message_), attributes); |
157 pango_attr_list_unref(attributes); | 157 pango_attr_list_unref(attributes); |
158 | 158 |
(...skipping 30 matching lines...) Expand all Loading... |
189 DCHECK(CalledOnValidThread()); | 189 DCHECK(CalledOnValidThread()); |
190 | 190 |
191 // Only generate bitmaps if the size has actually changed. | 191 // Only generate bitmaps if the size has actually changed. |
192 if (event->width == current_width_ && event->height == current_height_) | 192 if (event->width == current_width_ && event->height == current_height_) |
193 return FALSE; | 193 return FALSE; |
194 | 194 |
195 current_width_ = event->width; | 195 current_width_ = event->width; |
196 current_height_ = event->height; | 196 current_height_ = event->height; |
197 | 197 |
198 // Create the depth 1 pixmap for the window shape. | 198 // Create the depth 1 pixmap for the window shape. |
199 GdkPixmap* shape_mask = gdk_pixmap_new(NULL, current_width_, current_height_, | 199 GdkPixmap* shape_mask = |
200 1); | 200 gdk_pixmap_new(nullptr, current_width_, current_height_, 1); |
201 cairo_t* cairo_context = gdk_cairo_create(shape_mask); | 201 cairo_t* cairo_context = gdk_cairo_create(shape_mask); |
202 | 202 |
203 // Set the arc radius for the corners. | 203 // Set the arc radius for the corners. |
204 const int kCornerRadius = 6; | 204 const int kCornerRadius = 6; |
205 | 205 |
206 // Initialize the whole bitmap to be transparent. | 206 // Initialize the whole bitmap to be transparent. |
207 cairo_set_source_rgba(cairo_context, 0, 0, 0, 0); | 207 cairo_set_source_rgba(cairo_context, 0, 0, 0, 0); |
208 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); | 208 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); |
209 cairo_paint(cairo_context); | 209 cairo_paint(cairo_context); |
210 | 210 |
211 // Paint an opaque round rect covering the whole area (leaving the extreme | 211 // Paint an opaque round rect covering the whole area (leaving the extreme |
212 // corners transparent). | 212 // corners transparent). |
213 cairo_set_source_rgba(cairo_context, 1, 1, 1, 1); | 213 cairo_set_source_rgba(cairo_context, 1, 1, 1, 1); |
214 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); | 214 cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE); |
215 AddRoundRectPath(cairo_context, current_width_, current_height_, | 215 AddRoundRectPath(cairo_context, current_width_, current_height_, |
216 kCornerRadius); | 216 kCornerRadius); |
217 cairo_fill(cairo_context); | 217 cairo_fill(cairo_context); |
218 | 218 |
219 cairo_destroy(cairo_context); | 219 cairo_destroy(cairo_context); |
220 gdk_window_shape_combine_mask(widget->window, shape_mask, 0, 0); | 220 gdk_window_shape_combine_mask(widget->window, shape_mask, 0, 0); |
221 g_object_unref(shape_mask); | 221 g_object_unref(shape_mask); |
222 | 222 |
223 // Create a full-color pixmap for the window background image. | 223 // Create a full-color pixmap for the window background image. |
224 GdkPixmap* background = gdk_pixmap_new(NULL, current_width_, current_height_, | 224 GdkPixmap* background = |
225 24); | 225 gdk_pixmap_new(nullptr, current_width_, current_height_, 24); |
226 cairo_context = gdk_cairo_create(background); | 226 cairo_context = gdk_cairo_create(background); |
227 | 227 |
228 // Paint the whole bitmap one color. | 228 // Paint the whole bitmap one color. |
229 cairo_set_source_rgb(cairo_context, 0.91, 0.91, 0.91); | 229 cairo_set_source_rgb(cairo_context, 0.91, 0.91, 0.91); |
230 cairo_paint(cairo_context); | 230 cairo_paint(cairo_context); |
231 | 231 |
232 // Paint the round-rectangle edge. | 232 // Paint the round-rectangle edge. |
233 cairo_set_source_rgb(cairo_context, 0.13, 0.69, 0.11); | 233 cairo_set_source_rgb(cairo_context, 0.13, 0.69, 0.11); |
234 cairo_set_line_width(cairo_context, 6); | 234 cairo_set_line_width(cairo_context, 6); |
235 AddRoundRectPath(cairo_context, current_width_, current_height_, | 235 AddRoundRectPath(cairo_context, current_width_, current_height_, |
(...skipping 24 matching lines...) Expand all Loading... |
260 cairo_stroke(cairo_context); | 260 cairo_stroke(cairo_context); |
261 x += 3; | 261 x += 3; |
262 cairo_move_to(cairo_context, x, gripper_top); | 262 cairo_move_to(cairo_context, x, gripper_top); |
263 cairo_line_to(cairo_context, x, gripper_bottom); | 263 cairo_line_to(cairo_context, x, gripper_bottom); |
264 cairo_stroke(cairo_context); | 264 cairo_stroke(cairo_context); |
265 | 265 |
266 cairo_destroy(cairo_context); | 266 cairo_destroy(cairo_context); |
267 | 267 |
268 gdk_window_set_back_pixmap(widget->window, background, FALSE); | 268 gdk_window_set_back_pixmap(widget->window, background, FALSE); |
269 g_object_unref(background); | 269 g_object_unref(background); |
270 gdk_window_invalidate_rect(widget->window, NULL, TRUE); | 270 gdk_window_invalidate_rect(widget->window, nullptr, TRUE); |
271 | 271 |
272 return FALSE; | 272 return FALSE; |
273 } | 273 } |
274 | 274 |
275 gboolean DisconnectWindowGtk::OnButtonPress(GtkWidget* widget, | 275 gboolean DisconnectWindowGtk::OnButtonPress(GtkWidget* widget, |
276 GdkEventButton* event) { | 276 GdkEventButton* event) { |
277 DCHECK(CalledOnValidThread()); | 277 DCHECK(CalledOnValidThread()); |
278 | 278 |
279 gtk_window_begin_move_drag(GTK_WINDOW(disconnect_window_), | 279 gtk_window_begin_move_drag(GTK_WINDOW(disconnect_window_), |
280 event->button, | 280 event->button, |
281 event->x_root, | 281 event->x_root, |
282 event->y_root, | 282 event->y_root, |
283 event->time); | 283 event->time); |
284 return FALSE; | 284 return FALSE; |
285 } | 285 } |
286 | 286 |
287 } // namespace | 287 } // namespace |
288 | 288 |
289 // static | 289 // static |
290 scoped_ptr<HostWindow> HostWindow::CreateDisconnectWindow() { | 290 scoped_ptr<HostWindow> HostWindow::CreateDisconnectWindow() { |
291 return make_scoped_ptr(new DisconnectWindowGtk()); | 291 return make_scoped_ptr(new DisconnectWindowGtk()); |
292 } | 292 } |
293 | 293 |
294 } // namespace remoting | 294 } // namespace remoting |
OLD | NEW |