Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1119)

Side by Side Diff: chrome/browser/ui/views/tabs/tab_strip.cc

Issue 10825221: views: Use Tab pointer directly when calling TabStrip::tab_at. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/views/tabs/tab_strip.h" 5 #include "chrome/browser/ui/views/tabs/tab_strip.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windowsx.h> 8 #include <windowsx.h>
9 #endif 9 #endif
10 10
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 else 648 else
649 DoLayout(); 649 DoLayout();
650 650
651 SwapLayoutIfNecessary(); 651 SwapLayoutIfNecessary();
652 } 652 }
653 653
654 void TabStrip::MoveTab(int from_model_index, 654 void TabStrip::MoveTab(int from_model_index,
655 int to_model_index, 655 int to_model_index,
656 const TabRendererData& data) { 656 const TabRendererData& data) {
657 DCHECK_GT(tabs_.view_size(), 0); 657 DCHECK_GT(tabs_.view_size(), 0);
658 BaseTab* last_tab = tab_at(tab_count() - 1); 658 Tab* last_tab = tab_at(tab_count() - 1);
659 tab_at(from_model_index)->SetData(data); 659 tab_at(from_model_index)->SetData(data);
660 if (touch_layout_.get()) { 660 if (touch_layout_.get()) {
661 tabs_.MoveViewOnly(from_model_index, to_model_index); 661 tabs_.MoveViewOnly(from_model_index, to_model_index);
662 int mini_count = 0; 662 int mini_count = 0;
663 GenerateIdealBoundsForMiniTabs(&mini_count); 663 GenerateIdealBoundsForMiniTabs(&mini_count);
664 touch_layout_->MoveTab( 664 touch_layout_->MoveTab(
665 from_model_index, to_model_index, controller_->GetActiveIndex(), 665 from_model_index, to_model_index, controller_->GetActiveIndex(),
666 GetStartXForNormalTabs(), mini_count); 666 GetStartXForNormalTabs(), mini_count);
667 } else { 667 } else {
668 tabs_.Move(from_model_index, to_model_index); 668 tabs_.Move(from_model_index, to_model_index);
669 } 669 }
670 StartMoveTabAnimation(); 670 StartMoveTabAnimation();
671 if (TabDragController::IsAttachedTo(this) && 671 if (TabDragController::IsAttachedTo(this) &&
672 (last_tab != tab_at(tab_count() - 1) || last_tab->dragging())) { 672 (last_tab != tab_at(tab_count() - 1) || last_tab->dragging())) {
673 newtab_button_->SetVisible(false); 673 newtab_button_->SetVisible(false);
674 } 674 }
675 SwapLayoutIfNecessary(); 675 SwapLayoutIfNecessary();
676 } 676 }
677 677
678 void TabStrip::RemoveTabAt(int model_index) { 678 void TabStrip::RemoveTabAt(int model_index) {
679 if (touch_layout_.get()) { 679 if (touch_layout_.get()) {
680 BaseTab* tab = tab_at(model_index); 680 Tab* tab = tab_at(model_index);
681 tab->set_closing(true); 681 tab->set_closing(true);
682 int old_x = tabs_.ideal_bounds(model_index).x(); 682 int old_x = tabs_.ideal_bounds(model_index).x();
683 // We still need to paint the tab until we actually remove it. Put it in 683 // We still need to paint the tab until we actually remove it. Put it in
684 // tabs_closing_map_ so we can find it. 684 // tabs_closing_map_ so we can find it.
685 RemoveTabFromViewModel(model_index); 685 RemoveTabFromViewModel(model_index);
686 touch_layout_->RemoveTab(model_index, GenerateIdealBoundsForMiniTabs(NULL), 686 touch_layout_->RemoveTab(model_index, GenerateIdealBoundsForMiniTabs(NULL),
687 old_x); 687 old_x);
688 ScheduleRemoveTabAnimation(tab); 688 ScheduleRemoveTabAnimation(tab);
689 } else if (in_tab_close_ && model_index != GetModelCount()) { 689 } else if (in_tab_close_ && model_index != GetModelCount()) {
690 StartMouseInitiatedRemoveTabAnimation(model_index); 690 StartMouseInitiatedRemoveTabAnimation(model_index);
691 } else { 691 } else {
692 StartRemoveTabAnimation(model_index); 692 StartRemoveTabAnimation(model_index);
693 } 693 }
694 SwapLayoutIfNecessary(); 694 SwapLayoutIfNecessary();
695 } 695 }
696 696
697 void TabStrip::SetTabData(int model_index, const TabRendererData& data) { 697 void TabStrip::SetTabData(int model_index, const TabRendererData& data) {
698 BaseTab* tab = tab_at(model_index); 698 Tab* tab = tab_at(model_index);
699 bool mini_state_changed = tab->data().mini != data.mini; 699 bool mini_state_changed = tab->data().mini != data.mini;
700 tab->SetData(data); 700 tab->SetData(data);
701 701
702 if (mini_state_changed) { 702 if (mini_state_changed) {
703 if (touch_layout_.get()) { 703 if (touch_layout_.get()) {
704 int mini_tab_count = 0; 704 int mini_tab_count = 0;
705 int start_x = GenerateIdealBoundsForMiniTabs(&mini_tab_count); 705 int start_x = GenerateIdealBoundsForMiniTabs(&mini_tab_count);
706 touch_layout_->SetXAndMiniCount(start_x, mini_tab_count); 706 touch_layout_->SetXAndMiniCount(start_x, mini_tab_count);
707 } 707 }
708 if (GetWidget() && GetWidget()->IsVisible()) 708 if (GetWidget() && GetWidget()->IsVisible())
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 tab->set_theme_provider(GetThemeProvider()); 813 tab->set_theme_provider(GetThemeProvider());
814 return tab; 814 return tab;
815 } 815 }
816 816
817 bool TabStrip::IsDragSessionActive() const { 817 bool TabStrip::IsDragSessionActive() const {
818 return drag_controller_.get() != NULL; 818 return drag_controller_.get() != NULL;
819 } 819 }
820 820
821 bool TabStrip::IsActiveDropTarget() const { 821 bool TabStrip::IsActiveDropTarget() const {
822 for (int i = 0; i < tab_count(); ++i) { 822 for (int i = 0; i < tab_count(); ++i) {
823 BaseTab* tab = tab_at(i); 823 Tab* tab = tab_at(i);
824 if (tab->dragging()) 824 if (tab->dragging())
825 return true; 825 return true;
826 } 826 }
827 return false; 827 return false;
828 } 828 }
829 829
830 bool TabStrip::IsTabStripEditable() const { 830 bool TabStrip::IsTabStripEditable() const {
831 return !IsDragSessionActive() && !IsActiveDropTarget(); 831 return !IsDragSessionActive() && !IsActiveDropTarget();
832 } 832 }
833 833
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 CHECK(false); 973 CHECK(false);
974 return; 974 return;
975 } 975 }
976 std::vector<BaseTab*> tabs; 976 std::vector<BaseTab*> tabs;
977 int size_to_selected = 0; 977 int size_to_selected = 0;
978 int x = tab->GetMirroredXInView(event.x()); 978 int x = tab->GetMirroredXInView(event.x());
979 int y = event.y(); 979 int y = event.y();
980 // Build the set of selected tabs to drag and calculate the offset from the 980 // Build the set of selected tabs to drag and calculate the offset from the
981 // first selected tab. 981 // first selected tab.
982 for (int i = 0; i < tab_count(); ++i) { 982 for (int i = 0; i < tab_count(); ++i) {
983 BaseTab* other_tab = tab_at(i); 983 Tab* other_tab = tab_at(i);
984 if (IsTabSelected(other_tab)) { 984 if (IsTabSelected(other_tab)) {
985 tabs.push_back(other_tab); 985 tabs.push_back(other_tab);
986 if (other_tab == tab) { 986 if (other_tab == tab) {
987 size_to_selected = GetSizeNeededForTabs(tabs); 987 size_to_selected = GetSizeNeededForTabs(tabs);
988 x = size_to_selected - tab->width() + x; 988 x = size_to_selected - tab->width() + x;
989 } 989 }
990 } 990 }
991 } 991 }
992 DCHECK(!tabs.empty()); 992 DCHECK(!tabs.empty());
993 DCHECK(std::find(tabs.begin(), tabs.end(), tab) != tabs.end()); 993 DCHECK(std::find(tabs.begin(), tabs.end(), tab) != tabs.end());
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 1463
1464 void TabStrip::StartInsertTabAnimation(int model_index) { 1464 void TabStrip::StartInsertTabAnimation(int model_index) {
1465 PrepareForAnimation(); 1465 PrepareForAnimation();
1466 1466
1467 // The TabStrip can now use its entire width to lay out Tabs. 1467 // The TabStrip can now use its entire width to lay out Tabs.
1468 in_tab_close_ = false; 1468 in_tab_close_ = false;
1469 available_width_for_tabs_ = -1; 1469 available_width_for_tabs_ = -1;
1470 1470
1471 GenerateIdealBounds(); 1471 GenerateIdealBounds();
1472 1472
1473 BaseTab* tab = tab_at(model_index); 1473 Tab* tab = tab_at(model_index);
1474 if (model_index == 0) { 1474 if (model_index == 0) {
1475 tab->SetBounds(0, ideal_bounds(model_index).y(), 0, 1475 tab->SetBounds(0, ideal_bounds(model_index).y(), 0,
1476 ideal_bounds(model_index).height()); 1476 ideal_bounds(model_index).height());
1477 } else { 1477 } else {
1478 BaseTab* last_tab = tab_at(model_index - 1); 1478 Tab* last_tab = tab_at(model_index - 1);
1479 tab->SetBounds(last_tab->bounds().right() + tab_h_offset(), 1479 tab->SetBounds(last_tab->bounds().right() + tab_h_offset(),
1480 ideal_bounds(model_index).y(), 0, 1480 ideal_bounds(model_index).y(), 0,
1481 ideal_bounds(model_index).height()); 1481 ideal_bounds(model_index).height());
1482 } 1482 }
1483 1483
1484 AnimateToIdealBounds(); 1484 AnimateToIdealBounds();
1485 } 1485 }
1486 1486
1487 void TabStrip::StartMoveTabAnimation() { 1487 void TabStrip::StartMoveTabAnimation() {
1488 PrepareForAnimation(); 1488 PrepareForAnimation();
1489 GenerateIdealBounds(); 1489 GenerateIdealBounds();
1490 AnimateToIdealBounds(); 1490 AnimateToIdealBounds();
1491 } 1491 }
1492 1492
1493 void TabStrip::StartRemoveTabAnimation(int model_index) { 1493 void TabStrip::StartRemoveTabAnimation(int model_index) {
1494 PrepareForAnimation(); 1494 PrepareForAnimation();
1495 1495
1496 // Mark the tab as closing. 1496 // Mark the tab as closing.
1497 BaseTab* tab = tab_at(model_index); 1497 Tab* tab = tab_at(model_index);
1498 tab->set_closing(true); 1498 tab->set_closing(true);
1499 1499
1500 RemoveTabFromViewModel(model_index); 1500 RemoveTabFromViewModel(model_index);
1501 1501
1502 ScheduleRemoveTabAnimation(tab); 1502 ScheduleRemoveTabAnimation(tab);
1503 } 1503 }
1504 1504
1505 void TabStrip::ScheduleRemoveTabAnimation(BaseTab* tab) { 1505 void TabStrip::ScheduleRemoveTabAnimation(BaseTab* tab) {
1506 // Start an animation for the tabs. 1506 // Start an animation for the tabs.
1507 GenerateIdealBounds(); 1507 GenerateIdealBounds();
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
2235 2235
2236 PrepareForAnimation(); 2236 PrepareForAnimation();
2237 2237
2238 GenerateIdealBounds(); 2238 GenerateIdealBounds();
2239 AnimateToIdealBounds(); 2239 AnimateToIdealBounds();
2240 } 2240 }
2241 2241
2242 void TabStrip::StartMouseInitiatedRemoveTabAnimation(int model_index) { 2242 void TabStrip::StartMouseInitiatedRemoveTabAnimation(int model_index) {
2243 // The user initiated the close. We want to persist the bounds of all the 2243 // The user initiated the close. We want to persist the bounds of all the
2244 // existing tabs, so we manually shift ideal_bounds then animate. 2244 // existing tabs, so we manually shift ideal_bounds then animate.
2245 BaseTab* tab_closing = tab_at(model_index); 2245 Tab* tab_closing = tab_at(model_index);
2246 int delta = tab_closing->width() + tab_h_offset(); 2246 int delta = tab_closing->width() + tab_h_offset();
2247 // If the tab being closed is a mini-tab next to a non-mini-tab, be sure to 2247 // If the tab being closed is a mini-tab next to a non-mini-tab, be sure to
2248 // add the extra padding. 2248 // add the extra padding.
2249 DCHECK_NE(model_index + 1, tab_count()); 2249 DCHECK_NE(model_index + 1, tab_count());
2250 if (tab_closing->data().mini && model_index + 1 < tab_count() && 2250 if (tab_closing->data().mini && model_index + 1 < tab_count() &&
2251 !tab_at(model_index + 1)->data().mini) { 2251 !tab_at(model_index + 1)->data().mini) {
2252 delta += kMiniToNonMiniGap; 2252 delta += kMiniToNonMiniGap;
2253 } 2253 }
2254 2254
2255 for (int i = model_index + 1; i < tab_count(); ++i) { 2255 for (int i = model_index + 1; i < tab_count(); ++i) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 2348
2349 int mini_tab_count = GetMiniTabCount(); 2349 int mini_tab_count = GetMiniTabCount();
2350 int normal_count = tab_count() - mini_tab_count; 2350 int normal_count = tab_count() - mini_tab_count;
2351 if (normal_count <= 1 || normal_count == mini_tab_count) 2351 if (normal_count <= 1 || normal_count == mini_tab_count)
2352 return false; 2352 return false;
2353 int x = GetStartXForNormalTabs(); 2353 int x = GetStartXForNormalTabs();
2354 int available_width = width() - x - new_tab_button_width(); 2354 int available_width = width() - x - new_tab_button_width();
2355 return (Tab::GetTouchWidth() * normal_count + 2355 return (Tab::GetTouchWidth() * normal_count +
2356 tab_h_offset() * (normal_count - 1)) > available_width; 2356 tab_h_offset() * (normal_count - 1)) > available_width;
2357 } 2357 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698