WebCore:
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Sep 2004 21:12:10 +0000 (21:12 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Sep 2004 21:12:10 +0000 (21:12 +0000)
        Reviewed by Darin

        * WebCore.pbproj/project.pbxproj: New files added.
        * khtml/khtml_part.cpp:
        (KHTMLPart::clearSelection): No longer calls setFocusIfNeeded.
        (KHTMLPart::slotClearSelection): Merged old implementation from this function to
        clearSelection. Now just calls clearSelection. Also put in !APPLE_CHANGES since
        we do not call it.
        * khtml/xml/dom_docimpl.cpp:
        (DocumentImpl::setFocusNode): Add some code to determine when setting the focus should
        clear the selection.
        * kwq/KWQWidget.mm:
        (QWidget::hasFocus): Call _webcore_effectiveFirstResponder to get view to check for focus.
        (QWidget::setFocus): Ditto.
        * kwq/WebCoreBridge.mm:
        (-[WebCoreBridge deselectText]): Called slotClearSelection and should have been. Now calls
        clearSelection.
        * kwq/WebCoreView.h: Added.
        * kwq/WebCoreView.m: Added.
        (-[NSView _webcore_effectiveFirstResponder]): New method to yield the correct responder
        to check for firstResponder-ness before calling makeFirstResonder. This helps to prevent
        unwanted firstResponder switching.
        (-[NSClipView _webcore_effectiveFirstResponder]): Ditto.
        (-[NSScrollView _webcore_effectiveFirstResponder]): Ditto.

WebKit:

        Reviewed by Darin

        * WebView.subproj/WebFrameView.m:
        (-[WebFrameView _webcore_effectiveFirstResponder]): New function to yield the correct responder
        to check for firstResponder-ness before calling makeFirstResonder. This helps to prevent
        unwanted firstResponder switching.
        * WebView.subproj/WebView.m:
        (-[WebView _webcore_effectiveFirstResponder]): Ditto.

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

WebCore/ChangeLog-2005-08-23
WebCore/WebCore.pbproj/project.pbxproj
WebCore/khtml/khtml_part.cpp
WebCore/khtml/xml/dom_docimpl.cpp
WebCore/kwq/KWQWidget.mm
WebCore/kwq/WebCoreBridge.mm
WebCore/kwq/WebCoreView.h [new file with mode: 0644]
WebCore/kwq/WebCoreView.m [new file with mode: 0644]
WebKit/ChangeLog
WebKit/WebView.subproj/WebFrameView.m
WebKit/WebView.subproj/WebView.m

index 960b62addbf8da2f0b59bb2d89732db308200be7..424dcc4942945fb295c14866fc71cbd9d001060f 100644 (file)
@@ -1,3 +1,30 @@
+2004-09-22  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Darin
+
+        * WebCore.pbproj/project.pbxproj: New files added.
+        * khtml/khtml_part.cpp:
+        (KHTMLPart::clearSelection): No longer calls setFocusIfNeeded.
+        (KHTMLPart::slotClearSelection): Merged old implementation from this function to
+        clearSelection. Now just calls clearSelection. Also put in !APPLE_CHANGES since
+        we do not call it.
+        * khtml/xml/dom_docimpl.cpp:
+        (DocumentImpl::setFocusNode): Add some code to determine when setting the focus should
+        clear the selection.
+        * kwq/KWQWidget.mm:
+        (QWidget::hasFocus): Call _webcore_effectiveFirstResponder to get view to check for focus.
+        (QWidget::setFocus): Ditto.
+        * kwq/WebCoreBridge.mm: 
+        (-[WebCoreBridge deselectText]): Called slotClearSelection and should have been. Now calls
+        clearSelection.
+        * kwq/WebCoreView.h: Added.
+        * kwq/WebCoreView.m: Added.
+        (-[NSView _webcore_effectiveFirstResponder]): New method to yield the correct responder
+        to check for firstResponder-ness before calling makeFirstResonder. This helps to prevent 
+        unwanted firstResponder switching.
+        (-[NSClipView _webcore_effectiveFirstResponder]): Ditto.
+        (-[NSScrollView _webcore_effectiveFirstResponder]): Ditto.
+
 2004-09-21  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Darin.
index 83d7b29896c63ad6217da7f7283250d3095f7e49..3b9f77d2b5f6fdee13eea93c55bc433aca25b1ee 100644 (file)
                                93ABCE6006E1A42E0085925B,
                                93B641F406E28C5C0055F610,
                                BEF3442706F1123C000A65D3,
+                               BE855F800701E83500239769,
                        );
                        isa = PBXHeadersBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
                                93ABCE5F06E1A42E0085925B,
                                93B641F306E28C5C0055F610,
                                BEF3442606F1123C000A65D3,
+                               BE8560520701F91100239769,
                        );
                        isa = PBXSourcesBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
                        settings = {
                        };
                };
+               BE855F7F0701E83500239769 = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
+                       path = WebCoreView.h;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               BE855F800701E83500239769 = {
+                       fileRef = BE855F7F0701E83500239769;
+                       isa = PBXBuildFile;
+                       settings = {
+                               ATTRIBUTES = (
+                                       Private,
+                               );
+                       };
+               };
+               BE8560510701F91100239769 = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = WebCoreView.m;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               BE8560520701F91100239769 = {
+                       fileRef = BE8560510701F91100239769;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
                BE8BD8F206359F6000D3F20B = {
                        fileEncoding = 30;
                        isa = PBXFileReference;
                                F587855302DE375901EA4122,
                                517FA6B20370BD6100CA2D3A,
                                517FA6B60370C7ED00CA2D3A,
+                               BE855F7F0701E83500239769,
+                               BE8560510701F91100239769,
                                F587855402DE375901EA4122,
                                F587855502DE375901EA4122,
                                F58EF58E02DFDFB7018635CA,
index cbbfc046a15d9648f56863af6a134e0a4e7049ea..9df18d33d752ea1df589df33cefbe418e6c969f9 100644 (file)
@@ -2366,9 +2366,10 @@ void KHTMLPart::setDragCaret(const DOM::Selection &dragCaret)
 void KHTMLPart::clearSelection()
 {
     clearCaretRectIfNeeded();
-    setFocusNodeIfNeeded();
-    d->m_selection = Selection();
-    notifySelectionChanged();
+    bool hadSelection = hasSelection();
+    d->m_selection.clear();
+    if (hadSelection)
+        notifySelectionChanged();
 }
 
 void KHTMLPart::invalidateSelection()
@@ -2389,14 +2390,12 @@ void KHTMLPart::setCaretVisible(bool flag)
     selectionLayoutChanged();
 }
 
+#if !APPLE_CHANGES
 void KHTMLPart::slotClearSelection()
 {
-    clearCaretRectIfNeeded();
-    bool hadSelection = hasSelection();
-    d->m_selection.clear();
-    if (hadSelection)
-        notifySelectionChanged();
+    clearSelection();
 }
+#endif
 
 void KHTMLPart::clearCaretRectIfNeeded()
 {
index 3b4cd504170a250ef0f12d047444dddc844441ce..450752bdbb40153ae0c08f9deb71a8f1d9399177 100644 (file)
@@ -2419,6 +2419,14 @@ bool DocumentImpl::setFocusNode(NodeImpl *newFocusNode)
         }
     }
 
+    // Clear the selection when changing the focus node to null or to a node that is not 
+    // contained by the current selection.
+    if (part()) {
+        NodeImpl *startContainer = part()->selection().start().node();
+        if (!newFocusNode || (startContainer && startContainer != newFocusNode && !startContainer->isAncestor(newFocusNode)))
+            part()->clearSelection();
+    }
+
     if (newFocusNode) {
 #if APPLE_CHANGES            
         if (newFocusNode->isContentEditable() && !acceptsEditingFocus(newFocusNode)) {
index fceb2f0f0c181f1e22722ff68f0551d06f6a22c2..94dd5fece6dbe7b5e7f4db0419199d3e9d7bb492 100644 (file)
@@ -32,6 +32,7 @@
 #import "KWQFoundationExtras.h"
 #import "WebCoreBridge.h"
 #import "WebCoreFrameView.h"
+#import "WebCoreView.h"
 #import "khtmlview.h"
 #import "render_canvas.h"
 #import "render_replaced.h"
@@ -189,7 +190,7 @@ int QWidget::baselinePosition(int height) const
 
 bool QWidget::hasFocus() const
 {
-    NSView *view = getView();
+    NSView *view = [getView() _webcore_effectiveFirstResponder];
 
     KWQ_BLOCK_EXCEPTIONS;
     NSView *firstResponder = [KWQKHTMLPart::bridgeForWidget(this) firstResponder];
@@ -223,7 +224,7 @@ void QWidget::setFocus()
         return;
     }
     
-    NSView *view = getView();
+    NSView *view = [getView() _webcore_effectiveFirstResponder];
 
     KWQ_BLOCK_EXCEPTIONS;
     if ([view acceptsFirstResponder]) {
index b17bc45e07fd39dc032e67396f9b2349df213b89..b9c0c779088018ea013b5a8e8de1b9ee64fdbbc9 100644 (file)
@@ -566,7 +566,7 @@ static bool initializedKJS = FALSE;
 
 - (void)deselectText
 {
-    _part->slotClearSelection();
+    _part->clearSelection();
 }
 
 - (BOOL)isFrameSet
diff --git a/WebCore/kwq/WebCoreView.h b/WebCore/kwq/WebCoreView.h
new file mode 100644 (file)
index 0000000..ad23d31
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@interface NSView (WebCoreView)
+- (NSView *)_webcore_effectiveFirstResponder;
+@end
diff --git a/WebCore/kwq/WebCoreView.m b/WebCore/kwq/WebCoreView.m
new file mode 100644 (file)
index 0000000..8b2a31c
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+#import "WebCoreView.h"
+
+@interface NSClipView (WebCoreView)
+- (NSView *)_webcore_effectiveFirstResponder;
+@end
+
+@interface NSScrollView (WebCoreView)
+- (NSView *)_webcore_effectiveFirstResponder;
+@end
+
+@implementation NSView (WebCoreView)
+
+- (NSView *)_webcore_effectiveFirstResponder
+{
+    return self;
+}
+
+@end
+
+@implementation NSClipView (WebCoreView)
+
+- (NSView *)_webcore_effectiveFirstResponder
+{
+    NSView *view = [self documentView];
+    return view ? [view _webcore_effectiveFirstResponder] : [super _webcore_effectiveFirstResponder];
+}
+
+@end
+
+@implementation NSScrollView (WebCoreView)
+
+- (NSView *)_webcore_effectiveFirstResponder
+{
+    NSView *view = [self contentView];
+    return view ? [view _webcore_effectiveFirstResponder] : [super _webcore_effectiveFirstResponder];
+}
+
+@end
+
index 0767da2977b9e99687fd605db97ffe62e6764dd2..588ef45290d135e59bb843e4ef14161b52676f75 100644 (file)
@@ -1,3 +1,14 @@
+2004-09-22  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Darin
+
+        * WebView.subproj/WebFrameView.m:
+        (-[WebFrameView _webcore_effectiveFirstResponder]): New function to yield the correct responder
+        to check for firstResponder-ness before calling makeFirstResonder. This helps to prevent 
+        unwanted firstResponder switching.
+        * WebView.subproj/WebView.m:
+        (-[WebView _webcore_effectiveFirstResponder]): Ditto.
+
 2004-09-21  Chris Blumenberg  <cblu@apple.com
 
        Fixed:
index cb4f2aabc94f42453d4b075a51ee8df7396736f1..45046dbb95c0ac7e7ef9073a391b90f3a6877f2c 100644 (file)
@@ -35,6 +35,8 @@
 #import <WebKit/WebViewPrivate.h>
 #import <WebKit/WebAssertions.h>
 
+#import <WebCore/WebCoreView.h>
+
 #import <Foundation/NSDictionary_NSURLExtras.h>
 #import <Foundation/NSURLRequest.h>
 
@@ -745,4 +747,10 @@ static NSMutableDictionary *viewTypes;
     }
 }
 
+- (NSView *)_webcore_effectiveFirstResponder
+{
+    NSView *view = [self documentView];
+    return view ? [view _webcore_effectiveFirstResponder] : [super _webcore_effectiveFirstResponder];
+}
+
 @end
index d3b2ae78e5b9f58223159581a23f75c131f360c5..5bb14ea302a2520075d529e59b6d8f18d57b1e61 100644 (file)
@@ -54,6 +54,7 @@
 
 #import <WebCore/WebCoreEncodings.h>
 #import <WebCore/WebCoreSettings.h>
+#import <WebCore/WebCoreView.h>
 
 #import <Foundation/NSData_NSURLExtras.h>
 #import <Foundation/NSDictionary_NSURLExtras.h>
@@ -1868,6 +1869,12 @@ NS_ENDHANDLER
     return NO;
 }
 
+- (NSView *)_webcore_effectiveFirstResponder
+{
+    WebFrameView *frameView = [[self mainFrame] frameView];
+    return frameView ? [frameView _webcore_effectiveFirstResponder] : [super _webcore_effectiveFirstResponder];
+}
+
 - (void)setNextKeyView:(NSView *)aView
 {
     // This works together with becomeFirstResponder to splice the WebView into