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/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 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 constexpr char kWidgetName[] = "TouchCalibratorOverlay"; | 27 constexpr char kWidgetName[] = "TouchCalibratorOverlay"; |
| 28 | 28 |
| 29 constexpr int kAnimationFrameRate = 100; | 29 constexpr int kAnimationFrameRate = 100; |
| 30 constexpr int kFadeDurationInMs = 150; | 30 constexpr int kFadeDurationInMs = 150; |
| 31 constexpr int kPointMoveDurationInMs = 400; | 31 constexpr int kPointMoveDurationInMs = 400; |
| 32 constexpr int kPointMoveDurationLongInMs = 500; | 32 constexpr int kPointMoveDurationLongInMs = 500; |
| 33 | 33 |
| 34 const SkColor kExitLabelColor = SkColorSetARGBInline(255, 96, 96, 96); | 34 const SkColor kExitLabelColor = SkColorSetARGBInline(255, 138, 138, 138); |
| 35 constexpr int kExitLabelWidth = 300; | 35 constexpr int kExitLabelWidth = 300; |
| 36 constexpr int kExitLabelHeight = 20; | 36 constexpr int kExitLabelHeight = 20; |
| 37 | 37 |
| 38 const SkColor kTapHereLabelColor = SK_ColorWHITE; | 38 const SkColor kTapHereLabelColor = SK_ColorWHITE; |
| 39 | 39 |
| 40 constexpr int kHintBoxWidth = 298; | 40 constexpr int kHintBoxWidth = 298; |
| 41 constexpr int kHintBoxHeight = 180; | 41 constexpr int kHintBoxHeight = 180; |
| 42 constexpr int kHintBoxArrowWidth = 8; | |
| 43 constexpr int kHintBoxArrowHeight = 14; | |
| 42 constexpr int kHintBoxLabelTextSize = 5; | 44 constexpr int kHintBoxLabelTextSize = 5; |
| 43 constexpr int kHintBoxSublabelTextSize = 3; | 45 constexpr int kHintBoxSublabelTextSize = 3; |
| 44 | 46 |
| 45 constexpr int kThrobberCircleViewWidth = 64; | 47 constexpr int kThrobberCircleViewWidth = 64; |
| 46 constexpr float kThrobberCircleRadiusFactor = 3.f / 8.f; | 48 constexpr float kThrobberCircleRadiusFactor = 3.f / 8.f; |
| 47 | 49 |
| 48 constexpr int kFinalMessageTransitionDurationMs = 200; | 50 constexpr int kFinalMessageTransitionDurationMs = 200; |
| 49 constexpr int kCompleteMessageViewWidth = 427; | 51 constexpr int kCompleteMessageViewWidth = 427; |
| 50 constexpr int kCompleteMessageViewHeight = kThrobberCircleViewWidth; | 52 constexpr int kCompleteMessageViewHeight = kThrobberCircleViewWidth; |
| 51 constexpr int kCompleteMessageTextSize = 16; | 53 constexpr int kCompleteMessageTextSize = 16; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 HintBox(const gfx::Rect& bounds, int border_radius); | 273 HintBox(const gfx::Rect& bounds, int border_radius); |
| 272 ~HintBox() override; | 274 ~HintBox() override; |
| 273 | 275 |
| 274 // views::View overrides: | 276 // views::View overrides: |
| 275 void OnPaint(gfx::Canvas* canvas) override; | 277 void OnPaint(gfx::Canvas* canvas) override; |
| 276 | 278 |
| 277 void SetLabel(const base::string16& text, const SkColor& color); | 279 void SetLabel(const base::string16& text, const SkColor& color); |
| 278 void SetSubLabel(const base::string16& text, const SkColor& color); | 280 void SetSubLabel(const base::string16& text, const SkColor& color); |
| 279 | 281 |
| 280 private: | 282 private: |
| 283 void UpdateWidth(int updated_width); | |
| 284 void UpdateTriangle(); | |
| 285 | |
| 281 base::string16 label_text_; | 286 base::string16 label_text_; |
| 282 base::string16 sublabel_text_; | 287 base::string16 sublabel_text_; |
| 283 | 288 |
| 284 SkColor label_color_; | 289 SkColor label_color_; |
| 285 SkColor sublabel_color_; | 290 SkColor sublabel_color_; |
| 286 | 291 |
| 287 const int border_radius_; | 292 const int border_radius_; |
| 288 | 293 |
| 289 int horizontal_offset_; | 294 int horizontal_offset_; |
| 290 | 295 |
| 296 gfx::Rect rounded_rect_bounds_; | |
| 297 | |
| 291 gfx::FontList label_font_list_; | 298 gfx::FontList label_font_list_; |
| 292 gfx::FontList sublabel_font_list_; | 299 gfx::FontList sublabel_font_list_; |
| 293 | 300 |
| 294 gfx::Rect label_text_bounds_; | 301 gfx::Rect label_text_bounds_; |
| 295 gfx::Rect sublabel_text_bounds_; | 302 gfx::Rect sublabel_text_bounds_; |
| 296 | 303 |
| 297 SkPaint paint_; | 304 SkPaint paint_; |
| 298 | 305 |
| 306 SkPath triangle_path_; | |
| 307 | |
| 299 DISALLOW_COPY_AND_ASSIGN(HintBox); | 308 DISALLOW_COPY_AND_ASSIGN(HintBox); |
| 300 }; | 309 }; |
| 301 | 310 |
| 302 HintBox::HintBox(const gfx::Rect& bounds, int border_radius) | 311 HintBox::HintBox(const gfx::Rect& bounds, int border_radius) |
| 303 : border_radius_(border_radius) { | 312 : border_radius_(border_radius), |
| 313 rounded_rect_bounds_( | |
| 314 gfx::Rect(base::i18n::IsRTL() ? 0 : kHintBoxArrowWidth, | |
| 315 0, | |
| 316 bounds.width() - kHintBoxArrowWidth, | |
| 317 bounds.height())) { | |
|
oshima
2017/01/25 22:08:54
can you use GetMirroredxxx api on views?
malaykeshav
2017/01/25 23:54:22
Done
| |
| 304 SetBoundsRect(bounds); | 318 SetBoundsRect(bounds); |
| 305 | 319 |
| 306 paint_.setColor(SK_ColorWHITE); | 320 paint_.setColor(SK_ColorWHITE); |
| 307 paint_.setStyle(SkPaint::kFill_Style); | 321 paint_.setStyle(SkPaint::kFill_Style); |
| 308 paint_.setFlags(SkPaint::kAntiAlias_Flag); | 322 paint_.setFlags(SkPaint::kAntiAlias_Flag); |
| 309 | 323 |
| 310 horizontal_offset_ = width() * 0.08f; | 324 horizontal_offset_ = |
| 325 kHintBoxArrowWidth + rounded_rect_bounds_.width() * 0.08f; | |
| 311 int top_offset = horizontal_offset_; | 326 int top_offset = horizontal_offset_; |
| 312 int line_gap = height() * 0.018f; | 327 int line_gap = height() * 0.018f; |
| 313 int label_height = height() * 0.11f; | 328 int label_height = height() * 0.11f; |
| 314 | 329 |
| 315 label_text_bounds_.SetRect(horizontal_offset_, top_offset, 0, label_height); | 330 label_text_bounds_.SetRect(horizontal_offset_, top_offset, 0, label_height); |
| 316 | 331 |
| 317 top_offset += label_text_bounds_.height() + line_gap; | 332 top_offset += label_text_bounds_.height() + line_gap; |
| 318 | 333 |
| 319 sublabel_text_bounds_.SetRect(horizontal_offset_, top_offset, 0, | 334 sublabel_text_bounds_.SetRect(horizontal_offset_, top_offset, 0, |
| 320 label_height); | 335 label_height); |
| 336 | |
| 337 UpdateTriangle(); | |
| 321 } | 338 } |
| 322 | 339 |
| 323 HintBox::~HintBox() {} | 340 HintBox::~HintBox() {} |
| 324 | 341 |
| 342 void HintBox::UpdateTriangle() { | |
| 343 const int kHorizontalOffset = base::i18n::IsRTL() ? width() : 0; | |
| 344 const int kMultiplier = base::i18n::IsRTL() ? 1 : -1; | |
|
oshima
2017/01/25 22:08:54
ditto
malaykeshav
2017/01/25 23:54:22
Done
| |
| 345 | |
| 346 triangle_path_.reset(); | |
| 347 triangle_path_.moveTo(kHorizontalOffset, SkIntToScalar(height() / 2)); | |
| 348 triangle_path_.lineTo( | |
| 349 SkIntToScalar((kHorizontalOffset - kHintBoxArrowWidth) * kMultiplier), | |
| 350 SkIntToScalar((height() - kHintBoxArrowHeight) / 2)); | |
| 351 | |
| 352 triangle_path_.lineTo( | |
| 353 SkIntToScalar((kHorizontalOffset - kHintBoxArrowWidth) * kMultiplier), | |
| 354 SkIntToScalar((height() + kHintBoxArrowHeight) / 2)); | |
| 355 triangle_path_.close(); | |
| 356 } | |
| 357 | |
| 358 void HintBox::UpdateWidth(int updated_width) { | |
| 359 rounded_rect_bounds_.set_size(gfx::Size(updated_width, height())); | |
| 360 SetSize( | |
| 361 gfx::Size(rounded_rect_bounds_.width() + kHintBoxArrowWidth, height())); | |
| 362 | |
| 363 UpdateTriangle(); | |
| 364 } | |
| 365 | |
| 325 void HintBox::SetLabel(const base::string16& text, const SkColor& color) { | 366 void HintBox::SetLabel(const base::string16& text, const SkColor& color) { |
| 326 label_text_ = text; | 367 label_text_ = text; |
| 327 label_color_ = color; | 368 label_color_ = color; |
| 328 | 369 |
| 329 label_font_list_ = | 370 label_font_list_ = |
| 330 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( | 371 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
| 331 kHintBoxLabelTextSize, gfx::Font::FontStyle::NORMAL, | 372 kHintBoxLabelTextSize, gfx::Font::FontStyle::NORMAL, |
| 332 gfx::Font::Weight::NORMAL); | 373 gfx::Font::Weight::NORMAL); |
| 333 | 374 |
| 334 // Adjust size of label bounds based on text and font. | 375 // Adjust size of label bounds based on text and font. |
| 335 gfx::Size size = GetSizeForString(label_text_, label_font_list_); | 376 gfx::Size size = GetSizeForString(label_text_, label_font_list_); |
| 336 label_text_bounds_.set_size( | 377 label_text_bounds_.set_size( |
| 337 gfx::Size(size.width(), label_text_bounds_.height())); | 378 gfx::Size(size.width(), label_text_bounds_.height())); |
| 338 | 379 |
| 339 // Check if the width of hint box needs to be updated. | 380 // Check if the width of hint box needs to be updated. |
| 340 int minimum_expected_width = size.width() + 2 * horizontal_offset_; | 381 int minimum_expected_width = size.width() + 2 * horizontal_offset_; |
| 341 if (minimum_expected_width > width()) | 382 if (minimum_expected_width > rounded_rect_bounds_.width()) |
| 342 SetSize(gfx::Size(minimum_expected_width, height())); | 383 UpdateWidth(minimum_expected_width); |
| 343 } | 384 } |
| 344 | 385 |
| 345 void HintBox::SetSubLabel(const base::string16& text, const SkColor& color) { | 386 void HintBox::SetSubLabel(const base::string16& text, const SkColor& color) { |
| 346 sublabel_text_ = text; | 387 sublabel_text_ = text; |
| 347 sublabel_color_ = color; | 388 sublabel_color_ = color; |
| 348 | 389 |
| 349 sublabel_font_list_ = | 390 sublabel_font_list_ = |
| 350 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( | 391 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
| 351 kHintBoxSublabelTextSize, gfx::Font::FontStyle::NORMAL, | 392 kHintBoxSublabelTextSize, gfx::Font::FontStyle::NORMAL, |
| 352 gfx::Font::Weight::NORMAL); | 393 gfx::Font::Weight::NORMAL); |
| 353 | 394 |
| 354 // Adjust size of sublabel label bounds based on text and font. | 395 // Adjust size of sublabel label bounds based on text and font. |
| 355 gfx::Size size = GetSizeForString(sublabel_text_, sublabel_font_list_); | 396 gfx::Size size = GetSizeForString(sublabel_text_, sublabel_font_list_); |
| 356 sublabel_text_bounds_.set_size( | 397 sublabel_text_bounds_.set_size( |
| 357 gfx::Size(size.width(), sublabel_text_bounds_.height())); | 398 gfx::Size(size.width(), sublabel_text_bounds_.height())); |
| 358 | 399 |
| 359 // Check if the width of hint box needs to be updated. | 400 // Check if the width of hint box needs to be updated. |
| 360 int minimum_expected_width = size.width() + 2 * horizontal_offset_; | 401 int minimum_expected_width = size.width() + 2 * horizontal_offset_; |
| 361 if (minimum_expected_width > width()) | 402 if (minimum_expected_width > rounded_rect_bounds_.width()) |
| 362 SetSize(gfx::Size(minimum_expected_width, height())); | 403 UpdateWidth(minimum_expected_width); |
| 363 } | 404 } |
| 364 | 405 |
| 365 void HintBox::OnPaint(gfx::Canvas* canvas) { | 406 void HintBox::OnPaint(gfx::Canvas* canvas) { |
| 366 canvas->DrawRoundRect(GetLocalBounds(), border_radius_, paint_); | 407 canvas->DrawPath(triangle_path_, paint_); |
| 408 canvas->DrawRoundRect(rounded_rect_bounds_, border_radius_, paint_); | |
| 367 canvas->DrawStringRectWithFlags(label_text_, label_font_list_, label_color_, | 409 canvas->DrawStringRectWithFlags(label_text_, label_font_list_, label_color_, |
| 368 label_text_bounds_, gfx::Canvas::NO_ELLIPSIS); | 410 label_text_bounds_, gfx::Canvas::NO_ELLIPSIS); |
| 369 canvas->DrawStringRectWithFlags(sublabel_text_, sublabel_font_list_, | 411 canvas->DrawStringRectWithFlags(sublabel_text_, sublabel_font_list_, |
| 370 sublabel_color_, sublabel_text_bounds_, | 412 sublabel_color_, sublabel_text_bounds_, |
| 371 gfx::Canvas::NO_ELLIPSIS); | 413 gfx::Canvas::NO_ELLIPSIS); |
| 372 } | 414 } |
| 373 | 415 |
| 374 class CompletionMessageView : public views::View { | 416 class CompletionMessageView : public views::View { |
| 375 public: | 417 public: |
| 376 CompletionMessageView(const gfx::Rect& bounds, const base::string16& message); | 418 CompletionMessageView(const gfx::Rect& bounds, const base::string16& message); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 AddChildView(touch_point_view_); | 569 AddChildView(touch_point_view_); |
| 528 | 570 |
| 529 // Initialize the Hint Box view. | 571 // Initialize the Hint Box view. |
| 530 base::string16 hint_label_text = | 572 base::string16 hint_label_text = |
| 531 rb.GetLocalizedString(IDS_DISPLAY_TOUCH_CALIBRATION_HINT_LABEL_TEXT); | 573 rb.GetLocalizedString(IDS_DISPLAY_TOUCH_CALIBRATION_HINT_LABEL_TEXT); |
| 532 base::string16 hint_sublabel_text = | 574 base::string16 hint_sublabel_text = |
| 533 rb.GetLocalizedString(IDS_DISPLAY_TOUCH_CALIBRATION_HINT_SUBLABEL_TEXT); | 575 rb.GetLocalizedString(IDS_DISPLAY_TOUCH_CALIBRATION_HINT_SUBLABEL_TEXT); |
| 534 | 576 |
| 535 int tpv_width = touch_point_view_->width(); | 577 int tpv_width = touch_point_view_->width(); |
| 536 | 578 |
| 537 gfx::Size size(kHintBoxWidth, kHintBoxHeight); | 579 gfx::Size size(kHintBoxWidth + kHintBoxArrowWidth, kHintBoxHeight); |
| 538 | 580 |
| 539 gfx::Point position( | 581 gfx::Point position(touch_point_view_->x() + tpv_width * 1.2f, |
| 540 touch_point_view_->x() + tpv_width * 1.2f, | 582 touch_point_view_->y() + |
| 541 touch_point_view_->y() + (tpv_width / 2.f) - (size.height() / 2.f)); | 583 (kThrobberCircleViewWidth / 2.f) - |
| 584 (size.height() / 2.f)); | |
| 542 | 585 |
| 543 HintBox* hint_box = | 586 HintBox* hint_box = |
| 544 new HintBox(gfx::Rect(position, size), kHintRectBorderRadius); | 587 new HintBox(gfx::Rect(position, size), kHintRectBorderRadius); |
| 545 hint_box->SetVisible(false); | 588 hint_box->SetVisible(false); |
| 546 hint_box->SetLabel(hint_label_text, kHintLabelTextColor); | 589 hint_box->SetLabel(hint_label_text, kHintLabelTextColor); |
| 547 hint_box->SetSubLabel(hint_sublabel_text, kHintSublabelTextColor); | 590 hint_box->SetSubLabel(hint_sublabel_text, kHintSublabelTextColor); |
| 548 hint_box_view_ = hint_box; | 591 hint_box_view_ = hint_box; |
| 549 | 592 |
| 550 AddChildView(hint_box_view_); | 593 AddChildView(hint_box_view_); |
| 551 | 594 |
| 552 // Initialize the animated hint box throbber view. | 595 // Initialize the animated hint box throbber view. |
| 553 TouchTargetThrobberView* target_view = new TouchTargetThrobberView( | 596 TouchTargetThrobberView* target_view = new TouchTargetThrobberView( |
| 554 gfx::Rect((size.width() - kTouchTargetWidth) / 2, | 597 gfx::Rect((kHintBoxArrowWidth + size.width() - kTouchTargetWidth) / 2, |
| 555 size.height() * kTouchTargetVerticalOffsetFactor, | 598 size.height() * kTouchTargetVerticalOffsetFactor, |
| 556 kTouchTargetWidth, kTouchTargetHeight), | 599 kTouchTargetWidth, kTouchTargetHeight), |
| 557 kTouchTargetInnerCircleColor, kTouchTargetOuterCircleColor, | 600 kTouchTargetInnerCircleColor, kTouchTargetOuterCircleColor, |
| 558 kHandIconColor, kCircleAnimationDurationMs); | 601 kHandIconColor, kCircleAnimationDurationMs); |
| 559 target_view->SetVisible(true); | 602 target_view->SetVisible(true); |
| 560 | 603 |
| 561 hint_box_view_->AddChildView(target_view); | 604 hint_box_view_->AddChildView(target_view); |
| 562 | 605 |
| 563 // Initialize the view that contains the calibration complete message which | 606 // Initialize the view that contains the calibration complete message which |
| 564 // will be displayed at the end. | 607 // will be displayed at the end. |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 787 void TouchCalibratorView::SkipCurrentAnimation() { | 830 void TouchCalibratorView::SkipCurrentAnimation() { |
| 788 if (animator_->is_animating()) | 831 if (animator_->is_animating()) |
| 789 animator_->End(); | 832 animator_->End(); |
| 790 if (touch_point_view_ && | 833 if (touch_point_view_ && |
| 791 touch_point_view_->layer()->GetAnimator()->is_animating()) { | 834 touch_point_view_->layer()->GetAnimator()->is_animating()) { |
| 792 touch_point_view_->layer()->GetAnimator()->StopAnimating(); | 835 touch_point_view_->layer()->GetAnimator()->StopAnimating(); |
| 793 } | 836 } |
| 794 } | 837 } |
| 795 | 838 |
| 796 } // namespace chromeos | 839 } // namespace chromeos |
| OLD | NEW |