Commit fb3f9561 authored by bdash's avatar bdash

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:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@16760 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9623e8d6
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 Beth Dakin <bdakin@apple.com>
Reviewed Darin.
......@@ -118,6 +118,9 @@ typedef WebCore::Settings WebCoreSettingsImpl;
- (void)setDefaultTextEncoding:(NSString *)encoding;
- (NSString *)defaultTextEncoding;
- (void)setEditableLinkBehavior:(int)behavior;
- (int)editableLinkBehavior;
- (WebCoreSettingsImpl *)settings;
@end
/*
* Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
* (C) 2006 Graham Dennis (graham.dennis@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -334,6 +335,23 @@ using namespace WebCore;
return defaultTextEncoding;
}
- (void)setEditableLinkBehavior:(int)behavior
{
Settings::EditableLinkBehavior b = (Settings::EditableLinkBehavior)behavior;
if (b != Settings::EditableLinkDefaultBehavior &&
b != Settings::EditableLinkAlwaysLive &&
b != Settings::EditableLinkOnlyLiveWithShiftKey &&
b != Settings::EditableLinkLiveWhenNotFocused) {
settings->setEditableLinkBehavior(Settings::EditableLinkDefaultBehavior);
} else
settings->setEditableLinkBehavior(b);
}
- (int)editableLinkBehavior
{
return (int)settings->editableLinkBehavior();
}
- (Settings *)settings
{
return settings;
......
......@@ -5,6 +5,7 @@
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2000 Simon Hausmann <hausmann@kde.org>
* Copyright (C) 2003, 2006 Apple Computer, Inc.
* (C) 2006 Graham Dennis (graham.dennis@gmail.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -35,6 +36,8 @@
#include "MutationEvent.h"
#include "RenderFlow.h"
#include "RenderImage.h"
#include "SelectionController.h"
#include "Settings.h"
#include "UIEvent.h"
#include "csshelper.h"
......@@ -45,11 +48,13 @@ using namespace EventNames;
HTMLAnchorElement::HTMLAnchorElement(Document* doc)
: HTMLElement(aTag, doc)
, m_rootEditableElementForSelectionOnMouseDown(0)
{
}
HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document* doc)
: HTMLElement(tagName, doc)
, m_rootEditableElementForSelectionOnMouseDown(0)
{
}
......@@ -128,9 +133,36 @@ void HTMLAnchorElement::defaultEventHandler(Event *evt)
return;
}
if (e && !e->shiftKey() && isContentEditable()) {
HTMLElement::defaultEventHandler(evt);
return;
// If the link is editable, then we need to check the settings to see whether or not to follow the link
if (isContentEditable()) {
Settings::EditableLinkBehavior editableLinkBehavior = Settings::EditableLinkDefaultBehavior;
if (document()->frame() && document()->frame()->settings())
editableLinkBehavior = document()->frame()->settings()->editableLinkBehavior();
switch(editableLinkBehavior) {
// Always follow the link (Safari 2.0 behavior)
default:
case Settings::EditableLinkDefaultBehavior:
case Settings::EditableLinkAlwaysLive:
break;
// If the selection prior to clicking on this link resided in the same editable block as this link,
// and the shift key isn't pressed, we don't want to follow the link
case Settings::EditableLinkLiveWhenNotFocused:
if (e && !e->shiftKey() && m_rootEditableElementForSelectionOnMouseDown == rootEditableElement()) {
HTMLElement::defaultEventHandler(evt);
return;
}
break;
// Only follow the link if the shift key is down (WinIE/Firefox behavior)
case Settings::EditableLinkOnlyLiveWithShiftKey:
if (e && !e->shiftKey()) {
HTMLElement::defaultEventHandler(evt);
return;
}
break;
}
}
if (k) {
......@@ -176,6 +208,13 @@ void HTMLAnchorElement::defaultEventHandler(Event *evt)
document()->frame()->urlSelected(url, utarget);
evt->setDefaultHandled();
} else if (m_isLink && isContentEditable()) {
// This keeps track of the editable block that the selection was in (if it was in one) just before the link was clicked
// for the LiveWhenNotFocused editable link behavior
if (evt->type() == mousedownEvent && document()->frame() && document()->frame()->selectionController())
m_rootEditableElementForSelectionOnMouseDown = document()->frame()->selectionController()->rootEditableElement();
else if (evt->type() == mouseoutEvent)
m_rootEditableElementForSelectionOnMouseDown = 0;
}
HTMLElement::defaultEventHandler(evt);
......@@ -183,8 +222,31 @@ void HTMLAnchorElement::defaultEventHandler(Event *evt)
void HTMLAnchorElement::setActive(bool down, bool pause)
{
if (isContentEditable())
return;
if (isContentEditable()) {
Settings::EditableLinkBehavior editableLinkBehavior = Settings::EditableLinkDefaultBehavior;
if (document()->frame() && document()->frame()->settings())
editableLinkBehavior = document()->frame()->settings()->editableLinkBehavior();
switch(editableLinkBehavior) {
default:
case Settings::EditableLinkDefaultBehavior:
case Settings::EditableLinkAlwaysLive:
break;
// Don't set the link to be active if the current selection is in the same editable block as
// this link
case Settings::EditableLinkLiveWhenNotFocused:
if (down && document()->frame() && document()->frame()->selectionController() &&
document()->frame()->selectionController()->rootEditableElement() == rootEditableElement())
return;
break;
case Settings::EditableLinkOnlyLiveWithShiftKey:
return;
}
}
ContainerNode::setActive(down, pause);
}
......
......@@ -94,6 +94,9 @@ public:
String protocol() const;
String search() const;
String text() const;
private:
Element *m_rootEditableElementForSelectionOnMouseDown;
};
} //namespace
......
......@@ -15,6 +15,8 @@
<BODY>
<P>Repro movie for bug <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=7156">#7156</a></P>
<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>
<div id="editable" contentEditable="true">
<p>Test content</p>
<p><a href="about:blank">Test link</a></p>
......
......@@ -5,6 +5,7 @@
* 1999 Antti Koivisto <koivisto@kde.org>
* 2000 Dirk Mueller <mueller@kde.org>
* Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
* (C) 2006 Graham Dennis (graham.dennis@gmail.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -47,6 +48,7 @@
#include "RenderText.h"
#include "RenderView.h"
#include "SelectionController.h"
#include "Settings.h"
#include "cssstyleselector.h"
#ifdef SVG_SUPPORT
......@@ -665,6 +667,12 @@ static bool isSubmitImage(Node *node)
return node && node->hasTagName(inputTag) && static_cast<HTMLInputElement*>(node)->inputType() == HTMLInputElement::IMAGE;
}
// Returns true if the node's editable block is not current focused for editing
static bool nodeIsNotBeingEdited(Node* node, Frame* frame)
{
return frame->selectionController()->rootEditableElement() != node->rootEditableElement();
}
static Cursor selectCursor(const MouseEventWithHitTestResults& event, Frame* frame, bool mousePressed)
{
// During selection, use an I-beam no matter what we're over.
......@@ -703,7 +711,28 @@ static Cursor selectCursor(const MouseEventWithHitTestResults& event, Frame* fra
switch (style ? style->cursor() : CURSOR_AUTO) {
case CURSOR_AUTO: {
bool editable = (node && node->isContentEditable());
if ((event.isOverLink() || isSubmitImage(node)) && (!editable || event.event().shiftKey()))
bool editableLinkEnabled = false;
// If the link is editable, then we need to check the settings to see whether or not the link should be followed
if (editable) {
switch(frame->settings()->editableLinkBehavior()) {
default:
case Settings::EditableLinkDefaultBehavior:
case Settings::EditableLinkAlwaysLive:
editableLinkEnabled = true;
break;
case Settings::EditableLinkLiveWhenNotFocused:
editableLinkEnabled = nodeIsNotBeingEdited(node, frame) || event.event().shiftKey();
break;
case Settings::EditableLinkOnlyLiveWithShiftKey:
editableLinkEnabled = event.event().shiftKey();
break;
}
}
if ((event.isOverLink() || isSubmitImage(node)) && (!editable || editableLinkEnabled))
return handCursor();
RenderLayer* layer = renderer ? renderer->enclosingLayer() : 0;
bool inResizer = false;
......
/*
* Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
* (C) 2006 Graham Dennis (graham.dennis@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -34,6 +35,13 @@ namespace WebCore {
class Settings
{
public:
enum EditableLinkBehavior {
EditableLinkDefaultBehavior = 0,
EditableLinkAlwaysLive,
EditableLinkOnlyLiveWithShiftKey,
EditableLinkLiveWhenNotFocused
};
Settings()
: m_minimumFontSize(0)
, m_minimumLogicalFontSize(0)
......@@ -47,6 +55,7 @@ public:
, m_javaScriptCanOpenWindowsAutomatically(0)
, m_shouldPrintBackgrounds(0)
, m_textAreasAreResizable(0)
, m_editableLinkBehavior(EditableLinkDefaultBehavior)
{
}
......@@ -75,6 +84,7 @@ public:
KURL userStyleSheetLocation() const { return m_userStyleSheetLocation; }
bool shouldPrintBackgrounds() const { return m_shouldPrintBackgrounds; }
bool textAreasAreResizable() const { return m_textAreasAreResizable; }
EditableLinkBehavior editableLinkBehavior() const { return m_editableLinkBehavior; }
void setStdFontName(const AtomicString& s) { m_stdFontName = s; }
void setFixedFontName(const AtomicString& s) { m_fixedFontName = s; }
......@@ -100,6 +110,7 @@ public:
void setUserStyleSheetLocation(const KURL& s) { m_userStyleSheetLocation = s; }
void setShouldPrintBackgrounds(bool f) { m_shouldPrintBackgrounds = f; }
void setTextAreasAreResizable(bool f) { m_textAreasAreResizable = f; }
void setEditableLinkBehavior(EditableLinkBehavior e) { m_editableLinkBehavior = e; }
private:
AtomicString m_stdFontName;
......@@ -123,6 +134,7 @@ private:
bool m_javaScriptCanOpenWindowsAutomatically : 1;
bool m_shouldPrintBackgrounds : 1;
bool m_textAreasAreResizable : 1;
EditableLinkBehavior m_editableLinkBehavior;
};
}
......
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:]):
2006-10-03 Justin Garcia <justin.garcia@apple.com>
Reviewed by harrison
......
......@@ -64,6 +64,7 @@
#define WebKitShowsURLsInToolTipsPreferenceKey @"WebKitShowsURLsInToolTips"
#define WebKitPDFDisplayModePreferenceKey @"WebKitPDFDisplayMode"
#define WebKitPDFScaleFactorPreferenceKey @"WebKitPDFScaleFactor"
#define WebKitEditableLinkBehaviorPreferenceKey @"WebKitEditableLinkBehavior"
// Window display is throttled to 60 frames per second if WebKitThrottleWindowDisplayPreferenceKey
......
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
* (C) 2006 Graham Dennis (graham.dennis@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -231,6 +232,8 @@ + (void)initialize
[NSNumber numberWithBool:NO], WebKitShowsURLsInToolTipsPreferenceKey,
@"1", WebKitPDFDisplayModePreferenceKey,
@"0", WebKitPDFScaleFactorPreferenceKey,
[NSNumber numberWithInt:WebKitEditableLinkDefaultBehavior],
WebKitEditableLinkBehaviorPreferenceKey,
nil];
// This value shouldn't ever change, which is assumed in the initialization of WebKitPDFDisplayModePreferenceKey above
......@@ -657,6 +660,25 @@ - (void)setPDFDisplayMode:(PDFDisplayMode)mode
[self _setIntegerValue:mode forKey:WebKitPDFDisplayModePreferenceKey];
}
- (WebKitEditableLinkBehavior)editableLinkBehavior
{
WebKitEditableLinkBehavior value = [self _integerValueForKey:WebKitEditableLinkBehaviorPreferenceKey];
if (value != WebKitEditableLinkDefaultBehavior &&
value != WebKitEditableLinkAlwaysLive &&
value != WebKitEditableLinkOnlyLiveWithShiftKey &&
value != WebKitEditableLinkLiveWhenNotFocused) {
// ensure that a valid result is returned
value = WebKitEditableLinkDefaultBehavior;
}
return value;
}
- (void)setEditableLinkBehavior:(WebKitEditableLinkBehavior)behavior
{
[self _setIntegerValue:behavior forKey:WebKitEditableLinkBehaviorPreferenceKey];
}
static NSMutableDictionary *webPreferencesInstances = nil;
+ (WebPreferences *)_getInstanceForIdentifier:(NSString *)ident
......
......@@ -42,6 +42,14 @@
#endif
typedef enum {
WebKitEditableLinkDefaultBehavior = 0,
WebKitEditableLinkAlwaysLive,
WebKitEditableLinkOnlyLiveWithShiftKey,
WebKitEditableLinkLiveWhenNotFocused
} WebKitEditableLinkBehavior;
@interface WebPreferences (WebPrivate)
// Preferences that might be public in a future release
......@@ -61,6 +69,9 @@
- (float)PDFScaleFactor;
- (void)setPDFScaleFactor:(float)scale;
- (WebKitEditableLinkBehavior)editableLinkBehavior;
- (void)setEditableLinkBehavior:(WebKitEditableLinkBehavior)behavior;
// Other private methods
- (size_t)_pageCacheSize;
- (size_t)_objectCacheSize;
......
......@@ -876,6 +876,7 @@ - (void)_updateWebCoreSettingsFromPreferences:(WebPreferences *)preferences
}
[_private->settings setShouldPrintBackgrounds:[preferences shouldPrintBackgrounds]];
[_private->settings setTextAreasAreResizable:[preferences textAreasAreResizable]];
[_private->settings setEditableLinkBehavior:[preferences editableLinkBehavior]];
}
- (void)_preferencesChangedNotification: (NSNotification *)notification
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment