OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/views/tabs/tab_util.h" |
| 6 |
| 7 #include "grit/theme_resources.h" |
| 8 #include "ui/base/theme_provider.h" |
| 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/image/canvas_image_source.h" |
| 11 #include "ui/gfx/image/image_skia.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 // An image source used to overlay |background_id| and |background_overlay_id| |
| 16 // for GetTiledInactiveBackground(). |
| 17 class TabBackgroundImageSource: public gfx::CanvasImageSource { |
| 18 public: |
| 19 TabBackgroundImageSource(const gfx::ImageSkia& background, |
| 20 const gfx::ImageSkia& overlay, |
| 21 int relative_y_offset, |
| 22 int src_x, |
| 23 int src_y, |
| 24 int dst_w, |
| 25 int dst_h) |
| 26 : gfx::CanvasImageSource(gfx::Size(dst_w, dst_h), false), |
| 27 overlay_(overlay), |
| 28 background_(background), |
| 29 relative_y_offset_(relative_y_offset), |
| 30 src_x_(src_x), |
| 31 src_y_(src_y) { |
| 32 } |
| 33 |
| 34 virtual ~TabBackgroundImageSource() { |
| 35 } |
| 36 |
| 37 // Overridden from CanvasImageSource: |
| 38 virtual void Draw(gfx::Canvas* canvas) OVERRIDE { |
| 39 if (!background_.isNull()) { |
| 40 canvas->TileImageInt(background_, src_x_, src_y_ + relative_y_offset_, |
| 41 0, 0, size().width(), size().height()); |
| 42 } |
| 43 |
| 44 if (!overlay_.isNull()) { |
| 45 // We do not tile |overlay_| vertically because we have always done it |
| 46 // that way. |
| 47 // TODO: Investigate if any themes rely on the vertical tiling behavior. |
| 48 int dst_overlay_height = std::min(size().height() + src_y_, |
| 49 overlay_.height()); |
| 50 canvas->TileImageInt(overlay_, src_x_, src_y_, 0, 0, |
| 51 size().width(), dst_overlay_height); |
| 52 } |
| 53 } |
| 54 |
| 55 private: |
| 56 const gfx::ImageSkia overlay_; |
| 57 const gfx::ImageSkia background_; |
| 58 const int relative_y_offset_; |
| 59 int src_x_; |
| 60 int src_y_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(TabBackgroundImageSource); |
| 63 }; |
| 64 |
| 65 } // namespace |
| 66 |
| 67 // static |
| 68 gfx::ImageSkia TabUtil::CreateTiledInactiveBackground( |
| 69 ui::ThemeProvider* theme_provider, |
| 70 int background_id, |
| 71 int background_overlay_id, |
| 72 int relative_y_offset, |
| 73 int src_x, |
| 74 int src_y, |
| 75 int dst_w, |
| 76 int dst_h) { |
| 77 // Do not paint the ResourceBundle's IDR_THEME_TAB_BACKGROUND_V if the |
| 78 // theme author provided a custom IDR_THEME_TAB_BACKGROUND_V_OVERLAY. |
| 79 gfx::ImageSkia background; |
| 80 if (background_overlay_id != IDR_THEME_TAB_BACKGROUND_V_OVERLAY || |
| 81 !theme_provider->HasCustomImage(background_overlay_id)) { |
| 82 background = *theme_provider->GetImageSkiaNamed(background_id); |
| 83 } |
| 84 |
| 85 // The default theme does not provide overlay images. |
| 86 gfx::ImageSkia background_overlay; |
| 87 if (theme_provider->HasCustomImage(background_overlay_id)) { |
| 88 background_overlay = *theme_provider->GetImageSkiaNamed( |
| 89 background_overlay_id); |
| 90 } |
| 91 |
| 92 // The ImageSkia takes ownership of |source|. |
| 93 TabBackgroundImageSource* source = new TabBackgroundImageSource( |
| 94 background, background_overlay, relative_y_offset, src_x, src_y, |
| 95 dst_w, dst_h); |
| 96 return gfx::ImageSkia(source, source->size()); |
| 97 } |
OLD | NEW |