OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/gtk/tabs/tab_gtk.h" | 5 #include "chrome/browser/ui/gtk/tabs/tab_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 | 8 |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
12 #include "chrome/browser/ui/gtk/accelerators_gtk.h" | 12 #include "chrome/browser/ui/gtk/accelerators_gtk.h" |
| 13 #include "chrome/browser/ui/gtk/gtk_input_event_box.h" |
13 #include "chrome/browser/ui/gtk/menu_gtk.h" | 14 #include "chrome/browser/ui/gtk/menu_gtk.h" |
14 #include "chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.h" | 15 #include "chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.h" |
15 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 16 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| 17 #include "chrome/browser/ui/tabs/tab_resources.h" |
16 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
17 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
18 #include "ui/base/dragdrop/gtk_dnd_util.h" | 20 #include "ui/base/dragdrop/gtk_dnd_util.h" |
| 21 #include "ui/base/gtk/scoped_handle_gtk.h" |
19 #include "ui/base/models/accelerator_gtk.h" | 22 #include "ui/base/models/accelerator_gtk.h" |
20 #include "ui/gfx/path.h" | 23 #include "ui/gfx/path.h" |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 // Returns the width of the title for the current font, in pixels. | 27 // Returns the width of the title for the current font, in pixels. |
25 int GetTitleWidth(gfx::Font* font, string16 title) { | 28 int GetTitleWidth(gfx::Font* font, string16 title) { |
26 DCHECK(font); | 29 DCHECK(font); |
27 if (title.empty()) | 30 if (title.empty()) |
28 return 0; | 31 return 0; |
(...skipping 26 matching lines...) Expand all Loading... |
55 TabGtk::TabGtk(TabDelegate* delegate) | 58 TabGtk::TabGtk(TabDelegate* delegate) |
56 : TabRendererGtk(delegate->GetThemeProvider()), | 59 : TabRendererGtk(delegate->GetThemeProvider()), |
57 delegate_(delegate), | 60 delegate_(delegate), |
58 closing_(false), | 61 closing_(false), |
59 dragging_(false), | 62 dragging_(false), |
60 last_mouse_down_(NULL), | 63 last_mouse_down_(NULL), |
61 drag_widget_(NULL), | 64 drag_widget_(NULL), |
62 title_width_(0), | 65 title_width_(0), |
63 ALLOW_THIS_IN_INITIALIZER_LIST(destroy_factory_(this)), | 66 ALLOW_THIS_IN_INITIALIZER_LIST(destroy_factory_(this)), |
64 ALLOW_THIS_IN_INITIALIZER_LIST(drag_end_factory_(this)) { | 67 ALLOW_THIS_IN_INITIALIZER_LIST(drag_end_factory_(this)) { |
65 event_box_ = gtk_event_box_new(); | 68 event_box_ = gtk_input_event_box_new(); |
66 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_), FALSE); | |
67 g_signal_connect(event_box_, "button-press-event", | 69 g_signal_connect(event_box_, "button-press-event", |
68 G_CALLBACK(OnButtonPressEventThunk), this); | 70 G_CALLBACK(OnButtonPressEventThunk), this); |
69 g_signal_connect(event_box_, "button-release-event", | 71 g_signal_connect(event_box_, "button-release-event", |
70 G_CALLBACK(OnButtonReleaseEventThunk), this); | 72 G_CALLBACK(OnButtonReleaseEventThunk), this); |
71 g_signal_connect(event_box_, "enter-notify-event", | 73 g_signal_connect(event_box_, "enter-notify-event", |
72 G_CALLBACK(OnEnterNotifyEventThunk), this); | 74 G_CALLBACK(OnEnterNotifyEventThunk), this); |
73 g_signal_connect(event_box_, "leave-notify-event", | 75 g_signal_connect(event_box_, "leave-notify-event", |
74 G_CALLBACK(OnLeaveNotifyEventThunk), this); | 76 G_CALLBACK(OnLeaveNotifyEventThunk), this); |
75 gtk_widget_add_events(event_box_, | 77 gtk_widget_add_events(event_box_, |
76 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | 78 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | |
(...skipping 13 matching lines...) Expand all Loading... |
90 | 92 |
91 if (menu_controller_.get()) { | 93 if (menu_controller_.get()) { |
92 // The menu is showing. Close the menu. | 94 // The menu is showing. Close the menu. |
93 menu_controller_->Cancel(); | 95 menu_controller_->Cancel(); |
94 | 96 |
95 // Invoke this so that we hide the highlight. | 97 // Invoke this so that we hide the highlight. |
96 ContextMenuClosed(); | 98 ContextMenuClosed(); |
97 } | 99 } |
98 } | 100 } |
99 | 101 |
| 102 void TabGtk::Raise() const { |
| 103 GdkWindow* window = gtk_input_event_box_get_window( |
| 104 GTK_INPUT_EVENT_BOX(event_box_)); |
| 105 gdk_window_raise(window); |
| 106 } |
| 107 |
100 gboolean TabGtk::OnButtonPressEvent(GtkWidget* widget, GdkEventButton* event) { | 108 gboolean TabGtk::OnButtonPressEvent(GtkWidget* widget, GdkEventButton* event) { |
101 // Every button press ensures either a button-release-event or a drag-fail | 109 // Every button press ensures either a button-release-event or a drag-fail |
102 // signal for |widget|. | 110 // signal for |widget|. |
103 if (event->button == 1 && event->type == GDK_BUTTON_PRESS) { | 111 if (event->button == 1 && event->type == GDK_BUTTON_PRESS) { |
104 // Store whether or not we were selected just now... we only want to be | 112 // Store whether or not we were selected just now... we only want to be |
105 // able to drag foreground tabs, so we don't start dragging the tab if | 113 // able to drag foreground tabs, so we don't start dragging the tab if |
106 // it was in the background. | 114 // it was in the background. |
107 if (!IsActive()) { | 115 if (!IsActive()) { |
108 if (event->state & GDK_CONTROL_MASK) | 116 if (event->state & GDK_CONTROL_MASK) |
109 delegate_->ToggleTabSelection(this); | 117 delegate_->ToggleTabSelection(this); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 void TabGtk::UpdateData(TabContents* contents, bool app, bool loading_only) { | 258 void TabGtk::UpdateData(TabContents* contents, bool app, bool loading_only) { |
251 TabRendererGtk::UpdateData(contents, app, loading_only); | 259 TabRendererGtk::UpdateData(contents, app, loading_only); |
252 // Cache the title width so we don't recalculate it every time the tab is | 260 // Cache the title width so we don't recalculate it every time the tab is |
253 // resized. | 261 // resized. |
254 title_width_ = GetTitleWidth(title_font(), GetTitle()); | 262 title_width_ = GetTitleWidth(title_font(), GetTitle()); |
255 UpdateTooltipState(); | 263 UpdateTooltipState(); |
256 } | 264 } |
257 | 265 |
258 void TabGtk::SetBounds(const gfx::Rect& bounds) { | 266 void TabGtk::SetBounds(const gfx::Rect& bounds) { |
259 TabRendererGtk::SetBounds(bounds); | 267 TabRendererGtk::SetBounds(bounds); |
| 268 |
| 269 if (gtk_input_event_box_get_window(GTK_INPUT_EVENT_BOX(event_box_))) { |
| 270 gfx::Path mask; |
| 271 TabResources::GetHitTestMask(bounds.width(), bounds.height(), &mask); |
| 272 ui::ScopedRegion region(mask.CreateNativeRegion()); |
| 273 gdk_window_input_shape_combine_region( |
| 274 gtk_input_event_box_get_window(GTK_INPUT_EVENT_BOX(event_box_)), |
| 275 region.Get(), |
| 276 0, 0); |
| 277 } |
| 278 |
260 UpdateTooltipState(); | 279 UpdateTooltipState(); |
261 } | 280 } |
262 | 281 |
263 /////////////////////////////////////////////////////////////////////////////// | 282 /////////////////////////////////////////////////////////////////////////////// |
264 // TabGtk, private: | 283 // TabGtk, private: |
265 | 284 |
266 void TabGtk::ContextMenuClosed() { | 285 void TabGtk::ContextMenuClosed() { |
267 delegate()->StopAllHighlighting(); | 286 delegate()->StopAllHighlighting(); |
268 menu_controller_.reset(); | 287 menu_controller_.reset(); |
269 } | 288 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 gdk_event_free(last_mouse_down_); | 341 gdk_event_free(last_mouse_down_); |
323 last_mouse_down_ = NULL; | 342 last_mouse_down_ = NULL; |
324 } | 343 } |
325 | 344 |
326 // Notify the drag helper that we're done with any potential drag operations. | 345 // Notify the drag helper that we're done with any potential drag operations. |
327 // Clean up the drag helper, which is re-created on the next mouse press. | 346 // Clean up the drag helper, which is re-created on the next mouse press. |
328 delegate_->EndDrag(canceled); | 347 delegate_->EndDrag(canceled); |
329 | 348 |
330 observer_.reset(); | 349 observer_.reset(); |
331 } | 350 } |
OLD | NEW |