| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_VIEWS_SELECTION_CONTROLLER_H_ | 5 #ifndef UI_VIEWS_SELECTION_CONTROLLER_H_ |
| 6 #define UI_VIEWS_SELECTION_CONTROLLER_H_ | 6 #define UI_VIEWS_SELECTION_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "ui/gfx/geometry/point.h" | 10 #include "ui/gfx/geometry/point.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace views { | 23 namespace views { |
| 24 class SelectionControllerDelegate; | 24 class SelectionControllerDelegate; |
| 25 | 25 |
| 26 // Helper class used to facilitate mouse event handling and text selection. To | 26 // Helper class used to facilitate mouse event handling and text selection. To |
| 27 // use, clients must implement the SelectionControllerDelegate interface. | 27 // use, clients must implement the SelectionControllerDelegate interface. |
| 28 // TODO(karandeepb): Also make this class handle gesture events. | 28 // TODO(karandeepb): Also make this class handle gesture events. |
| 29 class VIEWS_EXPORT SelectionController { | 29 class VIEWS_EXPORT SelectionController { |
| 30 public: | 30 public: |
| 31 // Describes whether the view managing the delegate was initially focused when |
| 32 // the mouse press was received. |
| 33 enum InitialFocusStateOnMousePress { |
| 34 FOCUSED, |
| 35 UNFOCUSED, |
| 36 }; |
| 37 |
| 31 // |delegate| must be non-null. | 38 // |delegate| must be non-null. |
| 32 explicit SelectionController(SelectionControllerDelegate* delegate); | 39 explicit SelectionController(SelectionControllerDelegate* delegate); |
| 33 | 40 |
| 34 // Handle mouse events forwarded by |delegate_|. |handled| specifies whether | 41 // Handle mouse events forwarded by |delegate_|. |handled| specifies whether |
| 35 // the event has already been handled by the |delegate_|. If |handled| is | 42 // the event has already been handled by the |delegate_|. If |handled| is |
| 36 // true, the mouse event is just used to update the internal state without | 43 // true, the mouse event is just used to update the internal state without |
| 37 // updating the state of the associated RenderText instance. | 44 // updating the state of the associated RenderText instance. |
| 38 bool OnMousePressed(const ui::MouseEvent& event, bool handled); | 45 bool OnMousePressed(const ui::MouseEvent& event, |
| 46 bool handled, |
| 47 InitialFocusStateOnMousePress initial_focus_state); |
| 39 bool OnMouseDragged(const ui::MouseEvent& event); | 48 bool OnMouseDragged(const ui::MouseEvent& event); |
| 40 void OnMouseReleased(const ui::MouseEvent& event); | 49 void OnMouseReleased(const ui::MouseEvent& event); |
| 41 void OnMouseCaptureLost(); | 50 void OnMouseCaptureLost(); |
| 42 | 51 |
| 43 // Returns the latest click location. | 52 // Returns the latest click location. |
| 44 const gfx::Point& last_click_location() const { return last_click_location_; } | 53 const gfx::Point& last_click_location() const { return last_click_location_; } |
| 45 | 54 |
| 46 // Sets whether the SelectionController should update or paste the | 55 // Sets whether the SelectionController should update or paste the |
| 47 // selection clipboard on middle-click. Default is false. | 56 // selection clipboard on middle-click. Default is false. |
| 48 void set_handles_selection_clipboard(bool value) { | 57 void set_handles_selection_clipboard(bool value) { |
| 49 handles_selection_clipboard_ = value; | 58 handles_selection_clipboard_ = value; |
| 50 } | 59 } |
| 51 | 60 |
| 52 private: | 61 private: |
| 53 // Tracks the mouse clicks for single/double/triple clicks. | 62 // Tracks the mouse clicks for single/double/triple clicks. |
| 54 void TrackMouseClicks(const ui::MouseEvent& event); | 63 void TrackMouseClicks(const ui::MouseEvent& event); |
| 55 | 64 |
| 56 // Selects the word at the given |point|. | 65 // Selects the word at the given |point|. |
| 57 void SelectWord(const gfx::Point& point); | 66 void SelectWord(const gfx::Point& point); |
| 58 | 67 |
| 68 // Selects all the text. |
| 69 void SelectAll(); |
| 70 |
| 59 // Returns the associated render text instance via the |delegate_|. | 71 // Returns the associated render text instance via the |delegate_|. |
| 60 gfx::RenderText* GetRenderText(); | 72 gfx::RenderText* GetRenderText(); |
| 61 | 73 |
| 62 // Helper function to update the selection on a mouse drag as per | 74 // Helper function to update the selection on a mouse drag as per |
| 63 // |last_drag_location_|. Can be called asynchronously, through a timer. | 75 // |last_drag_location_|. Can be called asynchronously, through a timer. |
| 64 void SelectThroughLastDragLocation(); | 76 void SelectThroughLastDragLocation(); |
| 65 | 77 |
| 66 // A timer and point used to modify the selection when dragging. | 78 // A timer and point used to modify the selection when dragging. |
| 67 base::RepeatingTimer drag_selection_timer_; | 79 base::RepeatingTimer drag_selection_timer_; |
| 68 gfx::Point last_drag_location_; | 80 gfx::Point last_drag_location_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 84 | 96 |
| 85 // Whether the selection clipboard is handled. | 97 // Whether the selection clipboard is handled. |
| 86 bool handles_selection_clipboard_; | 98 bool handles_selection_clipboard_; |
| 87 | 99 |
| 88 DISALLOW_COPY_AND_ASSIGN(SelectionController); | 100 DISALLOW_COPY_AND_ASSIGN(SelectionController); |
| 89 }; | 101 }; |
| 90 | 102 |
| 91 } // namespace views | 103 } // namespace views |
| 92 | 104 |
| 93 #endif // UI_VIEWS_SELECTION_CONTROLLER_H_ | 105 #endif // UI_VIEWS_SELECTION_CONTROLLER_H_ |
| OLD | NEW |