WebCore:
authorthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Nov 2006 05:42:44 +0000 (05:42 +0000)
committerthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Nov 2006 05:42:44 +0000 (05:42 +0000)
        Reviewed by Harrison.

        <rdar://problem/4766635> Safari should never follow links in editable areas (add a WebKitEditableLinkNeverLive option)

        Adds an EditableLinkNeverLive setting that will make links in editable areas always dead.

        * bridge/mac/WebCoreSettings.mm:
        (-[WebCoreSettings setEditableLinkBehavior:]):
        * html/HTMLAnchorElement.cpp:
        (WebCore::HTMLAnchorElement::defaultEventHandler):
        (WebCore::HTMLAnchorElement::setActive):
        (WebCore::HTMLAnchorElement::isLiveLink):
        * page/FrameView.cpp:
        (WebCore::selectCursor):
        * page/Settings.h:
        (WebCore::Settings::):

WebKit:

        Reviewed by Harrison.

        <rdar://problem/4766635> Safari should never follow links in editable areas (add a WebKitEditableLinkNeverLive option)

        Adds an Open Link, Open Link in New Window and Copy Link to the editing context menu.
        Adds a new WebKitEditableLinkNeverLive preference value that maps to WebCore's EditableLinkNeverLive.

        * DefaultDelegates/WebDefaultContextMenuDelegate.m:
        (-[WebDefaultUIDelegate menuItemWithTag:target:representedObject:]):
        (-[WebDefaultUIDelegate contextMenuItemsForElement:defaultMenuItems:]):
        (-[WebDefaultUIDelegate editingContextMenuItemsForElement:defaultMenuItems:]):
        (-[WebDefaultUIDelegate requestWithURL:includingReferrerFromFrame:]):
        (-[WebDefaultUIDelegate openNewWindowWithURL:element:]):
        (-[WebDefaultUIDelegate openLink:]):
        * English.lproj/Localizable.strings:
        * WebKit.exp:
        * WebView/WebPreferences.m:
        (-[WebPreferences editableLinkBehavior]):
        * WebView/WebPreferencesPrivate.h:
        * WebView/WebUIDelegatePrivate.h:

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

13 files changed:
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/bridge/mac/WebCoreSettings.mm
WebCore/html/HTMLAnchorElement.cpp
WebCore/page/EventHandler.cpp
WebCore/page/Settings.h
WebKit/ChangeLog
WebKit/DefaultDelegates/WebDefaultContextMenuDelegate.m
WebKit/English.lproj/Localizable.strings
WebKit/WebKit.exp
WebKit/WebView/WebPreferences.m
WebKit/WebView/WebPreferencesPrivate.h
WebKit/WebView/WebUIDelegatePrivate.h

index 5d0ce58379ed46ab0479d281ac5505a48c272fb5..ed26b8a56f658982ef4124bd8d3d357fa236e546 100644 (file)
@@ -1,3 +1,22 @@
+2006-11-14  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Harrison.
+
+        <rdar://problem/4766635> Safari should never follow links in editable areas (add a WebKitEditableLinkNeverLive option)
+
+        Adds an EditableLinkNeverLive setting that will make links in editable areas always dead.
+
+        * bridge/mac/WebCoreSettings.mm:
+        (-[WebCoreSettings setEditableLinkBehavior:]):
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::HTMLAnchorElement::defaultEventHandler):
+        (WebCore::HTMLAnchorElement::setActive):
+        (WebCore::HTMLAnchorElement::isLiveLink):
+        * page/FrameView.cpp:
+        (WebCore::selectCursor):
+        * page/Settings.h:
+        (WebCore::Settings::):
+
 2006-11-14  Mark Rowe  <bdash@webkit.org>
 
         Reviewed by Oliver.
index 7d5c1daa41ea54ea848dcfa3323ff5c3e6f6c89d..03fc55513dcf025e5e7ea8376c65692bb681424d 100644 (file)
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
+                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
                        projectRoot = "";
+                       shouldCheckCompatibility = 1;
                        targets = (
                                93F198A508245E59001E9ABC /* WebCore */,
                                DD041FBE09D9DDBE0010AF2A /* Derived Sources */,
index f4250e66b854d63e46aaed7e3fe9029a92d23062..cd3461a4ca8d5a393b02df98582ac1eb27d1d5a2 100644 (file)
@@ -338,6 +338,7 @@ using namespace WebCore;
     Settings::EditableLinkBehavior b = (Settings::EditableLinkBehavior)behavior;
     if (b != Settings::EditableLinkDefaultBehavior &&
         b != Settings::EditableLinkAlwaysLive &&
+        b != Settings::EditableLinkNeverLive &&
         b != Settings::EditableLinkOnlyLiveWithShiftKey &&
         b != Settings::EditableLinkLiveWhenNotFocused) {
         settings->setEditableLinkBehavior(Settings::EditableLinkDefaultBehavior);
index fa7f2576f8ea16b526790b23ac2047284c91760d..02618a44aba94e02bdfa30dc3d74d250a4c1c561 100644 (file)
@@ -151,7 +151,11 @@ void HTMLAnchorElement::defaultEventHandler(Event* evt)
                 case Settings::EditableLinkDefaultBehavior:
                 case Settings::EditableLinkAlwaysLive:
                     break;
-                    
+
+                case Settings::EditableLinkNeverLive:
+                    HTMLElement::defaultEventHandler(evt);
+                    return;
+
                 // 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:
@@ -160,7 +164,7 @@ void HTMLAnchorElement::defaultEventHandler(Event* evt)
                         return;
                     }
                     break;
-                
+
                 // Only follow the link if the shift key is down (WinIE/Firefox behavior)
                 case Settings::EditableLinkOnlyLiveWithShiftKey:
                     if (e && !e->shiftKey()) {
@@ -245,7 +249,10 @@ void HTMLAnchorElement::setActive(bool down, bool pause)
             case Settings::EditableLinkDefaultBehavior:
             case Settings::EditableLinkAlwaysLive:
                 break;
-                
+
+            case Settings::EditableLinkNeverLive:
+                return;
+
             // Don't set the link to be active if the current selection is in the same editable block as
             // this link
             case Settings::EditableLinkLiveWhenNotFocused:
@@ -474,7 +481,10 @@ bool HTMLAnchorElement::isLiveLink() const
         case Settings::EditableLinkDefaultBehavior:
         case Settings::EditableLinkAlwaysLive:
             return true;
-            
+
+        case Settings::EditableLinkNeverLive:
+            return false;
+
         // 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:
index 0072f993511dec6558b8e658aef7db0ffbfa73c1..bc7f3b180bc91e1fe67234c38b0a2e7cf20fdd58 100644 (file)
@@ -557,7 +557,11 @@ static Cursor selectCursor(const MouseEventWithHitTestResults& event, Frame* fra
                     case Settings::EditableLinkAlwaysLive:
                         editableLinkEnabled = true;
                         break;
-                    
+
+                    case Settings::EditableLinkNeverLive:
+                        editableLinkEnabled = false;
+                        break;
+
                     case Settings::EditableLinkLiveWhenNotFocused:
                         editableLinkEnabled = nodeIsNotBeingEdited(node, frame) || event.event().shiftKey();
                         break;
index 7aa9bf78335a12a8eab0e2d4413295c151d2d84e..740892fe751ad0b157dca5d98f4a4d887181c68f 100644 (file)
@@ -39,7 +39,8 @@ public:
         EditableLinkDefaultBehavior = 0,
         EditableLinkAlwaysLive,
         EditableLinkOnlyLiveWithShiftKey,
-        EditableLinkLiveWhenNotFocused
+        EditableLinkLiveWhenNotFocused,
+        EditableLinkNeverLive
     };
 
     Settings()
index 7288d7820155d301ccacdbb03dc47e757a0dfd39..d5fae880f2b810baa289a4392c5096bdc099ab46 100644 (file)
@@ -1,3 +1,26 @@
+2006-11-14  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Harrison.
+
+        <rdar://problem/4766635> Safari should never follow links in editable areas (add a WebKitEditableLinkNeverLive option)
+
+        Adds an Open Link, Open Link in New Window and Copy Link to the editing context menu.
+        Adds a new WebKitEditableLinkNeverLive preference value that maps to WebCore's EditableLinkNeverLive.
+
+        * DefaultDelegates/WebDefaultContextMenuDelegate.m:
+        (-[WebDefaultUIDelegate menuItemWithTag:target:representedObject:]):
+        (-[WebDefaultUIDelegate contextMenuItemsForElement:defaultMenuItems:]):
+        (-[WebDefaultUIDelegate editingContextMenuItemsForElement:defaultMenuItems:]):
+        (-[WebDefaultUIDelegate requestWithURL:includingReferrerFromFrame:]):
+        (-[WebDefaultUIDelegate openNewWindowWithURL:element:]):
+        (-[WebDefaultUIDelegate openLink:]):
+        * English.lproj/Localizable.strings:
+        * WebKit.exp:
+        * WebView/WebPreferences.m:
+        (-[WebPreferences editableLinkBehavior]):
+        * WebView/WebPreferencesPrivate.h:
+        * WebView/WebUIDelegatePrivate.h:
+
 2006-11-14  Anders Carlsson  <acarlsson@apple.com>
 
         Turns out I wasn't forcing DWARF on the world at all, 
index 30722cbafeabc48059c14d8948820a55b0243cee..30069f9e228372ff88947f6c866a1072c9486ce6 100644 (file)
@@ -77,6 +77,10 @@ static NSString *localizedMenuTitleFromAppKit(NSString *key, NSString *comment)
     SEL action = NULL;
     
     switch(tag) {
+        case WebMenuItemTagOpenLink:
+            title = UI_STRING("Open Link", "Open Link context menu item");
+            action = @selector(openLink:);
+            break;
         case WebMenuItemTagOpenLinkInNewWindow:
             title = UI_STRING("Open Link in New Window", "Open in New Window context menu item");
             action = @selector(openLinkInNewWindow:);
@@ -206,7 +210,7 @@ static NSString *localizedMenuTitleFromAppKit(NSString *key, NSString *comment)
         }
         [menuItems addObject:[self menuItemWithTag:WebMenuItemTagCopyLinkToClipboard target:self representedObject:element]];
     }
-    
+
     WebFrame *webFrame = [element objectForKey:WebElementFrameKey];
     NSURL *imageURL = [element objectForKey:WebElementImageURLKey];
     
@@ -293,6 +297,8 @@ static NSString *localizedMenuTitleFromAppKit(NSString *key, NSString *comment)
         [menuItems addObject:[NSMenuItem separatorItem]];
     }
 
+    NSURL *linkURL = [element objectForKey:WebElementLinkURLKey];
+    
     if ([[element objectForKey:WebElementIsSelectedKey] boolValue] && !inPasswordField) {
         [menuItems addObject:[self menuItemWithTag:WebMenuItemTagSearchInSpotlight target:nil representedObject:element]];
         [menuItems addObject:[self menuItemWithTag:WebMenuItemTagSearchWeb target:nil representedObject:element]];
@@ -305,7 +311,17 @@ static NSString *localizedMenuTitleFromAppKit(NSString *key, NSString *comment)
         [menuItems addObject:[self menuItemWithTag:WebMenuItemTagLookUpInDictionary target:nil representedObject:element]];
         [menuItems addObject:[NSMenuItem separatorItem]];
     }
-    
+
+    if (linkURL) {
+        if([WebView _canHandleRequest:[NSURLRequest requestWithURL:linkURL]]) {
+            [menuItems addObject:[self menuItemWithTag:WebMenuItemTagOpenLink target:self representedObject:element]];
+            [menuItems addObject:[self menuItemWithTag:WebMenuItemTagOpenLinkInNewWindow target:self representedObject:element]];
+        }
+        [menuItems addObject:[self menuItemWithTag:WebMenuItemTagCopyLinkToClipboard target:self representedObject:element]];
+        // FIXME: we should add "Edit Link..." here like NSTextView has in it's context menu
+        [menuItems addObject:[NSMenuItem separatorItem]];
+    }
+
     // Load our NSTextView-like context menu nib.
     if (defaultMenu == nil) {
         static NSNib *textViewMenuNib = nil;
@@ -369,17 +385,20 @@ static NSString *localizedMenuTitleFromAppKit(NSString *key, NSString *comment)
     }
 }
 
-- (void)openNewWindowWithURL:(NSURL *)URL element:(NSDictionary *)element
+- (NSURLRequest *)requestWithURL:(NSURL *)URL includingReferrerFromFrame:(WebFrame *)webFrame
 {
-    WebFrame *webFrame = [element objectForKey:WebElementFrameKey];
-    WebView *webView = [webFrame webView];
-    
     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
     NSString *referrer = core(webFrame)->loader()->outgoingReferrer();
     if (referrer)
         [request _web_setHTTPReferrer:referrer];
-    
-    [webView _openNewWindowWithRequest:request];
+    return request;
+}
+
+- (void)openNewWindowWithURL:(NSURL *)URL element:(NSDictionary *)element
+{
+    WebFrame *webFrame = [element objectForKey:WebElementFrameKey];
+    WebView *webView = [webFrame webView];
+    [webView _openNewWindowWithRequest:[self requestWithURL:URL includingReferrerFromFrame:webFrame]];
 }
 
 - (void)downloadURL:(NSURL *)URL element:(NSDictionary *)element
@@ -389,6 +408,18 @@ static NSString *localizedMenuTitleFromAppKit(NSString *key, NSString *comment)
     [webView _downloadURL:URL];
 }
 
+- (void)openLink:(id)sender
+{
+    NSDictionary *element = [sender representedObject];
+    WebFrame *webFrame = [element objectForKey:WebElementFrameKey];
+    WebFrame *targetFrame = [element objectForKey:WebElementLinkTargetFrameKey];
+    NSURL *url = [element objectForKey:WebElementLinkURLKey];
+    if (targetFrame)
+        [targetFrame loadRequest:[self requestWithURL:url includingReferrerFromFrame:webFrame]];
+    else
+        [self openNewWindowWithURL:url element:element];
+}
+
 - (void)openLinkInNewWindow:(id)sender
 {
     NSDictionary *element = [sender representedObject];
index 8e8ac547e8afc7e0310105dd90b651fe54977a8d..734f079eb6bc2d2590339d2fe87adbb843f2decf 100644 (file)
Binary files a/WebKit/English.lproj/Localizable.strings and b/WebKit/English.lproj/Localizable.strings differ
index 0cdc778d11a234bad51d99a9edb59260f330d109..23465451687506a6371f00b62d44f0129f500aac 100644 (file)
@@ -41,6 +41,7 @@ _WebElementImageKey
 _WebElementImageRectKey
 _WebElementImageURLKey
 _WebElementIsSelectedKey
+_WebElementLinkIsLiveKey
 _WebElementLinkLabelKey
 _WebElementLinkTargetFrameKey
 _WebElementLinkTitleKey
index 4f31d98466f8f4745250be44b8d96e48e4a86774..8d60221c43f0947ec83784c5388b8f4a252f3587 100644 (file)
@@ -676,6 +676,7 @@ NS_ENDHANDLER
     WebKitEditableLinkBehavior value = [self _integerValueForKey:WebKitEditableLinkBehaviorPreferenceKey];
     if (value != WebKitEditableLinkDefaultBehavior &&
         value != WebKitEditableLinkAlwaysLive &&
+        value != WebKitEditableLinkNeverLive &&
         value != WebKitEditableLinkOnlyLiveWithShiftKey &&
         value != WebKitEditableLinkLiveWhenNotFocused) {
         // ensure that a valid result is returned
index f604aad64885965bde0efb714654c29495b9d11a..697fcf86c96adc9a5ba0bc2644f9ddd3cf295e34 100644 (file)
 
 #endif
 
-
+// WebKitEditableLinkBehavior needs to match the Settings::EditableLinkBehavior enum in WebCore
 typedef enum {
     WebKitEditableLinkDefaultBehavior = 0,
     WebKitEditableLinkAlwaysLive,
     WebKitEditableLinkOnlyLiveWithShiftKey,
-    WebKitEditableLinkLiveWhenNotFocused
+    WebKitEditableLinkLiveWhenNotFocused,
+    WebKitEditableLinkNeverLive
 } WebKitEditableLinkBehavior;
 
 @interface WebPreferences (WebPrivate)
index bd86618a75d21f0d790f01db32e5c9b013382d93..063238b6bde99008ce24cfa53a73945103e7d06f 100644 (file)
 
 #import <WebKit/WebUIDelegate.h>
 
+// FIXME: This should move to WebUIDelegate.h as part of the WebMenuItemTag enum there, when we're not in API freeze 
+enum { 
+    WebMenuItemTagOpenLink = 1000
+};
+
 @interface NSObject (WebUIDelegatePrivate)
 
 - (void)webView:(WebView *)webView addMessageToConsole:(NSDictionary *)message;