1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkEventSink_DEFINED
11 #define SkEventSink_DEFINED
12 
13 #include "SkRefCnt.h"
14 #include "SkEvent.h"
15 
16 /** \class SkEventSink
17 
18     SkEventSink is the base class for all objects that receive SkEvents.
19 */
20 class SkEventSink : public SkRefCnt {
21 public:
22 
23 
24              SkEventSink();
25     virtual ~SkEventSink();
26 
27     /**
28      *  Returns this eventsink's unique ID. Use this to post SkEvents to
29      *  this eventsink.
30      */
31     SkEventSinkID getSinkID() const { return fID; }
32 
33     /**
34      *  Call this to pass an event to this object for processing. Returns true if the
35      *  event was handled.
36      */
37     bool doEvent(const SkEvent&);
38 
39     /** Returns true if the sink (or one of its subclasses) understands the event as a query.
40         If so, the sink may modify the event to communicate its "answer".
41     */
42     bool doQuery(SkEvent* query);
43 
44     /**
45      *  Returns the matching eventsink, or null if not found
46      */
47     static SkEventSink* FindSink(SkEventSinkID);
48 
49 protected:
50     /** Override this to handle events in your subclass. Be sure to call the inherited version
51         for events that you don't handle.
52     */
53     virtual bool onEvent(const SkEvent&);
54     virtual bool onQuery(SkEvent*);
55 
56 private:
57     SkEventSinkID   fID;
58 
59     // for our private link-list
60     SkEventSink*    fNextSink;
61 
62     typedef SkRefCnt INHERITED;
63 };
64 
65 #endif
66