Commit c44533a0 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

desks: Add shadow to mini views.

Test: manual
Bug: 988521

Change-Id: Iee9cc88044ecdef9b42645cadce9dd2037918dec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1771672
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692105}
parent 370aa40f
......@@ -12,7 +12,10 @@
#include "base/containers/flat_map.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_tree_owner.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/skia_paint_util.h"
namespace ash {
......@@ -26,7 +29,10 @@ constexpr int kDeskPreviewHeight = 64;
constexpr int kBorderSize = 2;
// The rounded corner radii, also in dips.
constexpr gfx::RoundedCornersF kCornerRadii(4);
constexpr int kCornerRadius = 4;
constexpr gfx::RoundedCornersF kCornerRadii(kCornerRadius);
constexpr int kShadowElevation = 4;
// Holds data about the original desk's layers to determine what we should do
// when we attempt to mirror those layers.
......@@ -136,6 +142,56 @@ void GetLayersData(aura::Window* window,
} // namespace
// -----------------------------------------------------------------------------
// DeskPreviewView::ShadowRenderer
// Layer delegate which handles drawing a shadow around DeskPreviewView.
class DeskPreviewView::ShadowRenderer : public ui::LayerDelegate {
public:
ShadowRenderer()
: shadow_values_(gfx::ShadowValue::MakeMdShadowValues(kShadowElevation)) {
}
~ShadowRenderer() override = default;
gfx::Rect GetPaintedBounds() const {
gfx::Rect total_rect(bounds_);
total_rect.Inset(gfx::ShadowValue::GetMargin(shadow_values_));
return total_rect;
}
void set_bounds(const gfx::Rect& bounds) { bounds_ = bounds; }
private:
// ui::LayerDelegate:
void OnPaintLayer(const ui::PaintContext& context) override {
ui::PaintRecorder recorder(context, bounds_.size());
cc::PaintFlags shadow_flags;
shadow_flags.setAntiAlias(true);
shadow_flags.setLooper(gfx::CreateShadowDrawLooper(shadow_values_));
const gfx::Rect rrect_bounds =
bounds_ - GetPaintedBounds().OffsetFromOrigin();
const auto r_rect = SkRRect::MakeRectXY(gfx::RectToSkRect(rrect_bounds),
kCornerRadius, kCornerRadius);
recorder.canvas()->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference,
/*do_anti_alias=*/true);
recorder.canvas()->sk_canvas()->drawRRect(r_rect, shadow_flags);
}
void OnDeviceScaleFactorChanged(float old_device_scale_factor,
float new_device_scale_factor) override {}
gfx::Rect bounds_;
const gfx::ShadowValues shadow_values_;
DISALLOW_COPY_AND_ASSIGN(ShadowRenderer);
};
// -----------------------------------------------------------------------------
// DeskPreviewView
DeskPreviewView::DeskPreviewView(DeskMiniView* mini_view)
: mini_view_(mini_view),
background_view_(new views::View),
......@@ -143,11 +199,16 @@ DeskPreviewView::DeskPreviewView(DeskMiniView* mini_view)
desk_mirrored_contents_view_(new views::View),
force_occlusion_tracker_visible_(
std::make_unique<aura::WindowOcclusionTracker::ScopedForceVisible>(
mini_view->GetDeskContainer())) {
mini_view->GetDeskContainer())),
shadow_delegate_(std::make_unique<ShadowRenderer>()) {
DCHECK(mini_view_);
SetPaintToLayer(ui::LAYER_NOT_DRAWN);
layer()->SetMasksToBounds(true);
layer()->SetMasksToBounds(false);
shadow_layer_.SetFillsBoundsOpaquely(false);
layer()->Add(&shadow_layer_);
shadow_layer_.set_delegate(shadow_delegate_.get());
background_view_->SetPaintToLayer(ui::LAYER_SOLID_COLOR);
auto* background_layer = background_view_->layer();
......@@ -218,6 +279,8 @@ const char* DeskPreviewView::GetClassName() const {
void DeskPreviewView::Layout() {
gfx::Rect bounds = GetLocalBounds();
shadow_delegate_->set_bounds(bounds);
shadow_layer_.SetBounds(shadow_delegate_->GetPaintedBounds());
background_view_->SetBoundsRect(bounds);
bounds.Inset(kBorderSize, kBorderSize);
wallpaper_preview_->SetBoundsRect(bounds);
......
......@@ -79,6 +79,8 @@ class DeskPreviewView : public views::View {
void Layout() override;
private:
class ShadowRenderer;
DeskMiniView* const mini_view_;
// A view to paint a background color behind the |wallpaper_preview_| to
......@@ -107,6 +109,9 @@ class DeskPreviewView : public views::View {
std::unique_ptr<aura::WindowOcclusionTracker::ScopedForceVisible>
force_occlusion_tracker_visible_;
ui::Layer shadow_layer_;
std::unique_ptr<ShadowRenderer> shadow_delegate_;
DISALLOW_COPY_AND_ASSIGN(DeskPreviewView);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment