Chromium Code Reviews| Index: chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view.cc |
| diff --git a/chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view.cc b/chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view.cc |
| index c0484a6b4cfe14d543d2159b59ae896e12012f5a..dd8b1acde489c4b5b98225097a7697ffd5a20e32 100644 |
| --- a/chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view.cc |
| +++ b/chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view.cc |
| @@ -8,7 +8,11 @@ |
| #include "ash/public/cpp/shell_window_ids.h" |
| #include "ash/shell.h" |
| #include "ui/aura/window.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#include "ui/gfx/animation/linear_animation.h" |
| #include "ui/gfx/canvas.h" |
| +#include "ui/strings/grit/ui_strings.h" |
| +#include "ui/views/controls/label.h" |
| #include "ui/views/widget/widget.h" |
| namespace chromeos { |
| @@ -17,6 +21,16 @@ namespace { |
| constexpr char kWidgetName[] = "TouchCalibratorOverlay"; |
| +const int kAnimationFrameRate = 100; |
| +const int kFadeDurationInMs = 150; |
| + |
| +const SkColor kExitLabelColor = SkColorSetARGBInline(255, 96, 96, 96); |
| +const SkColor kExitLabelShadowColor = SkColorSetARGBInline(255, 11, 11, 11); |
| +const int kExitLabelWidth = 300; |
| +const int kExitLabelHeight = 20; |
| + |
| +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
|
| + |
| // Returns the initialization params for the widget that contains the touch |
| // calibrator view. |
| views::Widget::InitParams GetWidgetParams(aura::Window* root_window) { |
| @@ -37,7 +51,9 @@ views::Widget::InitParams GetWidgetParams(aura::Window* root_window) { |
| TouchCalibratorView::TouchCalibratorView(const display::Display& target_display, |
| bool is_primary_view) |
| - : display_(target_display), is_primary_view_(is_primary_view) { |
| + : display_(target_display), |
| + is_primary_view_(is_primary_view), |
| + exit_label_(nullptr) { |
| aura::Window* root = ash::Shell::GetInstance() |
| ->window_tree_host_manager() |
| ->GetRootWindowForDisplayId(display_.id()); |
| @@ -47,29 +63,107 @@ TouchCalibratorView::TouchCalibratorView(const display::Display& target_display, |
| widget_->SetBounds(display_.bounds()); |
| widget_->Show(); |
| set_owned_by_client(); |
| + |
| + animator_.reset( |
| + new gfx::LinearAnimation(kFadeDurationInMs, kAnimationFrameRate, this)); |
| + |
| + InitViewContents(); |
| + AdvanceToNextState(); |
| } |
| TouchCalibratorView::~TouchCalibratorView() { |
| state_ = UNKNOWN; |
| widget_->Hide(); |
| + animator_->End(); |
| + if (exit_label_) |
| + 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
|
| +} |
| + |
| +void TouchCalibratorView::InitViewContents() { |
| + // Initialize the background rect. |
| + background_rect_ = |
| + gfx::RectF(0, 0, display_.bounds().width(), display_.bounds().height()); |
| + |
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| + // Initialize exit label that informs the user how to exit the touch |
| + // calibration setup. |
| + exit_label_ = new views::Label( |
| + rb.GetLocalizedString(IDS_DISPLAY_TOUCH_CALIBRATION_EXIT_LABEL), |
| + rb.GetFontListWithDelta(8, gfx::Font::FontStyle::NORMAL, |
| + gfx::Font::Weight::NORMAL)); |
| + exit_label_->SetBounds((display_.bounds().width() - kExitLabelWidth) / 2, |
| + 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
|
| + kExitLabelHeight); |
| + exit_label_->SetEnabledColor(kExitLabelColor); |
| + exit_label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| + exit_label_->SetShadows(gfx::ShadowValues( |
| + 1, gfx::ShadowValue(gfx::Vector2d(1, 1), 1, kExitLabelShadowColor))); |
| + exit_label_->SetSubpixelRenderingEnabled(false); |
| + exit_label_->SetVisible(false); |
| + |
| + AddChildView(exit_label_); |
| } |
| void TouchCalibratorView::OnPaint(gfx::Canvas* canvas) { |
| OnPaintBackground(canvas); |
| } |
| -void TouchCalibratorView::OnPaintBackground(gfx::Canvas* canvas) {} |
| +void TouchCalibratorView::OnPaintBackground(gfx::Canvas* canvas) { |
| + float opacity = |
| + 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
|
| + |
| + // If current state is a fade in or fade out state then update opacity |
| + // based on how far the animation has progressed. |
| + if (animator_ && (state_ == TouchCalibratorView::BACKGROUND_FADING_OUT || |
| + state_ == TouchCalibratorView::BACKGROUND_FADING_IN)) { |
| + opacity = static_cast<float>(animator_->CurrentValueBetween( |
| + start_opacity_value_, end_opacity_value_)); |
| + } |
| + |
| + paint_.setColor(SkColorSetA(SK_ColorBLACK, |
| + std::numeric_limits<uint8_t>::max() * opacity)); |
| + canvas->DrawRect(background_rect_, paint_); |
| +} |
| void TouchCalibratorView::AnimationProgressed(const gfx::Animation* animation) { |
| + SchedulePaint(); |
| } |
| void TouchCalibratorView::AnimationCanceled(const gfx::Animation* animation) { |
| AnimationEnded(animation); |
| } |
| -void TouchCalibratorView::AnimationEnded(const gfx::Animation* animation) {} |
| +void TouchCalibratorView::AnimationEnded(const gfx::Animation* animation) { |
| + switch (state_) { |
| + case BACKGROUND_FADING_IN: |
| + exit_label_->SetVisible(true); |
| + state_ = is_primary_view_ ? DISPLAY_POINT_1 : CALIBRATION_COMPLETE; |
| + break; |
| + default: |
| + break; |
| + } |
|
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
|
| +} |
| -void TouchCalibratorView::AdvanceToNextState() {} |
| +void TouchCalibratorView::AdvanceToNextState() { |
| + // Stop any previous animations and skip them to the end. |
| + animator_->End(); |
| + |
| + switch (state_) { |
| + case UNKNOWN: |
| + case BACKGROUND_FADING_IN: |
| + state_ = BACKGROUND_FADING_IN; |
| + start_opacity_value_ = 0.f; |
| + end_opacity_value_ = kBackgroundFinalOpacity; |
| + |
| + paint_.setStyle(SkPaint::kFill_Style); |
| + |
| + animator_->SetDuration(kFadeDurationInMs); |
| + break; |
| + default: |
| + break; |
| + } |
|
stevenjb
2016/12/22 22:03:33
if (state_ == BACKGROUND_FADING_IN || state_ == UN
malaykeshav
2016/12/23 00:09:06
ditto
|
| + animator_->Start(); |
| +} |
| bool TouchCalibratorView::GetDisplayPointLocation(gfx::Point* location) { |
| if (!is_primary_view_) |
| @@ -79,4 +173,9 @@ bool TouchCalibratorView::GetDisplayPointLocation(gfx::Point* location) { |
| void TouchCalibratorView::SkipToFinalState() {} |
| +void TouchCalibratorView::SkipCurrentAnimation() { |
| + if (animator_->is_animating()) |
| + animator_->End(); |
| +} |
| + |
| } // namespace chromeos |