SkView.h revision ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976e
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkView_DEFINED 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkView_DEFINED 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkEventSink.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRect.h" 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDOM.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTDict.h" 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkCanvas; 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkLayerView; 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkView 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView is the base class for screen management. All widgets and controls inherit 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com from SkView. 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkView : public SkEventSink { 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Flag_Shift { 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kVisible_Shift, 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kEnabled_Shift, 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFocusable_Shift, 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexH_Shift, 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexV_Shift, 34f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com kNoClip_Shift, 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlagShiftCount 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Flag_Mask { 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kVisible_Mask = 1 << kVisible_Shift, //!< set if the view is visible 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kEnabled_Mask = 1 << kEnabled_Shift, //!< set if the view is enabled 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFocusable_Mask = 1 << kFocusable_Shift, //!< set if the view can receive focus 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexH_Mask = 1 << kFlexH_Shift, //!< set if the view's width is stretchable 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexV_Mask = 1 << kFlexV_Shift, //!< set if the view's height is stretchable 44f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com kNoClip_Mask = 1 << kNoClip_Shift, //!< set if the view is not clipped to its bounds 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kAllFlagMasks = (uint32_t)(0 - 1) >> (32 - kFlagShiftCount) 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView(uint32_t flags = 0); 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkView(); 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the flags associated with the view 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t getFlags() const { return fFlags; } 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the flags associated with the view 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setFlags(uint32_t flags); 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper that returns non-zero if the kVisible_Mask bit is set in the view's flags 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int isVisible() const { return fFlags & kVisible_Mask; } 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int isEnabled() const { return fFlags & kEnabled_Mask; } 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int isFocusable() const { return fFlags & kFocusable_Mask; } 64f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int isClipToBounds() const { return !(fFlags & kNoClip_Mask); } 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper to set/clear the view's kVisible_Mask flag */ 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setVisibleP(bool); 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setEnabledP(bool); 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setFocusableP(bool); 69f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com void setClipToBounds(bool); 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's width */ 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar width() const { return fWidth; } 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's height */ 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar height() const { return fHeight; } 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the view's width and height. These must both be >= 0. This does not affect the view's loc */ 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setSize(SkScalar width, SkScalar height); 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setSize(const SkPoint& size) { this->setSize(size.fX, size.fY); } 788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setWidth(SkScalar width) { this->setSize(width, fHeight); } 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setHeight(SkScalar height) { this->setSize(fWidth, height); } 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a rectangle set to [0, 0, width, height] */ 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void getLocalBounds(SkRect* bounds) const; 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's left edge */ 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar locX() const { return fLoc.fX; } 858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's top edge */ 868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar locY() const { return fLoc.fY; } 878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the view's left and top edge. This does not affect the view's size */ 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLoc(SkScalar x, SkScalar y); 898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLoc(const SkPoint& loc) { this->setLoc(loc.fX, loc.fY); } 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLocX(SkScalar x) { this->setLoc(x, fLoc.fY); } 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLocY(SkScalar y) { this->setLoc(fLoc.fX, y); } 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Offset (move) the view by the specified dx and dy. This does not affect the view's size */ 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void offset(SkScalar dx, SkScalar dy); 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to have the view draw into the specified canvas. */ 96e522ca5d5f249bd51a00cb68bb051f811d0a9e85reed@android.com virtual void draw(SkCanvas* canvas); 97e522ca5d5f249bd51a00cb68bb051f811d0a9e85reed@android.com 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to invalidate part of all of a view, requesting that the view's 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw method be called. The rectangle parameter specifies the part of the view 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com that should be redrawn. If it is null, it specifies the entire view bounds. 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inval(SkRect* rectOrNull); 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Focus management 1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* getFocusView() const; 1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool hasFocus() const; 1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum FocusDirection { 1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kNext_FocusDirection, 1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPrev_FocusDirection, 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFocusDirectionCount 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool acceptFocus(); 1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* moveFocus(FocusDirection); 1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Click handling 1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Click { 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Click(SkView* target); 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~Click(); 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* getType() const { return fType; } 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool isType(const char type[]) const; 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setType(const char type[]); // does NOT make a copy of the string 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void copyType(const char type[]); // makes a copy of the string 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum State { 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kDown_State, 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kMoved_State, 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kUp_State 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint fOrig, fPrev, fCurr; 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint fIOrig, fIPrev, fICurr; 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com State fState; 138d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo void* fOwner; 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkEventSinkID fTargetID; 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com char* fType; 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool fWeOwnTheType; 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void resetType(); 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkView; 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Click* findClickHandler(SkScalar x, SkScalar y); 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void DoClickDown(Click*, int x, int y); 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void DoClickMoved(Click*, int x, int y); 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void DoClickUp(Click*, int x, int y); 1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Send the event to the view's parent, and its parent etc. until one of them 1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true from its onEvent call. This view is returned. If no parent handles 1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the event, null is returned. 15734245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com */ 1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* sendEventToParents(const SkEvent&); 15934245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com /** Send the query to the view's parent, and its parent etc. until one of them 16034245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com returns true from its onQuery call. This view is returned. If no parent handles 16134245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com the query, null is returned. 16234245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com */ 16334245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com SkView* sendQueryToParents(SkEvent*); 16434245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com 1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Depricated helper function. Just call event->post(sinkID, delay); 1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool postEvent(SkEvent* evt, SkEventSinkID sinkID, SkMSec delay) { return evt->post(sinkID, delay); } 1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // View hierarchy management 1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's parent, or null if it has none. This does not affect the parent's reference count. */ 1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* getParent() const { return fParent; } 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* attachChildToFront(SkView* child); 1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the child view to this view, and increment the child's reference count. The child view is added 1758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com such that it will be drawn before all other child views. 1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The child view parameter is returned. 1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* attachChildToBack(SkView* child); 1798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** If the view has a parent, detach the view from its parent and decrement the view's reference count. 1808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If the parent was the only owner of the view, this will cause the view to be deleted. 1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void detachFromParent(); 1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the child view to this view, and increment the child's reference count. The child view is added 1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com such that it will be drawn after all other child views. 1858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The child view parameter is returned. 1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Detach all child views from this view. */ 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void detachAllChildren(); 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Convert the specified point from global coordinates into view-local coordinates 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void globalToLocal(SkPoint* pt) const { if (pt) this->globalToLocal(pt->fX, pt->fY, pt); } 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Convert the specified x,y from global coordinates into view-local coordinates, returning 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the answer in the local parameter. 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void globalToLocal(SkScalar globalX, SkScalar globalY, SkPoint* local) const; 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class F2BIter 1998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Iterator that will return each of this view's children, in 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com front-to-back order (the order used for clicking). The first 2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call to next() returns the front-most child view. When 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com next() returns null, there are no more child views. 2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class F2BIter { 2068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com F2BIter(const SkView* parent); 2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* next(); 2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 2108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fFirstChild, *fChild; 2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class B2FIter 2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Iterator that will return each of this view's children, in 2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com back-to-front order (the order they are drawn). The first 2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call to next() returns the back-most child view. When 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com next() returns null, there are no more child views. 2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class B2FIter { 2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com B2FIter(const SkView* parent); 2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* next(); 2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fFirstChild, *fChild; 2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class Artist 2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Install a subclass of this in a view (calling setArtist()), and then the 2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default implementation of that view's onDraw() will invoke this object 2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com automatically. 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Artist : public SkRefCnt { 2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void draw(SkView*, SkCanvas*); 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inflate(const SkDOM&, const SkDOM::Node*); 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com protected: 2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onDraw(SkView*, SkCanvas*) = 0; 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onInflate(const SkDOM&, const SkDOM::Node*); 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the artist attached to this view (or null). The artist's reference 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count is not affected. 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Artist* getArtist() const; 2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the specified artist (or null) to the view, replacing any existing 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com artist. If the new artist is not null, its reference count is incremented. 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The artist parameter is returned. 2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Artist* setArtist(Artist* artist); 2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class Layout 2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Install a subclass of this in a view (calling setLayout()), and then the 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default implementation of that view's onLayoutChildren() will invoke 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this object automatically. 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Layout : public SkRefCnt { 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void layoutChildren(SkView* parent); 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inflate(const SkDOM&, const SkDOM::Node*); 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com protected: 2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onLayoutChildren(SkView* parent) = 0; 2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onInflate(const SkDOM&, const SkDOM::Node*); 2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the layout attached to this view (or null). The layout's reference 2688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count is not affected. 2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Layout* getLayout() const; 2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the specified layout (or null) to the view, replacing any existing 2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com layout. If the new layout is not null, its reference count is incremented. 2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The layout parameter is returned. 2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Layout* setLayout(Layout*, bool invokeLayoutNow = true); 2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** If a layout is attached to this view, call its layoutChildren() method 2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void invokeLayout(); 2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to initialize this view based on the specified XML node 2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inflate(const SkDOM& dom, const SkDOM::Node* node); 2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** After a view hierarchy is inflated, this may be called with a dictionary 2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com containing pairs of <name, view*>, where the name string was the view's 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com "id" attribute when it was inflated. 2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This will call the virtual onPostInflate for this view, and the recursively 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call postInflate on all of the view's children. 2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void postInflate(const SkTDict<SkView*>& ids); 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(void dump(bool recurse) const;) 2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to draw inside the view. Be sure to call the inherited version too */ 2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onDraw(SkCanvas*); 2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to be notified when the view's size changes. Be sure to call the inherited version too */ 2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onSizeChange(); 2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this if you want to handle an inval request from this view or one of its children. 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Tyically this is only overridden by the by the "window". If your subclass does handle the 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com request, return true so the request will not continue to propogate to the parent. 3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 303f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com virtual bool handleInval(const SkRect*); 3046c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called once before all of the children are drawn (or clipped/translated) 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual SkCanvas* beforeChildren(SkCanvas* c) { return c; } 3066c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called once after all of the children are drawn (or clipped/translated) 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void afterChildren(SkCanvas* orig) {} 3086c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com 3096c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called right before this child's onDraw is called 3106c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com virtual void beforeChild(SkView* child, SkCanvas* canvas) {} 3116c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called right after this child's onDraw is called 3126c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com virtual void afterChild(SkView* child, SkCanvas* canvas) {} 3136c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this if you might handle the click 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 316e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com virtual Click* onFindClickHandler(SkScalar x, SkScalar y); 317e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com /** Override this to decide if your children are targets for a click. 318e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com The default returns true, in which case your children views will be 319e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com candidates for onFindClickHandler. Returning false wil skip the children 320e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com and just call your onFindClickHandler. 321e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com */ 322e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com virtual bool onSendClickToChildren(SkScalar x, SkScalar y); 3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to track clicks, returning true as long as you want to track 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the pen/mouse. 3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool onClick(Click*); 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to initialize your subclass from the XML node. Be sure to call the inherited version too */ 3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node); 3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this if you want to perform post initialization work based on the ID dictionary built 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com during XML parsing. Be sure to call the inherited version too. 3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onPostInflate(const SkTDict<SkView*>&); 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // default action is to inval the view 3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onFocusChange(bool gainFocusP); 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // override these if you're acting as a layer/host 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool onGetFocusView(SkView**) const { return false; } 3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool onSetFocusView(SkView*) { return false; } 3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fWidth, fHeight; 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint fLoc; 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fParent; 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fFirstChild; 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fNextSibling; 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fPrevSibling; 3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fFlags; 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fContainsFocus; 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class B2FIter; 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class F2BIter; 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkLayerView; 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setFocusView(SkView* fvOrNull); 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* acceptFocus(FocusDirection); 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void detachFromParent_NoLayout(); 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 365