OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkView.h" | 8 #include "SkView.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 | 10 |
11 //////////////////////////////////////////////////////////////////////// | 11 //////////////////////////////////////////////////////////////////////// |
12 | 12 |
13 SkView::SkView(uint32_t flags) : fFlags(SkToU8(flags)) | 13 SkView::SkView(uint32_t flags) : fFlags(SkToU8(flags)) |
14 { | 14 { |
15 fWidth = fHeight = 0; | 15 fWidth = fHeight = 0; |
16 fLoc.set(0, 0); | 16 fLoc.set(0, 0); |
17 fParent = fFirstChild = fNextSibling = fPrevSibling = NULL; | 17 fParent = fFirstChild = fNextSibling = fPrevSibling = nullptr; |
18 fMatrix.setIdentity(); | 18 fMatrix.setIdentity(); |
19 fContainsFocus = 0; | 19 fContainsFocus = 0; |
20 } | 20 } |
21 | 21 |
22 SkView::~SkView() | 22 SkView::~SkView() |
23 { | 23 { |
24 this->detachAllChildren(); | 24 this->detachAllChildren(); |
25 } | 25 } |
26 | 26 |
27 void SkView::setFlags(uint32_t flags) | 27 void SkView::setFlags(uint32_t flags) |
28 { | 28 { |
29 SkASSERT((flags & ~kAllFlagMasks) == 0); | 29 SkASSERT((flags & ~kAllFlagMasks) == 0); |
30 | 30 |
31 uint32_t diff = fFlags ^ flags; | 31 uint32_t diff = fFlags ^ flags; |
32 | 32 |
33 if (diff & kVisible_Mask) | 33 if (diff & kVisible_Mask) |
34 this->inval(NULL); | 34 this->inval(nullptr); |
35 | 35 |
36 fFlags = SkToU8(flags); | 36 fFlags = SkToU8(flags); |
37 | 37 |
38 if (diff & kVisible_Mask) | 38 if (diff & kVisible_Mask) |
39 { | 39 { |
40 this->inval(NULL); | 40 this->inval(nullptr); |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 void SkView::setVisibleP(bool pred) | 44 void SkView::setVisibleP(bool pred) |
45 { | 45 { |
46 this->setFlags(SkSetClearShift(fFlags, pred, kVisible_Shift)); | 46 this->setFlags(SkSetClearShift(fFlags, pred, kVisible_Shift)); |
47 } | 47 } |
48 | 48 |
49 void SkView::setEnabledP(bool pred) | 49 void SkView::setEnabledP(bool pred) |
50 { | 50 { |
51 this->setFlags(SkSetClearShift(fFlags, pred, kEnabled_Shift)); | 51 this->setFlags(SkSetClearShift(fFlags, pred, kEnabled_Shift)); |
52 } | 52 } |
53 | 53 |
54 void SkView::setFocusableP(bool pred) | 54 void SkView::setFocusableP(bool pred) |
55 { | 55 { |
56 this->setFlags(SkSetClearShift(fFlags, pred, kFocusable_Shift)); | 56 this->setFlags(SkSetClearShift(fFlags, pred, kFocusable_Shift)); |
57 } | 57 } |
58 | 58 |
59 void SkView::setClipToBounds(bool pred) { | 59 void SkView::setClipToBounds(bool pred) { |
60 this->setFlags(SkSetClearShift(fFlags, !pred, kNoClip_Shift)); | 60 this->setFlags(SkSetClearShift(fFlags, !pred, kNoClip_Shift)); |
61 } | 61 } |
62 | 62 |
63 void SkView::setSize(SkScalar width, SkScalar height) | 63 void SkView::setSize(SkScalar width, SkScalar height) |
64 { | 64 { |
65 width = SkMaxScalar(0, width); | 65 width = SkMaxScalar(0, width); |
66 height = SkMaxScalar(0, height); | 66 height = SkMaxScalar(0, height); |
67 | 67 |
68 if (fWidth != width || fHeight != height) | 68 if (fWidth != width || fHeight != height) |
69 { | 69 { |
70 this->inval(NULL); | 70 this->inval(nullptr); |
71 fWidth = width; | 71 fWidth = width; |
72 fHeight = height; | 72 fHeight = height; |
73 this->inval(NULL); | 73 this->inval(nullptr); |
74 this->onSizeChange(); | 74 this->onSizeChange(); |
75 this->invokeLayout(); | 75 this->invokeLayout(); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 void SkView::setLoc(SkScalar x, SkScalar y) | 79 void SkView::setLoc(SkScalar x, SkScalar y) |
80 { | 80 { |
81 if (fLoc.fX != x || fLoc.fY != y) | 81 if (fLoc.fX != x || fLoc.fY != y) |
82 { | 82 { |
83 this->inval(NULL); | 83 this->inval(nullptr); |
84 fLoc.set(x, y); | 84 fLoc.set(x, y); |
85 this->inval(NULL); | 85 this->inval(nullptr); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 void SkView::offset(SkScalar dx, SkScalar dy) | 89 void SkView::offset(SkScalar dx, SkScalar dy) |
90 { | 90 { |
91 if (dx || dy) | 91 if (dx || dy) |
92 this->setLoc(fLoc.fX + dx, fLoc.fY + dy); | 92 this->setLoc(fLoc.fX + dx, fLoc.fY + dy); |
93 } | 93 } |
94 | 94 |
95 void SkView::setLocalMatrix(const SkMatrix& matrix) | 95 void SkView::setLocalMatrix(const SkMatrix& matrix) |
96 { | 96 { |
97 this->inval(NULL); | 97 this->inval(nullptr); |
98 fMatrix = matrix; | 98 fMatrix = matrix; |
99 this->inval(NULL); | 99 this->inval(nullptr); |
100 } | 100 } |
101 | 101 |
102 void SkView::draw(SkCanvas* canvas) | 102 void SkView::draw(SkCanvas* canvas) |
103 { | 103 { |
104 if (fWidth && fHeight && this->isVisible()) | 104 if (fWidth && fHeight && this->isVisible()) |
105 { | 105 { |
106 SkRect r; | 106 SkRect r; |
107 r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight); | 107 r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight); |
108 if (this->isClipToBounds() && | 108 if (this->isClipToBounds() && |
109 canvas->quickReject(r)) { | 109 canvas->quickReject(r)) { |
(...skipping 19 matching lines...) Expand all Loading... |
129 | 129 |
130 if (fParent) { | 130 if (fParent) { |
131 fParent->afterChild(this, canvas); | 131 fParent->afterChild(this, canvas); |
132 } | 132 } |
133 | 133 |
134 B2FIter iter(this); | 134 B2FIter iter(this); |
135 SkView* child; | 135 SkView* child; |
136 | 136 |
137 SkCanvas* childCanvas = this->beforeChildren(canvas); | 137 SkCanvas* childCanvas = this->beforeChildren(canvas); |
138 | 138 |
139 while ((child = iter.next()) != NULL) | 139 while ((child = iter.next()) != nullptr) |
140 child->draw(childCanvas); | 140 child->draw(childCanvas); |
141 | 141 |
142 this->afterChildren(canvas); | 142 this->afterChildren(canvas); |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 void SkView::inval(SkRect* rect) { | 146 void SkView::inval(SkRect* rect) { |
147 SkView* view = this; | 147 SkView* view = this; |
148 SkRect storage; | 148 SkRect storage; |
149 | 149 |
150 for (;;) { | 150 for (;;) { |
151 if (!view->isVisible()) { | 151 if (!view->isVisible()) { |
152 return; | 152 return; |
153 } | 153 } |
154 if (view->isClipToBounds()) { | 154 if (view->isClipToBounds()) { |
155 SkRect bounds; | 155 SkRect bounds; |
156 view->getLocalBounds(&bounds); | 156 view->getLocalBounds(&bounds); |
157 if (rect && !bounds.intersect(*rect)) { | 157 if (rect && !bounds.intersect(*rect)) { |
158 return; | 158 return; |
159 } | 159 } |
160 storage = bounds; | 160 storage = bounds; |
161 rect = &storage; | 161 rect = &storage; |
162 } | 162 } |
163 if (view->handleInval(rect)) { | 163 if (view->handleInval(rect)) { |
164 return; | 164 return; |
165 } | 165 } |
166 | 166 |
167 SkView* parent = view->fParent; | 167 SkView* parent = view->fParent; |
168 if (parent == NULL) { | 168 if (parent == nullptr) { |
169 return; | 169 return; |
170 } | 170 } |
171 | 171 |
172 if (rect) { | 172 if (rect) { |
173 rect->offset(view->fLoc.fX, view->fLoc.fY); | 173 rect->offset(view->fLoc.fX, view->fLoc.fY); |
174 } | 174 } |
175 view = parent; | 175 view = parent; |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 //////////////////////////////////////////////////////////////////////////// | 179 //////////////////////////////////////////////////////////////////////////// |
180 | 180 |
181 bool SkView::setFocusView(SkView* fv) | 181 bool SkView::setFocusView(SkView* fv) |
182 { | 182 { |
183 SkView* view = this; | 183 SkView* view = this; |
184 | 184 |
185 do { | 185 do { |
186 if (view->onSetFocusView(fv)) | 186 if (view->onSetFocusView(fv)) |
187 return true; | 187 return true; |
188 } while ((view = view->fParent) != NULL); | 188 } while ((view = view->fParent) != nullptr); |
189 return false; | 189 return false; |
190 } | 190 } |
191 | 191 |
192 SkView* SkView::getFocusView() const | 192 SkView* SkView::getFocusView() const |
193 { | 193 { |
194 SkView* focus = NULL; | 194 SkView* focus = nullptr; |
195 const SkView* view = this; | 195 const SkView* view = this; |
196 do { | 196 do { |
197 if (view->onGetFocusView(&focus)) | 197 if (view->onGetFocusView(&focus)) |
198 break; | 198 break; |
199 } while ((view = view->fParent) != NULL); | 199 } while ((view = view->fParent) != nullptr); |
200 return focus; | 200 return focus; |
201 } | 201 } |
202 | 202 |
203 bool SkView::hasFocus() const | 203 bool SkView::hasFocus() const |
204 { | 204 { |
205 return this == this->getFocusView(); | 205 return this == this->getFocusView(); |
206 } | 206 } |
207 | 207 |
208 bool SkView::acceptFocus() | 208 bool SkView::acceptFocus() |
209 { | 209 { |
210 return this->isFocusable() && this->setFocusView(this); | 210 return this->isFocusable() && this->setFocusView(this); |
211 } | 211 } |
212 | 212 |
213 /* | 213 /* |
214 Try to give focus to this view, or its children | 214 Try to give focus to this view, or its children |
215 */ | 215 */ |
216 SkView* SkView::acceptFocus(FocusDirection dir) | 216 SkView* SkView::acceptFocus(FocusDirection dir) |
217 { | 217 { |
218 if (dir == kNext_FocusDirection) | 218 if (dir == kNext_FocusDirection) |
219 { | 219 { |
220 if (this->acceptFocus()) | 220 if (this->acceptFocus()) |
221 return this; | 221 return this; |
222 | 222 |
223 B2FIter iter(this); | 223 B2FIter iter(this); |
224 SkView* child, *focus; | 224 SkView* child, *focus; |
225 while ((child = iter.next()) != NULL) | 225 while ((child = iter.next()) != nullptr) |
226 if ((focus = child->acceptFocus(dir)) != NULL) | 226 if ((focus = child->acceptFocus(dir)) != nullptr) |
227 return focus; | 227 return focus; |
228 } | 228 } |
229 else // prev | 229 else // prev |
230 { | 230 { |
231 F2BIter iter(this); | 231 F2BIter iter(this); |
232 SkView* child, *focus; | 232 SkView* child, *focus; |
233 while ((child = iter.next()) != NULL) | 233 while ((child = iter.next()) != nullptr) |
234 if ((focus = child->acceptFocus(dir)) != NULL) | 234 if ((focus = child->acceptFocus(dir)) != nullptr) |
235 return focus; | 235 return focus; |
236 | 236 |
237 if (this->acceptFocus()) | 237 if (this->acceptFocus()) |
238 return this; | 238 return this; |
239 } | 239 } |
240 | 240 |
241 return NULL; | 241 return nullptr; |
242 } | 242 } |
243 | 243 |
244 SkView* SkView::moveFocus(FocusDirection dir) | 244 SkView* SkView::moveFocus(FocusDirection dir) |
245 { | 245 { |
246 SkView* focus = this->getFocusView(); | 246 SkView* focus = this->getFocusView(); |
247 | 247 |
248 if (focus == NULL) | 248 if (focus == nullptr) |
249 { // start with the root | 249 { // start with the root |
250 focus = this; | 250 focus = this; |
251 while (focus->fParent) | 251 while (focus->fParent) |
252 focus = focus->fParent; | 252 focus = focus->fParent; |
253 } | 253 } |
254 | 254 |
255 SkView* child, *parent; | 255 SkView* child, *parent; |
256 | 256 |
257 if (dir == kNext_FocusDirection) | 257 if (dir == kNext_FocusDirection) |
258 { | 258 { |
259 parent = focus; | 259 parent = focus; |
260 child = focus->fFirstChild; | 260 child = focus->fFirstChild; |
261 if (child) | 261 if (child) |
262 goto FIRST_CHILD; | 262 goto FIRST_CHILD; |
263 else | 263 else |
264 goto NEXT_SIB; | 264 goto NEXT_SIB; |
265 | 265 |
266 do { | 266 do { |
267 while (child != parent->fFirstChild) | 267 while (child != parent->fFirstChild) |
268 { | 268 { |
269 FIRST_CHILD: | 269 FIRST_CHILD: |
270 if ((focus = child->acceptFocus(dir)) != NULL) | 270 if ((focus = child->acceptFocus(dir)) != nullptr) |
271 return focus; | 271 return focus; |
272 child = child->fNextSibling; | 272 child = child->fNextSibling; |
273 } | 273 } |
274 NEXT_SIB: | 274 NEXT_SIB: |
275 child = parent->fNextSibling; | 275 child = parent->fNextSibling; |
276 parent = parent->fParent; | 276 parent = parent->fParent; |
277 } while (parent != NULL); | 277 } while (parent != nullptr); |
278 } | 278 } |
279 else // prevfocus | 279 else // prevfocus |
280 { | 280 { |
281 parent = focus->fParent; | 281 parent = focus->fParent; |
282 if (parent == NULL) // we're the root | 282 if (parent == nullptr) // we're the root |
283 return focus->acceptFocus(dir); | 283 return focus->acceptFocus(dir); |
284 else | 284 else |
285 { | 285 { |
286 child = focus; | 286 child = focus; |
287 while (parent) | 287 while (parent) |
288 { | 288 { |
289 while (child != parent->fFirstChild) | 289 while (child != parent->fFirstChild) |
290 { | 290 { |
291 child = child->fPrevSibling; | 291 child = child->fPrevSibling; |
292 if ((focus = child->acceptFocus(dir)) != NULL) | 292 if ((focus = child->acceptFocus(dir)) != nullptr) |
293 return focus; | 293 return focus; |
294 } | 294 } |
295 if (parent->acceptFocus()) | 295 if (parent->acceptFocus()) |
296 return parent; | 296 return parent; |
297 | 297 |
298 child = parent; | 298 child = parent; |
299 parent = parent->fParent; | 299 parent = parent->fParent; |
300 } | 300 } |
301 } | 301 } |
302 } | 302 } |
303 return NULL; | 303 return nullptr; |
304 } | 304 } |
305 | 305 |
306 void SkView::onFocusChange(bool gainFocusP) | 306 void SkView::onFocusChange(bool gainFocusP) |
307 { | 307 { |
308 this->inval(NULL); | 308 this->inval(nullptr); |
309 } | 309 } |
310 | 310 |
311 //////////////////////////////////////////////////////////////////////////// | 311 //////////////////////////////////////////////////////////////////////////// |
312 | 312 |
313 SkView::Click::Click(SkView* target) | 313 SkView::Click::Click(SkView* target) |
314 { | 314 { |
315 SkASSERT(target); | 315 SkASSERT(target); |
316 fTargetID = target->getSinkID(); | 316 fTargetID = target->getSinkID(); |
317 fType = NULL; | 317 fType = nullptr; |
318 fWeOwnTheType = false; | 318 fWeOwnTheType = false; |
319 fOwner = NULL; | 319 fOwner = nullptr; |
320 } | 320 } |
321 | 321 |
322 SkView::Click::~Click() | 322 SkView::Click::~Click() |
323 { | 323 { |
324 this->resetType(); | 324 this->resetType(); |
325 } | 325 } |
326 | 326 |
327 void SkView::Click::resetType() | 327 void SkView::Click::resetType() |
328 { | 328 { |
329 if (fWeOwnTheType) | 329 if (fWeOwnTheType) |
330 { | 330 { |
331 sk_free(fType); | 331 sk_free(fType); |
332 fWeOwnTheType = false; | 332 fWeOwnTheType = false; |
333 } | 333 } |
334 fType = NULL; | 334 fType = nullptr; |
335 } | 335 } |
336 | 336 |
337 bool SkView::Click::isType(const char type[]) const | 337 bool SkView::Click::isType(const char type[]) const |
338 { | 338 { |
339 const char* t = fType; | 339 const char* t = fType; |
340 | 340 |
341 if (type == t) | 341 if (type == t) |
342 return true; | 342 return true; |
343 | 343 |
344 if (type == NULL) | 344 if (type == nullptr) |
345 type = ""; | 345 type = ""; |
346 if (t == NULL) | 346 if (t == nullptr) |
347 t = ""; | 347 t = ""; |
348 return !strcmp(t, type); | 348 return !strcmp(t, type); |
349 } | 349 } |
350 | 350 |
351 void SkView::Click::setType(const char type[]) | 351 void SkView::Click::setType(const char type[]) |
352 { | 352 { |
353 this->resetType(); | 353 this->resetType(); |
354 fType = (char*)type; | 354 fType = (char*)type; |
355 } | 355 } |
356 | 356 |
357 void SkView::Click::copyType(const char type[]) | 357 void SkView::Click::copyType(const char type[]) |
358 { | 358 { |
359 if (fType != type) | 359 if (fType != type) |
360 { | 360 { |
361 this->resetType(); | 361 this->resetType(); |
362 if (type) | 362 if (type) |
363 { | 363 { |
364 size_t len = strlen(type) + 1; | 364 size_t len = strlen(type) + 1; |
365 fType = (char*)sk_malloc_throw(len); | 365 fType = (char*)sk_malloc_throw(len); |
366 memcpy(fType, type, len); | 366 memcpy(fType, type, len); |
367 fWeOwnTheType = true; | 367 fWeOwnTheType = true; |
368 } | 368 } |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y, unsigned modi) { | 372 SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y, unsigned modi) { |
373 if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) { | 373 if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) { |
374 return NULL; | 374 return nullptr; |
375 } | 375 } |
376 | 376 |
377 if (this->onSendClickToChildren(x, y, modi)) { | 377 if (this->onSendClickToChildren(x, y, modi)) { |
378 F2BIter iter(this); | 378 F2BIter iter(this); |
379 SkView* child; | 379 SkView* child; |
380 | 380 |
381 while ((child = iter.next()) != NULL) | 381 while ((child = iter.next()) != nullptr) |
382 { | 382 { |
383 SkPoint p; | 383 SkPoint p; |
384 if (!child->globalToLocal(x, y, &p)) { | 384 if (!child->globalToLocal(x, y, &p)) { |
385 continue; | 385 continue; |
386 } | 386 } |
387 | 387 |
388 Click* click = child->findClickHandler(p.fX, p.fY, modi); | 388 Click* click = child->findClickHandler(p.fX, p.fY, modi); |
389 | 389 |
390 if (click) { | 390 if (click) { |
391 return click; | 391 return click; |
392 } | 392 } |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 return this->onFindClickHandler(x, y, modi); | 396 return this->onFindClickHandler(x, y, modi); |
397 } | 397 } |
398 | 398 |
399 void SkView::DoClickDown(Click* click, int x, int y, unsigned modi) | 399 void SkView::DoClickDown(Click* click, int x, int y, unsigned modi) |
400 { | 400 { |
401 SkASSERT(click); | 401 SkASSERT(click); |
402 | 402 |
403 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); | 403 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); |
404 if (NULL == target) { | 404 if (nullptr == target) { |
405 return; | 405 return; |
406 } | 406 } |
407 | 407 |
408 click->fIOrig.set(x, y); | 408 click->fIOrig.set(x, y); |
409 click->fICurr = click->fIPrev = click->fIOrig; | 409 click->fICurr = click->fIPrev = click->fIOrig; |
410 | 410 |
411 click->fOrig.iset(x, y); | 411 click->fOrig.iset(x, y); |
412 if (!target->globalToLocal(&click->fOrig)) { | 412 if (!target->globalToLocal(&click->fOrig)) { |
413 // no history to let us recover from this failure | 413 // no history to let us recover from this failure |
414 return; | 414 return; |
415 } | 415 } |
416 click->fPrev = click->fCurr = click->fOrig; | 416 click->fPrev = click->fCurr = click->fOrig; |
417 | 417 |
418 click->fState = Click::kDown_State; | 418 click->fState = Click::kDown_State; |
419 click->fModifierKeys = modi; | 419 click->fModifierKeys = modi; |
420 target->onClick(click); | 420 target->onClick(click); |
421 } | 421 } |
422 | 422 |
423 void SkView::DoClickMoved(Click* click, int x, int y, unsigned modi) | 423 void SkView::DoClickMoved(Click* click, int x, int y, unsigned modi) |
424 { | 424 { |
425 SkASSERT(click); | 425 SkASSERT(click); |
426 | 426 |
427 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); | 427 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); |
428 if (NULL == target) { | 428 if (nullptr == target) { |
429 return; | 429 return; |
430 } | 430 } |
431 | 431 |
432 click->fIPrev = click->fICurr; | 432 click->fIPrev = click->fICurr; |
433 click->fICurr.set(x, y); | 433 click->fICurr.set(x, y); |
434 | 434 |
435 click->fPrev = click->fCurr; | 435 click->fPrev = click->fCurr; |
436 click->fCurr.iset(x, y); | 436 click->fCurr.iset(x, y); |
437 if (!target->globalToLocal(&click->fCurr)) { | 437 if (!target->globalToLocal(&click->fCurr)) { |
438 // on failure pretend the mouse didn't move | 438 // on failure pretend the mouse didn't move |
439 click->fCurr = click->fPrev; | 439 click->fCurr = click->fPrev; |
440 } | 440 } |
441 | 441 |
442 click->fState = Click::kMoved_State; | 442 click->fState = Click::kMoved_State; |
443 click->fModifierKeys = modi; | 443 click->fModifierKeys = modi; |
444 target->onClick(click); | 444 target->onClick(click); |
445 } | 445 } |
446 | 446 |
447 void SkView::DoClickUp(Click* click, int x, int y, unsigned modi) | 447 void SkView::DoClickUp(Click* click, int x, int y, unsigned modi) |
448 { | 448 { |
449 SkASSERT(click); | 449 SkASSERT(click); |
450 | 450 |
451 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); | 451 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); |
452 if (NULL == target) { | 452 if (nullptr == target) { |
453 return; | 453 return; |
454 } | 454 } |
455 | 455 |
456 click->fIPrev = click->fICurr; | 456 click->fIPrev = click->fICurr; |
457 click->fICurr.set(x, y); | 457 click->fICurr.set(x, y); |
458 | 458 |
459 click->fPrev = click->fCurr; | 459 click->fPrev = click->fCurr; |
460 click->fCurr.iset(x, y); | 460 click->fCurr.iset(x, y); |
461 if (!target->globalToLocal(&click->fCurr)) { | 461 if (!target->globalToLocal(&click->fCurr)) { |
462 // on failure pretend the mouse didn't move | 462 // on failure pretend the mouse didn't move |
(...skipping 23 matching lines...) Expand all Loading... |
486 } | 486 } |
487 } | 487 } |
488 | 488 |
489 void SkView::onSizeChange() {} | 489 void SkView::onSizeChange() {} |
490 | 490 |
491 bool SkView::onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi) { | 491 bool SkView::onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi) { |
492 return true; | 492 return true; |
493 } | 493 } |
494 | 494 |
495 SkView::Click* SkView::onFindClickHandler(SkScalar x, SkScalar y, unsigned modi)
{ | 495 SkView::Click* SkView::onFindClickHandler(SkScalar x, SkScalar y, unsigned modi)
{ |
496 return NULL; | 496 return nullptr; |
497 } | 497 } |
498 | 498 |
499 bool SkView::onClick(Click*) { | 499 bool SkView::onClick(Click*) { |
500 return false; | 500 return false; |
501 } | 501 } |
502 | 502 |
503 bool SkView::handleInval(const SkRect*) { | 503 bool SkView::handleInval(const SkRect*) { |
504 return false; | 504 return false; |
505 } | 505 } |
506 | 506 |
507 ////////////////////////////////////////////////////////////////////// | 507 ////////////////////////////////////////////////////////////////////// |
508 | 508 |
509 void SkView::getLocalBounds(SkRect* bounds) const { | 509 void SkView::getLocalBounds(SkRect* bounds) const { |
510 if (bounds) { | 510 if (bounds) { |
511 bounds->set(0, 0, fWidth, fHeight); | 511 bounds->set(0, 0, fWidth, fHeight); |
512 } | 512 } |
513 } | 513 } |
514 | 514 |
515 ////////////////////////////////////////////////////////////////////// | 515 ////////////////////////////////////////////////////////////////////// |
516 ////////////////////////////////////////////////////////////////////// | 516 ////////////////////////////////////////////////////////////////////// |
517 | 517 |
518 void SkView::detachFromParent_NoLayout() { | 518 void SkView::detachFromParent_NoLayout() { |
519 this->validate(); | 519 this->validate(); |
520 if (fParent == NULL) { | 520 if (fParent == nullptr) { |
521 return; | 521 return; |
522 } | 522 } |
523 | 523 |
524 if (fContainsFocus) { | 524 if (fContainsFocus) { |
525 (void)this->setFocusView(NULL); | 525 (void)this->setFocusView(nullptr); |
526 } | 526 } |
527 | 527 |
528 this->inval(NULL); | 528 this->inval(nullptr); |
529 | 529 |
530 SkView* next = NULL; | 530 SkView* next = nullptr; |
531 | 531 |
532 if (fNextSibling != this) { // do we have any siblings | 532 if (fNextSibling != this) { // do we have any siblings |
533 fNextSibling->fPrevSibling = fPrevSibling; | 533 fNextSibling->fPrevSibling = fPrevSibling; |
534 fPrevSibling->fNextSibling = fNextSibling; | 534 fPrevSibling->fNextSibling = fNextSibling; |
535 next = fNextSibling; | 535 next = fNextSibling; |
536 } | 536 } |
537 | 537 |
538 if (fParent->fFirstChild == this) { | 538 if (fParent->fFirstChild == this) { |
539 fParent->fFirstChild = next; | 539 fParent->fFirstChild = next; |
540 } | 540 } |
541 | 541 |
542 fParent = fNextSibling = fPrevSibling = NULL; | 542 fParent = fNextSibling = fPrevSibling = nullptr; |
543 | 543 |
544 this->validate(); | 544 this->validate(); |
545 this->unref(); | 545 this->unref(); |
546 } | 546 } |
547 | 547 |
548 void SkView::detachFromParent() { | 548 void SkView::detachFromParent() { |
549 this->validate(); | 549 this->validate(); |
550 SkView* parent = fParent; | 550 SkView* parent = fParent; |
551 | 551 |
552 if (parent) { | 552 if (parent) { |
553 this->detachFromParent_NoLayout(); | 553 this->detachFromParent_NoLayout(); |
554 parent->invokeLayout(); | 554 parent->invokeLayout(); |
555 } | 555 } |
556 } | 556 } |
557 | 557 |
558 SkView* SkView::attachChildToBack(SkView* child) { | 558 SkView* SkView::attachChildToBack(SkView* child) { |
559 this->validate(); | 559 this->validate(); |
560 SkASSERT(child != this); | 560 SkASSERT(child != this); |
561 | 561 |
562 if (child == NULL || fFirstChild == child) | 562 if (child == nullptr || fFirstChild == child) |
563 goto DONE; | 563 goto DONE; |
564 | 564 |
565 child->ref(); | 565 child->ref(); |
566 child->detachFromParent_NoLayout(); | 566 child->detachFromParent_NoLayout(); |
567 | 567 |
568 if (fFirstChild == NULL) { | 568 if (fFirstChild == nullptr) { |
569 child->fNextSibling = child; | 569 child->fNextSibling = child; |
570 child->fPrevSibling = child; | 570 child->fPrevSibling = child; |
571 } else { | 571 } else { |
572 child->fNextSibling = fFirstChild; | 572 child->fNextSibling = fFirstChild; |
573 child->fPrevSibling = fFirstChild->fPrevSibling; | 573 child->fPrevSibling = fFirstChild->fPrevSibling; |
574 fFirstChild->fPrevSibling->fNextSibling = child; | 574 fFirstChild->fPrevSibling->fNextSibling = child; |
575 fFirstChild->fPrevSibling = child; | 575 fFirstChild->fPrevSibling = child; |
576 } | 576 } |
577 | 577 |
578 fFirstChild = child; | 578 fFirstChild = child; |
579 child->fParent = this; | 579 child->fParent = this; |
580 child->inval(NULL); | 580 child->inval(nullptr); |
581 | 581 |
582 this->validate(); | 582 this->validate(); |
583 this->invokeLayout(); | 583 this->invokeLayout(); |
584 DONE: | 584 DONE: |
585 return child; | 585 return child; |
586 } | 586 } |
587 | 587 |
588 SkView* SkView::attachChildToFront(SkView* child) { | 588 SkView* SkView::attachChildToFront(SkView* child) { |
589 this->validate(); | 589 this->validate(); |
590 SkASSERT(child != this); | 590 SkASSERT(child != this); |
591 | 591 |
592 if (child == NULL || (fFirstChild && fFirstChild->fPrevSibling == child)) | 592 if (child == nullptr || (fFirstChild && fFirstChild->fPrevSibling == child)) |
593 goto DONE; | 593 goto DONE; |
594 | 594 |
595 child->ref(); | 595 child->ref(); |
596 child->detachFromParent_NoLayout(); | 596 child->detachFromParent_NoLayout(); |
597 | 597 |
598 if (fFirstChild == NULL) { | 598 if (fFirstChild == nullptr) { |
599 fFirstChild = child; | 599 fFirstChild = child; |
600 child->fNextSibling = child; | 600 child->fNextSibling = child; |
601 child->fPrevSibling = child; | 601 child->fPrevSibling = child; |
602 } else { | 602 } else { |
603 child->fNextSibling = fFirstChild; | 603 child->fNextSibling = fFirstChild; |
604 child->fPrevSibling = fFirstChild->fPrevSibling; | 604 child->fPrevSibling = fFirstChild->fPrevSibling; |
605 fFirstChild->fPrevSibling->fNextSibling = child; | 605 fFirstChild->fPrevSibling->fNextSibling = child; |
606 fFirstChild->fPrevSibling = child; | 606 fFirstChild->fPrevSibling = child; |
607 } | 607 } |
608 | 608 |
609 child->fParent = this; | 609 child->fParent = this; |
610 child->inval(NULL); | 610 child->inval(nullptr); |
611 | 611 |
612 this->validate(); | 612 this->validate(); |
613 this->invokeLayout(); | 613 this->invokeLayout(); |
614 DONE: | 614 DONE: |
615 return child; | 615 return child; |
616 } | 616 } |
617 | 617 |
618 void SkView::detachAllChildren() { | 618 void SkView::detachAllChildren() { |
619 this->validate(); | 619 this->validate(); |
620 while (fFirstChild) | 620 while (fFirstChild) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 | 692 |
693 void SkView::onPostInflate(const SkTDict<SkView*>&) { | 693 void SkView::onPostInflate(const SkTDict<SkView*>&) { |
694 // override in subclass as needed | 694 // override in subclass as needed |
695 } | 695 } |
696 | 696 |
697 void SkView::postInflate(const SkTDict<SkView*>& dict) { | 697 void SkView::postInflate(const SkTDict<SkView*>& dict) { |
698 this->onPostInflate(dict); | 698 this->onPostInflate(dict); |
699 | 699 |
700 B2FIter iter(this); | 700 B2FIter iter(this); |
701 SkView* child; | 701 SkView* child; |
702 while ((child = iter.next()) != NULL) | 702 while ((child = iter.next()) != nullptr) |
703 child->postInflate(dict); | 703 child->postInflate(dict); |
704 } | 704 } |
705 | 705 |
706 ////////////////////////////////////////////////////////////////// | 706 ////////////////////////////////////////////////////////////////// |
707 | 707 |
708 SkView* SkView::sendEventToParents(const SkEvent& evt) { | 708 SkView* SkView::sendEventToParents(const SkEvent& evt) { |
709 SkView* parent = fParent; | 709 SkView* parent = fParent; |
710 | 710 |
711 while (parent) { | 711 while (parent) { |
712 if (parent->doEvent(evt)) { | 712 if (parent->doEvent(evt)) { |
713 return parent; | 713 return parent; |
714 } | 714 } |
715 parent = parent->fParent; | 715 parent = parent->fParent; |
716 } | 716 } |
717 return NULL; | 717 return nullptr; |
718 } | 718 } |
719 | 719 |
720 SkView* SkView::sendQueryToParents(SkEvent* evt) { | 720 SkView* SkView::sendQueryToParents(SkEvent* evt) { |
721 SkView* parent = fParent; | 721 SkView* parent = fParent; |
722 | 722 |
723 while (parent) { | 723 while (parent) { |
724 if (parent->doQuery(evt)) { | 724 if (parent->doQuery(evt)) { |
725 return parent; | 725 return parent; |
726 } | 726 } |
727 parent = parent->fParent; | 727 parent = parent->fParent; |
728 } | 728 } |
729 return NULL; | 729 return nullptr; |
730 } | 730 } |
731 | 731 |
732 ////////////////////////////////////////////////////////////////// | 732 ////////////////////////////////////////////////////////////////// |
733 ////////////////////////////////////////////////////////////////// | 733 ////////////////////////////////////////////////////////////////// |
734 | 734 |
735 SkView::F2BIter::F2BIter(const SkView* parent) { | 735 SkView::F2BIter::F2BIter(const SkView* parent) { |
736 fFirstChild = parent ? parent->fFirstChild : NULL; | 736 fFirstChild = parent ? parent->fFirstChild : nullptr; |
737 fChild = fFirstChild ? fFirstChild->fPrevSibling : NULL; | 737 fChild = fFirstChild ? fFirstChild->fPrevSibling : nullptr; |
738 } | 738 } |
739 | 739 |
740 SkView* SkView::F2BIter::next() { | 740 SkView* SkView::F2BIter::next() { |
741 SkView* curr = fChild; | 741 SkView* curr = fChild; |
742 | 742 |
743 if (fChild) { | 743 if (fChild) { |
744 if (fChild == fFirstChild) { | 744 if (fChild == fFirstChild) { |
745 fChild = NULL; | 745 fChild = nullptr; |
746 } else { | 746 } else { |
747 fChild = fChild->fPrevSibling; | 747 fChild = fChild->fPrevSibling; |
748 } | 748 } |
749 } | 749 } |
750 return curr; | 750 return curr; |
751 } | 751 } |
752 | 752 |
753 SkView::B2FIter::B2FIter(const SkView* parent) { | 753 SkView::B2FIter::B2FIter(const SkView* parent) { |
754 fFirstChild = parent ? parent->fFirstChild : NULL; | 754 fFirstChild = parent ? parent->fFirstChild : nullptr; |
755 fChild = fFirstChild; | 755 fChild = fFirstChild; |
756 } | 756 } |
757 | 757 |
758 SkView* SkView::B2FIter::next() { | 758 SkView* SkView::B2FIter::next() { |
759 SkView* curr = fChild; | 759 SkView* curr = fChild; |
760 | 760 |
761 if (fChild) { | 761 if (fChild) { |
762 SkView* next = fChild->fNextSibling; | 762 SkView* next = fChild->fNextSibling; |
763 if (next == fFirstChild) | 763 if (next == fFirstChild) |
764 next = NULL; | 764 next = nullptr; |
765 fChild = next; | 765 fChild = next; |
766 } | 766 } |
767 return curr; | 767 return curr; |
768 } | 768 } |
769 | 769 |
770 ////////////////////////////////////////////////////////////////// | 770 ////////////////////////////////////////////////////////////////// |
771 ////////////////////////////////////////////////////////////////// | 771 ////////////////////////////////////////////////////////////////// |
772 | 772 |
773 #ifdef SK_DEBUG | 773 #ifdef SK_DEBUG |
774 | 774 |
775 void SkView::validate() const { | 775 void SkView::validate() const { |
776 // SkASSERT(this->getRefCnt() > 0 && this->getRefCnt() < 100); | 776 // SkASSERT(this->getRefCnt() > 0 && this->getRefCnt() < 100); |
777 if (fParent) { | 777 if (fParent) { |
778 SkASSERT(fNextSibling); | 778 SkASSERT(fNextSibling); |
779 SkASSERT(fPrevSibling); | 779 SkASSERT(fPrevSibling); |
780 } else { | 780 } else { |
781 bool nextNull = NULL == fNextSibling; | 781 bool nextNull = nullptr == fNextSibling; |
782 bool prevNull = NULL == fNextSibling; | 782 bool prevNull = nullptr == fNextSibling; |
783 SkASSERT(nextNull == prevNull); | 783 SkASSERT(nextNull == prevNull); |
784 } | 784 } |
785 } | 785 } |
786 | 786 |
787 static inline void show_if_nonzero(const char name[], SkScalar value) | 787 static inline void show_if_nonzero(const char name[], SkScalar value) |
788 { | 788 { |
789 if (value) | 789 if (value) |
790 SkDebugf("%s=\"%g\"", name, value/65536.); | 790 SkDebugf("%s=\"%g\"", name, value/65536.); |
791 } | 791 } |
792 | 792 |
(...skipping 12 matching lines...) Expand all Loading... |
805 show_if_nonzero(" y", view->locY()); | 805 show_if_nonzero(" y", view->locY()); |
806 show_if_nonzero(" width", view->width()); | 806 show_if_nonzero(" width", view->width()); |
807 show_if_nonzero(" height", view->height()); | 807 show_if_nonzero(" height", view->height()); |
808 | 808 |
809 if (recurse) | 809 if (recurse) |
810 { | 810 { |
811 SkView::B2FIter iter(view); | 811 SkView::B2FIter iter(view); |
812 SkView* child; | 812 SkView* child; |
813 bool noChildren = true; | 813 bool noChildren = true; |
814 | 814 |
815 while ((child = iter.next()) != NULL) | 815 while ((child = iter.next()) != nullptr) |
816 { | 816 { |
817 if (noChildren) | 817 if (noChildren) |
818 SkDebugf(">\n"); | 818 SkDebugf(">\n"); |
819 noChildren = false; | 819 noChildren = false; |
820 dumpview(child, level + 1, true); | 820 dumpview(child, level + 1, true); |
821 } | 821 } |
822 | 822 |
823 if (!noChildren) | 823 if (!noChildren) |
824 { | 824 { |
825 tab(level); | 825 tab(level); |
826 SkDebugf("</view>\n"); | 826 SkDebugf("</view>\n"); |
827 } | 827 } |
828 else | 828 else |
829 goto ONELINER; | 829 goto ONELINER; |
830 } | 830 } |
831 else | 831 else |
832 { | 832 { |
833 ONELINER: | 833 ONELINER: |
834 SkDebugf(" />\n"); | 834 SkDebugf(" />\n"); |
835 } | 835 } |
836 } | 836 } |
837 | 837 |
838 void SkView::dump(bool recurse) const | 838 void SkView::dump(bool recurse) const |
839 { | 839 { |
840 dumpview(this, 0, recurse); | 840 dumpview(this, 0, recurse); |
841 } | 841 } |
842 | 842 |
843 #endif | 843 #endif |
OLD | NEW |