| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 // Inactive selected tabs have their throb value scaled by this. | 89 // Inactive selected tabs have their throb value scaled by this. |
| 90 const double kSelectedTabThrobScale = 0.95 - kSelectedTabOpacity; | 90 const double kSelectedTabThrobScale = 0.95 - kSelectedTabOpacity; |
| 91 | 91 |
| 92 // Offset from the right edge for the start of the pinned title change | 92 // Offset from the right edge for the start of the pinned title change |
| 93 // animation. | 93 // animation. |
| 94 const int kPinnedTitleChangeInitialXOffset = 6; | 94 const int kPinnedTitleChangeInitialXOffset = 6; |
| 95 | 95 |
| 96 // Max number of images to cache. This has to be at least two since rounding | 96 // Max number of images to cache. This has to be at least two since rounding |
| 97 // errors may lead to tabs in the same tabstrip having different sizes. | 97 // errors may lead to tabs in the same tabstrip having different sizes. |
| 98 const size_t kMaxImageCacheSize = 4; | 98 // 8 = normal/incognito, active/inactive, 2 sizes within tabstrip. |
| 99 const size_t kMaxImageCacheSize = 8; |
| 99 | 100 |
| 100 // Height of the miniature tab strip in immersive mode. | 101 // Height of the miniature tab strip in immersive mode. |
| 101 const int kImmersiveTabHeight = 3; | 102 const int kImmersiveTabHeight = 3; |
| 102 | 103 |
| 103 // Height of the small tab indicator rectangles in immersive mode. | 104 // Height of the small tab indicator rectangles in immersive mode. |
| 104 const int kImmersiveBarHeight = 2; | 105 const int kImmersiveBarHeight = 2; |
| 105 | 106 |
| 106 // Color for active and inactive tabs in the immersive mode light strip. These | 107 // Color for active and inactive tabs in the immersive mode light strip. These |
| 107 // should be a little brighter than the color of the normal art assets for tabs, | 108 // should be a little brighter than the color of the normal art assets for tabs, |
| 108 // which for active tabs is 230, 230, 230 and for inactive is 184, 184, 184. | 109 // which for active tabs is 230, 230, 230 and for inactive is 184, 184, 184. |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 canvas, bounds, | 404 canvas, bounds, |
| 404 tp->GetColor(ThemeProperties::COLOR_TAB_THROBBER_SPINNING), | 405 tp->GetColor(ThemeProperties::COLOR_TAB_THROBBER_SPINNING), |
| 405 base::TimeTicks::Now() - loading_start_time_, &waiting_state_); | 406 base::TimeTicks::Now() - loading_start_time_, &waiting_state_); |
| 406 } | 407 } |
| 407 } | 408 } |
| 408 | 409 |
| 409 //////////////////////////////////////////////////////////////////////////////// | 410 //////////////////////////////////////////////////////////////////////////////// |
| 410 // Tab::ImageCacheEntryMetadata | 411 // Tab::ImageCacheEntryMetadata |
| 411 | 412 |
| 412 struct Tab::ImageCacheEntryMetadata { | 413 struct Tab::ImageCacheEntryMetadata { |
| 413 ImageCacheEntryMetadata(bool incognito, | 414 ImageCacheEntryMetadata(int resource_id, |
| 414 int resource_id, | 415 SkColor fill_color, |
| 416 SkColor stroke_color, |
| 415 ui::ScaleFactor scale_factor, | 417 ui::ScaleFactor scale_factor, |
| 416 const gfx::Size& size); | 418 const gfx::Size& size); |
| 419 |
| 417 ~ImageCacheEntryMetadata(); | 420 ~ImageCacheEntryMetadata(); |
| 418 | 421 |
| 419 // Making this a non-member would require a friend declaration in Tab. Bleh. | 422 // Making this a non-member would require a friend declaration in Tab. Bleh. |
| 420 bool operator==(const ImageCacheEntryMetadata& rhs) const; | 423 bool operator==(const ImageCacheEntryMetadata& rhs) const; |
| 421 | 424 |
| 422 // Whether the resource is drawn in an incognito window. This is only set to | 425 int resource_id; // Only needed by pre-MD |
| 423 // true when Material Design is enabled, since before MD tabs in normal and | 426 SkColor fill_color; // Both colors only needed by MD |
| 424 // incognito windows look the same. | 427 SkColor stroke_color; |
| 425 bool incognito; | |
| 426 | |
| 427 int resource_id; | |
| 428 ui::ScaleFactor scale_factor; | 428 ui::ScaleFactor scale_factor; |
| 429 gfx::Size size; | 429 gfx::Size size; |
| 430 }; | 430 }; |
| 431 | 431 |
| 432 Tab::ImageCacheEntryMetadata::ImageCacheEntryMetadata( | 432 Tab::ImageCacheEntryMetadata::ImageCacheEntryMetadata( |
| 433 bool incognito, | |
| 434 int resource_id, | 433 int resource_id, |
| 434 SkColor fill_color, |
| 435 SkColor stroke_color, |
| 435 ui::ScaleFactor scale_factor, | 436 ui::ScaleFactor scale_factor, |
| 436 const gfx::Size& size) | 437 const gfx::Size& size) |
| 437 : incognito(incognito), | 438 : resource_id(resource_id), |
| 438 resource_id(resource_id), | 439 fill_color(fill_color), |
| 440 stroke_color(stroke_color), |
| 439 scale_factor(scale_factor), | 441 scale_factor(scale_factor), |
| 440 size(size) { | 442 size(size) { |
| 441 DCHECK_NE(ui::SCALE_FACTOR_NONE, scale_factor); | 443 DCHECK_NE(ui::SCALE_FACTOR_NONE, scale_factor); |
| 444 |
| 445 // Some fields are only relevant for pre-MD vs. MD. Erase the irrelevant ones |
| 446 // so they don't cause incorrect cache misses. |
| 447 // TODO(pkasting): Remove |resource_id| field when non-MD code is deleted. |
| 448 if (ui::MaterialDesignController::IsModeMaterial()) |
| 449 resource_id = 0; |
| 450 else |
| 451 fill_color = stroke_color = SK_ColorTRANSPARENT; |
| 442 } | 452 } |
| 443 | 453 |
| 444 Tab::ImageCacheEntryMetadata::~ImageCacheEntryMetadata() {} | 454 Tab::ImageCacheEntryMetadata::~ImageCacheEntryMetadata() {} |
| 445 | 455 |
| 446 bool Tab::ImageCacheEntryMetadata::operator==( | 456 bool Tab::ImageCacheEntryMetadata::operator==( |
| 447 const ImageCacheEntryMetadata& rhs) const { | 457 const ImageCacheEntryMetadata& rhs) const { |
| 448 return incognito == rhs.incognito && resource_id == rhs.resource_id && | 458 return resource_id == rhs.resource_id && fill_color == rhs.fill_color && |
| 449 scale_factor == rhs.scale_factor && size == rhs.size; | 459 stroke_color == rhs.stroke_color && scale_factor == rhs.scale_factor && |
| 460 size == rhs.size; |
| 450 } | 461 } |
| 451 | 462 |
| 452 //////////////////////////////////////////////////////////////////////////////// | 463 //////////////////////////////////////////////////////////////////////////////// |
| 453 // Tab::ImageCacheEntry | 464 // Tab::ImageCacheEntry |
| 454 | 465 |
| 455 struct Tab::ImageCacheEntry { | 466 struct Tab::ImageCacheEntry { |
| 456 ImageCacheEntry(const ImageCacheEntryMetadata& metadata, | 467 ImageCacheEntry(const ImageCacheEntryMetadata& metadata, |
| 457 const gfx::ImageSkia& image); | 468 const gfx::ImageSkia& image); |
| 458 ~ImageCacheEntry(); | 469 ~ImageCacheEntry(); |
| 459 | 470 |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 | 1322 |
| 1312 void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) { | 1323 void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) { |
| 1313 bool has_custom_image; | 1324 bool has_custom_image; |
| 1314 int fill_id = controller_->GetBackgroundResourceId(&has_custom_image); | 1325 int fill_id = controller_->GetBackgroundResourceId(&has_custom_image); |
| 1315 | 1326 |
| 1316 // If the theme is providing a custom background image, then its top edge | 1327 // If the theme is providing a custom background image, then its top edge |
| 1317 // should be at the top of the tab. Otherwise, we assume that the background | 1328 // should be at the top of the tab. Otherwise, we assume that the background |
| 1318 // image is a composited foreground + frame image. Note that if the theme is | 1329 // image is a composited foreground + frame image. Note that if the theme is |
| 1319 // only providing a custom frame image, |has_custom_image| will be true, but | 1330 // only providing a custom frame image, |has_custom_image| will be true, but |
| 1320 // we should use the |background_offset_| here. | 1331 // we should use the |background_offset_| here. |
| 1321 const int y_offset = GetThemeProvider()->HasCustomImage(fill_id) ? | 1332 const ui::ThemeProvider* tp = GetThemeProvider(); |
| 1333 const int y_offset = tp->HasCustomImage(fill_id) ? |
| 1322 -GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT) : background_offset_.y(); | 1334 -GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT) : background_offset_.y(); |
| 1323 | 1335 |
| 1324 // We only cache the image when it's the default image and we're not hovered, | 1336 // We only cache the image when it's the default image and we're not hovered, |
| 1325 // to avoid caching a background image that isn't the same for all tabs. | 1337 // to avoid caching a background image that isn't the same for all tabs. |
| 1326 if (has_custom_image || hover_controller_.ShouldDraw()) { | 1338 if (has_custom_image || hover_controller_.ShouldDraw()) { |
| 1327 PaintTabBackgroundUsingFillId(canvas, false, fill_id, has_custom_image, | 1339 PaintTabBackgroundUsingFillId(canvas, false, fill_id, has_custom_image, |
| 1328 y_offset); | 1340 y_offset); |
| 1329 return; | 1341 return; |
| 1330 } | 1342 } |
| 1331 | 1343 |
| 1332 const ImageCacheEntryMetadata metadata( | 1344 const ImageCacheEntryMetadata metadata( |
| 1333 ui::MaterialDesignController::IsModeMaterial() && | 1345 fill_id, tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB), |
| 1334 controller_->IsIncognito(), | 1346 controller_->GetToolbarTopSeparatorColor(), |
| 1335 fill_id, ui::GetSupportedScaleFactor(canvas->image_scale()), size()); | 1347 ui::GetSupportedScaleFactor(canvas->image_scale()), size()); |
| 1336 auto it = std::find_if( | 1348 auto it = std::find_if( |
| 1337 image_cache_->begin(), image_cache_->end(), | 1349 image_cache_->begin(), image_cache_->end(), |
| 1338 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; }); | 1350 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; }); |
| 1339 if (it == image_cache_->end()) { | 1351 if (it == image_cache_->end()) { |
| 1340 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); | 1352 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); |
| 1341 PaintTabBackgroundUsingFillId(&tmp_canvas, false, fill_id, false, y_offset); | 1353 PaintTabBackgroundUsingFillId(&tmp_canvas, false, fill_id, false, y_offset); |
| 1342 image_cache_->emplace_front(metadata, | 1354 image_cache_->emplace_front(metadata, |
| 1343 gfx::ImageSkia(tmp_canvas.ExtractImageRep())); | 1355 gfx::ImageSkia(tmp_canvas.ExtractImageRep())); |
| 1344 if (image_cache_->size() > kMaxImageCacheSize) | 1356 if (image_cache_->size() > kMaxImageCacheSize) |
| 1345 image_cache_->pop_back(); | 1357 image_cache_->pop_back(); |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1760 inactive_images_.image_c = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_CENTER); | 1772 inactive_images_.image_c = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_CENTER); |
| 1761 inactive_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_RIGHT); | 1773 inactive_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_INACTIVE_RIGHT); |
| 1762 inactive_images_.l_width = inactive_images_.image_l->width(); | 1774 inactive_images_.l_width = inactive_images_.image_l->width(); |
| 1763 inactive_images_.r_width = inactive_images_.image_r->width(); | 1775 inactive_images_.r_width = inactive_images_.image_r->width(); |
| 1764 | 1776 |
| 1765 mask_images_.image_l = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_LEFT); | 1777 mask_images_.image_l = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_LEFT); |
| 1766 mask_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_RIGHT); | 1778 mask_images_.image_r = rb.GetImageSkiaNamed(IDR_TAB_ALPHA_RIGHT); |
| 1767 mask_images_.l_width = mask_images_.image_l->width(); | 1779 mask_images_.l_width = mask_images_.image_l->width(); |
| 1768 mask_images_.r_width = mask_images_.image_r->width(); | 1780 mask_images_.r_width = mask_images_.image_r->width(); |
| 1769 } | 1781 } |
| OLD | NEW |