File: touch_editing_controller.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (116 lines) | stat: -rw-r--r-- 4,625 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_TOUCH_SELECTION_TOUCH_EDITING_CONTROLLER_H_
#define UI_TOUCH_SELECTION_TOUCH_EDITING_CONTROLLER_H_

#include "base/component_export.h"
#include "ui/menus/simple_menu_model.h"

namespace gfx {
class Point;
class Rect;
class SelectionBound;
}  // namespace gfx

namespace ui {

// An interface implemented by widget that has text that can be selected/edited
// using touch.
class COMPONENT_EXPORT(UI_BASE) TouchEditable
    : public ui::SimpleMenuModel::Delegate {
 public:
  // Commands that all TouchEditables support:
  // TODO(b/263419885): Rewrite MenuCommands as an enum class.
  enum MenuCommands {
    // Don't use command ID 0 - a lot of tests use 0 for "no command".
    kCut = 1,
    kCopy,
    kPaste,
    kSelectAll,
    kSelectWord,
    kLastTouchEditableCommandId = kSelectWord,
  };

  // TODO(b/266345972): Consider switching from local coordinates to screen
  // coordinates in this interface and see if it will simplify things.

  // Moves the caret to |position|. |position| is in local coordinates.
  virtual void MoveCaret(const gfx::Point& position) = 0;

  // Moves the logical end of the selection according to |extent| while keeping
  // the logical start of the selection fixed. Here, |extent| corresponds to the
  // position (in local coordinates) of the touch handle being dragged to update
  // the selection range.
  //
  // Note that the resultant end of the selection depends on the behaviour of
  // the TouchEditable, e.g. for "expand by word, shrink by character", the
  // selection end can move to the character or word boundary nearest to
  // |extent| depending on the previous extent position:
  // ____________________________________
  // | textf|ield wit|h selected text   |
  // ------------------------------------
  //                 ^extent
  //        ^start   ^end
  //
  // ____________________________________
  // | textf|ield with selec|ted| text   |
  // ------------------------------------
  //                        ^extent
  //        ^start              ^end
  //
  virtual void MoveRangeSelectionExtent(const gfx::Point& extent) = 0;

  // Sets the logical start and end of the selection according to |base| and
  // |extent|. |base| corresponds to the position of the fixed touch handle and
  // determines the logical start of the selection. |extent| corresponds to the
  // position of the currently dragging handle and determines the logical end of
  // the selection, which may be visually before, on, or after the logical start
  // of the selection. Both |base| and |start| are in local coordinates.
  virtual void SelectBetweenCoordinates(const gfx::Point& base,
                                        const gfx::Point& extent) = 0;

  // Gets the end points of the current selection. The end points |anchor| and
  // |focus| must be the cursor rect for the logical start and logical end of
  // selection (in local coordinates):
  // ____________________________________
  // | textfield with |selected text|   |
  // ------------------------------------
  //                  ^anchor       ^focus
  //
  // Visually, anchor could be to the right of focus in the figure above - it
  // depends on the selection direction.
  virtual void GetSelectionEndPoints(gfx::SelectionBound* anchor,
                                     gfx::SelectionBound* focus) = 0;

  // Gets the bounds of the client view in its local coordinates.
  virtual gfx::Rect GetBounds() = 0;

  // Gets the NativeView hosting the client.
  virtual gfx::NativeView GetNativeView() const = 0;

  // Checks whether the client is currently in a selection dragging state, i.e.
  // whether it is currently handling scroll gestures to adjust the cursor or
  // selection. If so, selection changes will notify the controller to update
  // the quick menu and touch selection magnifier without showing touch handles.
  virtual bool IsSelectionDragging() const = 0;

  // Converts a point to/from screen coordinates from/to client view.
  virtual void ConvertPointToScreen(gfx::Point* point) = 0;
  virtual void ConvertPointFromScreen(gfx::Point* point) = 0;

  // Tells the editable to open context menu.
  virtual void OpenContextMenu(const gfx::Point& anchor) = 0;

  // Tells the editable to end touch editing and destroy touch selection
  // controller it owns.
  virtual void DestroyTouchSelection() = 0;

 protected:
  ~TouchEditable() override {}
};

}  // namespace ui

#endif  // UI_TOUCH_SELECTION_TOUCH_EDITING_CONTROLLER_H_