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

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

Issue 2655003002: Adds arrow icon and updates exit label color for touch calibration (Closed)
Patch Set: nit Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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"
11 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/compositor/scoped_layer_animation_settings.h" 13 #include "ui/compositor/scoped_layer_animation_settings.h"
14 #include "ui/gfx/animation/linear_animation.h" 14 #include "ui/gfx/animation/linear_animation.h"
15 #include "ui/gfx/animation/throb_animation.h" 15 #include "ui/gfx/animation/throb_animation.h"
16 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/paint_vector_icon.h" 17 #include "ui/gfx/paint_vector_icon.h"
18 #include "ui/strings/grit/ui_strings.h" 18 #include "ui/strings/grit/ui_strings.h"
19 #include "ui/views/background.h" 19 #include "ui/views/background.h"
20 #include "ui/views/bubble/bubble_border.h"
20 #include "ui/views/controls/label.h" 21 #include "ui/views/controls/label.h"
21 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
22 23
23 namespace chromeos { 24 namespace chromeos {
24 25
25 namespace { 26 namespace {
26 27
27 constexpr char kWidgetName[] = "TouchCalibratorOverlay"; 28 constexpr char kWidgetName[] = "TouchCalibratorOverlay";
28 29
29 constexpr int kAnimationFrameRate = 100; 30 constexpr int kAnimationFrameRate = 100;
30 constexpr int kFadeDurationInMs = 150; 31 constexpr int kFadeDurationInMs = 150;
31 constexpr int kPointMoveDurationInMs = 400; 32 constexpr int kPointMoveDurationInMs = 400;
32 constexpr int kPointMoveDurationLongInMs = 500; 33 constexpr int kPointMoveDurationLongInMs = 500;
33 34
34 const SkColor kExitLabelColor = SkColorSetARGBInline(255, 96, 96, 96); 35 const SkColor kExitLabelColor = SkColorSetARGBInline(255, 138, 138, 138);
35 constexpr int kExitLabelWidth = 300; 36 constexpr int kExitLabelWidth = 300;
36 constexpr int kExitLabelHeight = 20; 37 constexpr int kExitLabelHeight = 20;
37 38
38 const SkColor kTapHereLabelColor = SK_ColorWHITE; 39 const SkColor kTapHereLabelColor = SK_ColorWHITE;
39 40
40 constexpr int kHintBoxWidth = 298; 41 constexpr int kHintBoxWidth = 298;
41 constexpr int kHintBoxHeight = 180; 42 constexpr int kHintBoxHeight = 180;
42 constexpr int kHintBoxLabelTextSize = 5; 43 constexpr int kHintBoxLabelTextSize = 5;
43 constexpr int kHintBoxSublabelTextSize = 3; 44 constexpr int kHintBoxSublabelTextSize = 3;
44 45
(...skipping 18 matching lines...) Expand all
63 64
64 constexpr int kCircleAnimationDurationMs = 900; 65 constexpr int kCircleAnimationDurationMs = 900;
65 66
66 constexpr int kHintRectBorderRadius = 4; 67 constexpr int kHintRectBorderRadius = 4;
67 68
68 constexpr float kBackgroundFinalOpacity = 0.75f; 69 constexpr float kBackgroundFinalOpacity = 0.75f;
69 70
70 constexpr int kTouchTargetWidth = 64; 71 constexpr int kTouchTargetWidth = 64;
71 constexpr int kTouchTargetHeight = kTouchTargetWidth + kTouchTargetWidth / 2; 72 constexpr int kTouchTargetHeight = kTouchTargetWidth + kTouchTargetWidth / 2;
72 73
73 constexpr float kTouchTargetVerticalOffsetFactor = 5.f / 12.f; 74 constexpr float kTouchTargetVerticalOffsetFactor = 11.f / 24.f;
74 75
75 const SkColor kTouchTargetInnerCircleColor = 76 const SkColor kTouchTargetInnerCircleColor =
76 SkColorSetARGBInline(255, 66, 133, 244); 77 SkColorSetARGBInline(255, 66, 133, 244);
77 const SkColor kTouchTargetOuterCircleColor = 78 const SkColor kTouchTargetOuterCircleColor =
78 SkColorSetA(kTouchTargetInnerCircleColor, 255 * 0.2); 79 SkColorSetA(kTouchTargetInnerCircleColor, 255 * 0.2);
79 const SkColor kHandIconColor = SkColorSetARGBInline(255, 201, 201, 201); 80 const SkColor kHandIconColor = SkColorSetARGBInline(255, 201, 201, 201);
80 constexpr float kHandIconHorizontalOffsetFactor = 7.f / 32.f; 81 constexpr float kHandIconHorizontalOffsetFactor = 7.f / 32.f;
81 82
82 // Returns the initialization params for the widget that contains the touch 83 // Returns the initialization params for the widget that contains the touch
83 // calibrator view. 84 // calibrator view.
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 HintBox(const gfx::Rect& bounds, int border_radius); 272 HintBox(const gfx::Rect& bounds, int border_radius);
272 ~HintBox() override; 273 ~HintBox() override;
273 274
274 // views::View overrides: 275 // views::View overrides:
275 void OnPaint(gfx::Canvas* canvas) override; 276 void OnPaint(gfx::Canvas* canvas) override;
276 277
277 void SetLabel(const base::string16& text, const SkColor& color); 278 void SetLabel(const base::string16& text, const SkColor& color);
278 void SetSubLabel(const base::string16& text, const SkColor& color); 279 void SetSubLabel(const base::string16& text, const SkColor& color);
279 280
280 private: 281 private:
282 void UpdateWidth(int updated_width);
283
281 base::string16 label_text_; 284 base::string16 label_text_;
282 base::string16 sublabel_text_; 285 base::string16 sublabel_text_;
283 286
284 SkColor label_color_; 287 SkColor label_color_;
285 SkColor sublabel_color_; 288 SkColor sublabel_color_;
286 289
287 const int border_radius_; 290 const int border_radius_;
288 291
292 int base_border_;
293
294 int arrow_width_;
295
289 int horizontal_offset_; 296 int horizontal_offset_;
290 297
298 gfx::Rect rounded_rect_bounds_;
299
291 gfx::FontList label_font_list_; 300 gfx::FontList label_font_list_;
292 gfx::FontList sublabel_font_list_; 301 gfx::FontList sublabel_font_list_;
293 302
294 gfx::Rect label_text_bounds_; 303 gfx::Rect label_text_bounds_;
295 gfx::Rect sublabel_text_bounds_; 304 gfx::Rect sublabel_text_bounds_;
296 305
297 SkPaint paint_; 306 SkPaint paint_;
298 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) {
304 SetBoundsRect(bounds); 313 SetBorder(base::MakeUnique<views::BubbleBorder>(
314 base::i18n::IsRTL() ? views::BubbleBorder::RIGHT_CENTER
315 : views::BubbleBorder::LEFT_CENTER,
316 views::BubbleBorder::NO_SHADOW_OPAQUE_BORDER, SK_ColorWHITE));
317
318 arrow_width_ = (GetInsets().right() - GetInsets().left()) *
319 (base::i18n::IsRTL() ? 1 : -1);
320
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.
323 base_border_ = base::i18n::IsRTL() ? GetInsets().left() : GetInsets().right();
324
325 SetBounds(bounds.x(), bounds.y() - base_border_,
326 bounds.width() + 2 * base_border_ + arrow_width_,
327 bounds.height() + 2 * base_border_);
328
329 rounded_rect_bounds_ = GetLocalBounds();
330 rounded_rect_bounds_.Inset(GetInsets());
305 331
306 paint_.setColor(SK_ColorWHITE); 332 paint_.setColor(SK_ColorWHITE);
307 paint_.setStyle(SkPaint::kFill_Style); 333 paint_.setStyle(SkPaint::kFill_Style);
308 paint_.setFlags(SkPaint::kAntiAlias_Flag); 334 paint_.setFlags(SkPaint::kAntiAlias_Flag);
309 335
310 horizontal_offset_ = width() * 0.08f; 336 horizontal_offset_ =
337 arrow_width_ + base_border_ + rounded_rect_bounds_.width() * 0.08f;
311 int top_offset = horizontal_offset_; 338 int top_offset = horizontal_offset_;
312 int line_gap = height() * 0.018f; 339 int line_gap = rounded_rect_bounds_.height() * 0.018f;
313 int label_height = height() * 0.11f; 340 int label_height = rounded_rect_bounds_.height() * 0.11f;
314 341
315 label_text_bounds_.SetRect(horizontal_offset_, top_offset, 0, label_height); 342 label_text_bounds_.SetRect(horizontal_offset_, top_offset, 0, label_height);
316 343
317 top_offset += label_text_bounds_.height() + line_gap; 344 top_offset += label_text_bounds_.height() + line_gap;
318 345
319 sublabel_text_bounds_.SetRect(horizontal_offset_, top_offset, 0, 346 sublabel_text_bounds_.SetRect(horizontal_offset_, top_offset, 0,
320 label_height); 347 label_height);
321 } 348 }
322 349
323 HintBox::~HintBox() {} 350 HintBox::~HintBox() {}
324 351
352 void HintBox::UpdateWidth(int updated_width) {
353 SetSize(gfx::Size(updated_width + 2 * base_border_ + arrow_width_, height()));
354 rounded_rect_bounds_ = GetLocalBounds();
355 rounded_rect_bounds_.Inset(GetInsets());
356 }
357
325 void HintBox::SetLabel(const base::string16& text, const SkColor& color) { 358 void HintBox::SetLabel(const base::string16& text, const SkColor& color) {
326 label_text_ = text; 359 label_text_ = text;
327 label_color_ = color; 360 label_color_ = color;
328 361
329 label_font_list_ = 362 label_font_list_ =
330 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( 363 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
331 kHintBoxLabelTextSize, gfx::Font::FontStyle::NORMAL, 364 kHintBoxLabelTextSize, gfx::Font::FontStyle::NORMAL,
332 gfx::Font::Weight::NORMAL); 365 gfx::Font::Weight::NORMAL);
333 366
334 // Adjust size of label bounds based on text and font. 367 // Adjust size of label bounds based on text and font.
335 gfx::Size size = GetSizeForString(label_text_, label_font_list_); 368 gfx::Size size = GetSizeForString(label_text_, label_font_list_);
336 label_text_bounds_.set_size( 369 label_text_bounds_.set_size(
337 gfx::Size(size.width(), label_text_bounds_.height())); 370 gfx::Size(size.width(), label_text_bounds_.height()));
338 371
339 // Check if the width of hint box needs to be updated. 372 // Check if the width of hint box needs to be updated.
340 int minimum_expected_width = size.width() + 2 * horizontal_offset_; 373 int minimum_expected_width =
341 if (minimum_expected_width > width()) 374 size.width() + 2 * horizontal_offset_ - arrow_width_;
342 SetSize(gfx::Size(minimum_expected_width, height())); 375 if (minimum_expected_width > rounded_rect_bounds_.width())
376 UpdateWidth(minimum_expected_width);
343 } 377 }
344 378
345 void HintBox::SetSubLabel(const base::string16& text, const SkColor& color) { 379 void HintBox::SetSubLabel(const base::string16& text, const SkColor& color) {
346 sublabel_text_ = text; 380 sublabel_text_ = text;
347 sublabel_color_ = color; 381 sublabel_color_ = color;
348 382
349 sublabel_font_list_ = 383 sublabel_font_list_ =
350 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( 384 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta(
351 kHintBoxSublabelTextSize, gfx::Font::FontStyle::NORMAL, 385 kHintBoxSublabelTextSize, gfx::Font::FontStyle::NORMAL,
352 gfx::Font::Weight::NORMAL); 386 gfx::Font::Weight::NORMAL);
353 387
354 // Adjust size of sublabel label bounds based on text and font. 388 // Adjust size of sublabel label bounds based on text and font.
355 gfx::Size size = GetSizeForString(sublabel_text_, sublabel_font_list_); 389 gfx::Size size = GetSizeForString(sublabel_text_, sublabel_font_list_);
356 sublabel_text_bounds_.set_size( 390 sublabel_text_bounds_.set_size(
357 gfx::Size(size.width(), sublabel_text_bounds_.height())); 391 gfx::Size(size.width(), sublabel_text_bounds_.height()));
358 392
359 // Check if the width of hint box needs to be updated. 393 // Check if the width of hint box needs to be updated.
360 int minimum_expected_width = size.width() + 2 * horizontal_offset_; 394 int minimum_expected_width =
361 if (minimum_expected_width > width()) 395 size.width() + 2 * horizontal_offset_ - arrow_width_;
362 SetSize(gfx::Size(minimum_expected_width, height())); 396 if (minimum_expected_width > rounded_rect_bounds_.width())
397 UpdateWidth(minimum_expected_width);
363 } 398 }
364 399
365 void HintBox::OnPaint(gfx::Canvas* canvas) { 400 void HintBox::OnPaint(gfx::Canvas* canvas) {
366 canvas->DrawRoundRect(GetLocalBounds(), border_radius_, paint_); 401 views::View::OnPaint(canvas);
402 canvas->DrawRoundRect(rounded_rect_bounds_, border_radius_, paint_);
367 canvas->DrawStringRectWithFlags(label_text_, label_font_list_, label_color_, 403 canvas->DrawStringRectWithFlags(label_text_, label_font_list_, label_color_,
368 label_text_bounds_, gfx::Canvas::NO_ELLIPSIS); 404 label_text_bounds_, gfx::Canvas::NO_ELLIPSIS);
369 canvas->DrawStringRectWithFlags(sublabel_text_, sublabel_font_list_, 405 canvas->DrawStringRectWithFlags(sublabel_text_, sublabel_font_list_,
370 sublabel_color_, sublabel_text_bounds_, 406 sublabel_color_, sublabel_text_bounds_,
371 gfx::Canvas::NO_ELLIPSIS); 407 gfx::Canvas::NO_ELLIPSIS);
372 } 408 }
373 409
374 class CompletionMessageView : public views::View { 410 class CompletionMessageView : public views::View {
375 public: 411 public:
376 CompletionMessageView(const gfx::Rect& bounds, const base::string16& message); 412 CompletionMessageView(const gfx::Rect& bounds, const base::string16& message);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 // Initialize the Hint Box view. 565 // Initialize the Hint Box view.
530 base::string16 hint_label_text = 566 base::string16 hint_label_text =
531 rb.GetLocalizedString(IDS_DISPLAY_TOUCH_CALIBRATION_HINT_LABEL_TEXT); 567 rb.GetLocalizedString(IDS_DISPLAY_TOUCH_CALIBRATION_HINT_LABEL_TEXT);
532 base::string16 hint_sublabel_text = 568 base::string16 hint_sublabel_text =
533 rb.GetLocalizedString(IDS_DISPLAY_TOUCH_CALIBRATION_HINT_SUBLABEL_TEXT); 569 rb.GetLocalizedString(IDS_DISPLAY_TOUCH_CALIBRATION_HINT_SUBLABEL_TEXT);
534 570
535 int tpv_width = touch_point_view_->width(); 571 int tpv_width = touch_point_view_->width();
536 572
537 gfx::Size size(kHintBoxWidth, kHintBoxHeight); 573 gfx::Size size(kHintBoxWidth, kHintBoxHeight);
538 574
539 gfx::Point position( 575 gfx::Point position(touch_point_view_->x() + tpv_width * 1.2f,
540 touch_point_view_->x() + tpv_width * 1.2f, 576 touch_point_view_->y() +
541 touch_point_view_->y() + (tpv_width / 2.f) - (size.height() / 2.f)); 577 (kThrobberCircleViewWidth / 2.f) -
578 (size.height() / 2.f));
542 579
543 HintBox* hint_box = 580 HintBox* hint_box =
544 new HintBox(gfx::Rect(position, size), kHintRectBorderRadius); 581 new HintBox(gfx::Rect(position, size), kHintRectBorderRadius);
545 hint_box->SetVisible(false); 582 hint_box->SetVisible(false);
546 hint_box->SetLabel(hint_label_text, kHintLabelTextColor); 583 hint_box->SetLabel(hint_label_text, kHintLabelTextColor);
547 hint_box->SetSubLabel(hint_sublabel_text, kHintSublabelTextColor); 584 hint_box->SetSubLabel(hint_sublabel_text, kHintSublabelTextColor);
548 hint_box_view_ = hint_box; 585 hint_box_view_ = hint_box;
549 586
550 AddChildView(hint_box_view_); 587 AddChildView(hint_box_view_);
551 588
552 // Initialize the animated hint box throbber view. 589 // Initialize the animated hint box throbber view.
553 TouchTargetThrobberView* target_view = new TouchTargetThrobberView( 590 TouchTargetThrobberView* target_view = new TouchTargetThrobberView(
554 gfx::Rect((size.width() - kTouchTargetWidth) / 2, 591 gfx::Rect((hint_box->width() - kTouchTargetWidth) / 2,
555 size.height() * kTouchTargetVerticalOffsetFactor, 592 hint_box->height() * kTouchTargetVerticalOffsetFactor,
556 kTouchTargetWidth, kTouchTargetHeight), 593 kTouchTargetWidth, kTouchTargetHeight),
557 kTouchTargetInnerCircleColor, kTouchTargetOuterCircleColor, 594 kTouchTargetInnerCircleColor, kTouchTargetOuterCircleColor,
558 kHandIconColor, kCircleAnimationDurationMs); 595 kHandIconColor, kCircleAnimationDurationMs);
559 target_view->SetVisible(true); 596 target_view->SetVisible(true);
560 597
561 hint_box_view_->AddChildView(target_view); 598 hint_box_view_->AddChildView(target_view);
562 599
563 // Initialize the view that contains the calibration complete message which 600 // Initialize the view that contains the calibration complete message which
564 // will be displayed at the end. 601 // will be displayed at the end.
565 base::string16 finish_msg_text = 602 base::string16 finish_msg_text =
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 void TouchCalibratorView::SkipCurrentAnimation() { 824 void TouchCalibratorView::SkipCurrentAnimation() {
788 if (animator_->is_animating()) 825 if (animator_->is_animating())
789 animator_->End(); 826 animator_->End();
790 if (touch_point_view_ && 827 if (touch_point_view_ &&
791 touch_point_view_->layer()->GetAnimator()->is_animating()) { 828 touch_point_view_->layer()->GetAnimator()->is_animating()) {
792 touch_point_view_->layer()->GetAnimator()->StopAnimating(); 829 touch_point_view_->layer()->GetAnimator()->StopAnimating();
793 } 830 }
794 } 831 }
795 832
796 } // namespace chromeos 833 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698