1 // Copyright (c) 2013 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.
5 #ifndef UI_BASE_TOUCH_TOUCH_EDITING_CONTROLLER_H_
6 #define UI_BASE_TOUCH_TOUCH_EDITING_CONTROLLER_H_
8 #include "ui/base/models/simple_menu_model.h"
9 #include "ui/gfx/point.h"
10 #include "ui/gfx/rect.h"
14 // An interface implemented by widget that has text that can be selected/edited
16 class UI_BASE_EXPORT TouchEditable
: public ui::SimpleMenuModel::Delegate
{
18 // TODO(mohsen): Consider switching from local coordinates to screen
19 // coordinates in this interface and see if it will simplify things.
21 // Select everything between start and end (points are in view's local
22 // coordinate system). |start| is the logical start and |end| is the logical
23 // end of selection. Visually, |start| may lie after |end|.
24 virtual void SelectRect(const gfx::Point
& start
, const gfx::Point
& end
) = 0;
26 // Move the caret to |point|. |point| is in local coordinates.
27 virtual void MoveCaretTo(const gfx::Point
& point
) = 0;
29 // Gets the end points of the current selection. The end points p1 and p2 must
30 // be the cursor rect for the start and end of selection (in local
32 // ____________________________________
33 // | textfield with |selected text| |
34 // ------------------------------------
37 // p1 should be the logical start and p2 the logical end of selection. Hence,
38 // visually, p1 could be to the right of p2 in the figure above.
39 virtual void GetSelectionEndPoints(gfx::Rect
* p1
, gfx::Rect
* p2
) = 0;
41 // Gets the bounds of the client view in its local coordinates.
42 virtual gfx::Rect
GetBounds() = 0;
44 // Gets the NativeView hosting the client.
45 virtual gfx::NativeView
GetNativeView() const = 0;
47 // Converts a point to/from screen coordinates from/to client view.
48 virtual void ConvertPointToScreen(gfx::Point
* point
) = 0;
49 virtual void ConvertPointFromScreen(gfx::Point
* point
) = 0;
51 // Returns true if the editable draws its own handles (hence, the
52 // TouchSelectionController need not draw handles).
53 virtual bool DrawsHandles() = 0;
55 // Tells the editable to open context menu.
56 virtual void OpenContextMenu(const gfx::Point
& anchor
) = 0;
58 // Tells the editable to end touch editing and destroy touch selection
59 // controller it owns.
60 virtual void DestroyTouchSelection() = 0;
63 virtual ~TouchEditable() {}
66 // This defines the callback interface for other code to be notified of changes
67 // in the state of a TouchEditable.
68 class UI_BASE_EXPORT TouchSelectionController
{
70 virtual ~TouchSelectionController() {}
72 // Creates a TouchSelectionController. Caller owns the returned object.
73 static TouchSelectionController
* create(
74 TouchEditable
* client_view
);
76 // Notifies the controller that the selection has changed.
77 virtual void SelectionChanged() = 0;
79 // Returns true if the user is currently dragging one of the handles.
80 virtual bool IsHandleDragInProgress() = 0;
82 // Hides visible handles. According to the value of |quick|, handles might
83 // fade out quickly or slowly.
84 virtual void HideHandles(bool quick
) = 0;
87 class UI_BASE_EXPORT TouchSelectionControllerFactory
{
89 static void SetInstance(TouchSelectionControllerFactory
* instance
);
91 virtual TouchSelectionController
* create(TouchEditable
* client_view
) = 0;
94 virtual ~TouchSelectionControllerFactory() {}
99 #endif // UI_BASE_TOUCH_TOUCH_EDITING_CONTROLLER_H_