1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/views/mac/SkEventNotifier.mm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 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 +#import "SkEventNotifier.h" 1.13 +#include "SkEvent.h" 1.14 +#define SkEventClass @"SkEvenClass" 1.15 +@implementation SkEventNotifier 1.16 +- (id)init { 1.17 + self = [super init]; 1.18 + if (self) { 1.19 + //Register as an observer for SkEventClass events and call 1.20 + //receiveSkEvent: upon receiving the event 1.21 + [[NSNotificationCenter defaultCenter] addObserver:self 1.22 + selector:@selector(receiveSkEvent:) 1.23 + name:SkEventClass 1.24 + object:nil]; 1.25 + } 1.26 + return self; 1.27 +} 1.28 + 1.29 +- (void)dealloc { 1.30 + [[NSNotificationCenter defaultCenter] removeObserver:self]; 1.31 + [super dealloc]; 1.32 +} 1.33 + 1.34 +-(BOOL) acceptsFirstResponder { 1.35 + return YES; 1.36 +} 1.37 + 1.38 +//SkEvent Handers 1.39 +- (void)receiveSkEvent:(NSNotification *)notification { 1.40 + if(SkEvent::ProcessEvent()) 1.41 + SkEvent::SignalNonEmptyQueue(); 1.42 +} 1.43 + 1.44 ++ (void)postTimedSkEvent:(NSTimeInterval)timeInterval { 1.45 + [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self 1.46 + selector:@selector(timerFireMethod:) 1.47 + userInfo:nil repeats:NO]; 1.48 +} 1.49 + 1.50 ++ (void)timerFireMethod:(NSTimer*)theTimer { 1.51 + SkEvent::ServiceQueueTimer(); 1.52 +} 1.53 + 1.54 +@end 1.55 +//////////////////////////////////////////////////////////////////////////////// 1.56 +void SkEvent::SignalNonEmptyQueue() { 1.57 + //post a SkEventClass event to the default notification queue 1.58 + NSNotification* notification = [NSNotification notificationWithName:SkEventClass object:nil]; 1.59 + [[NSNotificationQueue defaultQueue] enqueueNotification:notification 1.60 + postingStyle:NSPostWhenIdle 1.61 + coalesceMask:NSNotificationNoCoalescing 1.62 + forModes:nil]; 1.63 +} 1.64 + 1.65 +void SkEvent::SignalQueueTimer(SkMSec delay) { 1.66 + if (delay) { 1.67 + //Convert to seconds 1.68 + NSTimeInterval ti = delay/(float)SK_MSec1; 1.69 + [SkEventNotifier postTimedSkEvent:ti]; 1.70 + } 1.71 +}