Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1688)

Unified Diff: chrome/browser/ui/views/tabs/tab_paint_util.cc

Issue 18486007: Fix the misalignment on CrOS of the tab background images (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_paint_util.h ('k') | chrome/browser/ui/views/tabs/tab_strip.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5e5702a174629fc4b422da6c2f7ab0c18dd16158
--- /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),
+ background_(background),
+ overlay_(overlay),
+ 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 background_;
+ const gfx::ImageSkia overlay_;
+ 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());
+}
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_paint_util.h ('k') | chrome/browser/ui/views/tabs/tab_strip.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698