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

Unified Diff: chrome/browser/ui/views/tabs/tab_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, 5 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
Index: chrome/browser/ui/views/tabs/tab_util.cc
diff --git a/chrome/browser/ui/views/tabs/tab_util.cc b/chrome/browser/ui/views/tabs/tab_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d4c2c27f20ecff76ee7bd5bf933457aa4f66abd8
--- /dev/null
+++ b/chrome/browser/ui/views/tabs/tab_util.cc
@@ -0,0 +1,97 @@
+// 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_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()) {
+ // We do not tile |overlay_| vertically because we have always done it
+ // that way.
+ // TODO: Investigate if any themes rely on the vertical tiling behavior.
+ int dst_overlay_height = std::min(size().height() + src_y_,
+ overlay_.height());
+ canvas->TileImageInt(overlay_, src_x_, src_y_, 0, 0,
+ size().width(), dst_overlay_height);
+ }
+ }
+
+ private:
+ const gfx::ImageSkia overlay_;
+ const gfx::ImageSkia background_;
+ const int relative_y_offset_;
+ int src_x_;
+ int src_y_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabBackgroundImageSource);
+};
+
+} // namespace
+
+// static
+gfx::ImageSkia TabUtil::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());
+}

Powered by Google App Engine
This is Rietveld 408576698