Changeset 16760 in webkit


Ignore:
Timestamp:
Oct 3, 2006 7:31:10 PM (18 years ago)
Author:
bdash
Message:

2006-10-03 Graham Dennis <graham.dennis@gmail.com>

Reviewed by Timothy.

<http://bugzilla.opendarwin.org/show_bug.cgi?id=10338>
When contentEditable, cursor doesn't change to hand


Allow the behaviour of editable links to be specified by a WebPreference
The preference WebKitEditableLinkBehavior has four options:

  • AlwaysLive: Safari 2.0 behaviour
  • OnlyLiveWithShiftKey: Firefox/WinIE behaviour (and prior WebKit-ToT behaviour)
  • LiveWhenNotFocused: Editable links are live only when their editable block is not

focused, or when the shift key is pressed

  • DefaultBehavior: This is the same as OnlyLiveWithShiftKey.


No layout tests, just a modification of a manual-test as it isn't possible to test
this automatically.

  • bridge/mac/WebCoreSettings.h:
  • bridge/mac/WebCoreSettings.mm: (-[WebCoreSettings setEditableLinkBehavior:]): (-[WebCoreSettings editableLinkBehavior]):
  • html/HTMLAnchorElement.cpp: (WebCore::HTMLAnchorElement::HTMLAnchorElement): (WebCore::HTMLAnchorElement::defaultEventHandler): (WebCore::HTMLAnchorElement::setActive):
  • html/HTMLAnchorElement.h:
  • manual-tests/contenteditable-link.html:
  • page/FrameView.cpp: (WebCore::nodeIsNotBeingEdited): (WebCore::selectCursor):
  • page/Settings.h: (WebCore::Settings::): (WebCore::Settings::Settings): (WebCore::Settings::editableLinkBehavior): (WebCore::Settings::setEditableLinkBehavior):

2006-10-03 Graham Dennis <graham.dennis@gmail.com>

Reviewed by Timothy.

<http://bugzilla.opendarwin.org/show_bug.cgi?id=10338>
When contentEditable, cursor doesn't change to hand


Allow the behaviour of editable links to be specified by a WebPreference
The preference WebKitEditableLinkBehavior has four options:

  • AlwaysLive: Safari 2.0 behaviour
  • OnlyLiveWithShiftKey: Firefox/WinIE behaviour (and prior WebKit-ToT behaviour)
  • LiveWhenNotFocused: Editable links are live only when their editable block is not

focused, or when the shift key is pressed

  • DefaultBehavior: This is the same as OnlyLiveWithShiftKey.


No layout tests, just a modification of a manual-test as it isn't possible to test
this automatically.

  • WebView/WebPreferenceKeysPrivate.h:
  • WebView/WebPreferences.m: (+[WebPreferences initialize]): (-[WebPreferences editableLinkBehavior]): (-[WebPreferences setEditableLinkBehavior:]):
  • WebView/WebPreferencesPrivate.h:
  • WebView/WebView.m: (-[WebView _updateWebCoreSettingsFromPreferences:]):
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r16759 r16760  
     12006-10-03  Graham Dennis  <graham.dennis@gmail.com>
     2
     3        Reviewed by Timothy.
     4
     5        <http://bugzilla.opendarwin.org/show_bug.cgi?id=10338>
     6        When contentEditable, cursor doesn't change to hand
     7       
     8        Allow the behaviour of editable links to be specified by a WebPreference
     9        The preference WebKitEditableLinkBehavior has four options:
     10         - AlwaysLive: Safari 2.0 behaviour
     11         - OnlyLiveWithShiftKey: Firefox/WinIE behaviour (and prior WebKit-ToT behaviour)
     12         - LiveWhenNotFocused: Editable links are live only when their editable block is not
     13             focused, or when the shift key is pressed
     14         - DefaultBehavior: This is the same as OnlyLiveWithShiftKey.
     15         
     16        No layout tests, just a modification of a manual-test as it isn't possible to test
     17        this automatically.
     18
     19        * bridge/mac/WebCoreSettings.h:
     20        * bridge/mac/WebCoreSettings.mm:
     21        (-[WebCoreSettings setEditableLinkBehavior:]):
     22        (-[WebCoreSettings editableLinkBehavior]):
     23        * html/HTMLAnchorElement.cpp:
     24        (WebCore::HTMLAnchorElement::HTMLAnchorElement):
     25        (WebCore::HTMLAnchorElement::defaultEventHandler):
     26        (WebCore::HTMLAnchorElement::setActive):
     27        * html/HTMLAnchorElement.h:
     28        * manual-tests/contenteditable-link.html:
     29        * page/FrameView.cpp:
     30        (WebCore::nodeIsNotBeingEdited):
     31        (WebCore::selectCursor):
     32        * page/Settings.h:
     33        (WebCore::Settings::):
     34        (WebCore::Settings::Settings):
     35        (WebCore::Settings::editableLinkBehavior):
     36        (WebCore::Settings::setEditableLinkBehavior):
     37
    1382006-10-03  Beth Dakin  <bdakin@apple.com>
    239
  • trunk/WebCore/bridge/mac/WebCoreSettings.h

    r15438 r16760  
    119119- (NSString *)defaultTextEncoding;
    120120
     121- (void)setEditableLinkBehavior:(int)behavior;
     122- (int)editableLinkBehavior;
     123
    121124- (WebCoreSettingsImpl *)settings;
    122125
  • trunk/WebCore/bridge/mac/WebCoreSettings.mm

    r16245 r16760  
    11/*
    22 * Copyright (C) 2004, 2006 Apple Computer, Inc.  All rights reserved.
     3 *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    335336}
    336337
     338- (void)setEditableLinkBehavior:(int)behavior
     339{
     340    Settings::EditableLinkBehavior b = (Settings::EditableLinkBehavior)behavior;
     341    if (b != Settings::EditableLinkDefaultBehavior &&
     342        b != Settings::EditableLinkAlwaysLive &&
     343        b != Settings::EditableLinkOnlyLiveWithShiftKey &&
     344        b != Settings::EditableLinkLiveWhenNotFocused) {
     345        settings->setEditableLinkBehavior(Settings::EditableLinkDefaultBehavior);
     346    } else
     347        settings->setEditableLinkBehavior(b);
     348}
     349
     350- (int)editableLinkBehavior
     351{
     352    return (int)settings->editableLinkBehavior();
     353}
     354
    337355- (Settings *)settings
    338356{
  • trunk/WebCore/html/HTMLAnchorElement.cpp

    r16250 r16760  
    66 *           (C) 2000 Simon Hausmann <hausmann@kde.org>
    77 * Copyright (C) 2003, 2006 Apple Computer, Inc.
     8 *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
    89 *
    910 * This library is free software; you can redistribute it and/or
     
    3637#include "RenderFlow.h"
    3738#include "RenderImage.h"
     39#include "SelectionController.h"
     40#include "Settings.h"
    3841#include "UIEvent.h"
    3942#include "csshelper.h"
     
    4649HTMLAnchorElement::HTMLAnchorElement(Document* doc)
    4750    : HTMLElement(aTag, doc)
     51    , m_rootEditableElementForSelectionOnMouseDown(0)
    4852{
    4953}
     
    5155HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document* doc)
    5256    : HTMLElement(tagName, doc)
     57    , m_rootEditableElementForSelectionOnMouseDown(0)
    5358{
    5459}
     
    129134        }
    130135
    131         if (e && !e->shiftKey() && isContentEditable()) {
    132             HTMLElement::defaultEventHandler(evt);
    133             return;
     136        // If the link is editable, then we need to check the settings to see whether or not to follow the link
     137        if (isContentEditable()) {
     138            Settings::EditableLinkBehavior editableLinkBehavior = Settings::EditableLinkDefaultBehavior;
     139            if (document()->frame() && document()->frame()->settings())
     140                editableLinkBehavior = document()->frame()->settings()->editableLinkBehavior();
     141               
     142            switch(editableLinkBehavior) {
     143                // Always follow the link (Safari 2.0 behavior)
     144                default:
     145                case Settings::EditableLinkDefaultBehavior:
     146                case Settings::EditableLinkAlwaysLive:
     147                    break;
     148                   
     149                // If the selection prior to clicking on this link resided in the same editable block as this link,
     150                // and the shift key isn't pressed, we don't want to follow the link
     151                case Settings::EditableLinkLiveWhenNotFocused:
     152                    if (e && !e->shiftKey() && m_rootEditableElementForSelectionOnMouseDown == rootEditableElement()) {
     153                        HTMLElement::defaultEventHandler(evt);
     154                        return;
     155                    }
     156                    break;
     157               
     158                // Only follow the link if the shift key is down (WinIE/Firefox behavior)
     159                case Settings::EditableLinkOnlyLiveWithShiftKey:
     160                    if (e && !e->shiftKey()) {
     161                        HTMLElement::defaultEventHandler(evt);
     162                        return;
     163                    }
     164                    break;
     165            }
    134166        }
    135167
     
    177209
    178210        evt->setDefaultHandled();
     211    } else if (m_isLink && isContentEditable()) {
     212    // This keeps track of the editable block that the selection was in (if it was in one) just before the link was clicked
     213    // for the LiveWhenNotFocused editable link behavior
     214        if (evt->type() == mousedownEvent && document()->frame() && document()->frame()->selectionController())
     215            m_rootEditableElementForSelectionOnMouseDown = document()->frame()->selectionController()->rootEditableElement();
     216        else if (evt->type() == mouseoutEvent)
     217            m_rootEditableElementForSelectionOnMouseDown = 0;
    179218    }
    180219
     
    184223void HTMLAnchorElement::setActive(bool down, bool pause)
    185224{
    186     if (isContentEditable())
    187         return;
     225    if (isContentEditable()) {
     226        Settings::EditableLinkBehavior editableLinkBehavior = Settings::EditableLinkDefaultBehavior;
     227        if (document()->frame() && document()->frame()->settings())
     228            editableLinkBehavior = document()->frame()->settings()->editableLinkBehavior();
     229           
     230        switch(editableLinkBehavior) {
     231            default:
     232            case Settings::EditableLinkDefaultBehavior:
     233            case Settings::EditableLinkAlwaysLive:
     234                break;
     235               
     236            // Don't set the link to be active if the current selection is in the same editable block as
     237            // this link
     238            case Settings::EditableLinkLiveWhenNotFocused:
     239                if (down && document()->frame() && document()->frame()->selectionController() &&
     240                    document()->frame()->selectionController()->rootEditableElement() == rootEditableElement())
     241                    return;
     242                break;
     243           
     244            case Settings::EditableLinkOnlyLiveWithShiftKey:
     245                return;
     246        }
     247
     248    }
     249   
    188250    ContainerNode::setActive(down, pause);
    189251}
  • trunk/WebCore/html/HTMLAnchorElement.h

    r15834 r16760  
    9595    String search() const;
    9696    String text() const;
     97   
     98private:
     99    Element *m_rootEditableElementForSelectionOnMouseDown;
    97100};
    98101
  • trunk/WebCore/manual-tests/contenteditable-link.html

    r14346 r16760  
    1616<P>Repro movie for bug <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=7156">#7156</a></P>
    1717
     18<div>The behaviour of editable links is controlled by the user default WebKitEditableLinkBehavior. This can be set via a private WebPreference. If the preference is OnlyLiveWithShiftKey, then the link will only be active when the shift key is pressed (WinIE/Firefox behaviour). If the preference is WebKitEditableLinkAlwaysLive or WebKitEditableLinkDefaultBehavior, then the link is always active (Safari 2.0 behaviour). Finally, if the preference is WebKitEditableLinkLiveWhenNotFocused, the link will only be live if the selection before clicking on the link is not in the same editable block as the link.</div>
     19
    1820<div id="editable" contentEditable="true">
    1921  <p>Test content</p>
  • trunk/WebCore/page/FrameView.cpp

    r16741 r16760  
    66 *                     2000 Dirk Mueller <mueller@kde.org>
    77 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
     8 *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
    89 *
    910 * This library is free software; you can redistribute it and/or
     
    4849#include "RenderView.h"
    4950#include "SelectionController.h"
     51#include "Settings.h"
    5052#include "cssstyleselector.h"
    5153
     
    666668}
    667669
     670// Returns true if the node's editable block is not current focused for editing
     671static bool nodeIsNotBeingEdited(Node* node, Frame* frame)
     672{
     673    return frame->selectionController()->rootEditableElement() != node->rootEditableElement();
     674}
     675
    668676static Cursor selectCursor(const MouseEventWithHitTestResults& event, Frame* frame, bool mousePressed)
    669677{
     
    704712        case CURSOR_AUTO: {
    705713            bool editable = (node && node->isContentEditable());
    706             if ((event.isOverLink() || isSubmitImage(node)) && (!editable || event.event().shiftKey()))
     714            bool editableLinkEnabled = false;
     715
     716            // If the link is editable, then we need to check the settings to see whether or not the link should be followed
     717            if (editable) {
     718                switch(frame->settings()->editableLinkBehavior()) {
     719                    default:
     720                    case Settings::EditableLinkDefaultBehavior:
     721                    case Settings::EditableLinkAlwaysLive:
     722                        editableLinkEnabled = true;
     723                        break;
     724                   
     725                    case Settings::EditableLinkLiveWhenNotFocused:
     726                        editableLinkEnabled = nodeIsNotBeingEdited(node, frame) || event.event().shiftKey();
     727                        break;
     728                   
     729                    case Settings::EditableLinkOnlyLiveWithShiftKey:
     730                        editableLinkEnabled = event.event().shiftKey();
     731                        break;
     732                }
     733            }
     734           
     735            if ((event.isOverLink() || isSubmitImage(node)) && (!editable || editableLinkEnabled))
    707736                return handCursor();
    708737            RenderLayer* layer = renderer ? renderer->enclosingLayer() : 0;
  • trunk/WebCore/page/Settings.h

    r16250 r16760  
    11/*
    22 * Copyright (C) 2003, 2006 Apple Computer, Inc.  All rights reserved.
     3 *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3536{
    3637public:
     38    enum EditableLinkBehavior {
     39        EditableLinkDefaultBehavior = 0,
     40        EditableLinkAlwaysLive,
     41        EditableLinkOnlyLiveWithShiftKey,
     42        EditableLinkLiveWhenNotFocused
     43    };
     44
    3745    Settings()
    3846        : m_minimumFontSize(0)
     
    4856        , m_shouldPrintBackgrounds(0)
    4957        , m_textAreasAreResizable(0)
     58        , m_editableLinkBehavior(EditableLinkDefaultBehavior)
    5059    {
    5160    }
     
    7685    bool shouldPrintBackgrounds() const { return m_shouldPrintBackgrounds; }
    7786    bool textAreasAreResizable() const { return m_textAreasAreResizable; }
     87    EditableLinkBehavior editableLinkBehavior() const { return m_editableLinkBehavior; }
    7888
    7989    void setStdFontName(const AtomicString& s) { m_stdFontName = s; }
     
    101111    void setShouldPrintBackgrounds(bool f) { m_shouldPrintBackgrounds = f; }
    102112    void setTextAreasAreResizable(bool f) { m_textAreasAreResizable = f; }
     113    void setEditableLinkBehavior(EditableLinkBehavior e) { m_editableLinkBehavior = e; }
    103114   
    104115private:
     
    124135    bool m_shouldPrintBackgrounds : 1;
    125136    bool m_textAreasAreResizable : 1;
     137    EditableLinkBehavior m_editableLinkBehavior;
    126138};
    127139
  • trunk/WebKit/ChangeLog

    r16752 r16760  
     12006-10-03  Graham Dennis  <graham.dennis@gmail.com>
     2
     3        Reviewed by Timothy.
     4
     5        <http://bugzilla.opendarwin.org/show_bug.cgi?id=10338>
     6        When contentEditable, cursor doesn't change to hand
     7       
     8        Allow the behaviour of editable links to be specified by a WebPreference
     9        The preference WebKitEditableLinkBehavior has four options:
     10         - AlwaysLive: Safari 2.0 behaviour
     11         - OnlyLiveWithShiftKey: Firefox/WinIE behaviour (and prior WebKit-ToT behaviour)
     12         - LiveWhenNotFocused: Editable links are live only when their editable block is not
     13             focused, or when the shift key is pressed
     14         - DefaultBehavior: This is the same as OnlyLiveWithShiftKey.
     15         
     16        No layout tests, just a modification of a manual-test as it isn't possible to test
     17        this automatically.
     18
     19        * WebView/WebPreferenceKeysPrivate.h:
     20        * WebView/WebPreferences.m:
     21        (+[WebPreferences initialize]):
     22        (-[WebPreferences editableLinkBehavior]):
     23        (-[WebPreferences setEditableLinkBehavior:]):
     24        * WebView/WebPreferencesPrivate.h:
     25        * WebView/WebView.m:
     26        (-[WebView _updateWebCoreSettingsFromPreferences:]):
     27
    1282006-10-03  Justin Garcia  <justin.garcia@apple.com>
    229
  • trunk/WebKit/WebView/WebPreferenceKeysPrivate.h

    r14480 r16760  
    6565#define WebKitPDFDisplayModePreferenceKey @"WebKitPDFDisplayMode"
    6666#define WebKitPDFScaleFactorPreferenceKey @"WebKitPDFScaleFactor"
     67#define WebKitEditableLinkBehaviorPreferenceKey @"WebKitEditableLinkBehavior"
    6768
    6869
  • trunk/WebKit/WebView/WebPreferences.m

    r16686 r16760  
    11/*
    22 * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
     3 *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    232233        @"1",                           WebKitPDFDisplayModePreferenceKey,
    233234        @"0",                           WebKitPDFScaleFactorPreferenceKey,
     235        [NSNumber numberWithInt:WebKitEditableLinkDefaultBehavior],
     236                                        WebKitEditableLinkBehaviorPreferenceKey,
    234237        nil];
    235238
     
    658661}
    659662
     663- (WebKitEditableLinkBehavior)editableLinkBehavior
     664{
     665    WebKitEditableLinkBehavior value = [self _integerValueForKey:WebKitEditableLinkBehaviorPreferenceKey];
     666    if (value != WebKitEditableLinkDefaultBehavior &&
     667        value != WebKitEditableLinkAlwaysLive &&
     668        value != WebKitEditableLinkOnlyLiveWithShiftKey &&
     669        value != WebKitEditableLinkLiveWhenNotFocused) {
     670        // ensure that a valid result is returned
     671        value = WebKitEditableLinkDefaultBehavior;
     672    }
     673    return value;
     674}
     675
     676- (void)setEditableLinkBehavior:(WebKitEditableLinkBehavior)behavior
     677{
     678    [self _setIntegerValue:behavior forKey:WebKitEditableLinkBehaviorPreferenceKey];
     679}
     680
     681
    660682static NSMutableDictionary *webPreferencesInstances = nil;
    661683
  • trunk/WebKit/WebView/WebPreferencesPrivate.h

    r12930 r16760  
    4343#endif
    4444
     45
     46typedef enum {
     47    WebKitEditableLinkDefaultBehavior = 0,
     48    WebKitEditableLinkAlwaysLive,
     49    WebKitEditableLinkOnlyLiveWithShiftKey,
     50    WebKitEditableLinkLiveWhenNotFocused
     51} WebKitEditableLinkBehavior;
     52
    4553@interface WebPreferences (WebPrivate)
    4654
     
    6270- (void)setPDFScaleFactor:(float)scale;
    6371
     72- (WebKitEditableLinkBehavior)editableLinkBehavior;
     73- (void)setEditableLinkBehavior:(WebKitEditableLinkBehavior)behavior;
     74
    6475// Other private methods
    6576- (size_t)_pageCacheSize;
  • trunk/WebKit/WebView/WebView.m

    r16752 r16760  
    877877    [_private->settings setShouldPrintBackgrounds:[preferences shouldPrintBackgrounds]];
    878878    [_private->settings setTextAreasAreResizable:[preferences textAreasAreResizable]];
     879    [_private->settings setEditableLinkBehavior:[preferences editableLinkBehavior]];
    879880}
    880881
Note: See TracChangeset for help on using the changeset viewer.