| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 minimum_size.set_width(kLeftPadding + kRightPadding); | 136 minimum_size.set_width(kLeftPadding + kRightPadding); |
| 137 // Since we use bitmap images, the real minimum height of the image is | 137 // Since we use bitmap images, the real minimum height of the image is |
| 138 // defined most accurately by the height of the end cap images. | 138 // defined most accurately by the height of the end cap images. |
| 139 minimum_size.set_height(tab_active_.image_l->height()); | 139 minimum_size.set_height(tab_active_.image_l->height()); |
| 140 return minimum_size; | 140 return minimum_size; |
| 141 } | 141 } |
| 142 | 142 |
| 143 // static | 143 // static |
| 144 gfx::Size Tab::GetMinimumSelectedSize() { | 144 gfx::Size Tab::GetMinimumSelectedSize() { |
| 145 gfx::Size minimum_size = GetMinimumUnselectedSize(); | 145 gfx::Size minimum_size = GetMinimumUnselectedSize(); |
| 146 minimum_size.set_width(kLeftPadding + kFavIconSize + kRightPadding); | 146 minimum_size.set_width(kLeftPadding + kFaviconSize + kRightPadding); |
| 147 return minimum_size; | 147 return minimum_size; |
| 148 } | 148 } |
| 149 | 149 |
| 150 // static | 150 // static |
| 151 gfx::Size Tab::GetStandardSize() { | 151 gfx::Size Tab::GetStandardSize() { |
| 152 gfx::Size standard_size = GetMinimumUnselectedSize(); | 152 gfx::Size standard_size = GetMinimumUnselectedSize(); |
| 153 standard_size.set_width( | 153 standard_size.set_width( |
| 154 standard_size.width() + kFavIconTitleSpacing + kStandardTitleWidth); | 154 standard_size.width() + kFavIconTitleSpacing + kStandardTitleWidth); |
| 155 return standard_size; | 155 return standard_size; |
| 156 } | 156 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 220 } |
| 221 | 221 |
| 222 void Tab::Layout() { | 222 void Tab::Layout() { |
| 223 gfx::Rect lb = GetContentsBounds(); | 223 gfx::Rect lb = GetContentsBounds(); |
| 224 if (lb.IsEmpty()) | 224 if (lb.IsEmpty()) |
| 225 return; | 225 return; |
| 226 lb.Inset(kLeftPadding, kTopPadding, kRightPadding, kBottomPadding); | 226 lb.Inset(kLeftPadding, kTopPadding, kRightPadding, kBottomPadding); |
| 227 | 227 |
| 228 // The height of the content of the Tab is the largest of the favicon, | 228 // The height of the content of the Tab is the largest of the favicon, |
| 229 // the title text and the close button graphic. | 229 // the title text and the close button graphic. |
| 230 int content_height = std::max(kFavIconSize, font_height()); | 230 int content_height = std::max(kFaviconSize, font_height()); |
| 231 gfx::Size close_button_size(close_button()->GetPreferredSize()); | 231 gfx::Size close_button_size(close_button()->GetPreferredSize()); |
| 232 content_height = std::max(content_height, close_button_size.height()); | 232 content_height = std::max(content_height, close_button_size.height()); |
| 233 | 233 |
| 234 // Size the Favicon. | 234 // Size the Favicon. |
| 235 showing_icon_ = ShouldShowIcon(); | 235 showing_icon_ = ShouldShowIcon(); |
| 236 if (showing_icon_) { | 236 if (showing_icon_) { |
| 237 // Use the size of the favicon as apps use a bigger favicon size. | 237 // Use the size of the favicon as apps use a bigger favicon size. |
| 238 int favicon_top = kTopPadding + content_height / 2 - kFavIconSize / 2; | 238 int favicon_top = kTopPadding + content_height / 2 - kFaviconSize / 2; |
| 239 int favicon_left = lb.x(); | 239 int favicon_left = lb.x(); |
| 240 favicon_bounds_.SetRect(favicon_left, favicon_top, | 240 favicon_bounds_.SetRect(favicon_left, favicon_top, |
| 241 kFavIconSize, kFavIconSize); | 241 kFaviconSize, kFaviconSize); |
| 242 if (data().mini && width() < kMiniTabRendererAsNormalTabWidth) { | 242 if (data().mini && width() < kMiniTabRendererAsNormalTabWidth) { |
| 243 // Adjust the location of the favicon when transitioning from a normal | 243 // Adjust the location of the favicon when transitioning from a normal |
| 244 // tab to a mini-tab. | 244 // tab to a mini-tab. |
| 245 int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth(); | 245 int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth(); |
| 246 int ideal_delta = width() - GetMiniWidth(); | 246 int ideal_delta = width() - GetMiniWidth(); |
| 247 if (ideal_delta < mini_delta) { | 247 if (ideal_delta < mini_delta) { |
| 248 int ideal_x = (GetMiniWidth() - kFavIconSize) / 2; | 248 int ideal_x = (GetMiniWidth() - kFaviconSize) / 2; |
| 249 int x = favicon_bounds_.x() + static_cast<int>( | 249 int x = favicon_bounds_.x() + static_cast<int>( |
| 250 (1 - static_cast<float>(ideal_delta) / | 250 (1 - static_cast<float>(ideal_delta) / |
| 251 static_cast<float>(mini_delta)) * | 251 static_cast<float>(mini_delta)) * |
| 252 (ideal_x - favicon_bounds_.x())); | 252 (ideal_x - favicon_bounds_.x())); |
| 253 favicon_bounds_.set_x(x); | 253 favicon_bounds_.set_x(x); |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 } else { | 256 } else { |
| 257 favicon_bounds_.SetRect(lb.x(), lb.y(), 0, 0); | 257 favicon_bounds_.SetRect(lb.x(), lb.y(), 0, 0); |
| 258 } | 258 } |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 hover_canvas.DrawRectInt(hover_point_.x() - radius, | 602 hover_canvas.DrawRectInt(hover_point_.x() - radius, |
| 603 hover_point_.y() - radius, | 603 hover_point_.y() - radius, |
| 604 radius * 2, radius * 2, paint); | 604 radius * 2, radius * 2, paint); |
| 605 } | 605 } |
| 606 return hover_canvas.ExtractBitmap(); | 606 return hover_canvas.ExtractBitmap(); |
| 607 } | 607 } |
| 608 | 608 |
| 609 int Tab::IconCapacity() const { | 609 int Tab::IconCapacity() const { |
| 610 if (height() < GetMinimumUnselectedSize().height()) | 610 if (height() < GetMinimumUnselectedSize().height()) |
| 611 return 0; | 611 return 0; |
| 612 return (width() - kLeftPadding - kRightPadding) / kFavIconSize; | 612 return (width() - kLeftPadding - kRightPadding) / kFaviconSize; |
| 613 } | 613 } |
| 614 | 614 |
| 615 bool Tab::ShouldShowIcon() const { | 615 bool Tab::ShouldShowIcon() const { |
| 616 if (data().mini && height() >= GetMinimumUnselectedSize().height()) | 616 if (data().mini && height() >= GetMinimumUnselectedSize().height()) |
| 617 return true; | 617 return true; |
| 618 if (!data().show_icon) { | 618 if (!data().show_icon) { |
| 619 return false; | 619 return false; |
| 620 } else if (IsSelected()) { | 620 } else if (IsSelected()) { |
| 621 // The selected tab clips favicon before close button. | 621 // The selected tab clips favicon before close button. |
| 622 return IconCapacity() >= 2; | 622 return IconCapacity() >= 2; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); | 667 tab_active_.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); |
| 668 tab_active_.l_width = tab_active_.image_l->width(); | 668 tab_active_.l_width = tab_active_.image_l->width(); |
| 669 tab_active_.r_width = tab_active_.image_r->width(); | 669 tab_active_.r_width = tab_active_.image_r->width(); |
| 670 | 670 |
| 671 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); | 671 tab_inactive_.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); |
| 672 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); | 672 tab_inactive_.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); |
| 673 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); | 673 tab_inactive_.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); |
| 674 tab_inactive_.l_width = tab_inactive_.image_l->width(); | 674 tab_inactive_.l_width = tab_inactive_.image_l->width(); |
| 675 tab_inactive_.r_width = tab_inactive_.image_r->width(); | 675 tab_inactive_.r_width = tab_inactive_.image_r->width(); |
| 676 } | 676 } |
| OLD | NEW |