epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 7 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SkView.h" |
| 9 | #include "SkCanvas.h" |
Hal Canary | 20de615 | 2017-02-23 13:24:49 -0500 | [diff] [blame^] | 10 | #include "SkDOM.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 11 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 12 | static inline uint32_t SkSetClearShift(uint32_t bits, bool cond, unsigned shift) { |
| 13 | SkASSERT((int)cond == 0 || (int)cond == 1); |
| 14 | return (bits & ~(1 << shift)) | ((int)cond << shift); |
| 15 | } |
| 16 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 17 | //////////////////////////////////////////////////////////////////////// |
| 18 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 19 | SkView::SkView(uint32_t flags) : fFlags(SkToU8(flags)) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 20 | fWidth = fHeight = 0; |
| 21 | fLoc.set(0, 0); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 22 | fParent = fFirstChild = fNextSibling = fPrevSibling = nullptr; |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 23 | fMatrix.setIdentity(); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 24 | fContainsFocus = 0; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | } |
| 26 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 27 | SkView::~SkView() { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 28 | this->detachAllChildren(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 29 | } |
| 30 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 31 | void SkView::setFlags(uint32_t flags) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 32 | SkASSERT((flags & ~kAllFlagMasks) == 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 34 | uint32_t diff = fFlags ^ flags; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 36 | if (diff & kVisible_Mask) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 37 | this->inval(nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 39 | fFlags = SkToU8(flags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 41 | if (diff & kVisible_Mask) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 42 | this->inval(nullptr); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 43 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | } |
| 45 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 46 | void SkView::setVisibleP(bool pred) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 47 | this->setFlags(SkSetClearShift(fFlags, pred, kVisible_Shift)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | } |
| 49 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 50 | void SkView::setEnabledP(bool pred) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 51 | this->setFlags(SkSetClearShift(fFlags, pred, kEnabled_Shift)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | } |
| 53 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 54 | void SkView::setFocusableP(bool pred) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 55 | this->setFlags(SkSetClearShift(fFlags, pred, kFocusable_Shift)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | } |
| 57 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 58 | void SkView::setClipToBounds(bool pred) { |
| 59 | this->setFlags(SkSetClearShift(fFlags, !pred, kNoClip_Shift)); |
| 60 | } |
| 61 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 62 | void SkView::setSize(SkScalar width, SkScalar height) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 63 | width = SkMaxScalar(0, width); |
| 64 | height = SkMaxScalar(0, height); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 65 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 66 | if (fWidth != width || fHeight != height) |
| 67 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 68 | this->inval(nullptr); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 69 | fWidth = width; |
| 70 | fHeight = height; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 71 | this->inval(nullptr); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 72 | this->onSizeChange(); |
| 73 | this->invokeLayout(); |
| 74 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 75 | } |
| 76 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 77 | void SkView::setLoc(SkScalar x, SkScalar y) { |
| 78 | if (fLoc.fX != x || fLoc.fY != y) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 79 | this->inval(nullptr); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 80 | fLoc.set(x, y); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 81 | this->inval(nullptr); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 82 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 83 | } |
| 84 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 85 | void SkView::offset(SkScalar dx, SkScalar dy) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 86 | if (dx || dy) |
| 87 | this->setLoc(fLoc.fX + dx, fLoc.fY + dy); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 88 | } |
| 89 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 90 | void SkView::setLocalMatrix(const SkMatrix& matrix) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 91 | this->inval(nullptr); |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 92 | fMatrix = matrix; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 93 | this->inval(nullptr); |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 94 | } |
| 95 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 96 | void SkView::draw(SkCanvas* canvas) { |
| 97 | if (fWidth && fHeight && this->isVisible()) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 98 | SkRect r; |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 99 | r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight); |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 100 | if (this->isClipToBounds() && canvas->quickReject(r)) { |
| 101 | return; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 102 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 103 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 104 | SkAutoCanvasRestore as(canvas, true); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 105 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 106 | if (this->isClipToBounds()) { |
| 107 | canvas->clipRect(r); |
| 108 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 109 | |
| 110 | canvas->translate(fLoc.fX, fLoc.fY); |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 111 | canvas->concat(fMatrix); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 112 | |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 113 | if (fParent) { |
| 114 | fParent->beforeChild(this, canvas); |
| 115 | } |
reed@android.com | 562ea92 | 2010-02-08 21:45:03 +0000 | [diff] [blame] | 116 | |
| 117 | int sc = canvas->save(); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 118 | this->onDraw(canvas); |
reed@android.com | 562ea92 | 2010-02-08 21:45:03 +0000 | [diff] [blame] | 119 | canvas->restoreToCount(sc); |
| 120 | |
reed@android.com | 6c5f6f2 | 2009-08-14 16:08:38 +0000 | [diff] [blame] | 121 | if (fParent) { |
| 122 | fParent->afterChild(this, canvas); |
| 123 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 124 | |
| 125 | B2FIter iter(this); |
| 126 | SkView* child; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 127 | |
| 128 | SkCanvas* childCanvas = this->beforeChildren(canvas); |
| 129 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 130 | while ((child = iter.next()) != nullptr) |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 131 | child->draw(childCanvas); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 132 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 133 | this->afterChildren(canvas); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 134 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 135 | } |
| 136 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 137 | void SkView::inval(SkRect* rect) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 138 | SkView* view = this; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 139 | SkRect storage; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 140 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 141 | for (;;) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 142 | if (!view->isVisible()) { |
| 143 | return; |
| 144 | } |
| 145 | if (view->isClipToBounds()) { |
| 146 | SkRect bounds; |
| 147 | view->getLocalBounds(&bounds); |
| 148 | if (rect && !bounds.intersect(*rect)) { |
| 149 | return; |
| 150 | } |
| 151 | storage = bounds; |
| 152 | rect = &storage; |
| 153 | } |
| 154 | if (view->handleInval(rect)) { |
| 155 | return; |
| 156 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 157 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 158 | SkView* parent = view->fParent; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 159 | if (parent == nullptr) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 160 | return; |
| 161 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 162 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 163 | if (rect) { |
| 164 | rect->offset(view->fLoc.fX, view->fLoc.fY); |
| 165 | } |
| 166 | view = parent; |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 167 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | //////////////////////////////////////////////////////////////////////////// |
| 171 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 172 | bool SkView::setFocusView(SkView* fv) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 173 | SkView* view = this; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 174 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 175 | do { |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 176 | if (view->onSetFocusView(fv)) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 177 | return true; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 178 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 179 | } while ((view = view->fParent) != nullptr); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 180 | return false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 181 | } |
| 182 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 183 | SkView* SkView::getFocusView() const { |
| 184 | SkView* focus = nullptr; |
| 185 | const SkView* view = this; |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 186 | do { |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 187 | if (view->onGetFocusView(&focus)) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 188 | break; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 189 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 190 | } while ((view = view->fParent) != nullptr); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 191 | return focus; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 192 | } |
| 193 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 194 | bool SkView::hasFocus() const { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 195 | return this == this->getFocusView(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 196 | } |
| 197 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 198 | bool SkView::acceptFocus() { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 199 | return this->isFocusable() && this->setFocusView(this); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /* |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 203 | Try to give focus to this view, or its children |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 204 | */ |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 205 | SkView* SkView::acceptFocus(FocusDirection dir) { |
| 206 | if (dir == kNext_FocusDirection) { |
| 207 | if (this->acceptFocus()) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 208 | return this; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 209 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 210 | B2FIter iter(this); |
| 211 | SkView* child, *focus; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 212 | while ((child = iter.next()) != nullptr) { |
| 213 | if ((focus = child->acceptFocus(dir)) != nullptr) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 214 | return focus; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | } else { // prev |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 218 | F2BIter iter(this); |
| 219 | SkView* child, *focus; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 220 | while ((child = iter.next()) != nullptr) { |
| 221 | if ((focus = child->acceptFocus(dir)) != nullptr) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 222 | return focus; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | if (this->acceptFocus()) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 226 | return this; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 227 | } |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 228 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 229 | return nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 230 | } |
| 231 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 232 | SkView* SkView::moveFocus(FocusDirection dir) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 233 | SkView* focus = this->getFocusView(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 234 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 235 | if (focus == nullptr) { // start with the root |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 236 | focus = this; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 237 | while (focus->fParent) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 238 | focus = focus->fParent; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 239 | } |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 240 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 241 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 242 | SkView* child, *parent; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 243 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 244 | if (dir == kNext_FocusDirection) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 245 | parent = focus; |
| 246 | child = focus->fFirstChild; |
| 247 | if (child) |
| 248 | goto FIRST_CHILD; |
| 249 | else |
| 250 | goto NEXT_SIB; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 251 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 252 | do { |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 253 | while (child != parent->fFirstChild) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 254 | FIRST_CHILD: |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 255 | if ((focus = child->acceptFocus(dir)) != nullptr) |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 256 | return focus; |
| 257 | child = child->fNextSibling; |
| 258 | } |
| 259 | NEXT_SIB: |
| 260 | child = parent->fNextSibling; |
| 261 | parent = parent->fParent; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 262 | } while (parent != nullptr); |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 263 | } else { // prevfocus |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 264 | parent = focus->fParent; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 265 | if (parent == nullptr) { // we're the root |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 266 | return focus->acceptFocus(dir); |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 267 | } else { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 268 | child = focus; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 269 | while (parent) { |
| 270 | while (child != parent->fFirstChild) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 271 | child = child->fPrevSibling; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 272 | if ((focus = child->acceptFocus(dir)) != nullptr) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 273 | return focus; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 274 | } |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 275 | } |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 276 | if (parent->acceptFocus()) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 277 | return parent; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 278 | } |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 279 | child = parent; |
| 280 | parent = parent->fParent; |
| 281 | } |
| 282 | } |
| 283 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 284 | return nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 285 | } |
| 286 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 287 | void SkView::onFocusChange(bool gainFocusP) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 288 | this->inval(nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | //////////////////////////////////////////////////////////////////////////// |
| 292 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 293 | SkView::Click::Click(SkView* target) { |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 294 | SkASSERT(target); |
| 295 | fTargetID = target->getSinkID(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 296 | fType = nullptr; |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 297 | fWeOwnTheType = false; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 298 | fOwner = nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 299 | } |
| 300 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 301 | SkView::Click::~Click() { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 302 | this->resetType(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 303 | } |
| 304 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 305 | void SkView::Click::resetType() { |
| 306 | if (fWeOwnTheType) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 307 | sk_free(fType); |
| 308 | fWeOwnTheType = false; |
| 309 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 310 | fType = nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 311 | } |
| 312 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 313 | bool SkView::Click::isType(const char type[]) const { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 314 | const char* t = fType; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 315 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 316 | if (type == t) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 317 | return true; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 318 | } |
| 319 | if (type == nullptr) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 320 | type = ""; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 321 | } |
| 322 | if (t == nullptr) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 323 | t = ""; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 324 | } |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 325 | return !strcmp(t, type); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 326 | } |
| 327 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 328 | void SkView::Click::setType(const char type[]) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 329 | this->resetType(); |
| 330 | fType = (char*)type; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 331 | } |
| 332 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 333 | void SkView::Click::copyType(const char type[]) { |
| 334 | if (fType != type) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 335 | this->resetType(); |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 336 | if (type) { |
| 337 | size_t len = strlen(type) + 1; |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 338 | fType = (char*)sk_malloc_throw(len); |
| 339 | memcpy(fType, type, len); |
| 340 | fWeOwnTheType = true; |
| 341 | } |
| 342 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 343 | } |
| 344 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 345 | SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y, unsigned modi) { |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 346 | if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 347 | return nullptr; |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 348 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 349 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 350 | if (this->onSendClickToChildren(x, y, modi)) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 351 | F2BIter iter(this); |
| 352 | SkView* child; |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 353 | |
reed | 1a9caff | 2015-09-02 19:05:10 -0700 | [diff] [blame] | 354 | while ((child = iter.next()) != nullptr) { |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 355 | SkPoint p; |
reed | 1a9caff | 2015-09-02 19:05:10 -0700 | [diff] [blame] | 356 | #if 0 |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 357 | if (!child->globalToLocal(x, y, &p)) { |
| 358 | continue; |
| 359 | } |
reed | 1a9caff | 2015-09-02 19:05:10 -0700 | [diff] [blame] | 360 | #else |
| 361 | // the above seems broken, so just respecting fLoc for now <reed> |
| 362 | p.set(x - child->fLoc.x(), y - child->fLoc.y()); |
| 363 | #endif |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 364 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 365 | Click* click = child->findClickHandler(p.fX, p.fY, modi); |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 366 | |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 367 | if (click) { |
| 368 | return click; |
| 369 | } |
| 370 | } |
| 371 | } |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 372 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 373 | return this->onFindClickHandler(x, y, modi); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 374 | } |
| 375 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 376 | void SkView::DoClickDown(Click* click, int x, int y, unsigned modi) { |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 377 | SkASSERT(click); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 378 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 379 | SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 380 | if (nullptr == target) { |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 381 | return; |
| 382 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 383 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 384 | click->fIOrig.set(x, y); |
| 385 | click->fICurr = click->fIPrev = click->fIOrig; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 386 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 387 | click->fOrig.iset(x, y); |
| 388 | if (!target->globalToLocal(&click->fOrig)) { |
| 389 | // no history to let us recover from this failure |
| 390 | return; |
| 391 | } |
| 392 | click->fPrev = click->fCurr = click->fOrig; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 393 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 394 | click->fState = Click::kDown_State; |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 395 | click->fModifierKeys = modi; |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 396 | target->onClick(click); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 397 | } |
| 398 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 399 | void SkView::DoClickMoved(Click* click, int x, int y, unsigned modi) { |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 400 | SkASSERT(click); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 401 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 402 | SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 403 | if (nullptr == target) { |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 404 | return; |
| 405 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 406 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 407 | click->fIPrev = click->fICurr; |
| 408 | click->fICurr.set(x, y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 409 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 410 | click->fPrev = click->fCurr; |
| 411 | click->fCurr.iset(x, y); |
| 412 | if (!target->globalToLocal(&click->fCurr)) { |
| 413 | // on failure pretend the mouse didn't move |
| 414 | click->fCurr = click->fPrev; |
| 415 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 416 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 417 | click->fState = Click::kMoved_State; |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 418 | click->fModifierKeys = modi; |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 419 | target->onClick(click); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 420 | } |
| 421 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 422 | void SkView::DoClickUp(Click* click, int x, int y, unsigned modi) { |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 423 | SkASSERT(click); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 424 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 425 | SkView* target = (SkView*)SkEventSink::FindSink(click->fTargetID); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 426 | if (nullptr == target) { |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 427 | return; |
| 428 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 429 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 430 | click->fIPrev = click->fICurr; |
| 431 | click->fICurr.set(x, y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 432 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 433 | click->fPrev = click->fCurr; |
| 434 | click->fCurr.iset(x, y); |
| 435 | if (!target->globalToLocal(&click->fCurr)) { |
| 436 | // on failure pretend the mouse didn't move |
| 437 | click->fCurr = click->fPrev; |
| 438 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 439 | |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 440 | click->fState = Click::kUp_State; |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 441 | click->fModifierKeys = modi; |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 442 | target->onClick(click); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | ////////////////////////////////////////////////////////////////////// |
| 446 | |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 447 | void SkView::invokeLayout() { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 448 | SkView::Layout* layout = this->getLayout(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 449 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 450 | if (layout) { |
| 451 | layout->layoutChildren(this); |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 452 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 453 | } |
| 454 | |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 455 | void SkView::onDraw(SkCanvas* canvas) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 456 | Artist* artist = this->getArtist(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 457 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 458 | if (artist) { |
| 459 | artist->draw(this, canvas); |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 460 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 461 | } |
| 462 | |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 463 | void SkView::onSizeChange() {} |
| 464 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 465 | bool SkView::onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi) { |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 466 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 467 | } |
| 468 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 469 | SkView::Click* SkView::onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 470 | return nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 471 | } |
| 472 | |
reed@android.com | e72fee5 | 2009-11-16 14:52:01 +0000 | [diff] [blame] | 473 | bool SkView::onClick(Click*) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 474 | return false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 475 | } |
| 476 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 477 | bool SkView::handleInval(const SkRect*) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 478 | return false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | ////////////////////////////////////////////////////////////////////// |
| 482 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 483 | void SkView::getLocalBounds(SkRect* bounds) const { |
| 484 | if (bounds) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 485 | bounds->set(0, 0, fWidth, fHeight); |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 486 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | ////////////////////////////////////////////////////////////////////// |
| 490 | ////////////////////////////////////////////////////////////////////// |
| 491 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 492 | void SkView::detachFromParent_NoLayout() { |
| 493 | this->validate(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 494 | if (fParent == nullptr) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 495 | return; |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 496 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 497 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 498 | if (fContainsFocus) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 499 | (void)this->setFocusView(nullptr); |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 500 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 501 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 502 | this->inval(nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 503 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 504 | SkView* next = nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 505 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 506 | if (fNextSibling != this) { // do we have any siblings |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 507 | fNextSibling->fPrevSibling = fPrevSibling; |
| 508 | fPrevSibling->fNextSibling = fNextSibling; |
| 509 | next = fNextSibling; |
| 510 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 511 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 512 | if (fParent->fFirstChild == this) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 513 | fParent->fFirstChild = next; |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 514 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 515 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 516 | fParent = fNextSibling = fPrevSibling = nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 517 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 518 | this->validate(); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 519 | this->unref(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 520 | } |
| 521 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 522 | void SkView::detachFromParent() { |
| 523 | this->validate(); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 524 | SkView* parent = fParent; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 525 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 526 | if (parent) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 527 | this->detachFromParent_NoLayout(); |
| 528 | parent->invokeLayout(); |
| 529 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 530 | } |
| 531 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 532 | SkView* SkView::attachChildToBack(SkView* child) { |
| 533 | this->validate(); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 534 | SkASSERT(child != this); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 535 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 536 | if (child == nullptr || fFirstChild == child) |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 537 | goto DONE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 538 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 539 | child->ref(); |
| 540 | child->detachFromParent_NoLayout(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 541 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 542 | if (fFirstChild == nullptr) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 543 | child->fNextSibling = child; |
| 544 | child->fPrevSibling = child; |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 545 | } else { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 546 | child->fNextSibling = fFirstChild; |
| 547 | child->fPrevSibling = fFirstChild->fPrevSibling; |
| 548 | fFirstChild->fPrevSibling->fNextSibling = child; |
| 549 | fFirstChild->fPrevSibling = child; |
| 550 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 551 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 552 | fFirstChild = child; |
| 553 | child->fParent = this; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 554 | child->inval(nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 555 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 556 | this->validate(); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 557 | this->invokeLayout(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 558 | DONE: |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 559 | return child; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 560 | } |
| 561 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 562 | SkView* SkView::attachChildToFront(SkView* child) { |
| 563 | this->validate(); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 564 | SkASSERT(child != this); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 565 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 566 | if (child == nullptr || (fFirstChild && fFirstChild->fPrevSibling == child)) |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 567 | goto DONE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 568 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 569 | child->ref(); |
| 570 | child->detachFromParent_NoLayout(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 571 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 572 | if (fFirstChild == nullptr) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 573 | fFirstChild = child; |
| 574 | child->fNextSibling = child; |
| 575 | child->fPrevSibling = child; |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 576 | } else { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 577 | child->fNextSibling = fFirstChild; |
| 578 | child->fPrevSibling = fFirstChild->fPrevSibling; |
| 579 | fFirstChild->fPrevSibling->fNextSibling = child; |
| 580 | fFirstChild->fPrevSibling = child; |
| 581 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 582 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 583 | child->fParent = this; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 584 | child->inval(nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 585 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 586 | this->validate(); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 587 | this->invokeLayout(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 588 | DONE: |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 589 | return child; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 590 | } |
| 591 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 592 | void SkView::detachAllChildren() { |
| 593 | this->validate(); |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 594 | while (fFirstChild) |
| 595 | fFirstChild->detachFromParent_NoLayout(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 596 | } |
| 597 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 598 | void SkView::localToGlobal(SkMatrix* matrix) const { |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 599 | if (matrix) { |
| 600 | matrix->reset(); |
| 601 | const SkView* view = this; |
| 602 | while (view) |
| 603 | { |
| 604 | matrix->preConcat(view->getLocalMatrix()); |
| 605 | matrix->preTranslate(-view->fLoc.fX, -view->fLoc.fY); |
| 606 | view = view->fParent; |
| 607 | } |
| 608 | } |
| 609 | } |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 610 | |
| 611 | bool SkView::globalToLocal(SkScalar x, SkScalar y, SkPoint* local) const { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 612 | if (local) { |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 613 | SkMatrix m; |
| 614 | this->localToGlobal(&m); |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 615 | if (!m.invert(&m)) { |
| 616 | return false; |
| 617 | } |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 618 | SkPoint p; |
reed@google.com | f03bb56 | 2011-11-11 21:42:12 +0000 | [diff] [blame] | 619 | m.mapXY(x, y, &p); |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 620 | local->set(p.fX, p.fY); |
| 621 | } |
| 622 | |
| 623 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | ////////////////////////////////////////////////////////////////// |
| 627 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 628 | /* Even if the subclass overrides onInflate, they should always be |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 629 | sure to call the inherited method, so that we get called. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 630 | */ |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 631 | void SkView::onInflate(const SkDOM& dom, const SkDOM::Node* node) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 632 | SkScalar x, y; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 633 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 634 | x = this->locX(); |
| 635 | y = this->locY(); |
| 636 | (void)dom.findScalar(node, "x", &x); |
| 637 | (void)dom.findScalar(node, "y", &y); |
| 638 | this->setLoc(x, y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 639 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 640 | x = this->width(); |
| 641 | y = this->height(); |
| 642 | (void)dom.findScalar(node, "width", &x); |
| 643 | (void)dom.findScalar(node, "height", &y); |
| 644 | this->setSize(x, y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 645 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 646 | // inflate the flags |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 647 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 648 | static const char* gFlagNames[] = { |
| 649 | "visible", "enabled", "focusable", "flexH", "flexV" |
| 650 | }; |
| 651 | SkASSERT(SK_ARRAY_COUNT(gFlagNames) == kFlagShiftCount); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 652 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 653 | bool b; |
| 654 | uint32_t flags = this->getFlags(); |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 655 | for (unsigned i = 0; i < SK_ARRAY_COUNT(gFlagNames); i++) { |
| 656 | if (dom.findBool(node, gFlagNames[i], &b)) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 657 | flags = SkSetClearShift(flags, b, i); |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 658 | } |
| 659 | } |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 660 | this->setFlags(flags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 661 | } |
| 662 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 663 | void SkView::inflate(const SkDOM& dom, const SkDOM::Node* node) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 664 | this->onInflate(dom, node); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 665 | } |
| 666 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 667 | ////////////////////////////////////////////////////////////////// |
| 668 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 669 | SkView* SkView::sendEventToParents(const SkEvent& evt) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 670 | SkView* parent = fParent; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 671 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 672 | while (parent) { |
| 673 | if (parent->doEvent(evt)) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 674 | return parent; |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 675 | } |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 676 | parent = parent->fParent; |
| 677 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 678 | return nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 679 | } |
| 680 | |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 681 | SkView* SkView::sendQueryToParents(SkEvent* evt) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 682 | SkView* parent = fParent; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 683 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 684 | while (parent) { |
| 685 | if (parent->doQuery(evt)) { |
| 686 | return parent; |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 687 | } |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 688 | parent = parent->fParent; |
| 689 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 690 | return nullptr; |
reed@android.com | 34245c7 | 2009-11-03 04:00:48 +0000 | [diff] [blame] | 691 | } |
| 692 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 693 | ////////////////////////////////////////////////////////////////// |
| 694 | ////////////////////////////////////////////////////////////////// |
| 695 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 696 | SkView::F2BIter::F2BIter(const SkView* parent) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 697 | fFirstChild = parent ? parent->fFirstChild : nullptr; |
| 698 | fChild = fFirstChild ? fFirstChild->fPrevSibling : nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 699 | } |
| 700 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 701 | SkView* SkView::F2BIter::next() { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 702 | SkView* curr = fChild; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 703 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 704 | if (fChild) { |
| 705 | if (fChild == fFirstChild) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 706 | fChild = nullptr; |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 707 | } else { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 708 | fChild = fChild->fPrevSibling; |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 709 | } |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 710 | } |
| 711 | return curr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 712 | } |
| 713 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 714 | SkView::B2FIter::B2FIter(const SkView* parent) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 715 | fFirstChild = parent ? parent->fFirstChild : nullptr; |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 716 | fChild = fFirstChild; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 717 | } |
| 718 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 719 | SkView* SkView::B2FIter::next() { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 720 | SkView* curr = fChild; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 721 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 722 | if (fChild) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 723 | SkView* next = fChild->fNextSibling; |
| 724 | if (next == fFirstChild) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 725 | next = nullptr; |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 726 | fChild = next; |
| 727 | } |
| 728 | return curr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | ////////////////////////////////////////////////////////////////// |
| 732 | ////////////////////////////////////////////////////////////////// |
| 733 | |
| 734 | #ifdef SK_DEBUG |
| 735 | |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 736 | void SkView::validate() const { |
reed@google.com | 079813e | 2013-06-14 17:46:07 +0000 | [diff] [blame] | 737 | // SkASSERT(this->getRefCnt() > 0 && this->getRefCnt() < 100); |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 738 | if (fParent) { |
| 739 | SkASSERT(fNextSibling); |
| 740 | SkASSERT(fPrevSibling); |
| 741 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 742 | bool nextNull = nullptr == fNextSibling; |
| 743 | bool prevNull = nullptr == fNextSibling; |
reed@google.com | 732c5d5 | 2013-06-13 20:48:09 +0000 | [diff] [blame] | 744 | SkASSERT(nextNull == prevNull); |
reed@google.com | a25c94e | 2013-06-13 20:20:17 +0000 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 748 | static inline void show_if_nonzero(const char name[], SkScalar value) { |
| 749 | if (value) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 750 | SkDebugf("%s=\"%g\"", name, value/65536.); |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 751 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 752 | } |
| 753 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 754 | static void tab(int level) { |
| 755 | for (int i = 0; i < level; i++) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 756 | SkDebugf(" "); |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 757 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 758 | } |
| 759 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 760 | static void dumpview(const SkView* view, int level, bool recurse) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 761 | tab(level); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 762 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 763 | SkDebugf("<view"); |
| 764 | show_if_nonzero(" x", view->locX()); |
| 765 | show_if_nonzero(" y", view->locY()); |
| 766 | show_if_nonzero(" width", view->width()); |
| 767 | show_if_nonzero(" height", view->height()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 768 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 769 | if (recurse) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 770 | SkView::B2FIter iter(view); |
| 771 | SkView* child; |
| 772 | bool noChildren = true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 773 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 774 | while ((child = iter.next()) != nullptr) { |
| 775 | if (noChildren) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 776 | SkDebugf(">\n"); |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 777 | } |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 778 | noChildren = false; |
| 779 | dumpview(child, level + 1, true); |
| 780 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 781 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 782 | if (!noChildren) { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 783 | tab(level); |
| 784 | SkDebugf("</view>\n"); |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 785 | } else { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 786 | goto ONELINER; |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 787 | } |
| 788 | } else { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 789 | ONELINER: |
| 790 | SkDebugf(" />\n"); |
| 791 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 792 | } |
| 793 | |
reed | 9a878a0 | 2015-12-27 12:47:25 -0800 | [diff] [blame] | 794 | void SkView::dump(bool recurse) const { |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 795 | dumpview(this, 0, recurse); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | #endif |