| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
ve.ce.TableSelection = function VeCeTableSelection() { |
| 15 |
|
| 16 |
ve.ce.TableSelection.super.apply( this, arguments ); |
| 17 |
this.directionality = null; |
| 18 |
}; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
OO.inheritClass( ve.ce.TableSelection, ve.ce.Selection ); |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
ve.ce.TableSelection.static.name = 'table'; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
ve.ce.TableSelection.prototype.getSelectionRects = function () { |
| 34 |
return [ this.getSelectionBoundingRect() ]; |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
ve.ce.TableSelection.prototype.getSelectionBoundingRect = function () { |
| 41 |
const surface = this.getSurface(), |
| 42 |
tableNode = surface.getDocument().getBranchNodeFromOffset( this.model.tableRange.start + 1 ), |
| 43 |
nodes = tableNode.getCellNodesFromSelection( this.getModel() ), |
| 44 |
surfaceRect = surface.getSurface().getBoundingClientRect(); |
| 45 |
|
| 46 |
let top = Infinity; |
| 47 |
let bottom = -Infinity; |
| 48 |
let left = Infinity; |
| 49 |
let right = -Infinity; |
| 50 |
|
| 51 |
const cellElements = []; |
| 52 |
nodes.forEach( ( node ) => { |
| 53 |
cellElements.push( ...node.$element.toArray() ); |
| 54 |
} ); |
| 55 |
|
| 56 |
|
| 57 |
cellElements.forEach( ( cellElement ) => { |
| 58 |
if ( !cellElement ) { |
| 59 |
return null; |
| 60 |
} |
| 61 |
const cellOffset = cellElement.getBoundingClientRect(); |
| 62 |
|
| 63 |
top = Math.min( top, cellOffset.top ); |
| 64 |
bottom = Math.max( bottom, cellOffset.bottom ); |
| 65 |
left = Math.min( left, cellOffset.left ); |
| 66 |
right = Math.max( right, cellOffset.right ); |
| 67 |
} ); |
| 68 |
|
| 69 |
|
| 70 |
if ( !ve.test ) { |
| 71 |
switch ( $.client.profile().layout ) { |
| 72 |
case 'webkit': |
| 73 |
right += 1; |
| 74 |
bottom += 1; |
| 75 |
break; |
| 76 |
case 'gecko': |
| 77 |
left -= 1; |
| 78 |
top -= 1; |
| 79 |
break; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
const boundingRect = { |
| 84 |
top: top, |
| 85 |
bottom: bottom, |
| 86 |
left: left, |
| 87 |
right: right, |
| 88 |
width: right - left, |
| 89 |
height: bottom - top |
| 90 |
}; |
| 91 |
|
| 92 |
if ( !boundingRect || !surfaceRect ) { |
| 93 |
return null; |
| 94 |
} |
| 95 |
return ve.translateRect( boundingRect, -surfaceRect.left, -surfaceRect.top ); |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
ve.ce.TableSelection.prototype.getTableBoundingRect = function () { |
| 104 |
const surface = this.getSurface(), |
| 105 |
tableNode = surface.getDocument().getBranchNodeFromOffset( this.model.tableRange.start + 1 ); |
| 106 |
|
| 107 |
if ( !tableNode ) { |
| 108 |
return null; |
| 109 |
} |
| 110 |
|
| 111 |
const surfaceRect = surface.getSurface().getBoundingClientRect(); |
| 112 |
const boundingRect = tableNode.$element[ 0 ].getBoundingClientRect(); |
| 113 |
|
| 114 |
if ( !boundingRect || !surfaceRect ) { |
| 115 |
return null; |
| 116 |
} |
| 117 |
return ve.translateRect( boundingRect, -surfaceRect.left, -surfaceRect.top ); |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
ve.ce.TableSelection.prototype.isFocusedNode = function () { |
| 124 |
return true; |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
ve.ce.TableSelection.prototype.isNativeCursor = function () { |
| 131 |
return false; |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
ve.ce.TableSelection.prototype.getDirectionality = function ( doc ) { |
| 138 |
if ( !this.directionality ) { |
| 139 |
this.directionality = doc.getDirectionalityFromRange( this.getModel().tableRange ); |
| 140 |
} |
| 141 |
return this.directionality; |
| 142 |
}; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
ve.ce.selectionFactory.register( ve.ce.TableSelection ); |