| 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/views/tabs/tab_strip.h" | 5 #include "chrome/browser/views/tabs/tab_strip.h" |
| 6 | 6 |
| 7 #include "app/drag_drop_types.h" | 7 #include "app/drag_drop_types.h" |
| 8 #include "app/gfx/canvas.h" | 8 #include "app/gfx/canvas.h" |
| 9 #include "app/gfx/path.h" | 9 #include "app/gfx/path.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 // Don't animate the first tab, it looks weird, and don't animate anything | 1025 // Don't animate the first tab, it looks weird, and don't animate anything |
| 1026 // if the containing window isn't visible yet. | 1026 // if the containing window isn't visible yet. |
| 1027 if (GetTabCount() > 1 && GetWindow() && GetWindow()->IsVisible()) { | 1027 if (GetTabCount() > 1 && GetWindow() && GetWindow()->IsVisible()) { |
| 1028 StartInsertTabAnimation(index); | 1028 StartInsertTabAnimation(index); |
| 1029 } else { | 1029 } else { |
| 1030 Layout(); | 1030 Layout(); |
| 1031 } | 1031 } |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 void TabStrip::TabDetachedAt(TabContents* contents, int index) { | 1034 void TabStrip::TabDetachedAt(TabContents* contents, int index) { |
| 1035 if (CanUpdateDisplay()) { | 1035 GenerateIdealBounds(); |
| 1036 GenerateIdealBounds(); | 1036 StartRemoveTabAnimation(index, contents); |
| 1037 StartRemoveTabAnimation(index, contents); | 1037 // Have to do this _after_ calling StartRemoveTabAnimation, so that any |
| 1038 // Have to do this _after_ calling StartRemoveTabAnimation, so that any | 1038 // previous remove is completed fully and index is valid in sync with the |
| 1039 // previous remove is completed fully and index is valid in sync with the | 1039 // model index. |
| 1040 // model index. | 1040 GetTabAt(index)->set_closing(true); |
| 1041 GetTabAt(index)->set_closing(true); | |
| 1042 } | |
| 1043 } | 1041 } |
| 1044 | 1042 |
| 1045 void TabStrip::TabSelectedAt(TabContents* old_contents, | 1043 void TabStrip::TabSelectedAt(TabContents* old_contents, |
| 1046 TabContents* new_contents, | 1044 TabContents* new_contents, |
| 1047 int index, | 1045 int index, |
| 1048 bool user_gesture) { | 1046 bool user_gesture) { |
| 1049 DCHECK(index >= 0 && index < GetTabCount()); | 1047 DCHECK(index >= 0 && index < GetTabCount()); |
| 1050 if (CanUpdateDisplay()) { | 1048 // We have "tiny tabs" if the tabs are so tiny that the unselected ones are |
| 1051 // We have "tiny tabs" if the tabs are so tiny that the unselected ones are | 1049 // a different size to the selected ones. |
| 1052 // a different size to the selected ones. | 1050 bool tiny_tabs = current_unselected_width_ != current_selected_width_; |
| 1053 bool tiny_tabs = current_unselected_width_ != current_selected_width_; | 1051 if (!IsAnimating() && (!resize_layout_scheduled_ || tiny_tabs)) { |
| 1054 if (!IsAnimating() && (!resize_layout_scheduled_ || tiny_tabs)) { | 1052 Layout(); |
| 1055 Layout(); | 1053 } else { |
| 1056 } else { | 1054 SchedulePaint(); |
| 1057 SchedulePaint(); | 1055 } |
| 1058 } | |
| 1059 | 1056 |
| 1060 int old_index = model_->GetIndexOfTabContents(old_contents); | 1057 int old_index = model_->GetIndexOfTabContents(old_contents); |
| 1061 if (old_index >= 0) | 1058 if (old_index >= 0) |
| 1062 GetTabAt(old_index)->StopPinnedTabTitleAnimation(); | 1059 GetTabAt(old_index)->StopPinnedTabTitleAnimation(); |
| 1063 } | |
| 1064 } | 1060 } |
| 1065 | 1061 |
| 1066 void TabStrip::TabMoved(TabContents* contents, int from_index, int to_index, | 1062 void TabStrip::TabMoved(TabContents* contents, int from_index, int to_index, |
| 1067 bool pinned_state_changed) { | 1063 bool pinned_state_changed) { |
| 1068 gfx::Rect start_bounds = GetIdealBounds(from_index); | 1064 gfx::Rect start_bounds = GetIdealBounds(from_index); |
| 1069 Tab* tab = GetTabAt(from_index); | 1065 Tab* tab = GetTabAt(from_index); |
| 1070 tab_data_.erase(tab_data_.begin() + from_index); | 1066 tab_data_.erase(tab_data_.begin() + from_index); |
| 1071 TabData data = {tab, gfx::Rect()}; | 1067 TabData data = {tab, gfx::Rect()}; |
| 1072 tab->set_pinned(model_->IsTabPinned(to_index)); | 1068 tab->set_pinned(model_->IsTabPinned(to_index)); |
| 1073 tab_data_.insert(tab_data_.begin() + to_index, data); | 1069 tab_data_.insert(tab_data_.begin() + to_index, data); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1201 // so the View system can misinterpret this easily if the mouse is down that | 1197 // so the View system can misinterpret this easily if the mouse is down that |
| 1202 // the user is dragging. | 1198 // the user is dragging. |
| 1203 if (IsAnimating() || tab->closing() || !HasAvailableDragActions()) | 1199 if (IsAnimating() || tab->closing() || !HasAvailableDragActions()) |
| 1204 return; | 1200 return; |
| 1205 int index = GetIndexOfTab(tab); | 1201 int index = GetIndexOfTab(tab); |
| 1206 if (!model_->ContainsIndex(index)) { | 1202 if (!model_->ContainsIndex(index)) { |
| 1207 // It appears to be possible for a drag to start with an invalid tab. | 1203 // It appears to be possible for a drag to start with an invalid tab. |
| 1208 // This records some extra information in hopes of tracking down why. | 1204 // This records some extra information in hopes of tracking down why. |
| 1209 // The string contains the following, in order: | 1205 // The string contains the following, in order: |
| 1210 // . If a drag is already in progress, a 'D'. | 1206 // . If a drag is already in progress, a 'D'. |
| 1207 // . If the model is closing all, an 'A'. |
| 1211 // . Index of tab the user is dragging. | 1208 // . Index of tab the user is dragging. |
| 1212 // . Number of tabs. | 1209 // . Number of tabs. |
| 1213 // . Size of the model. | 1210 // . Size of the model. |
| 1214 // . Indices of any tabs that are being closed. | 1211 // . Indices of any tabs that are being closed. |
| 1215 // . ! end marker. | 1212 // . ! end marker. |
| 1216 std::string tmp; | 1213 std::string tmp; |
| 1217 if (drag_controller_.get()) | 1214 if (drag_controller_.get()) |
| 1218 tmp += "D"; | 1215 tmp += "D"; |
| 1216 if (model_->closing_all()) |
| 1217 tmp += " A"; |
| 1219 tmp += " " + IntToString(index); | 1218 tmp += " " + IntToString(index); |
| 1220 tmp += " " + IntToString(GetTabCount()); | 1219 tmp += " " + IntToString(GetTabCount()); |
| 1221 tmp += " " + IntToString(model_->count()); | 1220 tmp += " " + IntToString(model_->count()); |
| 1222 for (int i = 0; i < GetTabCount(); ++i) { | 1221 for (int i = 0; i < GetTabCount(); ++i) { |
| 1223 if (GetTabAt(i)->closing()) | 1222 if (GetTabAt(i)->closing()) |
| 1224 tmp += " " + IntToString(i); | 1223 tmp += " " + IntToString(i); |
| 1225 } | 1224 } |
| 1226 tmp += "!"; // End marker so we know we got all closing tabs. | 1225 tmp += "!"; // End marker so we know we got all closing tabs. |
| 1227 | 1226 |
| 1228 volatile char tab_state[128]; | 1227 volatile char tab_state[128]; |
| (...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1899 void TabStrip::StartPinAndMoveTabAnimation(int from_index, | 1898 void TabStrip::StartPinAndMoveTabAnimation(int from_index, |
| 1900 int to_index, | 1899 int to_index, |
| 1901 const gfx::Rect& start_bounds) { | 1900 const gfx::Rect& start_bounds) { |
| 1902 if (active_animation_.get()) | 1901 if (active_animation_.get()) |
| 1903 active_animation_->Stop(); | 1902 active_animation_->Stop(); |
| 1904 active_animation_.reset( | 1903 active_animation_.reset( |
| 1905 new PinAndMoveAnimation(this, from_index, to_index, start_bounds)); | 1904 new PinAndMoveAnimation(this, from_index, to_index, start_bounds)); |
| 1906 active_animation_->Start(); | 1905 active_animation_->Start(); |
| 1907 } | 1906 } |
| 1908 | 1907 |
| 1909 bool TabStrip::CanUpdateDisplay() { | |
| 1910 // Don't bother laying out/painting when we're closing all tabs. | |
| 1911 if (model_->closing_all()) { | |
| 1912 // Make sure any active animation is ended, too. | |
| 1913 if (active_animation_.get()) | |
| 1914 active_animation_->Stop(); | |
| 1915 return false; | |
| 1916 } | |
| 1917 return true; | |
| 1918 } | |
| 1919 | |
| 1920 void TabStrip::FinishAnimation(TabStrip::TabAnimation* animation, | 1908 void TabStrip::FinishAnimation(TabStrip::TabAnimation* animation, |
| 1921 bool layout) { | 1909 bool layout) { |
| 1922 active_animation_.reset(NULL); | 1910 active_animation_.reset(NULL); |
| 1923 | 1911 |
| 1924 // Reset the animation state of each tab. | 1912 // Reset the animation state of each tab. |
| 1925 for (int i = 0, count = GetTabCount(); i < count; ++i) | 1913 for (int i = 0, count = GetTabCount(); i < count; ++i) |
| 1926 GetTabAt(i)->set_animating_pinned_change(false); | 1914 GetTabAt(i)->set_animating_pinned_change(false); |
| 1927 | 1915 |
| 1928 if (layout) | 1916 if (layout) |
| 1929 Layout(); | 1917 Layout(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1990 &TabStrip::ResizeLayoutTabs), | 1978 &TabStrip::ResizeLayoutTabs), |
| 1991 kResizeTabsTimeMs); | 1979 kResizeTabsTimeMs); |
| 1992 } | 1980 } |
| 1993 } else { | 1981 } else { |
| 1994 // Mouse moved quickly out of the tab strip and then into it again, so | 1982 // Mouse moved quickly out of the tab strip and then into it again, so |
| 1995 // cancel the timer so that the strip doesn't move when the mouse moves | 1983 // cancel the timer so that the strip doesn't move when the mouse moves |
| 1996 // back over it. | 1984 // back over it. |
| 1997 resize_layout_factory_.RevokeAll(); | 1985 resize_layout_factory_.RevokeAll(); |
| 1998 } | 1986 } |
| 1999 } | 1987 } |
| OLD | NEW |