26 #include "../NativeWindowFromNode.h"
28 #include <nsIDOMWindow.h>
30 #include <nsComponentManagerUtils.h>
31 #include <nsServiceManagerUtils.h>
33 #import <objc/objc-class.h>
56 if ((
self = [super
init])) {
84 Method orig_method = nil, alt_method = nil;
87 orig_method = class_getInstanceMethod(aClass, orig_sel);
88 alt_method = class_getInstanceMethod(aClass, alt_sel);
91 if ((orig_method != nil) && (alt_method != nil)) {
95 temp_type = orig_method->method_types;
96 orig_method->method_types = alt_method->method_types;
97 alt_method->method_types = temp_type;
99 temp_imp = orig_method->method_imp;
100 orig_method->method_imp = alt_method->method_imp;
101 alt_method->method_imp = temp_imp;;
115 - (void)swizzledSendEvent:(NSEvent *)aEvent;
121 - (void)swizzledSendEvent:(NSEvent *)aEvent
125 @selector(swizzledSendEvent:),
126 @selector(sendEvent:));
128 [
self sendEvent:aEvent];
131 BOOL shouldReswizzle = YES;
132 if (NSLeftMouseUp == [aEvent type]) {
133 NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
134 [defaultCenter postNotificationName:kSBWindowStoppedMovingNotification
136 shouldReswizzle = NO;
142 if (shouldReswizzle) {
144 @selector(sendEvent:),
145 @selector(swizzledSendEvent:));
163 view:(NSView *)aView;
165 - (void)onWindowWillMove;
166 - (void)onWindowDidStopMoving:(NSNotification *)aNotification;
167 - (void)notifyListenerMoveStoppedTimeout;
176 if ((
self = [super
init])) {
187 [mWatchedView release];
195 nsCOMPtr<sbIWindowMoveListener>
listener =
197 NS_ENSURE_SUCCESS(rv, );
205 @selector(sendEvent:),
206 @selector(swizzledSendEvent:));
208 NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
209 [defaultCenter addObserver:self
210 selector:@selector(onWindowDidStopMoving:)
211 name:kSBWindowStoppedMovingNotification
215 - (void)onWindowDidStopMoving:(NSNotification *)aNotification
219 [
self performSelector:@selector(notifyListenerMoveStoppedTimeout)
224 [[NSNotificationCenter defaultCenter] removeObserver:self];
231 nsCOMPtr<sbIWindowMoveListener>
listener =
233 NS_ENSURE_SUCCESS(rv, );
248 - (void)windowWillMove:(NSNotification *)aNotification;
257 if ((
self = [super
init])) {
258 mListenerWinDict = [[NSMutableDictionary alloc] init];
268 [mListenerWinDict release];
273 - (void)beginObservingWindow:(NSWindow *)aWindow
277 [
self startListening];
282 NSView *contentView = [aWindow contentView];
288 [mListenerWinDict setObject:listenerContext
289 forKey:[NSNumber numberWithInt:[contentView hash]]];
292 - (void)stopObservingWindow:(NSWindow *)aWindow
295 NSView *contentView = [aWindow contentView];
298 NSNumber *viewHash = [NSNumber numberWithInt:[contentView hash]];
299 [mListenerWinDict removeObjectForKey:viewHash];
303 if ([mListenerWinDict
count] == 0) {
304 [
self stopListening];
308 - (void)startListening
315 NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
316 [defaultCenter addObserver:self
317 selector:@selector(windowWillMove:)
318 name:NSWindowWillMoveNotification
324 - (void)stopListening
330 [[NSNotificationCenter defaultCenter] removeObserver:self];
334 - (void)windowWillMove:(NSNotification *)aNotification
336 NSWindow *eventWindow = (NSWindow *)[aNotification
object];
338 NSView *contentView = [eventWindow contentView];
342 [NSNumber numberWithInt:[contentView
hash]]];
343 if (listenerContext) {
370 NS_ENSURE_TRUE(mWinListener, NS_ERROR_OUT_OF_MEMORY);
379 sbMacWindowMoveService::StartWatchingWindow(
383 NS_ENSURE_ARG_POINTER(aWindow);
384 NS_ENSURE_ARG_POINTER(aListener);
387 nsCOMPtr<nsISupports> supports = do_QueryInterface(aWindow, &rv);
388 NS_ENSURE_SUCCESS(rv, rv);
391 NS_ENSURE_TRUE(window, NS_ERROR_UNEXPECTED);
393 [mWinListener beginObservingWindow:window forListener:aListener];
398 sbMacWindowMoveService::StopWatchingWindow(
402 NS_ENSURE_ARG_POINTER(aWindow);
403 NS_ENSURE_ARG_POINTER(aListener);
406 nsCOMPtr<nsISupports> supports = do_QueryInterface(aWindow, &rv);
407 NS_ENSURE_SUCCESS(rv, rv);
410 NS_ENSURE_TRUE(window, NS_ERROR_UNEXPECTED);
412 [mWinListener stopObservingWindow:window forListener:aListener];
void notifyListenerMoveStoppedTimeout()
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
SBISupportsOwner * mListener
static NSString * kSBWindowStoppedMovingNotification
static void * get(nsISupports *window)
NS_DECL_ISUPPORTS NS_DECL_SBIWINDOWMOVESERVICE nsresult Init()
virtual ~sbMacWindowMoveService()
void MethodSwizzle(Class aClass, SEL orig_sel, SEL alt_sel)