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

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: Const not OK for Mac build. 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/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
23 #include "ui/gfx/favicon_size.h" 24 #include "ui/gfx/favicon_size.h"
24 #include "ui/gfx/font.h" 25 #include "ui/gfx/font.h"
25 #include "ui/gfx/path.h" 26 #include "ui/gfx/path.h"
26 #include "ui/gfx/skbitmap_operations.h" 27 #include "ui/gfx/skbitmap_operations.h"
27 #include "ui/views/controls/button/image_button.h" 28 #include "ui/views/controls/button/image_button.h"
28 #include "ui/views/widget/tooltip_manager.h" 29 #include "ui/views/widget/tooltip_manager.h"
29 #include "ui/views/widget/widget.h" 30 #include "ui/views/widget/widget.h"
30 #include "ui/views/window/non_client_view.h" 31 #include "ui/views/window/non_client_view.h"
31 32
33 namespace {
34
32 // Padding around the "content" of a tab, occupied by the tab border graphics. 35 // Padding around the "content" of a tab, occupied by the tab border graphics.
33 #if defined(USE_ASH) 36
34 static const int kLeftPadding = 21; 37 const int GetLeftPadding() {
35 static const int kTopPadding = 8; 38 static int value = -1;
36 static const int kRightPadding = 20; 39 if (value == -1) {
37 static const int kBottomPadding = 5; 40 switch (ui::GetDisplayLayout()) {
38 #else 41 case ui::LAYOUT_ASH:
39 static const int kLeftPadding = 16; 42 value = 21;
40 static const int kTopPadding = 6; 43 break;
41 static const int kRightPadding = 15; 44 case ui::LAYOUT_TOUCH:
42 static const int kBottomPadding = 5; 45 value = 20;
43 #endif 46 break;
47 default:
48 value = 16;
49 }
50 }
51 return value;
52 }
53
54 const int GetTopPadding() {
55 static int value = -1;
56 if (value == -1) {
57 switch (ui::GetDisplayLayout()) {
58 case ui::LAYOUT_ASH:
59 value = 8;
60 break;
61 case ui::LAYOUT_TOUCH:
62 value = 12;
63 break;
64 default:
65 value = 6;
66 }
67 }
68 return value;
69 }
70
71 const int GetRightPadding() {
72 static int value = -1;
73 if (value == -1) {
74 switch (ui::GetDisplayLayout()) {
75 case ui::LAYOUT_ASH:
76 value = 20;
77 break;
78 case ui::LAYOUT_TOUCH:
79 value = 21;
80 break;
81 default:
82 value = 15;
83 }
84 }
85 return value;
86 }
87
88 const int GetBottomPadding() {
89 static int value = -1;
90 if (value == -1) {
91 switch (ui::GetDisplayLayout()) {
92 case ui::LAYOUT_TOUCH:
93 value = 7;
94 break;
95 case ui::LAYOUT_ASH:
96 default:
97 value = 5;
98 }
99 }
100 return value;
101 }
44 102
45 // Height of the shadow at the top of the tab image assets. 103 // Height of the shadow at the top of the tab image assets.
46 #if defined(USE_ASH) 104 #if defined(USE_ASH)
47 static const int kDropShadowHeight = 4; 105 static const int kDropShadowHeight = 4;
48 #else 106 #else
49 static const int kDropShadowHeight = 2; 107 static const int kDropShadowHeight = 2;
50 #endif 108 #endif
51 static const int kToolbarOverlap = 1; 109 static const int kToolbarOverlap = 1;
52 static const int kFaviconTitleSpacing = 4; 110 static const int kFaviconTitleSpacing = 4;
53 // Additional vertical offset for title text relative to top of tab. 111 // Additional vertical offset for title text relative to top of tab.
(...skipping 27 matching lines...) Expand all
81 139
82 // How opaque to make the hover state (out of 1). 140 // How opaque to make the hover state (out of 1).
83 static const double kHoverOpacity = 0.33; 141 static const double kHoverOpacity = 0.33;
84 142
85 // Opacity for non-active selected tabs. 143 // Opacity for non-active selected tabs.
86 static const double kSelectedTabOpacity = .45; 144 static const double kSelectedTabOpacity = .45;
87 145
88 // Selected (but not active) tabs have their throb value scaled down by this. 146 // Selected (but not active) tabs have their throb value scaled down by this.
89 static const double kSelectedTabThrobScale = .5; 147 static const double kSelectedTabThrobScale = .5;
90 148
91 Tab::TabImage Tab::tab_alpha_ = {0};
92 Tab::TabImage Tab::tab_active_ = {0};
93 Tab::TabImage Tab::tab_inactive_ = {0};
94
95 // Durations for the various parts of the mini tab title animation. 149 // Durations for the various parts of the mini tab title animation.
96 static const int kMiniTitleChangeAnimationDuration1MS = 1600; 150 static const int kMiniTitleChangeAnimationDuration1MS = 1600;
97 static const int kMiniTitleChangeAnimationStart1MS = 0; 151 static const int kMiniTitleChangeAnimationStart1MS = 0;
98 static const int kMiniTitleChangeAnimationEnd1MS = 1900; 152 static const int kMiniTitleChangeAnimationEnd1MS = 1900;
99 static const int kMiniTitleChangeAnimationDuration2MS = 0; 153 static const int kMiniTitleChangeAnimationDuration2MS = 0;
100 static const int kMiniTitleChangeAnimationDuration3MS = 550; 154 static const int kMiniTitleChangeAnimationDuration3MS = 550;
101 static const int kMiniTitleChangeAnimationStart3MS = 150; 155 static const int kMiniTitleChangeAnimationStart3MS = 150;
102 static const int kMiniTitleChangeAnimationEnd3MS = 800; 156 static const int kMiniTitleChangeAnimationEnd3MS = 800;
103 157
104 // Offset from the right edge for the start of the mini title change animation. 158 // Offset from the right edge for the start of the mini title change animation.
105 static const int kMiniTitleChangeInitialXOffset = 6; 159 static const int kMiniTitleChangeInitialXOffset = 6;
106 160
107 // Radius of the radial gradient used for mini title change animation. 161 // Radius of the radial gradient used for mini title change animation.
108 static const int kMiniTitleChangeGradientRadius = 20; 162 static const int kMiniTitleChangeGradientRadius = 20;
109 163
110 // Colors of the gradient used during the mini title change animation. 164 // Colors of the gradient used during the mini title change animation.
111 static const SkColor kMiniTitleChangeGradientColor1 = SK_ColorWHITE; 165 static const SkColor kMiniTitleChangeGradientColor1 = SK_ColorWHITE;
112 static const SkColor kMiniTitleChangeGradientColor2 = 166 static const SkColor kMiniTitleChangeGradientColor2 =
113 SkColorSetARGB(0, 255, 255, 255); 167 SkColorSetARGB(0, 255, 255, 255);
114 168
169 } // namespace
170
171 Tab::TabImage Tab::tab_alpha_ = {0};
172 Tab::TabImage Tab::tab_active_ = {0};
173 Tab::TabImage Tab::tab_inactive_ = {0};
174
115 // static 175 // static
116 const char Tab::kViewClassName[] = "browser/tabs/Tab"; 176 const char Tab::kViewClassName[] = "browser/tabs/Tab";
117 177
118 //////////////////////////////////////////////////////////////////////////////// 178 ////////////////////////////////////////////////////////////////////////////////
119 // Tab, public: 179 // Tab, public:
120 180
121 Tab::Tab(TabController* controller) 181 Tab::Tab(TabController* controller)
122 : BaseTab(controller), 182 : BaseTab(controller),
123 showing_icon_(false), 183 showing_icon_(false),
124 showing_close_button_(false), 184 showing_close_button_(false),
(...skipping 30 matching lines...) Expand all
155 void Tab::StopMiniTabTitleAnimation() { 215 void Tab::StopMiniTabTitleAnimation() {
156 if (mini_title_animation_.get()) 216 if (mini_title_animation_.get())
157 mini_title_animation_->Stop(); 217 mini_title_animation_->Stop();
158 } 218 }
159 219
160 // static 220 // static
161 gfx::Size Tab::GetBasicMinimumUnselectedSize() { 221 gfx::Size Tab::GetBasicMinimumUnselectedSize() {
162 InitTabResources(); 222 InitTabResources();
163 223
164 gfx::Size minimum_size; 224 gfx::Size minimum_size;
165 minimum_size.set_width(kLeftPadding + kRightPadding); 225 minimum_size.set_width(GetLeftPadding() + GetRightPadding());
166 // Since we use bitmap images, the real minimum height of the image is 226 // Since we use bitmap images, the real minimum height of the image is
167 // defined most accurately by the height of the end cap images. 227 // defined most accurately by the height of the end cap images.
168 minimum_size.set_height(tab_active_.image_l->height()); 228 minimum_size.set_height(tab_active_.image_l->height());
169 return minimum_size; 229 return minimum_size;
170 } 230 }
171 231
172 gfx::Size Tab::GetMinimumUnselectedSize() { 232 gfx::Size Tab::GetMinimumUnselectedSize() {
173 return GetBasicMinimumUnselectedSize(); 233 return GetBasicMinimumUnselectedSize();
174 } 234 }
175 235
176 // static 236 // static
177 gfx::Size Tab::GetMinimumSelectedSize() { 237 gfx::Size Tab::GetMinimumSelectedSize() {
178 gfx::Size minimum_size = GetBasicMinimumUnselectedSize(); 238 gfx::Size minimum_size = GetBasicMinimumUnselectedSize();
179 minimum_size.set_width(kLeftPadding + gfx::kFaviconSize + kRightPadding); 239 minimum_size.set_width(
240 GetLeftPadding() + gfx::kFaviconSize + GetRightPadding());
180 return minimum_size; 241 return minimum_size;
181 } 242 }
182 243
183 // static 244 // static
184 gfx::Size Tab::GetStandardSize() { 245 gfx::Size Tab::GetStandardSize() {
185 gfx::Size standard_size = GetBasicMinimumUnselectedSize(); 246 gfx::Size standard_size = GetBasicMinimumUnselectedSize();
186 standard_size.set_width( 247 standard_size.set_width(
187 standard_size.width() + kFaviconTitleSpacing + kStandardTitleWidth); 248 standard_size.width() + kFaviconTitleSpacing + kStandardTitleWidth);
188 return standard_size; 249 return standard_size;
189 } 250 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 close_button()->SetBackground(close_button_color_, 310 close_button()->SetBackground(close_button_color_,
250 rb.GetBitmapNamed(IDR_TAB_CLOSE), 311 rb.GetBitmapNamed(IDR_TAB_CLOSE),
251 rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK)); 312 rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK));
252 } 313 }
253 } 314 }
254 315
255 void Tab::Layout() { 316 void Tab::Layout() {
256 gfx::Rect lb = GetContentsBounds(); 317 gfx::Rect lb = GetContentsBounds();
257 if (lb.IsEmpty()) 318 if (lb.IsEmpty())
258 return; 319 return;
259 lb.Inset(kLeftPadding, kTopPadding, kRightPadding, kBottomPadding); 320 lb.Inset(
321 GetLeftPadding(), GetTopPadding(), GetRightPadding(), GetBottomPadding());
260 322
261 // The height of the content of the Tab is the largest of the favicon, 323 // The height of the content of the Tab is the largest of the favicon,
262 // the title text and the close button graphic. 324 // the title text and the close button graphic.
263 int content_height = std::max(kTabIconSize, font_height()); 325 int content_height = std::max(kTabIconSize, font_height());
264 gfx::Size close_button_size(close_button()->GetPreferredSize()); 326 gfx::Size close_button_size(close_button()->GetPreferredSize());
265 content_height = std::max(content_height, close_button_size.height()); 327 content_height = std::max(content_height, close_button_size.height());
266 328
267 // Size the Favicon. 329 // Size the Favicon.
268 showing_icon_ = ShouldShowIcon(); 330 showing_icon_ = ShouldShowIcon();
269 if (showing_icon_) { 331 if (showing_icon_) {
270 // Use the size of the favicon as apps use a bigger favicon size. 332 // Use the size of the favicon as apps use a bigger favicon size.
271 int favicon_top = kTopPadding + content_height / 2 - kTabIconSize / 2; 333 int favicon_top = GetTopPadding() + content_height / 2 - kTabIconSize / 2;
272 int favicon_left = lb.x(); 334 int favicon_left = lb.x();
273 favicon_bounds_.SetRect(favicon_left, favicon_top, 335 favicon_bounds_.SetRect(favicon_left, favicon_top,
274 kTabIconSize, kTabIconSize); 336 kTabIconSize, kTabIconSize);
275 if (data().mini && width() < kMiniTabRendererAsNormalTabWidth) { 337 if (data().mini && width() < kMiniTabRendererAsNormalTabWidth) {
276 // Adjust the location of the favicon when transitioning from a normal 338 // Adjust the location of the favicon when transitioning from a normal
277 // tab to a mini-tab. 339 // tab to a mini-tab.
278 int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth(); 340 int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth();
279 int ideal_delta = width() - GetMiniWidth(); 341 int ideal_delta = width() - GetMiniWidth();
280 if (ideal_delta < mini_delta) { 342 if (ideal_delta < mini_delta) {
281 int ideal_x = (GetMiniWidth() - kTabIconSize) / 2; 343 int ideal_x = (GetMiniWidth() - kTabIconSize) / 2;
282 int x = favicon_bounds_.x() + static_cast<int>( 344 int x = favicon_bounds_.x() + static_cast<int>(
283 (1 - static_cast<float>(ideal_delta) / 345 (1 - static_cast<float>(ideal_delta) /
284 static_cast<float>(mini_delta)) * 346 static_cast<float>(mini_delta)) *
285 (ideal_x - favicon_bounds_.x())); 347 (ideal_x - favicon_bounds_.x()));
286 favicon_bounds_.set_x(x); 348 favicon_bounds_.set_x(x);
287 } 349 }
288 } 350 }
289 } else { 351 } else {
290 favicon_bounds_.SetRect(lb.x(), lb.y(), 0, 0); 352 favicon_bounds_.SetRect(lb.x(), lb.y(), 0, 0);
291 } 353 }
292 354
293 // Size the Close button. 355 // Size the Close button.
294 showing_close_button_ = ShouldShowCloseBox(); 356 showing_close_button_ = ShouldShowCloseBox();
295 if (showing_close_button_) { 357 if (showing_close_button_) {
296 int close_button_top = kTopPadding + kCloseButtonVertFuzz + 358 int close_button_top = GetTopPadding() + kCloseButtonVertFuzz +
297 (content_height - close_button_size.height()) / 2; 359 (content_height - close_button_size.height()) / 2;
298 // If the ratio of the close button size to tab width exceeds the maximum. 360 // If the ratio of the close button size to tab width exceeds the maximum.
299 close_button()->SetBounds(lb.width() + kCloseButtonHorzFuzz, 361 close_button()->SetBounds(lb.width() + kCloseButtonHorzFuzz,
300 close_button_top, close_button_size.width(), 362 close_button_top, close_button_size.width(),
301 close_button_size.height()); 363 close_button_size.height());
302 close_button()->SetVisible(true); 364 close_button()->SetVisible(true);
303 } else { 365 } else {
304 close_button()->SetBounds(0, 0, 0, 0); 366 close_button()->SetBounds(0, 0, 0, 0);
305 close_button()->SetVisible(false); 367 close_button()->SetVisible(false);
306 } 368 }
307 369
308 int title_left = favicon_bounds_.right() + kFaviconTitleSpacing; 370 int title_left = favicon_bounds_.right() + kFaviconTitleSpacing;
309 int title_top = 371 int title_top = GetTopPadding() + kTitleTextOffsetY +
310 kTopPadding + kTitleTextOffsetY + (content_height - font_height()) / 2; 372 (content_height - font_height()) / 2;
311 // Size the Title text to fill the remaining space. 373 // Size the Title text to fill the remaining space.
312 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) { 374 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) {
313 // If the user has big fonts, the title will appear rendered too far down 375 // If the user has big fonts, the title will appear rendered too far down
314 // on the y-axis if we use the regular top padding, so we need to adjust it 376 // on the y-axis if we use the regular top padding, so we need to adjust it
315 // so that the text appears centered. 377 // so that the text appears centered.
316 gfx::Size minimum_size = GetMinimumUnselectedSize(); 378 gfx::Size minimum_size = GetMinimumUnselectedSize();
317 int text_height = title_top + font_height() + kBottomPadding; 379 int text_height = title_top + font_height() + GetBottomPadding();
318 if (text_height > minimum_size.height()) 380 if (text_height > minimum_size.height())
319 title_top -= (text_height - minimum_size.height()) / 2; 381 title_top -= (text_height - minimum_size.height()) / 2;
320 382
321 int title_width; 383 int title_width;
322 if (close_button()->visible()) { 384 if (close_button()->visible()) {
323 title_width = std::max(close_button()->x() - 385 title_width = std::max(close_button()->x() -
324 kTitleCloseButtonSpacing - title_left, 0); 386 kTitleCloseButtonSpacing - title_left, 0);
325 } else { 387 } else {
326 title_width = std::max(lb.width() - title_left, 0); 388 title_width = std::max(lb.width() - title_left, 0);
327 } 389 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 // Now draw the highlights/shadows around the tab edge. 620 // Now draw the highlights/shadows around the tab edge.
559 canvas->DrawBitmapInt(*tab_image->image_l, 0, 0); 621 canvas->DrawBitmapInt(*tab_image->image_l, 0, 0);
560 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0, 622 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0,
561 width() - tab_image->l_width - tab_image->r_width, height()); 623 width() - tab_image->l_width - tab_image->r_width, height());
562 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, 0); 624 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, 0);
563 } 625 }
564 626
565 int Tab::IconCapacity() const { 627 int Tab::IconCapacity() const {
566 if (height() < GetMinimumUnselectedSize().height()) 628 if (height() < GetMinimumUnselectedSize().height())
567 return 0; 629 return 0;
568 return (width() - kLeftPadding - kRightPadding) / kTabIconSize; 630 return (width() - GetLeftPadding() - GetRightPadding()) / kTabIconSize;
569 } 631 }
570 632
571 bool Tab::ShouldShowIcon() const { 633 bool Tab::ShouldShowIcon() const {
572 if (data().mini && height() >= GetMinimumUnselectedSize().height()) 634 if (data().mini && height() >= GetMinimumUnselectedSize().height())
573 return true; 635 return true;
574 if (!data().show_icon) { 636 if (!data().show_icon) {
575 return false; 637 return false;
576 } else if (IsActive()) { 638 } else if (IsActive()) {
577 // The active tab clips favicon before close button. 639 // The active tab clips favicon before close button.
578 return IconCapacity() >= 2; 640 return IconCapacity() >= 2;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); 692 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT);
631 tab_active_.l_width = tab_active_.image_l->width(); 693 tab_active_.l_width = tab_active_.image_l->width();
632 tab_active_.r_width = tab_active_.image_r->width(); 694 tab_active_.r_width = tab_active_.image_r->width();
633 695
634 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); 696 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT);
635 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); 697 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER);
636 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); 698 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT);
637 tab_inactive_.l_width = tab_inactive_.image_l->width(); 699 tab_inactive_.l_width = tab_inactive_.image_l->width();
638 tab_inactive_.r_width = tab_inactive_.image_r->width(); 700 tab_inactive_.r_width = tab_inactive_.image_r->width();
639 } 701 }
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