Esanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/160495
Change subject: Rename inlineRects to startAndEndRects everywhere ...................................................................... Rename inlineRects to startAndEndRects everywhere Also rename outerRects to rects in FocusableNode Change-Id: I8d3f2bc303495bf140710874c897b2477531236b --- M src/ce/ve.ce.FocusableNode.js M src/ce/ve.ce.Surface.js M src/ui/ve.ui.DesktopContext.js M tests/ce/ve.ce.Surface.test.js 4 files changed, 65 insertions(+), 65 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/95/160495/1 diff --git a/src/ce/ve.ce.FocusableNode.js b/src/ce/ve.ce.FocusableNode.js index 8b18b0f..d4dd8b9 100644 --- a/src/ce/ve.ce.FocusableNode.js +++ b/src/ce/ve.ce.FocusableNode.js @@ -32,9 +32,9 @@ this.$highlights = this.$( '<div>' ).addClass( 've-ce-focusableNode-highlights' ); this.$focusable = $focusable || this.$element; this.surface = null; - this.outerRects = null; + this.rects = null; this.boundingRect = null; - this.inlineRects = null; + this.startAndEndRects = null; // Events this.connect( this, { @@ -394,7 +394,7 @@ * Calculate position of highlights */ ve.ce.FocusableNode.prototype.calculateHighlights = function () { - var i, l, outerRects = [], + var i, l, rects = [], surfaceOffset = this.surface.getSurface().getBoundingClientRect(); function contains( rect1, rect2 ) { @@ -421,48 +421,48 @@ continue; } contained = false; - for ( j = 0, jl = outerRects.length; j < jl; j++ ) { + for ( j = 0, jl = rects.length; j < jl; j++ ) { // This rect is contained by an existing rect, discard - if ( contains( outerRects[j], clientRects[i] ) ) { + if ( contains( rects[j], clientRects[i] ) ) { contained = true; break; } // An existing rect is contained by this rect, discard the existing rect - if ( contains( clientRects[i], outerRects[j] ) ) { - outerRects.splice( j, 1 ); + if ( contains( clientRects[i], rects[j] ) ) { + rects.splice( j, 1 ); j--; jl--; } } if ( !contained ) { - outerRects.push( clientRects[i] ); + rects.push( clientRects[i] ); } } } ); this.boundingRect = null; - // inlineRects is lazily evaluated in getInlineRects from outerRects - this.inlineRects = null; + // startAndEndRects is lazily evaluated in getStartAndEndRects from rects + this.startAndEndRects = null; - for ( i = 0, l = outerRects.length; i < l; i++ ) { + for ( i = 0, l = rects.length; i < l; i++ ) { // Translate to relative - outerRects[i] = ve.translateRect( outerRects[i], -surfaceOffset.left, -surfaceOffset.top ); + rects[i] = ve.translateRect( rects[i], -surfaceOffset.left, -surfaceOffset.top ); this.$highlights.append( this.createHighlight().css( { - top: outerRects[i].top, - left: outerRects[i].left, - width: outerRects[i].width, - height: outerRects[i].height + top: rects[i].top, + left: rects[i].left, + width: rects[i].width, + height: rects[i].height } ) ); if ( !this.boundingRect ) { - this.boundingRect = ve.copy( outerRects[i] ); + this.boundingRect = ve.copy( rects[i] ); } else { - this.boundingRect.top = Math.min( this.boundingRect.top, outerRects[i].top ); - this.boundingRect.left = Math.min( this.boundingRect.left, outerRects[i].left ); - this.boundingRect.bottom = Math.max( this.boundingRect.bottom, outerRects[i].bottom ); - this.boundingRect.right = Math.max( this.boundingRect.right, outerRects[i].right ); + this.boundingRect.top = Math.min( this.boundingRect.top, rects[i].top ); + this.boundingRect.left = Math.min( this.boundingRect.left, rects[i].left ); + this.boundingRect.bottom = Math.max( this.boundingRect.bottom, rects[i].bottom ); + this.boundingRect.right = Math.max( this.boundingRect.right, rects[i].right ); } } if ( this.boundingRect ) { @@ -470,7 +470,7 @@ this.boundingRect.height = this.boundingRect.bottom - this.boundingRect.top; } - this.outerRects = outerRects; + this.rects = rects; }; /** @@ -488,13 +488,13 @@ this.calculateHighlights(); this.$highlights.empty(); - for ( i = 0, l = this.outerRects.length; i < l; i++ ) { + for ( i = 0, l = this.rects.length; i < l; i++ ) { this.$highlights.append( this.createHighlight().css( { - top: this.outerRects[i].top, - left: this.outerRects[i].left, - width: this.outerRects[i].width, - height: this.outerRects[i].height + top: this.rects[i].top, + left: this.rects[i].left, + width: this.rects[i].width, + height: this.rects[i].height } ) ); } @@ -517,12 +517,12 @@ * * @return {Object|null} Start and end rectangles */ -ve.ce.FocusableNode.prototype.getInlineRects = function () { +ve.ce.FocusableNode.prototype.getStartAndEndRects = function () { if ( !this.highlighted ) { this.calculateHighlights(); } - if ( !this.inlineRects ) { - this.inlineRects = ve.getStartAndEndRects( this.outerRects ); + if ( !this.startAndEndRects ) { + this.startAndEndRects = ve.getStartAndEndRects( this.rects ); } - return this.inlineRects; + return this.startAndEndRects; }; diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js index 3cb1292..eb592ff 100644 --- a/src/ce/ve.ce.Surface.js +++ b/src/ce/ve.ce.Surface.js @@ -317,26 +317,26 @@ }; /** - * Get the inline coordinates of the selection range relative to the viewport. + * Get the start and end rectangles of the selection range relative to the viewport. * * Returned coordinates are client coordinates (i.e. relative to the viewport). - * For coordinates relative to the surface, use #getSelectionInlineRelativeRects + * For coordinates relative to the surface, use #getSelectionStartAndEndRelativeRects * * @method * @returns {Object|null} Start and end selection rectangles */ -ve.ce.Surface.prototype.getSelectionInlineClientRects = function () { - var inlineRects, surfaceRect, boundingRect, rtl, x, collapsedRect; +ve.ce.Surface.prototype.getSelectionStartAndEndClientRects = function () { + var startAndEndRects, surfaceRect, boundingRect, rtl, x, collapsedRect; if ( this.focusedNode ) { - inlineRects = this.focusedNode.getInlineRects(); + startAndEndRects = this.focusedNode.getStartAndEndRects(); surfaceRect = this.getSurface().getBoundingClientRect(); - if ( !inlineRects || !surfaceRect ) { + if ( !startAndEndRects || !surfaceRect ) { return null; } // Convert surface relative coords to client coords return { - start: ve.translateRect( inlineRects.start, surfaceRect.left, surfaceRect.top ), - end: ve.translateRect( inlineRects.end, surfaceRect.left, surfaceRect.top ) + start: ve.translateRect( startAndEndRects.start, surfaceRect.left, surfaceRect.top ), + end: ve.translateRect( startAndEndRects.end, surfaceRect.left, surfaceRect.top ) }; } @@ -391,7 +391,7 @@ * @returns {Object|null} Selection rectangle, with keys top, bottom, left, right, width, height */ ve.ce.Surface.prototype.getSelectionBoundingClientRect = function () { - var inlineRects, boundingRect, surfaceRect, nativeRange; + var rects, boundingRect, surfaceRect, nativeRange; if ( this.focusedNode ) { boundingRect = this.focusedNode.getBoundingRect(); @@ -410,15 +410,15 @@ try { nativeRange = this.getNativeRange(); - inlineRects = nativeRange.getClientRects(); - // Try the zeroth inline rect first as Chrome sometimes returns a rectangle + rects = nativeRange.getClientRects(); + // Try the zeroth rect first as Chrome sometimes returns a rectangle // full of zeros for getBoundingClientRect when the cursor is collapsed. - // We could test for this failure and fall back to inline[0], except for the - // fact that the bounding rect is 1px bigger than inline[0], so cursoring across + // We could test for this failure and fall back to rects[0], except for the + // fact that the bounding rect is 1px bigger than rects[0], so cursoring across // a link causes a verticle wobble as it alternately breaks and unbreaks. // See https://code.google.com/p/chromium/issues/detail?id=238976 - if ( inlineRects.length === 1 ) { - return inlineRects[0]; + if ( rects.length === 1 ) { + return rects[0]; } return nativeRange.getBoundingClientRect(); } catch ( e ) { @@ -430,27 +430,27 @@ * Get the inline coordinates of the selection range relative to the surface. * * Returned coordinates are relative to the surface. For client coordinates, - * use #getSelectionInlineClientRects. + * use #getSelectionStartAndEndClientRects. * * @method * @returns {Object|null} Start and end selection rectangles */ -ve.ce.Surface.prototype.getSelectionInlineRelativeRects = function () { - var inlineRects, surfaceRect; +ve.ce.Surface.prototype.getSelectionStartAndEndRelativeRects = function () { + var startAndEndRects, surfaceRect; if ( this.focusedNode ) { // We can optimize the focusedNode case as we already have the relative coordinates - return this.focusedNode.getInlineRects(); + return this.focusedNode.getStartAndEndRects(); } - inlineRects = this.getSelectionInlineClientRects(); + startAndEndRects = this.getSelectionStartAndEndClientRects(); surfaceRect = this.getSurface().getBoundingClientRect(); - if ( !inlineRects || !surfaceRect ) { + if ( !startAndEndRects || !surfaceRect ) { return null; } return { - start: ve.translateRect( inlineRects.start, -surfaceRect.left, -surfaceRect.top ), - end: ve.translateRect( inlineRects.end, -surfaceRect.left, -surfaceRect.top ) + start: ve.translateRect( startAndEndRects.start, -surfaceRect.left, -surfaceRect.top ), + end: ve.translateRect( startAndEndRects.end, -surfaceRect.left, -surfaceRect.top ) }; }; diff --git a/src/ui/ve.ui.DesktopContext.js b/src/ui/ve.ui.DesktopContext.js index 06ec337..76fa78a 100644 --- a/src/ui/ve.ui.DesktopContext.js +++ b/src/ui/ve.ui.DesktopContext.js @@ -178,7 +178,7 @@ * @inheritdoc */ ve.ui.DesktopContext.prototype.updateDimensions = function () { - var $container, inlineRects, position, embeddable, middle, + var $container, startAndEndRects, position, embeddable, middle, rtl = this.surface.getModel().getDocument().getDir() === 'rtl', surface = this.surface.getView(), focusedNode = surface.getFocusedNode(), @@ -209,12 +209,12 @@ } } else { // The selection is text or an inline focused node - inlineRects = surface.getSelectionInlineRelativeRects(); - if ( inlineRects && boundingRect ) { + startAndEndRects = surface.getSelectionStartAndEndRelativeRects(); + if ( startAndEndRects && boundingRect ) { middle = ( boundingRect.left + boundingRect.right ) / 2; if ( - ( !rtl && inlineRects.end.right > middle ) || - ( rtl && inlineRects.end.left < middle ) + ( !rtl && startAndEndRects.end.right > middle ) || + ( rtl && startAndEndRects.end.left < middle ) ) { // If the middle position is within the end rect, use it position = { @@ -224,13 +224,13 @@ } else { // ..otherwise use the side of the end rect position = { - x: rtl ? inlineRects.end.left : inlineRects.end.right, - y: inlineRects.end.bottom + x: rtl ? startAndEndRects.end.left : startAndEndRects.end.right, + y: startAndEndRects.end.bottom }; } } - // If !inlineRects, the surface apparently isn't selected, so getSelectionBoundingRelativeRect() - // returned null. This shouldn't happen because the context is only supposed to be + // If !startAndEndRects, the surface apparently isn't selected. + // This shouldn't happen because the context is only supposed to be // displayed in response to a selection, but for some reason this does happen when opening // an inspector without changing the selection. // Skip updating the cursor position, but still update the width and height. diff --git a/tests/ce/ve.ce.Surface.test.js b/tests/ce/ve.ce.Surface.test.js index 4cd7aa7..e467d3a 100644 --- a/tests/ce/ve.ce.Surface.test.js +++ b/tests/ce/ve.ce.Surface.test.js @@ -1090,8 +1090,8 @@ // TODO: ve.ce.Surface#isRenderingLocked // TODO: ve.ce.Surface#getSelectionBoundingClientRect // TODO: ve.ce.Surface#getSelectionBoundingRelativeRect -// TODO: ve.ce.Surface#getSelectionInlineClientRects -// TODO: ve.ce.Surface#getSelectionInlineRelativeRects +// TODO: ve.ce.Surface#getSelectionStartAndEndClientRects +// TODO: ve.ce.Surface#getSelectionStartAndEndRelativeRects /* Methods without return values */ // TODO: ve.ce.Surface#initialize -- To view, visit https://gerrit.wikimedia.org/r/160495 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8d3f2bc303495bf140710874c897b2477531236b Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits