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 "SkWindow.h" |
| 9 | #include "SkCanvas.h" |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 10 | #include "SkDevice.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 11 | #include "SkOSMenu.h" |
| 12 | #include "SkSystemEventTypes.h" |
| 13 | #include "SkTime.h" |
| 14 | |
| 15 | #define SK_EventDelayInval "\xd" "n" "\xa" "l" |
| 16 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 17 | SkWindow::SkWindow() : fFocusView(NULL) { |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 18 | fClicks.reset(); |
| 19 | fWaitingOnInval = false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | |
| 21 | #ifdef SK_BUILD_FOR_WINCE |
commit-bot@chromium.org | e24ad23 | 2014-02-16 22:03:38 +0000 | [diff] [blame] | 22 | fColorType = kRGB_565_SkColorType; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | #else |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 24 | fColorType = kN32_SkColorType; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | #endif |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 26 | |
| 27 | fMatrix.reset(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | } |
| 29 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 30 | SkWindow::~SkWindow() { |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 31 | fClicks.deleteAll(); |
| 32 | fMenus.deleteAll(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | } |
| 34 | |
reed@google.com | 5957f47 | 2012-10-01 20:31:56 +0000 | [diff] [blame] | 35 | SkCanvas* SkWindow::createCanvas() { |
| 36 | return new SkCanvas(this->getBitmap()); |
| 37 | } |
| 38 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 39 | void SkWindow::setMatrix(const SkMatrix& matrix) { |
| 40 | if (fMatrix != matrix) { |
| 41 | fMatrix = matrix; |
| 42 | this->inval(NULL); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void SkWindow::preConcat(const SkMatrix& matrix) { |
| 47 | SkMatrix m; |
| 48 | m.setConcat(fMatrix, matrix); |
| 49 | this->setMatrix(m); |
| 50 | } |
| 51 | |
| 52 | void SkWindow::postConcat(const SkMatrix& matrix) { |
| 53 | SkMatrix m; |
| 54 | m.setConcat(matrix, fMatrix); |
| 55 | this->setMatrix(m); |
| 56 | } |
| 57 | |
commit-bot@chromium.org | e24ad23 | 2014-02-16 22:03:38 +0000 | [diff] [blame] | 58 | void SkWindow::setColorType(SkColorType ct) { |
| 59 | this->resize(fBitmap.width(), fBitmap.height(), ct); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 60 | } |
| 61 | |
commit-bot@chromium.org | e24ad23 | 2014-02-16 22:03:38 +0000 | [diff] [blame] | 62 | void SkWindow::resize(int width, int height, SkColorType ct) { |
| 63 | if (ct == kUnknown_SkColorType) |
| 64 | ct = fColorType; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 65 | |
commit-bot@chromium.org | e24ad23 | 2014-02-16 22:03:38 +0000 | [diff] [blame] | 66 | if (width != fBitmap.width() || height != fBitmap.height() || ct != fColorType) { |
| 67 | fColorType = ct; |
| 68 | fBitmap.allocPixels(SkImageInfo::Make(width, height, |
| 69 | ct, kPremul_SkAlphaType)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 70 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 71 | this->setSize(SkIntToScalar(width), SkIntToScalar(height)); |
| 72 | this->inval(NULL); |
| 73 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 74 | } |
| 75 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 76 | bool SkWindow::handleInval(const SkRect* localR) { |
| 77 | SkIRect ir; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 79 | if (localR) { |
| 80 | SkRect devR; |
| 81 | SkMatrix inverse; |
| 82 | if (!fMatrix.invert(&inverse)) { |
| 83 | return false; |
| 84 | } |
| 85 | fMatrix.mapRect(&devR, *localR); |
| 86 | devR.round(&ir); |
| 87 | } else { |
reed@google.com | f9bb7a8 | 2011-03-01 15:15:13 +0000 | [diff] [blame] | 88 | ir.set(0, 0, |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 89 | SkScalarRoundToInt(this->width()), |
| 90 | SkScalarRoundToInt(this->height())); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 91 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 92 | fDirtyRgn.op(ir, SkRegion::kUnion_Op); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 93 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 94 | this->onHandleInval(ir); |
| 95 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 96 | } |
| 97 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 98 | void SkWindow::forceInvalAll() { |
reed@google.com | 261b8e2 | 2011-04-14 17:53:24 +0000 | [diff] [blame] | 99 | fDirtyRgn.setRect(0, 0, |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 100 | SkScalarCeilToInt(this->width()), |
| 101 | SkScalarCeilToInt(this->height())); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 102 | } |
| 103 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 104 | #if defined(SK_BUILD_FOR_WINCE) && defined(USE_GX_SCREEN) |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 105 | #include <windows.h> |
| 106 | #include <gx.h> |
| 107 | extern GXDisplayProperties gDisplayProps; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 108 | #endif |
| 109 | |
| 110 | #ifdef SK_SIMULATE_FAILED_MALLOC |
| 111 | extern bool gEnableControlledThrow; |
| 112 | #endif |
| 113 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 114 | bool SkWindow::update(SkIRect* updateArea) { |
| 115 | if (!fDirtyRgn.isEmpty()) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 116 | SkBitmap bm = this->getBitmap(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 117 | |
| 118 | #if defined(SK_BUILD_FOR_WINCE) && defined(USE_GX_SCREEN) |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 119 | char* buffer = (char*)GXBeginDraw(); |
| 120 | SkASSERT(buffer); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 121 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 122 | RECT rect; |
| 123 | GetWindowRect((HWND)((SkOSWindow*)this)->getHWND(), &rect); |
| 124 | buffer += rect.top * gDisplayProps.cbyPitch + rect.left * gDisplayProps.cbxPitch; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 125 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 126 | bm.setPixels(buffer); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 127 | #endif |
| 128 | |
robertphillips@google.com | ce9dce0 | 2012-10-02 12:32:22 +0000 | [diff] [blame] | 129 | SkAutoTUnref<SkCanvas> canvas(this->createCanvas()); |
| 130 | |
| 131 | canvas->clipRegion(fDirtyRgn); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 132 | if (updateArea) |
| 133 | *updateArea = fDirtyRgn.getBounds(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 134 | |
robertphillips@google.com | ce9dce0 | 2012-10-02 12:32:22 +0000 | [diff] [blame] | 135 | SkAutoCanvasRestore acr(canvas, true); |
| 136 | canvas->concat(fMatrix); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 137 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 138 | // empty this now, so we can correctly record any inval calls that |
| 139 | // might be made during the draw call. |
| 140 | fDirtyRgn.setEmpty(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 141 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 142 | #ifdef SK_SIMULATE_FAILED_MALLOC |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 143 | gEnableControlledThrow = true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 144 | #endif |
| 145 | #ifdef SK_BUILD_FOR_WIN32 |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 146 | //try { |
robertphillips@google.com | ce9dce0 | 2012-10-02 12:32:22 +0000 | [diff] [blame] | 147 | this->draw(canvas); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 148 | //} |
| 149 | //catch (...) { |
| 150 | //} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 151 | #else |
robertphillips@google.com | ce9dce0 | 2012-10-02 12:32:22 +0000 | [diff] [blame] | 152 | this->draw(canvas); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 153 | #endif |
| 154 | #ifdef SK_SIMULATE_FAILED_MALLOC |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 155 | gEnableControlledThrow = false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 156 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 157 | |
| 158 | #if defined(SK_BUILD_FOR_WINCE) && defined(USE_GX_SCREEN) |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 159 | GXEndDraw(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 160 | #endif |
| 161 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 162 | return true; |
| 163 | } |
| 164 | return false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 165 | } |
| 166 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 167 | bool SkWindow::handleChar(SkUnichar uni) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 168 | if (this->onHandleChar(uni)) |
| 169 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 170 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 171 | SkView* focus = this->getFocusView(); |
| 172 | if (focus == NULL) |
| 173 | focus = this; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 174 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 175 | SkEvent evt(SK_EventType_Unichar); |
| 176 | evt.setFast32(uni); |
| 177 | return focus->doEvent(evt); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 178 | } |
| 179 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 180 | bool SkWindow::handleKey(SkKey key) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 181 | if (key == kNONE_SkKey) |
| 182 | return false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 183 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 184 | if (this->onHandleKey(key)) |
| 185 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 186 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 187 | // send an event to the focus-view |
| 188 | { |
| 189 | SkView* focus = this->getFocusView(); |
| 190 | if (focus == NULL) |
| 191 | focus = this; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 192 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 193 | SkEvent evt(SK_EventType_Key); |
| 194 | evt.setFast32(key); |
| 195 | if (focus->doEvent(evt)) |
| 196 | return true; |
| 197 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 198 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 199 | if (key == kUp_SkKey || key == kDown_SkKey) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 200 | if (this->moveFocus(key == kUp_SkKey ? kPrev_FocusDirection : kNext_FocusDirection) == NULL) |
| 201 | this->onSetFocusView(NULL); |
| 202 | return true; |
| 203 | } |
| 204 | return false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 205 | } |
| 206 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 207 | bool SkWindow::handleKeyUp(SkKey key) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 208 | if (key == kNONE_SkKey) |
| 209 | return false; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 210 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 211 | if (this->onHandleKeyUp(key)) |
| 212 | return true; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 213 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 214 | //send an event to the focus-view |
| 215 | { |
| 216 | SkView* focus = this->getFocusView(); |
| 217 | if (focus == NULL) |
| 218 | focus = this; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 219 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 220 | //should this one be the same? |
| 221 | SkEvent evt(SK_EventType_KeyUp); |
| 222 | evt.setFast32(key); |
| 223 | if (focus->doEvent(evt)) |
| 224 | return true; |
| 225 | } |
| 226 | return false; |
| 227 | } |
| 228 | |
yangsu@google.com | 654d72f | 2011-08-01 17:27:33 +0000 | [diff] [blame] | 229 | void SkWindow::addMenu(SkOSMenu* menu) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 230 | *fMenus.append() = menu; |
| 231 | this->onAddMenu(menu); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 232 | } |
| 233 | |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 234 | void SkWindow::setTitle(const char title[]) { |
| 235 | if (NULL == title) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 236 | title = ""; |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 237 | } |
| 238 | fTitle.set(title); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 239 | this->onSetTitle(title); |
| 240 | } |
| 241 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 242 | bool SkWindow::onEvent(const SkEvent& evt) { |
| 243 | if (evt.isType(SK_EventDelayInval)) { |
| 244 | for (SkRegion::Iterator iter(fDirtyRgn); !iter.done(); iter.next()) |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 245 | this->onHandleInval(iter.rect()); |
| 246 | fWaitingOnInval = false; |
| 247 | return true; |
| 248 | } |
| 249 | return this->INHERITED::onEvent(evt); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 250 | } |
| 251 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 252 | bool SkWindow::onGetFocusView(SkView** focus) const { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 253 | if (focus) |
| 254 | *focus = fFocusView; |
| 255 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 256 | } |
| 257 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 258 | bool SkWindow::onSetFocusView(SkView* focus) { |
| 259 | if (fFocusView != focus) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 260 | if (fFocusView) |
| 261 | fFocusView->onFocusChange(false); |
| 262 | fFocusView = focus; |
| 263 | if (focus) |
| 264 | focus->onFocusChange(true); |
| 265 | } |
| 266 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 267 | } |
| 268 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 269 | void SkWindow::onHandleInval(const SkIRect&) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 270 | } |
| 271 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 272 | bool SkWindow::onHandleChar(SkUnichar) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 273 | return false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 274 | } |
| 275 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 276 | bool SkWindow::onHandleKey(SkKey) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 277 | return false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 278 | } |
| 279 | |
tfarina@chromium.org | 658650c | 2014-01-25 18:45:45 +0000 | [diff] [blame] | 280 | bool SkWindow::onHandleKeyUp(SkKey) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 281 | return false; |
| 282 | } |
| 283 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 284 | bool SkWindow::handleClick(int x, int y, Click::State state, void *owner, |
| 285 | unsigned modifierKeys) { |
| 286 | return this->onDispatchClick(x, y, state, owner, modifierKeys); |
mike@reedtribe.org | dd0cd34 | 2011-03-21 00:53:39 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 289 | bool SkWindow::onDispatchClick(int x, int y, Click::State state, |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 290 | void* owner, unsigned modifierKeys) { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 291 | bool handled = false; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 292 | |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 293 | // First, attempt to find an existing click with this owner. |
| 294 | int index = -1; |
| 295 | for (int i = 0; i < fClicks.count(); i++) { |
| 296 | if (owner == fClicks[i]->fOwner) { |
| 297 | index = i; |
| 298 | break; |
| 299 | } |
| 300 | } |
| 301 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 302 | switch (state) { |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 303 | case Click::kDown_State: { |
| 304 | if (index != -1) { |
| 305 | delete fClicks[index]; |
| 306 | fClicks.remove(index); |
| 307 | } |
| 308 | Click* click = this->findClickHandler(SkIntToScalar(x), |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 309 | SkIntToScalar(y), modifierKeys); |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 310 | |
| 311 | if (click) { |
| 312 | click->fOwner = owner; |
| 313 | *fClicks.append() = click; |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 314 | SkView::DoClickDown(click, x, y, modifierKeys); |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 315 | handled = true; |
| 316 | } |
| 317 | break; |
| 318 | } |
| 319 | case Click::kMoved_State: |
| 320 | if (index != -1) { |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 321 | SkView::DoClickMoved(fClicks[index], x, y, modifierKeys); |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 322 | handled = true; |
| 323 | } |
| 324 | break; |
| 325 | case Click::kUp_State: |
| 326 | if (index != -1) { |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 327 | SkView::DoClickUp(fClicks[index], x, y, modifierKeys); |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 328 | delete fClicks[index]; |
| 329 | fClicks.remove(index); |
| 330 | handled = true; |
| 331 | } |
| 332 | break; |
| 333 | default: |
| 334 | // Do nothing |
| 335 | break; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 336 | } |
| 337 | return handled; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 338 | } |