Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1613)

Side by Side Diff: src/views/SkView.cpp

Issue 1548223002: remove cruft from SkTypes.h, including SkBool (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/utils/SkInterpolator.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1
2 /* 1 /*
3 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
4 * 3 *
5 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
7
8 #include "SkView.h" 8 #include "SkView.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 10
11 static inline uint32_t SkSetClearShift(uint32_t bits, bool cond, unsigned shift) {
12 SkASSERT((int)cond == 0 || (int)cond == 1);
13 return (bits & ~(1 << shift)) | ((int)cond << shift);
14 }
15
11 //////////////////////////////////////////////////////////////////////// 16 ////////////////////////////////////////////////////////////////////////
12 17
13 SkView::SkView(uint32_t flags) : fFlags(SkToU8(flags)) 18 SkView::SkView(uint32_t flags) : fFlags(SkToU8(flags)) {
14 {
15 fWidth = fHeight = 0; 19 fWidth = fHeight = 0;
16 fLoc.set(0, 0); 20 fLoc.set(0, 0);
17 fParent = fFirstChild = fNextSibling = fPrevSibling = nullptr; 21 fParent = fFirstChild = fNextSibling = fPrevSibling = nullptr;
18 fMatrix.setIdentity(); 22 fMatrix.setIdentity();
19 fContainsFocus = 0; 23 fContainsFocus = 0;
20 } 24 }
21 25
22 SkView::~SkView() 26 SkView::~SkView() {
23 {
24 this->detachAllChildren(); 27 this->detachAllChildren();
25 } 28 }
26 29
27 void SkView::setFlags(uint32_t flags) 30 void SkView::setFlags(uint32_t flags) {
28 {
29 SkASSERT((flags & ~kAllFlagMasks) == 0); 31 SkASSERT((flags & ~kAllFlagMasks) == 0);
30 32
31 uint32_t diff = fFlags ^ flags; 33 uint32_t diff = fFlags ^ flags;
32 34
33 if (diff & kVisible_Mask) 35 if (diff & kVisible_Mask)
34 this->inval(nullptr); 36 this->inval(nullptr);
35 37
36 fFlags = SkToU8(flags); 38 fFlags = SkToU8(flags);
37 39
38 if (diff & kVisible_Mask) 40 if (diff & kVisible_Mask) {
39 {
40 this->inval(nullptr); 41 this->inval(nullptr);
41 } 42 }
42 } 43 }
43 44
44 void SkView::setVisibleP(bool pred) 45 void SkView::setVisibleP(bool pred) {
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 {
51 this->setFlags(SkSetClearShift(fFlags, pred, kEnabled_Shift)); 50 this->setFlags(SkSetClearShift(fFlags, pred, kEnabled_Shift));
52 } 51 }
53 52
54 void SkView::setFocusableP(bool pred) 53 void SkView::setFocusableP(bool pred) {
55 {
56 this->setFlags(SkSetClearShift(fFlags, pred, kFocusable_Shift)); 54 this->setFlags(SkSetClearShift(fFlags, pred, kFocusable_Shift));
57 } 55 }
58 56
59 void SkView::setClipToBounds(bool pred) { 57 void SkView::setClipToBounds(bool pred) {
60 this->setFlags(SkSetClearShift(fFlags, !pred, kNoClip_Shift)); 58 this->setFlags(SkSetClearShift(fFlags, !pred, kNoClip_Shift));
61 } 59 }
62 60
63 void SkView::setSize(SkScalar width, SkScalar height) 61 void SkView::setSize(SkScalar width, SkScalar height) {
64 {
65 width = SkMaxScalar(0, width); 62 width = SkMaxScalar(0, width);
66 height = SkMaxScalar(0, height); 63 height = SkMaxScalar(0, height);
67 64
68 if (fWidth != width || fHeight != height) 65 if (fWidth != width || fHeight != height)
69 { 66 {
70 this->inval(nullptr); 67 this->inval(nullptr);
71 fWidth = width; 68 fWidth = width;
72 fHeight = height; 69 fHeight = height;
73 this->inval(nullptr); 70 this->inval(nullptr);
74 this->onSizeChange(); 71 this->onSizeChange();
75 this->invokeLayout(); 72 this->invokeLayout();
76 } 73 }
77 } 74 }
78 75
79 void SkView::setLoc(SkScalar x, SkScalar y) 76 void SkView::setLoc(SkScalar x, SkScalar y) {
80 { 77 if (fLoc.fX != x || fLoc.fY != y) {
81 if (fLoc.fX != x || fLoc.fY != y)
82 {
83 this->inval(nullptr); 78 this->inval(nullptr);
84 fLoc.set(x, y); 79 fLoc.set(x, y);
85 this->inval(nullptr); 80 this->inval(nullptr);
86 } 81 }
87 } 82 }
88 83
89 void SkView::offset(SkScalar dx, SkScalar dy) 84 void SkView::offset(SkScalar dx, SkScalar dy) {
90 {
91 if (dx || dy) 85 if (dx || dy)
92 this->setLoc(fLoc.fX + dx, fLoc.fY + dy); 86 this->setLoc(fLoc.fX + dx, fLoc.fY + dy);
93 } 87 }
94 88
95 void SkView::setLocalMatrix(const SkMatrix& matrix) 89 void SkView::setLocalMatrix(const SkMatrix& matrix) {
96 {
97 this->inval(nullptr); 90 this->inval(nullptr);
98 fMatrix = matrix; 91 fMatrix = matrix;
99 this->inval(nullptr); 92 this->inval(nullptr);
100 } 93 }
101 94
102 void SkView::draw(SkCanvas* canvas) 95 void SkView::draw(SkCanvas* canvas) {
103 { 96 if (fWidth && fHeight && this->isVisible()) {
104 if (fWidth && fHeight && this->isVisible())
105 {
106 SkRect r; 97 SkRect r;
107 r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight); 98 r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight);
108 if (this->isClipToBounds() && 99 if (this->isClipToBounds() && canvas->quickReject(r)) {
109 canvas->quickReject(r)) { 100 return;
110 return;
111 } 101 }
112 102
113 SkAutoCanvasRestore as(canvas, true); 103 SkAutoCanvasRestore as(canvas, true);
114 104
115 if (this->isClipToBounds()) { 105 if (this->isClipToBounds()) {
116 canvas->clipRect(r); 106 canvas->clipRect(r);
117 } 107 }
118 108
119 canvas->translate(fLoc.fX, fLoc.fY); 109 canvas->translate(fLoc.fX, fLoc.fY);
120 canvas->concat(fMatrix); 110 canvas->concat(fMatrix);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 161
172 if (rect) { 162 if (rect) {
173 rect->offset(view->fLoc.fX, view->fLoc.fY); 163 rect->offset(view->fLoc.fX, view->fLoc.fY);
174 } 164 }
175 view = parent; 165 view = parent;
176 } 166 }
177 } 167 }
178 168
179 //////////////////////////////////////////////////////////////////////////// 169 ////////////////////////////////////////////////////////////////////////////
180 170
181 bool SkView::setFocusView(SkView* fv) 171 bool SkView::setFocusView(SkView* fv) {
182 {
183 SkView* view = this; 172 SkView* view = this;
184 173
185 do { 174 do {
186 if (view->onSetFocusView(fv)) 175 if (view->onSetFocusView(fv)) {
187 return true; 176 return true;
177 }
188 } while ((view = view->fParent) != nullptr); 178 } while ((view = view->fParent) != nullptr);
189 return false; 179 return false;
190 } 180 }
191 181
192 SkView* SkView::getFocusView() const 182 SkView* SkView::getFocusView() const {
193 { 183 SkView* focus = nullptr;
194 SkView* focus = nullptr; 184 const SkView* view = this;
195 const SkView* view = this;
196 do { 185 do {
197 if (view->onGetFocusView(&focus)) 186 if (view->onGetFocusView(&focus)) {
198 break; 187 break;
188 }
199 } while ((view = view->fParent) != nullptr); 189 } while ((view = view->fParent) != nullptr);
200 return focus; 190 return focus;
201 } 191 }
202 192
203 bool SkView::hasFocus() const 193 bool SkView::hasFocus() const {
204 {
205 return this == this->getFocusView(); 194 return this == this->getFocusView();
206 } 195 }
207 196
208 bool SkView::acceptFocus() 197 bool SkView::acceptFocus() {
209 {
210 return this->isFocusable() && this->setFocusView(this); 198 return this->isFocusable() && this->setFocusView(this);
211 } 199 }
212 200
213 /* 201 /*
214 Try to give focus to this view, or its children 202 Try to give focus to this view, or its children
215 */ 203 */
216 SkView* SkView::acceptFocus(FocusDirection dir) 204 SkView* SkView::acceptFocus(FocusDirection dir) {
217 { 205 if (dir == kNext_FocusDirection) {
218 if (dir == kNext_FocusDirection) 206 if (this->acceptFocus()) {
219 {
220 if (this->acceptFocus())
221 return this; 207 return this;
222 208 }
223 B2FIter iter(this); 209 B2FIter iter(this);
224 SkView* child, *focus; 210 SkView* child, *focus;
225 while ((child = iter.next()) != nullptr) 211 while ((child = iter.next()) != nullptr) {
226 if ((focus = child->acceptFocus(dir)) != nullptr) 212 if ((focus = child->acceptFocus(dir)) != nullptr) {
227 return focus; 213 return focus;
228 } 214 }
229 else // prev 215 }
230 { 216 } else { // prev
231 F2BIter iter(this); 217 F2BIter iter(this);
232 SkView* child, *focus; 218 SkView* child, *focus;
233 while ((child = iter.next()) != nullptr) 219 while ((child = iter.next()) != nullptr) {
234 if ((focus = child->acceptFocus(dir)) != nullptr) 220 if ((focus = child->acceptFocus(dir)) != nullptr) {
235 return focus; 221 return focus;
236 222 }
237 if (this->acceptFocus()) 223 }
224 if (this->acceptFocus()) {
238 return this; 225 return this;
226 }
239 } 227 }
240
241 return nullptr; 228 return nullptr;
242 } 229 }
243 230
244 SkView* SkView::moveFocus(FocusDirection dir) 231 SkView* SkView::moveFocus(FocusDirection dir) {
245 {
246 SkView* focus = this->getFocusView(); 232 SkView* focus = this->getFocusView();
247 233
248 if (focus == nullptr) 234 if (focus == nullptr) { // start with the root
249 { // start with the root
250 focus = this; 235 focus = this;
251 while (focus->fParent) 236 while (focus->fParent) {
252 focus = focus->fParent; 237 focus = focus->fParent;
238 }
253 } 239 }
254 240
255 SkView* child, *parent; 241 SkView* child, *parent;
256 242
257 if (dir == kNext_FocusDirection) 243 if (dir == kNext_FocusDirection) {
258 {
259 parent = focus; 244 parent = focus;
260 child = focus->fFirstChild; 245 child = focus->fFirstChild;
261 if (child) 246 if (child)
262 goto FIRST_CHILD; 247 goto FIRST_CHILD;
263 else 248 else
264 goto NEXT_SIB; 249 goto NEXT_SIB;
265 250
266 do { 251 do {
267 while (child != parent->fFirstChild) 252 while (child != parent->fFirstChild) {
268 {
269 FIRST_CHILD: 253 FIRST_CHILD:
270 if ((focus = child->acceptFocus(dir)) != nullptr) 254 if ((focus = child->acceptFocus(dir)) != nullptr)
271 return focus; 255 return focus;
272 child = child->fNextSibling; 256 child = child->fNextSibling;
273 } 257 }
274 NEXT_SIB: 258 NEXT_SIB:
275 child = parent->fNextSibling; 259 child = parent->fNextSibling;
276 parent = parent->fParent; 260 parent = parent->fParent;
277 } while (parent != nullptr); 261 } while (parent != nullptr);
278 } 262 } else { // prevfocus
279 else // prevfocus
280 {
281 parent = focus->fParent; 263 parent = focus->fParent;
282 if (parent == nullptr) // we're the root 264 if (parent == nullptr) { // we're the root
283 return focus->acceptFocus(dir); 265 return focus->acceptFocus(dir);
284 else 266 } else {
285 {
286 child = focus; 267 child = focus;
287 while (parent) 268 while (parent) {
288 { 269 while (child != parent->fFirstChild) {
289 while (child != parent->fFirstChild)
290 {
291 child = child->fPrevSibling; 270 child = child->fPrevSibling;
292 if ((focus = child->acceptFocus(dir)) != nullptr) 271 if ((focus = child->acceptFocus(dir)) != nullptr) {
293 return focus; 272 return focus;
273 }
294 } 274 }
295 if (parent->acceptFocus()) 275 if (parent->acceptFocus()) {
296 return parent; 276 return parent;
297 277 }
298 child = parent; 278 child = parent;
299 parent = parent->fParent; 279 parent = parent->fParent;
300 } 280 }
301 } 281 }
302 } 282 }
303 return nullptr; 283 return nullptr;
304 } 284 }
305 285
306 void SkView::onFocusChange(bool gainFocusP) 286 void SkView::onFocusChange(bool gainFocusP) {
307 {
308 this->inval(nullptr); 287 this->inval(nullptr);
309 } 288 }
310 289
311 //////////////////////////////////////////////////////////////////////////// 290 ////////////////////////////////////////////////////////////////////////////
312 291
313 SkView::Click::Click(SkView* target) 292 SkView::Click::Click(SkView* target) {
314 {
315 SkASSERT(target); 293 SkASSERT(target);
316 fTargetID = target->getSinkID(); 294 fTargetID = target->getSinkID();
317 fType = nullptr; 295 fType = nullptr;
318 fWeOwnTheType = false; 296 fWeOwnTheType = false;
319 fOwner = nullptr; 297 fOwner = nullptr;
320 } 298 }
321 299
322 SkView::Click::~Click() 300 SkView::Click::~Click() {
323 {
324 this->resetType(); 301 this->resetType();
325 } 302 }
326 303
327 void SkView::Click::resetType() 304 void SkView::Click::resetType() {
328 { 305 if (fWeOwnTheType) {
329 if (fWeOwnTheType)
330 {
331 sk_free(fType); 306 sk_free(fType);
332 fWeOwnTheType = false; 307 fWeOwnTheType = false;
333 } 308 }
334 fType = nullptr; 309 fType = nullptr;
335 } 310 }
336 311
337 bool SkView::Click::isType(const char type[]) const 312 bool SkView::Click::isType(const char type[]) const {
338 {
339 const char* t = fType; 313 const char* t = fType;
340 314
341 if (type == t) 315 if (type == t) {
342 return true; 316 return true;
343 317 }
344 if (type == nullptr) 318 if (type == nullptr) {
345 type = ""; 319 type = "";
346 if (t == nullptr) 320 }
321 if (t == nullptr) {
347 t = ""; 322 t = "";
323 }
348 return !strcmp(t, type); 324 return !strcmp(t, type);
349 } 325 }
350 326
351 void SkView::Click::setType(const char type[]) 327 void SkView::Click::setType(const char type[]) {
352 {
353 this->resetType(); 328 this->resetType();
354 fType = (char*)type; 329 fType = (char*)type;
355 } 330 }
356 331
357 void SkView::Click::copyType(const char type[]) 332 void SkView::Click::copyType(const char type[]) {
358 { 333 if (fType != type) {
359 if (fType != type)
360 {
361 this->resetType(); 334 this->resetType();
362 if (type) 335 if (type) {
363 { 336 size_t len = strlen(type) + 1;
364 size_t len = strlen(type) + 1;
365 fType = (char*)sk_malloc_throw(len); 337 fType = (char*)sk_malloc_throw(len);
366 memcpy(fType, type, len); 338 memcpy(fType, type, len);
367 fWeOwnTheType = true; 339 fWeOwnTheType = true;
368 } 340 }
369 } 341 }
370 } 342 }
371 343
372 SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y, unsigned modi) { 344 SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y, unsigned modi) {
373 if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) { 345 if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) {
374 return nullptr; 346 return nullptr;
(...skipping 18 matching lines...) Expand all
393 365
394 if (click) { 366 if (click) {
395 return click; 367 return click;
396 } 368 }
397 } 369 }
398 } 370 }
399 371
400 return this->onFindClickHandler(x, y, modi); 372 return this->onFindClickHandler(x, y, modi);
401 } 373 }
402 374
403 void SkView::DoClickDown(Click* click, int x, int y, unsigned modi) 375 void SkView::DoClickDown(Click* click, int x, int y, unsigned modi) {
404 {
405 SkASSERT(click); 376 SkASSERT(click);
406 377
407 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); 378 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID);
408 if (nullptr == target) { 379 if (nullptr == target) {
409 return; 380 return;
410 } 381 }
411 382
412 click->fIOrig.set(x, y); 383 click->fIOrig.set(x, y);
413 click->fICurr = click->fIPrev = click->fIOrig; 384 click->fICurr = click->fIPrev = click->fIOrig;
414 385
415 click->fOrig.iset(x, y); 386 click->fOrig.iset(x, y);
416 if (!target->globalToLocal(&click->fOrig)) { 387 if (!target->globalToLocal(&click->fOrig)) {
417 // no history to let us recover from this failure 388 // no history to let us recover from this failure
418 return; 389 return;
419 } 390 }
420 click->fPrev = click->fCurr = click->fOrig; 391 click->fPrev = click->fCurr = click->fOrig;
421 392
422 click->fState = Click::kDown_State; 393 click->fState = Click::kDown_State;
423 click->fModifierKeys = modi; 394 click->fModifierKeys = modi;
424 target->onClick(click); 395 target->onClick(click);
425 } 396 }
426 397
427 void SkView::DoClickMoved(Click* click, int x, int y, unsigned modi) 398 void SkView::DoClickMoved(Click* click, int x, int y, unsigned modi) {
428 {
429 SkASSERT(click); 399 SkASSERT(click);
430 400
431 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); 401 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID);
432 if (nullptr == target) { 402 if (nullptr == target) {
433 return; 403 return;
434 } 404 }
435 405
436 click->fIPrev = click->fICurr; 406 click->fIPrev = click->fICurr;
437 click->fICurr.set(x, y); 407 click->fICurr.set(x, y);
438 408
439 click->fPrev = click->fCurr; 409 click->fPrev = click->fCurr;
440 click->fCurr.iset(x, y); 410 click->fCurr.iset(x, y);
441 if (!target->globalToLocal(&click->fCurr)) { 411 if (!target->globalToLocal(&click->fCurr)) {
442 // on failure pretend the mouse didn't move 412 // on failure pretend the mouse didn't move
443 click->fCurr = click->fPrev; 413 click->fCurr = click->fPrev;
444 } 414 }
445 415
446 click->fState = Click::kMoved_State; 416 click->fState = Click::kMoved_State;
447 click->fModifierKeys = modi; 417 click->fModifierKeys = modi;
448 target->onClick(click); 418 target->onClick(click);
449 } 419 }
450 420
451 void SkView::DoClickUp(Click* click, int x, int y, unsigned modi) 421 void SkView::DoClickUp(Click* click, int x, int y, unsigned modi) {
452 {
453 SkASSERT(click); 422 SkASSERT(click);
454 423
455 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); 424 SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID);
456 if (nullptr == target) { 425 if (nullptr == target) {
457 return; 426 return;
458 } 427 }
459 428
460 click->fIPrev = click->fICurr; 429 click->fIPrev = click->fICurr;
461 click->fICurr.set(x, y); 430 click->fICurr.set(x, y);
462 431
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 matrix->reset(); 599 matrix->reset();
631 const SkView* view = this; 600 const SkView* view = this;
632 while (view) 601 while (view)
633 { 602 {
634 matrix->preConcat(view->getLocalMatrix()); 603 matrix->preConcat(view->getLocalMatrix());
635 matrix->preTranslate(-view->fLoc.fX, -view->fLoc.fY); 604 matrix->preTranslate(-view->fLoc.fX, -view->fLoc.fY);
636 view = view->fParent; 605 view = view->fParent;
637 } 606 }
638 } 607 }
639 } 608 }
640 bool SkView::globalToLocal(SkScalar x, SkScalar y, SkPoint* local) const 609
641 { 610 bool SkView::globalToLocal(SkScalar x, SkScalar y, SkPoint* local) const {
642 SkASSERT(this); 611 SkASSERT(this);
643 612
644 if (local) { 613 if (local) {
645 SkMatrix m; 614 SkMatrix m;
646 this->localToGlobal(&m); 615 this->localToGlobal(&m);
647 if (!m.invert(&m)) { 616 if (!m.invert(&m)) {
648 return false; 617 return false;
649 } 618 }
650 SkPoint p; 619 SkPoint p;
651 m.mapXY(x, y, &p); 620 m.mapXY(x, y, &p);
(...skipping 25 matching lines...) Expand all
677 646
678 // inflate the flags 647 // inflate the flags
679 648
680 static const char* gFlagNames[] = { 649 static const char* gFlagNames[] = {
681 "visible", "enabled", "focusable", "flexH", "flexV" 650 "visible", "enabled", "focusable", "flexH", "flexV"
682 }; 651 };
683 SkASSERT(SK_ARRAY_COUNT(gFlagNames) == kFlagShiftCount); 652 SkASSERT(SK_ARRAY_COUNT(gFlagNames) == kFlagShiftCount);
684 653
685 bool b; 654 bool b;
686 uint32_t flags = this->getFlags(); 655 uint32_t flags = this->getFlags();
687 for (unsigned i = 0; i < SK_ARRAY_COUNT(gFlagNames); i++) 656 for (unsigned i = 0; i < SK_ARRAY_COUNT(gFlagNames); i++) {
688 if (dom.findBool(node, gFlagNames[i], &b)) 657 if (dom.findBool(node, gFlagNames[i], &b)) {
689 flags = SkSetClearShift(flags, b, i); 658 flags = SkSetClearShift(flags, b, i);
659 }
660 }
690 this->setFlags(flags); 661 this->setFlags(flags);
691 } 662 }
692 663
693 void SkView::inflate(const SkDOM& dom, const SkDOM::Node* node) { 664 void SkView::inflate(const SkDOM& dom, const SkDOM::Node* node) {
694 this->onInflate(dom, node); 665 this->onInflate(dom, node);
695 } 666 }
696 667
697 void SkView::onPostInflate(const SkTDict<SkView*>&) { 668 void SkView::onPostInflate(const SkTDict<SkView*>&) {
698 // override in subclass as needed 669 // override in subclass as needed
699 } 670 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 if (fParent) { 752 if (fParent) {
782 SkASSERT(fNextSibling); 753 SkASSERT(fNextSibling);
783 SkASSERT(fPrevSibling); 754 SkASSERT(fPrevSibling);
784 } else { 755 } else {
785 bool nextNull = nullptr == fNextSibling; 756 bool nextNull = nullptr == fNextSibling;
786 bool prevNull = nullptr == fNextSibling; 757 bool prevNull = nullptr == fNextSibling;
787 SkASSERT(nextNull == prevNull); 758 SkASSERT(nextNull == prevNull);
788 } 759 }
789 } 760 }
790 761
791 static inline void show_if_nonzero(const char name[], SkScalar value) 762 static inline void show_if_nonzero(const char name[], SkScalar value) {
792 { 763 if (value) {
793 if (value)
794 SkDebugf("%s=\"%g\"", name, value/65536.); 764 SkDebugf("%s=\"%g\"", name, value/65536.);
765 }
795 } 766 }
796 767
797 static void tab(int level) 768 static void tab(int level) {
798 { 769 for (int i = 0; i < level; i++) {
799 for (int i = 0; i < level; i++)
800 SkDebugf(" "); 770 SkDebugf(" ");
771 }
801 } 772 }
802 773
803 static void dumpview(const SkView* view, int level, bool recurse) 774 static void dumpview(const SkView* view, int level, bool recurse) {
804 {
805 tab(level); 775 tab(level);
806 776
807 SkDebugf("<view"); 777 SkDebugf("<view");
808 show_if_nonzero(" x", view->locX()); 778 show_if_nonzero(" x", view->locX());
809 show_if_nonzero(" y", view->locY()); 779 show_if_nonzero(" y", view->locY());
810 show_if_nonzero(" width", view->width()); 780 show_if_nonzero(" width", view->width());
811 show_if_nonzero(" height", view->height()); 781 show_if_nonzero(" height", view->height());
812 782
813 if (recurse) 783 if (recurse) {
814 {
815 SkView::B2FIter iter(view); 784 SkView::B2FIter iter(view);
816 SkView* child; 785 SkView* child;
817 bool noChildren = true; 786 bool noChildren = true;
818 787
819 while ((child = iter.next()) != nullptr) 788 while ((child = iter.next()) != nullptr) {
820 { 789 if (noChildren) {
821 if (noChildren)
822 SkDebugf(">\n"); 790 SkDebugf(">\n");
791 }
823 noChildren = false; 792 noChildren = false;
824 dumpview(child, level + 1, true); 793 dumpview(child, level + 1, true);
825 } 794 }
826 795
827 if (!noChildren) 796 if (!noChildren) {
828 {
829 tab(level); 797 tab(level);
830 SkDebugf("</view>\n"); 798 SkDebugf("</view>\n");
799 } else {
800 goto ONELINER;
831 } 801 }
832 else 802 } else {
833 goto ONELINER;
834 }
835 else
836 {
837 ONELINER: 803 ONELINER:
838 SkDebugf(" />\n"); 804 SkDebugf(" />\n");
839 } 805 }
840 } 806 }
841 807
842 void SkView::dump(bool recurse) const 808 void SkView::dump(bool recurse) const {
843 {
844 dumpview(this, 0, recurse); 809 dumpview(this, 0, recurse);
845 } 810 }
846 811
847 #endif 812 #endif
OLDNEW
« no previous file with comments | « src/utils/SkInterpolator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698