Chromium Code Reviews| 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/macros.h" | 10 #include "base/macros.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 GtkWidget* button_; | 47 GtkWidget* button_; |
| 48 | 48 |
| 49 // Used to distinguish resize events from other types of "configure-event" | 49 // Used to distinguish resize events from other types of "configure-event" |
| 50 // notifications. | 50 // notifications. |
| 51 int current_width_; | 51 int current_width_; |
| 52 int current_height_; | 52 int current_height_; |
| 53 | 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowGtk); | 54 DISALLOW_COPY_AND_ASSIGN(DisconnectWindowGtk); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 #if GTK_MAJOR_VERSION == 2 | |
| 57 // Helper function for creating a rectangular path with rounded corners, as | 58 // Helper function for creating a rectangular path with rounded corners, as |
| 58 // Cairo doesn't have this facility. |radius| is the arc-radius of each | 59 // Cairo doesn't have this facility. |radius| is the arc-radius of each |
| 59 // corner. The bounding rectangle extends from (0, 0) to (width, height). | 60 // corner. The bounding rectangle extends from (0, 0) to (width, height). |
| 60 void AddRoundRectPath(cairo_t* cairo_context, int width, int height, | 61 void AddRoundRectPath(cairo_t* cairo_context, int width, int height, |
| 61 int radius) { | 62 int radius) { |
| 62 cairo_new_sub_path(cairo_context); | 63 cairo_new_sub_path(cairo_context); |
| 63 cairo_arc(cairo_context, width - radius, radius, radius, -M_PI_2, 0); | 64 cairo_arc(cairo_context, width - radius, radius, radius, -M_PI_2, 0); |
| 64 cairo_arc(cairo_context, width - radius, height - radius, radius, 0, M_PI_2); | 65 cairo_arc(cairo_context, width - radius, height - radius, radius, 0, M_PI_2); |
| 65 cairo_arc(cairo_context, radius, height - radius, radius, M_PI_2, 2 * M_PI_2); | 66 cairo_arc(cairo_context, radius, height - radius, radius, M_PI_2, 2 * M_PI_2); |
| 66 cairo_arc(cairo_context, radius, radius, radius, 2 * M_PI_2, 3 * M_PI_2); | 67 cairo_arc(cairo_context, radius, radius, radius, 2 * M_PI_2, 3 * M_PI_2); |
| 67 cairo_close_path(cairo_context); | 68 cairo_close_path(cairo_context); |
| 68 } | 69 } |
| 70 #endif | |
| 69 | 71 |
| 70 DisconnectWindowGtk::DisconnectWindowGtk() | 72 DisconnectWindowGtk::DisconnectWindowGtk() |
| 71 : disconnect_window_(nullptr), | 73 : disconnect_window_(nullptr), |
| 72 current_width_(0), | 74 current_width_(0), |
| 73 current_height_(0) { | 75 current_height_(0) { |
| 74 } | 76 } |
| 75 | 77 |
| 76 DisconnectWindowGtk::~DisconnectWindowGtk() { | 78 DisconnectWindowGtk::~DisconnectWindowGtk() { |
| 77 DCHECK(CalledOnValidThread()); | 79 DCHECK(CalledOnValidThread()); |
| 78 | 80 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 G_CALLBACK(OnButtonPressThunk), this); | 133 G_CALLBACK(OnButtonPressThunk), this); |
| 132 | 134 |
| 133 // All magic numbers taken from screen shots provided by UX. | 135 // All magic numbers taken from screen shots provided by UX. |
| 134 // The alignment sets narrow margins at the top and bottom, compared with | 136 // The alignment sets narrow margins at the top and bottom, compared with |
| 135 // left and right. The left margin is made larger to accommodate the | 137 // left and right. The left margin is made larger to accommodate the |
| 136 // window movement gripper. | 138 // window movement gripper. |
| 137 GtkWidget* align = gtk_alignment_new(0, 0, 1, 1); | 139 GtkWidget* align = gtk_alignment_new(0, 0, 1, 1); |
| 138 gtk_alignment_set_padding(GTK_ALIGNMENT(align), 8, 8, 24, 12); | 140 gtk_alignment_set_padding(GTK_ALIGNMENT(align), 8, 8, 24, 12); |
| 139 gtk_container_add(GTK_CONTAINER(window), align); | 141 gtk_container_add(GTK_CONTAINER(window), align); |
| 140 | 142 |
| 143 #if GTK_MAJOR_VERSION == 2 | |
| 141 GtkWidget* button_row = gtk_hbox_new(FALSE, 12); | 144 GtkWidget* button_row = gtk_hbox_new(FALSE, 12); |
| 145 #else | |
| 146 GtkWidget* button_row = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12); | |
| 147 gtk_box_set_homogeneous(GTK_BOX(button_row), FALSE); | |
| 148 #endif | |
| 142 gtk_container_add(GTK_CONTAINER(align), button_row); | 149 gtk_container_add(GTK_CONTAINER(align), button_row); |
| 143 | 150 |
| 144 button_ = gtk_button_new_with_label( | 151 button_ = gtk_button_new_with_label( |
| 145 l10n_util::GetStringUTF8(IDS_STOP_SHARING_BUTTON).c_str()); | 152 l10n_util::GetStringUTF8(IDS_STOP_SHARING_BUTTON).c_str()); |
| 146 gtk_box_pack_end(GTK_BOX(button_row), button_, FALSE, FALSE, 0); | 153 gtk_box_pack_end(GTK_BOX(button_row), button_, FALSE, FALSE, 0); |
| 147 | 154 |
| 148 g_signal_connect(button_, "clicked", G_CALLBACK(OnClickedThunk), this); | 155 g_signal_connect(button_, "clicked", G_CALLBACK(OnClickedThunk), this); |
| 149 | 156 |
| 150 message_ = gtk_label_new(nullptr); | 157 message_ = gtk_label_new(nullptr); |
| 151 gtk_box_pack_end(GTK_BOX(button_row), message_, FALSE, FALSE, 0); | 158 gtk_box_pack_end(GTK_BOX(button_row), message_, FALSE, FALSE, 0); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 GdkEventConfigure* event) { | 197 GdkEventConfigure* event) { |
| 191 DCHECK(CalledOnValidThread()); | 198 DCHECK(CalledOnValidThread()); |
| 192 | 199 |
| 193 // Only generate bitmaps if the size has actually changed. | 200 // Only generate bitmaps if the size has actually changed. |
| 194 if (event->width == current_width_ && event->height == current_height_) | 201 if (event->width == current_width_ && event->height == current_height_) |
| 195 return FALSE; | 202 return FALSE; |
| 196 | 203 |
| 197 current_width_ = event->width; | 204 current_width_ = event->width; |
| 198 current_height_ = event->height; | 205 current_height_ = event->height; |
| 199 | 206 |
| 207 #if GTK_MAJOR_VERSION == 2 | |
|
Tom (Use chromium acct)
2017/02/01 00:02:42
We can just let gtk draw the window background, ri
Sergey Ulanov
2017/02/02 00:42:49
I don't think we want to omit this code. This code
| |
| 200 // Create the depth 1 pixmap for the window shape. | 208 // Create the depth 1 pixmap for the window shape. |
| 201 GdkPixmap* shape_mask = | 209 GdkPixmap* shape_mask = |
| 202 gdk_pixmap_new(nullptr, current_width_, current_height_, 1); | 210 gdk_pixmap_new(nullptr, current_width_, current_height_, 1); |
| 203 cairo_t* cairo_context = gdk_cairo_create(shape_mask); | 211 cairo_t* cairo_context = gdk_cairo_create(shape_mask); |
| 204 | 212 |
| 205 // Set the arc radius for the corners. | 213 // Set the arc radius for the corners. |
| 206 const int kCornerRadius = 6; | 214 const int kCornerRadius = 6; |
| 207 | 215 |
| 208 // Initialize the whole bitmap to be transparent. | 216 // Initialize the whole bitmap to be transparent. |
| 209 cairo_set_source_rgba(cairo_context, 0, 0, 0, 0); | 217 cairo_set_source_rgba(cairo_context, 0, 0, 0, 0); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 x += 3; | 271 x += 3; |
| 264 cairo_move_to(cairo_context, x, gripper_top); | 272 cairo_move_to(cairo_context, x, gripper_top); |
| 265 cairo_line_to(cairo_context, x, gripper_bottom); | 273 cairo_line_to(cairo_context, x, gripper_bottom); |
| 266 cairo_stroke(cairo_context); | 274 cairo_stroke(cairo_context); |
| 267 | 275 |
| 268 cairo_destroy(cairo_context); | 276 cairo_destroy(cairo_context); |
| 269 | 277 |
| 270 gdk_window_set_back_pixmap(widget->window, background, FALSE); | 278 gdk_window_set_back_pixmap(widget->window, background, FALSE); |
| 271 g_object_unref(background); | 279 g_object_unref(background); |
| 272 gdk_window_invalidate_rect(widget->window, nullptr, TRUE); | 280 gdk_window_invalidate_rect(widget->window, nullptr, TRUE); |
| 281 #endif | |
| 273 | 282 |
| 274 return FALSE; | 283 return FALSE; |
| 275 } | 284 } |
| 276 | 285 |
| 277 gboolean DisconnectWindowGtk::OnButtonPress(GtkWidget* widget, | 286 gboolean DisconnectWindowGtk::OnButtonPress(GtkWidget* widget, |
| 278 GdkEventButton* event) { | 287 GdkEventButton* event) { |
| 279 DCHECK(CalledOnValidThread()); | 288 DCHECK(CalledOnValidThread()); |
| 280 | 289 |
| 281 gtk_window_begin_move_drag(GTK_WINDOW(disconnect_window_), | 290 gtk_window_begin_move_drag(GTK_WINDOW(disconnect_window_), |
| 282 event->button, | 291 event->button, |
| 283 event->x_root, | 292 event->x_root, |
| 284 event->y_root, | 293 event->y_root, |
| 285 event->time); | 294 event->time); |
| 286 return FALSE; | 295 return FALSE; |
| 287 } | 296 } |
| 288 | 297 |
| 289 } // namespace | 298 } // namespace |
| 290 | 299 |
| 291 // static | 300 // static |
| 292 std::unique_ptr<HostWindow> HostWindow::CreateDisconnectWindow() { | 301 std::unique_ptr<HostWindow> HostWindow::CreateDisconnectWindow() { |
| 293 return base::MakeUnique<DisconnectWindowGtk>(); | 302 return base::MakeUnique<DisconnectWindowGtk>(); |
| 294 } | 303 } |
| 295 | 304 |
| 296 } // namespace remoting | 305 } // namespace remoting |
| OLD | NEW |