OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_CLIENT_AU RA_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_CLIENT_AU RA_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_CLIENT_AU RA_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_CLIENT_AU RA_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/observer_list.h" | |
11 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "content/browser/renderer_host/input/touch_selection_controller_client_ manager.h" | |
12 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
13 #include "ui/touch_selection/touch_selection_controller.h" | 15 #include "ui/touch_selection/touch_selection_controller.h" |
14 #include "ui/touch_selection/touch_selection_menu_runner.h" | 16 #include "ui/touch_selection/touch_selection_menu_runner.h" |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 struct ContextMenuParams; | 19 struct ContextMenuParams; |
18 class RenderWidgetHostViewAura; | 20 class RenderWidgetHostViewAura; |
19 | 21 |
20 // An implementation of |TouchSelectionControllerClient| to be used in Aura's | 22 // An implementation of |TouchSelectionControllerClient| to be used in Aura's |
21 // implementation of touch selection for contents. | 23 // implementation of touch selection for contents. |
22 class CONTENT_EXPORT TouchSelectionControllerClientAura | 24 class CONTENT_EXPORT TouchSelectionControllerClientAura |
23 : public ui::TouchSelectionControllerClient, | 25 : public ui::TouchSelectionControllerClient, |
24 public ui::TouchSelectionMenuClient { | 26 public ui::TouchSelectionMenuClient, |
27 public TouchSelectionControllerClientManager { | |
25 public: | 28 public: |
26 explicit TouchSelectionControllerClientAura(RenderWidgetHostViewAura* rwhva); | 29 explicit TouchSelectionControllerClientAura(RenderWidgetHostViewAura* rwhva); |
27 ~TouchSelectionControllerClientAura() override; | 30 ~TouchSelectionControllerClientAura() override; |
28 | 31 |
29 // Called when |rwhva_|'s window is moved, to update the quick menu's | 32 // Called when |rwhva_|'s window is moved, to update the quick menu's |
30 // position. | 33 // position. |
31 void OnWindowMoved(); | 34 void OnWindowMoved(); |
32 | 35 |
33 // Called on first touch down/last touch up to hide/show the quick menu. | 36 // Called on first touch down/last touch up to hide/show the quick menu. |
34 void OnTouchDown(); | 37 void OnTouchDown(); |
35 void OnTouchUp(); | 38 void OnTouchUp(); |
36 | 39 |
37 // Called when touch scroll starts/completes to hide/show touch handles and | 40 // Called when touch scroll starts/completes to hide/show touch handles and |
38 // the quick menu. | 41 // the quick menu. |
39 void OnScrollStarted(); | 42 void OnScrollStarted(); |
40 void OnScrollCompleted(); | 43 void OnScrollCompleted(); |
41 | 44 |
42 // Gives an opportunity to the client to handle context menu request and show | 45 // Gives an opportunity to the client to handle context menu request and show |
43 // the quick menu instead, if appropriate. Returns |true| to indicate that no | 46 // the quick menu instead, if appropriate. Returns |true| to indicate that no |
44 // further handling is needed. | 47 // further handling is needed. |
45 // TODO(mohsen): This is to match Chrome on Android behavior. However, it is | 48 // TODO(mohsen): This is to match Chrome on Android behavior. However, it is |
46 // better not to send context menu request from the renderer in this case and | 49 // better not to send context menu request from the renderer in this case and |
47 // instead decide in the client about showing the quick menu in response to | 50 // instead decide in the client about showing the quick menu in response to |
48 // selection events. (http://crbug.com/548245) | 51 // selection events. (http://crbug.com/548245) |
49 bool HandleContextMenu(const ContextMenuParams& params); | 52 bool HandleContextMenu(const ContextMenuParams& params); |
50 | 53 |
54 void UpdateClientSelectionBounds(const gfx::SelectionBound& start, | |
55 const gfx::SelectionBound& end); | |
56 | |
57 // TouchSelectionControllerClientManager. | |
58 void UpdateClientSelectionBounds( | |
59 const gfx::SelectionBound& start, | |
60 const gfx::SelectionBound& end, | |
61 ui::TouchSelectionControllerClient* client, | |
62 ui::TouchSelectionMenuClient* menu_client) override; | |
63 void InvalidateClient(ui::TouchSelectionControllerClient* client) override; | |
64 ui::TouchSelectionController* GetTouchSelectionController() override; | |
65 void AddObserver( | |
66 TouchSelectionControllerClientManager::Observer* observer) override; | |
67 void RemoveObserver( | |
68 TouchSelectionControllerClientManager::Observer* observer) override; | |
69 | |
51 private: | 70 private: |
52 friend class TestTouchSelectionControllerClientAura; | 71 friend class TestTouchSelectionControllerClientAura; |
53 class EnvPreTargetHandler; | 72 class EnvPreTargetHandler; |
54 | 73 |
55 bool IsQuickMenuAvailable() const; | 74 bool IsQuickMenuAvailable() const; |
56 void ShowQuickMenu(); | 75 void ShowQuickMenu(); |
57 void UpdateQuickMenu(); | 76 void UpdateQuickMenu(); |
58 | 77 |
59 // ui::TouchSelectionControllerClient: | 78 // ui::TouchSelectionControllerClient: |
60 bool SupportsAnimation() const override; | 79 bool SupportsAnimation() const override; |
61 void SetNeedsAnimate() override; | 80 void SetNeedsAnimate() override; |
62 void MoveCaret(const gfx::PointF& position) override; | 81 void MoveCaret(const gfx::PointF& position) override; |
63 void MoveRangeSelectionExtent(const gfx::PointF& extent) override; | 82 void MoveRangeSelectionExtent(const gfx::PointF& extent) override; |
64 void SelectBetweenCoordinates(const gfx::PointF& base, | 83 void SelectBetweenCoordinates(const gfx::PointF& base, |
65 const gfx::PointF& extent) override; | 84 const gfx::PointF& extent) override; |
66 void OnSelectionEvent(ui::SelectionEventType event) override; | 85 void OnSelectionEvent(ui::SelectionEventType event) override; |
67 std::unique_ptr<ui::TouchHandleDrawable> CreateDrawable() override; | 86 std::unique_ptr<ui::TouchHandleDrawable> CreateDrawable() override; |
68 | 87 |
69 // ui::TouchSelectionMenuClient: | 88 // ui::TouchSelectionMenuClient: |
70 bool IsCommandIdEnabled(int command_id) const override; | 89 bool IsCommandIdEnabled(int command_id) const override; |
71 void ExecuteCommand(int command_id, int event_flags) override; | 90 void ExecuteCommand(int command_id, int event_flags) override; |
72 void RunContextMenu() override; | 91 void RunContextMenu() override; |
73 | 92 |
74 // Not owned, non-null for the lifetime of this object. | 93 // Not owned, non-null for the lifetime of this object. |
75 RenderWidgetHostViewAura* rwhva_; | 94 RenderWidgetHostViewAura* rwhva_; |
76 | 95 |
96 class InternalClient : public TouchSelectionControllerClient { | |
97 public: | |
98 InternalClient(RenderWidgetHostViewAura* rwhva) : rwhva_(rwhva) {} | |
99 ~InternalClient() final {} | |
100 | |
101 bool SupportsAnimation() const final; | |
102 void SetNeedsAnimate() final; | |
103 void MoveCaret(const gfx::PointF& position) final; | |
104 void MoveRangeSelectionExtent(const gfx::PointF& extent) final; | |
105 void SelectBetweenCoordinates(const gfx::PointF& base, | |
106 const gfx::PointF& extent) final; | |
107 void OnSelectionEvent(ui::SelectionEventType event) final; | |
108 std::unique_ptr<ui::TouchHandleDrawable> CreateDrawable() final; | |
109 | |
110 private: | |
111 RenderWidgetHostViewAura* rwhva_; | |
112 } internal_client_; | |
113 | |
114 // Keep tracke of which client interface to use. | |
kenrb
2017/05/23 16:19:03
nit: /s/tracke/track
wjmaclean
2017/05/23 17:00:41
Done.
| |
115 TouchSelectionControllerClient* active_client_; | |
116 TouchSelectionMenuClient* active_menu_client_; | |
117 gfx::SelectionBound manager_selection_start_; | |
118 gfx::SelectionBound manager_selection_end_; | |
119 | |
120 base::ObserverList<TouchSelectionControllerClientManager::Observer> | |
121 observers_; | |
122 | |
77 base::Timer quick_menu_timer_; | 123 base::Timer quick_menu_timer_; |
78 bool quick_menu_requested_; | 124 bool quick_menu_requested_; |
79 bool touch_down_; | 125 bool touch_down_; |
80 bool scroll_in_progress_; | 126 bool scroll_in_progress_; |
81 bool handle_drag_in_progress_; | 127 bool handle_drag_in_progress_; |
82 | 128 |
83 bool show_quick_menu_immediately_for_test_; | 129 bool show_quick_menu_immediately_for_test_; |
84 | 130 |
85 // A pre-target event handler for aura::Env which deactivates touch selection | 131 // A pre-target event handler for aura::Env which deactivates touch selection |
86 // on mouse and keyboard events. | 132 // on mouse and keyboard events. |
87 std::unique_ptr<EnvPreTargetHandler> env_pre_target_handler_; | 133 std::unique_ptr<EnvPreTargetHandler> env_pre_target_handler_; |
88 | 134 |
89 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerClientAura); | 135 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerClientAura); |
90 }; | 136 }; |
91 | 137 |
92 } // namespace content | 138 } // namespace content |
93 | 139 |
94 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_CLIENT _AURA_H_ | 140 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_CLIENT _AURA_H_ |
OLD | NEW |