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

Side by Side Diff: chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view.cc

Issue 2603463002: Adds background fade in animation and exit label to touch calibrator view (Closed)
Patch Set: Resolving comments Created 3 years, 12 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view .h" 5 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view .h"
6 6
7 #include "ash/display/window_tree_host_manager.h" 7 #include "ash/display/window_tree_host_manager.h"
8 #include "ash/public/cpp/shell_window_ids.h" 8 #include "ash/public/cpp/shell_window_ids.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/animation/linear_animation.h"
11 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
14 #include "ui/strings/grit/ui_strings.h"
15 #include "ui/views/controls/label.h"
12 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
13 17
14 namespace chromeos { 18 namespace chromeos {
15 19
16 namespace { 20 namespace {
17 21
18 constexpr char kWidgetName[] = "TouchCalibratorOverlay"; 22 constexpr char kWidgetName[] = "TouchCalibratorOverlay";
19 23
24 constexpr int kAnimationFrameRate = 100;
25 constexpr int kFadeDurationInMs = 150;
26
27 const SkColor kExitLabelColor = SkColorSetARGBInline(255, 96, 96, 96);
28 const SkColor kExitLabelShadowColor = SkColorSetARGBInline(255, 11, 11, 11);
29 constexpr int kExitLabelWidth = 300;
30 constexpr int kExitLabelHeight = 20;
31
32 constexpr float kBackgroundFinalOpacity = 0.75f;
33
20 // Returns the initialization params for the widget that contains the touch 34 // Returns the initialization params for the widget that contains the touch
21 // calibrator view. 35 // calibrator view.
22 views::Widget::InitParams GetWidgetParams(aura::Window* root_window) { 36 views::Widget::InitParams GetWidgetParams(aura::Window* root_window) {
23 views::Widget::InitParams params; 37 views::Widget::InitParams params;
24 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; 38 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
25 params.name = kWidgetName; 39 params.name = kWidgetName;
26 params.keep_on_top = true; 40 params.keep_on_top = true;
27 params.accept_events = true; 41 params.accept_events = true;
28 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; 42 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
29 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 43 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
30 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 44 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
31 params.parent = ash::Shell::GetContainer( 45 params.parent = ash::Shell::GetContainer(
32 root_window, ash::kShellWindowId_OverlayContainer); 46 root_window, ash::kShellWindowId_OverlayContainer);
33 return params; 47 return params;
34 } 48 }
35 49
36 } // namespace 50 } // namespace
37 51
38 TouchCalibratorView::TouchCalibratorView(const display::Display& target_display, 52 TouchCalibratorView::TouchCalibratorView(const display::Display& target_display,
39 bool is_primary_view) 53 bool is_primary_view)
40 : display_(target_display), is_primary_view_(is_primary_view) { 54 : display_(target_display),
55 is_primary_view_(is_primary_view),
56 exit_label_(nullptr) {
41 aura::Window* root = ash::Shell::GetInstance() 57 aura::Window* root = ash::Shell::GetInstance()
42 ->window_tree_host_manager() 58 ->window_tree_host_manager()
43 ->GetRootWindowForDisplayId(display_.id()); 59 ->GetRootWindowForDisplayId(display_.id());
44 widget_.reset(new views::Widget); 60 widget_.reset(new views::Widget);
45 widget_->Init(GetWidgetParams(root)); 61 widget_->Init(GetWidgetParams(root));
46 widget_->SetContentsView(this); 62 widget_->SetContentsView(this);
47 widget_->SetBounds(display_.bounds()); 63 widget_->SetBounds(display_.bounds());
48 widget_->Show(); 64 widget_->Show();
49 set_owned_by_client(); 65 set_owned_by_client();
66
67 animator_.reset(
68 new gfx::LinearAnimation(kFadeDurationInMs, kAnimationFrameRate, this));
69
70 InitViewContents();
71 AdvanceToNextState();
50 } 72 }
51 73
52 TouchCalibratorView::~TouchCalibratorView() { 74 TouchCalibratorView::~TouchCalibratorView() {
53 state_ = UNKNOWN; 75 state_ = UNKNOWN;
54 widget_->Hide(); 76 widget_->Hide();
77 animator_->End();
78 }
79
80 void TouchCalibratorView::InitViewContents() {
81 // Initialize the background rect.
82 background_rect_ =
83 gfx::RectF(0, 0, display_.bounds().width(), display_.bounds().height());
84
85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
86 // Initialize exit label that informs the user how to exit the touch
87 // calibration setup.
88 exit_label_ = new views::Label(
89 rb.GetLocalizedString(IDS_DISPLAY_TOUCH_CALIBRATION_EXIT_LABEL),
90 rb.GetFontListWithDelta(8, gfx::Font::FontStyle::NORMAL,
91 gfx::Font::Weight::NORMAL));
92 exit_label_->SetBounds((display_.bounds().width() - kExitLabelWidth) / 2,
93 display_.bounds().height() * 3.f / 4, kExitLabelWidth,
94 kExitLabelHeight);
95 exit_label_->SetEnabledColor(kExitLabelColor);
96 exit_label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
97 exit_label_->SetShadows(gfx::ShadowValues(
98 1, gfx::ShadowValue(gfx::Vector2d(1, 1), 1, kExitLabelShadowColor)));
99 exit_label_->SetSubpixelRenderingEnabled(false);
100 exit_label_->SetVisible(false);
101
102 AddChildView(exit_label_);
55 } 103 }
56 104
57 void TouchCalibratorView::OnPaint(gfx::Canvas* canvas) { 105 void TouchCalibratorView::OnPaint(gfx::Canvas* canvas) {
58 OnPaintBackground(canvas); 106 OnPaintBackground(canvas);
59 } 107 }
60 108
61 void TouchCalibratorView::OnPaintBackground(gfx::Canvas* canvas) {} 109 void TouchCalibratorView::OnPaintBackground(gfx::Canvas* canvas) {
110 float opacity;
111
112 // If current state is a fade in or fade out state then update opacity
113 // based on how far the animation has progressed.
114 if (animator_ && (state_ == TouchCalibratorView::BACKGROUND_FADING_OUT ||
115 state_ == TouchCalibratorView::BACKGROUND_FADING_IN)) {
116 opacity = static_cast<float>(animator_->CurrentValueBetween(
117 start_opacity_value_, end_opacity_value_));
118 } else {
119 opacity = state_ == BACKGROUND_FADING_OUT ? 0.f : kBackgroundFinalOpacity;
120 }
121
122 paint_.setColor(SkColorSetA(SK_ColorBLACK,
123 std::numeric_limits<uint8_t>::max() * opacity));
124 canvas->DrawRect(background_rect_, paint_);
125 }
62 126
63 void TouchCalibratorView::AnimationProgressed(const gfx::Animation* animation) { 127 void TouchCalibratorView::AnimationProgressed(const gfx::Animation* animation) {
128 SchedulePaint();
64 } 129 }
65 130
66 void TouchCalibratorView::AnimationCanceled(const gfx::Animation* animation) { 131 void TouchCalibratorView::AnimationCanceled(const gfx::Animation* animation) {
67 AnimationEnded(animation); 132 AnimationEnded(animation);
68 } 133 }
69 134
70 void TouchCalibratorView::AnimationEnded(const gfx::Animation* animation) {} 135 void TouchCalibratorView::AnimationEnded(const gfx::Animation* animation) {
136 switch (state_) {
137 case BACKGROUND_FADING_IN:
138 exit_label_->SetVisible(true);
139 state_ = is_primary_view_ ? DISPLAY_POINT_1 : CALIBRATION_COMPLETE;
140 break;
141 default:
142 break;
143 }
144 }
71 145
72 void TouchCalibratorView::AdvanceToNextState() {} 146 void TouchCalibratorView::AdvanceToNextState() {
147 // Stop any previous animations and skip them to the end.
148 animator_->End();
149
150 switch (state_) {
151 case UNKNOWN:
152 case BACKGROUND_FADING_IN:
153 state_ = BACKGROUND_FADING_IN;
154 start_opacity_value_ = 0.f;
155 end_opacity_value_ = kBackgroundFinalOpacity;
156
157 paint_.setStyle(SkPaint::kFill_Style);
158
159 animator_->SetDuration(kFadeDurationInMs);
160 break;
161 default:
162 break;
163 }
164 animator_->Start();
165 }
73 166
74 bool TouchCalibratorView::GetDisplayPointLocation(gfx::Point* location) { 167 bool TouchCalibratorView::GetDisplayPointLocation(gfx::Point* location) {
75 if (!is_primary_view_) 168 if (!is_primary_view_)
76 return false; 169 return false;
77 return false; 170 return false;
78 } 171 }
79 172
80 void TouchCalibratorView::SkipToFinalState() {} 173 void TouchCalibratorView::SkipToFinalState() {}
81 174
175 void TouchCalibratorView::SkipCurrentAnimationForTest() {
176 if (animator_->is_animating())
177 animator_->End();
178 }
179
82 } // namespace chromeos 180 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view.h ('k') | ui/strings/ui_strings.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698