diff --git a/webodf/lib/gui/AnnotationViewManager.js b/webodf/lib/gui/AnnotationViewManager.js index ce69f515..1dd89c52 100644 --- a/webodf/lib/gui/AnnotationViewManager.js +++ b/webodf/lib/gui/AnnotationViewManager.js @@ -46,6 +46,11 @@ gui.AnnotatableCanvas.prototype.getZoomLevel = function () {"use strict"; }; * @return {Element} */ gui.AnnotatableCanvas.prototype.getSizer = function () {"use strict"; }; + +/** + * @return {!gui.Viewport} + */ +gui.AnnotatableCanvas.prototype.getViewport = function () {"use strict"; }; /*jslint emptyblock:false*/ /** @@ -75,7 +80,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment, /** * Wraps an annotation with various HTML elements for styling, including connectors * @param {!odf.AnnotationElement} annotation - * @return {undefined} + * @return {!Element} */ function wrapAnnotation(annotation) { var annotationWrapper = doc.createElement('div'), @@ -102,6 +107,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment, annotationWrapper.appendChild(annotationNote); annotationWrapper.appendChild(connectorHorizontal); annotationWrapper.appendChild(connectorAngular); + return annotationNote; } /** @@ -343,9 +349,11 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment, /** * Adds an annotation to track, and wraps and highlights it * @param {!odf.AnnotationElement} annotation + * @param {!boolean=} scrollIntoView Scroll the annotation note into view after creation * @return {undefined} */ - function addAnnotation(annotation) { + function addAnnotation(annotation, scrollIntoView) { + var annotationNote; showAnnotationsPane(true); // TODO: make use of the fact that current list is already sorted @@ -354,11 +362,14 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment, sortAnnotations(); - wrapAnnotation(annotation); + annotationNote = wrapAnnotation(annotation); if (annotation.annotationEndElement) { highlightAnnotation(annotation); } rerenderAnnotations(); + if (scrollIntoView === true) { + canvas.getViewport().scrollIntoView(annotationNote.getBoundingClientRect()); + } } this.addAnnotation = addAnnotation; diff --git a/webodf/lib/manifest.json b/webodf/lib/manifest.json index a3a74f5b..4d791fb8 100644 --- a/webodf/lib/manifest.json +++ b/webodf/lib/manifest.json @@ -62,6 +62,7 @@ "ops.Session" ], "gui.AnnotationViewManager": [ + "gui.Viewport", "odf.OdfContainer", "odf.OdfUtils" ], diff --git a/webodf/lib/odf/OdfCanvas.js b/webodf/lib/odf/OdfCanvas.js index dea4f72c..3353e9b2 100644 --- a/webodf/lib/odf/OdfCanvas.js +++ b/webodf/lib/odf/OdfCanvas.js @@ -1065,7 +1065,9 @@ function modifyAnnotations(odffragment) { var annotationNodes = /**@type{!Array.}*/(domUtils.getElementsByTagNameNS(odffragment, officens, 'annotation')); - annotationNodes.forEach(annotationViewManager.addAnnotation); + annotationNodes.forEach(function(annotation) { + annotationViewManager.addAnnotation(annotation, false); + }); annotationViewManager.rerenderAnnotations(); } @@ -1296,7 +1298,7 @@ */ this.addAnnotation = function (annotation) { if (annotationViewManager) { - annotationViewManager.addAnnotation(annotation); + annotationViewManager.addAnnotation(annotation, true); fixContainerSize(); } }; diff --git a/webodf/tools/karma.conf.js b/webodf/tools/karma.conf.js index 692b2897..4fa88862 100644 --- a/webodf/tools/karma.conf.js +++ b/webodf/tools/karma.conf.js @@ -46,6 +46,7 @@ module.exports = function (config) { 'lib/gui/CommonConstraints.js', 'lib/gui/SessionConstraints.js', 'lib/gui/BlacklistNamespaceNodeFilter.js', + 'lib/gui/Viewport.js', 'lib/xmldom/LSSerializerFilter.js', 'lib/odf/OdfNodeFilter.js', 'lib/odf/Namespaces.js', @@ -55,7 +56,6 @@ module.exports = function (config) { 'lib/odf/OdfContainer.js', 'lib/odf/OdfUtils.js', 'lib/gui/AnnotationViewManager.js', - 'lib/gui/Viewport.js', 'lib/gui/SingleScrollViewport.js', 'lib/odf/FontLoader.js', 'lib/odf/Formatting.js',