Reviewed by Timothy.
authorthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Apr 2006 01:44:35 +0000 (01:44 +0000)
committerthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Apr 2006 01:44:35 +0000 (01:44 +0000)
        http://bugzilla.opendarwin.org/show_bug.cgi?id=6637
        Bug 6637: selecting node in Inspector after closing window crashes Safari

        When the window the Web Inspector was inspecting is closed, the inspector goes into its
        no-selection state. Choosing to inspect another element activates it again. The inspector
        will also follow the WebView if the URL changes and select the root element on the new page.

        * WebInspector/WebInspector.m:
        (-[NSWindow setWebFrame:]):
        (-[NSWindow setRootDOMNode:]):
        (-[WebInspector _revealAndSelectNodeInTree:]):
        (-[WebInspector _update]):
        (-[WebInspector _updateRoot]):
        (-[WebInspector inspectedWebViewProgressFinished:]):
        (-[WebInspector inspectedWindowWillClose:]):
        (-[WebInspector webView:didFinishLoadForFrame:]):
        * WebInspector/WebInspectorPanel.m:
        (-[WebInspectorPanel canBecomeMainWindow]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@13976 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/WebInspector/WebInspector.m
WebKit/WebInspector/WebInspectorPanel.m

index 154bf154b6a33d27d5a5fb72ce40b99ff1788454..64a36bacd9c217b3909afd42ca8a4a6cd036abc9 100644 (file)
@@ -1,3 +1,26 @@
+2006-04-19  James G. Speth  <speth@end.com>
+
+        Reviewed by Timothy.
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=6637
+        Bug 6637: selecting node in Inspector after closing window crashes Safari
+
+        When the window the Web Inspector was inspecting is closed, the inspector goes into its
+        no-selection state. Choosing to inspect another element activates it again. The inspector
+        will also follow the WebView if the URL changes and select the root element on the new page.
+
+        * WebInspector/WebInspector.m:
+        (-[NSWindow setWebFrame:]):
+        (-[NSWindow setRootDOMNode:]):
+        (-[WebInspector _revealAndSelectNodeInTree:]):
+        (-[WebInspector _update]):
+        (-[WebInspector _updateRoot]):
+        (-[WebInspector inspectedWebViewProgressFinished:]):
+        (-[WebInspector inspectedWindowWillClose:]):
+        (-[WebInspector webView:didFinishLoadForFrame:]):
+        * WebInspector/WebInspectorPanel.m:
+        (-[WebInspectorPanel canBecomeMainWindow]):
+
 2006-04-18  Darin Adler  <darin@apple.com>
 
         Reviewed by Beth.
index 0d4c4f475c8a1ddc5df2a8bfb98e05ce1af1edd3..8bb35a0644f6fe944784ece24c2b557f8f80e272 100644 (file)
@@ -164,10 +164,21 @@ static NSMapTable *lastChildIgnoringWhitespaceCache = NULL;
     if ([webFrame isEqual:_private->webFrame])
         return;
 
+    if (_private->webFrame) {
+        [[NSNotificationCenter defaultCenter] removeObserver:self name:WebViewProgressFinishedNotification object:[_private->webFrame webView]];
+        [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowWillCloseNotification object:[[_private->webFrame webView] window]];
+    }
+    
     [webFrame retain];
     [_private->webFrame release];
     _private->webFrame = webFrame;
 
+    if (_private->webFrame) {
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(inspectedWebViewProgressFinished:) name:WebViewProgressFinishedNotification object:[_private->webFrame webView]];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(inspectedWindowWillClose:) name:NSWindowWillCloseNotification object:[[_private->webFrame webView] window]];
+    }
+
+    [_private->treeOutlineView setAllowsEmptySelection:NO];
     [self setFocusedDOMNode:[webFrame DOMDocument]];
 }
 
@@ -180,7 +191,7 @@ static NSMapTable *lastChildIgnoringWhitespaceCache = NULL;
 
 - (void)setRootDOMNode:(DOMNode *)node
 {
-    if (![node hasChildNodes] || [node isSameNode:_private->rootNode])
+    if ([node isSameNode:_private->rootNode])
         return;
 
     [node retain];
@@ -548,7 +559,7 @@ static NSMapTable *lastChildIgnoringWhitespaceCache = NULL;
 
 - (void)_revealAndSelectNodeInTree:(DOMNode *)node
 {
-    if (!_private->webViewLoaded || !node)
+    if (!_private->webViewLoaded)
         return;
 
     if (!_private->preventRevealOnFocus) {
@@ -572,8 +583,10 @@ static NSMapTable *lastChildIgnoringWhitespaceCache = NULL;
     if (index != -1) {
         [_private->treeOutlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:index] byExtendingSelection:NO];
         [_private->treeOutlineView scrollRowToVisible:index];
-        [self _updateTreeScrollbar];
+    } else {
+        [_private->treeOutlineView deselectAll:self];
     }
+    [self _updateTreeScrollbar];
 }
 
 - (void)_refreshSearch
@@ -641,8 +654,13 @@ static NSMapTable *lastChildIgnoringWhitespaceCache = NULL;
 
 - (void)_update
 {
-    if (_private->webViewLoaded && [self focusedDOMNode])
-        [[_private->webView windowScriptObject] callWebScriptMethod:@"updatePanes" withArguments:nil];
+    if (_private->webViewLoaded) {
+        if ([self focusedDOMNode]) {
+            [[_private->webView windowScriptObject] callWebScriptMethod:@"toggleNoSelection" withArguments:[NSArray arrayWithObject:[NSNumber numberWithBool:NO]]];
+            [[_private->webView windowScriptObject] callWebScriptMethod:@"updatePanes" withArguments:nil];
+        } else
+            [[_private->webView windowScriptObject] callWebScriptMethod:@"toggleNoSelection" withArguments:[NSArray arrayWithObject:[NSNumber numberWithBool:YES]]];
+    }
 }
 
 - (void)_updateTraversalButtons
@@ -673,7 +691,7 @@ static NSMapTable *lastChildIgnoringWhitespaceCache = NULL;
 
 - (void)_updateRoot
 {
-    if (!_private->webViewLoaded || ![self rootDOMNode] || _private->searchResultsVisible)
+    if (!_private->webViewLoaded || _private->searchResultsVisible)
         return;
 
     DOMHTMLElement *titleArea = (DOMHTMLElement *)[_private->domDocument getElementById:@"treePopupTitleArea"];
@@ -693,7 +711,8 @@ static NSMapTable *lastChildIgnoringWhitespaceCache = NULL;
     _private->preventSelectionRefocus = YES;
     DOMNode *focusedNode = [[self focusedDOMNode] retain];
     [_private->treeOutlineView reloadData];
-    [_private->treeOutlineView expandItem:[self rootDOMNode]];
+    if ([self rootDOMNode])
+        [_private->treeOutlineView expandItem:[self rootDOMNode]];
     [self _revealAndSelectNodeInTree:focusedNode];
     [focusedNode release];
     _private->preventSelectionRefocus = NO;
@@ -748,8 +767,31 @@ static NSMapTable *lastChildIgnoringWhitespaceCache = NULL;
 
 #pragma mark -
 
+- (void)inspectedWebViewProgressFinished:(NSNotification *)notification
+{
+    if ([notification object] == [[self webFrame] webView]) {
+        [self setFocusedDOMNode:[[self webFrame] DOMDocument]];
+        [self _update];
+        [self _updateRoot];
+        [self _highlightNode:[self focusedDOMNode]];
+    }
+}
+
+- (void)inspectedWindowWillClose:(NSNotification *)notification
+{
+    [self setFocusedDOMNode:nil];
+    [self setWebFrame:nil];
+    [_private->treeOutlineView setAllowsEmptySelection:YES];
+    [_private->treeOutlineView deselectAll:self];
+    [self _update];
+    [self _updateRoot];
+}
+
+#pragma mark -
+
 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
 {
+    // note: this is the Inspector's own WebView, not the one being inspected
     _private->webViewLoaded = YES;
     [[sender windowScriptObject] setValue:self forKey:@"Inspector"];
 
index 047fb2ca75b37f05197b4e6f7c84e243b8d2acd6..598dbea9d01dd6e1b83d1664f07c767e4a1d86b1 100644 (file)
@@ -43,7 +43,8 @@
 
 - (BOOL)canBecomeMainWindow
 {
-    return YES;
+    // prevent the inspector from confusing other panels
+    return NO;
 }
 
 - (void)moveWindow:(NSEvent *)event