SkWindow.cpp revision f9bb7a8e2052d21e6a7f48d5b73d2ef97637a09e
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkWindow.h" 28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h" 3f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com#include "SkDevice.h" 48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkOSMenu.h" 58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkSystemEventTypes.h" 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTime.h" 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SK_EventDelayInval "\xd" "n" "\xa" "l" 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define TEST_BOUNDERx 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBounder.h" 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass test_bounder : public SkBounder { 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com test_bounder(const SkBitmap& bm) : fCanvas(bm) {} 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool onIRect(const SkIRect& r) 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRect rr; 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rr.set(SkIntToScalar(r.fLeft), SkIntToScalar(r.fTop), 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIntToScalar(r.fRight), SkIntToScalar(r.fBottom)); 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPaint p; 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setStyle(SkPaint::kStroke_Style); 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p.setColor(SK_ColorYELLOW); 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if 0 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rr.inset(SK_ScalarHalf, SK_ScalarHalf); 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#else 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com rr.inset(-SK_ScalarHalf, -SK_ScalarHalf); 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fCanvas.drawRect(rr, p); 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkCanvas fCanvas; 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkWindow::SkWindow() : fFocusView(NULL) 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClick = NULL; 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fWaitingOnInval = false; 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_BUILD_FOR_WINCE 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fConfig = SkBitmap::kRGB_565_Config; 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#else 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fConfig = SkBitmap::kARGB_8888_Config; 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 52f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 53f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fMatrix.reset(); 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkWindow::~SkWindow() 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com delete fClick; 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fMenus.deleteAll(); 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 63f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkWindow::setMatrix(const SkMatrix& matrix) { 64f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fMatrix != matrix) { 65f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fMatrix = matrix; 66f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->inval(NULL); 67f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 68f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com} 69f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 70f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkWindow::preConcat(const SkMatrix& matrix) { 71f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkMatrix m; 72f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com m.setConcat(fMatrix, matrix); 73f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->setMatrix(m); 74f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com} 75f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 76f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkWindow::postConcat(const SkMatrix& matrix) { 77f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkMatrix m; 78f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com m.setConcat(matrix, fMatrix); 79f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->setMatrix(m); 80f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com} 81f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkWindow::setConfig(SkBitmap::Config config) 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->resize(fBitmap.width(), fBitmap.height(), config); 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkWindow::resize(int width, int height, SkBitmap::Config config) 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (config == SkBitmap::kNo_Config) 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com config = fConfig; 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (width != fBitmap.width() || height != fBitmap.height() || config != fConfig) 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fConfig = config; 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBitmap.setConfig(config, width, height); 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBitmap.allocPixels(); 97f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fBitmap.setIsOpaque(true); 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->setSize(SkIntToScalar(width), SkIntToScalar(height)); 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->inval(NULL); 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkWindow::eraseARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) 1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBitmap.eraseARGB(a, r, g, b); 1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkWindow::eraseRGB(U8CPU r, U8CPU g, U8CPU b) 1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fBitmap.eraseRGB(r, g, b); 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 114f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.combool SkWindow::handleInval(const SkRect* localR) 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIRect ir; 1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 118f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (localR) { 119f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkRect devR; 120f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkMatrix inverse; 121f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (!fMatrix.invert(&inverse)) { 122f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com return false; 123f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 124f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fMatrix.mapRect(&devR, *localR); 125f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com devR.round(&ir); 126f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 127f9bb7a8e2052d21e6a7f48d5b73d2ef97637a09ereed@google.com ir.set(0, 0, 128f9bb7a8e2052d21e6a7f48d5b73d2ef97637a09ereed@google.com SkScalarRound(this->width()), 129f9bb7a8e2052d21e6a7f48d5b73d2ef97637a09ereed@google.com SkScalarRound(this->height())); 130f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fDirtyRgn.op(ir, SkRegion::kUnion_Op); 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->onHandleInval(ir); 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 137f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkWindow::forceInvalAll() { 138f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fDirtyRgn.setRect(0, 0, this->width(), this->height()); 139f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com} 140f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if defined(SK_BUILD_FOR_WINCE) && defined(USE_GX_SCREEN) 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #include <windows.h> 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com #include <gx.h> 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com extern GXDisplayProperties gDisplayProps; 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_SIMULATE_FAILED_MALLOC 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comextern bool gEnableControlledThrow; 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 151f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.combool SkWindow::update(SkIRect* updateArea, SkCanvas* canvas) 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (!fDirtyRgn.isEmpty()) 1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBitmap bm = this->getBitmap(); 1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if defined(SK_BUILD_FOR_WINCE) && defined(USE_GX_SCREEN) 1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com char* buffer = (char*)GXBeginDraw(); 1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkASSERT(buffer); 1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com RECT rect; 1628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com GetWindowRect((HWND)((SkOSWindow*)this)->getHWND(), &rect); 1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com buffer += rect.top * gDisplayProps.cbyPitch + rect.left * gDisplayProps.cbxPitch; 1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bm.setPixels(buffer); 1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 168f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkCanvas rasterCanvas; 169f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkDevice* device; 170f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 171f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (NULL == canvas) { 172f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com canvas = &rasterCanvas; 173f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com device = new SkDevice(canvas, bm, false); 174f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com canvas->setDevice(device)->unref(); 175f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 176f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com canvas->setBitmapDevice(bm); 177f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 179f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com canvas->clipRegion(fDirtyRgn); 1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (updateArea) 1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *updateArea = fDirtyRgn.getBounds(); 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 183f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkAutoCanvasRestore acr(canvas, true); 184f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com canvas->concat(fMatrix); 185f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // empty this now, so we can correctly record any inval calls that 1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // might be made during the draw call. 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fDirtyRgn.setEmpty(); 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef TEST_BOUNDER 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com test_bounder b(bm); 192f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com canvas->setBounder(&b); 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_SIMULATE_FAILED_MALLOC 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com gEnableControlledThrow = true; 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_BUILD_FOR_WIN32 198f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com //try { 199f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->draw(canvas); 200f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com //} 201f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com //catch (...) { 202f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com //} 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#else 204f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->draw(canvas); 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 2068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_SIMULATE_FAILED_MALLOC 2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com gEnableControlledThrow = false; 2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef TEST_BOUNDER 210f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com canvas->setBounder(NULL); 2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if defined(SK_BUILD_FOR_WINCE) && defined(USE_GX_SCREEN) 2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com GXEndDraw(); 2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkWindow::handleChar(SkUnichar uni) 2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (this->onHandleChar(uni)) 2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* focus = this->getFocusView(); 2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (focus == NULL) 2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com focus = this; 2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkEvent evt(SK_EventType_Unichar); 2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com evt.setFast32(uni); 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return focus->doEvent(evt); 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkWindow::handleKey(SkKey key) 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (key == kNONE_SkKey) 2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (this->onHandleKey(key)) 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // send an event to the focus-view 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* focus = this->getFocusView(); 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (focus == NULL) 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com focus = this; 2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkEvent evt(SK_EventType_Key); 2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com evt.setFast32(key); 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (focus->doEvent(evt)) 2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (key == kUp_SkKey || key == kDown_SkKey) 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (this->moveFocus(key == kUp_SkKey ? kPrev_FocusDirection : kNext_FocusDirection) == NULL) 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->onSetFocusView(NULL); 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkWindow::handleKeyUp(SkKey key) 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (key == kNONE_SkKey) 2688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (this->onHandleKeyUp(key)) 2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //send an event to the focus-view 2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 2758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* focus = this->getFocusView(); 2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (focus == NULL) 2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com focus = this; 2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //should this one be the same? 2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkEvent evt(SK_EventType_KeyUp); 2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com evt.setFast32(key); 2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (focus->doEvent(evt)) 2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkWindow::addMenu(SkOSMenu* menu) 2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *fMenus.append() = menu; 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->onAddMenu(menu); 2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2940ae6b245f2b79bc04f0801b08fcf05abcf98fd6creed@android.comvoid SkWindow::setTitle(const char title[]) { 2950ae6b245f2b79bc04f0801b08fcf05abcf98fd6creed@android.com if (NULL == title) { 2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com title = ""; 2970ae6b245f2b79bc04f0801b08fcf05abcf98fd6creed@android.com } 2980ae6b245f2b79bc04f0801b08fcf05abcf98fd6creed@android.com fTitle.set(title); 2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->onSetTitle(title); 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkWindow::handleMenu(uint32_t cmd) 3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < fMenus.count(); i++) 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkEvent* evt = fMenus[i]->createEvent(cmd); 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (evt) 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com evt->post(this->getSinkID()); 3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com////////////////////////////////////////////////////////////////////// 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkWindow::onEvent(const SkEvent& evt) 3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (evt.isType(SK_EventDelayInval)) 3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkRegion::Iterator iter(fDirtyRgn); 3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (; !iter.done(); iter.next()) 3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->onHandleInval(iter.rect()); 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fWaitingOnInval = false; 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return this->INHERITED::onEvent(evt); 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkWindow::onGetFocusView(SkView** focus) const 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (focus) 3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *focus = fFocusView; 3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkWindow::onSetFocusView(SkView* focus) 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fFocusView != focus) 3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fFocusView) 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fFocusView->onFocusChange(false); 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fFocusView = focus; 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (focus) 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com focus->onFocusChange(true); 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com////////////////////////////////////////////////////////////////////// 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkWindow::onHandleInval(const SkIRect&) 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkWindow::onHandleChar(SkUnichar) 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkWindow::onHandleKey(SkKey key) 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkWindow::onHandleKeyUp(SkKey key) 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkWindow::handleClick(int x, int y, Click::State state) 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com{ 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool handled = false; 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com switch (state) { 3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case Click::kDown_State: 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClick) 3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com delete fClick; 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClick = this->findClickHandler(SkIntToScalar(x), SkIntToScalar(y)); 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClick) 3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView::DoClickDown(fClick, x, y); 3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com handled = true; 3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case Click::kMoved_State: 3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClick) 3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView::DoClickMoved(fClick, x, y); 3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com handled = true; 3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com case Click::kUp_State: 3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (fClick) 3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView::DoClickUp(fClick, x, y); 3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com delete fClick; 4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fClick = NULL; 4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com handled = true; 4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com break; 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return handled; 4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 408