SkView.h revision f03bb566e25ace918f8fdda3cb8426626a00894c
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" 17f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com#include "SkMatrix.h" 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkCanvas; 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkLayerView; 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkView 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView is the base class for screen management. All widgets and controls inherit 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com from SkView. 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkView : public SkEventSink { 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Flag_Shift { 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kVisible_Shift, 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kEnabled_Shift, 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFocusable_Shift, 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexH_Shift, 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexV_Shift, 35f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com kNoClip_Shift, 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlagShiftCount 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Flag_Mask { 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kVisible_Mask = 1 << kVisible_Shift, //!< set if the view is visible 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kEnabled_Mask = 1 << kEnabled_Shift, //!< set if the view is enabled 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFocusable_Mask = 1 << kFocusable_Shift, //!< set if the view can receive focus 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexH_Mask = 1 << kFlexH_Shift, //!< set if the view's width is stretchable 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexV_Mask = 1 << kFlexV_Shift, //!< set if the view's height is stretchable 45f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com kNoClip_Mask = 1 << kNoClip_Shift, //!< set if the view is not clipped to its bounds 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kAllFlagMasks = (uint32_t)(0 - 1) >> (32 - kFlagShiftCount) 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView(uint32_t flags = 0); 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkView(); 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the flags associated with the view 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t getFlags() const { return fFlags; } 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the flags associated with the view 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setFlags(uint32_t flags); 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper that returns non-zero if the kVisible_Mask bit is set in the view's flags 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int isVisible() const { return fFlags & kVisible_Mask; } 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int isEnabled() const { return fFlags & kEnabled_Mask; } 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int isFocusable() const { return fFlags & kFocusable_Mask; } 65f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int isClipToBounds() const { return !(fFlags & kNoClip_Mask); } 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper to set/clear the view's kVisible_Mask flag */ 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setVisibleP(bool); 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setEnabledP(bool); 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setFocusableP(bool); 70f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com void setClipToBounds(bool); 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's width */ 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar width() const { return fWidth; } 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's height */ 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar height() const { return fHeight; } 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the view's width and height. These must both be >= 0. This does not affect the view's loc */ 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setSize(SkScalar width, SkScalar height); 788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setSize(const SkPoint& size) { this->setSize(size.fX, size.fY); } 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setWidth(SkScalar width) { this->setSize(width, fHeight); } 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setHeight(SkScalar height) { this->setSize(fWidth, height); } 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a rectangle set to [0, 0, width, height] */ 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void getLocalBounds(SkRect* bounds) const; 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 84f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com /** Loc - the view's offset with respect to its parent in its view hiearchy. 85f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com NOTE: For more complex transforms, use Local Matrix. The tranformations 86f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com are applied in the following order: 87f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com canvas->translate(fLoc.fX, fLoc.fY); 88f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com canvas->concat(fMatrix); 89f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com */ 908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's left edge */ 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar locX() const { return fLoc.fX; } 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's top edge */ 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar locY() const { return fLoc.fY; } 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the view's left and top edge. This does not affect the view's size */ 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLoc(SkScalar x, SkScalar y); 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLoc(const SkPoint& loc) { this->setLoc(loc.fX, loc.fY); } 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLocX(SkScalar x) { this->setLoc(x, fLoc.fY); } 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLocY(SkScalar y) { this->setLoc(fLoc.fX, y); } 99f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com 100f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com /** Local Matrix - matrix used to tranform the view with respect to its 101f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com parent in its view hiearchy. Use setLocalMatrix to apply matrix 102f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com transformations to the current view and in turn affect its children. 103f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com NOTE: For simple offsets, use Loc. The transformations are applied in 104f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com the following order: 105f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com canvas->translate(fLoc.fX, fLoc.fY); 106f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com canvas->concat(fMatrix); 107f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com */ 108f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com const SkMatrix& getLocalMatrix() const { return fMatrix; } 109f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com void setLocalMatrix(const SkMatrix& matrix); 110f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com 1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Offset (move) the view by the specified dx and dy. This does not affect the view's size */ 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void offset(SkScalar dx, SkScalar dy); 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to have the view draw into the specified canvas. */ 115e522ca5d5f249bd51a00cb68bb051f811d0a9e85reed@android.com virtual void draw(SkCanvas* canvas); 116e522ca5d5f249bd51a00cb68bb051f811d0a9e85reed@android.com 1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to invalidate part of all of a view, requesting that the view's 1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw method be called. The rectangle parameter specifies the part of the view 1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com that should be redrawn. If it is null, it specifies the entire view bounds. 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inval(SkRect* rectOrNull); 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Focus management 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* getFocusView() const; 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool hasFocus() const; 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum FocusDirection { 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kNext_FocusDirection, 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPrev_FocusDirection, 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFocusDirectionCount 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool acceptFocus(); 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* moveFocus(FocusDirection); 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Click handling 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Click { 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Click(SkView* target); 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~Click(); 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* getType() const { return fType; } 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool isType(const char type[]) const; 1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setType(const char type[]); // does NOT make a copy of the string 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void copyType(const char type[]); // makes a copy of the string 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum State { 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kDown_State, 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kMoved_State, 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kUp_State 1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint fOrig, fPrev, fCurr; 1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint fIOrig, fIPrev, fICurr; 1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com State fState; 157d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo void* fOwner; 1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkEventSinkID fTargetID; 1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com char* fType; 1618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool fWeOwnTheType; 1628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void resetType(); 1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkView; 1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Click* findClickHandler(SkScalar x, SkScalar y); 1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void DoClickDown(Click*, int x, int y); 1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void DoClickMoved(Click*, int x, int y); 1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com static void DoClickUp(Click*, int x, int y); 1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Send the event to the view's parent, and its parent etc. until one of them 1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true from its onEvent call. This view is returned. If no parent handles 1758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the event, null is returned. 17634245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com */ 1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* sendEventToParents(const SkEvent&); 17834245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com /** Send the query to the view's parent, and its parent etc. until one of them 17934245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com returns true from its onQuery call. This view is returned. If no parent handles 18034245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com the query, null is returned. 18134245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com */ 18234245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com SkView* sendQueryToParents(SkEvent*); 18334245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com 1848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // View hierarchy management 1858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's parent, or null if it has none. This does not affect the parent's reference count. */ 1878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* getParent() const { return fParent; } 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* attachChildToFront(SkView* child); 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the child view to this view, and increment the child's reference count. The child view is added 1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com such that it will be drawn before all other child views. 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The child view parameter is returned. 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* attachChildToBack(SkView* child); 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** If the view has a parent, detach the view from its parent and decrement the view's reference count. 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If the parent was the only owner of the view, this will cause the view to be deleted. 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void detachFromParent(); 1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the child view to this view, and increment the child's reference count. The child view is added 1998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com such that it will be drawn after all other child views. 2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The child view parameter is returned. 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Detach all child views from this view. */ 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void detachAllChildren(); 2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Convert the specified point from global coordinates into view-local coordinates 2068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void globalToLocal(SkPoint* pt) const { if (pt) this->globalToLocal(pt->fX, pt->fY, pt); } 2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Convert the specified x,y from global coordinates into view-local coordinates, returning 2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the answer in the local parameter. 2108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void globalToLocal(SkScalar globalX, SkScalar globalY, SkPoint* local) const; 2128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class F2BIter 2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Iterator that will return each of this view's children, in 2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com front-to-back order (the order used for clicking). The first 2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call to next() returns the front-most child view. When 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com next() returns null, there are no more child views. 2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class F2BIter { 2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com F2BIter(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 B2FIter 2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Iterator that will return each of this view's children, in 2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com back-to-front order (the order they are drawn). The first 2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call to next() returns the back-most child view. When 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com next() returns null, there are no more child views. 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class B2FIter { 2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com B2FIter(const SkView* parent); 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* next(); 2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fFirstChild, *fChild; 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class Artist 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Install a subclass of this in a view (calling setArtist()), and then the 2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default implementation of that view's onDraw() will invoke this object 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com automatically. 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Artist : public SkRefCnt { 2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void draw(SkView*, SkCanvas*); 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inflate(const SkDOM&, const SkDOM::Node*); 2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com protected: 2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onDraw(SkView*, SkCanvas*) = 0; 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onInflate(const SkDOM&, const SkDOM::Node*); 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the artist attached to this view (or null). The artist's reference 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count is not affected. 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Artist* getArtist() const; 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the specified artist (or null) to the view, replacing any existing 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com artist. If the new artist is not null, its reference count is incremented. 2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The artist parameter is returned. 2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Artist* setArtist(Artist* artist); 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class Layout 2688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Install a subclass of this in a view (calling setLayout()), and then the 2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default implementation of that view's onLayoutChildren() will invoke 2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this object automatically. 2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Layout : public SkRefCnt { 2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void layoutChildren(SkView* parent); 2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inflate(const SkDOM&, const SkDOM::Node*); 2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com protected: 2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onLayoutChildren(SkView* parent) = 0; 2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onInflate(const SkDOM&, const SkDOM::Node*); 2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the layout attached to this view (or null). The layout's reference 2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count is not affected. 2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Layout* getLayout() const; 2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the specified layout (or null) to the view, replacing any existing 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com layout. If the new layout is not null, its reference count is incremented. 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The layout parameter is returned. 2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Layout* setLayout(Layout*, bool invokeLayoutNow = true); 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** If a layout is attached to this view, call its layoutChildren() method 2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void invokeLayout(); 2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to initialize this view based on the specified XML node 2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inflate(const SkDOM& dom, const SkDOM::Node* node); 2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** After a view hierarchy is inflated, this may be called with a dictionary 2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com containing pairs of <name, view*>, where the name string was the view's 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com "id" attribute when it was inflated. 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This will call the virtual onPostInflate for this view, and the recursively 3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call postInflate on all of the view's children. 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void postInflate(const SkTDict<SkView*>& ids); 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(void dump(bool recurse) const;) 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to draw inside the view. Be sure to call the inherited version too */ 3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onDraw(SkCanvas*); 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to be notified when the view's size changes. Be sure to call the inherited version too */ 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onSizeChange(); 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this if you want to handle an inval request from this view or one of its children. 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Tyically this is only overridden by the by the "window". If your subclass does handle the 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com request, return true so the request will not continue to propogate to the parent. 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 318f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com virtual bool handleInval(const SkRect*); 3196c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called once before all of the children are drawn (or clipped/translated) 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual SkCanvas* beforeChildren(SkCanvas* c) { return c; } 3216c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called once after all of the children are drawn (or clipped/translated) 3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void afterChildren(SkCanvas* orig) {} 3236c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com 3246c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called right before this child's onDraw is called 3256c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com virtual void beforeChild(SkView* child, SkCanvas* canvas) {} 3266c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called right after this child's onDraw is called 3276c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com virtual void afterChild(SkView* child, SkCanvas* canvas) {} 3286c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com 3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this if you might handle the click 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 331e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com virtual Click* onFindClickHandler(SkScalar x, SkScalar y); 332e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com /** Override this to decide if your children are targets for a click. 333e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com The default returns true, in which case your children views will be 334e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com candidates for onFindClickHandler. Returning false wil skip the children 335e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com and just call your onFindClickHandler. 336e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com */ 337e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com virtual bool onSendClickToChildren(SkScalar x, SkScalar y); 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to track clicks, returning true as long as you want to track 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the pen/mouse. 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool onClick(Click*); 3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to initialize your subclass from the XML node. Be sure to call the inherited version too */ 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node); 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this if you want to perform post initialization work based on the ID dictionary built 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com during XML parsing. Be sure to call the inherited version too. 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onPostInflate(const SkTDict<SkView*>&); 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // default action is to inval the view 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onFocusChange(bool gainFocusP); 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // override these if you're acting as a layer/host 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool onGetFocusView(SkView**) const { return false; } 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool onSetFocusView(SkView*) { return false; } 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fWidth, fHeight; 360f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com SkMatrix fMatrix; 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint fLoc; 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fParent; 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fFirstChild; 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fNextSibling; 3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fPrevSibling; 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fFlags; 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fContainsFocus; 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class B2FIter; 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class F2BIter; 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkLayerView; 3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setFocusView(SkView* fvOrNull); 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* acceptFocus(FocusDirection); 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void detachFromParent_NoLayout(); 377f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com /** Compute the matrix to transform view-local coordinates into global ones */ 378f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com void localToGlobal(SkMatrix* matrix) const; 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 383