Changeset 20901 in webkit


Ignore:
Timestamp:
Apr 16, 2007 8:41:04 AM (17 years ago)
Author:
darin
Message:

WebCore:

Reviewed by John Sullivan.

  • fix a related problem where elements could look focused in non-active windows
  • simplify secure keyboard entry logic in Frame::setIsActive
  • WebCore.exp: Add two new symbols for use by WebKit.
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::dispatchFocusEvent): Call setUseSecureKeyboardEntryWhenActive rather than calling setSecureKeyboardEntry directly -- does nothing if the frame is not active. (WebCore::HTMLInputElement::dispatchBlurEvent): Ditto.
  • page/Frame.cpp: (WebCore::Frame::setUseSecureKeyboardEntryWhenActive): Added. Calls setUseSecureKeyboardEntry only if the frame is active, but also stores away the state, so that the setIsActive function doesn't have to recompute it. (WebCore::Frame::setIsActive): Rewrote all the comments in the function. Removed the code to manage control tints, which are not based on the whether the frame is active but rather on AppKit's concept of whether the window should have "key appearance". Simplified the logic about when to call setUseSecureKeyboardEntry by using the value of m_useSecureKeyboardEntryWhenActive. (WebCore::FramePrivate::FramePrivate): Initialize m_useSecureKeyboardEntryWhenActive.
  • page/Frame.h: Made setSecureKeyboardEntry private and renamed it to setUseSecureKeyboardEntry, removed isSecureKeyboardEntry, and added a public setUseSecureKeyboardEntryWhenActive.
  • page/FramePrivate.h: Added m_useSecureKeyboardEntryWhenActive.
  • page/mac/FrameMac.mm: (WebCore::Frame::setUseSecureKeyboardEntry): Added an assertion, and removed isSecureKeyboardEntry().
  • page/FrameView.h: Added updateControlTints.
  • page/FrameView.cpp: (WebCore::FrameView::updateControlTints): Added. Code was moved here from setIsActive for two reasons: (1) it makes more sense in the view class, and (2) it needs to be called at the appropriate time for AppKit, not when active changes.
  • rendering/RenderTheme.cpp: (WebCore::RenderTheme::isFocused): Added an isActive check here to match the logic in the implementation of the CSS pseudo-state.
  • rendering/RenderThemeMac.mm: (WebCore::RenderThemeMac::updateFocusedState): Use the isFocused function instead of repeating the logic here. Removed the "need to add a key window test here" comment. (WebCore::RenderThemeMac::controlSupportsTints): Added a comment about the NSCell SPI that's related to the _windowChangedKeyState method we now use in WebHTMLView.

WebKit:

Reviewed by John Sullivan.

  • WebView/WebHTMLView.mm: (-[WebHTMLView _windowChangedKeyState]): Added. Calls FrameView::updateControlTints.
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r20900 r20901  
     12007-04-16  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by John Sullivan.
     4
     5        - fix http://bugs.webkit.org/show_bug.cgi?id=13303
     6          <rdar://problem/5126341> REGRESSION: controls in a background Safari window
     7          maintain active appearance if the address bar has focus (13303)
     8
     9        - fix a related problem where elements could look focused in non-active windows
     10
     11        - simplify secure keyboard entry logic in Frame::setIsActive
     12
     13        * WebCore.exp: Add two new symbols for use by WebKit.
     14
     15        * html/HTMLInputElement.cpp:
     16        (WebCore::HTMLInputElement::dispatchFocusEvent): Call setUseSecureKeyboardEntryWhenActive
     17        rather than calling setSecureKeyboardEntry directly -- does nothing if the frame is not active.
     18        (WebCore::HTMLInputElement::dispatchBlurEvent): Ditto.
     19
     20        * page/Frame.cpp:
     21        (WebCore::Frame::setUseSecureKeyboardEntryWhenActive): Added. Calls
     22        setUseSecureKeyboardEntry only if the frame is active, but also stores away the state,
     23        so that the setIsActive function doesn't have to recompute it.
     24        (WebCore::Frame::setIsActive): Rewrote all the comments in the function. Removed the code
     25        to manage control tints, which are not based on the whether the frame is active but rather
     26        on AppKit's concept of whether the window should have "key appearance". Simplified the
     27        logic about when to call setUseSecureKeyboardEntry by using the value of
     28        m_useSecureKeyboardEntryWhenActive.
     29        (WebCore::FramePrivate::FramePrivate): Initialize m_useSecureKeyboardEntryWhenActive.
     30        * page/Frame.h: Made setSecureKeyboardEntry private and renamed it to
     31        setUseSecureKeyboardEntry, removed isSecureKeyboardEntry, and
     32        added a public setUseSecureKeyboardEntryWhenActive.
     33        * page/FramePrivate.h: Added m_useSecureKeyboardEntryWhenActive.
     34        * page/mac/FrameMac.mm: (WebCore::Frame::setUseSecureKeyboardEntry): Added an assertion,
     35        and removed isSecureKeyboardEntry().
     36
     37        * page/FrameView.h: Added updateControlTints.
     38        * page/FrameView.cpp: (WebCore::FrameView::updateControlTints): Added. Code was moved
     39        here from setIsActive for two reasons: (1) it makes more sense in the view class, and
     40        (2) it needs to be called at the appropriate time for AppKit, not when active changes.
     41
     42        * rendering/RenderTheme.cpp: (WebCore::RenderTheme::isFocused): Added an isActive
     43        check here to match the logic in the implementation of the CSS pseudo-state.
     44        * rendering/RenderThemeMac.mm:
     45        (WebCore::RenderThemeMac::updateFocusedState): Use the isFocused function instead of
     46        repeating the logic here. Removed the "need to add a key window test here" comment.
     47        (WebCore::RenderThemeMac::controlSupportsTints): Added a comment about the NSCell
     48        SPI that's related to the _windowChangedKeyState method we now use in WebHTMLView.
     49
    1502007-04-16  Darin Adler  <darin@apple.com>
    251
  • trunk/WebCore/WebCore.exp

    r20837 r20901  
    441441__ZN7WebCore9FrameTree11appendChildEN3WTF10PassRefPtrINS_5FrameEEE
    442442__ZN7WebCore9FrameTree7setNameERKNS_12AtomicStringE
     443__ZN7WebCore9FrameView18updateControlTintsEv
    443444__ZN7WebCore9HTMLNames10listingTagE
    444445__ZN7WebCore9HTMLNames13blockquoteTagE
     
    572573__ZNK7WebCore5Frame4pageEv
    573574__ZNK7WebCore5Frame4treeEv
     575__ZNK7WebCore5Frame4viewEv
    574576__ZNK7WebCore5Frame6bridgeEv
    575577__ZNK7WebCore5Frame6editorEv
  • trunk/WebCore/html/HTMLInputElement.cpp

    r20725 r20901  
    233233        setAutofilled(false);
    234234        if (inputType() == PASSWORD && document()->frame())
    235             document()->frame()->setSecureKeyboardEntry(true);
     235            document()->frame()->setUseSecureKeyboardEntryWhenActive(true);
    236236    }
    237237    HTMLGenericFormElement::dispatchFocusEvent();
     
    242242    if (isTextField() && document()->frame()) {
    243243        if (inputType() == PASSWORD)
    244             document()->frame()->setSecureKeyboardEntry(false);
     244            document()->frame()->setUseSecureKeyboardEntryWhenActive(false);
    245245        document()->frame()->textFieldDidEndEditing(this);
    246246    }
  • trunk/WebCore/page/Frame.cpp

    r20819 r20901  
    771771
    772772#if !PLATFORM(MAC)
    773 void Frame::setSecureKeyboardEntry(bool)
    774 {
    775 }
    776 
    777 bool Frame::isSecureKeyboardEntry()
    778 {
    779     return false;
     773
     774void Frame::setUseSecureKeyboardEntry(bool)
     775{
    780776}
    781777
    782778#endif
     779
     780void Frame::setUseSecureKeyboardEntryWhenActive(bool usesSecureKeyboard)
     781{
     782    if (d->m_useSecureKeyboardEntryWhenActive == usesSecureKeyboard)
     783        return;
     784    d->m_useSecureKeyboardEntryWhenActive = usesSecureKeyboard;
     785
     786    if (d->m_isActive)
     787        setUseSecureKeyboardEntry(usesSecureKeyboard);
     788}
    783789
    784790CSSMutableStyleDeclaration *Frame::typingStyle() const
     
    14811487    if (d->m_isActive == flag)
    14821488        return;
    1483    
    14841489    d->m_isActive = flag;
    14851490
    1486     // This method does the job of updating the view based on whether the view is "active".
    1487     // This involves three kinds of drawing updates:
    1488 
    1489     // 1. The background color used to draw behind selected content (active | inactive color)
     1491    // Because RenderObject::selectionBackgroundColor() and
     1492    // RenderObject::selectionForegroundColor() check if the frame is active,
     1493    // we have to update places those colors were painted.
    14901494    if (d->m_view)
    14911495        d->m_view->updateContents(enclosingIntRect(visibleSelectionRect()));
    14921496
    1493     // 2. Caret blinking (blinks | does not blink)
     1497    // Caret appears in the active frame.
    14941498    if (flag)
    14951499        setSelectionFromNone();
    14961500    setCaretVisible(flag);
    1497    
    1498     // 3. The drawing of a focus ring around links in web pages.
    1499     Document *doc = document();
    1500     if (doc) {
    1501         Node *node = doc->focusedNode();
    1502         if (node) {
     1501
     1502    // Because CSSStyleSelector::checkOneSelector() and
     1503    // RenderTheme::isFocused() check if the frame is active, we have to
     1504    // update style and theme state that depended on those.
     1505    if (d->m_doc) {
     1506        if (Node* node = d->m_doc->focusedNode()) {
    15031507            node->setChanged();
    1504             if (node->renderer() && node->renderer()->style()->hasAppearance())
    1505                 theme()->stateChanged(node->renderer(), FocusState);
     1508            if (RenderObject* renderer = node->renderer())
     1509                if (renderer && renderer->style()->hasAppearance())
     1510                    theme()->stateChanged(renderer, FocusState);
    15061511        }
    15071512    }
    1508    
    1509     // 4. Changing the tint of controls from clear to aqua/graphite and vice versa.  We
    1510     // do a "fake" paint.  When the theme gets a paint call, it can then do an invalidate.  This is only
    1511     // done if the theme supports control tinting.
    1512     if (doc && d->m_view && theme()->supportsControlTints() && renderer()) {
    1513         doc->updateLayout(); // Ensure layout is up to date.
    1514         IntRect visibleRect(enclosingIntRect(d->m_view->visibleContentRect()));
    1515         GraphicsContext context((PlatformGraphicsContext*)0);
    1516         context.setUpdatingControlTints(true);
    1517         paint(&context, visibleRect);
    1518     }
    1519    
    1520     // 5. Enable or disable secure keyboard entry
    1521     if ((flag && !isSecureKeyboardEntry() && doc && doc->focusedNode() && doc->focusedNode()->hasTagName(inputTag) &&
    1522             static_cast<HTMLInputElement*>(doc->focusedNode())->inputType() == HTMLInputElement::PASSWORD) ||
    1523         (!flag && isSecureKeyboardEntry()))
    1524             setSecureKeyboardEntry(flag);
     1513
     1514    // Secure keyboard entry is set by the active frame.
     1515    if (d->m_useSecureKeyboardEntryWhenActive)
     1516        setUseSecureKeyboardEntry(flag);
    15251517}
    15261518
     
    18711863    , m_caretPaint(true)
    18721864    , m_isActive(false)
     1865    , m_useSecureKeyboardEntryWhenActive(false)
    18731866    , m_lifeSupportTimer(thisFrame, &Frame::lifeSupportTimerFired)
    18741867    , m_loader(new FrameLoader(thisFrame, frameLoaderClient))
  • trunk/WebCore/page/Frame.h

    r20794 r20901  
    11// -*- c-basic-offset: 4 -*-
    2  /* This file is part of the KDE project
    3  *
     2/*
    43 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
    54 *                     1999-2001 Lars Knoll <knoll@kde.org>
     
    87 *                     2000-2001 Dirk Mueller <mueller@kde.org>
    98 *                     2000 Stefan Schimanski <1Stein@gmx.de>
    10  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
     9 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
    1110 * Copyright (C) 2007 Trolltech ASA
    1211 *
     
    4342namespace KJS {
    4443    class Interpreter;
    45     class JSObject;
    4644   
    4745    namespace Bindings {
     
    5351#if PLATFORM(MAC)
    5452#ifdef __OBJC__
    55 @class WebCoreFrameBridge;
    56 @class WebScriptObject;
    5753@class NSArray;
    5854@class NSDictionary;
    59 @class NSFont;
    60 @class NSImage;
    6155@class NSMenu;
    6256@class NSMutableDictionary;
    6357@class NSString;
    6458@class WebCoreFrameBridge;
     59@class WebScriptObject;
    6560#else
    66 class WebCoreFrameBridge;
    67 class WebScriptObject;
    6861class NSArray;
    6962class NSDictionary;
    70 class NSFont;
    71 class NSImage;
    7263class NSMenu;
    7364class NSMutableDictionary;
    7465class NSString;
    7566class WebCoreFrameBridge;
    76 typedef unsigned int NSDragOperation;
     67class WebScriptObject;
    7768typedef int NSWritingDirection;
    7869#endif
     
    10697class Page;
    10798class Range;
    108 class RenderObject;
    10999class RenderPart;
    110 class RenderStyle;
    111100class Selection;
    112101class SelectionController;
     
    179168    // should move to FrameView
    180169    void paint(GraphicsContext*, const IntRect&);
    181     void setPaintRestriction(PaintRestriction pr);
     170    void setPaintRestriction(PaintRestriction);
    182171
    183172    void setUserStyleSheetLocation(const KURL&);
     
    326315    bool isContentEditable() const; // if true, everything in frame is editable
    327316
    328     void setSecureKeyboardEntry(bool);
    329     bool isSecureKeyboardEntry();
     317    void setUseSecureKeyboardEntryWhenActive(bool);
    330318
    331319    CSSMutableStyleDeclaration* typingStyle() const;
     
    344332private:
    345333    void caretBlinkTimerFired(Timer<Frame>*);
     334    void setUseSecureKeyboardEntry(bool);
    346335
    347336// === to be moved into the Platform directory
     
    360349
    361350#if PLATFORM(MAC)
     351
    362352// === undecided, may or may not belong here
    363353
     
    380370
    381371public:
    382 
    383372    FloatRect customHighlightLineRect(const AtomicString& type, const FloatRect& lineRect, Node*);
    384373    void paintCustomHighlight(const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect, bool text, bool line, Node*);
     
    387376
    388377public:
    389 
    390378    NSDictionary* fontAttributesForSelectionStart() const;
    391379    NSWritingDirection baseWritingDirectionForSelectionStart() const;
    392380
    393381    void setMarkedTextRange(const Range* , NSArray* attributes, NSArray* ranges);
    394 #endif
     382
     383#endif
     384
    395385};
    396386
  • trunk/WebCore/page/FramePrivate.h

    r19811 r20901  
    9898        bool m_caretPaint : 1;
    9999        bool m_isActive : 1;
     100        bool m_useSecureKeyboardEntryWhenActive : 1;
    100101
    101102        RefPtr<CSSMutableStyleDeclaration> m_typingStyle;
  • trunk/WebCore/page/FrameView.cpp

    r20794 r20901  
    1 /* This file is part of the KDE project
    2  *
     1/*
    32 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
    43 *                     1999 Lars Knoll <knoll@kde.org>
    54 *                     1999 Antti Koivisto <koivisto@kde.org>
    65 *                     2000 Dirk Mueller <mueller@kde.org>
    7  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
     6 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
    87 *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
    98 *           (C) 2006 Alexey Proskuryakov (ap@nypop.com)
     
    3433#include "FrameLoader.h"
    3534#include "FrameLoaderClient.h"
     35#include "GraphicsContext.h"
    3636#include "HTMLDocument.h"
    3737#include "HTMLFrameSetElement.h"
     
    3939#include "OverflowEvent.h"
    4040#include "RenderPart.h"
     41#include "RenderTheme.h"
    4142#include "RenderView.h"
    4243
     
    894895}
    895896
    896 }
     897void FrameView::updateControlTints()
     898{
     899    // This is called when control tints are changed from aqua/graphite to clear and vice versa.
     900    // We do a "fake" paint, and when the theme gets a paint call, it can then do an invalidate.
     901    // This is only done if the theme supports control tinting. It's up to the theme and platform
     902    // to define when controls get the tint and to call this function when that changes.
     903    Document* doc = m_frame->document();
     904    if (doc && theme()->supportsControlTints() && m_frame->renderer()) {
     905        doc->updateLayout(); // Ensure layout is up to date.
     906        PlatformGraphicsContext* const noContext = 0;
     907        GraphicsContext context(noContext);
     908        context.setUpdatingControlTints(true);
     909        m_frame->paint(&context, enclosingIntRect(visibleContentRect()));
     910    }
     911}
     912
     913}
  • trunk/WebCore/page/FrameView.h

    r20794 r20901  
    122122
    123123    void updateDashboardRegions();
     124    void updateControlTints();
    124125
    125126    void restoreScrollbar();
  • trunk/WebCore/page/mac/FrameMac.mm

    r20404 r20901  
    507507
    508508const short enableRomanKeyboardsOnly = -23;
    509 void Frame::setSecureKeyboardEntry(bool enable)
    510 {
     509void Frame::setUseSecureKeyboardEntry(bool enable)
     510{
     511    // Caller is responsible for only calling when it's an actual change.
     512    ASSERT(enable != IsSecureEventInputEnabled());
    511513    if (enable) {
    512514        EnableSecureEventInput();
    513 // FIXME: KeyScript is deprecated in Leopard, we need a new solution for this <rdar://problem/4727607>
     515        // FIXME: Since KeyScript is deprecated in Leopard, we need a new solution for this. <rdar://problem/4727607>
    514516#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
    515517        KeyScript(enableRomanKeyboardsOnly);
     
    521523#endif
    522524    }
    523 }
    524 
    525 bool Frame::isSecureKeyboardEntry()
    526 {
    527     return IsSecureEventInputEnabled();
    528525}
    529526
  • trunk/WebCore/rendering/RenderTheme.cpp

    r18263 r20901  
    2424
    2525#include "Document.h"
     26#include "Frame.h"
    2627#include "GraphicsContext.h"
    2728#include "HTMLInputElement.h"
     
    355356bool RenderTheme::isFocused(const RenderObject* o) const
    356357{
    357     if (!o->element())
    358         return false;
    359     return o->element() == o->element()->document()->focusedNode();
     358    Node* node = o->element();
     359    if (!node)
     360        return false;
     361    Document* document = node->document();
     362    Frame* frame = document->frame();
     363    return node == document->focusedNode() && frame && frame->isActive();
    360364}
    361365
  • trunk/WebCore/rendering/RenderThemeMac.mm

    r20475 r20901  
    258258void RenderThemeMac::updateFocusedState(NSCell* cell, const RenderObject* o)
    259259{
    260     // FIXME: Need to add a key window test here, or the element will look
    261     // focused even when in the background.
    262260    bool oldFocused = [cell showsFirstResponder];
    263     bool focused = (o->element() && o->document()->focusedNode() == o->element()) && (o->style()->outlineStyleIsAuto());
     261    bool focused = isFocused(o) && o->style()->outlineStyleIsAuto();
    264262    if (focused != oldFocused)
    265263        [cell setShowsFirstResponder:focused];
     
    283281bool RenderThemeMac::controlSupportsTints(const RenderObject* o) const
    284282{
     283    // An alternate way to implement this would be to get the appropriate cell object
     284    // and call the private _needRedrawOnWindowChangedKeyState method. An advantage of
     285    // that would be that we would match AppKit behavior more closely, but a disadvantage
     286    // would be that we would rely on an AppKit SPI method.
     287
    285288    if (!isEnabled(o))
    286289        return false;
  • trunk/WebKit/ChangeLog

    r20888 r20901  
     12007-04-16  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by John Sullivan.
     4
     5        - fix http://bugs.webkit.org/show_bug.cgi?id=13303
     6          <rdar://problem/5126341> REGRESSION: controls in a background Safari window
     7          maintain active appearance if the address bar has focus (13303)
     8
     9        * WebView/WebHTMLView.mm: (-[WebHTMLView _windowChangedKeyState]):
     10        Added. Calls FrameView::updateControlTints.
     11
    1122007-04-13  Oliver Hunt  <oliver@apple.com>
    213
  • trunk/WebKit/WebView/WebHTMLView.mm

    r20814 r20901  
    8383#import <WebCore/Frame.h>
    8484#import <WebCore/FrameLoader.h>
     85#import <WebCore/FrameView.h>
    8586#import <WebCore/HitTestResult.h>
    8687#import <WebCore/Image.h>
     
    129130- (void)_setDrawsOwnDescendants:(BOOL)drawsOwnDescendants;
    130131- (void)_propagateDirtyRectsToOpaqueAncestors;
     132- (void)_windowChangedKeyState;
    131133@end
    132134
     
    48934895}
    48944896
     4897// Despite its name, this is called at different times than windowDidBecomeKey is.
     4898// It takes into account all the other factors that determine when NSCell draws
     4899// with different tints, so it's the right call to use for control tints. We'd prefer
     4900// to do this with API. <rdar://problem/5136760>
     4901- (void)_windowChangedKeyState
     4902{
     4903    if (Frame* frame = core([self _frame]))
     4904        if (FrameView* view = frame->view())
     4905            view->updateControlTints();
     4906    [super _windowChangedKeyState];
     4907}
     4908
    48954909@end
    48964910
Note: See TracChangeset for help on using the changeset viewer.