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