Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a section and remove latlng and leaflet usage from impress&draw c… #10921

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion browser/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ COOL_JS_LST =\
src/canvas/CanvasSectionProps.js \
src/canvas/CanvasSectionContainer.ts \
src/canvas/CanvasSectionObject.ts \
src/canvas/sections/HTMLObjectSection.ts \
src/canvas/sections/CommentMarkerSubSection.ts \
src/canvas/sections/CommentSection.ts \
src/canvas/sections/CommentListSection.ts \
src/canvas/sections/CalcGridSection.ts \
Expand All @@ -273,7 +275,6 @@ COOL_JS_LST =\
src/canvas/sections/PreloadMapSection.ts \
src/canvas/sections/TilesSection.ts \
src/canvas/sections/AutoFillMarkerSection.ts \
src/canvas/sections/HTMLObjectSection.ts \
src/canvas/sections/URLPopUpSection.ts \
src/canvas/sections/InvalidationRectangleSection.ts \
src/canvas/sections/ShapeHandlesSection.ts \
Expand Down Expand Up @@ -947,6 +948,7 @@ pot:
admin/src/Util.js \
js/global.js \
src/canvas/sections/CommentListSection.ts \
src/canvas/sections/CommentMarkerSubSection.ts \
src/canvas/sections/CommentSection.ts \
src/canvas/sections/ShapeHandlesSection.ts \
src/canvas/sections/URLPopUpSection.ts \
Expand Down
2 changes: 1 addition & 1 deletion browser/src/canvas/sections/CommentListSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2375,7 +2375,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {
if (this.sectionProperties.docLayer._docType === 'spreadsheet')
this.hideAllComments(); // Apply drawing orders.

if (!(<any>window).mode.isMobile() && (this.sectionProperties.docLayer._docType === 'presentation' || this.sectionProperties.docLayer._docType === 'drawing'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be still non-mobile only? on mobile we have annotation mobile-wizard to manage comments

if ((this.sectionProperties.docLayer._docType === 'presentation' || this.sectionProperties.docLayer._docType === 'drawing'))
this.showHideComments();

CommentSection.importingComments = false;
Expand Down
123 changes: 123 additions & 0 deletions browser/src/canvas/sections/CommentMarkerSubSection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/* global Proxy _ */
/*
* Copyright the Collabora Online contributors.
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

/*
This class is for Impress's and Draw's comment markers.
This is a sub section, needs to know about the parent section.
*/

class CommentMarkerSubSection extends HTMLObjectSection {
constructor(
sectionName: string,
objectWidth: number,
objectHeight: number,
documentPosition: cool.SimplePoint,
extraClass: string = '',
showSection: boolean = false,
parentSection: any, // Parent section.
data: any, // Parent section's data.
) {
super(
sectionName,
objectWidth,
objectHeight,
documentPosition,
extraClass,
showSection,
);
this.sectionProperties.parentSection = parentSection;
this.sectionProperties.data = data;
this.sectionProperties.dragStartPosition = null;
}

private sendAnnotationPositionChange(newPosition: number[]): void {
if (app.file.fileBasedView) {
app.map.setPart(this.sectionProperties.docLayer._selectedPart, false);
newPosition[1] -= this.sectionProperties.data.yAddition;
}

const comment = {
Id: {
type: 'string',
value: this.sectionProperties.data.id,
},
PositionX: {
type: 'int32',
value: newPosition[0],
},
PositionY: {
type: 'int32',
value: newPosition[1],
},
};
app.map.sendUnoCommand('.uno:EditAnnotation', comment);

if (app.file.fileBasedView) app.setPart(0, false);
}

onMouseMove(
point: Array<number>,
dragDistance: Array<number>,
e: MouseEvent,
): void {
if (this.sectionProperties.parentSection === null) return;

if (app.sectionContainer.isDraggingSomething()) {
(<any>window).IgnorePanning = true;

if (this.sectionProperties.parent === null) return;

if (this.sectionProperties.dragStartPosition === null)
this.sectionProperties.dragStartPosition = this.position.slice();

this.setPosition(
this.sectionProperties.dragStartPosition[0] + dragDistance[0],
this.sectionProperties.dragStartPosition[1] + dragDistance[1],
);
}
}

onDragEnd(): void {
(<any>window).IgnorePanning = undefined;

this.sectionProperties.dragStartPosition = null;

const twips = [
this.position[0] * app.pixelsToTwips,
this.position[1] * app.pixelsToTwips,
];

this.sendAnnotationPositionChange(twips);
}

onClick(point: number[], e: MouseEvent): void {
e.stopPropagation();
this.stopPropagating();
this.sectionProperties.parentSection.sectionProperties.commentListSection.selectById(
this.sectionProperties.data.id,
);
}

onMouseDown(point: number[], e: MouseEvent): void {
e.stopPropagation();
this.stopPropagating();
}

onMouseUp(point: number[], e: MouseEvent): void {
e.stopPropagation();
if (this.containerObject.isDraggingSomething()) {
this.stopPropagating();
this.onDragEnd();
}
}
}

app.definitions.commentMarkerSubSection = CommentMarkerSubSection;
104 changes: 38 additions & 66 deletions browser/src/canvas/sections/CommentSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export class Comment extends CanvasSectionObject {
* We will check child comment to see if its parent has also been revived.
*/
this.sectionProperties.possibleParentCommentId = null;
this.sectionProperties.annotationMarker = null;
this.sectionProperties.wrapper = null;
this.sectionProperties.container = null;
this.sectionProperties.author = null;
Expand Down Expand Up @@ -134,6 +133,7 @@ export class Comment extends CanvasSectionObject {
this.sectionProperties.childLinesNode = null;
this.sectionProperties.childLines = [];
this.sectionProperties.childCommentOffset = 8;
this.sectionProperties.commentMarkerSubSection = null; // For Impress and Draw documents.

this.convertRectanglesToCoreCoordinates(); // Convert rectangle coordiantes into core pixels on initialization.

Expand Down Expand Up @@ -233,6 +233,9 @@ export class Comment extends CanvasSectionObject {

this.sectionProperties.container.style.visibility = 'hidden';

if (this.sectionProperties.commentMarkerSubSection === null)
this.createMarkerSubSection();

this.doPendingInitializationInView();
}

Expand Down Expand Up @@ -718,32 +721,35 @@ export class Comment extends CanvasSectionObject {
this.setPositionAndSize();
if (this.sectionProperties.docLayer._docType === 'spreadsheet')
this.positionCalcComment();
else if (this.sectionProperties.docLayer._docType === "presentation" || this.sectionProperties.docLayer._docType === "drawing") {
if (this.sectionProperties.commentMarkerSubSection !== null) {
this.sectionProperties.commentMarkerSubSection.sectionProperties.data = this.sectionProperties.data;
this.sectionProperties.commentMarkerSubSection.setPosition(
this.sectionProperties.data.anchorPos[0] * app.twipsToPixels,
this.sectionProperties.data.anchorPos[1] * app.twipsToPixels
);
}
}
}

private updateAnnotationMarker (): void {
// Make sure to place the markers only for presentations and draw documents
if (this.sectionProperties.docLayer._docType !== 'presentation' && this.sectionProperties.docLayer._docType !== 'drawing')
private createMarkerSubSection() {
if (this.sectionProperties.data.rectangle === null)
return;

if (this.sectionProperties.data == null)
return;
const showMarker = app.impress.partList[this.sectionProperties.docLayer._selectedPart].hash === parseInt(this.sectionProperties.data.parthash) ||
app.file.fileBasedView;

if (this.sectionProperties.annotationMarker === null) {
this.sectionProperties.annotationMarker = L.marker(new L.LatLng(0, 0), {
icon: L.divIcon({
className: 'annotation-marker',
iconSize: null
}),
draggable: true
});
if (app.impress.partList[this.sectionProperties.docLayer._selectedPart].hash === parseInt(this.sectionProperties.data.parthash) || app.file.fileBasedView)
this.map.addLayer(this.sectionProperties.annotationMarker);
}
if (this.sectionProperties.data.rectangle != null) {
this.sectionProperties.annotationMarker.setLatLng(this.sectionProperties.docLayer._twipsToLatLng(new L.Point(this.sectionProperties.data.rectangle[0], this.sectionProperties.data.rectangle[1])));
this.sectionProperties.annotationMarker.on('dragstart drag dragend', this.onMarkerDrag, this);
//this.sectionProperties.annotationMarker.on('click', this.onMarkerClick, this);
}
this.sectionProperties.commentMarkerSubSection = new CommentMarkerSubSection(
this.name + this.sectionProperties.data.id + String(Math.random()), // Section name - only as a placeholder.
28, 28, // Width and height.
new SimplePoint(this.sectionProperties.data.anchorPos[0], this.sectionProperties.data.anchorPos[1]), // Document position.
'annotation-marker', // Extra class.
showMarker, // Show section.
this, // Parent section.
this.sectionProperties.data
);

app.sectionContainer.addSection(this.sectionProperties.commentMarkerSubSection);
}

public isContainerVisible (): boolean {
Expand All @@ -759,18 +765,19 @@ export class Comment extends CanvasSectionObject {
this.updateContent();
this.updateLayout();
this.updatePosition();
this.updateAnnotationMarker();
}

private showMarker (): void {
if (this.sectionProperties.annotationMarker != null) {
this.map.addLayer(this.sectionProperties.annotationMarker);
if (this.sectionProperties.commentMarkerSubSection != null) {
this.sectionProperties.commentMarkerSubSection.showSection = true;
this.sectionProperties.commentMarkerSubSection.onSectionShowStatusChange();
}
}

private hideMarker (): void {
if (this.sectionProperties.annotationMarker != null) {
this.map.removeLayer(this.sectionProperties.annotationMarker);
if (this.sectionProperties.commentMarkerSubSection != null) {
this.sectionProperties.commentMarkerSubSection.showSection = false;
this.sectionProperties.commentMarkerSubSection.onSectionShowStatusChange();
}
}

Expand Down Expand Up @@ -1230,44 +1237,6 @@ export class Comment extends CanvasSectionObject {
return false;
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
private sendAnnotationPositionChange (newPosition: any): void {
if (app.file.fileBasedView) {
this.map.setPart(this.sectionProperties.docLayer._selectedPart, false);
newPosition.y -= this.sectionProperties.data.yAddition;
}

var comment = {
Id: {
type: 'string',
value: this.sectionProperties.data.id
},
PositionX: {
type: 'int32',
value: newPosition.x
},
PositionY: {
type: 'int32',
value: newPosition.y
}
};
this.map.sendUnoCommand('.uno:EditAnnotation', comment);

if (app.file.fileBasedView)
this.map.setPart(0, false);
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
private onMarkerDrag (event: any): void {
if (this.sectionProperties.annotationMarker == null)
return;

if (event.type === 'dragend') {
var pointTwip = this.sectionProperties.docLayer._latLngToTwips(this.sectionProperties.annotationMarker.getLatLng());
this.sendAnnotationPositionChange(pointTwip);
}
}

public isDisplayed (): boolean {
return (this.sectionProperties.container.style && this.sectionProperties.container.style.visibility === '');
}
Expand Down Expand Up @@ -1501,7 +1470,10 @@ export class Comment extends CanvasSectionObject {

this.sectionProperties.commentListSection.hideArrow();
var container = this.sectionProperties.container;
this.hideMarker();

if (this.sectionProperties.commentMarkerSubSection !== null)
app.sectionContainer.removeSection(this.sectionProperties.commentMarkerSubSection.name);

if (container && container.parentElement) {
var c: number = 0;
while (c < 10) {
Expand Down
1 change: 0 additions & 1 deletion browser/src/control/Control.JSDialogBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,6 @@ L.Control.JSDialogBuilder = L.Control.extend({
annotation.update();
annotation.setExpanded();
annotation.hideMarker();
annotation.sectionProperties.annotationMarker = null;
},

_rootCommentControl: function(parentContainer, data, builder) {
Expand Down
15 changes: 0 additions & 15 deletions browser/src/layer/tile/ImpressTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,21 +342,6 @@ L.ImpressTileLayer = L.CanvasTileLayer.extend({
this._updateFileBasedView();
},

_addHighlightSelectedWizardComment: function(annotation) {
if (this.lastWizardCommentHighlight) {
this.lastWizardCommentHighlight.removeClass('impress-comment-highlight');
}
if (annotation._annotationMarker) {
this.lastWizardCommentHighlight = $(this._map._layers[annotation._annotationMarker._leaflet_id]._icon);
this.lastWizardCommentHighlight.addClass('impress-comment-highlight');
}
},

_removeHighlightSelectedWizardComment: function() {
if (this.lastWizardCommentHighlight)
this.lastWizardCommentHighlight.removeClass('impress-comment-highlight');
},

_invalidateAllPreviews: function () {
L.CanvasTileLayer.prototype._invalidateAllPreviews.call(this);
this._map.fire('invalidateparts');
Expand Down