WebCore:
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Jul 2004 23:17:24 +0000 (23:17 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Jul 2004 23:17:24 +0000 (23:17 +0000)
        Reviewed by Trey

        Fix for this bug:

        <rdar://problem/3738920> Caret blinks in inactive window

        As part of the fix, I cleaned up the way we handle special drawing that needs
        to be done in the HTML view that is first responder in the key window (e.g the
        drawing of text selection highlight and caret blinking).

        * khtml/khtml_part.cpp: Removed setCaretVisible function. Updating caret visibility
        is now done in setDisplaysWithFocusAttributes, described below.
        * khtml/khtml_part.h: Ditto.
        * khtml/khtmlpart_p.h:
        (KHTMLPartPrivate::KHTMLPartPrivate): m_caretVisible now defaults to false. This prevents
        the caret from blinking when an app is started from the command line and remains in the
        background.
        * khtml/khtmlview.cpp:
        (KHTMLView::focusInEvent): Remove caret code from here. Not needed.
        (KHTMLView::focusOutEvent): Ditto.
        * kwq/KWQKHTMLPart.h:
        (KWQKHTMLPart::displaysWithFocusAttributes): New accessor to return cached value to other code
        in WebCore.
        * kwq/KWQKHTMLPart.mm:
        (KWQKHTMLPart::KWQKHTMLPart):
        (KWQKHTMLPart::setDisplaysWithFocusAttributes): Renamed from setShowsFirstResponder and modified
        to do the display updating in a clearer way....and now has comments!
        * kwq/WebCoreBridge.h: Remove several obsolete functions that use to try to do the work of the new
        setDisplaysWithFocusAttributes function (and did so less well).
        * kwq/WebCoreBridge.mm:
        (-[WebCoreBridge drawRect:]): Now calls displaysWithFocusAttributes to figure out how to draw the
        text selection background.
        (-[WebCoreBridge setDisplaysWithFocusAttributes:]): Calls through to setDisplaysWithFocusAttributes in
        KWQKHTMLPart.
        (-[WebCoreBridge selectionColor]): Flipped the value of this ternary expression to accommodate the
        change from usesInactiveTextBackgroundColor to setDisplaysWithFocusAttributes.
        (-[WebCoreBridge setCaretVisible:]): Removed.

WebKit:

        Reviewed by Trey

        Fix for this bug:

        <rdar://problem/3738920> Caret blinks in inactive window

        As part of the fix, I cleaned up the way we handle special drawing that needs
        to be done in the HTML view that is first responder in the key window (e.g the
        drawing of text selection highlight and caret blinking).

        * WebView.subproj/WebHTMLView.m:
        (-[WebHTMLView updateFocusDisplay]): New method that centralizes the changes
        we need to make when the first responder-ness of the view or key-ness of the
        window changes.
        (-[WebHTMLView viewDidMoveToWindow]): Call new updateFocusDisplay helper.
        (-[WebHTMLView windowDidBecomeKey:]): Ditto.
        (-[WebHTMLView windowDidResignKey:]): Ditto.
        (-[WebHTMLView becomeFirstResponder]): Ditto.
        (-[WebHTMLView resignFirstResponder]): Ditto.

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

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

index c9ce4c1c90071fb8b0096ef81593f651642e3d00..21382e8740ee98ed4283b5b560c76424c9a0553b 100644 (file)
@@ -1,3 +1,43 @@
+2004-07-23  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Trey
+
+        Fix for this bug:
+        
+        <rdar://problem/3738920> Caret blinks in inactive window
+
+        As part of the fix, I cleaned up the way we handle special drawing that needs
+        to be done in the HTML view that is first responder in the key window (e.g the
+        drawing of text selection highlight and caret blinking).
+
+        * khtml/khtml_part.cpp: Removed setCaretVisible function. Updating caret visibility
+        is now done in setDisplaysWithFocusAttributes, described below.
+        * khtml/khtml_part.h: Ditto.
+        * khtml/khtmlpart_p.h:
+        (KHTMLPartPrivate::KHTMLPartPrivate): m_caretVisible now defaults to false. This prevents
+        the caret from blinking when an app is started from the command line and remains in the
+        background.
+        * khtml/khtmlview.cpp:
+        (KHTMLView::focusInEvent): Remove caret code from here. Not needed.
+        (KHTMLView::focusOutEvent): Ditto.
+        * kwq/KWQKHTMLPart.h:
+        (KWQKHTMLPart::displaysWithFocusAttributes): New accessor to return cached value to other code
+        in WebCore.
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::KWQKHTMLPart):
+        (KWQKHTMLPart::setDisplaysWithFocusAttributes): Renamed from setShowsFirstResponder and modified
+        to do the display updating in a clearer way....and now has comments!
+        * kwq/WebCoreBridge.h: Remove several obsolete functions that use to try to do the work of the new
+        setDisplaysWithFocusAttributes function (and did so less well).
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge drawRect:]): Now calls displaysWithFocusAttributes to figure out how to draw the
+        text selection background.
+        (-[WebCoreBridge setDisplaysWithFocusAttributes:]): Calls through to setDisplaysWithFocusAttributes in 
+        KWQKHTMLPart.
+        (-[WebCoreBridge selectionColor]): Flipped the value of this ternary expression to accommodate the
+        change from usesInactiveTextBackgroundColor to setDisplaysWithFocusAttributes.
+        (-[WebCoreBridge setCaretVisible:]): Removed.
+
 2004-07-23  John Sullivan  <sullivan@apple.com>
 
         Reviewed by Maciej.
index d3ea56c4833b2003f3242a4f39ccf2d1e8f2c0e2..e7a81ffce7b3b6fa435515483bacf92d34b8c26d 100644 (file)
@@ -154,7 +154,7 @@ public:
     m_onlyLocalReferences = false;
 
     m_caretBlinkTimer = 0;
-    m_caretVisible = true;
+    m_caretVisible = false;
     m_caretBlinks = true;
     m_caretPaint = true;
     
index dae015cc93ca97dde4523fac639adc4af12d6fdf..5674256e90face8a7901370b845465aa0ac3de6d 100644 (file)
@@ -273,11 +273,8 @@ public:
     
     void setMediaType(const QString &);
 
-    void setUsesInactiveTextBackgroundColor(bool u) { _usesInactiveTextBackgroundColor = u; }
-    bool usesInactiveTextBackgroundColor() const { return _usesInactiveTextBackgroundColor; }
-
-    void setShowsFirstResponder(bool flag);
-    bool showsFirstResponder() const { return _showsFirstResponder; }
+    void setDisplaysWithFocusAttributes(bool flag);
+    bool displaysWithFocusAttributes() const { return _displaysWithFocusAttributes; }
     
     // Convenience, to avoid repeating the code to dig down to get this.
     QChar backslashAsCurrencySymbol() const;
@@ -379,8 +376,7 @@ private:
 
     KWQWindowWidget *_windowWidget;
 
-    bool _usesInactiveTextBackgroundColor;
-    bool _showsFirstResponder;
+    bool _displaysWithFocusAttributes;
     mutable bool _drawSelectionOnly;
     bool _haveUndoRedoOperations;
     
index 2a13757a0163f4525075acbcba92cfba65b2c3d0..ae6f0dbd41598292bb9ce3b74121cac228d285fb 100644 (file)
@@ -183,8 +183,7 @@ KWQKHTMLPart::KWQKHTMLPart()
     , _formValuesAboutToBeSubmitted(nil)
     , _formAboutToBeSubmitted(nil)
     , _windowWidget(NULL)
-    , _usesInactiveTextBackgroundColor(false)
-    , _showsFirstResponder(true)
+    , _displaysWithFocusAttributes(false)
     , _drawSelectionOnly(false)
     , _bindingRoot(0)
     , _windowScriptObject(0)
@@ -3267,17 +3266,28 @@ void KWQKHTMLPart::setMediaType(const QString &type)
     }
 }
 
-void KWQKHTMLPart::setShowsFirstResponder(bool flag)
+void KWQKHTMLPart::setDisplaysWithFocusAttributes(bool flag)
 {
-    if (flag != _showsFirstResponder) {
-        _showsFirstResponder = flag;
-        DocumentImpl *doc = xmlDocImpl();
-        if (doc) {
-            NodeImpl *node = doc->focusNode();
-            if (node && node->renderer())
-                node->renderer()->repaint();
-        }
-        setCaretVisible(flag);
+    if (_displaysWithFocusAttributes == flag)
+        return;
+    _displaysWithFocusAttributes = flag;
+        
+    // This method does the job of updating the view based on whether the view is "active".
+    // This involves three kinds of drawing updates:
+
+    // 1. The background color used to draw behind selected content (active | inactive color)
+    if (d->m_view)
+        d->m_view->updateContents(QRect(visibleSelectionRect()));
+
+    // 2. Caret blinking (blinks | does not blink)
+    setCaretVisible(flag);
+
+    // 3. The drawing of a focus ring around links in web pages.
+    DocumentImpl *doc = xmlDocImpl();
+    if (doc) {
+        NodeImpl *node = doc->focusNode();
+        if (node && node->renderer())
+            node->renderer()->repaint();
     }
 }
 
index f0e86ed9891c5d191e6d5b73c776cbe4827e62b9..15bf0bd0088045a5ea17c3ea919be491525ac2e2 100644 (file)
@@ -186,11 +186,6 @@ typedef enum {
 - (void)adjustPageHeightNew:(float *)newBottom top:(float)oldTop bottom:(float)oldBottom limit:(float)bottomLimit;
 - (NSArray*)computePageRectsWithPrintWidthScaleFactor:(float)printWidthScaleFactor printHeight:(float)printHeight;
 
-- (void)setUsesInactiveTextBackgroundColor:(BOOL)uses;
-- (BOOL)usesInactiveTextBackgroundColor;
-
-- (void)setShowsFirstResponder:(BOOL)flag;
-
 - (void)setActivationEventNumber:(int)num;
 - (void)mouseDown:(NSEvent *)event;
 - (void)mouseUp:(NSEvent *)event;
@@ -243,6 +238,8 @@ typedef enum {
 - (NSAttributedString *)selectedAttributedString;
 - (NSString *)selectedString;
 
+- (void)setDisplaysWithFocusAttributes:(BOOL)flag;
+
 - (NSString *)stringForRange:(DOMRange *)range;
 
 - (NSString *)markupStringFromNode:(DOMNode *)node nodes:(NSArray **)nodes;
@@ -306,8 +303,6 @@ typedef enum {
 - (void)insertText:(NSString *)text;
 - (void)insertNewline;
 
-- (void)setCaretVisible:(BOOL)flag;
-
 - (void)setSelectionToDragCaret;
 - (void)moveSelectionToDragCaret:(DOMDocumentFragment *)selectionFragment;
 - (void)moveDragCaretToPoint:(NSPoint)point;
index 418f8b9abba7d8380f85f1ac23e5847b3109f515..a8fb357c90e1b876e3075fe84b06a22b1606ac22 100644 (file)
@@ -630,8 +630,9 @@ static BOOL nowPrinting(WebCoreBridge *self)
 - (void)drawRect:(NSRect)rect
 {
     QPainter painter(nowPrinting(self));
-    painter.setUsesInactiveTextBackgroundColor(_part->usesInactiveTextBackgroundColor());
-    painter.setDrawsFocusRing(_part->showsFirstResponder());
+    bool displaysWithFocusAttributes = _part->displaysWithFocusAttributes();
+    painter.setUsesInactiveTextBackgroundColor(!displaysWithFocusAttributes);
+    painter.setDrawsFocusRing(displaysWithFocusAttributes);
     [self drawRect:rect withPainter:&painter];
 }
 
@@ -1253,19 +1254,9 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     return externalRepresentation(_part->renderer()).getNSString();
 }
 
-- (void)setUsesInactiveTextBackgroundColor:(BOOL)uses
+- (void)setDisplaysWithFocusAttributes:(BOOL)flag
 {
-    _part->setUsesInactiveTextBackgroundColor(uses);
-}
-
-- (BOOL)usesInactiveTextBackgroundColor
-{
-    return _part->usesInactiveTextBackgroundColor();
-}
-
-- (void)setShowsFirstResponder:(BOOL)flag
-{
-    _part->setShowsFirstResponder(flag);
+    _part->setDisplaysWithFocusAttributes(flag);
 }
 
 - (void)setShouldCreateRenderers:(BOOL)f
@@ -1301,7 +1292,7 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
             return pseudoStyle->backgroundColor().getNSColor();
         }
     }
-    return _part->usesInactiveTextBackgroundColor() ? [NSColor secondarySelectedControlColor] : [NSColor selectedTextBackgroundColor];
+    return _part->displaysWithFocusAttributes() ? [NSColor selectedTextBackgroundColor] : [NSColor secondarySelectedControlColor];
 }
 
 - (void)adjustViewSize
@@ -1497,14 +1488,6 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     [self ensureCaretVisible];
 }
 
-- (void)setCaretVisible:(BOOL)flag
-{
-    if (!_part)
-        return;
-        
-    _part->setCaretVisible(flag);
-}
-
 - (void)setSelectionToDragCaret
 {
     _part->setSelection(_part->dragCaret());
index 71a1b4bb649081131742565477da8b67930f9c06..cc7954bcf82f7653fc53854a65a35d9a69c7d38b 100644 (file)
@@ -1,3 +1,25 @@
+2004-07-23  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Trey
+
+        Fix for this bug:
+        
+        <rdar://problem/3738920> Caret blinks in inactive window
+
+        As part of the fix, I cleaned up the way we handle special drawing that needs
+        to be done in the HTML view that is first responder in the key window (e.g the
+        drawing of text selection highlight and caret blinking).
+
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView updateFocusDisplay]): New method that centralizes the changes
+        we need to make when the first responder-ness of the view or key-ness of the
+        window changes.
+        (-[WebHTMLView viewDidMoveToWindow]): Call new updateFocusDisplay helper.
+        (-[WebHTMLView windowDidBecomeKey:]): Ditto.
+        (-[WebHTMLView windowDidResignKey:]): Ditto.
+        (-[WebHTMLView becomeFirstResponder]): Ditto.
+        (-[WebHTMLView resignFirstResponder]): Ditto.
+
 2004-07-22  Darin Adler  <darin@apple.com>
 
         * Plugins.subproj/npruntime.h: Update with new version from newer JavaScriptCore.
index 3eae7305e79d8be66c8feeff67afede82a49ef9f..c17f434984e25a921e7fb316d2109e6125578c16 100644 (file)
@@ -1253,23 +1253,6 @@ static WebHTMLView *lastHitView = nil;
     return YES;
 }
 
-- (void)updateTextBackgroundColor
-{
-    NSWindow *window = [self window];
-    BOOL shouldUseInactiveTextBackgroundColor = !([window isKeyWindow] && [window firstResponder] == self) ||
-        _private->resigningFirstResponder;
-    WebBridge *bridge = [self _bridge];
-    if ([bridge usesInactiveTextBackgroundColor] != shouldUseInactiveTextBackgroundColor) {
-        [bridge setUsesInactiveTextBackgroundColor:shouldUseInactiveTextBackgroundColor];
-        [self setNeedsDisplayInRect:[bridge visibleSelectionRect]];
-    }
-}
-
-- (void)setCaretVisible:(BOOL)flag
-{
-    [[self _bridge] setCaretVisible:flag];
-}
-
 - (BOOL)maintainsInactiveSelection
 {
     // This method helps to determing whether the view should maintain
@@ -1310,9 +1293,20 @@ static WebHTMLView *lastHitView = nil;
         name:NSMouseMovedNotification object:nil];
 }
 
-- (void)updateShowsFirstResponder
+- (void)updateFocusDisplay
 {
-    [[self _bridge] setShowsFirstResponder:[[self window] isKeyWindow]];
+    // 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 
+    // drawing updates right now, all handled in WebCore in response to the call over the bridge. 
+    // 
+    // The three display attributes are as follows:
+    // 
+    // 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.
+
+    BOOL flag = !_private->resigningFirstResponder && [[self window] isKeyWindow] && [self firstResponderIsSelfOrDescendantView];
+    [[self _bridge] setDisplaysWithFocusAttributes:flag];
 }
 
 - (void)addSuperviewObservers
@@ -1416,7 +1410,7 @@ static WebHTMLView *lastHitView = nil;
             [self addWindowObservers];
             [self addSuperviewObservers];
             [self addMouseMovedObserver];
-            [self updateTextBackgroundColor];
+            [self updateFocusDisplay];
     
             [[self _pluginController] startAllPlugins];
     
@@ -1717,20 +1711,14 @@ static WebHTMLView *lastHitView = nil;
 {
     ASSERT([notification object] == [self window]);
     [self addMouseMovedObserver];
-    if ([self firstResponderIsSelfOrDescendantView]) {
-        [self updateTextBackgroundColor];
-        [self updateShowsFirstResponder];
-    }
+    [self updateFocusDisplay];
 }
 
 - (void)windowDidResignKey: (NSNotification *)notification
 {
     ASSERT([notification object] == [self window]);
     [self removeMouseMovedObserver];
-    if ([self firstResponderIsSelfOrDescendantView]) {
-        [self updateTextBackgroundColor];
-        [self updateShowsFirstResponder];
-    }
+    [self updateFocusDisplay];
 }
 
 - (void)windowWillClose:(NSNotification *)notification
@@ -2070,8 +2058,7 @@ static WebHTMLView *lastHitView = nil;
     if (view) {
         [[self window] makeFirstResponder:view];
     }
-    [self setCaretVisible:YES];
-    [self updateTextBackgroundColor];
+    [self updateFocusDisplay];
     return YES;
 }
 
@@ -2090,8 +2077,7 @@ static WebHTMLView *lastHitView = nil;
                 [self deselectAll];
             }
         }
-        [self setCaretVisible:NO];
-        [self updateTextBackgroundColor];
+        [self updateFocusDisplay];
         _private->resigningFirstResponder = NO;
     }
     return resign;