| 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 |
ve.ce.FocusableNode = function VeCeFocusableNode( $focusable, config ) { |
| 31 |
config = config || {}; |
| 32 |
|
| 33 |
|
| 34 |
this.focused = false; |
| 35 |
this.highlighted = false; |
| 36 |
this.isFocusableSetup = false; |
| 37 |
this.$highlights = $( '<div>' ).addClass( 've-ce-focusableNode-highlights' ) |
| 38 |
|
| 39 |
|
| 40 |
.attr( 'tabIndex', 0 ); |
| 41 |
this.$focusable = $focusable || this.$element; |
| 42 |
this.$bounding = config.$bounding || this.$focusable; |
| 43 |
this.focusableSurface = null; |
| 44 |
this.rects = null; |
| 45 |
this.boundingRect = null; |
| 46 |
this.startAndEndRects = null; |
| 47 |
this.icon = null; |
| 48 |
this.touchMoved = false; |
| 49 |
|
| 50 |
if ( Array.isArray( config.classes ) ) { |
| 51 |
|
| 52 |
this.$highlights.addClass( config.classes ); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
this.redrawHighlightsDebounced = ve.debounce( this.redrawHighlights.bind( this ), 100 ); |
| 58 |
|
| 59 |
|
| 60 |
this.$element |
| 61 |
.addClass( 've-ce-focusableNode' ) |
| 62 |
.prop( 'contentEditable', 'false' ); |
| 63 |
|
| 64 |
|
| 65 |
this.connect( this, { |
| 66 |
setup: 'onFocusableSetup', |
| 67 |
teardown: 'onFocusableTeardown', |
| 68 |
resizeStart: 'onFocusableResizeStart', |
| 69 |
resizeEnd: 'onFocusableResizeEnd', |
| 70 |
rerender: 'onFocusableRerender' |
| 71 |
} ); |
| 72 |
}; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
OO.initClass( ve.ce.FocusableNode ); |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
ve.ce.FocusableNode.static.iconWhenInvisible = null; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
ve.ce.FocusableNode.static.primaryCommandName = null; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
ve.ce.FocusableNode.static.deleteCommandName = null; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
ve.ce.FocusableNode.static.getRectsForElement = function ( $element, relativeRect ) { |
| 129 |
let $set; |
| 130 |
let rects = []; |
| 131 |
|
| 132 |
function process( el ) { |
| 133 |
if ( el.classList.contains( 've-ce-noHighlight' ) ) { |
| 134 |
return; |
| 135 |
} |
| 136 |
|
| 137 |
const $el = $( el ); |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
const overflow = $el.css( 'overflow' ); |
| 143 |
if ( overflow && overflow !== 'visible' && $el.css( 'display' ) !== 'inline' ) { |
| 144 |
$set = $set.not( $el.find( '*' ) ); |
| 145 |
} |
| 146 |
|
| 147 |
ve.batchPush( rects, el.getClientRects() ); |
| 148 |
} |
| 149 |
|
| 150 |
$set = $element.find( '*' ).addBack(); |
| 151 |
|
| 152 |
for ( let i = 0; i < $set.length; i++ ) { |
| 153 |
process( $set[ i ] ); |
| 154 |
} |
| 155 |
|
| 156 |
rects = ve.minimizeRects( rects ); |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
const filteredRects = rects.filter( ( rect ) => rect.width > 1 && rect.height > 1 ); |
| 162 |
|
| 163 |
if ( filteredRects.length > 0 ) { |
| 164 |
rects = filteredRects; |
| 165 |
} |
| 166 |
|
| 167 |
let boundingRect = null; |
| 168 |
|
| 169 |
for ( let i = 0, l = rects.length; i < l; i++ ) { |
| 170 |
|
| 171 |
if ( relativeRect ) { |
| 172 |
rects[ i ] = ve.translateRect( rects[ i ], -relativeRect.left, -relativeRect.top ); |
| 173 |
} |
| 174 |
if ( !boundingRect ) { |
| 175 |
boundingRect = ve.copy( rects[ i ] ); |
| 176 |
} else { |
| 177 |
boundingRect.top = Math.min( boundingRect.top, rects[ i ].top ); |
| 178 |
boundingRect.left = Math.min( boundingRect.left, rects[ i ].left ); |
| 179 |
boundingRect.bottom = Math.max( boundingRect.bottom, rects[ i ].bottom ); |
| 180 |
boundingRect.right = Math.max( boundingRect.right, rects[ i ].right ); |
| 181 |
} |
| 182 |
} |
| 183 |
if ( boundingRect ) { |
| 184 |
boundingRect.width = boundingRect.right - boundingRect.left; |
| 185 |
boundingRect.height = boundingRect.bottom - boundingRect.top; |
| 186 |
} |
| 187 |
|
| 188 |
return { |
| 189 |
rects: rects, |
| 190 |
boundingRect: boundingRect |
| 191 |
}; |
| 192 |
}; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
ve.ce.FocusableNode.prototype.createHighlight = function () { |
| 202 |
|
| 203 |
return $( '<div>' ) |
| 204 |
.addClass( [ 've-ce-focusableNode-highlight', ...this.getExtraHighlightClasses() ] ) |
| 205 |
.prop( { |
| 206 |
title: this.constructor.static.getDescription( this.model ), |
| 207 |
draggable: true |
| 208 |
} ) |
| 209 |
.on( { |
| 210 |
dragstart: this.onFocusableDragStart.bind( this ), |
| 211 |
dragend: this.onFocusableDragEnd.bind( this ) |
| 212 |
} ); |
| 213 |
}; |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
ve.ce.FocusableNode.prototype.getExtraHighlightClasses = function () { |
| 221 |
return this.generatedContentsInvalid ? [ 've-ce-focusableNode-highlight-error' ] : []; |
| 222 |
}; |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
ve.ce.FocusableNode.prototype.onFocusableSetup = function () { |
| 228 |
|
| 229 |
if ( this.isFocusableSetup || !this.root ) { |
| 230 |
return; |
| 231 |
} |
| 232 |
|
| 233 |
this.focusableSurface = this.root.getSurface(); |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
if ( !this.$element.hasClass( 've-ce-focusableNode' ) ) { |
| 238 |
|
| 239 |
|
| 240 |
this.$element |
| 241 |
.addClass( 've-ce-focusableNode' ) |
| 242 |
.prop( 'contentEditable', 'false' ); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
this.$focusable.on( { |
| 247 |
'mouseenter.ve-ce-focusableNode': this.onFocusableMouseEnter.bind( this ), |
| 248 |
'touchstart.ve-ce-focusableNode': this.onFocusableTouchStart.bind( this ), |
| 249 |
'touchmove.ve-ce-focusableNode': this.onFocusableTouchMove.bind( this ), |
| 250 |
'mousedown.ve-ce-focusableNode touchend.ve-ce-focusableNode': this.onFocusableMouseDown.bind( this ) |
| 251 |
} ); |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
if ( !this.$element.is( this.$focusable ) ) { |
| 257 |
this.$element.on( { |
| 258 |
'mousedown.ve-ce-focusableNode': function ( e ) { |
| 259 |
if ( !ve.isContentEditable( e.target ) ) { |
| 260 |
e.preventDefault(); |
| 261 |
} |
| 262 |
} |
| 263 |
} ); |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
this.$element.on( { |
| 268 |
'click.ve-ce-focusableNode': function ( e ) { |
| 269 |
if ( !ve.isContentEditable( e.target ) && e.which === OO.ui.MouseButtons.LEFT ) { |
| 270 |
e.preventDefault(); |
| 271 |
} |
| 272 |
} |
| 273 |
} ); |
| 274 |
|
| 275 |
if ( this.constructor.static.iconWhenInvisible ) { |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
this.$element |
| 280 |
.find( 'img:not([width]),img:not([height])' ) |
| 281 |
.addBack( 'img:not([width]),img:not([height])' ) |
| 282 |
.on( 'load', this.updateInvisibleIcon.bind( this ) ); |
| 283 |
this.updateInvisibleIcon(); |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
this.redrawHighlightsDebounced(); |
| 289 |
|
| 290 |
this.isFocusableSetup = true; |
| 291 |
}; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
ve.ce.FocusableNode.prototype.updateInvisibleIcon = function () { |
| 301 |
if ( !this.constructor.static.iconWhenInvisible ) { |
| 302 |
return; |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
if ( this.icon ) { |
| 307 |
this.icon.$element.detach(); |
| 308 |
} |
| 309 |
const showIcon = !this.hasRendering(); |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
requestAnimationFrame( () => { |
| 314 |
this.updateInvisibleIconSync( showIcon ); |
| 315 |
} ); |
| 316 |
}; |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
ve.ce.FocusableNode.prototype.updateInvisibleIconSync = function ( showIcon ) { |
| 325 |
if ( !this.getModel() ) { |
| 326 |
|
| 327 |
return; |
| 328 |
} |
| 329 |
if ( showIcon ) { |
| 330 |
|
| 331 |
const voidAndHiddenTypes = [ 'style', 'script', ...ve.elementTypes.void ]; |
| 332 |
const $firstElement = this.$element.not( voidAndHiddenTypes.join( ',' ) ).first(); |
| 333 |
this.createInvisibleIcon(); |
| 334 |
if ( |
| 335 |
|
| 336 |
document.body.contains( $firstElement[ 0 ] ) && |
| 337 |
|
| 338 |
!$firstElement.is( ':visible' ) |
| 339 |
) { |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
$firstElement.empty().css( 'display', 'inline-block' ); |
| 344 |
} |
| 345 |
$firstElement |
| 346 |
.addClass( 've-ce-focusableNode-invisible' ) |
| 347 |
.prepend( this.icon.$element ); |
| 348 |
} else if ( this.icon ) { |
| 349 |
this.$element.removeClass( 've-ce-focusableNode-invisible' ); |
| 350 |
this.icon.$element.detach(); |
| 351 |
} |
| 352 |
}; |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
ve.ce.FocusableNode.prototype.createInvisibleIcon = function () { |
| 358 |
if ( this.icon ) { |
| 359 |
return; |
| 360 |
} |
| 361 |
this.icon = new OO.ui.ButtonWidget( { |
| 362 |
classes: [ 've-ce-focusableNode-invisibleIcon' ], |
| 363 |
framed: false, |
| 364 |
|
| 365 |
tabIndex: null, |
| 366 |
icon: this.constructor.static.iconWhenInvisible |
| 367 |
} ); |
| 368 |
this.updateInvisibleIconLabel(); |
| 369 |
}; |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
ve.ce.FocusableNode.prototype.getInvisibleIconLabel = function () { |
| 379 |
return this.model ? this.constructor.static.getDescription( this.model ) : ''; |
| 380 |
}; |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
ve.ce.FocusableNode.prototype.updateInvisibleIconLabel = function () { |
| 386 |
if ( this.icon ) { |
| 387 |
this.icon.setLabel( this.getInvisibleIconLabel() || null ); |
| 388 |
} |
| 389 |
}; |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
ve.ce.FocusableNode.prototype.onFocusableTeardown = function () { |
| 395 |
|
| 396 |
if ( !this.isFocusableSetup || !this.root ) { |
| 397 |
return; |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
this.$focusable.off( '.ve-ce-focusableNode' ); |
| 402 |
this.$element.off( '.ve-ce-focusableNode' ); |
| 403 |
|
| 404 |
|
| 405 |
this.clearHighlights(); |
| 406 |
|
| 407 |
|
| 408 |
this.$element |
| 409 |
.removeClass( 've-ce-focusableNode' ) |
| 410 |
.removeProp( 'contentEditable' ); |
| 411 |
|
| 412 |
this.focusableSurface = null; |
| 413 |
this.isFocusableSetup = false; |
| 414 |
}; |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
ve.ce.FocusableNode.prototype.onFocusableMouseDown = function ( e ) { |
| 422 |
if ( e.type === 'touchend' && this.touchMoved ) { |
| 423 |
return; |
| 424 |
} |
| 425 |
|
| 426 |
if ( this.isInContentEditableDisabled() ) { |
| 427 |
return; |
| 428 |
} |
| 429 |
|
| 430 |
const surfaceModel = this.focusableSurface.getModel(), |
| 431 |
selection = surfaceModel.getSelection(), |
| 432 |
nodeRange = this.model.getOuterRange(); |
| 433 |
|
| 434 |
if ( e.which === OO.ui.MouseButtons.RIGHT ) { |
| 435 |
|
| 436 |
|
| 437 |
this.$highlights.prop( 'contentEditable', 'true' ); |
| 438 |
|
| 439 |
ve.selectElement( this.$highlights[ 0 ] ); |
| 440 |
setTimeout( () => { |
| 441 |
|
| 442 |
this.$highlights.prop( 'contentEditable', 'false' ); |
| 443 |
this.focusableSurface.preparePasteTargetForCopy(); |
| 444 |
} ); |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
setTimeout( () => { |
| 449 |
|
| 450 |
if ( this.focusableSurface ) { |
| 451 |
const range = selection instanceof ve.dm.LinearSelection && selection.getRange(); |
| 452 |
surfaceModel.getLinearFragment( |
| 453 |
e.shiftKey && range ? |
| 454 |
ve.Range.static.newCoveringRange( |
| 455 |
[ range, nodeRange ], range.from > nodeRange.from |
| 456 |
) : |
| 457 |
nodeRange |
| 458 |
).select(); |
| 459 |
this.focusableSurface.updateActiveAnnotations(); |
| 460 |
|
| 461 |
this.focusableSurface.activate(); |
| 462 |
} |
| 463 |
} ); |
| 464 |
}; |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
ve.ce.FocusableNode.prototype.onFocusableDblClick = function () { |
| 472 |
if ( this.isInContentEditableDisabled() ) { |
| 473 |
return; |
| 474 |
} |
| 475 |
if ( this.getModel().isEditable() ) { |
| 476 |
this.executeCommand(); |
| 477 |
} |
| 478 |
}; |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
ve.ce.FocusableNode.prototype.executeCommand = function () { |
| 484 |
if ( !this.model.isInspectable() ) { |
| 485 |
return; |
| 486 |
} |
| 487 |
const surface = this.focusableSurface.getSurface(); |
| 488 |
const command = surface.commandRegistry.getCommandForNode( this ); |
| 489 |
if ( command ) { |
| 490 |
command.execute( surface ); |
| 491 |
} |
| 492 |
}; |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
ve.ce.FocusableNode.prototype.onFocusableDragStart = function ( e ) { |
| 500 |
if ( this.focusableSurface ) { |
| 501 |
|
| 502 |
this.focusableSurface.onDocumentDragStart( e ); |
| 503 |
} |
| 504 |
}; |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
ve.ce.FocusableNode.prototype.onFocusableDragEnd = function () { |
| 514 |
|
| 515 |
|
| 516 |
if ( this.focusableSurface ) { |
| 517 |
this.focusableSurface.endRelocation(); |
| 518 |
} |
| 519 |
}; |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
ve.ce.FocusableNode.prototype.onFocusableMouseEnter = function () { |
| 527 |
if ( !this.root.getSurface().dragging && !this.root.getSurface().resizing && !this.isInContentEditableDisabled() ) { |
| 528 |
this.createHighlights(); |
| 529 |
} |
| 530 |
}; |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
ve.ce.FocusableNode.prototype.onFocusableTouchStart = function () { |
| 538 |
this.touchMoved = false; |
| 539 |
}; |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
ve.ce.FocusableNode.prototype.onFocusableTouchMove = function () { |
| 547 |
this.touchMoved = true; |
| 548 |
}; |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
ve.ce.FocusableNode.prototype.onSurfaceMouseMove = function ( e ) { |
| 556 |
const $target = $( e.target ); |
| 557 |
if ( |
| 558 |
|
| 559 |
!$target.hasClass( 've-ce-focusableNode-highlight' ) && |
| 560 |
!OO.ui.contains( this.$focusable.toArray(), $target[ 0 ], true ) |
| 561 |
) { |
| 562 |
this.clearHighlights(); |
| 563 |
} |
| 564 |
}; |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
ve.ce.FocusableNode.prototype.onSurfaceMouseLeave = function ( e ) { |
| 572 |
if ( e.relatedTarget === null ) { |
| 573 |
this.clearHighlights(); |
| 574 |
} |
| 575 |
}; |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
ve.ce.FocusableNode.prototype.onFocusableResizeStart = function () { |
| 581 |
this.clearHighlights(); |
| 582 |
}; |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
ve.ce.FocusableNode.prototype.onFocusableResizeEnd = function () { |
| 588 |
this.redrawHighlightsDebounced(); |
| 589 |
}; |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
ve.ce.FocusableNode.prototype.onFocusableRerender = function () { |
| 595 |
if ( this.focused && this.focusableSurface ) { |
| 596 |
this.redrawHighlightsDebounced(); |
| 597 |
|
| 598 |
this.focusableSurface.getSurface().getContext().updateDimensions( true ); |
| 599 |
} |
| 600 |
}; |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
ve.ce.FocusableNode.prototype.isFocused = function () { |
| 608 |
return this.focused; |
| 609 |
}; |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
ve.ce.FocusableNode.prototype.setFocused = function ( value ) { |
| 619 |
value = !!value; |
| 620 |
if ( this.focused !== value ) { |
| 621 |
this.focused = value; |
| 622 |
if ( this.focused ) { |
| 623 |
this.emit( 'focus' ); |
| 624 |
this.$element.addClass( 've-ce-focusableNode-focused' ); |
| 625 |
this.createHighlights(); |
| 626 |
|
| 627 |
this.focusableSurface.appendHighlights( this.$highlights, this.focused ); |
| 628 |
this.focusableSurface.$element.off( '.ve-ce-focusableNode' ); |
| 629 |
} else { |
| 630 |
this.emit( 'blur' ); |
| 631 |
this.$element.removeClass( 've-ce-focusableNode-focused' ); |
| 632 |
this.$highlights.removeClass( 've-ce-focusableNode-highlights-deactivated' ); |
| 633 |
this.clearHighlights(); |
| 634 |
} |
| 635 |
} |
| 636 |
}; |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
ve.ce.FocusableNode.prototype.createHighlights = function () { |
| 642 |
if ( this.highlighted ) { |
| 643 |
return; |
| 644 |
} |
| 645 |
|
| 646 |
this.$highlights.on( { |
| 647 |
mousedown: this.onFocusableMouseDown.bind( this ), |
| 648 |
dblclick: this.onFocusableDblClick.bind( this ) |
| 649 |
} ); |
| 650 |
|
| 651 |
this.highlighted = true; |
| 652 |
|
| 653 |
this.positionHighlights(); |
| 654 |
|
| 655 |
this.focusableSurface.appendHighlights( this.$highlights, this.focused ); |
| 656 |
this.focusableSurface.connect( this, { |
| 657 |
position: 'positionHighlights', |
| 658 |
activation: 'onSurfaceActivation' |
| 659 |
} ); |
| 660 |
|
| 661 |
|
| 662 |
if ( !this.focused ) { |
| 663 |
this.focusableSurface.$element.on( { |
| 664 |
'mousemove.ve-ce-focusableNode': this.onSurfaceMouseMove.bind( this ), |
| 665 |
'mouseleave.ve-ce-focusableNode': this.onSurfaceMouseLeave.bind( this ) |
| 666 |
} ); |
| 667 |
} |
| 668 |
}; |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
ve.ce.FocusableNode.prototype.onSurfaceActivation = function () { |
| 674 |
this.$highlights.toggleClass( 've-ce-focusableNode-highlights-deactivated', !!this.focusableSurface.isShownAsDeactivated() ); |
| 675 |
}; |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
ve.ce.FocusableNode.prototype.clearHighlights = function () { |
| 681 |
if ( !this.highlighted ) { |
| 682 |
return; |
| 683 |
} |
| 684 |
this.$highlights.remove().empty(); |
| 685 |
this.focusableSurface.$element.off( '.ve-ce-focusableNode' ); |
| 686 |
this.focusableSurface.disconnect( this ); |
| 687 |
this.highlighted = false; |
| 688 |
this.boundingRect = null; |
| 689 |
}; |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
ve.ce.FocusableNode.prototype.redrawHighlights = function () { |
| 695 |
if ( this.focused && this.focusableSurface ) { |
| 696 |
|
| 697 |
|
| 698 |
this.setFocused( false ); |
| 699 |
this.setFocused( true ); |
| 700 |
} |
| 701 |
}; |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
ve.ce.FocusableNode.prototype.calculateHighlights = function () { |
| 707 |
|
| 708 |
if ( !this.focusableSurface ) { |
| 709 |
this.rects = []; |
| 710 |
this.boundingRect = null; |
| 711 |
this.startAndEndRects = null; |
| 712 |
return; |
| 713 |
} |
| 714 |
|
| 715 |
const surfaceOffset = this.focusableSurface.getSurface().getBoundingClientRect(); |
| 716 |
|
| 717 |
const allRects = this.constructor.static.getRectsForElement( this.$focusable, surfaceOffset ); |
| 718 |
|
| 719 |
this.rects = allRects.rects; |
| 720 |
this.boundingRect = allRects.boundingRect; |
| 721 |
|
| 722 |
this.startAndEndRects = null; |
| 723 |
}; |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
ve.ce.FocusableNode.prototype.positionHighlights = function () { |
| 729 |
if ( !this.highlighted ) { |
| 730 |
return; |
| 731 |
} |
| 732 |
|
| 733 |
this.calculateHighlights(); |
| 734 |
this.$highlights.empty() |
| 735 |
|
| 736 |
.append( $( '<span>' ).addClass( 've-ce-focusableNode-highlight-selectable' ).text( '\u00a0' ) ); |
| 737 |
|
| 738 |
for ( let i = 0, l = this.rects.length; i < l; i++ ) { |
| 739 |
const $highlight = this.createHighlight(); |
| 740 |
this.$highlights.append( |
| 741 |
$highlight.css( { |
| 742 |
top: this.rects[ i ].top, |
| 743 |
left: this.rects[ i ].left, |
| 744 |
width: this.rects[ i ].width, |
| 745 |
height: this.rects[ i ].height |
| 746 |
} ) |
| 747 |
); |
| 748 |
} |
| 749 |
}; |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
ve.ce.FocusableNode.prototype.getRects = function () { |
| 757 |
if ( !this.highlighted ) { |
| 758 |
this.calculateHighlights(); |
| 759 |
} |
| 760 |
return this.rects; |
| 761 |
}; |
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
ve.ce.FocusableNode.prototype.getBoundingRect = function () { |
| 769 |
if ( !this.$bounding.is( this.$focusable ) ) { |
| 770 |
const surfaceOffset = this.focusableSurface.getSurface().getBoundingClientRect(); |
| 771 |
const allRects = this.constructor.static.getRectsForElement( this.$bounding, surfaceOffset ); |
| 772 |
return allRects.boundingRect; |
| 773 |
} |
| 774 |
if ( !this.highlighted ) { |
| 775 |
this.calculateHighlights(); |
| 776 |
} |
| 777 |
return this.boundingRect; |
| 778 |
}; |
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
ve.ce.FocusableNode.prototype.getStartAndEndRects = function () { |
| 786 |
if ( !this.highlighted ) { |
| 787 |
this.calculateHighlights(); |
| 788 |
} |
| 789 |
if ( !this.startAndEndRects ) { |
| 790 |
this.startAndEndRects = ve.getStartAndEndRects( this.rects ); |
| 791 |
} |
| 792 |
return this.startAndEndRects; |
| 793 |
}; |
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
x |
| 799 |
) |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
ve.ce.FocusableNode.prototype.hasRendering = function () { |
| 804 |
let visible = false; |
| 805 |
|
| 806 |
function checkSize( width, height ) { |
| 807 |
return ( width >= 10 && height >= 4 ) || |
| 808 |
( height >= 10 && width >= 4 ); |
| 809 |
} |
| 810 |
|
| 811 |
this.$element.each( ( i, element ) => { |
| 812 |
if ( |
| 813 |
checkSize( element.offsetWidth, element.offsetHeight ) || |
| 814 |
|
| 815 |
checkSize( element.width, element.height ) |
| 816 |
) { |
| 817 |
visible = true; |
| 818 |
return false; |
| 819 |
} |
| 820 |
} ); |
| 821 |
return visible; |
| 822 |
}; |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
ve.ce.FocusableNode.prototype.isInContentEditableDisabled = function () { |
| 833 |
return !!this.traverseUpstream( ( node ) => !( |
| 834 |
node.isContentEditable && !node.isContentEditable() |
| 835 |
) ); |
| 836 |
}; |