[email protected] | 21f4012 | 2013-02-14 21:58:35 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 79f06c737 | 2011-11-21 18:00:32 | [diff] [blame] | 5 | #ifndef UI_UI_VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_IMPL_H_ |
6 | #define UI_UI_VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_IMPL_H_ | ||||
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 7 | |
[email protected] | 4723a44 | 2011-08-26 20:11:53 | [diff] [blame] | 8 | #include "base/timer.h" |
[email protected] | fa246b2 | 2013-02-13 06:18:00 | [diff] [blame] | 9 | #include "ui/base/touch/touch_editing_controller.h" |
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 10 | #include "ui/gfx/point.h" |
[email protected] | 5025f86 | 2011-11-30 23:35:20 | [diff] [blame] | 11 | #include "ui/views/view.h" |
[email protected] | 45647af | 2011-12-01 16:09:33 | [diff] [blame] | 12 | #include "ui/views/views_export.h" |
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 13 | |
14 | namespace views { | ||||
15 | |||||
16 | // Touch specific implementation of TouchSelectionController. Responsible for | ||||
17 | // displaying selection handles and menu elements relevant in a touch interface. | ||||
[email protected] | f283925 | 2011-08-26 20:09:10 | [diff] [blame] | 18 | class VIEWS_EXPORT TouchSelectionControllerImpl |
[email protected] | 21f4012 | 2013-02-14 21:58:35 | [diff] [blame] | 19 | : public ui::TouchSelectionController { |
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 20 | public: |
21 | // Use TextSelectionController::create(). | ||||
[email protected] | fa246b2 | 2013-02-13 06:18:00 | [diff] [blame] | 22 | explicit TouchSelectionControllerImpl( |
23 | ui::TouchEditable* client_view); | ||||
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 24 | |
25 | virtual ~TouchSelectionControllerImpl(); | ||||
26 | |||||
27 | // TextSelectionController. | ||||
[email protected] | 21f4012 | 2013-02-14 21:58:35 | [diff] [blame] | 28 | virtual void SelectionChanged(const gfx::Point& p1, |
29 | const gfx::Point& p2) OVERRIDE; | ||||
30 | |||||
31 | virtual void ClientViewLostFocus() OVERRIDE; | ||||
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 32 | |
33 | private: | ||||
[email protected] | 6350b9f | 2011-08-08 19:03:59 | [diff] [blame] | 34 | friend class TouchSelectionControllerImplTest; |
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 35 | class SelectionHandleView; |
[email protected] | 21f4012 | 2013-02-14 21:58:35 | [diff] [blame] | 36 | class TouchContextMenuView; |
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 37 | |
38 | // Callback to inform the client view that the selection handle has been | ||||
39 | // dragged, hence selection may need to be updated. | ||||
[email protected] | cdd70c6 | 2011-08-03 18:47:23 | [diff] [blame] | 40 | void SelectionHandleDragged(const gfx::Point& drag_pos); |
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 41 | |
42 | // Convenience method to convert a point from a selection handle's coordinate | ||||
43 | // system to that of the client view. | ||||
44 | void ConvertPointToClientView(SelectionHandleView* source, gfx::Point* point); | ||||
45 | |||||
[email protected] | 21f4012 | 2013-02-14 21:58:35 | [diff] [blame] | 46 | // Checks if the client view supports a context menu command. |
47 | bool IsCommandIdEnabled(int command_id) const; | ||||
[email protected] | 4723a44 | 2011-08-26 20:11:53 | [diff] [blame] | 48 | |
[email protected] | 21f4012 | 2013-02-14 21:58:35 | [diff] [blame] | 49 | // Sends a context menu command to the client view. |
50 | void ExecuteCommand(int command_id); | ||||
[email protected] | 4723a44 | 2011-08-26 20:11:53 | [diff] [blame] | 51 | |
52 | // Time to show context menu. | ||||
53 | void ContextMenuTimerFired(); | ||||
54 | |||||
55 | // Convenience method to update the position/visibility of the context menu. | ||||
56 | void UpdateContextMenu(const gfx::Point& p1, const gfx::Point& p2); | ||||
57 | |||||
58 | // Convenience method for hiding context menu. | ||||
59 | void HideContextMenu(); | ||||
60 | |||||
[email protected] | 6350b9f | 2011-08-08 19:03:59 | [diff] [blame] | 61 | // Convenience methods for testing. |
62 | gfx::Point GetSelectionHandle1Position(); | ||||
63 | gfx::Point GetSelectionHandle2Position(); | ||||
64 | bool IsSelectionHandle1Visible(); | ||||
65 | bool IsSelectionHandle2Visible(); | ||||
66 | |||||
[email protected] | fa246b2 | 2013-02-13 06:18:00 | [diff] [blame] | 67 | ui::TouchEditable* client_view_; |
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 68 | scoped_ptr<SelectionHandleView> selection_handle_1_; |
69 | scoped_ptr<SelectionHandleView> selection_handle_2_; | ||||
[email protected] | 21f4012 | 2013-02-14 21:58:35 | [diff] [blame] | 70 | scoped_ptr<TouchContextMenuView> context_menu_; |
[email protected] | 4723a44 | 2011-08-26 20:11:53 | [diff] [blame] | 71 | |
72 | // Timer to trigger |context_menu| (|context_menu| is not shown if the | ||||
73 | // selection handles are being updated. It appears only when the handles are | ||||
74 | // stationary for a certain amount of time). | ||||
75 | base::OneShotTimer<TouchSelectionControllerImpl> context_menu_timer_; | ||||
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 76 | |
77 | // Pointer to the SelectionHandleView being dragged during a drag session. | ||||
78 | SelectionHandleView* dragging_handle_; | ||||
79 | |||||
80 | DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImpl); | ||||
81 | }; | ||||
82 | |||||
[email protected] | 4a3f5a6 | 2011-08-03 01:19:10 | [diff] [blame] | 83 | } // namespace views |
84 | |||||
[email protected] | 79f06c737 | 2011-11-21 18:00:32 | [diff] [blame] | 85 | #endif // UI_UI_VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_IMPL_H_ |