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

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

Issue 10407110: Adds clipping to the tabs when stacked. This is necessary so we don't (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test Created 8 years, 7 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/tab_strip.h ('k') | chrome/browser/ui/views/tabs/tab_unittest.cc » ('j') | 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 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 case ui::LAYOUT_TOUCH: 179 case ui::LAYOUT_TOUCH:
180 value = 24; 180 value = 24;
181 break; 181 break;
182 default: 182 default:
183 NOTREACHED(); 183 NOTREACHED();
184 } 184 }
185 } 185 }
186 return value; 186 return value;
187 } 187 }
188 188
189 // Amount to adjust the clip by when the tab is stacked before the active index.
190 int stacked_tab_left_clip() {
191 static int value = -1;
192 if (value == -1) {
193 switch (ui::GetDisplayLayout()) {
194 case ui::LAYOUT_ASH:
195 case ui::LAYOUT_DESKTOP:
196 value = 20;
197 break;
198 case ui::LAYOUT_TOUCH:
199 value = 26;
200 break;
201 default:
202 NOTREACHED();
203 }
204 }
205 return value;
206 }
207
208 // Amount to adjust the clip by when the tab is stacked after the active index.
209 int stacked_tab_right_clip() {
210 static int value = -1;
211 if (value == -1) {
212 switch (ui::GetDisplayLayout()) {
213 case ui::LAYOUT_ASH:
214 case ui::LAYOUT_DESKTOP:
215 value = 20;
216 break;
217 case ui::LAYOUT_TOUCH:
218 value = 26;
219 break;
220 default:
221 NOTREACHED();
222 }
223 }
224 return value;
225 }
226
189 // Animation delegate used when a dragged tab is released. When done sets the 227 // Animation delegate used when a dragged tab is released. When done sets the
190 // dragging state to false. 228 // dragging state to false.
191 class ResetDraggingStateDelegate 229 class ResetDraggingStateDelegate
192 : public views::BoundsAnimator::OwnedAnimationDelegate { 230 : public views::BoundsAnimator::OwnedAnimationDelegate {
193 public: 231 public:
194 explicit ResetDraggingStateDelegate(BaseTab* tab) : tab_(tab) { 232 explicit ResetDraggingStateDelegate(BaseTab* tab) : tab_(tab) {
195 } 233 }
196 234
197 virtual void AnimationEnded(const ui::Animation* animation) { 235 virtual void AnimationEnded(const ui::Animation* animation) {
198 tab_->set_dragging(false); 236 tab_->set_dragging(false);
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 return view && view->id() == VIEW_ID_TAB ? static_cast<BaseTab*>(view) : NULL; 986 return view && view->id() == VIEW_ID_TAB ? static_cast<BaseTab*>(view) : NULL;
949 } 987 }
950 988
951 void TabStrip::ClickActiveTab(const BaseTab* tab) const { 989 void TabStrip::ClickActiveTab(const BaseTab* tab) const {
952 DCHECK(IsActiveTab(tab)); 990 DCHECK(IsActiveTab(tab));
953 int index = GetModelIndexOfBaseTab(tab); 991 int index = GetModelIndexOfBaseTab(tab);
954 if (controller() && IsValidModelIndex(index)) 992 if (controller() && IsValidModelIndex(index))
955 controller()->ClickActiveTab(index); 993 controller()->ClickActiveTab(index);
956 } 994 }
957 995
996 bool TabStrip::ShouldPaintTab(const BaseTab* tab, gfx::Rect* clip) {
997 // Only touch layout needs to restrict the clip.
998 if (!touch_layout_.get())
999 return true;
1000
1001 int index = GetModelIndexOfBaseTab(tab);
1002 if (index == -1)
1003 return true; // Tab is closing, paint it all.
1004
1005 if (index < touch_layout_->active_index()) {
1006 if (tab_at(index)->x() == tab_at(index + 1)->x())
1007 return false;
1008
1009 clip->SetRect(0, 0, tab_at(index + 1)->x() - tab_at(index)->x() +
1010 stacked_tab_left_clip(),
1011 tab_at(index)->height());
1012 } else if (index > touch_layout_->active_index() && index > 0) {
1013 const gfx::Rect& tab_bounds(tab_at(index)->bounds());
1014 const gfx::Rect& previous_tab_bounds(tab_at(index - 1)->bounds());
1015 if (tab_bounds.x() == previous_tab_bounds.x())
1016 return false;
1017 if (previous_tab_bounds.right() + tab_h_offset() != tab_bounds.x()) {
1018 int x = previous_tab_bounds.right() - tab_bounds.x() -
1019 stacked_tab_right_clip();
1020 clip->SetRect(x, 0, tab_bounds.width() - x, tab_bounds.height());
1021 }
1022 }
1023 return true;
1024 }
1025
958 void TabStrip::MouseMovedOutOfHost() { 1026 void TabStrip::MouseMovedOutOfHost() {
959 ResizeLayoutTabs(); 1027 ResizeLayoutTabs();
960 } 1028 }
961 1029
962 /////////////////////////////////////////////////////////////////////////////// 1030 ///////////////////////////////////////////////////////////////////////////////
963 // TabStrip, views::View overrides: 1031 // TabStrip, views::View overrides:
964 1032
965 void TabStrip::Layout() { 1033 void TabStrip::Layout() {
966 // Only do a layout if our size changed. 1034 // Only do a layout if our size changed.
967 if (last_layout_size_ == size()) 1035 if (last_layout_size_ == size())
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 } 2084 }
2017 return NULL; 2085 return NULL;
2018 } 2086 }
2019 2087
2020 std::vector<int> TabStrip::GetTabXCoordinates() { 2088 std::vector<int> TabStrip::GetTabXCoordinates() {
2021 std::vector<int> results; 2089 std::vector<int> results;
2022 for (int i = 0; i < tab_count(); ++i) 2090 for (int i = 0; i < tab_count(); ++i)
2023 results.push_back(ideal_bounds(i).x()); 2091 results.push_back(ideal_bounds(i).x());
2024 return results; 2092 return results;
2025 } 2093 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip.h ('k') | chrome/browser/ui/views/tabs/tab_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698