Changeset 40468 in webkit
- Timestamp:
- Jan 31, 2009 4:59:19 PM (15 years ago)
- Location:
- trunk/WebKit/mac
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit/mac/ChangeLog
r40465 r40468 1 2009-01-31 John Sullivan <sullivan@apple.com> 2 3 https://bugs.webkit.org/show_bug.cgi?id=23665 4 5 Cleaned up code to add/remove NSNotification observers, to avoid performance hit 6 of calling removeObserver with unspecified notifications, or calling removeObserver 7 multiple times for the same notification. 8 9 Reviewed by Darin Adler 10 11 * WebView/WebHTMLView.mm: 12 added observingMouseMovedNotifications, observingSuperviewNotifications, and 13 observingWindowNotifications as BOOL ivars of _private object 14 (-[WebHTMLView _removeMouseMovedObserverUnconditionally]): 15 moved to file-internal section of file, added leading underscore, now bails out 16 if we aren't observing the relevant notifications, now records that we are no longer 17 observing the relevant notifications 18 (-[WebHTMLView _removeSuperviewObservers]): 19 ditto, also stores [NSNoticationCenter defaultCenter] in local var to avoid objc dispatch 20 (-[WebHTMLView _removeWindowObservers]): 21 ditto 22 (-[WebHTMLView close]): 23 replace general removeObserver: call with three specific calls for all the notifications 24 that this class actually observes 25 (-[WebHTMLView addMouseMovedObserver]): 26 bail out if already observing relevant notifications, now records that we are observing 27 the relevant notifications 28 (-[WebHTMLView removeMouseMovedObserver]): 29 updated for name change 30 (-[WebHTMLView addSuperviewObservers]): 31 bail out if already observing relevant notifications, now records that we are observing 32 the relevant notifications; also stores [NSNoticationCenter defaultCenter] in local var 33 to avoid objc dispatch 34 (-[WebHTMLView addWindowObservers]): 35 ditto 36 (-[WebHTMLView viewWillMoveToSuperview:]): 37 updated for name change 38 (-[WebHTMLView viewWillMoveToWindow:]): 39 updated for name changes 40 1 41 2009-01-31 Darin Adler <darin@apple.com> 2 42 -
trunk/WebKit/mac/WebView/WebHTMLView.mm
r40465 r40468 290 290 - (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText; 291 291 - (void)_pasteAsPlainTextWithPasteboard:(NSPasteboard *)pasteboard; 292 - (void)_removeMouseMovedObserverUnconditionally; 293 - (void)_removeSuperviewObservers; 294 - (void)_removeWindowObservers; 292 295 - (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action; 293 296 - (BOOL)_shouldInsertText:(NSString *)text replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action; … … 373 376 BOOL printing; 374 377 BOOL avoidingPrintOrphan; 378 BOOL observingMouseMovedNotifications; 379 BOOL observingSuperviewNotifications; 380 BOOL observingWindowNotifications; 375 381 376 382 id savedSubviews; … … 756 762 } 757 763 764 - (void)_removeMouseMovedObserverUnconditionally 765 { 766 if (!_private->observingMouseMovedNotifications) 767 return; 768 769 [[NSNotificationCenter defaultCenter] removeObserver:self name:WKMouseMovedNotification() object:nil]; 770 _private->observingMouseMovedNotifications = false; 771 } 772 773 - (void)_removeSuperviewObservers 774 { 775 if (!_private->observingSuperviewNotifications) 776 return; 777 778 NSView *superview = [self superview]; 779 if (!superview || ![self window]) 780 return; 781 782 NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 783 [notificationCenter removeObserver:self name:NSViewFrameDidChangeNotification object:superview]; 784 [notificationCenter removeObserver:self name:NSViewBoundsDidChangeNotification object:superview]; 785 786 _private->observingSuperviewNotifications = false; 787 } 788 789 - (void)_removeWindowObservers 790 { 791 if (!_private->observingWindowNotifications) 792 return; 793 794 NSWindow *window = [self window]; 795 if (!window) 796 return; 797 798 NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 799 [notificationCenter removeObserver:self name:NSWindowDidBecomeKeyNotification object:nil]; 800 [notificationCenter removeObserver:self name:NSWindowDidResignKeyNotification object:nil]; 801 [notificationCenter removeObserver:self name:NSWindowWillCloseNotification object:window]; 802 [notificationCenter removeObserver:self name:WKWindowWillOrderOnScreenNotification() object:window]; 803 804 _private->observingWindowNotifications = false; 805 } 806 758 807 - (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action 759 808 { … … 1844 1893 [self _cancelUpdateFocusedAndActiveStateTimer]; 1845 1894 [self _clearLastHitViewIfSelf]; 1846 // FIXME: This is slow; should remove individual observers instead. 1847 [[NSNotificationCenter defaultCenter] removeObserver:self]; 1895 [self _removeMouseMovedObserverUnconditionally]; 1896 [self _removeWindowObservers]; 1897 [self _removeSuperviewObservers]; 1848 1898 [_private->pluginController destroyAllPlugins]; 1849 1899 [_private->pluginController setDataSource:nil]; … … 2567 2617 - (void)addMouseMovedObserver 2568 2618 { 2569 if (!_private->dataSource || ![self _isTopHTMLView] )2619 if (!_private->dataSource || ![self _isTopHTMLView] || _private->observingMouseMovedNotifications) 2570 2620 return; 2571 2621 … … 2581 2631 name:WKMouseMovedNotification() object:nil]; 2582 2632 [self _frameOrBoundsChanged]; 2583 } 2584 2585 - (void)removeMouseMovedObserverUnconditionally 2586 { 2587 [[NSNotificationCenter defaultCenter] removeObserver:self 2588 name:WKMouseMovedNotification() object:nil]; 2633 _private->observingMouseMovedNotifications = true; 2589 2634 } 2590 2635 … … 2598 2643 2599 2644 [[self _webView] _mouseDidMoveOverElement:nil modifierFlags:0]; 2600 [self removeMouseMovedObserverUnconditionally];2645 [self _removeMouseMovedObserverUnconditionally]; 2601 2646 } 2602 2647 … … 2611 2656 // sizes that are based on the total size of the view. 2612 2657 2658 if (_private->observingSuperviewNotifications) 2659 return; 2660 2613 2661 NSView *superview = [self superview]; 2614 if (superview && [self window]) { 2615 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_frameOrBoundsChanged) 2616 name:NSViewFrameDidChangeNotification object:superview]; 2617 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_frameOrBoundsChanged) 2618 name:NSViewBoundsDidChangeNotification object:superview]; 2619 2620 // In addition to registering for frame/bounds change notifications, call -_frameOrBoundsChanged. 2621 // It will check the current size/scroll against the previous layout's size/scroll. We need to 2622 // do this here to catch the case where the WebView is laid out at one size, removed from its 2623 // window, resized, and inserted into another window. Our frame/bounds changed notifications 2624 // will not be sent in that situation, since we only watch for changes while in the view hierarchy. 2625 [self _frameOrBoundsChanged]; 2626 } 2627 } 2628 2629 - (void)removeSuperviewObservers 2630 { 2631 NSView *superview = [self superview]; 2632 if (superview && [self window]) { 2633 [[NSNotificationCenter defaultCenter] removeObserver:self 2634 name:NSViewFrameDidChangeNotification object:superview]; 2635 [[NSNotificationCenter defaultCenter] removeObserver:self 2636 name:NSViewBoundsDidChangeNotification object:superview]; 2637 } 2662 if (!superview || ![self window]) 2663 return; 2664 2665 NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 2666 [notificationCenter addObserver:self selector:@selector(_frameOrBoundsChanged) name:NSViewFrameDidChangeNotification object:superview]; 2667 [notificationCenter addObserver:self selector:@selector(_frameOrBoundsChanged) name:NSViewBoundsDidChangeNotification object:superview]; 2668 2669 // In addition to registering for frame/bounds change notifications, call -_frameOrBoundsChanged. 2670 // It will check the current size/scroll against the previous layout's size/scroll. We need to 2671 // do this here to catch the case where the WebView is laid out at one size, removed from its 2672 // window, resized, and inserted into another window. Our frame/bounds changed notifications 2673 // will not be sent in that situation, since we only watch for changes while in the view hierarchy. 2674 [self _frameOrBoundsChanged]; 2675 2676 _private->observingSuperviewNotifications = true; 2638 2677 } 2639 2678 2640 2679 - (void)addWindowObservers 2641 2680 { 2681 if (_private->observingWindowNotifications) 2682 return; 2683 2642 2684 NSWindow *window = [self window]; 2643 if (window) { 2644 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:) 2645 name:NSWindowDidBecomeKeyNotification object:nil]; 2646 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidResignKey:) 2647 name:NSWindowDidResignKeyNotification object:nil]; 2648 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillClose:) 2649 name:NSWindowWillCloseNotification object:window]; 2650 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillOrderOnScreen:) 2651 name:WKWindowWillOrderOnScreenNotification() object:window]; 2652 } 2653 } 2654 2655 - (void)removeWindowObservers 2656 { 2657 NSWindow *window = [self window]; 2658 if (window) { 2659 [[NSNotificationCenter defaultCenter] removeObserver:self 2660 name:NSWindowDidBecomeKeyNotification object:nil]; 2661 [[NSNotificationCenter defaultCenter] removeObserver:self 2662 name:NSWindowDidResignKeyNotification object:nil]; 2663 [[NSNotificationCenter defaultCenter] removeObserver:self 2664 name:NSWindowWillCloseNotification object:window]; 2665 [[NSNotificationCenter defaultCenter] removeObserver:self 2666 name:WKWindowWillOrderOnScreenNotification() object:window]; 2667 } 2685 if (!window) 2686 return; 2687 2688 NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 2689 [notificationCenter addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:nil]; 2690 [notificationCenter addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:nil]; 2691 [notificationCenter addObserver:self selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification object:window]; 2692 [notificationCenter addObserver:self selector:@selector(windowWillOrderOnScreen:) name:WKWindowWillOrderOnScreenNotification() object:window]; 2693 2694 _private->observingWindowNotifications = true; 2668 2695 } 2669 2696 2670 2697 - (void)viewWillMoveToSuperview:(NSView *)newSuperview 2671 2698 { 2672 [self removeSuperviewObservers];2699 [self _removeSuperviewObservers]; 2673 2700 } 2674 2701 … … 2695 2722 2696 2723 // FIXME: Some of these calls may not work because this view may be already removed from it's superview. 2697 [self removeMouseMovedObserverUnconditionally];2698 [self removeWindowObservers];2699 [self removeSuperviewObservers];2724 [self _removeMouseMovedObserverUnconditionally]; 2725 [self _removeWindowObservers]; 2726 [self _removeSuperviewObservers]; 2700 2727 [self _cancelUpdateMouseoverTimer]; 2701 2728 [self _cancelUpdateFocusedAndActiveStateTimer];
Note: See TracChangeset
for help on using the changeset viewer.