OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/tabs/tab.h" | 5 #include "chrome/browser/views/tabs/tab.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "app/multi_animation.h" | 9 #include "app/multi_animation.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
11 #include "app/slide_animation.h" | 11 #include "app/slide_animation.h" |
12 #include "app/throb_animation.h" | 12 #include "app/throb_animation.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/browser_theme_provider.h" | 14 #include "chrome/browser/browser_theme_provider.h" |
15 #include "chrome/browser/defaults.h" | 15 #include "chrome/browser/defaults.h" |
16 #include "gfx/canvas.h" | 16 #include "gfx/canvas.h" |
17 #include "gfx/favicon_size.h" | 17 #include "gfx/favicon_size.h" |
18 #include "gfx/font.h" | 18 #include "gfx/font.h" |
19 #include "gfx/path.h" | 19 #include "gfx/path.h" |
20 #include "gfx/skbitmap_operations.h" | 20 #include "gfx/skbitmap_operations.h" |
21 #include "grit/app_resources.h" | 21 #include "grit/app_resources.h" |
22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
23 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
24 #include "third_party/skia/include/effects/SkGradientShader.h" | 24 #include "third_party/skia/include/effects/SkGradientShader.h" |
25 #include "views/controls/button/image_button.h" | 25 #include "views/controls/button/image_button.h" |
| 26 #include "views/widget/root_view.h" |
26 #include "views/widget/tooltip_manager.h" | 27 #include "views/widget/tooltip_manager.h" |
27 #include "views/widget/widget.h" | 28 #include "views/widget/widget.h" |
28 #include "views/window/non_client_view.h" | 29 #include "views/window/non_client_view.h" |
29 #include "views/window/window.h" | 30 #include "views/window/window.h" |
30 | 31 |
31 static const int kLeftPadding = 16; | 32 static const int kLeftPadding = 16; |
32 static const int kTopPadding = 6; | 33 static const int kTopPadding = 6; |
33 static const int kRightPadding = 15; | 34 static const int kRightPadding = 15; |
34 static const int kBottomPadding = 5; | 35 static const int kBottomPadding = 5; |
35 static const int kDropShadowHeight = 2; | 36 static const int kDropShadowHeight = 2; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 99 |
99 } // namespace | 100 } // namespace |
100 | 101 |
101 // static | 102 // static |
102 const char Tab::kViewClassName[] = "browser/tabs/Tab"; | 103 const char Tab::kViewClassName[] = "browser/tabs/Tab"; |
103 | 104 |
104 //////////////////////////////////////////////////////////////////////////////// | 105 //////////////////////////////////////////////////////////////////////////////// |
105 // Tab, public: | 106 // Tab, public: |
106 | 107 |
107 Tab::Tab(TabController* controller) | 108 Tab::Tab(TabController* controller) |
108 : BaseTab(controller), | 109 : BaseTab(controller, true), |
109 showing_icon_(false), | 110 showing_icon_(false), |
110 showing_close_button_(false), | 111 showing_close_button_(false), |
111 close_button_color_(NULL), | 112 close_button_color_(NULL), |
112 render_as_new_tab_(false), | 113 render_as_new_tab_(false), |
113 render_unselected_(false), | 114 render_unselected_(false), |
114 alpha_(1) { | 115 alpha_(1) { |
115 InitTabResources(); | 116 InitTabResources(); |
116 } | 117 } |
117 | 118 |
118 Tab::~Tab() { | 119 Tab::~Tab() { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 BrowserThemeProvider::COLOR_TAB_TEXT : | 226 BrowserThemeProvider::COLOR_TAB_TEXT : |
226 BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT); | 227 BrowserThemeProvider::COLOR_BACKGROUND_TAB_TEXT); |
227 | 228 |
228 if (!data().mini || width() > kMiniTabRendererAsNormalTabWidth) | 229 if (!data().mini || width() > kMiniTabRendererAsNormalTabWidth) |
229 PaintTitle(canvas, title_color); | 230 PaintTitle(canvas, title_color); |
230 | 231 |
231 if (show_icon) | 232 if (show_icon) |
232 PaintIcon(canvas); | 233 PaintIcon(canvas); |
233 | 234 |
234 // If the close button color has changed, generate a new one. | 235 // If the close button color has changed, generate a new one. |
235 if (!close_button_color_ || title_color != close_button_color_) { | 236 SetCloseButtonColor(title_color); |
236 close_button_color_ = title_color; | |
237 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
238 close_button()->SetBackground(close_button_color_, | |
239 rb.GetBitmapNamed(IDR_TAB_CLOSE), | |
240 rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK)); | |
241 } | |
242 } | 237 } |
243 | 238 |
244 void Tab::Layout() { | 239 void Tab::Layout() { |
245 gfx::Rect lb = GetLocalBounds(false); | 240 gfx::Rect lb = GetLocalBounds(false); |
246 if (lb.IsEmpty()) | 241 if (lb.IsEmpty()) |
247 return; | 242 return; |
248 lb.Inset(kLeftPadding, kTopPadding, kRightPadding, kBottomPadding); | 243 lb.Inset(kLeftPadding, kTopPadding, kRightPadding, kBottomPadding); |
249 | 244 |
250 // The height of the content of the Tab is the largest of the favicon, | 245 // The height of the content of the Tab is the largest of the favicon, |
251 // the title text and the close button graphic. | 246 // the title text and the close button graphic. |
(...skipping 27 matching lines...) Expand all Loading... |
279 (ideal_x - favicon_bounds_.x())); | 274 (ideal_x - favicon_bounds_.x())); |
280 favicon_bounds_.set_x(x); | 275 favicon_bounds_.set_x(x); |
281 } | 276 } |
282 } | 277 } |
283 } else { | 278 } else { |
284 favicon_bounds_.SetRect(lb.x(), lb.y(), 0, 0); | 279 favicon_bounds_.SetRect(lb.x(), lb.y(), 0, 0); |
285 } | 280 } |
286 | 281 |
287 // Size the Close button. | 282 // Size the Close button. |
288 showing_close_button_ = ShouldShowCloseBox(); | 283 showing_close_button_ = ShouldShowCloseBox(); |
| 284 gfx::Insets near_insets; |
289 if (showing_close_button_) { | 285 if (showing_close_button_) { |
290 int close_button_top = | 286 int close_button_top = |
291 kTopPadding + kCloseButtonVertFuzz + | 287 kTopPadding + kCloseButtonVertFuzz + |
292 (content_height - close_button_height()) / 2; | 288 (content_height - close_button_height()) / 2; |
293 // If the ratio of the close button size to tab width exceeds the maximum. | 289 // If the ratio of the close button size to tab width exceeds the maximum. |
294 close_button()->SetBounds(lb.width() + kCloseButtonHorzFuzz, | 290 close_button()->SetBounds(lb.width() + kCloseButtonHorzFuzz, |
295 close_button_top, close_button_width(), | 291 close_button_top, close_button_width(), |
296 close_button_height()); | 292 close_button_height()); |
297 close_button()->SetVisible(true); | 293 close_button()->SetVisible(true); |
| 294 int avail_width = width() - close_button()->bounds().right(); |
| 295 if (avail_width > 0) { |
| 296 View* root = GetRootView(); |
| 297 if (root) { // Root is NULL when dragging. |
| 298 // Enable mouse near events for the region from the top of the browser |
| 299 // to the bottom of the tab. |
| 300 gfx::Point loc; |
| 301 ConvertPointToView(close_button(), GetRootView(), &loc); |
| 302 near_insets.Set(loc.y(), close_button()->x(), |
| 303 height() - close_button()->bounds().bottom(), |
| 304 avail_width); |
| 305 } |
| 306 } |
298 } else { | 307 } else { |
299 close_button()->SetBounds(0, 0, 0, 0); | 308 close_button()->SetBounds(0, 0, 0, 0); |
300 close_button()->SetVisible(false); | 309 close_button()->SetVisible(false); |
301 } | 310 } |
| 311 close_button()->RegisterForMouseNearEvents(near_insets); |
302 | 312 |
303 int title_left = favicon_bounds_.right() + kFavIconTitleSpacing; | 313 int title_left = favicon_bounds_.right() + kFavIconTitleSpacing; |
304 int title_top = kTopPadding + (content_height - font_height()) / 2; | 314 int title_top = kTopPadding + (content_height - font_height()) / 2; |
305 // Size the Title text to fill the remaining space. | 315 // Size the Title text to fill the remaining space. |
306 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) { | 316 if (!data().mini || width() >= kMiniTabRendererAsNormalTabWidth) { |
307 // If the user has big fonts, the title will appear rendered too far down | 317 // If the user has big fonts, the title will appear rendered too far down |
308 // on the y-axis if we use the regular top padding, so we need to adjust it | 318 // on the y-axis if we use the regular top padding, so we need to adjust it |
309 // so that the text appears centered. | 319 // so that the text appears centered. |
310 gfx::Size minimum_size = GetMinimumUnselectedSize(); | 320 gfx::Size minimum_size = GetMinimumUnselectedSize(); |
311 int text_height = title_top + font_height() + kBottomPadding; | 321 int text_height = title_top + font_height() + kBottomPadding; |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 tab_inactive_nano.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_NANO_LEFT); | 702 tab_inactive_nano.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_NANO_LEFT); |
693 tab_inactive_nano.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_NANO_CENTER); | 703 tab_inactive_nano.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_NANO_CENTER); |
694 tab_inactive_nano.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_NANO_RIGHT); | 704 tab_inactive_nano.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_NANO_RIGHT); |
695 tab_inactive_nano.l_width = tab_inactive_nano.image_l->width(); | 705 tab_inactive_nano.l_width = tab_inactive_nano.image_l->width(); |
696 tab_inactive_nano.r_width = tab_inactive_nano.image_r->width(); | 706 tab_inactive_nano.r_width = tab_inactive_nano.image_r->width(); |
697 tab_inactive_nano.y_offset = kNanoTabDiffHeight; | 707 tab_inactive_nano.y_offset = kNanoTabDiffHeight; |
698 | 708 |
699 new_tab_mask = rb.GetBitmapNamed(IDR_TAB_ALPHA_NEW_TAB); | 709 new_tab_mask = rb.GetBitmapNamed(IDR_TAB_ALPHA_NEW_TAB); |
700 new_tab_shadow = rb.GetBitmapNamed(IDR_TAB_NEW_TAB_SHADOW); | 710 new_tab_shadow = rb.GetBitmapNamed(IDR_TAB_NEW_TAB_SHADOW); |
701 } | 711 } |
OLD | NEW |