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 #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); | |
|
sky
2016/10/21 15:03:40
I'm wondering if you can make this class an EventH
sky
2016/10/21 15:03:40
As commented over IM I think touch/gesture should
karandeepb
2016/10/25 05:30:42
Currently Textfield::OnMousePressed first forwards
karandeepb
2016/10/25 05:30:42
Done.
sky
2016/10/25 16:46:03
Fair enough. If you need certain ordering than I a
| |
| 38 bool OnMouseDragged(const ui::MouseEvent& event); | |
| 39 void OnMouseReleased(const ui::MouseEvent& event); | |
|
sky
2016/10/21 15:03:40
What happens if capture is lost? Doesn't that need
karandeepb
2016/10/25 05:30:42
Thanks for the catch. Textfield wasn't handling On
| |
| 40 | |
| 41 // Returns the latest click location. | |
| 42 gfx::Point last_click_location() const { return last_click_location_; } | |
|
sky
2016/10/21 15:03:40
const gfx::Point&
karandeepb
2016/10/25 05:30:42
Done. Is it preferred that we should be returning
sky
2016/10/25 16:46:03
Generally in chromium code you'll see const& retur
| |
| 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_; | |
|
sky
2016/10/21 15:03:40
Please add a comment as to what this means. It isn
karandeepb
2016/10/25 05:30:42
Done.
| |
| 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_ | |
| OLD | NEW |