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

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

Issue 2408623002: Views: Extract text selection code from Textfield. (Closed)
Patch Set: 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 // Tracks the mouse clicks for single/double/triple clicks.
46 void TrackMouseClicks(const ui::MouseEvent& event);
47
48 // Returns the associated render text instance via the |delegate_|.
49 gfx::RenderText* GetRenderText();
50
51 // Helper function to update the selection on a mouse drag as per
52 // |last_drag_location_|. Can be called asynchronously, through a timer.
53 void SelectThroughLastDragLocation();
54
55 // A timer and point used to modify the selection when dragging.
56 base::RepeatingTimer drag_selection_timer_;
57 gfx::Point last_drag_location_;
58
59 // State variables used to track double and triple clicks.
60 base::TimeTicks last_click_time_;
61 gfx::Point last_click_location_;
62 size_t aggregated_clicks_;
63 gfx::Range double_click_word_;
64
65 // Weak pointer.
66 SelectionControllerDelegate* delegate_;
67
68 DISALLOW_COPY_AND_ASSIGN(SelectionController);
69 };
70
71 } // namespace views
72
73 #endif // UI_VIEWS_SELECTION_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698