Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: ui/views/selection_controller.h

Issue 2408623002: Views: Extract text selection code from Textfield. (Closed)
Patch Set: Rebase. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 UI_VIEWS_SELECTION_CONTROLLER_H_
6 #define UI_VIEWS_SELECTION_CONTROLLER_H_
7
8 #include "base/time/time.h"
9 #include "base/timer/timer.h"
10 #include "ui/gfx/geometry/point.h"
11 #include "ui/gfx/range/range.h"
12 #include "ui/gfx/selection_model.h"
13 #include "ui/views/views_export.h"
14
15 namespace gfx {
16 class RenderText;
17 }
18
19 namespace ui {
20 class MouseEvent;
21 }
22
23 namespace views {
24 class SelectionControllerDelegate;
25
26 // Helper class used to facilitate mouse event handling and text selection. To
27 // use, clients must implement the SelectionControllerDelegate interface.
28 class VIEWS_EXPORT SelectionController {
29 public:
30 // |delegate| must be non-null.
31 explicit SelectionController(SelectionControllerDelegate* delegate);
32
33 // Handle mouse events forwarded by |delegate_|. |handled| specifies whether
34 // the event has already been handled by the |delegate_|. If |handled| is
35 // true, the mouse event is just used to update the internal state without
36 // updating the state of the associated RenderText instance.
37 bool OnMousePressed(const ui::MouseEvent& event, bool handled);
38 bool OnMouseDragged(const ui::MouseEvent& event);
39 void OnMouseReleased(const ui::MouseEvent& event);
40
41 // Returns the latest click location.
42 gfx::Point last_click_location() const { return last_click_location_; }
43
44 private:
45 // Helper methods to call the corresponding methods on the associated
46 // RenderText instance.
47 void SelectAll(bool reversed);
48 void SelectWordAt(const gfx::Point& point);
49 void SelectWord();
50 void SelectRange(const gfx::Range& range);
51 void MoveCursorTo(const gfx::Point& point, bool select);
52 void ClearSelection();
53
54 // Selects till the beginning/end of line in the given |direction|.
55 // TODO(karandeepb): Remove once multi-line text selection is supported.
56 void SelectTillEdge(gfx::VisualCursorDirection direction);
57
58 // Tracks the mouse clicks for single/double/triple clicks.
59 void TrackMouseClicks(const ui::MouseEvent& event);
60
61 // Returns the associated render text instance via the |delegate_|.
62 gfx::RenderText* GetRenderText();
63
64 // Helper function to update the selection on a mouse drag as per
65 // |last_drag_location_|. Can be called asynchronously, through a timer.
66 void SelectThroughLastDragLocation();
67
68 // A timer and point used to modify the selection when dragging.
69 base::RepeatingTimer drag_selection_timer_;
70 gfx::Point last_drag_location_;
71
72 // State variables used to track double and triple clicks.
73 base::TimeTicks last_click_time_;
74 gfx::Point last_click_location_;
75 size_t aggregated_clicks_;
76 gfx::Range double_click_word_;
77
78 // Weak pointer.
79 SelectionControllerDelegate* delegate_;
80
81 DISALLOW_COPY_AND_ASSIGN(SelectionController);
82 };
83
84 } // namespace views
85
86 #endif // UI_VIEWS_SELECTION_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698