Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: ash/display/shared_display_edge_indicator.cc

Issue 10917090: Update drag edge indicator view per request by UX team (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/display/shared_display_edge_indicator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/display/shared_display_edge_indicator.h" 5 #include "ash/display/shared_display_edge_indicator.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "ash/wm/coordinate_conversion.h" 9 #include "ash/wm/coordinate_conversion.h"
10 #include "third_party/skia/include/core/SkColor.h" 10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/aura/client/screen_position_client.h" 11 #include "ui/aura/client/screen_position_client.h"
12 #include "ui/base/animation/throb_animation.h" 12 #include "ui/base/animation/throb_animation.h"
13 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/display.h" 14 #include "ui/gfx/display.h"
15 #include "ui/gfx/screen.h" 15 #include "ui/gfx/screen.h"
16 #include "ui/views/painter.h" 16 #include "ui/views/view.h"
17 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
18 18
19 namespace ash { 19 namespace ash {
20 namespace internal { 20 namespace internal {
21 namespace { 21 namespace {
22 22
23 const int kIndicatorAnimationDurationMs = 1000; 23 const int kIndicatorAnimationDurationMs = 1000;
24 24
25 views::Widget* CreateWidget(const gfx::Rect& bounds) { 25 class IndicatorView : public views::View {
26 // This is just a placeholder and we'll use an image. 26 public:
27 views::Painter* painter = views::Painter::CreateHorizontalGradient( 27 IndicatorView() {
28 SK_ColorWHITE, SK_ColorWHITE); 28 }
29 virtual ~IndicatorView() {
30 }
29 31
32 void SetColor(SkColor color) {
33 color_ = color;
34 SchedulePaint();
35 }
36
37 // views::Views overrides:
38 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
39 canvas->FillRect(gfx::Rect(bounds().size()), color_);
40 }
41
42 private:
43 SkColor color_;
44 DISALLOW_COPY_AND_ASSIGN(IndicatorView);
45 };
46
47 views::Widget* CreateWidget(const gfx::Rect& bounds,
48 views::View* contents_view) {
30 views::Widget* widget = new views::Widget; 49 views::Widget* widget = new views::Widget;
31 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 50 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
32 params.transparent = true; 51 params.transparent = true;
33 params.can_activate = false; 52 params.can_activate = false;
34 params.keep_on_top = true; 53 params.keep_on_top = true;
35 widget->set_focus_on_creation(false); 54 widget->set_focus_on_creation(false);
36 widget->Init(params); 55 widget->Init(params);
37 widget->SetVisibilityChangedAnimationsEnabled(false); 56 widget->SetVisibilityChangedAnimationsEnabled(false);
38 widget->GetNativeWindow()->SetName("SharedEdgeIndicator"); 57 widget->GetNativeWindow()->SetName("SharedEdgeIndicator");
39 views::View* content_view = new views::View; 58 widget->SetContentsView(contents_view);
40 content_view->set_background(
41 views::Background::CreateBackgroundPainter(true, painter));
42 widget->SetContentsView(content_view);
43 gfx::Display display = gfx::Screen::GetDisplayMatching(bounds); 59 gfx::Display display = gfx::Screen::GetDisplayMatching(bounds);
44 aura::Window* window = widget->GetNativeWindow(); 60 aura::Window* window = widget->GetNativeWindow();
45 aura::client::ScreenPositionClient* screen_position_client = 61 aura::client::ScreenPositionClient* screen_position_client =
46 aura::client::GetScreenPositionClient(window->GetRootWindow()); 62 aura::client::GetScreenPositionClient(window->GetRootWindow());
47 screen_position_client->SetBounds(window, bounds, display); 63 screen_position_client->SetBounds(window, bounds, display);
48 widget->SetOpacity(0);
49 widget->Show(); 64 widget->Show();
50 return widget; 65 return widget;
51 } 66 }
52 67
53 } // namespace 68 } // namespace
54 69
55 SharedDisplayEdgeIndicator::SharedDisplayEdgeIndicator() 70 SharedDisplayEdgeIndicator::SharedDisplayEdgeIndicator()
56 : src_widget_(NULL), 71 : src_indicator_(NULL),
57 dst_widget_(NULL) { 72 dst_indicator_(NULL) {
58 } 73 }
59 74
60 SharedDisplayEdgeIndicator::~SharedDisplayEdgeIndicator() { 75 SharedDisplayEdgeIndicator::~SharedDisplayEdgeIndicator() {
61 Hide(); 76 Hide();
62 } 77 }
63 78
64 void SharedDisplayEdgeIndicator::Show(const gfx::Rect& src_bounds, 79 void SharedDisplayEdgeIndicator::Show(const gfx::Rect& src_bounds,
65 const gfx::Rect& dst_bounds) { 80 const gfx::Rect& dst_bounds) {
66 DCHECK(!src_widget_); 81 DCHECK(!src_indicator_);
67 DCHECK(!dst_widget_); 82 DCHECK(!dst_indicator_);
68 src_widget_ = CreateWidget(src_bounds); 83 src_indicator_ = new IndicatorView;
69 dst_widget_ = CreateWidget(dst_bounds); 84 dst_indicator_ = new IndicatorView;
85 CreateWidget(src_bounds, src_indicator_);
86 CreateWidget(src_bounds, dst_indicator_);
70 animation_.reset(new ui::ThrobAnimation(this)); 87 animation_.reset(new ui::ThrobAnimation(this));
71 animation_->SetThrobDuration(kIndicatorAnimationDurationMs); 88 animation_->SetThrobDuration(kIndicatorAnimationDurationMs);
72 animation_->StartThrobbing(-1 /* infinite */); 89 animation_->StartThrobbing(-1 /* infinite */);
73 } 90 }
74 91
75 void SharedDisplayEdgeIndicator::Hide() { 92 void SharedDisplayEdgeIndicator::Hide() {
76 if (src_widget_) 93 if (src_indicator_)
77 src_widget_->Close(); 94 src_indicator_->GetWidget()->Close();
78 src_widget_ = NULL; 95 src_indicator_ = NULL;
79 if (dst_widget_) 96 if (dst_indicator_)
80 dst_widget_->Close(); 97 dst_indicator_->GetWidget()->Close();
81 dst_widget_ = NULL; 98 dst_indicator_ = NULL;
82 } 99 }
83 100
84 void SharedDisplayEdgeIndicator::AnimationProgressed( 101 void SharedDisplayEdgeIndicator::AnimationProgressed(
85 const ui::Animation* animation) { 102 const ui::Animation* animation) {
86 int opacity = animation->CurrentValueBetween(0, 255); 103 int value = animation->CurrentValueBetween(0, 255);
87 if (src_widget_) 104 SkColor color = SkColorSetARGB(0xFF, value, value, value);
88 src_widget_->SetOpacity(opacity); 105 if (src_indicator_)
89 if (dst_widget_) 106 static_cast<IndicatorView*>(src_indicator_)->SetColor(color);
90 dst_widget_->SetOpacity(opacity); 107 if (dst_indicator_)
108 static_cast<IndicatorView*>(dst_indicator_)->SetColor(color);
109
91 } 110 }
92 111
93 } // namespace internal 112 } // namespace internal
94 } // namespace ash 113 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/shared_display_edge_indicator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698