gfx/skia/trunk/src/views/mac/SkEventNotifier.mm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2011 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9 #import "SkEventNotifier.h"
michael@0 10 #include "SkEvent.h"
michael@0 11 #define SkEventClass @"SkEvenClass"
michael@0 12 @implementation SkEventNotifier
michael@0 13 - (id)init {
michael@0 14 self = [super init];
michael@0 15 if (self) {
michael@0 16 //Register as an observer for SkEventClass events and call
michael@0 17 //receiveSkEvent: upon receiving the event
michael@0 18 [[NSNotificationCenter defaultCenter] addObserver:self
michael@0 19 selector:@selector(receiveSkEvent:)
michael@0 20 name:SkEventClass
michael@0 21 object:nil];
michael@0 22 }
michael@0 23 return self;
michael@0 24 }
michael@0 25
michael@0 26 - (void)dealloc {
michael@0 27 [[NSNotificationCenter defaultCenter] removeObserver:self];
michael@0 28 [super dealloc];
michael@0 29 }
michael@0 30
michael@0 31 -(BOOL) acceptsFirstResponder {
michael@0 32 return YES;
michael@0 33 }
michael@0 34
michael@0 35 //SkEvent Handers
michael@0 36 - (void)receiveSkEvent:(NSNotification *)notification {
michael@0 37 if(SkEvent::ProcessEvent())
michael@0 38 SkEvent::SignalNonEmptyQueue();
michael@0 39 }
michael@0 40
michael@0 41 + (void)postTimedSkEvent:(NSTimeInterval)timeInterval {
michael@0 42 [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self
michael@0 43 selector:@selector(timerFireMethod:)
michael@0 44 userInfo:nil repeats:NO];
michael@0 45 }
michael@0 46
michael@0 47 + (void)timerFireMethod:(NSTimer*)theTimer {
michael@0 48 SkEvent::ServiceQueueTimer();
michael@0 49 }
michael@0 50
michael@0 51 @end
michael@0 52 ////////////////////////////////////////////////////////////////////////////////
michael@0 53 void SkEvent::SignalNonEmptyQueue() {
michael@0 54 //post a SkEventClass event to the default notification queue
michael@0 55 NSNotification* notification = [NSNotification notificationWithName:SkEventClass object:nil];
michael@0 56 [[NSNotificationQueue defaultQueue] enqueueNotification:notification
michael@0 57 postingStyle:NSPostWhenIdle
michael@0 58 coalesceMask:NSNotificationNoCoalescing
michael@0 59 forModes:nil];
michael@0 60 }
michael@0 61
michael@0 62 void SkEvent::SignalQueueTimer(SkMSec delay) {
michael@0 63 if (delay) {
michael@0 64 //Convert to seconds
michael@0 65 NSTimeInterval ti = delay/(float)SK_MSec1;
michael@0 66 [SkEventNotifier postTimedSkEvent:ti];
michael@0 67 }
michael@0 68 }

mercurial