1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "ash/highlighter/highlighter_controller_test_api.h"
6 
7 #include "ash/fast_ink/fast_ink_points.h"
8 #include "ash/highlighter/highlighter_controller.h"
9 #include "ash/highlighter/highlighter_view.h"
10 #include "base/timer/timer.h"
11 
12 namespace ash {
13 
HighlighterControllerTestApi(HighlighterController * instance)14 HighlighterControllerTestApi::HighlighterControllerTestApi(
15     HighlighterController* instance)
16     : instance_(instance) {
17   AttachClient();
18 }
19 
~HighlighterControllerTestApi()20 HighlighterControllerTestApi::~HighlighterControllerTestApi() {
21   if (scoped_observer_)
22     DetachClient();
23   if (instance_->enabled())
24     instance_->SetEnabled(false);
25   instance_->DestroyPointerView();
26 }
27 
AttachClient()28 void HighlighterControllerTestApi::AttachClient() {
29   scoped_observer_ = std::make_unique<ScopedObserver>(this);
30   scoped_observer_->Add(instance_);
31 }
32 
DetachClient()33 void HighlighterControllerTestApi::DetachClient() {
34   scoped_observer_.reset();
35   instance_->CallExitCallback();
36 }
37 
SetEnabled(bool enabled)38 void HighlighterControllerTestApi::SetEnabled(bool enabled) {
39   instance_->UpdateEnabledState(
40       enabled ? HighlighterEnabledState::kEnabled
41               : HighlighterEnabledState::kDisabledBySessionComplete);
42 }
43 
DestroyPointerView()44 void HighlighterControllerTestApi::DestroyPointerView() {
45   instance_->DestroyPointerView();
46 }
47 
SimulateInterruptedStrokeTimeout()48 void HighlighterControllerTestApi::SimulateInterruptedStrokeTimeout() {
49   if (!instance_->interrupted_stroke_timer_)
50     return;
51   instance_->interrupted_stroke_timer_->Stop();
52   instance_->RecognizeGesture();
53 }
54 
IsShowingHighlighter() const55 bool HighlighterControllerTestApi::IsShowingHighlighter() const {
56   return !!instance_->highlighter_view_widget_;
57 }
58 
IsFadingAway() const59 bool HighlighterControllerTestApi::IsFadingAway() const {
60   return IsShowingHighlighter() && instance_->GetHighlighterView()->animating();
61 }
62 
IsShowingSelectionResult() const63 bool HighlighterControllerTestApi::IsShowingSelectionResult() const {
64   return !!instance_->result_view_widget_;
65 }
66 
IsWaitingToResumeStroke() const67 bool HighlighterControllerTestApi::IsWaitingToResumeStroke() const {
68   return instance_->interrupted_stroke_timer_ &&
69          instance_->interrupted_stroke_timer_->IsRunning();
70 }
71 
points() const72 const fast_ink::FastInkPoints& HighlighterControllerTestApi::points() const {
73   return instance_->GetHighlighterView()->points_;
74 }
75 
predicted_points() const76 const fast_ink::FastInkPoints& HighlighterControllerTestApi::predicted_points()
77     const {
78   return instance_->GetHighlighterView()->predicted_points_;
79 }
80 
HandleEnabledStateChangedCalled()81 bool HighlighterControllerTestApi::HandleEnabledStateChangedCalled() {
82   return handle_enabled_state_changed_called_;
83 }
84 
HandleSelectionCalled()85 bool HighlighterControllerTestApi::HandleSelectionCalled() {
86   return handle_selection_called_;
87 }
88 
OnHighlighterSelectionRecognized(const gfx::Rect & rect)89 void HighlighterControllerTestApi::OnHighlighterSelectionRecognized(
90     const gfx::Rect& rect) {
91   handle_selection_called_ = true;
92   selection_ = rect;
93 }
94 
OnHighlighterEnabledChanged(HighlighterEnabledState state)95 void HighlighterControllerTestApi::OnHighlighterEnabledChanged(
96     HighlighterEnabledState state) {
97   const bool enabled = (state == HighlighterEnabledState::kEnabled);
98   handle_enabled_state_changed_called_ = true;
99   enabled_ = enabled;
100 }
101 
102 }  // namespace ash
103