aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/pdf/Page.tsx
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-06-14 15:47:43 -0400
committeryipstanley <stanley_yip@brown.edu>2019-06-14 15:47:43 -0400
commit2ef1dd2089ad991f1d4897022f2d28c2eb130837 (patch)
tree57add9cdf31cad56fa93987ab570e5ef3e91fc1d /src/client/views/pdf/Page.tsx
parent4818b12510404e7d9cf07b7e872c49d7b752976a (diff)
highlighting
Diffstat (limited to 'src/client/views/pdf/Page.tsx')
-rw-r--r--src/client/views/pdf/Page.tsx74
1 files changed, 55 insertions, 19 deletions
diff --git a/src/client/views/pdf/Page.tsx b/src/client/views/pdf/Page.tsx
index bdb6952cc..44c502a04 100644
--- a/src/client/views/pdf/Page.tsx
+++ b/src/client/views/pdf/Page.tsx
@@ -28,7 +28,7 @@ interface IPageProps {
sendAnnotations: (annotations: HTMLDivElement[], page: number) => void;
receiveAnnotations: (page: number) => HTMLDivElement[] | undefined;
createAnnotation: (div: HTMLDivElement, page: number) => void;
- makeAnnotationDocuments: (doc: Doc) => Doc;
+ makeAnnotationDocuments: (doc: Doc | undefined) => Doc;
}
@observer
@@ -132,6 +132,20 @@ export default class Page extends React.Component<IPageProps> {
}
}
+ highlight = (targetDoc: Doc | undefined) => {
+ // creates annotation documents for current highlights
+ let annotationDoc = this.props.makeAnnotationDocuments(targetDoc);
+ let targetAnnotations = DocListCast(this.props.parent.Document.annotations);
+ if (targetAnnotations) {
+ targetAnnotations.push(annotationDoc);
+ this.props.parent.Document.annotations = new List<Doc>(targetAnnotations);
+ }
+ else {
+ this.props.parent.Document.annotations = new List<Doc>([annotationDoc]);
+ }
+ return annotationDoc;
+ }
+
/**
* This is temporary for creating annotations from highlights. It will
* start a drag event and create or put the necessary info into the drag event.
@@ -149,16 +163,7 @@ export default class Page extends React.Component<IPageProps> {
// document that this annotation is linked to
let targetDoc = Docs.TextDocument({ width: 200, height: 200, title: "New Annotation" });
targetDoc.targetPage = this.props.page;
- // creates annotation documents for current highlights
- let annotationDoc = this.props.makeAnnotationDocuments(targetDoc);
- let targetAnnotations = DocListCast(this.props.parent.Document.annotations);
- if (targetAnnotations) {
- targetAnnotations.push(annotationDoc);
- this.props.parent.Document.annotations = new List<Doc>(targetAnnotations);
- }
- else {
- this.props.parent.Document.annotations = new List<Doc>([annotationDoc]);
- }
+ let annotationDoc = this.highlight(targetDoc);
// create dragData and star tdrag
let dragData = new DragManager.AnnotationDragData(thisDoc, annotationDoc, targetDoc);
if (this._textLayer.current) {
@@ -173,8 +178,8 @@ export default class Page extends React.Component<IPageProps> {
// cleans up events and boolean
endDrag = (e: PointerEvent): void => {
- document.removeEventListener("pointermove", this.startDrag);
- document.removeEventListener("pointerup", this.endDrag);
+ // document.removeEventListener("pointermove", this.startDrag);
+ // document.removeEventListener("pointerup", this.endDrag);
this._dragging = false;
e.stopPropagation();
}
@@ -185,10 +190,10 @@ export default class Page extends React.Component<IPageProps> {
if (e.altKey && e.button === 0) {
e.stopPropagation();
- document.removeEventListener("pointermove", this.startDrag);
- document.addEventListener("pointermove", this.startDrag);
- document.removeEventListener("pointerup", this.endDrag);
- document.addEventListener("pointerup", this.endDrag);
+ // document.removeEventListener("pointermove", this.startDrag);
+ // document.addEventListener("pointermove", this.startDrag);
+ // document.removeEventListener("pointerup", this.endDrag);
+ // document.addEventListener("pointerup", this.endDrag);
}
else if (e.button === 0) {
let target: any = e.target;
@@ -299,6 +304,8 @@ export default class Page extends React.Component<IPageProps> {
}
copy.className = this._marquee.current.className;
this.props.createAnnotation(copy, this.props.page);
+ PDFMenu.Instance.StartDrag = this.startDrag;
+ PDFMenu.Instance.Highlight = this.highlight;
this._marquee.current.style.opacity = "0";
}
@@ -308,8 +315,10 @@ export default class Page extends React.Component<IPageProps> {
}
else {
let sel = window.getSelection();
- if (sel && sel.type === "range") {
-
+ if (sel && sel.type === "Range") {
+ PDFMenu.Instance.StartDrag = this.startDrag;
+ PDFMenu.Instance.Highlight = this.highlight;
+ this.createTextAnnotation(sel);
PDFMenu.Instance.Left = e.clientX;
PDFMenu.Instance.Top = e.clientY;
}
@@ -380,6 +389,33 @@ export default class Page extends React.Component<IPageProps> {
document.removeEventListener("pointerup", this.onSelectEnd);
}
+ @action
+ createTextAnnotation = (sel: Selection) => {
+ let clientRects = sel.getRangeAt(0).getClientRects();
+ if (this._textLayer.current) {
+ let boundingRect = this._textLayer.current.getBoundingClientRect();
+ for (let i = 0; i < clientRects.length; i++) {
+ let rect = clientRects.item(i);
+ if (rect) {
+ let annoBox = document.createElement("div");
+ annoBox.className = "pdfViewer-annotationBox";
+ // transforms the positions from screen onto the pdf div
+ annoBox.style.top = ((rect.top - boundingRect.top) * (this._textLayer.current.offsetHeight / boundingRect.height)).toString();
+ annoBox.style.left = ((rect.left - boundingRect.left) * (this._textLayer.current.offsetWidth / boundingRect.width)).toString();
+ annoBox.style.width = (rect.width * this._textLayer.current.offsetWidth / boundingRect.width).toString();
+ annoBox.style.height = (rect.height * this._textLayer.current.offsetHeight / boundingRect.height).toString();
+ this.props.createAnnotation(annoBox, this.props.page);
+ }
+ }
+ }
+ // clear selection
+ if (sel.empty) { // Chrome
+ sel.empty();
+ } else if (sel.removeAllRanges) { // Firefox
+ sel.removeAllRanges();
+ }
+ }
+
doubleClick = (e: React.MouseEvent) => {
let target: any = e.target;
// if double clicking text