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