Reviewed by Darin.
authorsullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Dec 2004 21:33:09 +0000 (21:33 +0000)
committersullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Dec 2004 21:33:09 +0000 (21:33 +0000)
        - fixed <rdar://problem/3913523> Mail needs SPI for adding tooltips to links
        - cleaned up some calls to +[WebPreferences standardPreferences] that should
          have been using -[WebView preferences]

        This adds a (currently SPI-only) new feature that shows the URL of the link
        under the mouse in a toolTip. I tested this in Safari, but we're adding this
        feature for Mail, and Safari won't use it (unless of course you know the
        magic defaults command)

        * Plugins.subproj/WebBaseNetscapePluginView.m:
        (-[WebBaseNetscapePluginView start]):
        use -[WebView preferences] instead of +[WebPreferences standardPreferences]

        * WebCoreSupport.subproj/WebBridge.m:
        (-[WebBridge getObjectCacheSize]):
        ditto
        (-[WebBridge _retrieveKeyboardUIModeFromPreferences:]):
        ditto

        * WebView.subproj/WebBaseResourceHandleDelegate.m:
        (-[WebBaseResourceHandleDelegate willCacheResponse:]):
        ditto

        * WebView.subproj/WebFrame.m:
        (-[WebFrame _transitionToCommitted:]):
        ditto
        (-[WebFrame _loadItem:withLoadType:]):
        ditto

        * WebView.subproj/WebHTMLViewInternal.h:
        private struct now keeps ivar for cached value of showsURLsInToolTips
        so it doesn't have look it up in preferences a zillion times

        * WebView.subproj/WebHTMLView.m:
        (-[WebHTMLView _updateMouseoverWithEvent:]):
        if private->showsURLsInToolTips is true, set the toolTip from the URL.
        Fall back to showing the title attribute in case some element has a title
        attribute but no URL.
        (-[WebHTMLView _mayStartDragAtEventLocation:]):
        use -[WebView preferences] instead of +[WebPreferences standardPreferences]
        (-[WebHTMLView _resetCachedWebPreferences:]):
        get a fresh value for private->showsURLsInToolTips
        (-[WebHTMLView initWithFrame:]):
        call _resetCachedWebPreferences the first time, and listen for WebPreferencesChanged notifications
        (-[WebHTMLView _handleStyleKeyEquivalent:]):
        use -[WebView preferences] instead of +[WebPreferences standardPreferences]

        * WebView.subproj/WebPreferenceKeysPrivate.h:
        added WebKitShowsURLsInToolTipsPreferenceKey

        * WebView.subproj/WebPreferences.m:
        (+[WebPreferences initialize]):
        initialize WebKitShowsURLsInToolTipsPreferenceKey to 0
        (-[WebPreferences showsURLsInToolTips]):
        return WebKitShowsURLsInToolTipsPreferenceKey value
        (-[WebPreferences setShowsURLsInToolTips:]):
        set WebKitShowsURLsInToolTipsPreferenceKey value

        * WebView.subproj/WebPreferencesPrivate.h:
        add declarations for showsURLsInToolTips and setter

        * WebView.subproj/WebTextView.m:
        (-[WebTextView _preferences]):
        new helper method that gets preferences from webView if there is a webView,
        otherwise gets global preferences
        (-[WebTextView setFixedWidthFont]):
        use new helper method rather than always using global preferences
        (-[WebTextView initWithFrame:]):
        observe WebPreferencesChangedNotification instead of unnecessarily general
        NSUserDefaultsChangedNotification

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

12 files changed:
WebKit/ChangeLog
WebKit/Plugins.subproj/WebBaseNetscapePluginView.m
WebKit/WebCoreSupport.subproj/WebBridge.m
WebKit/WebView.subproj/WebBaseResourceHandleDelegate.m
WebKit/WebView.subproj/WebFrame.m
WebKit/WebView.subproj/WebHTMLView.m
WebKit/WebView.subproj/WebHTMLViewInternal.h
WebKit/WebView.subproj/WebLoader.m
WebKit/WebView.subproj/WebPreferenceKeysPrivate.h
WebKit/WebView.subproj/WebPreferences.m
WebKit/WebView.subproj/WebPreferencesPrivate.h
WebKit/WebView.subproj/WebTextView.m

index b9c3174..67d7ac5 100644 (file)
@@ -1,3 +1,78 @@
+2004-12-16  John Sullivan  <sullivan@apple.com>
+
+        Reviewed by Darin.
+        
+        - fixed <rdar://problem/3913523> Mail needs SPI for adding tooltips to links
+        - cleaned up some calls to +[WebPreferences standardPreferences] that should
+          have been using -[WebView preferences]
+          
+        This adds a (currently SPI-only) new feature that shows the URL of the link
+        under the mouse in a toolTip. I tested this in Safari, but we're adding this
+        feature for Mail, and Safari won't use it (unless of course you know the
+        magic defaults command)
+
+        * Plugins.subproj/WebBaseNetscapePluginView.m:
+        (-[WebBaseNetscapePluginView start]):
+        use -[WebView preferences] instead of +[WebPreferences standardPreferences]
+        
+        * WebCoreSupport.subproj/WebBridge.m:
+        (-[WebBridge getObjectCacheSize]):
+        ditto
+        (-[WebBridge _retrieveKeyboardUIModeFromPreferences:]):
+        ditto
+        
+        * WebView.subproj/WebBaseResourceHandleDelegate.m:
+        (-[WebBaseResourceHandleDelegate willCacheResponse:]):
+        ditto
+        
+        * WebView.subproj/WebFrame.m:
+        (-[WebFrame _transitionToCommitted:]):
+        ditto
+        (-[WebFrame _loadItem:withLoadType:]):
+        ditto
+        
+        * WebView.subproj/WebHTMLViewInternal.h:
+        private struct now keeps ivar for cached value of showsURLsInToolTips
+        so it doesn't have look it up in preferences a zillion times
+        
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView _updateMouseoverWithEvent:]):
+        if private->showsURLsInToolTips is true, set the toolTip from the URL.
+        Fall back to showing the title attribute in case some element has a title
+        attribute but no URL.
+        (-[WebHTMLView _mayStartDragAtEventLocation:]):
+        use -[WebView preferences] instead of +[WebPreferences standardPreferences]
+        (-[WebHTMLView _resetCachedWebPreferences:]):
+        get a fresh value for private->showsURLsInToolTips
+        (-[WebHTMLView initWithFrame:]):
+        call _resetCachedWebPreferences the first time, and listen for WebPreferencesChanged notifications
+        (-[WebHTMLView _handleStyleKeyEquivalent:]):
+        use -[WebView preferences] instead of +[WebPreferences standardPreferences]
+        
+        * WebView.subproj/WebPreferenceKeysPrivate.h:
+        added WebKitShowsURLsInToolTipsPreferenceKey
+        
+        * WebView.subproj/WebPreferences.m:
+        (+[WebPreferences initialize]):
+        initialize WebKitShowsURLsInToolTipsPreferenceKey to 0
+        (-[WebPreferences showsURLsInToolTips]):
+        return WebKitShowsURLsInToolTipsPreferenceKey value
+        (-[WebPreferences setShowsURLsInToolTips:]):
+        set WebKitShowsURLsInToolTipsPreferenceKey value
+        
+        * WebView.subproj/WebPreferencesPrivate.h:
+        add declarations for showsURLsInToolTips and setter
+        
+        * WebView.subproj/WebTextView.m:
+        (-[WebTextView _preferences]):
+        new helper method that gets preferences from webView if there is a webView,
+        otherwise gets global preferences
+        (-[WebTextView setFixedWidthFont]):
+        use new helper method rather than always using global preferences
+        (-[WebTextView initWithFrame:]):
+        observe WebPreferencesChangedNotification instead of unnecessarily general
+        NSUserDefaultsChangedNotification
+
 2004-12-14  John Sullivan  <sullivan@apple.com>
 
         Reviewed by Ken.
index 095260b..ed856fb 100644 (file)
@@ -890,7 +890,8 @@ static OSStatus TSMEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEve
         return YES;
     }
 
-    if (![[WebPreferences standardPreferences] arePlugInsEnabled] || ![self canStart]) {
+    ASSERT([self webView]);
+    if (![[[self webView] preferences] arePlugInsEnabled] || ![self canStart]) {
         return NO;
     }
 
index 5e3e394..1544fab 100644 (file)
@@ -974,7 +974,8 @@ static BOOL loggedObjectCacheSize = NO;
 -(int)getObjectCacheSize
 {
     vm_size_t memSize = WebSystemMainMemory();
-    int cacheSize = [[WebPreferences standardPreferences] _objectCacheSize];
+    ASSERT([_frame webView]);
+    int cacheSize = [[[_frame webView] preferences] _objectCacheSize];
     int multiplier = 1;
     if (memSize >= 1024 * 1024 * 1024)
         multiplier = 4;
@@ -1214,7 +1215,8 @@ static id <WebFormDelegate> formDelegate(WebBridge *self)
     _keyboardUIMode = (mode & 0x2) ? WebCoreKeyboardAccessFull : WebCoreKeyboardAccessDefault;
     
     // check for tabbing to links
-    if ([[WebPreferences standardPreferences] tabsToLinks]) {
+    ASSERT([_frame webView]);
+    if ([[[_frame webView] preferences] tabsToLinks]) {
         _keyboardUIMode |= WebCoreKeyboardAccessTabsToLinks;
     }
 }
index 223e00f..8cd77af 100644 (file)
@@ -522,7 +522,7 @@ static BOOL NSURLConnectionSupportsBufferedData;
 - (NSCachedURLResponse *)willCacheResponse:(NSCachedURLResponse *)cachedResponse
 {
     // When in private browsing mode, prevent caching to disk
-    if ([cachedResponse storagePolicy] == NSURLCacheStorageAllowed && [[WebPreferences standardPreferences] privateBrowsingEnabled]) {
+    if ([cachedResponse storagePolicy] == NSURLCacheStorageAllowed && [[webView preferences] privateBrowsingEnabled]) {
         cachedResponse = [[[NSCachedURLResponse alloc] initWithResponse:[cachedResponse response]
                                                                    data:[cachedResponse data]
                                                                userInfo:[cachedResponse userInfo]
index 4a469ec..66e67e7 100644 (file)
@@ -762,7 +762,8 @@ NSString *WebPageCacheDocumentViewKey = @"WebPageCacheDocumentViewKey";
                     // Add item to history and BF list
                     NSURL *URL = [ds _URLForHistory];
                     if (URL && ![URL _web_isEmpty]){
-                        if (![[WebPreferences standardPreferences] privateBrowsingEnabled]) {
+                        ASSERT([self webView]);
+                        if (![[[self webView] preferences] privateBrowsingEnabled]) {
                             entry = [[WebHistory optionalSharedHistory] addItemForURL:URL];
                             if (ptitle)
                                 [entry setTitle: ptitle];                            
@@ -1309,13 +1310,13 @@ static CFAbsoluteTime _timeOfLastCompletedLoad;
             NSDate *cacheDate = [pageCache objectForKey: WebPageCacheEntryDateKey];
             NSTimeInterval delta = [[NSDate date] timeIntervalSinceDate: cacheDate];
 
-            if (delta <= [[WebPreferences standardPreferences] _backForwardCacheExpirationInterval]){
+            if (delta <= [[[self webView] preferences] _backForwardCacheExpirationInterval]){
                 newDataSource = [pageCache objectForKey: WebPageCacheDataSourceKey];
                 [self _loadDataSource:newDataSource withLoadType:loadType formState:nil];   
                 inPageCache = YES;
             }         
             else {
-                LOG (PageCache, "Not restoring page from back/forward cache because cache entry has expired, %@ (%3.5f > %3.5f seconds)\n", [[_private provisionalItem] URL], delta, [[WebPreferences standardPreferences] _backForwardCacheExpirationInterval]);
+                LOG (PageCache, "Not restoring page from back/forward cache because cache entry has expired, %@ (%3.5f > %3.5f seconds)\n", [[_private provisionalItem] URL], delta, [[[self webView] preferences] _backForwardCacheExpirationInterval]);
                 [item setHasPageCache: NO];
             }
         }
index c830502..c997f9b 100644 (file)
@@ -822,7 +822,14 @@ static WebHTMLView *lastHitView = nil;
     [[self _webView] _mouseDidMoveOverElement:element modifierFlags:[event modifierFlags]];
 
     // Set a tool tip; it won't show up right away but will if the user pauses.
-    [self _setToolTip:[element objectForKey:WebCoreElementTitleKey]];
+    NSString *newToolTip = nil;
+    if (_private->showsURLsInToolTips) {
+        newToolTip = [[element objectForKey:WebCoreElementLinkURLKey] _web_userVisibleString];
+    }
+    if (newToolTip == nil) {
+        newToolTip = [element objectForKey:WebCoreElementTitleKey];
+    }
+    [self _setToolTip:newToolTip];
 }
 
 + (NSArray *)_insertablePasteboardTypes
@@ -1093,9 +1100,10 @@ static WebHTMLView *lastHitView = nil;
     NSPoint mouseDownPoint = [self convertPoint:location fromView:nil];
     NSDictionary *mouseDownElement = [self elementAtPoint:mouseDownPoint];
 
+    ASSERT([self _webView]);
     if ([mouseDownElement objectForKey: WebElementImageKey] != nil &&
         [mouseDownElement objectForKey: WebElementImageURLKey] != nil && 
-        [[WebPreferences standardPreferences] loadsImagesAutomatically] && 
+        [[[self _webView] preferences] loadsImagesAutomatically] && 
         (_private->dragSourceActionMask & WebDragSourceActionImage)) {
         return YES;
     }
@@ -1386,6 +1394,16 @@ static WebHTMLView *lastHitView = nil;
     _NSInitializeKillRing();
 }
 
+- (void)_resetCachedWebPreferences:(NSNotification *)ignored
+{
+    WebPreferences *preferences = [[self _webView] preferences];
+    // Check for nil because we might not yet have an associated webView when this is called
+    if (preferences == nil) {
+        preferences = [WebPreferences standardPreferences];
+    }
+    _private->showsURLsInToolTips = [preferences showsURLsInToolTips];
+}
+
 - (id)initWithFrame:(NSRect)frame
 {
     [super initWithFrame:frame];
@@ -1399,7 +1417,11 @@ static WebHTMLView *lastHitView = nil;
 
     _private->pluginController = [[WebPluginController alloc] initWithDocumentView:self];
     _private->needsLayout = YES;
-
+    [self _resetCachedWebPreferences:nil];
+    [[NSNotificationCenter defaultCenter] 
+            addObserver:self selector:@selector(_resetCachedWebPreferences:) 
+                   name:WebPreferencesChangedNotification object:nil];
+    
     return self;
 }
 
@@ -3268,7 +3290,8 @@ static WebHTMLView *lastHitView = nil;
 
 - (BOOL)_handleStyleKeyEquivalent:(NSEvent *)event
 {
-    if (![[WebPreferences standardPreferences] respectStandardStyleKeyEquivalents]) {
+    ASSERT([self _webView]);
+    if (![[[self _webView] preferences] respectStandardStyleKeyEquivalents]) {
         return NO;
     }
     
index 0186eb8..02532fd 100644 (file)
@@ -10,6 +10,7 @@
     BOOL needsLayout;
     BOOL needsToApplyStyles;
     BOOL inWindow;
+    BOOL showsURLsInToolTips;
     BOOL ignoringMouseDraggedEvents;
     BOOL printing;
     BOOL initiatedDrag;
index 223e00f..8cd77af 100644 (file)
@@ -522,7 +522,7 @@ static BOOL NSURLConnectionSupportsBufferedData;
 - (NSCachedURLResponse *)willCacheResponse:(NSCachedURLResponse *)cachedResponse
 {
     // When in private browsing mode, prevent caching to disk
-    if ([cachedResponse storagePolicy] == NSURLCacheStorageAllowed && [[WebPreferences standardPreferences] privateBrowsingEnabled]) {
+    if ([cachedResponse storagePolicy] == NSURLCacheStorageAllowed && [[webView preferences] privateBrowsingEnabled]) {
         cachedResponse = [[[NSCachedURLResponse alloc] initWithResponse:[cachedResponse response]
                                                                    data:[cachedResponse data]
                                                                userInfo:[cachedResponse userInfo]
index 1580946..31dd737 100644 (file)
@@ -41,4 +41,5 @@
 // These are private both because callers should be using the cover methods and because the
 // cover methods themselves are private.
 #define WebKitRespectStandardStyleKeyEquivalentsPreferenceKey @"WebKitRespectStandardStyleKeyEquivalents"
+#define WebKitShowsURLsInToolTipsPreferenceKey @"WebKitShowsURLsInToolTips"
 
index 2c01a15..752c844 100644 (file)
@@ -200,6 +200,7 @@ NS_ENDHANDLER
         [NSNumber numberWithBool:NO],   WebKitTabToLinksPreferenceKey,
         [NSNumber numberWithBool:NO],   WebKitPrivateBrowsingEnabledPreferenceKey,
         [NSNumber numberWithBool:NO],   WebKitRespectStandardStyleKeyEquivalentsPreferenceKey,
+        [NSNumber numberWithBool:NO],   WebKitShowsURLsInToolTipsPreferenceKey,
         nil];
 
     [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
@@ -542,6 +543,16 @@ NS_ENDHANDLER
     [self _setBoolValue:flag forKey:WebKitRespectStandardStyleKeyEquivalentsPreferenceKey];
 }
 
+- (BOOL)showsURLsInToolTips
+{
+    return [self _boolValueForKey:WebKitShowsURLsInToolTipsPreferenceKey];
+}
+
+- (void)setShowsURLsInToolTips:(BOOL)flag
+{
+    [self _setBoolValue:flag forKey:WebKitShowsURLsInToolTipsPreferenceKey];
+}
+
 - (int)_pageCacheSize
 {
     return [[NSUserDefaults standardUserDefaults] integerForKey:WebKitPageCacheSizePreferenceKey];
index 54faa1c..561c5a4 100644 (file)
@@ -11,6 +11,9 @@
 - (BOOL)respectStandardStyleKeyEquivalents;
 - (void)setRespectStandardStyleKeyEquivalents:(BOOL)flag;
 
+- (BOOL)showsURLsInToolTips;
+- (void)setShowsURLsInToolTips:(BOOL)flag;
+
 // Other private methods
 - (int)_pageCacheSize;
 - (int)_objectCacheSize;
index 80994ef..35b0292 100644 (file)
@@ -48,7 +48,7 @@
         [self setEditable:NO];
         [[NSNotificationCenter defaultCenter] addObserver:self
                                                  selector:@selector(defaultsChanged:)
-                                                     name:NSUserDefaultsDidChangeNotification
+                                                     name:WebPreferencesChangedNotification
                                                    object:nil];
     }
     return self;
     return webView ? [webView textSizeMultiplier] : 1.0;
 }
 
+- (WebPreferences *)_preferences
+{
+    // Handle nil result because we might not be in a WebView at any given time.
+    WebPreferences *preferences = [[self _web_parentWebView] preferences];
+    if (preferences == nil) {
+        preferences = [WebPreferences standardPreferences];
+    }
+    return preferences;
+}
+
+
 - (void)setFixedWidthFont
 {
-    WebPreferences *preferences = [WebPreferences standardPreferences];
+    WebPreferences *preferences = [self _preferences];
     NSString *families[2];
     families[0] = [preferences fixedFontFamily];
     families[1] = nil;