Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 const int kAnimationFrameRate = 100; | |
| 25 const int kFadeDurationInMs = 150; | |
| 26 | |
| 27 const SkColor kExitLabelColor = SkColorSetARGBInline(255, 96, 96, 96); | |
| 28 const SkColor kExitLabelShadowColor = SkColorSetARGBInline(255, 11, 11, 11); | |
| 29 const int kExitLabelWidth = 300; | |
| 30 const int kExitLabelHeight = 20; | |
| 31 | |
| 32 const float kBackgroundFinalOpacity = 0.75f; | |
|
stevenjb
2016/12/22 22:03:32
constexpr for all of these.
malaykeshav
2016/12/23 00:09:06
done
| |
| 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 if (exit_label_) | |
| 79 delete exit_label_; | |
|
stevenjb
2016/12/22 22:03:33
Views are owned by the views hierarchy, this shoul
malaykeshav
2016/12/23 00:09:06
Done
| |
| 80 } | |
| 81 | |
| 82 void TouchCalibratorView::InitViewContents() { | |
| 83 // Initialize the background rect. | |
| 84 background_rect_ = | |
| 85 gfx::RectF(0, 0, display_.bounds().width(), display_.bounds().height()); | |
| 86 | |
| 87 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 88 // Initialize exit label that informs the user how to exit the touch | |
| 89 // calibration setup. | |
| 90 exit_label_ = new views::Label( | |
| 91 rb.GetLocalizedString(IDS_DISPLAY_TOUCH_CALIBRATION_EXIT_LABEL), | |
| 92 rb.GetFontListWithDelta(8, gfx::Font::FontStyle::NORMAL, | |
| 93 gfx::Font::Weight::NORMAL)); | |
| 94 exit_label_->SetBounds((display_.bounds().width() - kExitLabelWidth) / 2, | |
| 95 3 * display_.bounds().height() / 4, kExitLabelWidth, | |
|
stevenjb
2016/12/22 22:03:33
nit: display_.bounds().height() * 3 / 4 is a littl
malaykeshav
2016/12/23 00:09:06
Done
| |
| 96 kExitLabelHeight); | |
| 97 exit_label_->SetEnabledColor(kExitLabelColor); | |
| 98 exit_label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | |
| 99 exit_label_->SetShadows(gfx::ShadowValues( | |
| 100 1, gfx::ShadowValue(gfx::Vector2d(1, 1), 1, kExitLabelShadowColor))); | |
| 101 exit_label_->SetSubpixelRenderingEnabled(false); | |
| 102 exit_label_->SetVisible(false); | |
| 103 | |
| 104 AddChildView(exit_label_); | |
| 55 } | 105 } |
| 56 | 106 |
| 57 void TouchCalibratorView::OnPaint(gfx::Canvas* canvas) { | 107 void TouchCalibratorView::OnPaint(gfx::Canvas* canvas) { |
| 58 OnPaintBackground(canvas); | 108 OnPaintBackground(canvas); |
| 59 } | 109 } |
| 60 | 110 |
| 61 void TouchCalibratorView::OnPaintBackground(gfx::Canvas* canvas) {} | 111 void TouchCalibratorView::OnPaintBackground(gfx::Canvas* canvas) { |
| 112 float opacity = | |
| 113 state_ == BACKGROUND_FADING_OUT ? 0.f : kBackgroundFinalOpacity; | |
|
stevenjb
2016/12/22 22:03:32
nit: Don't initialize this, set it in an else at l
malaykeshav
2016/12/23 00:09:06
Done
| |
| 114 | |
| 115 // If current state is a fade in or fade out state then update opacity | |
| 116 // based on how far the animation has progressed. | |
| 117 if (animator_ && (state_ == TouchCalibratorView::BACKGROUND_FADING_OUT || | |
| 118 state_ == TouchCalibratorView::BACKGROUND_FADING_IN)) { | |
| 119 opacity = static_cast<float>(animator_->CurrentValueBetween( | |
| 120 start_opacity_value_, end_opacity_value_)); | |
| 121 } | |
| 122 | |
| 123 paint_.setColor(SkColorSetA(SK_ColorBLACK, | |
| 124 std::numeric_limits<uint8_t>::max() * opacity)); | |
| 125 canvas->DrawRect(background_rect_, paint_); | |
| 126 } | |
| 62 | 127 |
| 63 void TouchCalibratorView::AnimationProgressed(const gfx::Animation* animation) { | 128 void TouchCalibratorView::AnimationProgressed(const gfx::Animation* animation) { |
| 129 SchedulePaint(); | |
| 64 } | 130 } |
| 65 | 131 |
| 66 void TouchCalibratorView::AnimationCanceled(const gfx::Animation* animation) { | 132 void TouchCalibratorView::AnimationCanceled(const gfx::Animation* animation) { |
| 67 AnimationEnded(animation); | 133 AnimationEnded(animation); |
| 68 } | 134 } |
| 69 | 135 |
| 70 void TouchCalibratorView::AnimationEnded(const gfx::Animation* animation) {} | 136 void TouchCalibratorView::AnimationEnded(const gfx::Animation* animation) { |
| 137 switch (state_) { | |
| 138 case BACKGROUND_FADING_IN: | |
| 139 exit_label_->SetVisible(true); | |
| 140 state_ = is_primary_view_ ? DISPLAY_POINT_1 : CALIBRATION_COMPLETE; | |
| 141 break; | |
| 142 default: | |
| 143 break; | |
| 144 } | |
|
stevenjb
2016/12/22 22:03:33
if (state_ == BACKGROUND_FADING_IN) {
}
malaykeshav
2016/12/23 00:09:06
This will be handling multiple states in the subse
stevenjb
2016/12/23 00:16:11
Normally I would suggest changing to a switch at t
| |
| 145 } | |
| 71 | 146 |
| 72 void TouchCalibratorView::AdvanceToNextState() {} | 147 void TouchCalibratorView::AdvanceToNextState() { |
| 148 // Stop any previous animations and skip them to the end. | |
| 149 animator_->End(); | |
| 150 | |
| 151 switch (state_) { | |
| 152 case UNKNOWN: | |
| 153 case BACKGROUND_FADING_IN: | |
| 154 state_ = BACKGROUND_FADING_IN; | |
| 155 start_opacity_value_ = 0.f; | |
| 156 end_opacity_value_ = kBackgroundFinalOpacity; | |
| 157 | |
| 158 paint_.setStyle(SkPaint::kFill_Style); | |
| 159 | |
| 160 animator_->SetDuration(kFadeDurationInMs); | |
| 161 break; | |
| 162 default: | |
| 163 break; | |
| 164 } | |
|
stevenjb
2016/12/22 22:03:33
if (state_ == BACKGROUND_FADING_IN || state_ == UN
malaykeshav
2016/12/23 00:09:06
ditto
| |
| 165 animator_->Start(); | |
| 166 } | |
| 73 | 167 |
| 74 bool TouchCalibratorView::GetDisplayPointLocation(gfx::Point* location) { | 168 bool TouchCalibratorView::GetDisplayPointLocation(gfx::Point* location) { |
| 75 if (!is_primary_view_) | 169 if (!is_primary_view_) |
| 76 return false; | 170 return false; |
| 77 return false; | 171 return false; |
| 78 } | 172 } |
| 79 | 173 |
| 80 void TouchCalibratorView::SkipToFinalState() {} | 174 void TouchCalibratorView::SkipToFinalState() {} |
| 81 | 175 |
| 176 void TouchCalibratorView::SkipCurrentAnimation() { | |
| 177 if (animator_->is_animating()) | |
| 178 animator_->End(); | |
| 179 } | |
| 180 | |
| 82 } // namespace chromeos | 181 } // namespace chromeos |
| OLD | NEW |