180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkView_DEFINED 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkView_DEFINED 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkEventSink.h" 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkRect.h" 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDOM.h" 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTDict.h" 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkMatrix.h" 18d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger#include "SkMetaData.h" 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkCanvas; 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkLayerView; 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** \class SkView 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView is the base class for screen management. All widgets and controls inherit 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru from SkView. 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru*/ 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkView : public SkEventSink { 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru enum Flag_Shift { 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kVisible_Shift, 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kEnabled_Shift, 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kFocusable_Shift, 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kFlexH_Shift, 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kFlexV_Shift, 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kNoClip_Shift, 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kFlagShiftCount 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru enum Flag_Mask { 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kVisible_Mask = 1 << kVisible_Shift, //!< set if the view is visible 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kEnabled_Mask = 1 << kEnabled_Shift, //!< set if the view is enabled 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kFocusable_Mask = 1 << kFocusable_Shift, //!< set if the view can receive focus 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kFlexH_Mask = 1 << kFlexH_Shift, //!< set if the view's width is stretchable 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kFlexV_Mask = 1 << kFlexV_Shift, //!< set if the view's height is stretchable 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kNoClip_Mask = 1 << kNoClip_Shift, //!< set if the view is not clipped to its bounds 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kAllFlagMasks = (uint32_t)(0 - 1) >> (32 - kFlagShiftCount) 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView(uint32_t flags = 0); 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual ~SkView(); 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Return the flags associated with the view 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru uint32_t getFlags() const { return fFlags; } 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Set the flags associated with the view 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setFlags(uint32_t flags); 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Helper that returns non-zero if the kVisible_Mask bit is set in the view's flags 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int isVisible() const { return fFlags & kVisible_Mask; } 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int isEnabled() const { return fFlags & kEnabled_Mask; } 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int isFocusable() const { return fFlags & kFocusable_Mask; } 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int isClipToBounds() const { return !(fFlags & kNoClip_Mask); } 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Helper to set/clear the view's kVisible_Mask flag */ 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setVisibleP(bool); 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setEnabledP(bool); 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setFocusableP(bool); 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setClipToBounds(bool); 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Return the view's width */ 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar width() const { return fWidth; } 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Return the view's height */ 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar height() const { return fHeight; } 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Set the view's width and height. These must both be >= 0. This does not affect the view's loc */ 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setSize(SkScalar width, SkScalar height); 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setSize(const SkPoint& size) { this->setSize(size.fX, size.fY); } 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setWidth(SkScalar width) { this->setSize(width, fHeight); } 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setHeight(SkScalar height) { this->setSize(fWidth, height); } 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Return a rectangle set to [0, 0, width, height] */ 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void getLocalBounds(SkRect* bounds) const; 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Loc - the view's offset with respect to its parent in its view hiearchy. 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru NOTE: For more complex transforms, use Local Matrix. The tranformations 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru are applied in the following order: 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru canvas->translate(fLoc.fX, fLoc.fY); 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru canvas->concat(fMatrix); 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Return the view's left edge */ 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar locX() const { return fLoc.fX; } 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Return the view's top edge */ 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar locY() const { return fLoc.fY; } 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Set the view's left and top edge. This does not affect the view's size */ 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setLoc(SkScalar x, SkScalar y); 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setLoc(const SkPoint& loc) { this->setLoc(loc.fX, loc.fY); } 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setLocX(SkScalar x) { this->setLoc(x, fLoc.fY); } 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setLocY(SkScalar y) { this->setLoc(fLoc.fX, y); } 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Local Matrix - matrix used to tranform the view with respect to its 10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru parent in its view hiearchy. Use setLocalMatrix to apply matrix 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru transformations to the current view and in turn affect its children. 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru NOTE: For simple offsets, use Loc. The transformations are applied in 10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru the following order: 10680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru canvas->translate(fLoc.fX, fLoc.fY); 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru canvas->concat(fMatrix); 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkMatrix& getLocalMatrix() const { return fMatrix; } 11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setLocalMatrix(const SkMatrix& matrix); 11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Offset (move) the view by the specified dx and dy. This does not affect the view's size */ 11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void offset(SkScalar dx, SkScalar dy); 11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Call this to have the view draw into the specified canvas. */ 11680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void draw(SkCanvas* canvas); 11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 11880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Call this to invalidate part of all of a view, requesting that the view's 11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru draw method be called. The rectangle parameter specifies the part of the view 12080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru that should be redrawn. If it is null, it specifies the entire view bounds. 12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void inval(SkRect* rectOrNull); 12380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // Focus management 12580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* getFocusView() const; 12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool hasFocus() const; 12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru enum FocusDirection { 13080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kNext_FocusDirection, 13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kPrev_FocusDirection, 13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kFocusDirectionCount 13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool acceptFocus(); 13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* moveFocus(FocusDirection); 13780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // Click handling 13980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru class Click { 14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru public: 14280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Click(SkView* target); 14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual ~Click(); 14480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const char* getType() const { return fType; } 14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool isType(const char type[]) const; 14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void setType(const char type[]); // does NOT make a copy of the string 14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void copyType(const char type[]); // makes a copy of the string 14980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru enum State { 15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kDown_State, 15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kMoved_State, 15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru kUp_State 15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkPoint fOrig, fPrev, fCurr; 15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkIPoint fIOrig, fIPrev, fICurr; 15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru State fState; 15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void* fOwner; 159d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger unsigned fModifierKeys; 160d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger 161d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger SkMetaData fMeta; 16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru private: 16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkEventSinkID fTargetID; 16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru char* fType; 16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool fWeOwnTheType; 16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void resetType(); 16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru friend class SkView; 17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 171d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger Click* findClickHandler(SkScalar x, SkScalar y, unsigned modifierKeys); 17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 173d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger static void DoClickDown(Click*, int x, int y, unsigned modi); 174d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger static void DoClickMoved(Click*, int x, int y, unsigned modi); 175d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger static void DoClickUp(Click*, int x, int y, unsigned modi); 17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 17780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Send the event to the view's parent, and its parent etc. until one of them 17880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru returns true from its onEvent call. This view is returned. If no parent handles 17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru the event, null is returned. 18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* sendEventToParents(const SkEvent&); 18280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Send the query to the view's parent, and its parent etc. until one of them 18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru returns true from its onQuery call. This view is returned. If no parent handles 18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru the query, null is returned. 18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* sendQueryToParents(SkEvent*); 18780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // View hierarchy management 18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Return the view's parent, or null if it has none. This does not affect the parent's reference count. */ 19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* getParent() const { return fParent; } 19280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* attachChildToFront(SkView* child); 19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Attach the child view to this view, and increment the child's reference count. The child view is added 19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru such that it will be drawn before all other child views. 19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru The child view parameter is returned. 19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 19780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* attachChildToBack(SkView* child); 19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** If the view has a parent, detach the view from its parent and decrement the view's reference count. 19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru If the parent was the only owner of the view, this will cause the view to be deleted. 20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void detachFromParent(); 20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Attach the child view to this view, and increment the child's reference count. The child view is added 20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru such that it will be drawn after all other child views. 20480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru The child view parameter is returned. 20580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Detach all child views from this view. */ 20780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void detachAllChildren(); 20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Convert the specified point from global coordinates into view-local coordinates 21080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Return true on success; false on failure 21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool globalToLocal(SkPoint* pt) const { 21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (NULL != pt) { 21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return this->globalToLocal(pt->fX, pt->fY, pt); 21580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; // nothing to do so return true 21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 21880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Convert the specified x,y from global coordinates into view-local coordinates, returning 21980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru the answer in the local parameter. 22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool globalToLocal(SkScalar globalX, SkScalar globalY, SkPoint* local) const; 22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 22380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** \class F2BIter 22480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 22580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Iterator that will return each of this view's children, in 22680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru front-to-back order (the order used for clicking). The first 22780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru call to next() returns the front-most child view. When 22880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru next() returns null, there are no more child views. 22980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 23080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru class F2BIter { 23180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru public: 23280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru F2BIter(const SkView* parent); 23380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* next(); 23480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru private: 23580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* fFirstChild, *fChild; 23680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 23780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 23880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** \class B2FIter 23980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 24080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Iterator that will return each of this view's children, in 24180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru back-to-front order (the order they are drawn). The first 24280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru call to next() returns the back-most child view. When 24380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru next() returns null, there are no more child views. 24480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 24580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru class B2FIter { 24680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru public: 24780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru B2FIter(const SkView* parent); 24880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* next(); 24980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru private: 25080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* fFirstChild, *fChild; 25180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 25280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 25380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** \class Artist 25480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 25580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Install a subclass of this in a view (calling setArtist()), and then the 25680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru default implementation of that view's onDraw() will invoke this object 25780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru automatically. 25880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 25980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru class Artist : public SkRefCnt { 26080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru public: 26180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_DECLARE_INST_COUNT(Artist) 26280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 26380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void draw(SkView*, SkCanvas*); 26480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void inflate(const SkDOM&, const SkDOM::Node*); 26580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru protected: 26680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void onDraw(SkView*, SkCanvas*) = 0; 26780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void onInflate(const SkDOM&, const SkDOM::Node*); 26880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru private: 26980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru typedef SkRefCnt INHERITED; 27080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 27180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Return the artist attached to this view (or null). The artist's reference 27280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru count is not affected. 27380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 27480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Artist* getArtist() const; 27580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Attach the specified artist (or null) to the view, replacing any existing 27680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru artist. If the new artist is not null, its reference count is incremented. 27780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru The artist parameter is returned. 27880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 27980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Artist* setArtist(Artist* artist); 28080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 28180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** \class Layout 28280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 28380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Install a subclass of this in a view (calling setLayout()), and then the 28480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru default implementation of that view's onLayoutChildren() will invoke 28580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru this object automatically. 28680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 28780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru class Layout : public SkRefCnt { 28880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru public: 28980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_DECLARE_INST_COUNT(Layout) 29080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 29180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void layoutChildren(SkView* parent); 29280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void inflate(const SkDOM&, const SkDOM::Node*); 29380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru protected: 29480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void onLayoutChildren(SkView* parent) = 0; 29580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void onInflate(const SkDOM&, const SkDOM::Node*); 29680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru private: 29780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru typedef SkRefCnt INHERITED; 29880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru }; 29980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 30080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Return the layout attached to this view (or null). The layout's reference 30180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru count is not affected. 30280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 30380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Layout* getLayout() const; 30480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Attach the specified layout (or null) to the view, replacing any existing 30580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru layout. If the new layout is not null, its reference count is incremented. 30680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru The layout parameter is returned. 30780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 30880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Layout* setLayout(Layout*, bool invokeLayoutNow = true); 30980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** If a layout is attached to this view, call its layoutChildren() method 31080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 31180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void invokeLayout(); 31280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 31380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Call this to initialize this view based on the specified XML node 31480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 31580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void inflate(const SkDOM& dom, const SkDOM::Node* node); 31680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** After a view hierarchy is inflated, this may be called with a dictionary 31780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru containing pairs of <name, view*>, where the name string was the view's 31880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru "id" attribute when it was inflated. 31980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 32080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru This will call the virtual onPostInflate for this view, and the recursively 32180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru call postInflate on all of the view's children. 32280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 32380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void postInflate(const SkTDict<SkView*>& ids); 32480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 32580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDEBUGCODE(void dump(bool recurse) const;) 32680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 32780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprotected: 32880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Override this to draw inside the view. Be sure to call the inherited version too */ 32980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void onDraw(SkCanvas*); 33080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Override this to be notified when the view's size changes. Be sure to call the inherited version too */ 33180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void onSizeChange(); 33280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Override this if you want to handle an inval request from this view or one of its children. 33380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru Tyically this is only overridden by the by the "window". If your subclass does handle the 33480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru request, return true so the request will not continue to propogate to the parent. 33580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 33680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual bool handleInval(const SkRect*); 33780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru //! called once before all of the children are drawn (or clipped/translated) 33880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual SkCanvas* beforeChildren(SkCanvas* c) { return c; } 33980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru //! called once after all of the children are drawn (or clipped/translated) 34080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void afterChildren(SkCanvas* orig) {} 34180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 34280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru //! called right before this child's onDraw is called 34380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void beforeChild(SkView* child, SkCanvas* canvas) {} 34480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru //! called right after this child's onDraw is called 34580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void afterChild(SkView* child, SkCanvas* canvas) {} 34680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 34780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Override this if you might handle the click 34880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 349d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger virtual Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi); 35080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Override this to decide if your children are targets for a click. 35180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru The default returns true, in which case your children views will be 35280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru candidates for onFindClickHandler. Returning false wil skip the children 35380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru and just call your onFindClickHandler. 35480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 355d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger virtual bool onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi); 35680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Override this to track clicks, returning true as long as you want to track 35780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru the pen/mouse. 35880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 35980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual bool onClick(Click*); 36080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Override this to initialize your subclass from the XML node. Be sure to call the inherited version too */ 36180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node); 36280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Override this if you want to perform post initialization work based on the ID dictionary built 36380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru during XML parsing. Be sure to call the inherited version too. 36480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 36580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void onPostInflate(const SkTDict<SkView*>&); 36680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 36780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 36858190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger#ifdef SK_DEBUG 36958190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger void validate() const; 37058190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger#else 37158190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger void validate() const {} 37258190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger#endif 37380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // default action is to inval the view 37480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual void onFocusChange(bool gainFocusP); 37558190644c30e1c4aa8e527f3503c58f841e0fcf3Derek Sollenberger 37680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprotected: 37780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 37880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // override these if you're acting as a layer/host 37980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual bool onGetFocusView(SkView**) const { return false; } 38080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual bool onSetFocusView(SkView*) { return false; } 38180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 38280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate: 38380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar fWidth, fHeight; 38480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkMatrix fMatrix; 38580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkPoint fLoc; 38680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* fParent; 38780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* fFirstChild; 38880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* fNextSibling; 38980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* fPrevSibling; 39080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru uint8_t fFlags; 39180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru uint8_t fContainsFocus; 39280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 39380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru friend class B2FIter; 39480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru friend class F2BIter; 39580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 39680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru friend class SkLayerView; 39780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 39880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool setFocusView(SkView* fvOrNull); 39980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkView* acceptFocus(FocusDirection); 40080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void detachFromParent_NoLayout(); 40180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Compute the matrix to transform view-local coordinates into global ones */ 40280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void localToGlobal(SkMatrix* matrix) const; 40380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 40480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 40580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 406