Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| 13 namespace gfx { | |
| 14 class RenderText; | |
| 15 }; | |
|
tapted
2016/10/11 04:42:09
no ;
karandeepb
2016/10/14 09:27:34
Done.
| |
| 16 | |
| 17 namespace ui { | |
| 18 class MouseEvent; | |
| 19 } | |
| 20 | |
| 21 namespace views { | |
| 22 class SelectionControllerHost; | |
| 23 | |
| 24 // Helper class used by a SelectionControllerHost to facilitate mouse event | |
| 25 // handling and text selection. The class does not modify | |
| 26 // SelectionControllerHost's render text instance directly. Instead, all write | |
| 27 // operations are routed through calls to the SelectionControllerHost. | |
| 28 class SelectionController { | |
| 29 public: | |
| 30 explicit SelectionController(SelectionControllerHost* host); | |
| 31 | |
| 32 // Handle mouse events forwarded by |host_|. If |handled| is true, the mouse | |
| 33 // event is just used to update internal state without making any other | |
| 34 // changes. | |
| 35 bool OnMousePressed(const ui::MouseEvent& event, bool handled); | |
| 36 bool OnMouseDragged(const ui::MouseEvent& event); | |
| 37 void OnMouseReleased(const ui::MouseEvent& event); | |
| 38 | |
| 39 // Returns the latest click location. | |
| 40 gfx::Point last_click_location() const { return last_click_location_; } | |
| 41 | |
| 42 private: | |
| 43 // Tracks the mouse clicks for single/double/triple clicks. | |
| 44 void TrackMouseClicks(const ui::MouseEvent& event); | |
| 45 | |
| 46 // Returns the associated render text instance via the |host_|. | |
| 47 // Todo(karandeepb): Modify this to return a pointer to a const RenderText. | |
| 48 gfx::RenderText* GetRenderText(); | |
| 49 | |
| 50 // Helper function to update the selection on a mouse drag as per | |
| 51 // |last_drag_location_|. Can be called asynchronously. | |
| 52 void SelectThroughLastDragLocation(); | |
| 53 | |
| 54 // A timer and point used to modify the selection when dragging. | |
| 55 base::RepeatingTimer drag_selection_timer_; | |
| 56 gfx::Point last_drag_location_; | |
| 57 | |
| 58 // State variables used to track double and triple clicks. | |
| 59 base::TimeTicks last_click_time_; | |
| 60 gfx::Point last_click_location_; | |
| 61 size_t aggregated_clicks_; | |
| 62 gfx::Range double_click_word_; | |
| 63 | |
| 64 // The associated SelectionControllerHost instance. Weak pointer. | |
| 65 SelectionControllerHost* host_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(SelectionController); | |
| 68 }; | |
| 69 | |
| 70 } // namespace views | |
| 71 | |
| 72 #endif // UI_VIEWS_SELECTION_CONTROLLER_H_ | |
| OLD | NEW |