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_paint_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 canvas->TileImageInt(overlay_, src_x_, src_y_, 0, 0, size().width(), |
| 46 size().height()); |
| 47 } |
| 48 } |
| 49 |
| 50 private: |
| 51 const gfx::ImageSkia overlay_; |
| 52 const gfx::ImageSkia background_; |
| 53 const int relative_y_offset_; |
| 54 const int src_x_; |
| 55 const int src_y_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(TabBackgroundImageSource); |
| 58 }; |
| 59 |
| 60 } // namespace |
| 61 |
| 62 // static |
| 63 gfx::ImageSkia TabPaintUtil::CreateTiledInactiveBackground( |
| 64 ui::ThemeProvider* theme_provider, |
| 65 int background_id, |
| 66 int background_overlay_id, |
| 67 int relative_y_offset, |
| 68 int src_x, |
| 69 int src_y, |
| 70 int dst_w, |
| 71 int dst_h) { |
| 72 // Do not paint the ResourceBundle's IDR_THEME_TAB_BACKGROUND_V if the |
| 73 // theme author provided a custom IDR_THEME_TAB_BACKGROUND_V_OVERLAY. |
| 74 gfx::ImageSkia background; |
| 75 if (background_overlay_id != IDR_THEME_TAB_BACKGROUND_V_OVERLAY || |
| 76 !theme_provider->HasCustomImage(background_overlay_id)) { |
| 77 background = *theme_provider->GetImageSkiaNamed(background_id); |
| 78 } |
| 79 |
| 80 // The default theme does not provide overlay images. |
| 81 gfx::ImageSkia background_overlay; |
| 82 if (theme_provider->HasCustomImage(background_overlay_id)) { |
| 83 background_overlay = *theme_provider->GetImageSkiaNamed( |
| 84 background_overlay_id); |
| 85 } |
| 86 |
| 87 // The ImageSkia takes ownership of |source|. |
| 88 TabBackgroundImageSource* source = new TabBackgroundImageSource( |
| 89 background, background_overlay, relative_y_offset, src_x, src_y, |
| 90 dst_w, dst_h); |
| 91 return gfx::ImageSkia(source, source->size()); |
| 92 } |
OLD | NEW |