diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-02 22:10:29 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-02 22:10:29 +0000 |
commit | df654901b380956e7833477084866097bbd5a29d (patch) | |
tree | 1353871a137d58797162aeffdb6120721f3d4c2e /content/browser/web_contents/aura | |
parent | b7ae35675e92b1a36388f11f9cdbe6497a4410f9 (diff) | |
download | chromium_src-df654901b380956e7833477084866097bbd5a29d.zip chromium_src-df654901b380956e7833477084866097bbd5a29d.tar.gz chromium_src-df654901b380956e7833477084866097bbd5a29d.tar.bz2 |
gesture nav: Change how the shadows are painted.
Instead of creating a new parent aura::Window just for drawing the shadow,
and then duplicating that code for the overscroll window, create a single
layer for drawing the shadow (ShadowLayerDelegate) and use it for both
purposes. This cleans up a few pieces of code, and makes it possible to
use this same shadow code in a future CL.
BUG=226133, 196607
R=jam@chromium.org, sky@chromium.org
Review URL: https://codereview.chromium.org/14856007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197986 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/web_contents/aura')
-rw-r--r-- | content/browser/web_contents/aura/shadow_layer_delegate.cc | 61 | ||||
-rw-r--r-- | content/browser/web_contents/aura/shadow_layer_delegate.h | 46 |
2 files changed, 107 insertions, 0 deletions
diff --git a/content/browser/web_contents/aura/shadow_layer_delegate.cc b/content/browser/web_contents/aura/shadow_layer_delegate.cc new file mode 100644 index 0000000..8ff270b --- /dev/null +++ b/content/browser/web_contents/aura/shadow_layer_delegate.cc @@ -0,0 +1,61 @@ +// 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 "content/browser/web_contents/aura/shadow_layer_delegate.h" + +#include "base/bind.h" +#include "third_party/skia/include/effects/SkGradientShader.h" +#include "ui/aura/window.h" +#include "ui/compositor/layer.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/skia_util.h" + +namespace { + +const SkColor kShadowLightColor = SkColorSetARGB(0x0, 0, 0, 0); +const SkColor kShadowDarkColor = SkColorSetARGB(0x70, 0, 0, 0); +const int kShadowThick = 7; + +} // namespace + +namespace content { + +ShadowLayerDelegate::ShadowLayerDelegate(aura::Window* window) + : layer_(new ui::Layer(ui::LAYER_TEXTURED)) { + layer_->set_delegate(this); + layer_->SetBounds(gfx::Rect(-kShadowThick, 0, kShadowThick, + window->bounds().height())); + layer_->SetFillsBoundsOpaquely(false); + window->layer()->Add(layer_.get()); +} + +ShadowLayerDelegate::~ShadowLayerDelegate() { +} + +void ShadowLayerDelegate::OnPaintLayer(gfx::Canvas* canvas) { + SkPoint points[2]; + const SkColor kShadowColors[2] = { kShadowLightColor, kShadowDarkColor }; + + points[0].iset(0, 0); + points[1].iset(kShadowThick, 0); + + skia::RefPtr<SkShader> shader = skia::AdoptRef( + SkGradientShader::CreateLinear(points, kShadowColors, NULL, + arraysize(points), SkShader::kRepeat_TileMode, NULL)); + + gfx::Rect paint_rect = gfx::Rect(0, 0, kShadowThick, + layer_->bounds().height()); + SkPaint paint; + paint.setShader(shader.get()); + canvas->sk_canvas()->drawRect(gfx::RectToSkRect(paint_rect), paint); +} + +void ShadowLayerDelegate::OnDeviceScaleFactorChanged(float scale_factor) { +} + +base::Closure ShadowLayerDelegate::PrepareForLayerBoundsChange() { + return base::Bind(&base::DoNothing); +} + +} // namespace content diff --git a/content/browser/web_contents/aura/shadow_layer_delegate.h b/content/browser/web_contents/aura/shadow_layer_delegate.h new file mode 100644 index 0000000..25c2fb4 --- /dev/null +++ b/content/browser/web_contents/aura/shadow_layer_delegate.h @@ -0,0 +1,46 @@ +// 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. + +#ifndef CONTENT_BROWSER_WEB_CONTENTS_AURA_SHADOW_LAYER_DELEGATE_H_ +#define CONTENT_BROWSER_WEB_CONTENTS_AURA_SHADOW_LAYER_DELEGATE_H_ + +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "ui/compositor/layer_delegate.h" + +namespace aura { +class Window; +} + +namespace ui { +class Layer; +} + +namespace content { + +// ShadowLayerDelegate takes care of drawing a shadow on the left edge of a +// window. +class ShadowLayerDelegate : public ui::LayerDelegate { + public: + explicit ShadowLayerDelegate(aura::Window* shadow_for); + virtual ~ShadowLayerDelegate(); + + // Returns the layer for the shadow. Note that the ShadowLayerDelegate owns + // the layer, and the layer is destroyed when the delegate is destroyed. + ui::Layer* layer() { return layer_.get(); } + + private: + // Overridden from ui::LayerDelegate: + virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE; + virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; + virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE; + + scoped_ptr<ui::Layer> layer_; + + DISALLOW_COPY_AND_ASSIGN(ShadowLayerDelegate); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_WEB_CONTENTS_AURA_SHADOW_LAYER_DELEGATE_H_ |