Use simpleRectangle for docLayer._graphicSelection.

Signed-off-by: Gökay Şatır <gokaysatir@collabora.com>
Change-Id: Ibc84782abf8e7668d31360e106fc73522fcd4494
pull/9026/head
Gökay Şatır 2024-05-09 19:26:01 +03:00 committed by Gökay ŞATIR
parent 3feb7fe58c
commit 717e837211
7 changed files with 51 additions and 72 deletions

View File

@ -1545,9 +1545,8 @@ app.definitions.Socket = L.Class.extend({
if (this._map._docLayer) {
this._map._docLayer.removeAllViews();
this._map._docLayer._resetClientVisArea();
var graphicSelection = new L.LatLngBounds(new L.LatLng(0, 0), new L.LatLng(0, 0));
if (!this._map._docLayer._graphicSelection.equals(graphicSelection)) {
this._map._docLayer._graphicSelection = graphicSelection;
if (this._map._docLayer._graphicSelection) {
this._map._docLayer._graphicSelection = null;
this._map._docLayer._onUpdateGraphicSelection();
}
if (this._map._docLayer._docType === 'presentation')

View File

@ -907,10 +907,8 @@ L.CanvasTileLayer = L.Layer.extend({
this.lastCursorPos = null;
// Are we zooming currently ? - if so, no cursor.
this._isZooming = false;
// Original rectangle graphic selection in twips
this._graphicSelectionTwips = new L.Bounds(new L.Point(0, 0), new L.Point(0, 0));
// Rectangle graphic selection
this._graphicSelection = new L.LatLngBounds(new L.LatLng(0, 0), new L.LatLng(0, 0));
this._graphicSelection = null;
// Rotation angle of selected graphic object
this._graphicSelectionAngle = 0;
app.calc.cellCursorVisible = false;
@ -918,7 +916,7 @@ L.CanvasTileLayer = L.Layer.extend({
this._prevCellCursorAddress = null;
this._cellCursorOnPgUp = null;
this._cellCursorOnPgDn = null;
this._shapeGridOffset = new L.Point(0, 0);
this._shapeGridOffset = new app.definitions.simplePoint(0, 0);
// Tile garbage collection counter
this._gcCounter = 0;
@ -2223,14 +2221,9 @@ L.CanvasTileLayer = L.Layer.extend({
var videoDesc = JSON.parse(textMsg);
if (this._graphicSelectionTwips) {
var topLeftPoint = this._twipsToCssPixels(
this._graphicSelectionTwips.getTopLeft(), this._map.getZoom());
var bottomRightPoint = this._twipsToCssPixels(
this._graphicSelectionTwips.getBottomRight(), this._map.getZoom());
videoDesc.width = bottomRightPoint.x - topLeftPoint.x;
videoDesc.height = bottomRightPoint.y - topLeftPoint.y;
if (this._graphicSelection) {
videoDesc.width = this._graphicSelection.cWidth;
videoDesc.height = this._graphicSelection.cHeight;
}
// proxy cannot identify RouteToken if it is encoded
var routeTokenIndex = videoDesc.url.indexOf('%26RouteToken=');
@ -2253,8 +2246,7 @@ L.CanvasTileLayer = L.Layer.extend({
},
_resetSelectionRanges: function() {
this._graphicSelectionTwips = new L.Bounds(new L.Point(0, 0), new L.Point(0, 0));
this._graphicSelection = new L.LatLngBounds(new L.LatLng(0, 0), new L.LatLng(0, 0));
this._graphicSelection = null;
this._hasActiveSelection = false;
},
@ -2267,53 +2259,41 @@ L.CanvasTileLayer = L.Layer.extend({
},
_extractAndSetGraphicSelection: function(messageJSON) {
var calcRTL = this.isCalcRTL();
var signX = calcRTL ? -1 : 1;
var signX = this.isCalcRTL() ? -1 : 1;
var hasExtraInfo = messageJSON.length > 5;
var hasGridOffset = false;
var extraInfo = null;
if (hasExtraInfo) {
extraInfo = messageJSON[5];
if (extraInfo.gridOffsetX || extraInfo.gridOffsetY) {
this._shapeGridOffset = new L.Point(signX * parseInt(extraInfo.gridOffsetX), parseInt(extraInfo.gridOffsetY));
this._shapeGridOffset = new app.definitions.simplePoint(signX * extraInfo.gridOffsetX, extraInfo.gridOffsetY);
hasGridOffset = true;
}
}
// Calc RTL: Negate positive X coordinates from core if grid offset is available.
signX = hasGridOffset && calcRTL ? -1 : 1;
var topLeftTwips = new L.Point(signX * messageJSON[0], messageJSON[1]);
var offset = new L.Point(signX * messageJSON[2], messageJSON[3]);
var bottomRightTwips = topLeftTwips.add(offset);
signX = hasGridOffset && this.isCalcRTL() ? -1 : 1;
this._graphicSelection = new app.definitions.simpleRectangle(signX * messageJSON[0], messageJSON[1], signX * messageJSON[2], messageJSON[3]);
if (hasGridOffset) {
this._graphicSelectionTwips = new L.Bounds(topLeftTwips.add(this._shapeGridOffset), bottomRightTwips.add(this._shapeGridOffset));
} else {
this._graphicSelectionTwips = this._getGraphicSelectionRectangle(
new L.Bounds(topLeftTwips, bottomRightTwips));
}
this._graphicSelection = new L.LatLngBounds(
this._twipsToLatLng(this._graphicSelectionTwips.getTopLeft(), this._map.getZoom()),
this._twipsToLatLng(this._graphicSelectionTwips.getBottomRight(), this._map.getZoom()));
if (hasGridOffset)
this._graphicSelection.moveBy([this._shapeGridOffset.x, this._shapeGridOffset.y]);
this._graphicSelection.extraInfo = extraInfo;
},
renderDarkOverlay: function () {
var zoom = this._map.getZoom();
var northEastPoint = this._latLngToCorePixels(this._graphicSelection.getNorthEast(), zoom);
var southWestPoint = this._latLngToCorePixels(this._graphicSelection.getSouthWest(), zoom);
var topLeft = new L.Point(this._graphicSelection.pX1, this._graphicSelection.pY1);
var bottomRight = new L.Point(this._graphicSelection.pX2, this._graphicSelection.pY2);
if (this.isCalcRTL()) {
// Dark overlays (like any other overlay) need regular document coordinates.
// But in calc-rtl mode, charts (like shapes) have negative x document coordinate
// internal representation.
northEastPoint.x = Math.abs(northEastPoint.x);
southWestPoint.x = Math.abs(southWestPoint.x);
topLeft.x = Math.abs(topLeft.x);
bottomRight.x = Math.abs(bottomRight.x);
}
var bounds = new L.Bounds(northEastPoint, southWestPoint);
var bounds = new L.Bounds(topLeft, bottomRight);
this._oleCSelections.setPointSet(CPointSet.fromBounds(bounds));
},
@ -2346,7 +2326,7 @@ L.CanvasTileLayer = L.Layer.extend({
}
this.renderDarkOverlay();
this._graphicSelection = new L.LatLngBounds(new L.LatLng(0, 0), new L.LatLng(0, 0));
this._graphicSelection = null;
this._onUpdateGraphicSelection();
}
}
@ -2400,16 +2380,20 @@ L.CanvasTileLayer = L.Layer.extend({
}
// scroll to selected graphics, if it has no cursor
if (!this.isWriter() && !this._isEmptyRectangle(this._graphicSelection)
if (!this.isWriter() && this._graphicSelection
&& this._allowViewJump()) {
var docLayer = this._map._docLayer;
var paneRectsInLatLng = this.getPaneLatLngRectangles();
if (!this._graphicSelection.isInAny(paneRectsInLatLng) &&
if (
(
!app.isPointVisibleInTheDisplayedArea([this._graphicSelection.x1, this._graphicSelection.y1]) ||
!app.isPointVisibleInTheDisplayedArea([this._graphicSelection.x2, this._graphicSelection.y2])
)
&&
!this._selectionHandles.active &&
!(docLayer._followEditor || docLayer._followUser) &&
!this._map.calcInputBarHasFocus()) {
this.scrollToPos(this._graphicSelection.getNorthWest());
this.scrollToPos(new app.definitions.simplePoint(this._graphicSelection.x1, this._graphicSelection.y1));
}
}
@ -3656,7 +3640,7 @@ L.CanvasTileLayer = L.Layer.extend({
// hide the selection handles
this._onUpdateTextSelection();
// hide the graphic selection
this._graphicSelection = new L.LatLngBounds(new L.LatLng(0, 0), new L.LatLng(0, 0));
this._graphicSelection = null;
this._onUpdateGraphicSelection();
app.calc.cellCursorVisible = false;
this._prevCellCursor = null;
@ -3860,7 +3844,7 @@ L.CanvasTileLayer = L.Layer.extend({
// Scrolls the view to selected position
scrollToPos: function(pos) {
if (pos.pX) // Turn into lat/lng if required (pos may also be a simplePoint.).
if (pos instanceof app.definitions.simplePoint) // Turn into lat/lng if required (pos may also be a simplePoint.).
pos = this._twipsToLatLng({ x: pos.x, y: pos.y });
var center = this._map.project(pos);
@ -3884,8 +3868,7 @@ L.CanvasTileLayer = L.Layer.extend({
if (!zoom
&& scroll !== false
&& (app.file.textCursor.visible
|| (this._graphicSelection && !this._isEmptyRectangle(this._graphicSelection)))
&& (app.file.textCursor.visible || this._graphicSelection)
// Do not center view in Calc if no new cursor coordinates have arrived yet.
// ie, 'invalidatecursor' has not arrived after 'cursorvisible' yet.
&& (!this.isCalc() || (this._lastVisibleCursorRef && !this._lastVisibleCursorRef.equals(app.file.textCursor.rectangle.toArray())))
@ -4206,12 +4189,9 @@ L.CanvasTileLayer = L.Layer.extend({
}
}
else {
var newPos = new L.Point(
// Choose the logical left of the shape.
this._graphicSelectionTwips.min.x + deltaPos.x,
this._graphicSelectionTwips.min.y + deltaPos.y);
var size = this._graphicSelectionTwips.getSize();
// Choose the logical left of the shape.
var newPos = new L.Point(this._graphicSelection.x1 + deltaPos.x, this._graphicSelection.y1 + deltaPos.y);
var size = { x: this._graphicSelection.width, y: this._graphicSelection.height };
if (calcRTL) {
// make x coordinate of newPos +ve
@ -4262,8 +4242,8 @@ L.CanvasTileLayer = L.Layer.extend({
var calcRTL = this.isCalcRTL();
var aPos = this._latLngToTwips(e.pos);
var selMin = this._graphicSelectionTwips.min;
var selMax = this._graphicSelectionTwips.max;
var selMin = { x: this._graphicSelection.x1, y: this._graphicSelection.y1 };
var selMax = { x: this._graphicSelection.x2, y: this._graphicSelection.y2 };
var handleId = e.handleId;
@ -4325,7 +4305,7 @@ L.CanvasTileLayer = L.Layer.extend({
this._graphicMarker.setVisible(true);
}
else if (e.type === 'rotateend') {
var center = this._graphicSelectionTwips.getCenter();
var center = { x: this._graphicSelection.center[0], y: this._graphicSelection.center[1] };
if (this.isCalc() && this.options.printTwipsMsgsEnabled) {
center = this.sheetGeometry.getPrintTwipsPointFromTile(center);
}
@ -4415,7 +4395,7 @@ L.CanvasTileLayer = L.Layer.extend({
// Update group layer selection handler.
_onUpdateGraphicSelection: function () {
if (this._graphicSelection && !this._isEmptyRectangle(this._graphicSelection)) {
if (this._graphicSelection) {
// Hide the keyboard on graphic selection, unless cursor is visible.
// Don't interrupt editing in dialogs
if (!this._isAnyInputFocused())
@ -4716,8 +4696,7 @@ L.CanvasTileLayer = L.Layer.extend({
},
hasGraphicSelection: function() {
return (this._graphicSelection !== null &&
!this._isEmptyRectangle(this._graphicSelection));
return !!this._graphicSelection;
},
_onDragOver: function (e) {
@ -4942,7 +4921,7 @@ L.CanvasTileLayer = L.Layer.extend({
if (!this.options.printTwipsMsgsEnabled || !this.sheetGeometry)
return point;
var newPoint = new L.Point(parseInt(point.x), parseInt(point.y));
var _offset = offset ? new L.Point(parseInt(offset.x), parseInt(offset.y)) : this._shapeGridOffset;
var _offset = offset ? new L.Point(parseInt(offset.x), parseInt(offset.y)) : new L.Point(this._shapeGridOffset.x, this._shapeGridOffset.y);
return newPoint.add(_offset);
},

View File

@ -258,8 +258,7 @@ export class SheetGeometry {
// in print-twips.
public getPrintTwipsPointFromTile(point: Point): Point {
if (!(point instanceof L.Point)) {
console.error('Bad argument type, expected L.Point');
return point;
console.warn('Bad argument type, expected L.Point');
}
return new L.Point(this._columns.getPrintTwipsPosFromTile(point.x),

View File

@ -18,10 +18,9 @@ L.WriterTileLayer = L.CanvasTileLayer.extend({
newAnnotation: function (comment) {
if (app.file.textCursor.visible) {
comment.anchorPos = [app.file.textCursor.rectangle.x2, app.file.textCursor.rectangle.y1];
} else if (this._graphicSelection && !this._isEmptyRectangle(this._graphicSelection)) {
} else if (this._graphicSelection) {
// An image is selected, then guess the anchor based on the graphic selection.
const temp = this._latLngToTwips(this._graphicSelection.getSouthWest());
comment.anchorPos = [temp.x, temp.y];
comment.anchorPos = [this._graphicSelection.x1, this._graphicSelection.y2];
}
var annotation = app.sectionContainer.getSectionWithName(L.CSections.CommentList.name).add(comment);

View File

@ -3,7 +3,7 @@
* L.SVGGroup
*/
/* global _ */
/* global _ app */
L.SVGGroup = L.Layer.extend({
@ -21,6 +21,9 @@ L.SVGGroup = L.Layer.extend({
}),
initialize: function (bounds, options) {
if (bounds.clone) // If this is a simpleRectangle.
bounds = app.map._docLayer._simpleRectangleToLatLngBounds(bounds.clone());
L.setOptions(this, options);
this._pathNodeCollection = new L.Path.PathNodeCollection();
this._bounds = bounds;

View File

@ -52,7 +52,7 @@ L.Map.Mouse = L.Handler.extend({
if (docLayer._graphicMarker.isDragged) {
return;
}
if (!docLayer._isEmptyRectangle(docLayer._graphicSelection)) {
if (docLayer._graphicSelection) {
// if we have a graphic selection and the user clicks inside the rectangle
var isInside = docLayer._graphicMarker.getBounds().contains(e.latlng);
if (e.type === 'mousedown' && isInside) {

View File

@ -253,7 +253,7 @@ L.Map.TouchGesture = L.Handler.extend({
// check new selection if any
var graphicSelection = docLayer._graphicSelection;
if (!docLayer._cursorAtMispelledWord
&& (!graphicSelection || !graphicSelection.contains(latlng))
&& (!graphicSelection || !graphicSelection.containsPoint(posInTwips.toArray()))
&& (!app.calc.cellCursorVisible || !app.calc.cellCursorRectangle.containsPoint(posInTwips.toArray()))) {
// try to select text
doubleClick();
@ -284,8 +284,8 @@ L.Map.TouchGesture = L.Handler.extend({
textSelection.height = docLayer._selectionHandles.end.rectangle.y2 - docLayer._selectionHandles.start.rectangle.y1;
}
if ((textSelection && textSelection.pContainsPoint(posInTwips.toArray()))
|| (graphicSelection && graphicSelection.contains(latlng))
if ((textSelection && textSelection.containsPoint(posInTwips.toArray()))
|| (graphicSelection && graphicSelection.containsPoint(posInTwips.toArray()))
|| (app.calc.cellCursorVisible && app.calc.cellCursorRectangle.containsPoint(posInTwips.toArray())) || bContainsSel) {
// long touched an already selected object
// send right click to trigger context menus