WebCore:
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 26 Feb 2005 01:03:45 +0000 (01:03 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 26 Feb 2005 01:03:45 +0000 (01:03 +0000)
        Reviewed by John.

        - fixed <rdar://problem/4025088> window onblur and onfocus don't fire when text field has focus

        * kwq/KWQKHTMLPart.h: Added setWindowHasFocus function and m_windowHasFocus data member.
        * kwq/KWQKHTMLPart.mm:
        (KWQKHTMLPart::setDisplaysWithFocusAttributes): Took out the code that sends the focus and blur events.
        (KWQKHTMLPart::setWindowHasFocus): Put that code here instead.

        * kwq/WebCoreBridge.h: Added setWindowHasFocus: method to the bridge.
        * kwq/WebCoreBridge.mm: (-[WebCoreBridge setWindowHasFocus:]): Added. Calls method on the part.

WebKit:

        Reviewed by John.

        - fixed <rdar://problem/4025088> window onblur and onfocus don't fire when text field has focus

        * WebView.subproj/WebHTMLView.m:
        (-[WebHTMLView updateFocusState]): Renamed from updateFocusDisplay. Added call to setWindowHasFocus: method.
        (-[WebHTMLView viewDidMoveToWindow]): Call method by new name.
        (-[WebHTMLView windowDidBecomeKey:]): Ditto.
        (-[WebHTMLView windowDidResignKey:]): Ditto.
        (-[WebHTMLView becomeFirstResponder]): Ditto.
        (-[WebHTMLView resignFirstResponder]): Ditto.

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

WebCore/ChangeLog-2005-08-23
WebCore/kwq/KWQKHTMLPart.h
WebCore/kwq/KWQKHTMLPart.mm
WebCore/kwq/WebCoreBridge.h
WebCore/kwq/WebCoreBridge.mm
WebKit/ChangeLog
WebKit/WebView.subproj/WebHTMLView.m

index f75d3999a29b9b2ec1a93731e9856873ffb7789b..58d84f4cc2b605956bae1413cd19fb9d636f508f 100644 (file)
@@ -1,3 +1,17 @@
+2005-02-25  Darin Adler  <darin@apple.com>
+
+        Reviewed by John.
+
+        - fixed <rdar://problem/4025088> window onblur and onfocus don't fire when text field has focus
+
+        * kwq/KWQKHTMLPart.h: Added setWindowHasFocus function and m_windowHasFocus data member.
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::setDisplaysWithFocusAttributes): Took out the code that sends the focus and blur events.
+        (KWQKHTMLPart::setWindowHasFocus): Put that code here instead.
+
+        * kwq/WebCoreBridge.h: Added setWindowHasFocus: method to the bridge.
+        * kwq/WebCoreBridge.mm: (-[WebCoreBridge setWindowHasFocus:]): Added. Calls method on the part.
+
 2005-02-25  Darin Adler  <darin@apple.com>
 
         Reviewed by John.
index 6b0366ffc7e799d2dc2de851648cd73f6f651281..278ab32de80b802e36ca99fc6ef0e53b03049dda 100644 (file)
@@ -309,6 +309,8 @@ public:
     void setSelectionFromNone();
     void setDisplaysWithFocusAttributes(bool flag);
     bool displaysWithFocusAttributes() const;
+
+    void setWindowHasFocus(bool flag);
     
     // Convenience, to avoid repeating the code to dig down to get this.
     QChar backslashAsCurrencySymbol() const;
@@ -473,6 +475,8 @@ private:
     DOM::Range m_markedTextRange;
     bool m_markedTextUsesUnderlines;
     QValueList<MarkedTextUnderline> m_markedTextUnderlines;
+
+    bool m_windowHasFocus;
 };
 
 inline KWQKHTMLPart *KWQ(KHTMLPart *part) { return static_cast<KWQKHTMLPart *>(part); }
index ff7f58a2b2b7e1168189ae36ecb56552d1acc555..3990024aac58682f3a1aa7ccb645b8672446b554 100644 (file)
@@ -229,6 +229,8 @@ KWQKHTMLPart::KWQKHTMLPart()
     , _dragSrc(0)
     , _dragClipboard(0)
     , _elementToDraw(0)
+    , m_markedTextUsesUnderlines(false)
+    , m_windowHasFocus(false)
 {
     // Must init the cache before connecting to any signals
     Cache::init();
@@ -3693,7 +3695,7 @@ void KWQKHTMLPart::setDisplaysWithFocusAttributes(bool flag)
     if (d->m_isFocused == flag)
         return;
     d->m_isFocused = flag;
-        
+
     // This method does the job of updating the view based on whether the view is "active".
     // This involves three kinds of drawing updates:
 
@@ -3704,7 +3706,7 @@ void KWQKHTMLPart::setDisplaysWithFocusAttributes(bool flag)
     // 2. Caret blinking (blinks | does not blink)
     if (flag)
         setSelectionFromNone();
-    setCaretVisible(d->m_isFocused);
+    setCaretVisible(flag);
     
     // 3. The drawing of a focus ring around links in web pages.
     DocumentImpl *doc = xmlDocImpl();
@@ -3713,17 +3715,6 @@ void KWQKHTMLPart::setDisplaysWithFocusAttributes(bool flag)
         if (node && node->renderer())
             node->renderer()->repaint();
     }
-    
-    if (doc && doc->body()) {
-        if (flag) {
-            // Send onfocus event.
-            doc->body()->dispatchWindowEvent(EventImpl::FOCUS_EVENT, false, false);
-        }
-        else {
-            // Send onblur event.
-            doc->body()->dispatchWindowEvent(EventImpl::BLUR_EVENT, false, false);
-        }
-    }
 }
 
 bool KWQKHTMLPart::displaysWithFocusAttributes() const
@@ -3731,6 +3722,22 @@ bool KWQKHTMLPart::displaysWithFocusAttributes() const
     return d->m_isFocused;
 }
 
+void KWQKHTMLPart::setWindowHasFocus(bool flag)
+{
+    if (m_windowHasFocus == flag)
+        return;
+    m_windowHasFocus = flag;
+
+    DocumentImpl *doc = xmlDocImpl();
+    if (doc) {
+        NodeImpl *body = doc->body();
+        if (body) {
+            int eventID = flag ? EventImpl::FOCUS_EVENT : EventImpl::BLUR_EVENT;
+            body->dispatchWindowEvent(eventID, false, false);
+        }
+    }
+}
+
 QChar KWQKHTMLPart::backslashAsCurrencySymbol() const
 {
     DocumentImpl *doc = xmlDocImpl();
index d4fb5b51f97623a78c85fc4f0914f605112a7f73..08ac31e9dcfb51629fb3e96dc52520ba4eed9e3d 100644 (file)
@@ -300,6 +300,8 @@ typedef enum {
 - (void)setSelectionFromNone;
 - (void)setDisplaysWithFocusAttributes:(BOOL)flag;
 
+- (void)setWindowHasFocus:(BOOL)flag;
+
 - (NSString *)stringForRange:(DOMRange *)range;
 
 - (NSString *)markupStringFromNode:(DOMNode *)node nodes:(NSArray **)nodes;
index 329491e5132d7b0c6da95e09d955ed5a47070757..2a022634532416c2ae7076f7943bd8db33d8a6c8 100644 (file)
@@ -1373,6 +1373,11 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     _part->setDisplaysWithFocusAttributes(flag);
 }
 
+- (void)setWindowHasFocus:(BOOL)flag
+{
+    _part->setWindowHasFocus(flag);
+}
+
 - (void)setShouldCreateRenderers:(BOOL)f
 {
     _shouldCreateRenderers = f;
index 6a2bb35e8933b52f1a26d748120b301f5859551b..819e84ed8b184252df704a27c4113b2709b829c6 100644 (file)
@@ -1,3 +1,17 @@
+2005-02-25  Darin Adler  <darin@apple.com>
+
+        Reviewed by John.
+
+        - fixed <rdar://problem/4025088> window onblur and onfocus don't fire when text field has focus
+
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView updateFocusState]): Renamed from updateFocusDisplay. Added call to setWindowHasFocus: method.
+        (-[WebHTMLView viewDidMoveToWindow]): Call method by new name.
+        (-[WebHTMLView windowDidBecomeKey:]): Ditto.
+        (-[WebHTMLView windowDidResignKey:]): Ditto.
+        (-[WebHTMLView becomeFirstResponder]): Ditto.
+        (-[WebHTMLView resignFirstResponder]): Ditto.
+
 === Safari-400 ===
 
 2005-02-25  Richard Williamson   <rjw@apple.com>
index f72e90677da41edad4cbdb47cff079e7b9638621..a7efe60968910f90eb498da7c766ce0b2ff5b5dd 100644 (file)
@@ -1998,7 +1998,7 @@ static WebHTMLView *lastHitView = nil;
         name:NSMouseMovedNotification object:nil];
 }
 
-- (void)updateFocusDisplay
+- (void)updateFocusState
 {
     // This method does the job of updating the view based on the view's firstResponder-ness and
     // the window key-ness of the window containing this view. This involves three kinds of 
@@ -2009,9 +2009,17 @@ static WebHTMLView *lastHitView = nil;
     // 1. The background color used to draw behind selected content (active | inactive color)
     // 2. Caret blinking (blinks | does not blink)
     // 3. The drawing of a focus ring around links in web pages.
+    //
+    // Also, this is responsible for letting the bridge know if the window has gained or lost focus
+    // so we can send focus and blur events.
 
-    BOOL flag = !_private->resigningFirstResponder && [[self window] isKeyWindow] && [self _web_firstResponderCausesFocusDisplay];
-    [[self _bridge] setDisplaysWithFocusAttributes:flag];
+    WebBridge *bridge = [self _bridge];
+    BOOL windowIsKey = [[self window] isKeyWindow];
+
+    BOOL flag = !_private->resigningFirstResponder && windowIsKey && [self _web_firstResponderCausesFocusDisplay];
+    [bridge setDisplaysWithFocusAttributes:flag];
+
+    [bridge setWindowHasFocus:windowIsKey];
 }
 
 - (void)addSuperviewObservers
@@ -2115,14 +2123,15 @@ static WebHTMLView *lastHitView = nil;
             [self addWindowObservers];
             [self addSuperviewObservers];
             [self addMouseMovedObserver];
+
             // Schedule this update, rather than making the call right now.
             // The reason is that placing the caret in the just-installed view requires
             // the HTML/XML document to be available on the WebCore side, but it is not
             // at the time this code is running. However, it will be there on the next
             // crank of the run loop. Doing this helps to make a blinking caret appear 
             // in a new, empty window "automatic".
-            [self performSelector:@selector(updateFocusDisplay) withObject:nil afterDelay:0];
-    
+            [self performSelector:@selector(updateFocusState) withObject:nil afterDelay:0];
+
             [[self _pluginController] startAllPlugins];
     
             _private->lastScrollPosition = NSZeroPoint;
@@ -2473,7 +2482,7 @@ static WebHTMLView *lastHitView = nil;
 {
     ASSERT([notification object] == [self window]);
     [self addMouseMovedObserver];
-    [self updateFocusDisplay];
+    [self updateFocusState];
 }
 
 - (void)windowDidResignKey: (NSNotification *)notification
@@ -2481,7 +2490,7 @@ static WebHTMLView *lastHitView = nil;
     ASSERT([notification object] == [self window]);
     [_private->compController endRevertingChange:NO moveLeft:NO];
     [self removeMouseMovedObserver];
-    [self updateFocusDisplay];
+    [self updateFocusState];
 }
 
 - (void)windowWillClose:(NSNotification *)notification
@@ -2885,7 +2894,7 @@ static WebHTMLView *lastHitView = nil;
     if (view) {
         [[self window] makeFirstResponder:view];
     }
-    [self updateFocusDisplay];
+    [self updateFocusState];
     _private->startNewKillRingSequence = YES;
     return YES;
 }
@@ -2906,7 +2915,7 @@ static WebHTMLView *lastHitView = nil;
                 [self deselectAll];
             }
         }
-        [self updateFocusDisplay];
+        [self updateFocusState];
         _private->resigningFirstResponder = NO;
     }
     return resign;