Skip to content

Instantly share code, notes, and snippets.

@balazs
Created Oct 18, 2012
Embed
What would you like to do?
diff --git a/Source/WebKit2/UIProcess/API/mac/WKView.mm b/Source/WebKit2/UIProcess/API/mac/WKView.mm
index e4a6e6b..42ef662 100644
--- a/Source/WebKit2/UIProcess/API/mac/WKView.mm
+++ b/Source/WebKit2/UIProcess/API/mac/WKView.mm
@@ -1862,105 +1862,6 @@ static NSString * const windowDidOrderOffScreenNotification = @"NSWindowDidOrder
static NSString * const windowDidChangeBackingPropertiesNotification = @"NSWindowDidChangeBackingPropertiesNotification";
static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOldScaleFactorKey";
-- (void)_wk_updateWindowObserversForWindow:(NSWindow *)window
-{
- for (id observer in _data->_observers.get())
- [[NSNotificationCenter defaultCenter] removeObserver:observer];
- [_data->_observers.get() removeAllObjects];
-
- if (!window)
- return;
-
- if (!_data->_observers)
- _data->_observers = adoptNS([[NSMutableArray alloc] init]);
-
- #define ADD_OBSERVER(selectorName, notificationName, notificationObject) \
- [_data->_observers.get() addObject:[[NSNotificationCenter defaultCenter] \
- addObserverForName:notificationName object:notificationObject queue:[NSOperationQueue mainQueue] \
- usingBlock:^(NSNotification *notification){ [self selectorName:notification]; }] \
- ];
-
- ADD_OBSERVER(_wk_windowDidBecomeKey, NSWindowDidBecomeKeyNotification, nil);
- ADD_OBSERVER(_wk_windowDidChangeBackingProperties, windowDidChangeBackingPropertiesNotification, window);
- ADD_OBSERVER(_wk_windowDidChangeScreen, NSWindowDidChangeScreenNotification, window);
- ADD_OBSERVER(_wk_windowDidDeminiaturize, NSWindowDidDeminiaturizeNotification, window);
- ADD_OBSERVER(_wk_windowDidMiniaturize, NSWindowDidMiniaturizeNotification, window);
- ADD_OBSERVER(_wk_windowDidMove, NSWindowDidMoveNotification, window);
- ADD_OBSERVER(_wk_windowDidOrderOffScreen, windowDidOrderOffScreenNotification, window);
- ADD_OBSERVER(_wk_windowDidOrderOnScreen, windowDidBecomeVisibleNotification, window);
- ADD_OBSERVER(_wk_windowDidResignKey, NSWindowDidResignKeyNotification, nil);
- ADD_OBSERVER(_wk_windowDidResize, NSWindowDidResizeNotification, window);
-
- #undef ADD_OBSERVER
-}
-
-- (void)viewWillMoveToWindow:(NSWindow *)window
-{
- NSWindow *currentWindow = [self window];
- if (window == currentWindow)
- return;
-
-#if __MAC_OS_X_VERSION_MIN_REQUIRED == 1070
- // Avoid calling the code added in 121482 that ensures that the undo stack is cleaned up
- // before the WKView is moved from one window to another when the WKView is being moved
- // out of a popover window. This avoids a bug in OS X 10.7 that was fixed in 10.8.
- // While this technically reopens a potentially crashing code path that 121482 closed,
- // it only reopens it for WKViews that are used for text editing and that are removed
- // from an NSPopover at some time earlier than tear-down of the NSPopover.
- if (![currentWindow isKindOfClass:NSClassFromString(@"_NSPopoverWindow")])
-#endif
- _data->_pageClient->viewWillMoveToAnotherWindow();
-
- [self _wk_updateWindowObserversForWindow:window];
-
-#if __MAC_OS_X_VERSION_MIN_REQUIRED == 1060
- if ([currentWindow _growBoxOwner] == self)
- [currentWindow _setShowOpaqueGrowBoxForOwner:nil];
-#endif
-}
-
-- (void)viewDidMoveToWindow
-{
- // We want to make sure to update the active state while hidden, so if the view is about to become visible, we
- // update the active state first and then make it visible. If the view is about to be hidden, we hide it first and then
- // update the active state.
- if ([self window]) {
- _data->_windowHasValidBackingStore = NO;
- [self _wk_updateWindowVisibility];
- _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
- _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible | WebPageProxy::ViewIsInWindow);
- [self _wk_updateWindowAndViewFrames];
-
- if (!_data->_flagsChangedEventMonitor) {
- _data->_flagsChangedEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSFlagsChangedMask handler:^(NSEvent *flagsChangedEvent) {
- [self _wk_postFakeMouseMovedEventForFlagsChangedEvent:flagsChangedEvent];
- return flagsChangedEvent;
- }];
- }
-
- [self _wk_accessibilityRegisterUIProcessTokens];
- } else {
- [self _wk_updateWindowVisibility];
- _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible);
- _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive | WebPageProxy::ViewIsInWindow);
-
- [NSEvent removeMonitor:_data->_flagsChangedEventMonitor];
- _data->_flagsChangedEventMonitor = nil;
-
-#if ENABLE(GESTURE_EVENTS)
- if (_data->_endGestureMonitor) {
- [NSEvent removeMonitor:_data->_endGestureMonitor];
- _data->_endGestureMonitor = nil;
- }
-#endif
-#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
- WKHideWordDefinitionWindow();
-#endif
- }
-
- _data->_page->setIntrinsicDeviceScaleFactor([self _wk_intrinsicDeviceScaleFactor]);
-}
-
- (void)_wk_windowScreenDidChange
{
_data->_page->windowScreenDidChange((PlatformDisplayID)[[[[[self window] screen] deviceDescription] objectForKey:@"NSScreenNumber"] intValue]);
@@ -2067,6 +1968,109 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
CGContextRestoreGState(context);
}
+- (void)_wk_updateWindowObserversForWindow:(NSWindow *)window
+{
+ for (id observer in _data->_observers.get())
+ [[NSNotificationCenter defaultCenter] removeObserver:observer];
+ [_data->_observers.get() removeAllObjects];
+
+ if (!window)
+ return;
+
+ if (!_data->_observers)
+ _data->_observers = adoptNS([[NSMutableArray alloc] init]);
+
+ #define ADD_OBSERVER(selectorName, notificationName, notificationObject) \
+ [_data->_observers.get() addObject:[[NSNotificationCenter defaultCenter] \
+ addObserverForName:notificationName object:notificationObject queue:[NSOperationQueue mainQueue] \
+ usingBlock:^(NSNotification *notification){ [self selectorName:notification]; }] \
+ ];
+
+ ADD_OBSERVER(_wk_windowDidBecomeKey, NSWindowDidBecomeKeyNotification, nil);
+ ADD_OBSERVER(_wk_windowDidChangeBackingProperties, windowDidChangeBackingPropertiesNotification, window);
+ ADD_OBSERVER(_wk_windowDidChangeScreen, NSWindowDidChangeScreenNotification, window);
+ ADD_OBSERVER(_wk_windowDidDeminiaturize, NSWindowDidDeminiaturizeNotification, window);
+ ADD_OBSERVER(_wk_windowDidMiniaturize, NSWindowDidMiniaturizeNotification, window);
+ ADD_OBSERVER(_wk_windowDidMove, NSWindowDidMoveNotification, window);
+ ADD_OBSERVER(_wk_windowDidOrderOffScreen, windowDidOrderOffScreenNotification, window);
+ ADD_OBSERVER(_wk_windowDidOrderOnScreen, windowDidBecomeVisibleNotification, window);
+ ADD_OBSERVER(_wk_windowDidResignKey, NSWindowDidResignKeyNotification, nil);
+ ADD_OBSERVER(_wk_windowDidResize, NSWindowDidResizeNotification, window);
+
+ #undef ADD_OBSERVER
+}
+
+- (void)viewWillMoveToWindow:(NSWindow *)window
+{
+ NSWindow *currentWindow = [self window];
+ if (window == currentWindow)
+ return;
+
+#if __MAC_OS_X_VERSION_MIN_REQUIRED == 1070
+ // Avoid calling the code added in 121482 that ensures that the undo stack is cleaned up
+ // before the WKView is moved from one window to another when the WKView is being moved
+ // out of a popover window. This avoids a bug in OS X 10.7 that was fixed in 10.8.
+ // While this technically reopens a potentially crashing code path that 121482 closed,
+ // it only reopens it for WKViews that are used for text editing and that are removed
+ // from an NSPopover at some time earlier than tear-down of the NSPopover.
+ if (![currentWindow isKindOfClass:NSClassFromString(@"_NSPopoverWindow")])
+#endif
+ _data->_pageClient->viewWillMoveToAnotherWindow();
+
+ [self _wk_updateWindowObserversForWindow:window];
+
+#if __MAC_OS_X_VERSION_MIN_REQUIRED == 1060
+ if ([currentWindow _growBoxOwner] == self)
+ [currentWindow _setShowOpaqueGrowBoxForOwner:nil];
+#endif
+}
+
+- (void)viewDidMoveToWindow
+{
+ // We want to make sure to update the active state while hidden, so if the view is about to become visible, we
+ // update the active state first and then make it visible. If the view is about to be hidden, we hide it first and then
+ // update the active state.
+ if ([self window]) {
+ _data->_windowHasValidBackingStore = NO;
+ [self _wk_updateWindowVisibility];
+ _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
+ _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible | WebPageProxy::ViewIsInWindow);
+ [self _wk_updateWindowAndViewFrames];
+
+ if (!_data->_flagsChangedEventMonitor) {
+ _data->_flagsChangedEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSFlagsChangedMask handler:^(NSEvent *flagsChangedEvent) {
+ [self _wk_postFakeMouseMovedEventForFlagsChangedEvent:flagsChangedEvent];
+ return flagsChangedEvent;
+ }];
+ }
+
+ [self _wk_accessibilityRegisterUIProcessTokens];
+ } else {
+ [self _wk_updateWindowVisibility];
+ _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible);
+ _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive | WebPageProxy::ViewIsInWindow);
+
+ [NSEvent removeMonitor:_data->_flagsChangedEventMonitor];
+ _data->_flagsChangedEventMonitor = nil;
+
+#if ENABLE(GESTURE_EVENTS)
+ if (_data->_endGestureMonitor) {
+ [NSEvent removeMonitor:_data->_endGestureMonitor];
+ _data->_endGestureMonitor = nil;
+ }
+#endif
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+ WKHideWordDefinitionWindow();
+#endif
+ }
+
+ _data->_page->setIntrinsicDeviceScaleFactor([self _wk_intrinsicDeviceScaleFactor]);
+}
+
+
+
+
+
- (void)drawRect:(NSRect)rect
{
LOG(View, "drawRect: x:%g, y:%g, width:%g, height:%g", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment