diff options
author | Armen Kesablyan | 2012-06-20 15:16:30 -0700 |
---|---|---|
committer | Armen Kesablyan | 2012-06-20 15:16:30 -0700 |
commit | 65b989c7759af923fb9456d34bff89f91831ea1e (patch) | |
tree | e408be732a3eee71229bfc7dbf7cace998ce18de /node_modules/montage/ui/nearest-neighbor-component-search.js | |
parent | 38f571d1fdf02d36c3816637af7b2ca2493809da (diff) | |
parent | fc818d31de267d2b77fda3b3029ad38d48698be8 (diff) | |
download | ninja-65b989c7759af923fb9456d34bff89f91831ea1e.tar.gz |
Merge branch 'refs/heads/master' into binding
Conflicts:
node_modules/montage/ui/application.js
Signed-off-by: Armen Kesablyan <armen@motorola.com>
Diffstat (limited to 'node_modules/montage/ui/nearest-neighbor-component-search.js')
-rw-r--r-- | node_modules/montage/ui/nearest-neighbor-component-search.js | 232 |
1 files changed, 0 insertions, 232 deletions
diff --git a/node_modules/montage/ui/nearest-neighbor-component-search.js b/node_modules/montage/ui/nearest-neighbor-component-search.js deleted file mode 100644 index 8cc9e4c2..00000000 --- a/node_modules/montage/ui/nearest-neighbor-component-search.js +++ /dev/null | |||
@@ -1,232 +0,0 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage").Montage; | ||
8 | |||
9 | var NearestNeighborComponentSearch = exports.NearestNeighborComponentSearch = Montage.create(Montage, { | ||
10 | |||
11 | _componentList: { | ||
12 | enumerable: false, | ||
13 | value: null | ||
14 | }, | ||
15 | |||
16 | componentList: { | ||
17 | get: function () { | ||
18 | return this._componentList; | ||
19 | }, | ||
20 | set: function (value) { | ||
21 | var i; | ||
22 | |||
23 | this._componentList=value; | ||
24 | } | ||
25 | }, | ||
26 | |||
27 | _pointerPosition: { | ||
28 | enumerable: false, | ||
29 | value: null | ||
30 | }, | ||
31 | |||
32 | pointerPosition: { | ||
33 | get: function () { | ||
34 | return this._pointerPosition; | ||
35 | }, | ||
36 | set: function (value) { | ||
37 | var nearest = null; | ||
38 | |||
39 | this._pointerPosition=value; | ||
40 | if ((this._componentList)&&(this._componentList.length)) { | ||
41 | var target = value.target, | ||
42 | nearest; | ||
43 | |||
44 | for (var i=0; i<this._componentList.length; i++) { | ||
45 | this._componentList[i]._element.setAttribute("data-nn-index", i); | ||
46 | } | ||
47 | while ((target.tagName !== "BODY")&&!(nearest = target.getAttribute("data-nn-index"))) { | ||
48 | target = target.parentNode; | ||
49 | } | ||
50 | for (i=0; i<this._componentList.length; i++) { | ||
51 | this._componentList[i]._element.removeAttribute("data-nn-index", i); | ||
52 | } | ||
53 | } | ||
54 | if (nearest) { | ||
55 | this.nearestNeighborComponent = Number(nearest); | ||
56 | } else { | ||
57 | if (value && this._hasNearestNeighborComponentSearch && this._componentList) { | ||
58 | if (this._nearestNeighborComponentSearchMethod==="precise") { | ||
59 | this.nearestNeighborComponent=this._searchPreciseNearestNeighborComponent(); | ||
60 | } else { | ||
61 | this.nearestNeighborComponent=this._searchMidpointNearestNeighborComponent(); | ||
62 | } | ||
63 | } else { | ||
64 | this.nearestNeighborComponent=null; | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | }, | ||
69 | |||
70 | _hasNearestNeighborComponentSearch: { | ||
71 | enumerable: false, | ||
72 | value: true | ||
73 | }, | ||
74 | |||
75 | hasNearestNeighborComponentSearch: { | ||
76 | get: function () { | ||
77 | return this._hasNearestNeighborComponentSearch; | ||
78 | }, | ||
79 | set: function (value) { | ||
80 | if (value===true) { | ||
81 | this._hasNearestNeighborComponentSearch=true; | ||
82 | } else { | ||
83 | this._hasNearestNeighborComponentSearch=false; | ||
84 | } | ||
85 | } | ||
86 | }, | ||
87 | |||
88 | _nearestNeighborComponentSearchMethod: { | ||
89 | enumerable: false, | ||
90 | value: "precise" | ||
91 | }, | ||
92 | |||
93 | nearestNeighborComponentSearchMethod: { | ||
94 | get: function () { | ||
95 | return this._nearestNeighborComponentSearchMethod; | ||
96 | }, | ||
97 | set: function (value) { | ||
98 | if (value==="midpoint") { | ||
99 | this._nearestNeighborComponentSearchMethod=value; | ||
100 | } else { | ||
101 | this._nearestNeighborComponentSearchMethod="precise"; | ||
102 | } | ||
103 | } | ||
104 | }, | ||
105 | |||
106 | _pointToQuadSquaredDistance: { | ||
107 | enumerable: false, | ||
108 | value: function (pX, pY, q) { | ||
109 | var iDist, | ||
110 | i, j, u, x, y, div, | ||
111 | dist=1e20, a, b; | ||
112 | |||
113 | q[0]-=pX; q[1]-=pY; q[2]-=pX; q[3]-=pY; | ||
114 | q[4]-=pX; q[5]-=pY; q[6]-=pX; q[7]-=pY; | ||
115 | for (i=0; i<8; i+=2) { | ||
116 | j=(i+2)%8; | ||
117 | a=q[i+1]-q[j+1]; | ||
118 | b=q[j]-q[i]; | ||
119 | div=a*a+b*b; | ||
120 | if (div>1e-10) { | ||
121 | u=q[i+1]*a-q[i]*b; | ||
122 | if (u<0) { | ||
123 | x=q[i]; | ||
124 | y=q[i+1]; | ||
125 | } else if (u>div) { | ||
126 | x=q[i]+b; | ||
127 | y=q[i+1]-a; | ||
128 | } else { | ||
129 | u/=div; | ||
130 | x=q[i]+u*b; | ||
131 | y=q[i+1]-u*a; | ||
132 | } | ||
133 | iDist=x*x+y*y; | ||
134 | if (iDist<dist) { | ||
135 | dist=iDist; | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | return dist; | ||
140 | } | ||
141 | }, | ||
142 | |||
143 | _searchPreciseNearestNeighborComponent: { | ||
144 | enumerable: false, | ||
145 | value: function () { | ||
146 | var length=this._componentList.length, | ||
147 | point=new WebKitPoint(0, 0), | ||
148 | v0, v1, v2, v3, i, | ||
149 | quad=Array(8), | ||
150 | element, | ||
151 | iDistance, | ||
152 | distance=1e20, | ||
153 | pageX=this._pointerPosition.pageX, | ||
154 | pageY=this._pointerPosition.pageY, | ||
155 | convert=window.webkitConvertPointFromNodeToPage, | ||
156 | nearest=null, | ||
157 | index; | ||
158 | |||
159 | for (i=0; i<length; i++) { | ||
160 | element=this._componentList[i].element; | ||
161 | point.y=0; | ||
162 | v0=convert(element, point); | ||
163 | point.x=element.offsetWidth; | ||
164 | v1=convert(element, point); | ||
165 | point.y=element.offsetHeight; | ||
166 | v2=convert(element, point); | ||
167 | point.x=0; | ||
168 | v3=convert(element, point); | ||
169 | quad[0]=v0.x; | ||
170 | quad[1]=v0.y; | ||
171 | quad[2]=v1.x; | ||
172 | quad[3]=v1.y; | ||
173 | quad[4]=v2.x; | ||
174 | quad[5]=v2.y; | ||
175 | quad[6]=v3.x; | ||
176 | quad[7]=v3.y; | ||
177 | iDistance=this._pointToQuadSquaredDistance(pageX, pageY, quad); | ||
178 | if (iDistance < distance) { | ||
179 | distance=iDistance; | ||
180 | //nearest=this._componentList[i]; | ||
181 | nearest=i; | ||
182 | } | ||
183 | } | ||
184 | return nearest; | ||
185 | } | ||
186 | }, | ||
187 | |||
188 | _searchMidpointNearestNeighborComponent: { | ||
189 | enumerable: false, | ||
190 | value: function () { | ||
191 | var length=this._componentList.length, | ||
192 | point=new WebKitPoint(0, 0), | ||
193 | element, | ||
194 | iDistance, | ||
195 | distance=1e20, | ||
196 | v, i, | ||
197 | pageX=this._pointerPosition.pageX, | ||
198 | pageY=this._pointerPosition.pageY, | ||
199 | convert=window.webkitConvertPointFromNodeToPage, | ||
200 | nearest=null, | ||
201 | index; | ||
202 | |||
203 | for (i=0; i<length; i++) { | ||
204 | element=this._componentList[i].element; | ||
205 | point.x=element.offsetWidth>>1; | ||
206 | point.y=element.offsetHeight>>1; |