|
@@ -2,145 +2,146 @@ |
2 |
2 |
|
|
3 |
3 |
|
import com.google.gwt.core.client.JsArrayInteger; |
4 |
4 |
|
import com.google.gwt.user.client.Element; |
|
5 |
+ |
|
5 |
6 |
|
import com.googlecode.mgwt.ui.client.MGWT; |
6 |
7 |
|
|
7 |
8 |
|
public class WebkitCssUtilImpl implements CssUtilImpl { |
8 |
9 |
|
|
9 |
|
- |
private boolean has3d; |
|
10 |
+ |
private boolean has3d; |
10 |
11 |
|
|
11 |
|
- |
public WebkitCssUtilImpl() { |
12 |
|
- |
has3d = _has3d(); |
13 |
|
- |
} |
14 |
|
- |
|
15 |
|
- |
@Override |
16 |
|
- |
public void translate(Element el, int x, int y) { |
17 |
|
- |
String cssText = null; |
18 |
|
- |
if (has3d() && !MGWT.getOsDetection().isDesktop()) { |
19 |
|
- |
cssText = "translate3d(" + x + "px, " + y + "px, 0px)"; |
20 |
|
- |
} else { |
21 |
|
- |
cssText = "translate( " + x + "px, " + y + "px )"; |
22 |
|
- |
} |
|
12 |
+ |
public WebkitCssUtilImpl() { |
|
13 |
+ |
has3d = _has3d(); |
|
14 |
+ |
} |
|
15 |
+ |
|
|
16 |
+ |
@Override |
|
17 |
+ |
public void translate(Element el, int x, int y) { |
|
18 |
+ |
String cssText = null; |
|
19 |
+ |
if (has3d() && !MGWT.getOsDetection().isDesktop()) { |
|
20 |
+ |
cssText = "translate3d(" + x + "px, " + y + "px, 0px)"; |
|
21 |
+ |
} else { |
|
22 |
+ |
cssText = "translate( " + x + "px, " + y + "px )"; |
|
23 |
+ |
} |
23 |
24 |
|
|
24 |
|
- |
_translate(el, cssText); |
|
25 |
+ |
_translate(el, cssText); |
25 |
26 |
|
|
26 |
|
- |
} |
|
27 |
+ |
} |
27 |
28 |
|
|
28 |
|
- |
@Override |
29 |
|
- |
public native void setDelay(Element el, int milliseconds) /*-{ |
|
29 |
+ |
@Override |
|
30 |
+ |
public native void setDelay(Element el, int milliseconds) /*-{ |
30 |
31 |
|
el.style.webkitTransitionDelay = milliseconds + "ms"; |
31 |
|
- |
}-*/; |
|
32 |
+ |
}-*/; |
32 |
33 |
|
|
33 |
|
- |
@Override |
34 |
|
- |
public native void setOpacity(Element el, double opacity) /*-{ |
|
34 |
+ |
@Override |
|
35 |
+ |
public native void setOpacity(Element el, double opacity) /*-{ |
35 |
36 |
|
el.style.opacity = opacity; |
36 |
37 |
|
|
37 |
|
- |
}-*/; |
|
38 |
+ |
}-*/; |
38 |
39 |
|
|
39 |
|
- |
@Override |
40 |
|
- |
public native void setDuration(Element el, int time) /*-{ |
|
40 |
+ |
@Override |
|
41 |
+ |
public native void setDuration(Element el, int time) /*-{ |
41 |
42 |
|
el.style.webkitTransitionDuration = time + "ms"; |
42 |
43 |
|
|
43 |
|
- |
}-*/; |
|
44 |
+ |
}-*/; |
44 |
45 |
|
|
45 |
|
- |
private native void _translate(Element el, String css)/*-{ |
|
46 |
+ |
private native void _translate(Element el, String css)/*-{ |
46 |
47 |
|
el.style.webkitTransform = css; |
47 |
|
- |
}-*/; |
|
48 |
+ |
}-*/; |
48 |
49 |
|
|
49 |
|
- |
@Override |
50 |
|
- |
public void rotate(Element el, int degree) { |
51 |
|
- |
if (MGWT.getOsDetection().isAndroid()) { |
52 |
|
- |
el.getStyle().setProperty("WebkitTransform", "rotate(" + degree + "deg)"); |
53 |
|
- |
// _translate(el, ); |
54 |
|
- |
} else { |
55 |
|
- |
el.getStyle().setProperty("WebkitTransform", "rotate(" + degree + "deg) translateZ(0)"); |
56 |
|
- |
// _translate(el,"rotate(" + degree + "deg) translateZ(0)"); |
57 |
|
- |
|
58 |
|
- |
} |
59 |
|
- |
|
60 |
|
- |
} |
61 |
|
- |
|
62 |
|
- |
@Override |
63 |
|
- |
public boolean hasTransform() { |
64 |
|
- |
// TODO maybe we need runtime checks for older devices, but for now this |
65 |
|
- |
// is okay! |
66 |
|
- |
return true; |
67 |
|
- |
} |
68 |
|
- |
|
69 |
|
- |
@Override |
70 |
|
- |
public boolean hasTransistionEndEvent() { |
71 |
|
- |
// TODO this is okay for android from 2.1 |
72 |
|
- |
// so we should be okay without a runtime check |
73 |
|
- |
return true; |
74 |
|
- |
} |
75 |
|
- |
|
76 |
|
- |
@Override |
77 |
|
- |
public boolean has3d() { |
78 |
|
- |
return has3d; |
79 |
|
- |
} |
|
50 |
+ |
@Override |
|
51 |
+ |
public void rotate(Element el, int degree) { |
|
52 |
+ |
if (MGWT.getOsDetection().isAndroid()) { |
|
53 |
+ |
el.getStyle().setProperty("WebkitTransform", "rotate(" + degree + "deg)"); |
|
54 |
+ |
// _translate(el, ); |
|
55 |
+ |
} else { |
|
56 |
+ |
el.getStyle().setProperty("WebkitTransform", "rotate(" + degree + "deg) translateZ(0)"); |
|
57 |
+ |
// _translate(el,"rotate(" + degree + "deg) translateZ(0)"); |
|
58 |
+ |
|
|
59 |
+ |
} |
|
60 |
+ |
|
|
61 |
+ |
} |
|
62 |
+ |
|
|
63 |
+ |
@Override |
|
64 |
+ |
public boolean hasTransform() { |
|
65 |
+ |
// TODO maybe we need runtime checks for older devices, but for now this |
|
66 |
+ |
// is okay! |
|
67 |
+ |
return true; |
|
68 |
+ |
} |
|
69 |
+ |
|
|
70 |
+ |
@Override |
|
71 |
+ |
public boolean hasTransistionEndEvent() { |
|
72 |
+ |
// TODO this is okay for android from 2.1 |
|
73 |
+ |
// so we should be okay without a runtime check |
|
74 |
+ |
return true; |
|
75 |
+ |
} |
|
76 |
+ |
|
|
77 |
+ |
@Override |
|
78 |
+ |
public boolean has3d() { |
|
79 |
+ |
return has3d; |
|
80 |
+ |
} |
80 |
81 |
|
|
81 |
|
- |
private static native boolean _has3d()/*-{ |
|
82 |
+ |
private static native boolean _has3d()/*-{ |
82 |
83 |
|
return ('WebKitCSSMatrix' in $wnd && 'm11' in new WebKitCSSMatrix()) |
83 |
|
- |
}-*/; |
|
84 |
+ |
}-*/; |
84 |
85 |
|
|
85 |
|
- |
@Override |
86 |
|
- |
public String getTransformProperty() { |
87 |
|
- |
return "-webkit-transform"; |
88 |
|
- |
} |
89 |
|
- |
|
90 |
|
- |
@Override |
91 |
|
- |
public int[] getPositionFromTransForm(Element element) { |
92 |
|
- |
JsArrayInteger array = getPositionFromTransform(element); |
93 |
|
- |
return new int[] { array.get(0), array.get(1) }; |
94 |
|
- |
} |
|
86 |
+ |
@Override |
|
87 |
+ |
public String getTransformProperty() { |
|
88 |
+ |
return "-webkit-transform"; |
|
89 |
+ |
} |
|
90 |
+ |
|
|
91 |
+ |
@Override |
|
92 |
+ |
public int[] getPositionFromTransForm(Element element) { |
|
93 |
+ |
JsArrayInteger array = getPositionFromTransform(element); |
|
94 |
+ |
return new int[] {array.get(0), array.get(1)}; |
|
95 |
+ |
} |
95 |
96 |
|
|
96 |
|
- |
private native JsArrayInteger getPositionFromTransform(Element el)/*-{ |
|
97 |
+ |
private native JsArrayInteger getPositionFromTransform(Element el)/*-{ |
97 |
98 |
|
var matrix = getComputedStyle(el, null)['webkitTransform'].replace( |
98 |
99 |
|
/[^0-9-.,]/g, '').split(','); |
99 |
100 |
|
var x = matrix[4] * 1; |
100 |
101 |
|
var y = matrix[5] * 1; |
101 |
102 |
|
return [ x, y ]; |
102 |
|
- |
}-*/; |
|
103 |
+ |
}-*/; |
103 |
104 |
|
|
104 |
|
- |
@Override |
105 |
|
- |
public native int getTopPositionFromCssPosition(Element element) /*-{ |
|
105 |
+ |
@Override |
|
106 |
+ |
public native int getTopPositionFromCssPosition(Element element) /*-{ |
106 |
107 |
|
return getComputedStyle(element, null).top.replace(/[^0-9-]/g, '') * 1; |
107 |
|
- |
}-*/; |
|
108 |
+ |
}-*/; |
108 |
109 |
|
|
109 |
|
- |
@Override |
110 |
|
- |
public native int getLeftPositionFromCssPosition(Element element)/*-{ |
|
110 |
+ |
@Override |
|
111 |
+ |
public native int getLeftPositionFromCssPosition(Element element)/*-{ |
111 |
112 |
|
return getComputedStyle(element, null).left.replace(/[^0-9-]/g, '') * 1; |
112 |
|
- |
}-*/; |
|
113 |
+ |
}-*/; |
113 |
114 |
|
|
114 |
|
- |
@Override |
115 |
|
- |
public native void resetTransform(Element el) /*-{ |
|
115 |
+ |
@Override |
|
116 |
+ |
public native void resetTransform(Element el) /*-{ |
116 |
117 |
|
el.style.webkitTransform = ""; |
117 |
|
- |
}-*/; |
|
118 |
+ |
}-*/; |
118 |
119 |
|
|
119 |
|
- |
@Override |
120 |
|
- |
public native void setTransistionProperty(Element element, String string) /*-{ |
|
120 |
+ |
@Override |
|
121 |
+ |
public native void setTransistionProperty(Element element, String string) /*-{ |
121 |
122 |
|
element.webkitTransitionProperty = string; |
122 |
|
- |
}-*/; |
|
123 |
+ |
}-*/; |
123 |
124 |
|
|
124 |
|
- |
@Override |
125 |
|
- |
public native void setTransFormOrigin(Element el, int x, int y) /*-{ |
|
125 |
+ |
@Override |
|
126 |
+ |
public native void setTransFormOrigin(Element el, int x, int y) /*-{ |
126 |
127 |
|
el.webkitTransformOrigin = x + " " + y; |
127 |
|
- |
}-*/; |
|
128 |
+ |
}-*/; |
128 |
129 |
|
|
129 |
|
- |
@Override |
130 |
|
- |
public native void setTransistionTimingFunction(Element element, String string) /*-{ |
|
130 |
+ |
@Override |
|
131 |
+ |
public native void setTransistionTimingFunction(Element element, String string) /*-{ |
131 |
132 |
|
el.webkitTransitionTimingFunction = string; |
132 |
|
- |
}-*/; |
|
133 |
+ |
}-*/; |
133 |
134 |
|
|
134 |
|
- |
@Override |
135 |
|
- |
public void setTranslateAndZoom(Element el, int x, int y, double scale) { |
136 |
|
- |
String cssText = null; |
137 |
|
- |
if (MGWT.getOsDetection().isAndroid() || MGWT.getOsDetection().isDesktop()) { |
138 |
|
- |
cssText = "translate( " + x + "px, " + y + "px ) scale( + " + scale + ")"; |
139 |
|
- |
} else { |
140 |
|
- |
cssText = "translate3d(" + x + "px, " + y + "px, 0px) scale( + " + scale + ")"; |
141 |
|
- |
} |
142 |
|
- |
el.getStyle().setProperty("WebkitTransform", cssText); |
|
135 |
+ |
@Override |
|
136 |
+ |
public void setTranslateAndZoom(Element el, int x, int y, double scale) { |
|
137 |
+ |
String cssText = null; |
|
138 |
+ |
if (MGWT.getOsDetection().isAndroid() || MGWT.getOsDetection().isDesktop()) { |
|
139 |
+ |
cssText = "translate( " + x + "px, " + y + "px ) scale(" + scale + ")"; |
|
140 |
+ |
} else { |
|
141 |
+ |
cssText = "translate3d(" + x + "px, " + y + "px, 0px) scale(" + scale + ")"; |
|
142 |
+ |
} |
|
143 |
+ |
el.getStyle().setProperty("WebkitTransform", cssText); |
143 |
144 |
|
|
144 |
|
- |
} |
|
145 |
+ |
} |
145 |
146 |
|
|
146 |
147 |
|
} |