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

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: Better positioning for new tab button. Simplify scale.h interface. 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
« no previous file with comments | « no previous file | chrome/browser/ui/views/tabs/tab_strip.cc » ('j') | ui/base/scale.h » ('J')
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.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/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/base/scale.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 const int GetLeftPadding() {
35 static const int kLeftPadding = 21; 38 switch (ui::GetDisplayScale()) {
36 static const int kTopPadding = 8; 39 case ui::DS_ASH:
37 static const int kRightPadding = 20; 40 return 21;
38 static const int kBottomPadding = 5; 41 case ui::DS_METRO_100:
39 #else 42 case ui::DS_METRO_140:
40 static const int kLeftPadding = 16; 43 case ui::DS_METRO_180:
41 static const int kTopPadding = 6; 44 return 20;
42 static const int kRightPadding = 15; 45 default:
43 static const int kBottomPadding = 5; 46 return 16;
44 #endif 47 }
48 }
49
50 const int GetTopPadding() {
51 switch (ui::GetDisplayScale()) {
52 case ui::DS_ASH:
53 return 8;
54 case ui::DS_METRO_100:
55 case ui::DS_METRO_140:
56 case ui::DS_METRO_180:
57 return 12;
58 default:
59 return 6;
60 }
61 }
62
63 const int GetRightPadding() {
64 switch (ui::GetDisplayScale()) {
65 case ui::DS_ASH:
66 return 20;
67 case ui::DS_METRO_100:
68 case ui::DS_METRO_140:
69 case ui::DS_METRO_180:
70 return 21;
71 default:
72 return 15;
73 }
74 }
75
76 const int GetBottomPadding() {
77 switch (ui::GetDisplayScale()) {
78 case ui::DS_METRO_100:
79 case ui::DS_METRO_140:
80 case ui::DS_METRO_180:
81 return 7;
82 case ui::DS_ASH:
83 default:
84 return 5;
85 }
86 }
45 87
46 // Height of the shadow at the top of the tab image assets. 88 // Height of the shadow at the top of the tab image assets.
47 #if defined(USE_ASH) 89 #if defined(USE_ASH)
48 static const int kDropShadowHeight = 4; 90 static const int kDropShadowHeight = 4;
49 #else 91 #else
50 static const int kDropShadowHeight = 2; 92 static const int kDropShadowHeight = 2;
51 #endif 93 #endif
52 static const int kToolbarOverlap = 1; 94 static const int kToolbarOverlap = 1;
53 static const int kFaviconTitleSpacing = 4; 95 static const int kFaviconTitleSpacing = 4;
54 // Additional vertical offset for title text relative to top of tab. 96 // Additional vertical offset for title text relative to top of tab.
(...skipping 28 matching lines...) Expand all
83 125
84 // How opaque to make the hover state (out of 1). 126 // How opaque to make the hover state (out of 1).
85 static const double kHoverOpacity = 0.33; 127 static const double kHoverOpacity = 0.33;
86 128
87 // Opacity for non-active selected tabs. 129 // Opacity for non-active selected tabs.
88 static const double kSelectedTabOpacity = .45; 130 static const double kSelectedTabOpacity = .45;
89 131
90 // Selected (but not active) tabs have their throb value scaled down by this. 132 // Selected (but not active) tabs have their throb value scaled down by this.
91 static const double kSelectedTabThrobScale = .5; 133 static const double kSelectedTabThrobScale = .5;
92 134
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. 135 // Durations for the various parts of the mini tab title animation.
98 static const int kMiniTitleChangeAnimationDuration1MS = 1600; 136 static const int kMiniTitleChangeAnimationDuration1MS = 1600;
99 static const int kMiniTitleChangeAnimationStart1MS = 0; 137 static const int kMiniTitleChangeAnimationStart1MS = 0;
100 static const int kMiniTitleChangeAnimationEnd1MS = 1900; 138 static const int kMiniTitleChangeAnimationEnd1MS = 1900;
101 static const int kMiniTitleChangeAnimationDuration2MS = 0; 139 static const int kMiniTitleChangeAnimationDuration2MS = 0;
102 static const int kMiniTitleChangeAnimationDuration3MS = 550; 140 static const int kMiniTitleChangeAnimationDuration3MS = 550;
103 static const int kMiniTitleChangeAnimationStart3MS = 150; 141 static const int kMiniTitleChangeAnimationStart3MS = 150;
104 static const int kMiniTitleChangeAnimationEnd3MS = 800; 142 static const int kMiniTitleChangeAnimationEnd3MS = 800;
105 143
106 // Offset from the right edge for the start of the mini title change animation. 144 // Offset from the right edge for the start of the mini title change animation.
107 static const int kMiniTitleChangeInitialXOffset = 6; 145 static const int kMiniTitleChangeInitialXOffset = 6;
108 146
109 // Radius of the radial gradient used for mini title change animation. 147 // Radius of the radial gradient used for mini title change animation.
110 static const int kMiniTitleChangeGradientRadius = 20; 148 static const int kMiniTitleChangeGradientRadius = 20;
111 149
112 // Colors of the gradient used during the mini title change animation. 150 // Colors of the gradient used during the mini title change animation.
113 static const SkColor kMiniTitleChangeGradientColor1 = SK_ColorWHITE; 151 static const SkColor kMiniTitleChangeGradientColor1 = SK_ColorWHITE;
114 static const SkColor kMiniTitleChangeGradientColor2 = 152 static const SkColor kMiniTitleChangeGradientColor2 =
115 SkColorSetARGB(0, 255, 255, 255); 153 SkColorSetARGB(0, 255, 255, 255);
116 154
155 } // namespace
156
157 Tab::TabImage Tab::tab_alpha_ = {0};
158 Tab::TabImage Tab::tab_active_ = {0};
159 Tab::TabImage Tab::tab_inactive_ = {0};
160
117 // static 161 // static
118 const char Tab::kViewClassName[] = "browser/tabs/Tab"; 162 const char Tab::kViewClassName[] = "browser/tabs/Tab";
119 163
120 //////////////////////////////////////////////////////////////////////////////// 164 ////////////////////////////////////////////////////////////////////////////////
121 // Tab, public: 165 // Tab, public:
122 166
123 Tab::Tab(TabController* controller) 167 Tab::Tab(TabController* controller)
124 : BaseTab(controller), 168 : BaseTab(controller),
125 showing_icon_(false), 169 showing_icon_(false),
126 showing_close_button_(false), 170 showing_close_button_(false),
(...skipping 30 matching lines...) Expand all
157 void Tab::StopMiniTabTitleAnimation() { 201 void Tab::StopMiniTabTitleAnimation() {
158 if (mini_title_animation_.get()) 202 if (mini_title_animation_.get())
159 mini_title_animation_->Stop(); 203 mini_title_animation_->Stop();
160 } 204 }
161 205
162 // static 206 // static
163 gfx::Size Tab::GetBasicMinimumUnselectedSize() { 207 gfx::Size Tab::GetBasicMinimumUnselectedSize() {
164 InitTabResources(); 208 InitTabResources();
165 209
166 gfx::Size minimum_size; 210 gfx::Size minimum_size;
167 minimum_size.set_width(kLeftPadding + kRightPadding); 211 minimum_size.set_width(GetLeftPadding() + GetRightPadding());
168 // Since we use bitmap images, the real minimum height of the image is 212 // 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. 213 // defined most accurately by the height of the end cap images.
170 minimum_size.set_height(tab_active_.image_l->height()); 214 minimum_size.set_height(tab_active_.image_l->height());
171 return minimum_size; 215 return minimum_size;
172 } 216 }
173 217
174 gfx::Size Tab::GetMinimumUnselectedSize() { 218 gfx::Size Tab::GetMinimumUnselectedSize() {
175 if (TouchModeSupport::IsTouchOptimized()) 219 if (TouchModeSupport::IsTouchOptimized())
176 return GetTouchModeMinimumSize(); 220 return GetTouchModeMinimumSize();
177 return GetBasicMinimumUnselectedSize(); 221 return GetBasicMinimumUnselectedSize();
178 } 222 }
179 223
180 // static 224 // static
181 gfx::Size Tab::GetMinimumSelectedSize() { 225 gfx::Size Tab::GetMinimumSelectedSize() {
182 if (TouchModeSupport::IsTouchOptimized()) 226 if (TouchModeSupport::IsTouchOptimized())
183 return GetTouchModeMinimumSize(); 227 return GetTouchModeMinimumSize();
184 gfx::Size minimum_size = GetBasicMinimumUnselectedSize(); 228 gfx::Size minimum_size = GetBasicMinimumUnselectedSize();
185 minimum_size.set_width(kLeftPadding + gfx::kFaviconSize + kRightPadding); 229 minimum_size.set_width(
230 GetLeftPadding() + gfx::kFaviconSize + GetRightPadding());
186 return minimum_size; 231 return minimum_size;
187 } 232 }
188 233
189 // static 234 // static
190 gfx::Size Tab::GetStandardSize() { 235 gfx::Size Tab::GetStandardSize() {
191 gfx::Size standard_size = GetBasicMinimumUnselectedSize(); 236 gfx::Size standard_size = GetBasicMinimumUnselectedSize();
192 standard_size.set_width( 237 standard_size.set_width(
193 standard_size.width() + kFaviconTitleSpacing + kStandardTitleWidth); 238 standard_size.width() + kFaviconTitleSpacing + kStandardTitleWidth);
194 return standard_size; 239 return standard_size;
195 } 240 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 close_button()->SetBackground(close_button_color_, 309 close_button()->SetBackground(close_button_color_,
265 rb.GetBitmapNamed(IDR_TAB_CLOSE), 310 rb.GetBitmapNamed(IDR_TAB_CLOSE),
266 rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK)); 311 rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK));
267 } 312 }
268 } 313 }
269 314
270 void Tab::Layout() { 315 void Tab::Layout() {
271 gfx::Rect lb = GetContentsBounds(); 316 gfx::Rect lb = GetContentsBounds();
272 if (lb.IsEmpty()) 317 if (lb.IsEmpty())
273 return; 318 return;
274 lb.Inset(kLeftPadding, kTopPadding, kRightPadding, kBottomPadding); 319 lb.Inset(
320 GetLeftPadding(), GetTopPadding(), GetRightPadding(), GetBottomPadding());
275 321
276 // The height of the content of the Tab is the largest of the favicon, 322 // The height of the content of the Tab is the largest of the favicon,
277 // the title text and the close button graphic. 323 // the title text and the close button graphic.
278 int content_height = std::max(kTabIconSize, font_height()); 324 int content_height = std::max(kTabIconSize, font_height());
279 gfx::Size close_button_size(close_button()->GetPreferredSize()); 325 gfx::Size close_button_size(close_button()->GetPreferredSize());
280 content_height = std::max(content_height, close_button_size.height()); 326 content_height = std::max(content_height, close_button_size.height());
281 327
282 // Size the Favicon. 328 // Size the Favicon.
283 showing_icon_ = ShouldShowIcon(); 329 showing_icon_ = ShouldShowIcon();
284 if (showing_icon_) { 330 if (showing_icon_) {
285 // Use the size of the favicon as apps use a bigger favicon size. 331 // Use the size of the favicon as apps use a bigger favicon size.
286 int favicon_top = kTopPadding + content_height / 2 - kTabIconSize / 2; 332 int favicon_top = GetTopPadding() + content_height / 2 - kTabIconSize / 2;
287 int favicon_left = lb.x(); 333 int favicon_left = lb.x();
288 favicon_bounds_.SetRect(favicon_left, favicon_top, 334 favicon_bounds_.SetRect(favicon_left, favicon_top,
289 kTabIconSize, kTabIconSize); 335 kTabIconSize, kTabIconSize);
290 if (data().mini && width() < kMiniTabRendererAsNormalTabWidth) { 336 if (data().mini && width() < kMiniTabRendererAsNormalTabWidth) {
291 // Adjust the location of the favicon when transitioning from a normal 337 // Adjust the location of the favicon when transitioning from a normal
292 // tab to a mini-tab. 338 // tab to a mini-tab.
293 int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth(); 339 int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth();
294 int ideal_delta = width() - GetMiniWidth(); 340 int ideal_delta = width() - GetMiniWidth();
295 if (ideal_delta < mini_delta) { 341 if (ideal_delta < mini_delta) {
296 int ideal_x = (GetMiniWidth() - kTabIconSize) / 2; 342 int ideal_x = (GetMiniWidth() - kTabIconSize) / 2;
297 int x = favicon_bounds_.x() + static_cast<int>( 343 int x = favicon_bounds_.x() + static_cast<int>(
298 (1 - static_cast<float>(ideal_delta) / 344 (1 - static_cast<float>(ideal_delta) /
299 static_cast<float>(mini_delta)) * 345 static_cast<float>(mini_delta)) *
300 (ideal_x - favicon_bounds_.x())); 346 (ideal_x - favicon_bounds_.x()));
301 favicon_bounds_.set_x(x); 347 favicon_bounds_.set_x(x);
302 } 348 }
303 } 349 }
304 } else { 350 } else {
305 favicon_bounds_.SetRect(lb.x(), lb.y(), 0, 0); 351 favicon_bounds_.SetRect(lb.x(), lb.y(), 0, 0);
306 } 352 }
307 353
308 // Size the Close button. 354 // Size the Close button.
309 showing_close_button_ = ShouldShowCloseBox(); 355 showing_close_button_ = ShouldShowCloseBox();
310 if (showing_close_button_) { 356 if (showing_close_button_) {
311 int close_button_top = kTopPadding + kCloseButtonVertFuzz + 357 int close_button_top = GetTopPadding() + kCloseButtonVertFuzz +
312 (content_height - close_button_size.height()) / 2; 358 (content_height - close_button_size.height()) / 2;
313 // If the ratio of the close button size to tab width exceeds the maximum. 359 // If the ratio of the close button size to tab width exceeds the maximum.
314 close_button()->SetBounds(lb.width() + kCloseButtonHorzFuzz, 360 close_button()->SetBounds(lb.width() + kCloseButtonHorzFuzz,
315 close_button_top, close_button_size.width(), 361 close_button_top, close_button_size.width(),
316 close_button_size.height()); 362 close_button_size.height());
317 close_button()->SetVisible(true); 363 close_button()->SetVisible(true);
318 } else { 364 } else {
319 close_button()->SetBounds(0, 0, 0, 0); 365 close_button()->SetBounds(0, 0, 0, 0);
320 close_button()->SetVisible(false); 366 close_button()->SetVisible(false);
321 } 367 }
322 368
323 int title_left = favicon_bounds_.right() + kFaviconTitleSpacing; 369 int title_left = favicon_bounds_.right() + kFaviconTitleSpacing;
324 int title_top = 370 int title_top = GetTopPadding() + kTitleTextOffsetY +
325 kTopPadding + kTitleTextOffsetY + (content_height - font_height()) / 2; 371 (content_height - font_height()) / 2;
326 // Size the Title text to fill the remaining space. 372 // Size the Title text to fill the remaining space.
327 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) { 373 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) {
328 // If the user has big fonts, the title will appear rendered too far down 374 // 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 375 // on the y-axis if we use the regular top padding, so we need to adjust it
330 // so that the text appears centered. 376 // so that the text appears centered.
331 gfx::Size minimum_size = GetMinimumUnselectedSize(); 377 gfx::Size minimum_size = GetMinimumUnselectedSize();
332 int text_height = title_top + font_height() + kBottomPadding; 378 int text_height = title_top + font_height() + GetBottomPadding();
333 if (text_height > minimum_size.height()) 379 if (text_height > minimum_size.height())
334 title_top -= (text_height - minimum_size.height()) / 2; 380 title_top -= (text_height - minimum_size.height()) / 2;
335 381
336 int title_width; 382 int title_width;
337 if (close_button()->visible()) { 383 if (close_button()->visible()) {
338 title_width = std::max(close_button()->x() - 384 title_width = std::max(close_button()->x() -
339 kTitleCloseButtonSpacing - title_left, 0); 385 kTitleCloseButtonSpacing - title_left, 0);
340 } else { 386 } else {
341 title_width = std::max(lb.width() - title_left, 0); 387 title_width = std::max(lb.width() - title_left, 0);
342 } 388 }
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 // Now draw the highlights/shadows around the tab edge. 619 // Now draw the highlights/shadows around the tab edge.
574 canvas->DrawBitmapInt(*tab_image->image_l, 0, 0); 620 canvas->DrawBitmapInt(*tab_image->image_l, 0, 0);
575 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0, 621 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0,
576 width() - tab_image->l_width - tab_image->r_width, height()); 622 width() - tab_image->l_width - tab_image->r_width, height());
577 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, 0); 623 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, 0);
578 } 624 }
579 625
580 int Tab::IconCapacity() const { 626 int Tab::IconCapacity() const {
581 if (height() < GetMinimumUnselectedSize().height()) 627 if (height() < GetMinimumUnselectedSize().height())
582 return 0; 628 return 0;
583 return (width() - kLeftPadding - kRightPadding) / kTabIconSize; 629 return (width() - GetLeftPadding() - GetRightPadding()) / kTabIconSize;
584 } 630 }
585 631
586 bool Tab::ShouldShowIcon() const { 632 bool Tab::ShouldShowIcon() const {
587 if (data().mini && height() >= GetMinimumUnselectedSize().height()) 633 if (data().mini && height() >= GetMinimumUnselectedSize().height())
588 return true; 634 return true;
589 if (!data().show_icon) { 635 if (!data().show_icon) {
590 return false; 636 return false;
591 } else if (IsActive()) { 637 } else if (IsActive()) {
592 // The active tab clips favicon before close button. 638 // The active tab clips favicon before close button.
593 return IconCapacity() >= 2; 639 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); 691 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT);
646 tab_active_.l_width = tab_active_.image_l->width(); 692 tab_active_.l_width = tab_active_.image_l->width();
647 tab_active_.r_width = tab_active_.image_r->width(); 693 tab_active_.r_width = tab_active_.image_r->width();
648 694
649 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); 695 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT);
650 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); 696 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER);
651 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); 697 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT);
652 tab_inactive_.l_width = tab_inactive_.image_l->width(); 698 tab_inactive_.l_width = tab_inactive_.image_l->width();
653 tab_inactive_.r_width = tab_inactive_.image_r->width(); 699 tab_inactive_.r_width = tab_inactive_.image_r->width();
654 } 700 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/tabs/tab_strip.cc » ('j') | ui/base/scale.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698