OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_IMPL_H_ | |
6 #define VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_IMPL_H_ | |
7 #pragma once | |
8 | |
9 #include "base/timer.h" | |
10 #include "ui/gfx/point.h" | |
11 #include "views/touchui/touch_selection_controller.h" | |
12 #include "views/view.h" | |
13 #include "views/views_export.h" | |
14 | |
15 namespace views { | |
16 | |
17 // Touch specific implementation of TouchSelectionController. Responsible for | |
18 // displaying selection handles and menu elements relevant in a touch interface. | |
19 class VIEWS_EXPORT TouchSelectionControllerImpl | |
20 : public TouchSelectionController { | |
21 public: | |
22 // Use TextSelectionController::create(). | |
23 explicit TouchSelectionControllerImpl(TouchSelectionClientView* client_view); | |
24 | |
25 virtual ~TouchSelectionControllerImpl(); | |
26 | |
27 // TextSelectionController. | |
28 virtual void SelectionChanged(const gfx::Point& p1, | |
29 const gfx::Point& p2) OVERRIDE; | |
30 | |
31 virtual void ClientViewLostFocus() OVERRIDE; | |
32 | |
33 private: | |
34 friend class TouchSelectionControllerImplTest; | |
35 class SelectionHandleView; | |
36 class TouchContextMenuView; | |
37 | |
38 // Callback to inform the client view that the selection handle has been | |
39 // dragged, hence selection may need to be updated. | |
40 void SelectionHandleDragged(const gfx::Point& drag_pos); | |
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 | |
46 // Checks if the client view supports a context menu command. | |
47 bool IsCommandIdEnabled(int command_id) const; | |
48 | |
49 // Sends a context menu command to the client view. | |
50 void ExecuteCommand(int command_id); | |
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 | |
61 // Convenience methods for testing. | |
62 gfx::Point GetSelectionHandle1Position(); | |
63 gfx::Point GetSelectionHandle2Position(); | |
64 bool IsSelectionHandle1Visible(); | |
65 bool IsSelectionHandle2Visible(); | |
66 | |
67 TouchSelectionClientView* client_view_; | |
68 scoped_ptr<SelectionHandleView> selection_handle_1_; | |
69 scoped_ptr<SelectionHandleView> selection_handle_2_; | |
70 scoped_ptr<TouchContextMenuView> context_menu_; | |
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_; | |
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 | |
83 } // namespace views | |
84 | |
85 #endif // VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_IMPL_H_ | |
OLD | NEW |