| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/gfx/size.h" | 7 #include "base/gfx/size.h" |
| 8 #include "chrome/app/theme/theme_resources.h" | 8 #include "chrome/app/theme/theme_resources.h" |
| 9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
| 10 #include "chrome/browser/tab_contents.h" | 10 #include "chrome/browser/tab_contents.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/common/stl_util-inl.h" | 25 #include "chrome/common/stl_util-inl.h" |
| 26 #include "chrome/common/win_util.h" | 26 #include "chrome/common/win_util.h" |
| 27 #include "chrome/views/image_view.h" | 27 #include "chrome/views/image_view.h" |
| 28 #include "chrome/views/painter.h" | 28 #include "chrome/views/painter.h" |
| 29 | 29 |
| 30 #include "generated_resources.h" | 30 #include "generated_resources.h" |
| 31 | 31 |
| 32 #undef min | 32 #undef min |
| 33 #undef max | 33 #undef max |
| 34 | 34 |
| 35 using base::TimeDelta; | |
| 36 using views::DropTargetEvent; | 35 using views::DropTargetEvent; |
| 37 | 36 |
| 38 static const int kDefaultAnimationDurationMs = 100; | 37 static const int kDefaultAnimationDurationMs = 100; |
| 39 static const int kResizeLayoutAnimationDurationMs = 166; | 38 static const int kResizeLayoutAnimationDurationMs = 166; |
| 40 static const int kReorderAnimationDurationMs = 166; | 39 static const int kReorderAnimationDurationMs = 166; |
| 41 | 40 |
| 42 static const int kLoadingAnimationFrameTimeMs = 30; | |
| 43 static const int kNewTabButtonHOffset = -5; | 41 static const int kNewTabButtonHOffset = -5; |
| 44 static const int kNewTabButtonVOffset = 5; | 42 static const int kNewTabButtonVOffset = 5; |
| 45 static const int kResizeTabsTimeMs = 300; | 43 static const int kResizeTabsTimeMs = 300; |
| 46 static const int kSuspendAnimationsTimeMs = 200; | 44 static const int kSuspendAnimationsTimeMs = 200; |
| 47 static const int kTabHOffset = -16; | 45 static const int kTabHOffset = -16; |
| 48 static const int kTabStripAnimationVSlop = 40; | 46 static const int kTabStripAnimationVSlop = 40; |
| 49 | 47 |
| 50 // Size of the drop indicator. | 48 // Size of the drop indicator. |
| 51 static int drop_indicator_width; | 49 static int drop_indicator_width; |
| 52 static int drop_indicator_height; | 50 static int drop_indicator_height; |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 // the stopping of the active animation above may have left the TabStrip in a | 581 // the stopping of the active animation above may have left the TabStrip in a |
| 584 // bad (visual) state. | 582 // bad (visual) state. |
| 585 Layout(); | 583 Layout(); |
| 586 } | 584 } |
| 587 | 585 |
| 588 gfx::Rect TabStrip::GetIdealBounds(int index) { | 586 gfx::Rect TabStrip::GetIdealBounds(int index) { |
| 589 DCHECK(index >= 0 && index < GetTabCount()); | 587 DCHECK(index >= 0 && index < GetTabCount()); |
| 590 return tab_data_.at(index).ideal_bounds; | 588 return tab_data_.at(index).ideal_bounds; |
| 591 } | 589 } |
| 592 | 590 |
| 591 void TabStrip::UpdateLoadingAnimations() { |
| 592 for (int i = 0, index = 0; i < GetTabCount(); ++i, ++index) { |
| 593 Tab* current_tab = GetTabAt(i); |
| 594 if (current_tab->closing()) { |
| 595 --index; |
| 596 } else { |
| 597 TabContents* contents = model_->GetTabContentsAt(index); |
| 598 if (!contents || !contents->is_loading()) { |
| 599 current_tab->ValidateLoadingAnimation(Tab::ANIMATION_NONE); |
| 600 } else if (contents->waiting_for_response()) { |
| 601 current_tab->ValidateLoadingAnimation(Tab::ANIMATION_WAITING); |
| 602 } else { |
| 603 current_tab->ValidateLoadingAnimation(Tab::ANIMATION_LOADING); |
| 604 } |
| 605 } |
| 606 } |
| 607 } |
| 608 |
| 593 /////////////////////////////////////////////////////////////////////////////// | 609 /////////////////////////////////////////////////////////////////////////////// |
| 594 // TabStrip, views::View overrides: | 610 // TabStrip, views::View overrides: |
| 595 | 611 |
| 596 void TabStrip::PaintChildren(ChromeCanvas* canvas) { | 612 void TabStrip::PaintChildren(ChromeCanvas* canvas) { |
| 597 // Paint the tabs in reverse order, so they stack to the left. | 613 // Paint the tabs in reverse order, so they stack to the left. |
| 598 Tab* selected_tab = NULL; | 614 Tab* selected_tab = NULL; |
| 599 for (int i = GetTabCount() - 1; i >= 0; --i) { | 615 for (int i = GetTabCount() - 1; i >= 0; --i) { |
| 600 Tab* tab = GetTabAt(i); | 616 Tab* tab = GetTabAt(i); |
| 601 // We must ask the _Tab's_ model, not ourselves, because in some situations | 617 // We must ask the _Tab's_ model, not ourselves, because in some situations |
| 602 // the model will be different to this object, e.g. when a Tab is being | 618 // the model will be different to this object, e.g. when a Tab is being |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 } | 890 } |
| 875 | 891 |
| 876 void TabStrip::TabChangedAt(TabContents* contents, int index) { | 892 void TabStrip::TabChangedAt(TabContents* contents, int index) { |
| 877 // Index is in terms of the model. Need to make sure we adjust that index in | 893 // Index is in terms of the model. Need to make sure we adjust that index in |
| 878 // case we have an animation going. | 894 // case we have an animation going. |
| 879 Tab* tab = GetTabAtAdjustForAnimation(index); | 895 Tab* tab = GetTabAtAdjustForAnimation(index); |
| 880 tab->UpdateData(contents); | 896 tab->UpdateData(contents); |
| 881 tab->UpdateFromModel(); | 897 tab->UpdateFromModel(); |
| 882 } | 898 } |
| 883 | 899 |
| 884 void TabStrip::TabValidateAnimations() { | |
| 885 if (model_->TabsAreLoading()) { | |
| 886 if (!loading_animation_timer_.IsRunning()) { | |
| 887 // Loads are happening, and the timer isn't running, so start it. | |
| 888 loading_animation_timer_.Start( | |
| 889 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this, | |
| 890 &TabStrip::LoadingAnimationCallback); | |
| 891 } | |
| 892 } else { | |
| 893 if (loading_animation_timer_.IsRunning()) { | |
| 894 loading_animation_timer_.Stop(); | |
| 895 // Loads are now complete, update the state if a task was scheduled. | |
| 896 LoadingAnimationCallback(); | |
| 897 } | |
| 898 } | |
| 899 } | |
| 900 | |
| 901 /////////////////////////////////////////////////////////////////////////////// | 900 /////////////////////////////////////////////////////////////////////////////// |
| 902 // TabStrip, Tab::Delegate implementation: | 901 // TabStrip, Tab::Delegate implementation: |
| 903 | 902 |
| 904 bool TabStrip::IsTabSelected(const Tab* tab) const { | 903 bool TabStrip::IsTabSelected(const Tab* tab) const { |
| 905 if (tab->closing()) | 904 if (tab->closing()) |
| 906 return false; | 905 return false; |
| 907 | 906 |
| 908 int tab_count = GetTabCount(); | 907 int tab_count = GetTabCount(); |
| 909 for (int i = 0, index = 0; i < tab_count; ++i, ++index) { | 908 for (int i = 0, index = 0; i < tab_count; ++i, ++index) { |
| 910 Tab* current_tab = GetTabAt(i); | 909 Tab* current_tab = GetTabAt(i); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 } | 1245 } |
| 1247 } | 1246 } |
| 1248 | 1247 |
| 1249 void TabStrip::RemoveMessageLoopObserver() { | 1248 void TabStrip::RemoveMessageLoopObserver() { |
| 1250 if (added_as_message_loop_observer_) { | 1249 if (added_as_message_loop_observer_) { |
| 1251 MessageLoopForUI::current()->RemoveObserver(this); | 1250 MessageLoopForUI::current()->RemoveObserver(this); |
| 1252 added_as_message_loop_observer_ = false; | 1251 added_as_message_loop_observer_ = false; |
| 1253 } | 1252 } |
| 1254 } | 1253 } |
| 1255 | 1254 |
| 1256 void TabStrip::LoadingAnimationCallback() { | |
| 1257 for (int i = 0, index = 0; i < GetTabCount(); ++i, ++index) { | |
| 1258 Tab* current_tab = GetTabAt(i); | |
| 1259 if (current_tab->closing()) { | |
| 1260 --index; | |
| 1261 } else { | |
| 1262 TabContents* contents = model_->GetTabContentsAt(index); | |
| 1263 if (!contents || !contents->is_loading()) { | |
| 1264 current_tab->ValidateLoadingAnimation(Tab::ANIMATION_NONE); | |
| 1265 } else if (contents->waiting_for_response()) { | |
| 1266 current_tab->ValidateLoadingAnimation(Tab::ANIMATION_WAITING); | |
| 1267 } else { | |
| 1268 current_tab->ValidateLoadingAnimation(Tab::ANIMATION_LOADING); | |
| 1269 } | |
| 1270 } | |
| 1271 } | |
| 1272 | |
| 1273 // Make sure the model delegates updates the animation as well. | |
| 1274 TabStripModelDelegate* delegate; | |
| 1275 if (model_ && (delegate = model_->delegate())) | |
| 1276 delegate->ValidateLoadingAnimations(); | |
| 1277 } | |
| 1278 | |
| 1279 gfx::Rect TabStrip::GetDropBounds(int drop_index, | 1255 gfx::Rect TabStrip::GetDropBounds(int drop_index, |
| 1280 bool drop_before, | 1256 bool drop_before, |
| 1281 bool* is_beneath) { | 1257 bool* is_beneath) { |
| 1282 DCHECK(drop_index != -1); | 1258 DCHECK(drop_index != -1); |
| 1283 int center_x; | 1259 int center_x; |
| 1284 if (drop_index < GetTabCount()) { | 1260 if (drop_index < GetTabCount()) { |
| 1285 Tab* tab = GetTabAt(drop_index); | 1261 Tab* tab = GetTabAt(drop_index); |
| 1286 if (drop_before) | 1262 if (drop_before) |
| 1287 center_x = tab->x() - (kTabHOffset / 2); | 1263 center_x = tab->x() - (kTabHOffset / 2); |
| 1288 else | 1264 else |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1553 return last_tab->x() + last_tab->width(); | 1529 return last_tab->x() + last_tab->width(); |
| 1554 } | 1530 } |
| 1555 | 1531 |
| 1556 bool TabStrip::IsPointInTab(Tab* tab, | 1532 bool TabStrip::IsPointInTab(Tab* tab, |
| 1557 const gfx::Point& point_in_tabstrip_coords) { | 1533 const gfx::Point& point_in_tabstrip_coords) { |
| 1558 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); | 1534 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); |
| 1559 View::ConvertPointToView(this, tab, &point_in_tab_coords); | 1535 View::ConvertPointToView(this, tab, &point_in_tab_coords); |
| 1560 return tab->HitTest(point_in_tab_coords); | 1536 return tab->HitTest(point_in_tab_coords); |
| 1561 } | 1537 } |
| 1562 | 1538 |
| OLD | NEW |