Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/155618
Change subject: Rename getRelativeOffset to getBoundingRect and use in
getSelectionRect
......................................................................
Rename getRelativeOffset to getBoundingRect and use in getSelectionRect
By return top/left/right/bottom we can simplify the calculations
in the one current use case.
It can also be used trivially in getSelectionRect.
Change-Id: Ia58afc145fecd5fb2bb07e2dd958eb1b7be112ea
---
M src/ce/ve.ce.FocusableNode.js
M src/ce/ve.ce.Surface.js
M src/ui/ve.ui.DesktopContext.js
3 files changed, 24 insertions(+), 34 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/18/155618/1
diff --git a/src/ce/ve.ce.FocusableNode.js b/src/ce/ve.ce.FocusableNode.js
index 4e60612..73c10ec 100644
--- a/src/ce/ve.ce.FocusableNode.js
+++ b/src/ce/ve.ce.FocusableNode.js
@@ -467,18 +467,15 @@
};
/**
- * Get the offset of the focusable node highight relative to the surface
+ * Get the bounding rectangle of the focusable node highight relative to the
surface
*
- * @return {Object} Top and left offsets of the focusable node relative to the
surface
+ * @return {Object} Top, left, bottom & right positions of the focusable node
relative to the surface
*/
-ve.ce.FocusableNode.prototype.getRelativeOffset = function () {
+ve.ce.FocusableNode.prototype.getBoundingRect = function () {
if ( !this.highlighted ) {
this.createHighlights();
}
- return {
- top: this.boundingRect.top,
- left: this.boundingRect.left
- };
+ return this.boundingRect;
};
/**
@@ -487,11 +484,9 @@
* @return {Object} Width and height of the focusable node
*/
ve.ce.FocusableNode.prototype.getDimensions = function () {
- if ( !this.highlighted ) {
- this.createHighlights();
- }
+ var boundingRect = this.getBoundingRect();
return {
- width: this.boundingRect.right - this.boundingRect.left,
- height: this.boundingRect.bottom - this.boundingRect.top
+ width: boundingRect.right - boundingRect.left,
+ height: boundingRect.bottom - boundingRect.top
};
};
diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 25e0bf1..6dbadea 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -273,18 +273,18 @@
* @returns {Object|null} { start: { x: ..., y: ... }, end: { x: ..., y: ... }
}
*/
ve.ce.Surface.prototype.getSelectionRect = function () {
- var sel, focusedOffset;
+ var sel, boundingRect;
if ( this.focusedNode ) {
- focusedOffset = this.focusedNode.$element.offset();
+ boundingRect = this.focusedNode.getBoundingRect();
return {
start: {
- x: focusedOffset.left,
- y: focusedOffset.top
+ x: boundingRect.left,
+ y: boundingRect.top
},
end: {
- x: focusedOffset.left +
this.focusedNode.$element.width(),
- y: focusedOffset.top +
this.focusedNode.$element.height()
+ x: boundingRect.right,
+ y: boundingRect.bottom
}
};
}
diff --git a/src/ui/ve.ui.DesktopContext.js b/src/ui/ve.ui.DesktopContext.js
index d9e7874..91a6cf0 100644
--- a/src/ui/ve.ui.DesktopContext.js
+++ b/src/ui/ve.ui.DesktopContext.js
@@ -206,35 +206,30 @@
* @inheritdoc
*/
ve.ui.DesktopContext.prototype.updateDimensions = function ( transition ) {
- var $container, focusedOffset, focusedDimensions, cursorPosition,
position,
+ var $container, boundingRect, cursorPosition, position, rtl,
surface = this.surface.getView(),
focusedNode = surface.getFocusedNode(),
surfaceOffset = surface.$element.offset(),
- rtl = this.surface.getModel().getDocument().getDir() === 'rtl',
embeddable = this.isEmbeddable();
$container = this.inspector ? this.inspector.$frame :
this.menu.$element;
if ( focusedNode ) {
+ rtl = this.surface.getModel().getDocument().getDir() === 'rtl';
this.popup.toggleAnchor( !embeddable );
// Get the position relative to the surface it is embedded in
- focusedOffset = focusedNode.getRelativeOffset();
- focusedDimensions = focusedNode.getDimensions();
+ boundingRect = focusedNode.getBoundingRect();
if ( embeddable ) {
- position = { y: focusedOffset.top };
- // When context is embedded in RTL, it requires
adjustments to the relative
- // positioning (pop up on the other side):
- if ( rtl ) {
- position.x = focusedOffset.left;
- this.popup.align = 'left';
- } else {
- position.x = focusedOffset.left +
focusedDimensions.width;
- this.popup.align = 'right';
- }
+ // Embedded context position depends on directionality
+ position = {
+ x: rtl ? boundingRect.left : boundingRect.right,
+ y: boundingRect.top
+ };
+ this.popup.align = rtl ? 'left' : 'right';
} else {
// Get the position of the focusedNode:
position = {
- x: focusedOffset.left + focusedDimensions.width
/ 2,
- y: focusedOffset.top + focusedDimensions.height
+ x: ( boundingRect.left + boundingRect.right ) /
2,
+ y: boundingRect.bottom
};
this.popup.align = 'center';
}
--
To view, visit https://gerrit.wikimedia.org/r/155618
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia58afc145fecd5fb2bb07e2dd958eb1b7be112ea
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits