[Sync] Move reenable logic into DTM
[chromium-blink-merge.git] / ash / display / shared_display_edge_indicator.cc
blobf94a9a5fd1d61767514d596fb1fa4c80b40c1a2f
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 virtual ~IndicatorView() {
32 void SetColor(SkColor color) {
33 color_ = color;
34 SchedulePaint();
37 // views::Views overrides:
38 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
39 canvas->FillRect(gfx::Rect(bounds().size()), color_);
42 private:
43 SkColor color_;
44 DISALLOW_COPY_AND_ASSIGN(IndicatorView);
47 views::Widget* CreateWidget(const gfx::Rect& bounds,
48 views::View* contents_view) {
49 views::Widget* widget = new views::Widget;
50 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
51 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
52 params.keep_on_top = true;
53 // We set the context to the primary root window; this is OK because the ash
54 // stacking controller will still place us in the correct RootWindow.
55 params.context = Shell::GetPrimaryRootWindow();
56 widget->set_focus_on_creation(false);
57 widget->Init(params);
58 widget->SetVisibilityChangedAnimationsEnabled(false);
59 widget->GetNativeWindow()->SetName("SharedEdgeIndicator");
60 widget->SetContentsView(contents_view);
61 gfx::Display display = Shell::GetScreen()->GetDisplayMatching(bounds);
62 aura::Window* window = widget->GetNativeWindow();
63 aura::client::ScreenPositionClient* screen_position_client =
64 aura::client::GetScreenPositionClient(window->GetRootWindow());
65 screen_position_client->SetBounds(window, bounds, display);
66 widget->Show();
67 return widget;
70 } // namespace
72 SharedDisplayEdgeIndicator::SharedDisplayEdgeIndicator()
73 : src_indicator_(NULL),
74 dst_indicator_(NULL) {
77 SharedDisplayEdgeIndicator::~SharedDisplayEdgeIndicator() {
78 Hide();
81 void SharedDisplayEdgeIndicator::Show(const gfx::Rect& src_bounds,
82 const gfx::Rect& dst_bounds) {
83 DCHECK(!src_indicator_);
84 DCHECK(!dst_indicator_);
85 src_indicator_ = new IndicatorView;
86 dst_indicator_ = new IndicatorView;
87 CreateWidget(src_bounds, src_indicator_);
88 CreateWidget(dst_bounds, dst_indicator_);
89 animation_.reset(new gfx::ThrobAnimation(this));
90 animation_->SetThrobDuration(kIndicatorAnimationDurationMs);
91 animation_->StartThrobbing(-1 /* infinite */);
94 void SharedDisplayEdgeIndicator::Hide() {
95 if (src_indicator_)
96 src_indicator_->GetWidget()->Close();
97 src_indicator_ = NULL;
98 if (dst_indicator_)
99 dst_indicator_->GetWidget()->Close();
100 dst_indicator_ = NULL;
103 void SharedDisplayEdgeIndicator::AnimationProgressed(
104 const gfx::Animation* animation) {
105 int value = animation->CurrentValueBetween(0, 255);
106 SkColor color = SkColorSetARGB(0xFF, value, value, value);
107 if (src_indicator_)
108 static_cast<IndicatorView*>(src_indicator_)->SetColor(color);
109 if (dst_indicator_)
110 static_cast<IndicatorView*>(dst_indicator_)->SetColor(color);
114 } // namespace ash