blob: 5d042e739b131c201efdd7dd17b1ff4d796e03be [file] [log] [blame]
[email protected]21f40122013-02-14 21:58:351// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]4a3f5a62011-08-03 01:19:102// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]79f06c7372011-11-21 18:00:325#ifndef UI_UI_VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_IMPL_H_
6#define UI_UI_VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_IMPL_H_
[email protected]4a3f5a62011-08-03 01:19:107
[email protected]4723a442011-08-26 20:11:538#include "base/timer.h"
[email protected]fa246b22013-02-13 06:18:009#include "ui/base/touch/touch_editing_controller.h"
[email protected]4a3f5a62011-08-03 01:19:1010#include "ui/gfx/point.h"
[email protected]5025f862011-11-30 23:35:2011#include "ui/views/view.h"
[email protected]45647af2011-12-01 16:09:3312#include "ui/views/views_export.h"
[email protected]4a3f5a62011-08-03 01:19:1013
14namespace views {
15
16// Touch specific implementation of TouchSelectionController. Responsible for
17// displaying selection handles and menu elements relevant in a touch interface.
[email protected]f2839252011-08-26 20:09:1018class VIEWS_EXPORT TouchSelectionControllerImpl
[email protected]21f40122013-02-14 21:58:3519 : public ui::TouchSelectionController {
[email protected]4a3f5a62011-08-03 01:19:1020 public:
21 // Use TextSelectionController::create().
[email protected]fa246b22013-02-13 06:18:0022 explicit TouchSelectionControllerImpl(
23 ui::TouchEditable* client_view);
[email protected]4a3f5a62011-08-03 01:19:1024
25 virtual ~TouchSelectionControllerImpl();
26
27 // TextSelectionController.
[email protected]21f40122013-02-14 21:58:3528 virtual void SelectionChanged(const gfx::Point& p1,
29 const gfx::Point& p2) OVERRIDE;
30
31 virtual void ClientViewLostFocus() OVERRIDE;
[email protected]4a3f5a62011-08-03 01:19:1032
33 private:
[email protected]6350b9f2011-08-08 19:03:5934 friend class TouchSelectionControllerImplTest;
[email protected]4a3f5a62011-08-03 01:19:1035 class SelectionHandleView;
[email protected]21f40122013-02-14 21:58:3536 class TouchContextMenuView;
[email protected]4a3f5a62011-08-03 01:19:1037
38 // Callback to inform the client view that the selection handle has been
39 // dragged, hence selection may need to be updated.
[email protected]cdd70c62011-08-03 18:47:2340 void SelectionHandleDragged(const gfx::Point& drag_pos);
[email protected]4a3f5a62011-08-03 01:19:1041
42 // Convenience method to convert a point from a selection handle's coordinate
43 // system to that of the client view.
44 void ConvertPointToClientView(SelectionHandleView* source, gfx::Point* point);
45
[email protected]21f40122013-02-14 21:58:3546 // Checks if the client view supports a context menu command.
47 bool IsCommandIdEnabled(int command_id) const;
[email protected]4723a442011-08-26 20:11:5348
[email protected]21f40122013-02-14 21:58:3549 // Sends a context menu command to the client view.
50 void ExecuteCommand(int command_id);
[email protected]4723a442011-08-26 20:11:5351
52 // Time to show context menu.
53 void ContextMenuTimerFired();
54
55 // Convenience method to update the position/visibility of the context menu.
56 void UpdateContextMenu(const gfx::Point& p1, const gfx::Point& p2);
57
58 // Convenience method for hiding context menu.
59 void HideContextMenu();
60
[email protected]6350b9f2011-08-08 19:03:5961 // Convenience methods for testing.
62 gfx::Point GetSelectionHandle1Position();
63 gfx::Point GetSelectionHandle2Position();
64 bool IsSelectionHandle1Visible();
65 bool IsSelectionHandle2Visible();
66
[email protected]fa246b22013-02-13 06:18:0067 ui::TouchEditable* client_view_;
[email protected]4a3f5a62011-08-03 01:19:1068 scoped_ptr<SelectionHandleView> selection_handle_1_;
69 scoped_ptr<SelectionHandleView> selection_handle_2_;
[email protected]21f40122013-02-14 21:58:3570 scoped_ptr<TouchContextMenuView> context_menu_;
[email protected]4723a442011-08-26 20:11:5371
72 // Timer to trigger |context_menu| (|context_menu| is not shown if the
73 // selection handles are being updated. It appears only when the handles are
74 // stationary for a certain amount of time).
75 base::OneShotTimer<TouchSelectionControllerImpl> context_menu_timer_;
[email protected]4a3f5a62011-08-03 01:19:1076
77 // Pointer to the SelectionHandleView being dragged during a drag session.
78 SelectionHandleView* dragging_handle_;
79
80 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImpl);
81};
82
[email protected]4a3f5a62011-08-03 01:19:1083} // namespace views
84
[email protected]79f06c7372011-11-21 18:00:3285#endif // UI_UI_VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_IMPL_H_