Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / display / shared_display_edge_indicator.cc
blob09d666aea008ba26936a9ed0156950418a001db2
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/display/shared_display_edge_indicator.h"
7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h"
9 #include "ash/wm/coordinate_conversion.h"
10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/aura/client/screen_position_client.h"
12 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/gfx/animation/throb_animation.h"
14 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/display.h"
16 #include "ui/gfx/screen.h"
17 #include "ui/views/view.h"
18 #include "ui/views/widget/widget.h"
20 namespace ash {
21 namespace {
23 const int kIndicatorAnimationDurationMs = 1000;
25 class IndicatorView : public views::View {
26 public:
27 IndicatorView() {
29 ~IndicatorView() override {}
31 void SetColor(SkColor color) {
32 color_ = color;
33 SchedulePaint();
36 // views::Views overrides:
37 void OnPaint(gfx::Canvas* canvas) override {
38 canvas->FillRect(gfx::Rect(bounds().size()), color_);
41 private:
42 SkColor color_;
43 DISALLOW_COPY_AND_ASSIGN(IndicatorView);
46 views::Widget* CreateWidget(const gfx::Rect& bounds,
47 views::View* contents_view) {
48 views::Widget* widget = new views::Widget;
49 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
50 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
51 params.keep_on_top = true;
52 // We set the context to the primary root window; this is OK because the ash
53 // stacking controller will still place us in the correct RootWindow.
54 params.context = Shell::GetPrimaryRootWindow();
55 widget->set_focus_on_creation(false);
56 widget->Init(params);
57 widget->SetVisibilityChangedAnimationsEnabled(false);
58 widget->GetNativeWindow()->SetName("SharedEdgeIndicator");
59 widget->SetContentsView(contents_view);
60 gfx::Display display = Shell::GetScreen()->GetDisplayMatching(bounds);
61 aura::Window* window = widget->GetNativeWindow();
62 aura::client::ScreenPositionClient* screen_position_client =
63 aura::client::GetScreenPositionClient(window->GetRootWindow());
64 screen_position_client->SetBounds(window, bounds, display);
65 widget->Show();
66 return widget;
69 } // namespace
71 SharedDisplayEdgeIndicator::SharedDisplayEdgeIndicator()
72 : src_indicator_(NULL),
73 dst_indicator_(NULL) {
76 SharedDisplayEdgeIndicator::~SharedDisplayEdgeIndicator() {
77 Hide();
80 void SharedDisplayEdgeIndicator::Show(const gfx::Rect& src_bounds,
81 const gfx::Rect& dst_bounds) {
82 DCHECK(!src_indicator_);
83 DCHECK(!dst_indicator_);
84 src_indicator_ = new IndicatorView;
85 dst_indicator_ = new IndicatorView;
86 CreateWidget(src_bounds, src_indicator_);
87 CreateWidget(dst_bounds, dst_indicator_);
88 animation_.reset(new gfx::ThrobAnimation(this));
89 animation_->SetThrobDuration(kIndicatorAnimationDurationMs);
90 animation_->StartThrobbing(-1 /* infinite */);
93 void SharedDisplayEdgeIndicator::Hide() {
94 if (src_indicator_)
95 src_indicator_->GetWidget()->Close();
96 src_indicator_ = NULL;
97 if (dst_indicator_)
98 dst_indicator_->GetWidget()->Close();
99 dst_indicator_ = NULL;
102 void SharedDisplayEdgeIndicator::AnimationProgressed(
103 const gfx::Animation* animation) {
104 int value = animation->CurrentValueBetween(0, 255);
105 SkColor color = SkColorSetARGB(0xFF, value, value, value);
106 if (src_indicator_)
107 static_cast<IndicatorView*>(src_indicator_)->SetColor(color);
108 if (dst_indicator_)
109 static_cast<IndicatorView*>(dst_indicator_)->SetColor(color);
113 } // namespace ash