1 // Copyright 2018 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 #ifndef CHROME_BROWSER_VR_PLATFORM_UI_INPUT_DELEGATE_H_
6 #define CHROME_BROWSER_VR_PLATFORM_UI_INPUT_DELEGATE_H_
7 
8 #include <memory>
9 #include <queue>
10 
11 #include "base/bind.h"
12 #include "base/callback.h"
13 #include "base/macros.h"
14 #include "chrome/browser/vr/input_event.h"
15 #include "chrome/browser/vr/macros.h"
16 #include "chrome/browser/vr/model/text_input_info.h"
17 #include "chrome/browser/vr/text_edit_action.h"
18 #include "chrome/browser/vr/vr_base_export.h"
19 #include "ui/gfx/geometry/size.h"
20 
21 namespace base {
22 class TimeTicks;
23 }  // namespace base
24 
25 namespace gfx {
26 class PointF;
27 }  // namespace gfx
28 
29 namespace vr {
30 
31 class PlatformInputHandler;
32 
33 // This class is responsible for processing all events and gestures for
34 // PlatformUiElement.
35 class VR_BASE_EXPORT PlatformUiInputDelegate {
36  public:
37   PlatformUiInputDelegate();
38   explicit PlatformUiInputDelegate(PlatformInputHandler* input_handler);
39   virtual ~PlatformUiInputDelegate();
40 
size()41   const gfx::Size& size() const { return size_; }
42 
43   // The following functions are virtual so that they may be overridden in the
44   // MockContentInputDelegate.
45   VIRTUAL_FOR_MOCKS void OnHoverEnter(const gfx::PointF& normalized_hit_point,
46                                       base::TimeTicks timestamp);
47   VIRTUAL_FOR_MOCKS void OnHoverLeave(base::TimeTicks timestamp);
48   VIRTUAL_FOR_MOCKS void OnHoverMove(const gfx::PointF& normalized_hit_point,
49                                      base::TimeTicks timestamp);
50   VIRTUAL_FOR_MOCKS void OnButtonDown(const gfx::PointF& normalized_hit_point,
51                                       base::TimeTicks timestamp);
52   VIRTUAL_FOR_MOCKS void OnButtonUp(const gfx::PointF& normalized_hit_point,
53                                     base::TimeTicks timestamp);
54   VIRTUAL_FOR_MOCKS void OnTouchMove(const gfx::PointF& normalized_hit_point,
55                                      base::TimeTicks timestamp);
56   VIRTUAL_FOR_MOCKS void OnInputEvent(std::unique_ptr<InputEvent> event,
57                                       const gfx::PointF& normalized_hit_point);
58 
SetSize(int width,int height)59   void SetSize(int width, int height) { size_ = {width, height}; }
SetPlatformInputHandlerForTest(PlatformInputHandler * input_handler)60   void SetPlatformInputHandlerForTest(PlatformInputHandler* input_handler) {
61     input_handler_ = input_handler;
62   }
63 
64  protected:
65   virtual void SendGestureToTarget(std::unique_ptr<InputEvent> event);
input_handler()66   PlatformInputHandler* input_handler() const { return input_handler_; }
67 
68  private:
69   void UpdateGesture(const gfx::PointF& normalized_content_hit_point,
70                      InputEvent* gesture);
71   std::unique_ptr<InputEvent> MakeInputEvent(
72       InputEvent::Type type,
73       const gfx::PointF& normalized_web_content_location,
74       base::TimeTicks time_stamp) const;
75   gfx::Point CalculateLocation(
76       const gfx::PointF& normalized_web_content_location) const;
77 
78   gfx::Size size_;
79 
80   PlatformInputHandler* input_handler_ = nullptr;
81 
82   DISALLOW_COPY_AND_ASSIGN(PlatformUiInputDelegate);
83 };
84 
85 }  // namespace vr
86 
87 #endif  // CHROME_BROWSER_VR_PLATFORM_UI_INPUT_DELEGATE_H_
88