diff options
author | 2011-08-03 19:41:24 +0000 | |
---|---|---|
committer | 2011-08-03 19:41:24 +0000 | |
commit | c514dde99e10fb3dbfff5a15537211a7eb094365 (patch) | |
tree | e309517c6ecfb794b28991a526cadd5f04835a57 | |
parent | 81c3f8de1cbb93a8b99d730a75ab16d864612e95 (diff) |
allow events to store their target sink ID
git-svn-id: http://skia.googlecode.com/svn/trunk@2036 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/views/SkEvent.h | 46 | ||||
-rw-r--r-- | src/views/SkEvent.cpp | 28 |
2 files changed, 53 insertions, 21 deletions
diff --git a/include/views/SkEvent.h b/include/views/SkEvent.h index f2726894f0..71a2a72527 100644 --- a/include/views/SkEvent.h +++ b/include/views/SkEvent.h @@ -43,8 +43,6 @@ public: SkEvent(const SkEvent& src); ~SkEvent(); -// /** Return the event's type (will never be null) */ -// const char* getType() const; /** Copy the event's type into the specified SkString parameter */ void getType(SkString* str) const; /** Returns true if the event's type matches exactly the specified type (case sensitive) */ @@ -60,6 +58,17 @@ public: */ void setType(const char type[], size_t len = 0); + /** + * Return the target ID, or 0 if there is none. + */ + SkEventSinkID getTargetID() const { return fTargetID; } + + /** + * Set the target ID for this event. 0 means none. Can be specified when + * the event is posted or sent. + */ + void setTargetID(SkEventSinkID targetID) { fTargetID = targetID; } + /** Return the event's unnamed 32bit field. Default value is 0 */ uint32_t getFast32() const { return f32; } /** Set the event's unnamed 32bit field. In XML, use @@ -159,17 +168,40 @@ public: */ static bool PostTime(SkEvent* evt, SkEventSinkID targetID, SkMSec time); + /** + * Post to the event queue using the event's targetID. If this is 0, then + * false is returned and the event is deleted, otherwise true is returned + * and ownership of the event passes to the event queue. + */ + bool post() { + return this->postDelay(0); + } + + /** + * Post to the event queue using the event's targetID and the specifed + * millisecond delay. If the event's targetID is 0, then false is returned + * and the event is deleted, otherwise true is returned and ownership of + * the event passes to the event queue. + */ + bool postDelay(SkMSec delay); + + /** + * Post to the event queue using the event's targetID and the specifed + * millisecond time. If the event's targetID is 0, then false is returned + * and the event is deleted, otherwise true is returned and ownership of + * the event passes to the event queue. + */ + bool postTime(SkMSec time); + /** Helper method for calling SkEvent::PostTime(this, ...), where the caller specifies a delay. The real "time" will be computed automatically by sampling the clock and adding its value to delay. */ - bool post(SkEventSinkID sinkID, SkMSec delay = 0) - { + bool post(SkEventSinkID sinkID, SkMSec delay = 0) { return SkEvent::Post(this, sinkID, delay); } - void postTime(SkEventSinkID sinkID, SkMSec time) - { + void postTime(SkEventSinkID sinkID, SkMSec time) { SkEvent::PostTime(this, sinkID, time); } @@ -232,10 +264,10 @@ private: SkMetaData fMeta; mutable char* fType; // may be characters with low bit set to know that it is not a pointer uint32_t f32; + SkEventSinkID fTargetID; SkDEBUGCODE(bool fDebugTrace;) // these are for our implementation of the event queue - SkEventSinkID fTargetID; SkMSec fTime; SkEvent* fNextEvent; // either in the delay or normal event queue void initialize(const char* type, size_t typeLen); diff --git a/src/views/SkEvent.cpp b/src/views/SkEvent.cpp index 2c09bc3bcb..d330636207 100644 --- a/src/views/SkEvent.cpp +++ b/src/views/SkEvent.cpp @@ -58,20 +58,6 @@ static size_t makeCharArray(char* buffer, size_t compact) return strlen(buffer); } -#if 0 -const char* SkEvent::getType() const -{ - if ((size_t) fType & 1) { // not a pointer - char chars[sizeof(size_t) + 1]; - size_t len = makeCharArray(chars, (size_t) fType); - fType = (char*) sk_malloc_throw(len); - SkASSERT(((size_t) fType & 1) == 0); - memcpy(fType, chars, len); - } - return fType; -} -#endif - void SkEvent::getType(SkString* str) const { if (str) @@ -370,6 +356,20 @@ bool SkEvent::PostTime(SkEvent* evt, SkEventSinkID sinkID, SkMSec time) return true; } +bool SkEvent::postDelay(SkMSec delay) { + return SkEvent::Post(this, this->getTargetID(), delay); +} + +bool SkEvent::postTime(SkMSec time) { + SkEventSinkID target = this->getTargetID(); + if (target) { + return SkEvent::PostTime(this, target, time); + } else { + delete this; + return false; + } +} + bool SkEvent::Enqueue(SkEvent* evt) { SkEvent_Globals& globals = *(SkEvent_Globals*)SkGlobals::Find(SK_Event_GlobalsTag, create_globals); |