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