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

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

Issue 10115029: Set toolbar padding to something appropriate for Metro icons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improve comment as requested. Created 8 years, 8 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
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.h" 5 #include "chrome/browser/ui/views/tabs/tab.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/defaults.h" 10 #include "chrome/browser/defaults.h"
11 #include "chrome/browser/themes/theme_service.h" 11 #include "chrome/browser/themes/theme_service.h"
12 #include "chrome/browser/ui/tabs/tab_resources.h" 12 #include "chrome/browser/ui/tabs/tab_resources.h"
13 #include "chrome/browser/ui/views/tabs/tab_controller.h" 13 #include "chrome/browser/ui/views/tabs/tab_controller.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
16 #include "grit/theme_resources_standard.h" 16 #include "grit/theme_resources_standard.h"
17 #include "grit/ui_resources.h" 17 #include "grit/ui_resources.h"
18 #include "third_party/skia/include/effects/SkGradientShader.h" 18 #include "third_party/skia/include/effects/SkGradientShader.h"
19 #include "ui/base/animation/multi_animation.h" 19 #include "ui/base/animation/multi_animation.h"
20 #include "ui/base/animation/throb_animation.h" 20 #include "ui/base/animation/throb_animation.h"
21 #include "ui/base/layout.h"
21 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/base/touch/touch_mode_support.h" 23 #include "ui/base/touch/touch_mode_support.h"
23 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
24 #include "ui/gfx/favicon_size.h" 25 #include "ui/gfx/favicon_size.h"
25 #include "ui/gfx/font.h" 26 #include "ui/gfx/font.h"
26 #include "ui/gfx/path.h" 27 #include "ui/gfx/path.h"
27 #include "ui/gfx/skbitmap_operations.h" 28 #include "ui/gfx/skbitmap_operations.h"
28 #include "ui/views/controls/button/image_button.h" 29 #include "ui/views/controls/button/image_button.h"
29 #include "ui/views/widget/tooltip_manager.h" 30 #include "ui/views/widget/tooltip_manager.h"
30 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
31 #include "ui/views/window/non_client_view.h" 32 #include "ui/views/window/non_client_view.h"
32 33
34 namespace {
35
33 // Padding around the "content" of a tab, occupied by the tab border graphics. 36 // Padding around the "content" of a tab, occupied by the tab border graphics.
34 #if defined(USE_ASH) 37
35 static const int kLeftPadding = 21; 38 const int GetLeftPadding() {
36 static const int kTopPadding = 8; 39 static int value = -1;
37 static const int kRightPadding = 20; 40 if (value == -1) {
38 static const int kBottomPadding = 5; 41 switch (ui::GetDisplayLayout()) {
39 #else 42 case ui::LAYOUT_ASH:
40 static const int kLeftPadding = 16; 43 value = 21;
41 static const int kTopPadding = 6; 44 break;
42 static const int kRightPadding = 15; 45 case ui::LAYOUT_METRO:
43 static const int kBottomPadding = 5; 46 value = 20;
44 #endif 47 break;
48 default:
49 value = 16;
50 }
51 }
52 return value;
53 }
54
55 const int GetTopPadding() {
56 static int value = -1;
57 if (value == -1) {
58 switch (ui::GetDisplayLayout()) {
59 case ui::LAYOUT_ASH:
60 value = 8;
61 break;
62 case ui::LAYOUT_METRO:
63 value = 12;
64 break;
65 default:
66 value = 6;
67 }
68 }
69 return value;
70 }
71
72 const int GetRightPadding() {
73 static int value = -1;
74 if (value == -1) {
75 switch (ui::GetDisplayLayout()) {
76 case ui::LAYOUT_ASH:
77 value = 20;
78 break;
79 case ui::LAYOUT_METRO:
80 value = 21;
81 break;
82 default:
83 value = 15;
84 }
85 }
86 return value;
87 }
88
89 const int GetBottomPadding() {
90 static int value = -1;
91 if (value == -1) {
92 switch (ui::GetDisplayLayout()) {
93 case ui::LAYOUT_METRO:
94 value = 7;
95 break;
96 case ui::LAYOUT_ASH:
97 default:
98 value = 5;
99 }
100 }
101 return value;
102 }
45 103
46 // Height of the shadow at the top of the tab image assets. 104 // Height of the shadow at the top of the tab image assets.
47 #if defined(USE_ASH) 105 #if defined(USE_ASH)
48 static const int kDropShadowHeight = 4; 106 static const int kDropShadowHeight = 4;
49 #else 107 #else
50 static const int kDropShadowHeight = 2; 108 static const int kDropShadowHeight = 2;
51 #endif 109 #endif
52 static const int kToolbarOverlap = 1; 110 static const int kToolbarOverlap = 1;
53 static const int kFaviconTitleSpacing = 4; 111 static const int kFaviconTitleSpacing = 4;
54 // Additional vertical offset for title text relative to top of tab. 112 // Additional vertical offset for title text relative to top of tab.
(...skipping 28 matching lines...) Expand all
83 141
84 // How opaque to make the hover state (out of 1). 142 // How opaque to make the hover state (out of 1).
85 static const double kHoverOpacity = 0.33; 143 static const double kHoverOpacity = 0.33;
86 144
87 // Opacity for non-active selected tabs. 145 // Opacity for non-active selected tabs.
88 static const double kSelectedTabOpacity = .45; 146 static const double kSelectedTabOpacity = .45;
89 147
90 // Selected (but not active) tabs have their throb value scaled down by this. 148 // Selected (but not active) tabs have their throb value scaled down by this.
91 static const double kSelectedTabThrobScale = .5; 149 static const double kSelectedTabThrobScale = .5;
92 150
93 Tab::TabImage Tab::tab_alpha_ = {0};
94 Tab::TabImage Tab::tab_active_ = {0};
95 Tab::TabImage Tab::tab_inactive_ = {0};
96
97 // Durations for the various parts of the mini tab title animation. 151 // Durations for the various parts of the mini tab title animation.
98 static const int kMiniTitleChangeAnimationDuration1MS = 1600; 152 static const int kMiniTitleChangeAnimationDuration1MS = 1600;
99 static const int kMiniTitleChangeAnimationStart1MS = 0; 153 static const int kMiniTitleChangeAnimationStart1MS = 0;
100 static const int kMiniTitleChangeAnimationEnd1MS = 1900; 154 static const int kMiniTitleChangeAnimationEnd1MS = 1900;
101 static const int kMiniTitleChangeAnimationDuration2MS = 0; 155 static const int kMiniTitleChangeAnimationDuration2MS = 0;
102 static const int kMiniTitleChangeAnimationDuration3MS = 550; 156 static const int kMiniTitleChangeAnimationDuration3MS = 550;
103 static const int kMiniTitleChangeAnimationStart3MS = 150; 157 static const int kMiniTitleChangeAnimationStart3MS = 150;
104 static const int kMiniTitleChangeAnimationEnd3MS = 800; 158 static const int kMiniTitleChangeAnimationEnd3MS = 800;
105 159
106 // Offset from the right edge for the start of the mini title change animation. 160 // Offset from the right edge for the start of the mini title change animation.
107 static const int kMiniTitleChangeInitialXOffset = 6; 161 static const int kMiniTitleChangeInitialXOffset = 6;
108 162
109 // Radius of the radial gradient used for mini title change animation. 163 // Radius of the radial gradient used for mini title change animation.
110 static const int kMiniTitleChangeGradientRadius = 20; 164 static const int kMiniTitleChangeGradientRadius = 20;
111 165
112 // Colors of the gradient used during the mini title change animation. 166 // Colors of the gradient used during the mini title change animation.
113 static const SkColor kMiniTitleChangeGradientColor1 = SK_ColorWHITE; 167 static const SkColor kMiniTitleChangeGradientColor1 = SK_ColorWHITE;
114 static const SkColor kMiniTitleChangeGradientColor2 = 168 static const SkColor kMiniTitleChangeGradientColor2 =
115 SkColorSetARGB(0, 255, 255, 255); 169 SkColorSetARGB(0, 255, 255, 255);
116 170
171 } // namespace
172
173 Tab::TabImage Tab::tab_alpha_ = {0};
174 Tab::TabImage Tab::tab_active_ = {0};
175 Tab::TabImage Tab::tab_inactive_ = {0};
176
117 // static 177 // static
118 const char Tab::kViewClassName[] = "browser/tabs/Tab"; 178 const char Tab::kViewClassName[] = "browser/tabs/Tab";
119 179
120 //////////////////////////////////////////////////////////////////////////////// 180 ////////////////////////////////////////////////////////////////////////////////
121 // Tab, public: 181 // Tab, public:
122 182
123 Tab::Tab(TabController* controller) 183 Tab::Tab(TabController* controller)
124 : BaseTab(controller), 184 : BaseTab(controller),
125 showing_icon_(false), 185 showing_icon_(false),
126 showing_close_button_(false), 186 showing_close_button_(false),
(...skipping 30 matching lines...) Expand all
157 void Tab::StopMiniTabTitleAnimation() { 217 void Tab::StopMiniTabTitleAnimation() {
158 if (mini_title_animation_.get()) 218 if (mini_title_animation_.get())
159 mini_title_animation_->Stop(); 219 mini_title_animation_->Stop();
160 } 220 }
161 221
162 // static 222 // static
163 gfx::Size Tab::GetBasicMinimumUnselectedSize() { 223 gfx::Size Tab::GetBasicMinimumUnselectedSize() {
164 InitTabResources(); 224 InitTabResources();
165 225
166 gfx::Size minimum_size; 226 gfx::Size minimum_size;
167 minimum_size.set_width(kLeftPadding + kRightPadding); 227 minimum_size.set_width(GetLeftPadding() + GetRightPadding());
168 // Since we use bitmap images, the real minimum height of the image is 228 // Since we use bitmap images, the real minimum height of the image is
169 // defined most accurately by the height of the end cap images. 229 // defined most accurately by the height of the end cap images.
170 minimum_size.set_height(tab_active_.image_l->height()); 230 minimum_size.set_height(tab_active_.image_l->height());
171 return minimum_size; 231 return minimum_size;
172 } 232 }
173 233
174 gfx::Size Tab::GetMinimumUnselectedSize() { 234 gfx::Size Tab::GetMinimumUnselectedSize() {
175 if (TouchModeSupport::IsTouchOptimized()) 235 if (TouchModeSupport::IsTouchOptimized())
176 return GetTouchModeMinimumSize(); 236 return GetTouchModeMinimumSize();
177 return GetBasicMinimumUnselectedSize(); 237 return GetBasicMinimumUnselectedSize();
178 } 238 }
179 239
180 // static 240 // static
181 gfx::Size Tab::GetMinimumSelectedSize() { 241 gfx::Size Tab::GetMinimumSelectedSize() {
182 if (TouchModeSupport::IsTouchOptimized()) 242 if (TouchModeSupport::IsTouchOptimized())
183 return GetTouchModeMinimumSize(); 243 return GetTouchModeMinimumSize();
184 gfx::Size minimum_size = GetBasicMinimumUnselectedSize(); 244 gfx::Size minimum_size = GetBasicMinimumUnselectedSize();
185 minimum_size.set_width(kLeftPadding + gfx::kFaviconSize + kRightPadding); 245 minimum_size.set_width(
246 GetLeftPadding() + gfx::kFaviconSize + GetRightPadding());
186 return minimum_size; 247 return minimum_size;
187 } 248 }
188 249
189 // static 250 // static
190 gfx::Size Tab::GetStandardSize() { 251 gfx::Size Tab::GetStandardSize() {
191 gfx::Size standard_size = GetBasicMinimumUnselectedSize(); 252 gfx::Size standard_size = GetBasicMinimumUnselectedSize();
192 standard_size.set_width( 253 standard_size.set_width(
193 standard_size.width() + kFaviconTitleSpacing + kStandardTitleWidth); 254 standard_size.width() + kFaviconTitleSpacing + kStandardTitleWidth);
194 return standard_size; 255 return standard_size;
195 } 256 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 close_button()->SetBackground(close_button_color_, 325 close_button()->SetBackground(close_button_color_,
265 rb.GetBitmapNamed(IDR_TAB_CLOSE), 326 rb.GetBitmapNamed(IDR_TAB_CLOSE),
266 rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK)); 327 rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK));
267 } 328 }
268 } 329 }
269 330
270 void Tab::Layout() { 331 void Tab::Layout() {
271 gfx::Rect lb = GetContentsBounds(); 332 gfx::Rect lb = GetContentsBounds();
272 if (lb.IsEmpty()) 333 if (lb.IsEmpty())
273 return; 334 return;
274 lb.Inset(kLeftPadding, kTopPadding, kRightPadding, kBottomPadding); 335 lb.Inset(
336 GetLeftPadding(), GetTopPadding(), GetRightPadding(), GetBottomPadding());
275 337
276 // The height of the content of the Tab is the largest of the favicon, 338 // The height of the content of the Tab is the largest of the favicon,
277 // the title text and the close button graphic. 339 // the title text and the close button graphic.
278 int content_height = std::max(kTabIconSize, font_height()); 340 int content_height = std::max(kTabIconSize, font_height());
279 gfx::Size close_button_size(close_button()->GetPreferredSize()); 341 gfx::Size close_button_size(close_button()->GetPreferredSize());
280 content_height = std::max(content_height, close_button_size.height()); 342 content_height = std::max(content_height, close_button_size.height());
281 343
282 // Size the Favicon. 344 // Size the Favicon.
283 showing_icon_ = ShouldShowIcon(); 345 showing_icon_ = ShouldShowIcon();
284 if (showing_icon_) { 346 if (showing_icon_) {
285 // Use the size of the favicon as apps use a bigger favicon size. 347 // Use the size of the favicon as apps use a bigger favicon size.
286 int favicon_top = kTopPadding + content_height / 2 - kTabIconSize / 2; 348 int favicon_top = GetTopPadding() + content_height / 2 - kTabIconSize / 2;
287 int favicon_left = lb.x(); 349 int favicon_left = lb.x();
288 favicon_bounds_.SetRect(favicon_left, favicon_top, 350 favicon_bounds_.SetRect(favicon_left, favicon_top,
289 kTabIconSize, kTabIconSize); 351 kTabIconSize, kTabIconSize);
290 if (data().mini && width() < kMiniTabRendererAsNormalTabWidth) { 352 if (data().mini && width() < kMiniTabRendererAsNormalTabWidth) {
291 // Adjust the location of the favicon when transitioning from a normal 353 // Adjust the location of the favicon when transitioning from a normal
292 // tab to a mini-tab. 354 // tab to a mini-tab.
293 int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth(); 355 int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth();
294 int ideal_delta = width() - GetMiniWidth(); 356 int ideal_delta = width() - GetMiniWidth();
295 if (ideal_delta < mini_delta) { 357 if (ideal_delta < mini_delta) {
296 int ideal_x = (GetMiniWidth() - kTabIconSize) / 2; 358 int ideal_x = (GetMiniWidth() - kTabIconSize) / 2;
297 int x = favicon_bounds_.x() + static_cast<int>( 359 int x = favicon_bounds_.x() + static_cast<int>(
298 (1 - static_cast<float>(ideal_delta) / 360 (1 - static_cast<float>(ideal_delta) /
299 static_cast<float>(mini_delta)) * 361 static_cast<float>(mini_delta)) *
300 (ideal_x - favicon_bounds_.x())); 362 (ideal_x - favicon_bounds_.x()));
301 favicon_bounds_.set_x(x); 363 favicon_bounds_.set_x(x);
302 } 364 }
303 } 365 }
304 } else { 366 } else {
305 favicon_bounds_.SetRect(lb.x(), lb.y(), 0, 0); 367 favicon_bounds_.SetRect(lb.x(), lb.y(), 0, 0);
306 } 368 }
307 369
308 // Size the Close button. 370 // Size the Close button.
309 showing_close_button_ = ShouldShowCloseBox(); 371 showing_close_button_ = ShouldShowCloseBox();
310 if (showing_close_button_) { 372 if (showing_close_button_) {
311 int close_button_top = kTopPadding + kCloseButtonVertFuzz + 373 int close_button_top = GetTopPadding() + kCloseButtonVertFuzz +
312 (content_height - close_button_size.height()) / 2; 374 (content_height - close_button_size.height()) / 2;
313 // If the ratio of the close button size to tab width exceeds the maximum. 375 // If the ratio of the close button size to tab width exceeds the maximum.
314 close_button()->SetBounds(lb.width() + kCloseButtonHorzFuzz, 376 close_button()->SetBounds(lb.width() + kCloseButtonHorzFuzz,
315 close_button_top, close_button_size.width(), 377 close_button_top, close_button_size.width(),
316 close_button_size.height()); 378 close_button_size.height());
317 close_button()->SetVisible(true); 379 close_button()->SetVisible(true);
318 } else { 380 } else {
319 close_button()->SetBounds(0, 0, 0, 0); 381 close_button()->SetBounds(0, 0, 0, 0);
320 close_button()->SetVisible(false); 382 close_button()->SetVisible(false);
321 } 383 }
322 384
323 int title_left = favicon_bounds_.right() + kFaviconTitleSpacing; 385 int title_left = favicon_bounds_.right() + kFaviconTitleSpacing;
324 int title_top = 386 int title_top = GetTopPadding() + kTitleTextOffsetY +
325 kTopPadding + kTitleTextOffsetY + (content_height - font_height()) / 2; 387 (content_height - font_height()) / 2;
326 // Size the Title text to fill the remaining space. 388 // Size the Title text to fill the remaining space.
327 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) { 389 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) {
328 // If the user has big fonts, the title will appear rendered too far down 390 // If the user has big fonts, the title will appear rendered too far down
329 // on the y-axis if we use the regular top padding, so we need to adjust it 391 // on the y-axis if we use the regular top padding, so we need to adjust it
330 // so that the text appears centered. 392 // so that the text appears centered.
331 gfx::Size minimum_size = GetMinimumUnselectedSize(); 393 gfx::Size minimum_size = GetMinimumUnselectedSize();
332 int text_height = title_top + font_height() + kBottomPadding; 394 int text_height = title_top + font_height() + GetBottomPadding();
333 if (text_height > minimum_size.height()) 395 if (text_height > minimum_size.height())
334 title_top -= (text_height - minimum_size.height()) / 2; 396 title_top -= (text_height - minimum_size.height()) / 2;
335 397
336 int title_width; 398 int title_width;
337 if (close_button()->visible()) { 399 if (close_button()->visible()) {
338 title_width = std::max(close_button()->x() - 400 title_width = std::max(close_button()->x() -
339 kTitleCloseButtonSpacing - title_left, 0); 401 kTitleCloseButtonSpacing - title_left, 0);
340 } else { 402 } else {
341 title_width = std::max(lb.width() - title_left, 0); 403 title_width = std::max(lb.width() - title_left, 0);
342 } 404 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 // Now draw the highlights/shadows around the tab edge. 635 // Now draw the highlights/shadows around the tab edge.
574 canvas->DrawBitmapInt(*tab_image->image_l, 0, 0); 636 canvas->DrawBitmapInt(*tab_image->image_l, 0, 0);
575 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0, 637 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0,
576 width() - tab_image->l_width - tab_image->r_width, height()); 638 width() - tab_image->l_width - tab_image->r_width, height());
577 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, 0); 639 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, 0);
578 } 640 }
579 641
580 int Tab::IconCapacity() const { 642 int Tab::IconCapacity() const {
581 if (height() < GetMinimumUnselectedSize().height()) 643 if (height() < GetMinimumUnselectedSize().height())
582 return 0; 644 return 0;
583 return (width() - kLeftPadding - kRightPadding) / kTabIconSize; 645 return (width() - GetLeftPadding() - GetRightPadding()) / kTabIconSize;
584 } 646 }
585 647
586 bool Tab::ShouldShowIcon() const { 648 bool Tab::ShouldShowIcon() const {
587 if (data().mini && height() >= GetMinimumUnselectedSize().height()) 649 if (data().mini && height() >= GetMinimumUnselectedSize().height())
588 return true; 650 return true;
589 if (!data().show_icon) { 651 if (!data().show_icon) {
590 return false; 652 return false;
591 } else if (IsActive()) { 653 } else if (IsActive()) {
592 // The active tab clips favicon before close button. 654 // The active tab clips favicon before close button.
593 return IconCapacity() >= 2; 655 return IconCapacity() >= 2;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); 707 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT);
646 tab_active_.l_width = tab_active_.image_l->width(); 708 tab_active_.l_width = tab_active_.image_l->width();
647 tab_active_.r_width = tab_active_.image_r->width(); 709 tab_active_.r_width = tab_active_.image_r->width();
648 710
649 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); 711 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT);
650 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); 712 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER);
651 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); 713 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT);
652 tab_inactive_.l_width = tab_inactive_.image_l->width(); 714 tab_inactive_.l_width = tab_inactive_.image_l->width();
653 tab_inactive_.r_width = tab_inactive_.image_r->width(); 715 tab_inactive_.r_width = tab_inactive_.image_r->width();
654 } 716 }
OLDNEW
« no previous file with comments | « chrome/app/theme/metro/theme_tab_background2_metro_1_0x.png ('k') | chrome/browser/ui/views/tabs/tab_strip.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698