gfx/skia/trunk/include/views/SkEventSink.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/views/SkEventSink.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,112 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2006 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkEventSink_DEFINED
    1.14 +#define SkEventSink_DEFINED
    1.15 +
    1.16 +#include "SkRefCnt.h"
    1.17 +#include "SkEvent.h"
    1.18 +
    1.19 +struct SkTagList;
    1.20 +
    1.21 +/** \class SkEventSink
    1.22 +
    1.23 +    SkEventSink is the base class for all objects that receive SkEvents.
    1.24 +*/
    1.25 +class SkEventSink : public SkRefCnt {
    1.26 +public:
    1.27 +    SK_DECLARE_INST_COUNT(SkEventSink)
    1.28 +
    1.29 +             SkEventSink();
    1.30 +    virtual ~SkEventSink();
    1.31 +
    1.32 +    /**
    1.33 +     *  Returns this eventsink's unique ID. Use this to post SkEvents to
    1.34 +     *  this eventsink.
    1.35 +     */
    1.36 +    SkEventSinkID getSinkID() const { return fID; }
    1.37 +
    1.38 +    /**
    1.39 +     *  Call this to pass an event to this object for processing. Returns true if the
    1.40 +     *  event was handled.
    1.41 +     */
    1.42 +    bool doEvent(const SkEvent&);
    1.43 +
    1.44 +    /** Returns true if the sink (or one of its subclasses) understands the event as a query.
    1.45 +        If so, the sink may modify the event to communicate its "answer".
    1.46 +    */
    1.47 +    bool doQuery(SkEvent* query);
    1.48 +
    1.49 +    /**
    1.50 +     *  Add sinkID to the list of listeners, to receive events from calls to sendToListeners()
    1.51 +     *  and postToListeners(). If sinkID already exists in the listener list, no change is made.
    1.52 +     */
    1.53 +    void addListenerID(SkEventSinkID sinkID);
    1.54 +
    1.55 +    /**
    1.56 +     *  Copy listeners from one event sink to another, typically from parent to child.
    1.57 +     *  @param from the event sink to copy the listeners from
    1.58 +     */
    1.59 +    void copyListeners(const SkEventSink& from);
    1.60 +
    1.61 +    /**
    1.62 +     *  Remove sinkID from the list of listeners. If sinkID does not appear in the list,
    1.63 +     *  no change is made.
    1.64 +     */
    1.65 +    void removeListenerID(SkEventSinkID);
    1.66 +
    1.67 +    /**
    1.68 +     *  Returns true if there are 1 or more listeners attached to this eventsink
    1.69 +     */
    1.70 +    bool hasListeners() const;
    1.71 +
    1.72 +    /**
    1.73 +     *  Posts a copy of evt to each of the eventsinks in the lisener list.
    1.74 +     *  This ignores the targetID and target proc in evt.
    1.75 +     */
    1.76 +    void postToListeners(const SkEvent& evt, SkMSec delay = 0);
    1.77 +
    1.78 +    enum EventResult {
    1.79 +        kHandled_EventResult,       //!< the eventsink returned true from its doEvent method
    1.80 +        kNotHandled_EventResult,    //!< the eventsink returned false from its doEvent method
    1.81 +        kSinkNotFound_EventResult   //!< no matching eventsink was found for the event's getSink().
    1.82 +    };
    1.83 +
    1.84 +    /**
    1.85 +     *  DoEvent handles dispatching the event to its target ID or proc.
    1.86 +     */
    1.87 +    static EventResult DoEvent(const SkEvent&);
    1.88 +
    1.89 +    /**
    1.90 +     *  Returns the matching eventsink, or null if not found
    1.91 +     */
    1.92 +    static SkEventSink* FindSink(SkEventSinkID);
    1.93 +
    1.94 +protected:
    1.95 +    /** Override this to handle events in your subclass. Be sure to call the inherited version
    1.96 +        for events that you don't handle.
    1.97 +    */
    1.98 +    virtual bool onEvent(const SkEvent&);
    1.99 +    virtual bool onQuery(SkEvent*);
   1.100 +
   1.101 +    SkTagList*  findTagList(U8CPU tag) const;
   1.102 +    void        addTagList(SkTagList*);
   1.103 +    void        removeTagList(U8CPU tag);
   1.104 +
   1.105 +private:
   1.106 +    SkEventSinkID   fID;
   1.107 +    SkTagList*      fTagHead;
   1.108 +
   1.109 +    // for our private link-list
   1.110 +    SkEventSink*    fNextSink;
   1.111 +
   1.112 +    typedef SkRefCnt INHERITED;
   1.113 +};
   1.114 +
   1.115 +#endif

mercurial