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