00001 /* 00002 * Copyright (C) 2006 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SkEventSink_DEFINED 00018 #define SkEventSink_DEFINED 00019 00020 #include "SkRefCnt.h" 00021 #include "SkEvent.h" 00022 00023 struct SkTagList; 00024 00029 class SkEventSink : public SkRefCnt { 00030 public: 00031 SkEventSink(); 00032 virtual ~SkEventSink(); 00033 00037 SkEventSinkID getSinkID() const { return fID; } 00038 00042 bool doEvent(const SkEvent&); 00046 bool doQuery(SkEvent* query); 00047 00051 void addListenerID(SkEventSinkID sinkID); 00055 void copyListeners(const SkEventSink& from); 00059 void removeListenerID(SkEventSinkID); 00062 bool hasListeners() const; 00065 void postToListeners(const SkEvent& evt, SkMSec delay = 0); 00066 00067 enum EventResult { 00068 kHandled_EventResult, 00069 kNotHandled_EventResult, 00070 kSinkNotFound_EventResult 00071 }; 00077 static EventResult DoEvent(const SkEvent&, SkEventSinkID targetID); 00078 00081 static SkEventSink* FindSink(SkEventSinkID); 00082 00083 protected: 00087 virtual bool onEvent(const SkEvent&); 00088 virtual bool onQuery(SkEvent*); 00089 00090 SkTagList* findTagList(U8CPU tag) const; 00091 void addTagList(SkTagList*); 00092 void removeTagList(U8CPU tag); 00093 00094 private: 00095 SkEventSinkID fID; 00096 SkTagList* fTagHead; 00097 00098 // for our private link-list 00099 SkEventSink* fNextSink; 00100 }; 00101 00102 #endif 00103