Skip to content

Commit

Permalink
Use a section and remove latlng and leaflet usage from impress&draw c…
Browse files Browse the repository at this point in the history
…omments.

Signed-off-by: Gökay Şatır <[email protected]>
Change-Id: Id83eb01940d345b9954c441dd7cb0cff12516fa7
  • Loading branch information
gokaysatir committed Jan 13, 2025
1 parent 7faabbd commit a400bca
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 62 deletions.
4 changes: 3 additions & 1 deletion browser/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,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 @@ -269,7 +271,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 @@ -943,6 +944,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
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;
108 changes: 47 additions & 61 deletions browser/src/canvas/sections/CommentSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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 @@ -130,6 +129,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 @@ -713,32 +713,50 @@ 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 createMarkerSubSection() {
if (this.sectionProperties.data.rectangle === null)
return;

if (app.sectionContainer.doesSectionExist(this.name + 'Marker'))
app.sectionContainer.removeSection(this.name + 'Marker');

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

this.sectionProperties.commentMarkerSubSection = new CommentMarkerSubSection(
this.name + 'Marker', // Section name.
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);
}

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

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

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);
}
if (this.sectionProperties.commentMarkerSubSection === null)
this.createMarkerSubSection();
}

public isContainerVisible (): boolean {
Expand All @@ -754,18 +772,20 @@ export class Comment extends CanvasSectionObject {
this.updateContent();
this.updateLayout();
this.updatePosition();
this.updateAnnotationMarker();
this.updateCommentMarker();
}

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 @@ -1205,44 +1225,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 @@ -1477,6 +1459,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);

if (container && container.parentElement) {
var c: number = 0;
while (c < 10) {
Expand Down

0 comments on commit a400bca

Please sign in to comment.