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/resources/vector_icons/vector_icons.h" | 9 #include "ash/resources/vector_icons/vector_icons.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 // Current radius of the outer circle. | 145 // Current radius of the outer circle. |
146 int outer_radius_; | 146 int outer_radius_; |
147 | 147 |
148 // Minimum radius for outer animated circle. | 148 // Minimum radius for outer animated circle. |
149 const int smallest_radius_animated_circle_; | 149 const int smallest_radius_animated_circle_; |
150 | 150 |
151 // Maximum radius for outer animated circle. | 151 // Maximum radius for outer animated circle. |
152 const int largest_radius_animated_circle_; | 152 const int largest_radius_animated_circle_; |
153 | 153 |
154 SkPaint inner_circle_paint_; | 154 cc::PaintFlags inner_circle_flags_; |
155 SkPaint outer_circle_paint_; | 155 cc::PaintFlags outer_circle_flags_; |
156 | 156 |
157 std::unique_ptr<gfx::ThrobAnimation> animation_; | 157 std::unique_ptr<gfx::ThrobAnimation> animation_; |
158 | 158 |
159 // Center of the concentric circles. | 159 // Center of the concentric circles. |
160 const gfx::Point center_; | 160 const gfx::Point center_; |
161 | 161 |
162 DISALLOW_COPY_AND_ASSIGN(CircularThrobberView); | 162 DISALLOW_COPY_AND_ASSIGN(CircularThrobberView); |
163 }; | 163 }; |
164 | 164 |
165 CircularThrobberView::CircularThrobberView(int width, | 165 CircularThrobberView::CircularThrobberView(int width, |
166 const SkColor& inner_circle_color, | 166 const SkColor& inner_circle_color, |
167 const SkColor& outer_circle_color, | 167 const SkColor& outer_circle_color, |
168 int animation_duration) | 168 int animation_duration) |
169 : inner_radius_(width / 4), | 169 : inner_radius_(width / 4), |
170 outer_radius_(inner_radius_), | 170 outer_radius_(inner_radius_), |
171 smallest_radius_animated_circle_(width * kThrobberCircleRadiusFactor), | 171 smallest_radius_animated_circle_(width * kThrobberCircleRadiusFactor), |
172 largest_radius_animated_circle_(width / 2), | 172 largest_radius_animated_circle_(width / 2), |
173 center_(gfx::Point(width / 2, width / 2)) { | 173 center_(gfx::Point(width / 2, width / 2)) { |
174 SetSize(gfx::Size(width, width)); | 174 SetSize(gfx::Size(width, width)); |
175 | 175 |
176 inner_circle_paint_.setColor(inner_circle_color); | 176 inner_circle_flags_.setColor(inner_circle_color); |
177 inner_circle_paint_.setStyle(SkPaint::kFill_Style); | 177 inner_circle_flags_.setAntiAlias(true); |
178 inner_circle_paint_.setFlags(SkPaint::kAntiAlias_Flag); | 178 inner_circle_flags_.setStyle(cc::PaintFlags::kFill_Style); |
179 | 179 |
180 outer_circle_paint_.setColor(outer_circle_color); | 180 outer_circle_flags_.setColor(outer_circle_color); |
181 outer_circle_paint_.setStyle(SkPaint::kFill_Style); | 181 outer_circle_flags_.setAntiAlias(true); |
182 outer_circle_paint_.setFlags(SkPaint::kAntiAlias_Flag); | 182 outer_circle_flags_.setStyle(cc::PaintFlags::kFill_Style); |
183 | 183 |
184 animation_.reset(new gfx::ThrobAnimation(this)); | 184 animation_.reset(new gfx::ThrobAnimation(this)); |
185 animation_->SetThrobDuration(animation_duration); | 185 animation_->SetThrobDuration(animation_duration); |
186 animation_->StartThrobbing(-1); | 186 animation_->StartThrobbing(-1); |
187 | 187 |
188 SchedulePaint(); | 188 SchedulePaint(); |
189 } | 189 } |
190 | 190 |
191 CircularThrobberView::~CircularThrobberView() {} | 191 CircularThrobberView::~CircularThrobberView() {} |
192 | 192 |
193 void CircularThrobberView::OnPaint(gfx::Canvas* canvas) { | 193 void CircularThrobberView::OnPaint(gfx::Canvas* canvas) { |
194 canvas->DrawCircle(center_, outer_radius_, outer_circle_paint_); | 194 canvas->DrawCircle(center_, outer_radius_, outer_circle_flags_); |
195 canvas->DrawCircle(center_, inner_radius_, inner_circle_paint_); | 195 canvas->DrawCircle(center_, inner_radius_, inner_circle_flags_); |
196 } | 196 } |
197 | 197 |
198 void CircularThrobberView::AnimationProgressed( | 198 void CircularThrobberView::AnimationProgressed( |
199 const gfx::Animation* animation) { | 199 const gfx::Animation* animation) { |
200 if (animation != animation_.get()) | 200 if (animation != animation_.get()) |
201 return; | 201 return; |
202 outer_radius_ = animation->CurrentValueBetween( | 202 outer_radius_ = animation->CurrentValueBetween( |
203 smallest_radius_animated_circle_, largest_radius_animated_circle_); | 203 smallest_radius_animated_circle_, largest_radius_animated_circle_); |
204 SchedulePaint(); | 204 SchedulePaint(); |
205 } | 205 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 int horizontal_offset_; | 296 int horizontal_offset_; |
297 | 297 |
298 gfx::Rect rounded_rect_bounds_; | 298 gfx::Rect rounded_rect_bounds_; |
299 | 299 |
300 gfx::FontList label_font_list_; | 300 gfx::FontList label_font_list_; |
301 gfx::FontList sublabel_font_list_; | 301 gfx::FontList sublabel_font_list_; |
302 | 302 |
303 gfx::Rect label_text_bounds_; | 303 gfx::Rect label_text_bounds_; |
304 gfx::Rect sublabel_text_bounds_; | 304 gfx::Rect sublabel_text_bounds_; |
305 | 305 |
306 SkPaint paint_; | 306 cc::PaintFlags flags_; |
307 | 307 |
308 DISALLOW_COPY_AND_ASSIGN(HintBox); | 308 DISALLOW_COPY_AND_ASSIGN(HintBox); |
309 }; | 309 }; |
310 | 310 |
311 HintBox::HintBox(const gfx::Rect& bounds, int border_radius) | 311 HintBox::HintBox(const gfx::Rect& bounds, int border_radius) |
312 : border_radius_(border_radius) { | 312 : border_radius_(border_radius) { |
313 SetBorder(base::MakeUnique<views::BubbleBorder>( | 313 SetBorder(base::MakeUnique<views::BubbleBorder>( |
314 base::i18n::IsRTL() ? views::BubbleBorder::RIGHT_CENTER | 314 base::i18n::IsRTL() ? views::BubbleBorder::RIGHT_CENTER |
315 : views::BubbleBorder::LEFT_CENTER, | 315 : views::BubbleBorder::LEFT_CENTER, |
316 views::BubbleBorder::NO_SHADOW_OPAQUE_BORDER, SK_ColorWHITE)); | 316 views::BubbleBorder::NO_SHADOW_OPAQUE_BORDER, SK_ColorWHITE)); |
317 | 317 |
318 arrow_width_ = (GetInsets().right() - GetInsets().left()) * | 318 arrow_width_ = (GetInsets().right() - GetInsets().left()) * |
319 (base::i18n::IsRTL() ? 1 : -1); | 319 (base::i18n::IsRTL() ? 1 : -1); |
320 | 320 |
321 // Border on all sides are the same except on the side of the arrow, in which | 321 // Border on all sides are the same except on the side of the arrow, in which |
322 // case the width of the arrow is additional. | 322 // case the width of the arrow is additional. |
323 base_border_ = base::i18n::IsRTL() ? GetInsets().left() : GetInsets().right(); | 323 base_border_ = base::i18n::IsRTL() ? GetInsets().left() : GetInsets().right(); |
324 | 324 |
325 SetBounds(bounds.x(), bounds.y() - base_border_, | 325 SetBounds(bounds.x(), bounds.y() - base_border_, |
326 bounds.width() + 2 * base_border_ + arrow_width_, | 326 bounds.width() + 2 * base_border_ + arrow_width_, |
327 bounds.height() + 2 * base_border_); | 327 bounds.height() + 2 * base_border_); |
328 | 328 |
329 rounded_rect_bounds_ = GetLocalBounds(); | 329 rounded_rect_bounds_ = GetLocalBounds(); |
330 rounded_rect_bounds_.Inset(GetInsets()); | 330 rounded_rect_bounds_.Inset(GetInsets()); |
331 | 331 |
332 paint_.setColor(SK_ColorWHITE); | 332 flags_.setColor(SK_ColorWHITE); |
333 paint_.setStyle(SkPaint::kFill_Style); | 333 flags_.setStyle(cc::PaintFlags::kFill_Style); |
334 paint_.setFlags(SkPaint::kAntiAlias_Flag); | 334 flags_.setAntiAlias(true); |
335 | 335 |
336 horizontal_offset_ = | 336 horizontal_offset_ = |
337 arrow_width_ + base_border_ + rounded_rect_bounds_.width() * 0.08f; | 337 arrow_width_ + base_border_ + rounded_rect_bounds_.width() * 0.08f; |
338 int top_offset = horizontal_offset_; | 338 int top_offset = horizontal_offset_; |
339 int line_gap = rounded_rect_bounds_.height() * 0.018f; | 339 int line_gap = rounded_rect_bounds_.height() * 0.018f; |
340 int label_height = rounded_rect_bounds_.height() * 0.11f; | 340 int label_height = rounded_rect_bounds_.height() * 0.11f; |
341 | 341 |
342 label_text_bounds_.SetRect(horizontal_offset_, top_offset, 0, label_height); | 342 label_text_bounds_.SetRect(horizontal_offset_, top_offset, 0, label_height); |
343 | 343 |
344 top_offset += label_text_bounds_.height() + line_gap; | 344 top_offset += label_text_bounds_.height() + line_gap; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 392 |
393 // Check if the width of hint box needs to be updated. | 393 // Check if the width of hint box needs to be updated. |
394 int minimum_expected_width = | 394 int minimum_expected_width = |
395 size.width() + 2 * horizontal_offset_ - arrow_width_; | 395 size.width() + 2 * horizontal_offset_ - arrow_width_; |
396 if (minimum_expected_width > rounded_rect_bounds_.width()) | 396 if (minimum_expected_width > rounded_rect_bounds_.width()) |
397 UpdateWidth(minimum_expected_width); | 397 UpdateWidth(minimum_expected_width); |
398 } | 398 } |
399 | 399 |
400 void HintBox::OnPaint(gfx::Canvas* canvas) { | 400 void HintBox::OnPaint(gfx::Canvas* canvas) { |
401 views::View::OnPaint(canvas); | 401 views::View::OnPaint(canvas); |
402 canvas->DrawRoundRect(rounded_rect_bounds_, border_radius_, paint_); | 402 canvas->DrawRoundRect(rounded_rect_bounds_, border_radius_, flags_); |
403 canvas->DrawStringRectWithFlags(label_text_, label_font_list_, label_color_, | 403 canvas->DrawStringRectWithFlags(label_text_, label_font_list_, label_color_, |
404 label_text_bounds_, gfx::Canvas::NO_ELLIPSIS); | 404 label_text_bounds_, gfx::Canvas::NO_ELLIPSIS); |
405 canvas->DrawStringRectWithFlags(sublabel_text_, sublabel_font_list_, | 405 canvas->DrawStringRectWithFlags(sublabel_text_, sublabel_font_list_, |
406 sublabel_color_, sublabel_text_bounds_, | 406 sublabel_color_, sublabel_text_bounds_, |
407 gfx::Canvas::NO_ELLIPSIS); | 407 gfx::Canvas::NO_ELLIPSIS); |
408 } | 408 } |
409 | 409 |
410 class CompletionMessageView : public views::View { | 410 class CompletionMessageView : public views::View { |
411 public: | 411 public: |
412 CompletionMessageView(const gfx::Rect& bounds, const base::string16& message); | 412 CompletionMessageView(const gfx::Rect& bounds, const base::string16& message); |
413 ~CompletionMessageView() override; | 413 ~CompletionMessageView() override; |
414 | 414 |
415 // views::View overrides: | 415 // views::View overrides: |
416 void OnPaint(gfx::Canvas* canvas) override; | 416 void OnPaint(gfx::Canvas* canvas) override; |
417 | 417 |
418 private: | 418 private: |
419 const base::string16 message_; | 419 const base::string16 message_; |
420 gfx::FontList font_list_; | 420 gfx::FontList font_list_; |
421 | 421 |
422 gfx::Rect text_bounds_; | 422 gfx::Rect text_bounds_; |
423 | 423 |
424 gfx::ImageSkia check_icon_; | 424 gfx::ImageSkia check_icon_; |
425 | 425 |
426 SkPaint paint_; | 426 cc::PaintFlags flags_; |
427 | 427 |
428 DISALLOW_COPY_AND_ASSIGN(CompletionMessageView); | 428 DISALLOW_COPY_AND_ASSIGN(CompletionMessageView); |
429 }; | 429 }; |
430 | 430 |
431 CompletionMessageView::CompletionMessageView(const gfx::Rect& bounds, | 431 CompletionMessageView::CompletionMessageView(const gfx::Rect& bounds, |
432 const base::string16& message) | 432 const base::string16& message) |
433 : message_(message) { | 433 : message_(message) { |
434 SetBoundsRect(bounds); | 434 SetBoundsRect(bounds); |
435 | 435 |
436 int x_offset = height() * 5.f / 4.f; | 436 int x_offset = height() * 5.f / 4.f; |
437 text_bounds_.SetRect(x_offset, 0, width() - x_offset, height()); | 437 text_bounds_.SetRect(x_offset, 0, width() - x_offset, height()); |
438 | 438 |
439 font_list_ = ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( | 439 font_list_ = ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
440 kCompleteMessageTextSize, gfx::Font::FontStyle::NORMAL, | 440 kCompleteMessageTextSize, gfx::Font::FontStyle::NORMAL, |
441 gfx::Font::Weight::NORMAL); | 441 gfx::Font::Weight::NORMAL); |
442 | 442 |
443 // crbug/676513 moves this file to src/ash which will require an ash icon | 443 // crbug/676513 moves this file to src/ash which will require an ash icon |
444 // file. | 444 // file. |
445 check_icon_ = gfx::CreateVectorIcon(ash::kTouchCalibrationCompleteCheckIcon, | 445 check_icon_ = gfx::CreateVectorIcon(ash::kTouchCalibrationCompleteCheckIcon, |
446 SK_ColorWHITE); | 446 SK_ColorWHITE); |
447 | 447 |
448 paint_.setColor(SK_ColorWHITE); | 448 flags_.setColor(SK_ColorWHITE); |
449 paint_.setStyle(SkPaint::kFill_Style); | 449 flags_.setStyle(cc::PaintFlags::kFill_Style); |
450 paint_.setFlags(SkPaint::kAntiAlias_Flag); | 450 flags_.setAntiAlias(true); |
451 } | 451 } |
452 | 452 |
453 CompletionMessageView::~CompletionMessageView() {} | 453 CompletionMessageView::~CompletionMessageView() {} |
454 | 454 |
455 void CompletionMessageView::OnPaint(gfx::Canvas* canvas) { | 455 void CompletionMessageView::OnPaint(gfx::Canvas* canvas) { |
456 canvas->DrawImageInt(check_icon_, 0, 0); | 456 canvas->DrawImageInt(check_icon_, 0, 0); |
457 | 457 |
458 // TODO(malaykeshav): Work with elizabethchiu@ to get better UX for RTL. | 458 // TODO(malaykeshav): Work with elizabethchiu@ to get better UX for RTL. |
459 canvas->DrawStringRectWithFlags( | 459 canvas->DrawStringRectWithFlags( |
460 message_, font_list_, paint_.getColor(), text_bounds_, | 460 message_, font_list_, flags_.getColor(), text_bounds_, |
461 gfx::Canvas::TEXT_ALIGN_LEFT | gfx::Canvas::NO_SUBPIXEL_RENDERING); | 461 gfx::Canvas::TEXT_ALIGN_LEFT | gfx::Canvas::NO_SUBPIXEL_RENDERING); |
462 } | 462 } |
463 | 463 |
464 TouchCalibratorView::TouchCalibratorView(const display::Display& target_display, | 464 TouchCalibratorView::TouchCalibratorView(const display::Display& target_display, |
465 bool is_primary_view) | 465 bool is_primary_view) |
466 : display_(target_display), | 466 : display_(target_display), |
467 is_primary_view_(is_primary_view), | 467 is_primary_view_(is_primary_view), |
468 exit_label_(nullptr), | 468 exit_label_(nullptr), |
469 tap_label_(nullptr), | 469 tap_label_(nullptr), |
470 throbber_circle_(nullptr), | 470 throbber_circle_(nullptr), |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 // If current state is a fade in or fade out state then update opacity | 628 // If current state is a fade in or fade out state then update opacity |
629 // based on how far the animation has progressed. | 629 // based on how far the animation has progressed. |
630 if (animator_ && (state_ == TouchCalibratorView::BACKGROUND_FADING_OUT || | 630 if (animator_ && (state_ == TouchCalibratorView::BACKGROUND_FADING_OUT || |
631 state_ == TouchCalibratorView::BACKGROUND_FADING_IN)) { | 631 state_ == TouchCalibratorView::BACKGROUND_FADING_IN)) { |
632 opacity = static_cast<float>(animator_->CurrentValueBetween( | 632 opacity = static_cast<float>(animator_->CurrentValueBetween( |
633 start_opacity_value_, end_opacity_value_)); | 633 start_opacity_value_, end_opacity_value_)); |
634 } else { | 634 } else { |
635 opacity = state_ == BACKGROUND_FADING_OUT ? 0.f : kBackgroundFinalOpacity; | 635 opacity = state_ == BACKGROUND_FADING_OUT ? 0.f : kBackgroundFinalOpacity; |
636 } | 636 } |
637 | 637 |
638 paint_.setColor(SkColorSetA(SK_ColorBLACK, | 638 flags_.setColor(SkColorSetA(SK_ColorBLACK, |
639 std::numeric_limits<uint8_t>::max() * opacity)); | 639 std::numeric_limits<uint8_t>::max() * opacity)); |
640 canvas->DrawRect(background_rect_, paint_); | 640 canvas->DrawRect(background_rect_, flags_); |
641 } | 641 } |
642 | 642 |
643 void TouchCalibratorView::AnimationProgressed(const gfx::Animation* animation) { | 643 void TouchCalibratorView::AnimationProgressed(const gfx::Animation* animation) { |
644 if (!is_primary_view_) { | 644 if (!is_primary_view_) { |
645 SchedulePaint(); | 645 SchedulePaint(); |
646 return; | 646 return; |
647 } | 647 } |
648 } | 648 } |
649 | 649 |
650 void TouchCalibratorView::AnimationCanceled(const gfx::Animation* animation) { | 650 void TouchCalibratorView::AnimationCanceled(const gfx::Animation* animation) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 // Stop any previous animations and skip them to the end. | 708 // Stop any previous animations and skip them to the end. |
709 SkipCurrentAnimation(); | 709 SkipCurrentAnimation(); |
710 | 710 |
711 switch (state_) { | 711 switch (state_) { |
712 case UNKNOWN: | 712 case UNKNOWN: |
713 case BACKGROUND_FADING_IN: | 713 case BACKGROUND_FADING_IN: |
714 state_ = BACKGROUND_FADING_IN; | 714 state_ = BACKGROUND_FADING_IN; |
715 start_opacity_value_ = 0.f; | 715 start_opacity_value_ = 0.f; |
716 end_opacity_value_ = kBackgroundFinalOpacity; | 716 end_opacity_value_ = kBackgroundFinalOpacity; |
717 | 717 |
718 paint_.setStyle(SkPaint::kFill_Style); | 718 flags_.setStyle(cc::PaintFlags::kFill_Style); |
719 animator_->SetDuration(kFadeDurationInMs); | 719 animator_->SetDuration(kFadeDurationInMs); |
720 animator_->Start(); | 720 animator_->Start(); |
721 return; | 721 return; |
722 case DISPLAY_POINT_1: | 722 case DISPLAY_POINT_1: |
723 state_ = ANIMATING_1_TO_2; | 723 state_ = ANIMATING_1_TO_2; |
724 | 724 |
725 // The touch point has to be animated from the top left corner of the | 725 // The touch point has to be animated from the top left corner of the |
726 // screen to the top right corner. | 726 // screen to the top right corner. |
727 AnimateLayerToPosition( | 727 AnimateLayerToPosition( |
728 touch_point_view_, kPointMoveDurationInMs, | 728 touch_point_view_, kPointMoveDurationInMs, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 completion_message_view_, kFadeDurationInMs, | 774 completion_message_view_, kFadeDurationInMs, |
775 gfx::Point(completion_message_view_->x(), | 775 gfx::Point(completion_message_view_->x(), |
776 completion_message_view_->y() + | 776 completion_message_view_->y() + |
777 2 * completion_message_view_->height()), | 777 2 * completion_message_view_->height()), |
778 0.f); | 778 0.f); |
779 } | 779 } |
780 | 780 |
781 start_opacity_value_ = kBackgroundFinalOpacity; | 781 start_opacity_value_ = kBackgroundFinalOpacity; |
782 end_opacity_value_ = 0.f; | 782 end_opacity_value_ = 0.f; |
783 | 783 |
784 paint_.setStyle(SkPaint::kFill_Style); | 784 flags_.setStyle(cc::PaintFlags::kFill_Style); |
785 animator_->SetDuration(kFadeDurationInMs); | 785 animator_->SetDuration(kFadeDurationInMs); |
786 animator_->Start(); | 786 animator_->Start(); |
787 return; | 787 return; |
788 default: | 788 default: |
789 return; | 789 return; |
790 } | 790 } |
791 } | 791 } |
792 | 792 |
793 bool TouchCalibratorView::GetDisplayPointLocation(gfx::Point* location) { | 793 bool TouchCalibratorView::GetDisplayPointLocation(gfx::Point* location) { |
794 DCHECK(location); | 794 DCHECK(location); |
(...skipping 29 matching lines...) Expand all Loading... |
824 void TouchCalibratorView::SkipCurrentAnimation() { | 824 void TouchCalibratorView::SkipCurrentAnimation() { |
825 if (animator_->is_animating()) | 825 if (animator_->is_animating()) |
826 animator_->End(); | 826 animator_->End(); |
827 if (touch_point_view_ && | 827 if (touch_point_view_ && |
828 touch_point_view_->layer()->GetAnimator()->is_animating()) { | 828 touch_point_view_->layer()->GetAnimator()->is_animating()) { |
829 touch_point_view_->layer()->GetAnimator()->StopAnimating(); | 829 touch_point_view_->layer()->GetAnimator()->StopAnimating(); |
830 } | 830 } |
831 } | 831 } |
832 | 832 |
833 } // namespace chromeos | 833 } // namespace chromeos |
OLD | NEW |