Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ce/ve.ce.Selection.js

raw symbols SCIP
1 /*!
2 * VisualEditor Selection class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * @class
9 * @abstract
10 * @constructor
11 * @param {ve.dm.Selection} model Selection model
12 * @param {ve.ce.Surface} surface Surface view
13 */
14 ve.ce.Selection = function VeCeSelection( model, surface ) {
15 this.model = model;
16 this.surface = surface;
17 };
18
19 /* Inheritance */
20
21 OO.initClass( ve.ce.Selection );
22
23 /* Static Properties */
24
25 ve.ce.Selection.static.type = null;
26
27 /* Static methods */
28
29 /**
30 * Create a new selection view from a selection model
31 *
32 * @param {ve.dm.Selection} model Selection model
33 * @param {ve.ce.Surface} surface Surface view
34 * @return {ve.ce.Selection} Selection view
35 */
36 ve.ce.Selection.static.newFromModel = function ( model, surface ) {
37 return ve.ce.selectionFactory.create( model.getName(), model, surface );
38 };
39
40 /* Method */
41
42 /**
43 * Get the surface view this selection exists on
44 *
45 * @return {ve.ce.Surface} Surface view
46 */
47 ve.ce.Selection.prototype.getSurface = function () {
48 return this.surface;
49 };
50
51 /**
52 * Get the selection model
53 *
54 * @return {ve.dm.Selection} Selection model
55 */
56 ve.ce.Selection.prototype.getModel = function () {
57 return this.model;
58 };
59
60 /**
61 * Get the rectangles of the selection relative to the surface.
62 *
63 * @abstract
64 * @return {Object[]|null} Selection rectangles
65 */
66 ve.ce.Selection.prototype.getSelectionRects = null;
67
68 /**
69 * Get the start and end rectangles of the selection relative to the surface.
70 *
71 * @abstract
72 * @return {Object.<string,Object>|null} Start and end selection rectangles
73 */
74 ve.ce.Selection.prototype.getSelectionStartAndEndRects = function () {
75 return ve.getStartAndEndRects( this.getSelectionRects() );
76 };
77
78 /**
79 * Get the rectangle for the selection's focus end
80 *
81 * The default gives the bounding rectangle after using collapseToTo.
82 *
83 * @return {Object|null} Selection rectangle
84 */
85 ve.ce.Selection.prototype.getSelectionFocusRect = function () {
86 const toSelection = new this.constructor( this.getModel().collapseToTo(), this.surface );
87 return toSelection.getSelectionBoundingRect();
88 };
89
90 /**
91 * Get the coordinates of the selection's bounding rectangle relative to the surface.
92 *
93 * @abstract
94 * @return {Object|null} Selection rectangle, with keys top, bottom, left, right, width, height
95 */
96 ve.ce.Selection.prototype.getSelectionBoundingRect = null;
97
98 /**
99 * Check if the selection covers a focused node
100 *
101 * @abstract
102 * @return {boolean} The selection covers a focused node
103 */
104 ve.ce.Selection.prototype.isFocusedNode = null;
105
106 /**
107 * Check if the selection is a native cursor selection
108 *
109 * @abstract
110 * @return {boolean} The selection is represented by a native cursor
111 */
112 ve.ce.Selection.prototype.isNativeCursor = null;
113
114 /**
115 * Check if two selections are equal
116 *
117 * @param {ve.ce.Selection} other Other selection
118 * @return {boolean} Selections are equal
119 */
120 ve.ce.Selection.prototype.equals = function ( other ) {
121 return this.getSurface() === other.getSurface() &&
122 this.getModel().equals( other.getModel() );
123 };
124
125 /**
126 * Get the block directionality of the selection
127 *
128 * Note: This is not the direction of the selection (e.g. ve.Range#isBackwards); it is the
129 * computed block-level CSS directionality. The actual directionality at any point within the
130 * selection depends on both this and the browser's implementation of BIDI algorithm.
131 *
132 * @abstract
133 * @param {ve.ce.Document} doc The document to which this selection applies
134 * @return {string} 'rtl', 'ltr'
135 */
136 ve.ce.Selection.prototype.getDirectionality = null;
137
138 /* Factory */
139
140 ve.ce.selectionFactory = new OO.Factory();