OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk/tabs/tab_strip_gtk.h" | 5 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" |
6 | 6 |
7 #include "base/gfx/gtk_util.h" | 7 #include "base/gfx/gtk_util.h" |
8 #include "base/gfx/point.h" | 8 #include "base/gfx/point.h" |
9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 TabGtk::GetMinimumUnselectedSize().height()); | 69 TabGtk::GetMinimumUnselectedSize().height()); |
70 gtk_widget_set_app_paintable(tabstrip_.get(), TRUE); | 70 gtk_widget_set_app_paintable(tabstrip_.get(), TRUE); |
71 g_signal_connect(G_OBJECT(tabstrip_.get()), "expose-event", | 71 g_signal_connect(G_OBJECT(tabstrip_.get()), "expose-event", |
72 G_CALLBACK(OnExpose), this); | 72 G_CALLBACK(OnExpose), this); |
73 g_signal_connect(G_OBJECT(tabstrip_.get()), "configure-event", | 73 g_signal_connect(G_OBJECT(tabstrip_.get()), "configure-event", |
74 G_CALLBACK(OnConfigure), this); | 74 G_CALLBACK(OnConfigure), this); |
75 g_signal_connect(G_OBJECT(tabstrip_.get()), "motion-notify-event", | 75 g_signal_connect(G_OBJECT(tabstrip_.get()), "motion-notify-event", |
76 G_CALLBACK(OnMotionNotify), this); | 76 G_CALLBACK(OnMotionNotify), this); |
77 g_signal_connect(G_OBJECT(tabstrip_.get()), "button-press-event", | 77 g_signal_connect(G_OBJECT(tabstrip_.get()), "button-press-event", |
78 G_CALLBACK(OnButtonPress), this); | 78 G_CALLBACK(OnButtonPress), this); |
| 79 g_signal_connect(G_OBJECT(tabstrip_.get()), "leave-notify-event", |
| 80 G_CALLBACK(OnLeaveNotify), this); |
79 gtk_widget_add_events(tabstrip_.get(), | 81 gtk_widget_add_events(tabstrip_.get(), |
80 GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK); | 82 GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK); |
81 gtk_widget_show_all(tabstrip_.get()); | 83 gtk_widget_show_all(tabstrip_.get()); |
82 | 84 |
83 bounds_ = GetInitialWidgetBounds(tabstrip_.get()); | 85 bounds_ = GetInitialWidgetBounds(tabstrip_.get()); |
84 } | 86 } |
85 | 87 |
86 void TabStripGtk::AddTabStripToBox(GtkWidget* box) { | 88 void TabStripGtk::AddTabStripToBox(GtkWidget* box) { |
87 gtk_box_pack_start(GTK_BOX(box), tabstrip_.get(), FALSE, FALSE, 0); | 89 gtk_box_pack_start(GTK_BOX(box), tabstrip_.get(), FALSE, FALSE, 0); |
88 } | 90 } |
89 | 91 |
90 void TabStripGtk::Layout() { | 92 void TabStripGtk::Layout() { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 *unselected_width = std::max(calc_width, min_unselected_width); | 378 *unselected_width = std::max(calc_width, min_unselected_width); |
377 } else if ((min_unselected_width > min_selected_width) && | 379 } else if ((min_unselected_width > min_selected_width) && |
378 (desired_tab_width < min_unselected_width)) { | 380 (desired_tab_width < min_unselected_width)) { |
379 *selected_width = std::max(available_width - total_offset - | 381 *selected_width = std::max(available_width - total_offset - |
380 (min_unselected_width * (tab_count - 1)), min_selected_width); | 382 (min_unselected_width * (tab_count - 1)), min_selected_width); |
381 } | 383 } |
382 } | 384 } |
383 } | 385 } |
384 | 386 |
385 // static | 387 // static |
386 gboolean TabStripGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e, | 388 gboolean TabStripGtk::OnExpose(GtkWidget* widget, GdkEventExpose* event, |
387 TabStripGtk* tabstrip) { | 389 TabStripGtk* tabstrip) { |
388 ChromeCanvasPaint canvas(e); | 390 ChromeCanvasPaint canvas(event); |
389 if (canvas.isEmpty()) | 391 if (canvas.isEmpty()) |
390 return TRUE; | 392 return TRUE; |
391 | 393 |
392 canvas.TileImageInt(*background, 0, 0, tabstrip->bounds_.width(), | 394 canvas.TileImageInt(*background, 0, 0, tabstrip->bounds_.width(), |
393 tabstrip->bounds_.height()); | 395 tabstrip->bounds_.height()); |
394 | 396 |
395 // Paint the tabs in reverse order, so they stack to the left. | 397 // Paint the tabs in reverse order, so they stack to the left. |
396 TabGtk* selected_tab = NULL; | 398 TabGtk* selected_tab = NULL; |
397 int tab_count = tabstrip->GetTabCount(); | 399 int tab_count = tabstrip->GetTabCount(); |
398 for (int i = tab_count - 1; i >= 0; --i) { | 400 for (int i = tab_count - 1; i >= 0; --i) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 // static | 482 // static |
481 gboolean TabStripGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event, | 483 gboolean TabStripGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event, |
482 TabStripGtk* tabstrip) { | 484 TabStripGtk* tabstrip) { |
483 if (tabstrip->hover_index_ != -1 && | 485 if (tabstrip->hover_index_ != -1 && |
484 tabstrip->hover_index_ != tabstrip->model()->selected_index()) { | 486 tabstrip->hover_index_ != tabstrip->model()->selected_index()) { |
485 tabstrip->model()->SelectTabContentsAt(tabstrip->hover_index_, true); | 487 tabstrip->model()->SelectTabContentsAt(tabstrip->hover_index_, true); |
486 } | 488 } |
487 | 489 |
488 return TRUE; | 490 return TRUE; |
489 } | 491 } |
| 492 |
| 493 // static |
| 494 gboolean TabStripGtk::OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event, |
| 495 TabStripGtk* tabstrip) { |
| 496 // A leave-notify-event is generated on mouse click, which sets the mode to |
| 497 // GDK_CROSSING_GRAB. Ignore this event because it doesn't meant the mouse |
| 498 // has left the tabstrip. |
| 499 if (tabstrip->hover_index_ != -1 && event->mode != GDK_CROSSING_GRAB) { |
| 500 tabstrip->GetTabAt(tabstrip->hover_index_)->SetHovering(false); |
| 501 tabstrip->hover_index_ = -1; |
| 502 gtk_widget_queue_draw(tabstrip->tabstrip_.get()); |
| 503 } |
| 504 |
| 505 return TRUE; |
| 506 } |
OLD | NEW |