SkView.h revision a22e2117e44efa4298dd0eb6df304a8166c8e9c3
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
20607ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com     *  Return true on success; false on failure
20707ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com     */
20807ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com    bool        globalToLocal(SkPoint* pt) const {
20907ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com        if (NULL != pt) {
21007ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com            return this->globalToLocal(pt->fX, pt->fY, pt);
21107ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com        }
21207ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com        return true;  // nothing to do so return true
21307ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com    }
2148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Convert the specified x,y from global coordinates into view-local coordinates, returning
2158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the answer in the local parameter.
2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
21707ef911f18e30566d8a9d790e0bd69a836fd9d24robertphillips@google.com    bool        globalToLocal(SkScalar globalX, SkScalar globalY, SkPoint* local) const;
2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** \class F2BIter
2208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Iterator that will return each of this view's children, in
2228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        front-to-back order (the order used for clicking). The first
2238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        call to next() returns the front-most child view. When
2248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        next() returns null, there are no more child views.
2258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class F2BIter {
2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        F2BIter(const SkView* parent);
2298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkView* next();
2308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    private:
2318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkView* fFirstChild, *fChild;
2328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** \class B2FIter
2358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Iterator that will return each of this view's children, in
2378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        back-to-front order (the order they are drawn). The first
2388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        call to next() returns the back-most child view. When
2398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        next() returns null, there are no more child views.
2408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class B2FIter {
2428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
2438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        B2FIter(const SkView* parent);
2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkView* next();
2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    private:
2468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkView* fFirstChild, *fChild;
2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** \class Artist
2508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Install a subclass of this in a view (calling setArtist()), and then the
2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        default implementation of that view's onDraw() will invoke this object
2538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        automatically.
2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class Artist : public SkRefCnt {
2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
257a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com        SK_DECLARE_INST_COUNT(Artist)
258a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com
2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void draw(SkView*, SkCanvas*);
2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void inflate(const SkDOM&, const SkDOM::Node*);
2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    protected:
2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        virtual void onDraw(SkView*, SkCanvas*) = 0;
2638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        virtual void onInflate(const SkDOM&, const SkDOM::Node*);
264a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com    private:
265a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com        typedef SkRefCnt INHERITED;
2668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
2678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the artist attached to this view (or null). The artist's reference
2688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        count is not affected.
2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Artist* getArtist() const;
2718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Attach the specified artist (or null) to the view, replacing any existing
2728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        artist. If the new artist is not null, its reference count is incremented.
2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The artist parameter is returned.
2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Artist* setArtist(Artist* artist);
2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** \class Layout
2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Install a subclass of this in a view (calling setLayout()), and then the
2808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        default implementation of that view's onLayoutChildren() will invoke
2818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        this object automatically.
2828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class Layout : public SkRefCnt {
2848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
285a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com        SK_DECLARE_INST_COUNT(Layout)
286a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com
2878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void layoutChildren(SkView* parent);
2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        void inflate(const SkDOM&, const SkDOM::Node*);
2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    protected:
2908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        virtual void onLayoutChildren(SkView* parent) = 0;
2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        virtual void onInflate(const SkDOM&, const SkDOM::Node*);
292a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com    private:
293a22e2117e44efa4298dd0eb6df304a8166c8e9c3robertphillips@google.com        typedef SkRefCnt INHERITED;
2948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
2968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Return the layout attached to this view (or null). The layout's reference
2978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        count is not affected.
2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
2998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Layout* getLayout() const;
3008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Attach the specified layout (or null) to the view, replacing any existing
3018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        layout. If the new layout is not null, its reference count is incremented.
3028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        The layout parameter is returned.
3038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Layout* setLayout(Layout*, bool invokeLayoutNow = true);
3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** If a layout is attached to this view, call its layoutChildren() method
3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    invokeLayout();
3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Call this to initialize this view based on the specified XML node
3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    inflate(const SkDOM& dom, const SkDOM::Node* node);
3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** After a view hierarchy is inflated, this may be called with a dictionary
3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        containing pairs of <name, view*>, where the name string was the view's
3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        "id" attribute when it was inflated.
3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This will call the virtual onPostInflate for this view, and the recursively
3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        call postInflate on all of the view's children.
3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    postInflate(const SkTDict<SkView*>& ids);
3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDEBUGCODE(void dump(bool recurse) const;)
3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Override this to draw inside the view. Be sure to call the inherited version too */
3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void    onDraw(SkCanvas*);
3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Override this to be notified when the view's size changes. Be sure to call the inherited version too */
3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void    onSizeChange();
3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Override this if you want to handle an inval request from this view or one of its children.
3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Tyically this is only overridden by the by the "window". If your subclass does handle the
3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        request, return true so the request will not continue to propogate to the parent.
3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
332f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com    virtual bool    handleInval(const SkRect*);
3336c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com    //! called once before all of the children are drawn (or clipped/translated)
3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual SkCanvas* beforeChildren(SkCanvas* c) { return c; }
3356c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com    //! called once after all of the children are drawn (or clipped/translated)
3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void afterChildren(SkCanvas* orig) {}
3376c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com
3386c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com    //! called right before this child's onDraw is called
3396c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com    virtual void beforeChild(SkView* child, SkCanvas* canvas) {}
3406c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com    //! called right after this child's onDraw is called
3416c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com    virtual void afterChild(SkView* child, SkCanvas* canvas) {}
3426c5f6f25b43f1210decb48956c1a2fbe5b58f889reed@android.com
3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Override this if you might handle the click
3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
345e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com    virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
346e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com    /** Override this to decide if your children are targets for a click.
347e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com        The default returns true, in which case your children views will be
348e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com        candidates for onFindClickHandler. Returning false wil skip the children
349e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com        and just call your onFindClickHandler.
350e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com     */
351e72fee513a5f903d6aa17066d2f3b79ac31f05dereed@android.com    virtual bool onSendClickToChildren(SkScalar x, SkScalar y);
3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Override this to track clicks, returning true as long as you want to track
3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the pen/mouse.
3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool    onClick(Click*);
3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Override this to initialize your subclass from the XML node. Be sure to call the inherited version too */
3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void    onInflate(const SkDOM& dom, const SkDOM::Node* node);
3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Override this if you want to perform post initialization work based on the ID dictionary built
3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        during XML parsing. Be sure to call the inherited version too.
3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    */
3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void    onPostInflate(const SkTDict<SkView*>&);
3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // default action is to inval the view
3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void    onFocusChange(bool gainFocusP);
3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // override these if you're acting as a layer/host
3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool    onGetFocusView(SkView**) const { return false; }
3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool    onSetFocusView(SkView*) { return false; }
3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkScalar    fWidth, fHeight;
374f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com    SkMatrix    fMatrix;
3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPoint     fLoc;
3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkView*     fParent;
3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkView*     fFirstChild;
3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkView*     fNextSibling;
3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkView*     fPrevSibling;
3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    uint8_t     fFlags;
3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    uint8_t     fContainsFocus;
3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class B2FIter;
3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class F2BIter;
3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkLayerView;
3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool    setFocusView(SkView* fvOrNull);
3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkView* acceptFocus(FocusDirection);
3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void    detachFromParent_NoLayout();
391f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com    /** Compute the matrix to transform view-local coordinates into global ones */
392f03bb566e25ace918f8fdda3cb8426626a00894creed@google.com    void    localToGlobal(SkMatrix* matrix) const;
3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
397