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" 1676a834a107af38fb2e85413bc7a46e555c444a85reed#include "../private/SkTDict.h" 17f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com#include "SkMatrix.h" 18e78dd4b529e1677dfb9ee395ddf9f89614b7e8eamike@reedtribe.org#include "SkMetaData.h" 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkCanvas; 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkLayerView; 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkView 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView is the base class for screen management. All widgets and controls inherit 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com from SkView. 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkView : public SkEventSink { 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Flag_Shift { 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kVisible_Shift, 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kEnabled_Shift, 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFocusable_Shift, 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexH_Shift, 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexV_Shift, 36f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com kNoClip_Shift, 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlagShiftCount 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Flag_Mask { 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kVisible_Mask = 1 << kVisible_Shift, //!< set if the view is visible 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kEnabled_Mask = 1 << kEnabled_Shift, //!< set if the view is enabled 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFocusable_Mask = 1 << kFocusable_Shift, //!< set if the view can receive focus 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexH_Mask = 1 << kFlexH_Shift, //!< set if the view's width is stretchable 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFlexV_Mask = 1 << kFlexV_Shift, //!< set if the view's height is stretchable 46f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com kNoClip_Mask = 1 << kNoClip_Shift, //!< set if the view is not clipped to its bounds 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kAllFlagMasks = (uint32_t)(0 - 1) >> (32 - kFlagShiftCount) 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView(uint32_t flags = 0); 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkView(); 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the flags associated with the view 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint32_t getFlags() const { return fFlags; } 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the flags associated with the view 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setFlags(uint32_t flags); 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper that returns non-zero if the kVisible_Mask bit is set in the view's flags 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int isVisible() const { return fFlags & kVisible_Mask; } 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int isEnabled() const { return fFlags & kEnabled_Mask; } 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int isFocusable() const { return fFlags & kFocusable_Mask; } 66f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com int isClipToBounds() const { return !(fFlags & kNoClip_Mask); } 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Helper to set/clear the view's kVisible_Mask flag */ 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setVisibleP(bool); 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setEnabledP(bool); 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setFocusableP(bool); 71f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com void setClipToBounds(bool); 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's width */ 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar width() const { return fWidth; } 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's height */ 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar height() const { return fHeight; } 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the view's width and height. These must both be >= 0. This does not affect the view's loc */ 788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setSize(SkScalar width, SkScalar height); 798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setSize(const SkPoint& size) { this->setSize(size.fX, size.fY); } 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setWidth(SkScalar width) { this->setSize(width, fHeight); } 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setHeight(SkScalar height) { this->setSize(fWidth, height); } 828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return a rectangle set to [0, 0, width, height] */ 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void getLocalBounds(SkRect* bounds) const; 848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 85f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com /** Loc - the view's offset with respect to its parent in its view hiearchy. 86fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com NOTE: For more complex transforms, use Local Matrix. The tranformations 87f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com are applied in the following order: 88fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com canvas->translate(fLoc.fX, fLoc.fY); 89f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com canvas->concat(fMatrix); 90f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com */ 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's left edge */ 928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar locX() const { return fLoc.fX; } 938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's top edge */ 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar locY() const { return fLoc.fY; } 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the view's left and top edge. This does not affect the view's size */ 968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLoc(SkScalar x, SkScalar y); 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLoc(const SkPoint& loc) { this->setLoc(loc.fX, loc.fY); } 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLocX(SkScalar x) { this->setLoc(x, fLoc.fY); } 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLocY(SkScalar y) { this->setLoc(fLoc.fX, y); } 100fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 101fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com /** Local Matrix - matrix used to tranform the view with respect to its 102fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com parent in its view hiearchy. Use setLocalMatrix to apply matrix 103f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com transformations to the current view and in turn affect its children. 104f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com NOTE: For simple offsets, use Loc. The transformations are applied in 105f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com the following order: 106fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com canvas->translate(fLoc.fX, fLoc.fY); 107f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com canvas->concat(fMatrix); 108f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com */ 109f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com const SkMatrix& getLocalMatrix() const { return fMatrix; } 110f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com void setLocalMatrix(const SkMatrix& matrix); 111f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com 1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Offset (move) the view by the specified dx and dy. This does not affect the view's size */ 1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void offset(SkScalar dx, SkScalar dy); 1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to have the view draw into the specified canvas. */ 116e522ca5d5f249bd51a00cb68bb051f811d0a9e85reed@android.com virtual void draw(SkCanvas* canvas); 117e522ca5d5f249bd51a00cb68bb051f811d0a9e85reed@android.com 1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to invalidate part of all of a view, requesting that the view's 1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com draw method be called. The rectangle parameter specifies the part of the view 1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com that should be redrawn. If it is null, it specifies the entire view bounds. 1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inval(SkRect* rectOrNull); 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Focus management 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* getFocusView() const; 1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool hasFocus() const; 1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum FocusDirection { 1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kNext_FocusDirection, 1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kPrev_FocusDirection, 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kFocusDirectionCount 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool acceptFocus(); 1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* moveFocus(FocusDirection); 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Click handling 1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Click { 1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Click(SkView* target); 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~Click(); 1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const char* getType() const { return fType; } 1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool isType(const char type[]) const; 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setType(const char type[]); // does NOT make a copy of the string 1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void copyType(const char type[]); // makes a copy of the string 1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum State { 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kDown_State, 1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kMoved_State, 1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kUp_State 1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint fOrig, fPrev, fCurr; 1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkIPoint fIOrig, fIPrev, fICurr; 1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com State fState; 158d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo void* fOwner; 1594d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com unsigned fModifierKeys; 160e78dd4b529e1677dfb9ee395ddf9f89614b7e8eamike@reedtribe.org 161e78dd4b529e1677dfb9ee395ddf9f89614b7e8eamike@reedtribe.org SkMetaData fMeta; 1628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkEventSinkID fTargetID; 1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com char* fType; 1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool fWeOwnTheType; 1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void resetType(); 1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkView; 1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 1714d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com Click* findClickHandler(SkScalar x, SkScalar y, unsigned modifierKeys); 1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1734d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com static void DoClickDown(Click*, int x, int y, unsigned modi); 1744d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com static void DoClickMoved(Click*, int x, int y, unsigned modi); 1754d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com static void DoClickUp(Click*, int x, int y, unsigned modi); 1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Send the event to the view's parent, and its parent etc. until one of them 1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com returns true from its onEvent call. This view is returned. If no parent handles 1798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the event, null is returned. 18034245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com */ 1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* sendEventToParents(const SkEvent&); 18234245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com /** Send the query to the view's parent, and its parent etc. until one of them 18334245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com returns true from its onQuery call. This view is returned. If no parent handles 18434245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com the query, null is returned. 18534245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com */ 18634245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com SkView* sendQueryToParents(SkEvent*); 18734245c7871f6339de8cc2be8fb1090ca3cba54efreed@android.com 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // View hierarchy management 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the view's parent, or null if it has none. This does not affect the parent's reference count. */ 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* getParent() const { return fParent; } 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* attachChildToFront(SkView* child); 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the child view to this view, and increment the child's reference count. The child view is added 1948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com such that it will be drawn before all other child views. 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The child view parameter is returned. 1968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* attachChildToBack(SkView* child); 1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** If the view has a parent, detach the view from its parent and decrement the view's reference count. 1998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com If the parent was the only owner of the view, this will cause the view to be deleted. 2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void detachFromParent(); 2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the child view to this view, and increment the child's reference count. The child view is added 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com such that it will be drawn after all other child views. 2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The child view parameter is returned. 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Detach all child views from this view. */ 2078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void detachAllChildren(); 2088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Convert the specified point from global coordinates into view-local coordinates 21007ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com * Return true on success; false on failure 21107ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com */ 212fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com bool globalToLocal(SkPoint* pt) const { 21349f085dddff10473b6ebf832a974288300224e60bsalomon if (pt) { 21407ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com return this->globalToLocal(pt->fX, pt->fY, pt); 21507ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com } 21607ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com return true; // nothing to do so return true 21707ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com } 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Convert the specified x,y from global coordinates into view-local coordinates, returning 2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the answer in the local parameter. 2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 22107ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com bool globalToLocal(SkScalar globalX, SkScalar globalY, SkPoint* local) const; 2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class F2BIter 224fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Iterator that will return each of this view's children, in 2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com front-to-back order (the order used for clicking). The first 2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call to next() returns the front-most child view. When 2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com next() returns null, there are no more child views. 2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class F2BIter { 2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com F2BIter(const SkView* parent); 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* next(); 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fFirstChild, *fChild; 2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class B2FIter 239fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Iterator that will return each of this view's children, in 2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com back-to-front order (the order they are drawn). The first 2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call to next() returns the back-most child view. When 2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com next() returns null, there are no more child views. 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class B2FIter { 2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com B2FIter(const SkView* parent); 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* next(); 2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fFirstChild, *fChild; 2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class Artist 254fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Install a subclass of this in a view (calling setArtist()), and then the 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default implementation of that view's onDraw() will invoke this object 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com automatically. 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Artist : public SkRefCnt { 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2612766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein 262a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com 2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void draw(SkView*, SkCanvas*); 2648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inflate(const SkDOM&, const SkDOM::Node*); 2658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com protected: 2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onDraw(SkView*, SkCanvas*) = 0; 2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onInflate(const SkDOM&, const SkDOM::Node*); 268a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com private: 269a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com typedef SkRefCnt INHERITED; 2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the artist attached to this view (or null). The artist's reference 2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count is not affected. 2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Artist* getArtist() const; 2758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the specified artist (or null) to the view, replacing any existing 2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com artist. If the new artist is not null, its reference count is incremented. 2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The artist parameter is returned. 2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Artist* setArtist(Artist* artist); 2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** \class Layout 282fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Install a subclass of this in a view (calling setLayout()), and then the 2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com default implementation of that view's onLayoutChildren() will invoke 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this object automatically. 2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com class Layout : public SkRefCnt { 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 2892766c00fc0b6a07d46e5f74cdad45da2ef625237mtklein 290a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void layoutChildren(SkView* parent); 2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inflate(const SkDOM&, const SkDOM::Node*); 2938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com protected: 2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onLayoutChildren(SkView* parent) = 0; 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onInflate(const SkDOM&, const SkDOM::Node*); 296a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com private: 297a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com typedef SkRefCnt INHERITED; 2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the layout attached to this view (or null). The layout's reference 3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com count is not affected. 3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Layout* getLayout() const; 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Attach the specified layout (or null) to the view, replacing any existing 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com layout. If the new layout is not null, its reference count is incremented. 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The layout parameter is returned. 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Layout* setLayout(Layout*, bool invokeLayoutNow = true); 3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** If a layout is attached to this view, call its layoutChildren() method 3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void invokeLayout(); 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Call this to initialize this view based on the specified XML node 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void inflate(const SkDOM& dom, const SkDOM::Node* node); 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** After a view hierarchy is inflated, this may be called with a dictionary 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com containing pairs of <name, view*>, where the name string was the view's 3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com "id" attribute when it was inflated. 3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This will call the virtual onPostInflate for this view, and the recursively 3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call postInflate on all of the view's children. 3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void postInflate(const SkTDict<SkView*>& ids); 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(void dump(bool recurse) const;) 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to draw inside the view. Be sure to call the inherited version too */ 3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onDraw(SkCanvas*); 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to be notified when the view's size changes. Be sure to call the inherited version too */ 3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onSizeChange(); 3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this if you want to handle an inval request from this view or one of its children. 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Tyically this is only overridden by the by the "window". If your subclass does handle the 3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com request, return true so the request will not continue to propogate to the parent. 3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 336f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com virtual bool handleInval(const SkRect*); 3376c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called once before all of the children are drawn (or clipped/translated) 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual SkCanvas* beforeChildren(SkCanvas* c) { return c; } 3396c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called once after all of the children are drawn (or clipped/translated) 340c87dd2ce965cd1bbc8a74abe0c141658a469d7f2djsollen virtual void afterChildren(SkCanvas*) {} 3416c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com 3426c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called right before this child's onDraw is called 343c87dd2ce965cd1bbc8a74abe0c141658a469d7f2djsollen virtual void beforeChild(SkView* /*child*/, SkCanvas*) {} 3446c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com //! called right after this child's onDraw is called 345c87dd2ce965cd1bbc8a74abe0c141658a469d7f2djsollen virtual void afterChild(SkView* /*child*/, SkCanvas*) {} 3466c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this if you might handle the click 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3494d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com virtual Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi); 350e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com /** Override this to decide if your children are targets for a click. 351e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com The default returns true, in which case your children views will be 352e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com candidates for onFindClickHandler. Returning false wil skip the children 353e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com and just call your onFindClickHandler. 354e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com */ 3554d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com virtual bool onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi); 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to track clicks, returning true as long as you want to track 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the pen/mouse. 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool onClick(Click*); 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this to initialize your subclass from the XML node. Be sure to call the inherited version too */ 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node); 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Override this if you want to perform post initialization work based on the ID dictionary built 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com during XML parsing. Be sure to call the inherited version too. 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onPostInflate(const SkTDict<SkView*>&); 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 368079813e2da59f35e2744af7a785d01d9f490e280reed@google.com#ifdef SK_DEBUG 369079813e2da59f35e2744af7a785d01d9f490e280reed@google.com void validate() const; 370079813e2da59f35e2744af7a785d01d9f490e280reed@google.com#else 371079813e2da59f35e2744af7a785d01d9f490e280reed@google.com void validate() const {} 372079813e2da59f35e2744af7a785d01d9f490e280reed@google.com#endif 3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // default action is to inval the view 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void onFocusChange(bool gainFocusP); 375079813e2da59f35e2744af7a785d01d9f490e280reed@google.com 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // override these if you're acting as a layer/host 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool onGetFocusView(SkView**) const { return false; } 3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool onSetFocusView(SkView*) { return false; } 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar fWidth, fHeight; 384f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com SkMatrix fMatrix; 3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint fLoc; 3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fParent; 3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fFirstChild; 3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fNextSibling; 3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* fPrevSibling; 3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fFlags; 3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fContainsFocus; 3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class B2FIter; 3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class F2BIter; 395fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkLayerView; 3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool setFocusView(SkView* fvOrNull); 3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* acceptFocus(FocusDirection); 4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void detachFromParent_NoLayout(); 401f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com /** Compute the matrix to transform view-local coordinates into global ones */ 402f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com void localToGlobal(SkMatrix* matrix) const; 4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 406