| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
| (...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); | 1172 gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); |
| 1173 canvas->DrawImageInt(background_image, 0, 0); | 1173 canvas->DrawImageInt(background_image, 0, 0); |
| 1174 gfx::Canvas hover_canvas(size(), canvas->image_scale(), false); | 1174 gfx::Canvas hover_canvas(size(), canvas->image_scale(), false); |
| 1175 DrawHighlight(&hover_canvas, p, SkFloatToScalar(radius), alpha); | 1175 DrawHighlight(&hover_canvas, p, SkFloatToScalar(radius), alpha); |
| 1176 gfx::ImageSkia hover_image = gfx::ImageSkiaOperations::CreateMaskedImage( | 1176 gfx::ImageSkia hover_image = gfx::ImageSkiaOperations::CreateMaskedImage( |
| 1177 gfx::ImageSkia(hover_canvas.ExtractImageRep()), background_image); | 1177 gfx::ImageSkia(hover_canvas.ExtractImageRep()), background_image); |
| 1178 canvas->DrawImageInt(hover_image, 0, 0); | 1178 canvas->DrawImageInt(hover_image, 0, 0); |
| 1179 } | 1179 } |
| 1180 | 1180 |
| 1181 void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) { | 1181 void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) { |
| 1182 int fill_id, frame_id; | 1182 bool has_custom_image; |
| 1183 GetTabIdAndFrameId(GetWidget(), &fill_id, &frame_id); | 1183 int fill_id = controller_->GetBackgroundResourceId(&has_custom_image); |
| 1184 // HasCustomImage() is only true if the theme provides the image. However, | |
| 1185 // even if the theme does not provide a tab background, the theme machinery | |
| 1186 // will make one if given a frame image. | |
| 1187 ui::ThemeProvider* theme_provider = GetThemeProvider(); | |
| 1188 const bool has_custom_image = theme_provider->HasCustomImage(fill_id) || | |
| 1189 (frame_id != 0 && theme_provider->HasCustomImage(frame_id)); | |
| 1190 | |
| 1191 // Explicitly map the id so we cache correctly. | 1184 // Explicitly map the id so we cache correctly. |
| 1192 const chrome::HostDesktopType host_desktop_type = GetHostDesktopType(this); | 1185 const chrome::HostDesktopType host_desktop_type = GetHostDesktopType(this); |
| 1193 fill_id = chrome::MapThemeImage(host_desktop_type, fill_id); | 1186 fill_id = chrome::MapThemeImage(host_desktop_type, fill_id); |
| 1194 | 1187 |
| 1195 // If the theme is providing a custom background image, then its top edge | 1188 // If the theme is providing a custom background image, then its top edge |
| 1196 // should be at the top of the tab. Otherwise, we assume that the background | 1189 // should be at the top of the tab. Otherwise, we assume that the background |
| 1197 // image is a composited foreground + frame image. | 1190 // image is a composited foreground + frame image. |
| 1198 const int y_offset = GetThemeProvider()->HasCustomImage(fill_id) ? | 1191 const int y_offset = GetThemeProvider()->HasCustomImage(fill_id) ? |
| 1199 0 : background_offset_.y(); | 1192 0 : background_offset_.y(); |
| 1200 | 1193 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 // The main bar is as wide as the normal tab's horizontal top line. | 1477 // The main bar is as wide as the normal tab's horizontal top line. |
| 1485 // This top line of the tab extends a few pixels left and right of the | 1478 // This top line of the tab extends a few pixels left and right of the |
| 1486 // center image due to pixels in the rounded corner images. | 1479 // center image due to pixels in the rounded corner images. |
| 1487 const int kBarPadding = 1; | 1480 const int kBarPadding = 1; |
| 1488 int main_bar_left = active_images_.l_width - kBarPadding; | 1481 int main_bar_left = active_images_.l_width - kBarPadding; |
| 1489 int main_bar_right = width() - active_images_.r_width + kBarPadding; | 1482 int main_bar_right = width() - active_images_.r_width + kBarPadding; |
| 1490 return gfx::Rect( | 1483 return gfx::Rect( |
| 1491 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); | 1484 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); |
| 1492 } | 1485 } |
| 1493 | 1486 |
| 1494 void Tab::GetTabIdAndFrameId(views::Widget* widget, | |
| 1495 int* tab_id, | |
| 1496 int* frame_id) const { | |
| 1497 if (widget && | |
| 1498 widget->GetTopLevelWidget()->ShouldWindowContentsBeTransparent()) { | |
| 1499 *tab_id = IDR_THEME_TAB_BACKGROUND_V; | |
| 1500 *frame_id = 0; | |
| 1501 } else if (data().incognito) { | |
| 1502 *tab_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; | |
| 1503 *frame_id = IDR_THEME_FRAME_INCOGNITO; | |
| 1504 } else { | |
| 1505 *tab_id = IDR_THEME_TAB_BACKGROUND; | |
| 1506 *frame_id = IDR_THEME_FRAME; | |
| 1507 } | |
| 1508 } | |
| 1509 | |
| 1510 //////////////////////////////////////////////////////////////////////////////// | 1487 //////////////////////////////////////////////////////////////////////////////// |
| 1511 // Tab, private static: | 1488 // Tab, private static: |
| 1512 | 1489 |
| 1513 // static | 1490 // static |
| 1514 void Tab::InitTabResources() { | 1491 void Tab::InitTabResources() { |
| 1515 static bool initialized = false; | 1492 static bool initialized = false; |
| 1516 if (initialized) | 1493 if (initialized) |
| 1517 return; | 1494 return; |
| 1518 | 1495 |
| 1519 initialized = true; | 1496 initialized = true; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1566 const gfx::ImageSkia& image) { | 1543 const gfx::ImageSkia& image) { |
| 1567 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1544 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
| 1568 ImageCacheEntry entry; | 1545 ImageCacheEntry entry; |
| 1569 entry.resource_id = resource_id; | 1546 entry.resource_id = resource_id; |
| 1570 entry.scale_factor = scale_factor; | 1547 entry.scale_factor = scale_factor; |
| 1571 entry.image = image; | 1548 entry.image = image; |
| 1572 image_cache_->push_front(entry); | 1549 image_cache_->push_front(entry); |
| 1573 if (image_cache_->size() > kMaxImageCacheSize) | 1550 if (image_cache_->size() > kMaxImageCacheSize) |
| 1574 image_cache_->pop_back(); | 1551 image_cache_->pop_back(); |
| 1575 } | 1552 } |
| OLD | NEW |