diff --git a/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java b/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java index 7793a0dc5..a1f1bb269 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java +++ b/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java @@ -16,6 +16,9 @@ package org.teavm.dom.browser; import org.teavm.dom.html.HTMLDocument; +import org.teavm.dom.typedarrays.ArrayBuffer; +import org.teavm.dom.typedarrays.Int8Array; +import org.teavm.jso.JSConstructor; import org.teavm.jso.JSGlobal; import org.teavm.jso.JSObject; import org.teavm.jso.JSProperty; @@ -39,4 +42,25 @@ public interface Window extends JSGlobal { int setInterval(TimerHandler handler, int delay); void clearInterval(int timeoutId); + + @JSConstructor("ArrayBuffer") + ArrayBuffer createArrayBuffer(int length); + + @JSConstructor("Int8Array") + Int8Array createInt8Array(int length); + + @JSConstructor("Int8Array") + Int8Array createInt8Array(ArrayBuffer buffer); + + @JSConstructor("Int8Array") + Int8Array createInt8Array(ArrayBuffer buffer, int offset, int length); + + @JSConstructor("Uint8ClampedArray") + Int8Array createUint8ClampedArray(int length); + + @JSConstructor("Uint8ClampedArray") + Int8Array createUint8ClampedArray(ArrayBuffer buffer); + + @JSConstructor("Uint8ClampedArray") + Int8Array createUintClamped8Array(ArrayBuffer buffer, int offset, int length); } diff --git a/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasGradient.java b/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasGradient.java new file mode 100644 index 000000000..b374669fd --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasGradient.java @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.canvas; + +import org.teavm.jso.JSObject; + +/** + * + * @author Alexey Andreev + */ +public interface CanvasGradient extends JSObject { +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasImageSource.java b/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasImageSource.java new file mode 100644 index 000000000..8d0722827 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasImageSource.java @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.canvas; + +import org.teavm.jso.JSObject; + +/** + * + * @author Alexey Andreev + */ +public interface CanvasImageSource extends JSObject { +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasPattern.java b/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasPattern.java new file mode 100644 index 000000000..0e0a3aebe --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasPattern.java @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.canvas; + +import org.teavm.jso.JSObject; + +/** + * + * @author Alexey Andreev + */ +public interface CanvasPattern extends JSObject { +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasRenderingContext2D.java b/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasRenderingContext2D.java new file mode 100644 index 000000000..8b07bfa81 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/canvas/CanvasRenderingContext2D.java @@ -0,0 +1,268 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.canvas; + +import org.teavm.dom.core.Element; +import org.teavm.dom.html.HTMLCanvasElement; +import org.teavm.jso.JSArray; +import org.teavm.jso.JSArrayReader; +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface CanvasRenderingContext2D extends JSObject { + // Path + + void beginPath(); + + void closePath(); + + void arc(double x, double y, double radius, double startAngle, double endAngle, boolean anticlockwise); + + void arc(double x, double y, double radius, double startAngle, double endAngle); + + void arcTo(double x1, double y1, double x2, double y2, double radius); + + void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y); + + void clearRect(double x, double y, double width, double height); + + void moveTo(double x, double y); + + void lineTo(double x, double y); + + boolean isPointInPath(double x, double y); + + boolean isPointInStroke(double x, double y); + + void quadraticCurveTo(double cpx, double cpy, double x, double y); + + void rect(double x, double y, double width, double height); + + void scrollPathIntoView(); + + // Clip + + void clip(); + + // Creating images, gradients and patterns + + ImageData createImageData(double width, double height); + + CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1); + + CanvasPattern createPattern(CanvasImageSource image, String repetition); + + CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1); + + // Drawing images + + void drawImage(CanvasImageSource image, double dx, double dy); + + void drawImage(CanvasImageSource image, double dx, double dy, double dw, double dh); + + void drawImage(CanvasImageSource image, double sx, double sy, double sw, double sh, double dx, double dy, + double dw, double dh); + + // Focus ring + + boolean drawCustomFocusRing(Element element); + + void drawSystemFocusRing(Element element); + + // Line dash + + JSArrayReader getLineDash(); + + void setLineDash(JSArray lineDash); + + // Image data + + void putImageData(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, + double dirtyWidth, double dirtyHeight); + + void putImageData(ImageData imagedata, double dx, double dy); + + ImageData getImageData(double x, double y, double width, double height); + + // Text + + TextMetrics measureText(String text); + + // Fill + + void fill(); + + void fillRect(double x, double y, double width, double height); + + void fillText(String text, double x, double y, double maxWidth); + + void fillText(String text, double x, double y); + + // Sroke + + void stroke(); + + void strokeRect(double x, double y, double w, double h); + + void strokeText(String text, float x, float y, float maxWidth); + + void strokeText(String text, float x, float y); + + // Transformation + + void setTransform(double m11, double m12, double m21, double m22, double dx, double dy); + + void transform(double m11, double m12, double m21, double m22, double dx, double dy); + + void translate(double x, double y); + + void rotate(double angle); + + void scale(double x, double y); + + // Save and restore + + void save(); + + void restore(); + + // Fill properties + + @JSProperty + JSObject getFillStyle(); + + @JSProperty + void setFillStyle(String fillStyle); + + @JSProperty + void setFillStyle(CanvasGradient gradient); + + @JSProperty + void setFillStyle(CanvasPattern pattern); + + // Line properties + + @JSProperty + String getLineCap(); + + @JSProperty + void setLineCap(String lineCap); + + @JSProperty + float getLineDashOffset(); + + @JSProperty + void setLineDashOffset(float lineDashOffset); + + @JSProperty + String getLineJoin(); + + @JSProperty + void setLineJoin(String lineJoin); + + @JSProperty + double getLineWidth(); + + @JSProperty + void setLineWidth(double lineWidth); + + @JSProperty + double getMiterLimit(); + + @JSProperty + void setMiterLimit(double miterLimit); + + @JSProperty + JSObject getStrokeStyle(); + + @JSProperty + void setStrokeStyle(String fillStyle); + + @JSProperty + void setStrokeStyle(CanvasGradient gradient); + + @JSProperty + void setStrokeStyle(CanvasPattern pattern); + + // Alpha composite options + + @JSProperty + double getGlobalAlpha(); + + @JSProperty + void setGlobalAlpha(double globalAlpha); + + @JSProperty + String getGlobalCompositeOperation(); + + @JSProperty + void setGlobalCompositeOperation(String operation); + + // Shadow properties + + @JSProperty + double getShadowBlur(); + + @JSProperty + void setShadowBlur(double shadowBlur); + + @JSProperty + String getShadowColor(); + + @JSProperty + void setShadowColor(String shadowColor); + + @JSProperty + double getShadowOffsetX(); + + @JSProperty + void setShadowOffsetX(double offsetX); + + @JSProperty + double getShadowOffsetY(); + + @JSProperty + void setShadowOffsetY(double offsetY); + + // Text properties + + @JSProperty + String getFont(); + + @JSProperty + void setFont(String font); + + @JSProperty + String getTextAlign(); + + @JSProperty + void setTextAlign(String textAlign); + + @JSProperty + String getTextBaseline(); + + @JSProperty + void setTextBaseline(String textBaseline); + + // Misc. + + @JSProperty + HTMLCanvasElement getCanvas(); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/canvas/ImageData.java b/teavm-dom/src/main/java/org/teavm/dom/canvas/ImageData.java new file mode 100644 index 000000000..d9ba34dd5 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/canvas/ImageData.java @@ -0,0 +1,38 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.canvas; + +import org.teavm.dom.typedarrays.Uint8ClampedArray; +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface ImageData extends JSObject { + @JSProperty + int getWidth(); + + @JSProperty + int getHeight(); + + @JSProperty + Uint8ClampedArray getData(); + + @JSProperty + void setData(Uint8ClampedArray data); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/canvas/TextMetrics.java b/teavm-dom/src/main/java/org/teavm/dom/canvas/TextMetrics.java new file mode 100644 index 000000000..33932259f --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/canvas/TextMetrics.java @@ -0,0 +1,28 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.canvas; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface TextMetrics extends JSObject { + @JSProperty + int getWidth(); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/html/HTMLCanvasElement.java b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLCanvasElement.java new file mode 100644 index 000000000..a247b3fd7 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLCanvasElement.java @@ -0,0 +1,40 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.html; + +import org.teavm.dom.canvas.CanvasImageSource; +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface HTMLCanvasElement extends HTMLElement, CanvasImageSource { + @JSProperty + int getWidth(); + + @JSProperty + void setWidth(int width); + + @JSProperty + int getHeight(); + + @JSProperty + void setHeight(int height); + + JSObject getContext(String contextId); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/html/HTMLImageElement.java b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLImageElement.java new file mode 100644 index 000000000..cf2967719 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLImageElement.java @@ -0,0 +1,55 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.html; + +import org.teavm.dom.canvas.CanvasImageSource; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface HTMLImageElement extends HTMLElement, CanvasImageSource { + @JSProperty + String getAlt(); + + @JSProperty + void setAlt(String alt); + + @JSProperty + int getWidth(); + + @JSProperty + void setWidth(int width); + + @JSProperty + int getHeight(); + + @JSProperty + void setHeight(int height); + + @JSProperty + int getNaturalWidth(); + + @JSProperty + int getNaturalHeight(); + + @JSProperty + String getSrc(); + + @JSProperty + void setSrc(String src); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/typedarrays/ArrayBuffer.java b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/ArrayBuffer.java new file mode 100644 index 000000000..2f0e361bc --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/ArrayBuffer.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.typedarrays; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface ArrayBuffer extends JSObject { + @JSProperty + int getByteLength(); + + ArrayBuffer slice(int begin, int end); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/typedarrays/ArrayBufferView.java b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/ArrayBufferView.java new file mode 100644 index 000000000..8377e2b19 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/ArrayBufferView.java @@ -0,0 +1,34 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.typedarrays; + +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface ArrayBufferView extends JSObject { + @JSProperty + int getLength(); + + @JSProperty + int getByteLength(); + + @JSProperty + ArrayBuffer getBuffer(); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Int8Array.java b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Int8Array.java new file mode 100644 index 000000000..934d896fb --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Int8Array.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.typedarrays; + +import org.teavm.jso.JSIndexer; + +/** + * + * @author Alexey Andreev + */ +public interface Int8Array extends ArrayBufferView { + @JSIndexer + byte get(int index); + + @JSIndexer + void set(int index, byte value); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Uint8ClampedArray.java b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Uint8ClampedArray.java new file mode 100644 index 000000000..60dc2a426 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/typedarrays/Uint8ClampedArray.java @@ -0,0 +1,30 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.dom.typedarrays; + +import org.teavm.jso.JSIndexer; + +/** + * + * @author Alexey Andreev + */ +public interface Uint8ClampedArray extends ArrayBufferView { + @JSIndexer + short get(int index); + + @JSIndexer + void set(int index, int value); +}