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 "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" | 5 #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 if (!model_->closing_all()) | 908 if (!model_->closing_all()) |
909 NOTREACHED() << "Leaving in an inconsistent state!"; | 909 NOTREACHED() << "Leaving in an inconsistent state!"; |
910 tab_data_.erase(it); | 910 tab_data_.erase(it); |
911 break; | 911 break; |
912 } | 912 } |
913 } | 913 } |
914 | 914 |
915 gtk_container_remove(GTK_CONTAINER(tabstrip_.get()), tab->widget()); | 915 gtk_container_remove(GTK_CONTAINER(tabstrip_.get()), tab->widget()); |
916 // If we delete the dragged source tab here, the DestroyDragWidget posted | 916 // If we delete the dragged source tab here, the DestroyDragWidget posted |
917 // task will be run after the tab is deleted, leading to a crash. | 917 // task will be run after the tab is deleted, leading to a crash. |
918 MessageLoop::current()->DeleteSoon(FROM_HERE, tab); | 918 base::MessageLoop::current()->DeleteSoon(FROM_HERE, tab); |
919 | 919 |
920 // Force a layout here, because if we've just quickly drag detached a Tab, | 920 // Force a layout here, because if we've just quickly drag detached a Tab, |
921 // the stopping of the active animation above may have left the TabStrip in a | 921 // the stopping of the active animation above may have left the TabStrip in a |
922 // bad (visual) state. | 922 // bad (visual) state. |
923 Layout(); | 923 Layout(); |
924 } | 924 } |
925 | 925 |
926 gfx::Rect TabStripGtk::GetIdealBounds(int index) { | 926 gfx::Rect TabStripGtk::GetIdealBounds(int index) { |
927 DCHECK(index >= 0 && index < GetTabCount()); | 927 DCHECK(index >= 0 && index < GetTabCount()); |
928 return tab_data_.at(index).ideal_bounds; | 928 return tab_data_.at(index).ideal_bounds; |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 gtk_container_remove(GTK_CONTAINER(tabstrip_.get()), removed->widget()); | 1410 gtk_container_remove(GTK_CONTAINER(tabstrip_.get()), removed->widget()); |
1411 delete removed; | 1411 delete removed; |
1412 } | 1412 } |
1413 } | 1413 } |
1414 | 1414 |
1415 void TabStripGtk::HandleGlobalMouseMoveEvent() { | 1415 void TabStripGtk::HandleGlobalMouseMoveEvent() { |
1416 if (!IsCursorInTabStripZone()) { | 1416 if (!IsCursorInTabStripZone()) { |
1417 // Mouse moved outside the tab slop zone, start a timer to do a resize | 1417 // Mouse moved outside the tab slop zone, start a timer to do a resize |
1418 // layout after a short while... | 1418 // layout after a short while... |
1419 if (!weak_factory_.HasWeakPtrs()) { | 1419 if (!weak_factory_.HasWeakPtrs()) { |
1420 MessageLoop::current()->PostDelayedTask( | 1420 base::MessageLoop::current()->PostDelayedTask( |
1421 FROM_HERE, | 1421 FROM_HERE, |
1422 base::Bind(&TabStripGtk::ResizeLayoutTabs, | 1422 base::Bind(&TabStripGtk::ResizeLayoutTabs, |
1423 weak_factory_.GetWeakPtr()), | 1423 weak_factory_.GetWeakPtr()), |
1424 base::TimeDelta::FromMilliseconds(kResizeTabsTimeMs)); | 1424 base::TimeDelta::FromMilliseconds(kResizeTabsTimeMs)); |
1425 } | 1425 } |
1426 } else { | 1426 } else { |
1427 // Mouse moved quickly out of the tab strip and then into it again, so | 1427 // Mouse moved quickly out of the tab strip and then into it again, so |
1428 // cancel the timer so that the strip doesn't move when the mouse moves | 1428 // cancel the timer so that the strip doesn't move when the mouse moves |
1429 // back over it. | 1429 // back over it. |
1430 weak_factory_.InvalidateWeakPtrs(); | 1430 weak_factory_.InvalidateWeakPtrs(); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 active_tab = tab; | 1648 active_tab = tab; |
1649 else | 1649 else |
1650 tab->Raise(); | 1650 tab->Raise(); |
1651 } | 1651 } |
1652 if (active_tab) | 1652 if (active_tab) |
1653 active_tab->Raise(); | 1653 active_tab->Raise(); |
1654 } | 1654 } |
1655 | 1655 |
1656 void TabStripGtk::AddMessageLoopObserver() { | 1656 void TabStripGtk::AddMessageLoopObserver() { |
1657 if (!added_as_message_loop_observer_) { | 1657 if (!added_as_message_loop_observer_) { |
1658 MessageLoopForUI::current()->AddObserver(this); | 1658 base::MessageLoopForUI::current()->AddObserver(this); |
1659 added_as_message_loop_observer_ = true; | 1659 added_as_message_loop_observer_ = true; |
1660 } | 1660 } |
1661 } | 1661 } |
1662 | 1662 |
1663 void TabStripGtk::RemoveMessageLoopObserver() { | 1663 void TabStripGtk::RemoveMessageLoopObserver() { |
1664 if (added_as_message_loop_observer_) { | 1664 if (added_as_message_loop_observer_) { |
1665 MessageLoopForUI::current()->RemoveObserver(this); | 1665 base::MessageLoopForUI::current()->RemoveObserver(this); |
1666 added_as_message_loop_observer_ = false; | 1666 added_as_message_loop_observer_ = false; |
1667 } | 1667 } |
1668 } | 1668 } |
1669 | 1669 |
1670 gfx::Rect TabStripGtk::GetDropBounds(int drop_index, | 1670 gfx::Rect TabStripGtk::GetDropBounds(int drop_index, |
1671 bool drop_before, | 1671 bool drop_before, |
1672 bool* is_beneath) { | 1672 bool* is_beneath) { |
1673 DCHECK_NE(drop_index, -1); | 1673 DCHECK_NE(drop_index, -1); |
1674 int center_x; | 1674 int center_x; |
1675 if (drop_index < GetTabCount()) { | 1675 if (drop_index < GetTabCount()) { |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 // and shown before tabs are added (as in a popup window). | 2118 // and shown before tabs are added (as in a popup window). |
2119 if (GetTabCount() == 0) | 2119 if (GetTabCount() == 0) |
2120 return; | 2120 return; |
2121 | 2121 |
2122 // When there is only one tab, Layout() so we don't animate it. With more | 2122 // When there is only one tab, Layout() so we don't animate it. With more |
2123 // tabs, we should always attempt a resize unless we already have one coming | 2123 // tabs, we should always attempt a resize unless we already have one coming |
2124 // up in our message loop. | 2124 // up in our message loop. |
2125 if (GetTabCount() == 1) { | 2125 if (GetTabCount() == 1) { |
2126 Layout(); | 2126 Layout(); |
2127 } else if (!layout_factory_.HasWeakPtrs()) { | 2127 } else if (!layout_factory_.HasWeakPtrs()) { |
2128 MessageLoop::current()->PostDelayedTask( | 2128 base::MessageLoop::current()->PostDelayedTask( |
2129 FROM_HERE, | 2129 FROM_HERE, |
2130 base::Bind(&TabStripGtk::Layout, layout_factory_.GetWeakPtr()), | 2130 base::Bind(&TabStripGtk::Layout, layout_factory_.GetWeakPtr()), |
2131 base::TimeDelta::FromMilliseconds(kLayoutAfterSizeAllocateMs)); | 2131 base::TimeDelta::FromMilliseconds(kLayoutAfterSizeAllocateMs)); |
2132 } | 2132 } |
2133 } | 2133 } |
2134 | 2134 |
2135 gboolean TabStripGtk::OnDragMotion(GtkWidget* widget, GdkDragContext* context, | 2135 gboolean TabStripGtk::OnDragMotion(GtkWidget* widget, GdkDragContext* context, |
2136 gint x, gint y, guint time) { | 2136 gint x, gint y, guint time) { |
2137 UpdateDropIndex(context, x, y); | 2137 UpdateDropIndex(context, x, y); |
2138 return TRUE; | 2138 return TRUE; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2272 | 2272 |
2273 void TabStripGtk::SetNewTabButtonBackground() { | 2273 void TabStripGtk::SetNewTabButtonBackground() { |
2274 SkColor color = theme_service_->GetColor( | 2274 SkColor color = theme_service_->GetColor( |
2275 ThemeProperties::COLOR_BUTTON_BACKGROUND); | 2275 ThemeProperties::COLOR_BUTTON_BACKGROUND); |
2276 SkBitmap background = theme_service_->GetImageNamed( | 2276 SkBitmap background = theme_service_->GetImageNamed( |
2277 IDR_THEME_WINDOW_CONTROL_BACKGROUND).AsBitmap(); | 2277 IDR_THEME_WINDOW_CONTROL_BACKGROUND).AsBitmap(); |
2278 SkBitmap mask = theme_service_->GetImageNamed( | 2278 SkBitmap mask = theme_service_->GetImageNamed( |
2279 IDR_NEWTAB_BUTTON_MASK).AsBitmap(); | 2279 IDR_NEWTAB_BUTTON_MASK).AsBitmap(); |
2280 newtab_button_->SetBackground(color, background, mask); | 2280 newtab_button_->SetBackground(color, background, mask); |
2281 } | 2281 } |
OLD | NEW |