Index: chrome/browser/ui/views/tabs/tab_paint_util.cc |
diff --git a/chrome/browser/ui/views/tabs/tab_paint_util.cc b/chrome/browser/ui/views/tabs/tab_paint_util.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fecc01a0f2a5af7df1d0ce4b53e51e5850d7049b |
--- /dev/null |
+++ b/chrome/browser/ui/views/tabs/tab_paint_util.cc |
@@ -0,0 +1,92 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/views/tabs/tab_paint_util.h" |
+ |
+#include "grit/theme_resources.h" |
+#include "ui/base/theme_provider.h" |
+#include "ui/gfx/canvas.h" |
+#include "ui/gfx/image/canvas_image_source.h" |
+#include "ui/gfx/image/image_skia.h" |
+ |
+namespace { |
+ |
+// An image source used to overlay |background_id| and |background_overlay_id| |
+// for GetTiledInactiveBackground(). |
+class TabBackgroundImageSource: public gfx::CanvasImageSource { |
+ public: |
+ TabBackgroundImageSource(const gfx::ImageSkia& background, |
+ const gfx::ImageSkia& overlay, |
+ int relative_y_offset, |
+ int src_x, |
+ int src_y, |
+ int dst_w, |
+ int dst_h) |
+ : gfx::CanvasImageSource(gfx::Size(dst_w, dst_h), false), |
+ overlay_(overlay), |
+ background_(background), |
+ relative_y_offset_(relative_y_offset), |
+ src_x_(src_x), |
+ src_y_(src_y) { |
+ } |
+ |
+ virtual ~TabBackgroundImageSource() { |
+ } |
+ |
+ // Overridden from CanvasImageSource: |
+ virtual void Draw(gfx::Canvas* canvas) OVERRIDE { |
+ if (!background_.isNull()) { |
+ canvas->TileImageInt(background_, src_x_, src_y_ + relative_y_offset_, |
+ 0, 0, size().width(), size().height()); |
+ } |
+ |
+ if (!overlay_.isNull()) { |
+ canvas->TileImageInt(overlay_, src_x_, src_y_, 0, 0, size().width(), |
+ size().height()); |
+ } |
+ } |
+ |
+ private: |
+ const gfx::ImageSkia overlay_; |
+ const gfx::ImageSkia background_; |
+ const int relative_y_offset_; |
+ const int src_x_; |
+ const int src_y_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TabBackgroundImageSource); |
+}; |
+ |
+} // namespace |
+ |
+// static |
+gfx::ImageSkia TabPaintUtil::CreateTiledInactiveBackground( |
+ ui::ThemeProvider* theme_provider, |
+ int background_id, |
+ int background_overlay_id, |
+ int relative_y_offset, |
+ int src_x, |
+ int src_y, |
+ int dst_w, |
+ int dst_h) { |
+ // Do not paint the ResourceBundle's IDR_THEME_TAB_BACKGROUND_V if the |
+ // theme author provided a custom IDR_THEME_TAB_BACKGROUND_V_OVERLAY. |
+ gfx::ImageSkia background; |
+ if (background_overlay_id != IDR_THEME_TAB_BACKGROUND_V_OVERLAY || |
+ !theme_provider->HasCustomImage(background_overlay_id)) { |
+ background = *theme_provider->GetImageSkiaNamed(background_id); |
+ } |
+ |
+ // The default theme does not provide overlay images. |
+ gfx::ImageSkia background_overlay; |
+ if (theme_provider->HasCustomImage(background_overlay_id)) { |
+ background_overlay = *theme_provider->GetImageSkiaNamed( |
+ background_overlay_id); |
+ } |
+ |
+ // The ImageSkia takes ownership of |source|. |
+ TabBackgroundImageSource* source = new TabBackgroundImageSource( |
+ background, background_overlay, relative_y_offset, src_x, src_y, |
+ dst_w, dst_h); |
+ return gfx::ImageSkia(source, source->size()); |
+} |