[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / ash / display / shared_display_edge_indicator.cc
blob1abbbf5a0cfc2601a712371399e998c5a38589f7
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/base/animation/throb_animation.h"
13 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/display.h"
15 #include "ui/gfx/screen.h"
16 #include "ui/views/view.h"
17 #include "ui/views/widget/widget.h"
19 namespace ash {
20 namespace internal {
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.transparent = true;
52 params.can_activate = false;
53 params.keep_on_top = true;
54 widget->set_focus_on_creation(false);
55 widget->Init(params);
56 widget->SetVisibilityChangedAnimationsEnabled(false);
57 widget->GetNativeWindow()->SetName("SharedEdgeIndicator");
58 widget->SetContentsView(contents_view);
59 gfx::Display display = Shell::GetScreen()->GetDisplayMatching(bounds);
60 aura::Window* window = widget->GetNativeWindow();
61 aura::client::ScreenPositionClient* screen_position_client =
62 aura::client::GetScreenPositionClient(window->GetRootWindow());
63 screen_position_client->SetBounds(window, bounds, display);
64 widget->Show();
65 return widget;
68 } // namespace
70 SharedDisplayEdgeIndicator::SharedDisplayEdgeIndicator()
71 : src_indicator_(NULL),
72 dst_indicator_(NULL) {
75 SharedDisplayEdgeIndicator::~SharedDisplayEdgeIndicator() {
76 Hide();
79 void SharedDisplayEdgeIndicator::Show(const gfx::Rect& src_bounds,
80 const gfx::Rect& dst_bounds) {
81 DCHECK(!src_indicator_);
82 DCHECK(!dst_indicator_);
83 src_indicator_ = new IndicatorView;
84 dst_indicator_ = new IndicatorView;
85 CreateWidget(src_bounds, src_indicator_);
86 CreateWidget(src_bounds, dst_indicator_);
87 animation_.reset(new ui::ThrobAnimation(this));
88 animation_->SetThrobDuration(kIndicatorAnimationDurationMs);
89 animation_->StartThrobbing(-1 /* infinite */);
92 void SharedDisplayEdgeIndicator::Hide() {
93 if (src_indicator_)
94 src_indicator_->GetWidget()->Close();
95 src_indicator_ = NULL;
96 if (dst_indicator_)
97 dst_indicator_->GetWidget()->Close();
98 dst_indicator_ = NULL;
101 void SharedDisplayEdgeIndicator::AnimationProgressed(
102 const ui::Animation* animation) {
103 int value = animation->CurrentValueBetween(0, 255);
104 SkColor color = SkColorSetARGB(0xFF, value, value, value);
105 if (src_indicator_)
106 static_cast<IndicatorView*>(src_indicator_)->SetColor(color);
107 if (dst_indicator_)
108 static_cast<IndicatorView*>(dst_indicator_)->SetColor(color);
112 } // namespace internal
113 } // namespace ash