Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #233 from vandenoever/typechecking
Browse files Browse the repository at this point in the history
Add more type information.
  • Loading branch information
adityab committed Dec 2, 2013
2 parents fc82e73 + 1b10d7d commit ee4e747
Show file tree
Hide file tree
Showing 22 changed files with 1,052 additions and 723 deletions.
36 changes: 18 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -268,45 +268,45 @@ set(TYPEDLIBJSFILES
lib/core/UnitTester.js
lib/core/Utils.js
lib/core/Zip.js
lib/gui/Avatar.js
lib/gui/EditInfoHandle.js
lib/gui/KeyboardHandler.js
lib/odf/Namespaces.js
lib/odf/OdfUtils.js
lib/ops/Server.js
lib/xmldom/LSSerializerFilter.js
lib/xmldom/XPath.js
lib/core/Cursor.js
lib/core/PositionFilter.js
lib/core/PositionFilterChain.js
lib/gui/AnnotationViewManager.js
lib/gui/SelectionMover.js
lib/odf/MetadataManager.js
lib/odf/OdfNodeFilter.js
lib/odf/Style2CSS.js
lib/odf/StyleInfo.js
lib/odf/TextSerializer.js
lib/ops/TextPositionFilter.js
lib/xmldom/LSSerializer.js
lib/gui/Clipboard.js
lib/odf/OdfContainer.js
lib/odf/FontLoader.js
lib/odf/ObjectNameGenerator.js
lib/odf/TextStyleApplicator.js
lib/odf/Formatting.js
lib/odf/OdfCanvas.js
lib/gui/StyleHelper.js
)
# This list is generated automatically, do not edit this list by hand.
set(UNTYPEDLIBJSFILES
# These files depend only on files that are 100% typed.
lib/core/RawDeflate.js
lib/gui/Avatar.js
lib/gui/Clipboard.js
lib/gui/EditInfoHandle.js
lib/gui/KeyboardHandler.js
lib/gui/SelectionMover.js
lib/gui/StyleHelper.js
lib/odf/OdfContainer.js
lib/odf/Style2CSS.js
lib/gui/ImageSelector.js
lib/odf/CommandLineTools.js
lib/ops/Member.js
lib/ops/Server.js
lib/ops/StepsTranslator.js
lib/ops/TextPositionFilter.js
lib/xmldom/RelaxNGParser.js
# These files depend on files that are not 100% typed.
lib/gui/AnnotationViewManager.js
lib/odf/OdfCanvas.js
lib/gui/ImageSelector.js
lib/odf/CommandLineTools.js
lib/odf/FontLoader.js
lib/odf/ObjectNameGenerator.js
lib/odf/TextStyleApplicator.js
lib/odf/Formatting.js
lib/ops/OdtCursor.js
lib/ops/OdtDocument.js
lib/ops/Operation.js
Expand Down
2 changes: 1 addition & 1 deletion webodf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ if (Java_JAVA_EXECUTABLE)
OUTPUT typecheck.js
COMMAND ${Java_JAVA_EXECUTABLE}
ARGS -jar ${CLOSURE_JAR}
--define IS_COMPILED_CODE=true
--define IS_COMPILED_CODE=true --js webodf.css.js
${SHARED_CLOSURE_ARGS} ${TYPED_LIB_CLOSURE_ARGS}
--jscomp_error reportUnknownTypes
--compilation_level ADVANCED_OPTIMIZATIONS
Expand Down
55 changes: 37 additions & 18 deletions webodf/lib/gui/AnnotationViewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,36 @@
* This needs to be fixed soon.
*/

/*jslint emptyblock:true*/
/**
* Abstraction of document canvas that can have annotations.
* @class
* @interface
*/
gui.AnnotatableCanvas = function AnnotatableCanvas() {"use strict"; };
gui.AnnotatableCanvas.prototype.refreshSize = function () {"use strict"; };
/**
* @return {!number}
*/
gui.AnnotatableCanvas.prototype.getZoomLevel = function () {"use strict"; };
/**
* @return {Element}
*/
gui.AnnotatableCanvas.prototype.getSizer = function () {"use strict"; };
/*jslint emptyblock:false*/

/**
* A GUI class for wrapping Annotation nodes inside html wrappers, positioning
* them on the sidebar, drawing connectors, and highlighting comments.
* @constructor
* @param {!odf.OdfCanvas} odfCanvas
* @param {!gui.AnnotatableCanvas} canvas
* @param {!Element} odfFragment
* @param {!Element} annotationsPane
*/
gui.AnnotationViewManager = function AnnotationViewManager(odfCanvas, odfFragment, annotationsPane) {
gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment, annotationsPane) {
"use strict";
var annotations = [],
var /**@type{!Array.<!{node:!Element,end:Node}>}*/
annotations = [],
doc = odfFragment.ownerDocument,
odfUtils = new odf.OdfUtils(),
/**@const*/
Expand All @@ -66,7 +85,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(odfCanvas, odfFragmen
"Expected to be run in an environment which has a global window, like a browser.");
/**
* Wraps an annotation with various HTML elements for styling, including connectors
* @param {!{node: !Element, end: ?Node}} annotation
* @param {!{node:!Element,end:Node}} annotation
* @return {undefined}
*/
function wrapAnnotation(annotation) {
Expand Down Expand Up @@ -95,7 +114,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(odfCanvas, odfFragmen

/**
* Unwraps an annotation
* @param {!{node: !Element, end: ?Node}} annotation
* @param {!{node:!Element,end:Node}} annotation
* @return {undefined}
*/
function unwrapAnnotation(annotation) {
Expand All @@ -110,7 +129,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(odfCanvas, odfFragmen

/**
* Highlights the text between the annotation node and it's end
* @param {!{node: !Element, end: ?Node}} annotation
* @param {!{node:!Element,end:Node}} annotation
* @return {undefined}
*/
function highlightAnnotation(annotation) {
Expand Down Expand Up @@ -141,7 +160,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(odfCanvas, odfFragmen

/**
* Unhighlights the text between the annotation node and it's end
* @param {!{node: !Element, end: ?Node}} annotation
* @param {!{node:!Element,end:Node}} annotation
* @return {undefined}
*/
function unhighlightAnnotation(annotation) {
Expand Down Expand Up @@ -180,18 +199,18 @@ gui.AnnotationViewManager = function AnnotationViewManager(odfCanvas, odfFragmen
/**
* Recalculates the positions, widths, and rotation angles of things like the annotation note and it's
* connectors. Can and should be called frequently to update the UI
* @param {!{node: !Node, end: ?Node}} annotation
* @param {!{node:!Element,end:Node}} annotation
* @return {undefined}
*/
function renderAnnotation(annotation) {
var annotationNote = annotation.node.parentNode,
connectorHorizontal = annotationNote.nextSibling,
connectorAngular = connectorHorizontal.nextSibling,
annotationWrapper = annotationNote.parentNode,
var annotationNote = annotation.node.parentElement,
connectorHorizontal = annotationNote.nextElementSibling,
connectorAngular = connectorHorizontal.nextElementSibling,
annotationWrapper = annotationNote.parentElement,
connectorAngle = 0,
previousAnnotation = annotations[annotations.indexOf(annotation) - 1],
previousRect,
zoomLevel = odfCanvas.getZoomLevel();
zoomLevel = canvas.getZoomLevel();

annotationNote.style.left =
(annotationsPane.getBoundingClientRect().left
Expand All @@ -203,7 +222,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(odfCanvas, odfFragmen
- CONNECTOR_MARGIN + 'px';

if (previousAnnotation) {
previousRect = previousAnnotation.node.parentNode.getBoundingClientRect();
previousRect = previousAnnotation.node.parentElement.getBoundingClientRect();
if ((annotationWrapper.getBoundingClientRect().top - previousRect.bottom) / zoomLevel <= NOTE_MARGIN) {
annotationNote.style.top = Math.abs(annotationWrapper.getBoundingClientRect().top - previousRect.bottom) / zoomLevel + NOTE_MARGIN + 'px';
} else {
Expand Down Expand Up @@ -237,7 +256,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(odfCanvas, odfFragmen
* @return {undefined}
*/
function showAnnotationsPane(show) {
var sizer = odfCanvas.getSizer();
var sizer = canvas.getSizer();

if (show) {
annotationsPane.style.display = 'inline-block';
Expand All @@ -246,7 +265,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(odfCanvas, odfFragmen
annotationsPane.style.display = 'none';
sizer.style.paddingRight = 0;
}
odfCanvas.refreshSize();
canvas.refreshSize();
}

/**
Expand Down Expand Up @@ -280,7 +299,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(odfCanvas, odfFragmen

/**
* Adds an annotation to track, and wraps and highlights it
* @param {!{node: !Element, end: ?Node}} annotation
* @param {!{node:!Element,end:Node}} annotation
* @return {undefined}
*/
function addAnnotation(annotation) {
Expand All @@ -303,7 +322,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(odfCanvas, odfFragmen

/**
* Unhighlights, unwraps, and ejects an annotation from the tracking
* @param {!{node: !Element, end: ?Node}} annotation
* @param {!{node:!Element,end:Node}} annotation
* @return {undefined}
*/
function forgetAnnotation(annotation) {
Expand Down
8 changes: 6 additions & 2 deletions webodf/lib/gui/Clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@ runtime.loadClass("odf.TextSerializer");
*/
gui.Clipboard = function Clipboard() {
"use strict";
var xmlSerializer, textSerializer, filter;
var /**@type{!xmldom.LSSerializer}*/
xmlSerializer,
/**@type{!odf.TextSerializer}*/
textSerializer,
filter;

/**
* Copy the contents of the supplied range onto the clipboard (if available).
* @param {!Event} e
* @param {!Range} range Selection range to copy into the clipboard
* @return {boolean} Returns true if the data was successfully copied to the clipboard
*/
this.setDataFromRange = function(e, range) {
this.setDataFromRange = function (e, range) {
var result = true,
setDataResult,
clipboard = e.clipboardData,
Expand Down
12 changes: 9 additions & 3 deletions webodf/lib/gui/EditInfoHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@
/*global gui*/
/**
* @constructor
* @param {!Element} parentElement
*/
gui.EditInfoHandle = function EditInfoHandle(parentElement) {
"use strict";

var edits = [],
var /**@type{!Array.<{memberid:string,time:Date}>}*/
edits = [],
/**@type{!HTMLDivElement}*/
handle,
document = /**@type{!Document}*/(parentElement.ownerDocument),
htmlns = document.documentElement.namespaceURI,
Expand Down Expand Up @@ -73,6 +76,9 @@ gui.EditInfoHandle = function EditInfoHandle(parentElement) {
}
}

/**
* @param {!Array.<{memberid:string,time:Date}>} editArray
*/
this.setEdits = function (editArray) {
edits = editArray;
renderEdits();
Expand All @@ -90,13 +96,13 @@ gui.EditInfoHandle = function EditInfoHandle(parentElement) {
* @param {!function(!Object=)} callback, passing an error object in case of error
* @return {undefined}
*/
this.destroy = function(callback) {
this.destroy = function (callback) {
parentElement.removeChild(handle);
callback();
};

function init() {
handle = document.createElementNS(htmlns, "div");
handle = /**@type{!HTMLDivElement}*/(document.createElementNS(htmlns, "div"));
handle.setAttribute('class', 'editInfoHandle');

handle.style.display = 'none';
Expand Down
10 changes: 8 additions & 2 deletions webodf/lib/gui/KeyboardHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@
gui.KeyboardHandler = function KeyboardHandler() {
"use strict";
var modifier = gui.KeyboardHandler.Modifier,
/**@type{?function(!KeyboardEvent):boolean}*/
defaultBinding = null,
/**@type{!Object.<string,function():boolean>}*/
bindings = {};

/**
* @param {!KeyboardEvent} e
* @return {!number}
*/
function getModifiers(e) {
Expand All @@ -62,6 +65,8 @@ gui.KeyboardHandler = function KeyboardHandler() {
}

/**
* @param {!number} keyCode
* @param {!number} modifiers
* @return {!string}
*/
function getKeyCombo(keyCode, modifiers) {
Expand Down Expand Up @@ -92,7 +97,7 @@ gui.KeyboardHandler = function KeyboardHandler() {

/**
* @param {!number} keyCode
* @@param {!number} modifiers
* @param {!number} modifiers
*/
this.unbind = function (keyCode, modifiers) {
var keyCombo = getKeyCombo(keyCode, modifiers);
Expand All @@ -108,10 +113,11 @@ gui.KeyboardHandler = function KeyboardHandler() {
};

/**
* @param {!Event} e
* @param {!KeyboardEvent} e
*/
this.handleEvent = function (e) {
var keyCombo = getKeyCombo(e.keyCode, getModifiers(e)),
/**@type{function():boolean|undefined}*/
callback = bindings[keyCombo],
handled = false;

Expand Down
16 changes: 8 additions & 8 deletions webodf/lib/gui/SelectionMover.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ runtime.loadClass("odf.OdfUtils");
*/
gui.SelectionMover = function SelectionMover(cursor, rootNode) {
"use strict";
var odfUtils,
domUtils,
var odfUtils = new odf.OdfUtils(),
domUtils = new core.DomUtils(),
/**@type{!core.PositionIterator}*/
positionIterator,
cachedXOffset,
timeoutHandle,
Expand Down Expand Up @@ -98,8 +99,8 @@ gui.SelectionMover = function SelectionMover(cursor, rootNode) {
var rectangle,
simplifiedRectangle = null;

if (clientRectangles) {
rectangle = useRightEdge ? clientRectangles[clientRectangles.length - 1] : clientRectangles[0];
if (clientRectangles && clientRectangles.length > 0) {
rectangle = useRightEdge ? clientRectangles.item(clientRectangles.length - 1) : clientRectangles.item(0);
}

if (rectangle) {
Expand Down Expand Up @@ -151,7 +152,8 @@ gui.SelectionMover = function SelectionMover(cursor, rootNode) {
}

if (!rectangle) {
if (nodeType === Node.ELEMENT_NODE && container.childNodes[offset - 1]) {
if (nodeType === Node.ELEMENT_NODE && offset > 0
&& /**@type{!Element}*/(container).childNodes.length >= offset) {
// Fallback 2 - there are other child nodes directly preceding this offset. Try those
rectangle = getVisibleRect(container, offset - 1, range, true);
} else if (container.nodeType === Node.TEXT_NODE && offset > 0) {
Expand Down Expand Up @@ -201,7 +203,7 @@ gui.SelectionMover = function SelectionMover(cursor, rootNode) {
if (extend) {
c = iterator.container();
o = iterator.unfilteredDomOffset();
if (domUtils.comparePoints(selectionRange.startContainer, selectionRange.startOffset, c, o) === -1) {
if (domUtils.comparePoints(/**@type{!Node}*/(selectionRange.startContainer), selectionRange.startOffset, c, o) === -1) {
selectionRange.setStart(c, o);
isForwardSelection = false;
} else {
Expand Down Expand Up @@ -626,8 +628,6 @@ gui.SelectionMover = function SelectionMover(cursor, rootNode) {
};
};
function init() {
odfUtils = new odf.OdfUtils();
domUtils = new core.DomUtils();
positionIterator = gui.SelectionMover.createPositionIterator(rootNode);
var range = rootNode.ownerDocument.createRange();
range.setStart(positionIterator.container(), positionIterator.unfilteredDomOffset());
Expand Down
Loading

0 comments on commit ee4e747

Please sign in to comment.