Commit 10acb93c authored by gdennis's avatar gdennis

WebCore:

        Reviewed by Tim Hatcher.

        Part of patch for http://bugs.webkit.org/show_bug.cgi?id=11323
        Link dragging behaviour does not obey WebKitEditableLinkBehavior WebPref
        
        No layout tests added as this must be tested manually by the test
        WebCore/manual-tests/contenteditable-link.html

        * WebCore.exp: Exported HitTestResult::isLiveLink().
        * html/HTMLAnchorElement.cpp:
        (WebCore::HTMLAnchorElement::HTMLAnchorElement):
        (WebCore::HTMLAnchorElement::defaultEventHandler):
        (WebCore::HTMLAnchorElement::isLiveLink):
        * html/HTMLAnchorElement.h: added m_wasShiftKeyDownOnMouseDown variable
        to track shift key status.
        * manual-tests/contenteditable-link.html: Added description about link
        dragging behaviour.
        * rendering/HitTestResult.cpp:
        (WebCore::HitTestResult::isLiveLink): Added.
        * rendering/HitTestResult.h:

WebKit:

        Reviewed by Tim Hatcher.

        Part of patch for http://bugs.webkit.org/show_bug.cgi?id=11323
        Link dragging behaviour does not obey WebKitEditableLinkBehavior WebPref

        * DefaultDelegates/WebDefaultUIDelegate.m:
        (-[NSApplication webView:dragSourceActionMaskForPoint:]): Logic moved to 
        WebHTMLView's _mayStartDragAtEventLocation
        * Misc/WebElementDictionary.m: added isLiveLink
        (+[WebElementDictionary initializeLookupTable]):
        (-[WebElementDictionary _isLiveLink]):
        * WebView/WebHTMLView.m: 
        (-[WebHTMLView _mayStartDragAtEventLocation:]): Editable links should
        only be followed if isLiveLink is true
        (-[WebHTMLView _isMoveDrag:]): A drag of a live editable link is not
        a move
        (-[WebHTMLView draggingUpdatedWithDraggingInfo:actionMask:]):
        (-[WebHTMLView concludeDragForDraggingInfo:actionMask:]):
        * WebView/WebView.mm: added WebElementLinkIsLiveKey
        * WebView/WebViewPrivate.h: ditto



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@17629 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bf2cf324
2006-11-06 Graham Dennis <graham.dennis@gmail.com>
Reviewed by Tim Hatcher.
Part of patch for http://bugs.webkit.org/show_bug.cgi?id=11323
Link dragging behaviour does not obey WebKitEditableLinkBehavior WebPref
No layout tests added as this must be tested manually by the test
WebCore/manual-tests/contenteditable-link.html
* WebCore.exp: Exported HitTestResult::isLiveLink().
* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::HTMLAnchorElement):
(WebCore::HTMLAnchorElement::defaultEventHandler):
(WebCore::HTMLAnchorElement::isLiveLink):
* html/HTMLAnchorElement.h: added m_wasShiftKeyDownOnMouseDown variable
to track shift key status.
* manual-tests/contenteditable-link.html: Added description about link
dragging behaviour.
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::isLiveLink): Added.
* rendering/HitTestResult.h:
2006-11-06 Brady Eidson <beidson@apple.com>
Reviewed by Oliver
......@@ -307,6 +307,7 @@ __ZNK7WebCore13HitTestResult16altDisplayStringEv
__ZNK7WebCore13HitTestResult18titleDisplayStringEv
__ZNK7WebCore13HitTestResult5imageEv
__ZNK7WebCore13HitTestResult5titleEv
__ZNK7WebCore13HitTestResult10isLiveLinkEv
__ZNK7WebCore14DocumentLoader10isStoppingEv
__ZNK7WebCore14DocumentLoader11frameLoaderEv
__ZNK7WebCore14DocumentLoader11isCommittedEv
......
......@@ -50,12 +50,14 @@ using namespace EventNames;
HTMLAnchorElement::HTMLAnchorElement(Document* doc)
: HTMLElement(aTag, doc)
, m_rootEditableElementForSelectionOnMouseDown(0)
, m_wasShiftKeyDownOnMouseDown(false)
{
}
HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document* doc)
: HTMLElement(tagName, doc)
, m_rootEditableElementForSelectionOnMouseDown(0)
, m_wasShiftKeyDownOnMouseDown(false)
{
}
......@@ -212,10 +214,17 @@ void HTMLAnchorElement::defaultEventHandler(Event* evt)
} 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())
if (evt->type() == mousedownEvent && document()->frame() && document()->frame()->selectionController()) {
MouseEvent* e = static_cast<MouseEvent*>(evt);
m_rootEditableElementForSelectionOnMouseDown = document()->frame()->selectionController()->rootEditableElement();
else if (evt->type() == mouseoutEvent)
m_wasShiftKeyDownOnMouseDown = e && e->shiftKey();
} else if (evt->type() == mouseoverEvent) {
// These are cleared on mouseover and not mouseout because their values are needed for drag events, but these happen
// after mouse out events.
m_rootEditableElementForSelectionOnMouseDown = 0;
m_wasShiftKeyDownOnMouseDown = false;
}
}
HTMLElement::defaultEventHandler(evt);
......@@ -446,5 +455,34 @@ String HTMLAnchorElement::text() const
return innerText();
}
bool HTMLAnchorElement::isLiveLink() const
{
if (!m_isLink)
return false;
if (!isContentEditable())
return true;
Settings::EditableLinkBehavior editableLinkBehavior = Settings::EditableLinkDefaultBehavior;
if (document() && document()->frame() && document()->frame()->settings())
editableLinkBehavior = document()->frame()->settings()->editableLinkBehavior();
switch(editableLinkBehavior) {
default:
case Settings::EditableLinkDefaultBehavior:
case Settings::EditableLinkAlwaysLive:
return true;
// Don't set the link to be live if the current selection is in the same editable block as
// this link or if the shift key is down
case Settings::EditableLinkLiveWhenNotFocused:
return m_wasShiftKeyDownOnMouseDown || m_rootEditableElementForSelectionOnMouseDown != rootEditableElement();
case Settings::EditableLinkOnlyLiveWithShiftKey:
return m_wasShiftKeyDownOnMouseDown;
}
// not reached
ASSERT(0);
return false;
}
}
......@@ -95,8 +95,11 @@ public:
String search() const;
String text() const;
bool isLiveLink() const;
private:
Element *m_rootEditableElementForSelectionOnMouseDown;
bool m_wasShiftKeyDownOnMouseDown;
};
} //namespace
......
......@@ -17,6 +17,9 @@
<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>Also, when a link is 'live' it can be dragged as a link, and when the link isn't 'live', dragging a link just performs a normal text selection.
</div>
<div id="editable" contentEditable="true">
<p>Test content</p>
<p><a href="about:blank">Test link</a></p>
......
......@@ -27,6 +27,7 @@
#include "Document.h"
#include "Frame.h"
#include "FrameTree.h"
#include "HTMLAnchorElement.h"
#include "HTMLElement.h"
#include "HTMLImageElement.h"
#include "HTMLInputElement.h"
......@@ -228,6 +229,17 @@ KURL HitTestResult::absoluteLinkURL() const
static_cast<Element*>(m_innerURLElement.get())->getAttribute("href")).deprecatedString()));
}
bool HitTestResult::isLiveLink() const
{
if (!(m_innerURLElement && m_innerURLElement->document()))
return false;
if (!m_innerURLElement->hasTagName(aTag))
return false;
return static_cast<HTMLAnchorElement*>(m_innerURLElement.get())->isLiveLink();
}
String HitTestResult::titleDisplayString() const
{
if (!(m_innerURLElement && m_innerURLElement->isHTMLElement()))
......
......@@ -66,6 +66,7 @@ public:
KURL absoluteLinkURL() const;
String titleDisplayString() const;
String textContent() const;
bool isLiveLink() const;
private:
RefPtr<Node> m_innerNode;
......
2006-11-06 Graham Dennis <graham.dennis@gmail.com>
Reviewed by Tim Hatcher.
Part of patch for http://bugs.webkit.org/show_bug.cgi?id=11323
Link dragging behaviour does not obey WebKitEditableLinkBehavior WebPref
* DefaultDelegates/WebDefaultUIDelegate.m:
(-[NSApplication webView:dragSourceActionMaskForPoint:]): Logic moved to
WebHTMLView's _mayStartDragAtEventLocation
* Misc/WebElementDictionary.m: added isLiveLink
(+[WebElementDictionary initializeLookupTable]):
(-[WebElementDictionary _isLiveLink]):
* WebView/WebHTMLView.m:
(-[WebHTMLView _mayStartDragAtEventLocation:]): Editable links should
only be followed if isLiveLink is true
(-[WebHTMLView _isMoveDrag:]): A drag of a live editable link is not
a move
(-[WebHTMLView draggingUpdatedWithDraggingInfo:actionMask:]):
(-[WebHTMLView concludeDragForDraggingInfo:actionMask:]):
* WebView/WebView.mm: added WebElementLinkIsLiveKey
* WebView/WebViewPrivate.h: ditto
2006-11-04 Maciej Stachowiak <mjs@apple.com>
Reviewed by Oliver.
......
......@@ -203,10 +203,6 @@ - (void)webView:(WebView *)webView willPerformDragDestinationAction:(WebDragDest
- (unsigned)webView:(WebView *)webView dragSourceActionMaskForPoint:(NSPoint)point;
{
DOMElement *elementAtPoint = [[webView elementAtPoint:point] objectForKey:WebElementDOMNodeKey];
if ([elementAtPoint respondsToSelector:@selector(isContentEditable)] && [(id)elementAtPoint isContentEditable])
return (WebDragSourceActionAny & ~WebDragSourceActionLink);
return WebDragSourceActionAny;
}
......
......@@ -79,6 +79,7 @@ + (void)initializeLookupTable
addLookupKey(WebElementLinkTargetFrameKey, @selector(_targetWebFrame));
addLookupKey(WebElementLinkTitleKey, @selector(_titleDisplayString));
addLookupKey(WebElementLinkLabelKey, @selector(_textContent));
addLookupKey(WebElementLinkIsLiveKey, @selector(_isLiveLink));
}
- (id)initWithHitTestResult:(const HitTestResult&)result
......@@ -218,4 +219,9 @@ - (NSString *)_textContent
return _result->textContent();
}
- (NSNumber *)_isLiveLink
{
return [NSNumber numberWithBool:_result->isLiveLink()];
}
@end
/*
* Copyright (C) 2005, 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
......@@ -1512,7 +1513,8 @@ - (BOOL)_mayStartDragAtEventLocation:(NSPoint)location
return YES;
if ([mouseDownElement objectForKey:WebElementLinkURLKey]
&& (_private->dragSourceActionMask & WebDragSourceActionLink))
&& (_private->dragSourceActionMask & WebDragSourceActionLink)
&& [[mouseDownElement objectForKey:WebElementLinkIsLiveKey] boolValue])
return YES;
if ([[mouseDownElement objectForKey:WebElementIsSelectedKey] boolValue]
......@@ -5972,13 +5974,14 @@ - (BOOL)_canProcessDragWithDraggingInfo:(id <NSDraggingInfo>)draggingInfo
return NO;
}
- (BOOL)_isMoveDrag
- (BOOL)_isMoveDrag:(id <NSDraggingInfo>)draggingInfo
{
FrameMac* coreFrame = core([self _frame]);
return _private->initiatedDrag
&& coreFrame
&& coreFrame->selectionController()->isContentEditable()
&& !([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask);
&& !([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
&& ![[[draggingInfo draggingPasteboard] types] containsObject:NSURLPboardType];
}
- (BOOL)_isNSColorDrag:(id <NSDraggingInfo>)draggingInfo
......@@ -6008,7 +6011,7 @@ - (NSDragOperation)draggingUpdatedWithDraggingInfo:(id <NSDraggingInfo>)dragging
ASSERT(innerFrame);
ASSERT([innerFrame isKindOfClass:[WebFrame class]]);
WebHTMLView* innerView = (WebHTMLView *)[[innerFrame frameView] documentView];
operation = [innerView _isMoveDrag] ? NSDragOperationMove : NSDragOperationCopy;
operation = [innerView _isMoveDrag:draggingInfo] ? NSDragOperationMove : NSDragOperationCopy;
}
} else
[[self _webView] removeDragCaret];
......@@ -6072,14 +6075,14 @@ - (BOOL)concludeDragForDraggingInfo:(id <NSDraggingInfo>)draggingInfo actionMask
BOOL didInsert = NO;
if ([self _canProcessDragWithDraggingInfo:draggingInfo]) {
NSPasteboard *pasteboard = [draggingInfo draggingPasteboard];
if ([innerView _isMoveDrag] || [innerBridge isDragCaretRichlyEditable]) {
if ([innerView _isMoveDrag:draggingInfo] || [innerBridge isDragCaretRichlyEditable]) {
DOMRange *range = [innerBridge dragCaretDOMRange];
BOOL chosePlainText;
DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard
inContext:range allowPlainText:YES chosePlainText:&chosePlainText];
if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:range givenAction:WebViewInsertActionDropped]) {
[[webView _UIDelegateForwarder] webView:webView willPerformDragDestinationAction:WebDragDestinationActionEdit forDraggingInfo:draggingInfo];
if ([innerView _isMoveDrag]) {
if ([innerView _isMoveDrag:draggingInfo]) {
BOOL smartMove = [innerBridge selectionGranularity] == WebBridgeSelectByWord && [self _canSmartReplaceWithPasteboard:pasteboard];
[innerBridge moveSelectionToDragCaret:fragment smartMove:smartMove];
} else {
......
......@@ -342,6 +342,7 @@ NSString *WebElementLinkTitleKey = @"WebElementLinkTitle";
NSString *WebElementLinkURLKey = @"WebElementLinkURL";
NSString *WebElementSpellingToolTipKey = @"WebElementSpellingToolTip";
NSString *WebElementTitleKey = @"WebElementTitle";
NSString *WebElementLinkIsLiveKey = @"WebElementLinkIsLive";
NSString *WebViewProgressStartedNotification = @"WebProgressStartedNotification";
NSString *WebViewProgressEstimateChangedNotification = @"WebProgressEstimateChangedNotification";
......
......@@ -84,6 +84,9 @@ extern NSString *_WebMainFrameDocumentKey;
extern NSString *WebElementTitleKey; // NSString of the title of the element (used by Safari)
extern NSString *WebElementSpellingToolTipKey; // NSString of a tooltip representing misspelling or bad grammar (used internally)
// other WebElementDictionary keys
extern NSString *WebElementLinkIsLiveKey; // NSNumber of BOOL indictating whether the link is live or not
typedef enum {
WebDashboardBehaviorAlwaysSendMouseEventsToAllWindows,
WebDashboardBehaviorAlwaysSendActiveNullEventsToPlugIns,
......
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