Chromium Code Reviews| Index: ui/views/selection_controller.h |
| diff --git a/ui/views/selection_controller.h b/ui/views/selection_controller.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..225f15c2ad8d9c33bd0b1474ee5f6bd3a9dea30c |
| --- /dev/null |
| +++ b/ui/views/selection_controller.h |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_VIEWS_SELECTION_CONTROLLER_H_ |
| +#define UI_VIEWS_SELECTION_CONTROLLER_H_ |
| + |
| +#include "base/time/time.h" |
| +#include "base/timer/timer.h" |
| +#include "ui/gfx/geometry/point.h" |
| +#include "ui/gfx/range/range.h" |
| + |
| +namespace gfx { |
| +class RenderText; |
| +}; |
|
tapted
2016/10/11 04:42:09
no ;
karandeepb
2016/10/14 09:27:34
Done.
|
| + |
| +namespace ui { |
| +class MouseEvent; |
| +} |
| + |
| +namespace views { |
| +class SelectionControllerHost; |
| + |
| +// Helper class used by a SelectionControllerHost to facilitate mouse event |
| +// handling and text selection. The class does not modify |
| +// SelectionControllerHost's render text instance directly. Instead, all write |
| +// operations are routed through calls to the SelectionControllerHost. |
| +class SelectionController { |
| + public: |
| + explicit SelectionController(SelectionControllerHost* host); |
| + |
| + // Handle mouse events forwarded by |host_|. If |handled| is true, the mouse |
| + // event is just used to update internal state without making any other |
| + // changes. |
| + bool OnMousePressed(const ui::MouseEvent& event, bool handled); |
| + bool OnMouseDragged(const ui::MouseEvent& event); |
| + void OnMouseReleased(const ui::MouseEvent& event); |
| + |
| + // Returns the latest click location. |
| + gfx::Point last_click_location() const { return last_click_location_; } |
| + |
| + private: |
| + // Tracks the mouse clicks for single/double/triple clicks. |
| + void TrackMouseClicks(const ui::MouseEvent& event); |
| + |
| + // Returns the associated render text instance via the |host_|. |
| + // Todo(karandeepb): Modify this to return a pointer to a const RenderText. |
| + gfx::RenderText* GetRenderText(); |
| + |
| + // Helper function to update the selection on a mouse drag as per |
| + // |last_drag_location_|. Can be called asynchronously. |
| + void SelectThroughLastDragLocation(); |
| + |
| + // A timer and point used to modify the selection when dragging. |
| + base::RepeatingTimer drag_selection_timer_; |
| + gfx::Point last_drag_location_; |
| + |
| + // State variables used to track double and triple clicks. |
| + base::TimeTicks last_click_time_; |
| + gfx::Point last_click_location_; |
| + size_t aggregated_clicks_; |
| + gfx::Range double_click_word_; |
| + |
| + // The associated SelectionControllerHost instance. Weak pointer. |
| + SelectionControllerHost* host_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SelectionController); |
| +}; |
| + |
| +} // namespace views |
| + |
| +#endif // UI_VIEWS_SELECTION_CONTROLLER_H_ |