- 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
+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.
return YES;
}
- if (![[WebPreferences standardPreferences] arePlugInsEnabled] || ![self canStart]) {
+ ASSERT([self webView]);
+ if (![[[self webView] preferences] arePlugInsEnabled] || ![self canStart]) {
return 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;
_keyboardUIMode = (mode & 0x2) ? WebCoreKeyboardAccessFull : WebCoreKeyboardAccessDefault;
// check for tabbing to links
- if ([[WebPreferences standardPreferences] tabsToLinks]) {
+ ASSERT([_frame webView]);
+ if ([[[_frame webView] preferences] tabsToLinks]) {
_keyboardUIMode |= WebCoreKeyboardAccessTabsToLinks;
}
}
- (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]
// 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];
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];
}
}
[[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
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;
}
_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];
_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;
}
- (BOOL)_handleStyleKeyEquivalent:(NSEvent *)event
{
- if (![[WebPreferences standardPreferences] respectStandardStyleKeyEquivalents]) {
+ ASSERT([self _webView]);
+ if (![[[self _webView] preferences] respectStandardStyleKeyEquivalents]) {
return NO;
}
BOOL needsLayout;
BOOL needsToApplyStyles;
BOOL inWindow;
+ BOOL showsURLsInToolTips;
BOOL ignoringMouseDraggedEvents;
BOOL printing;
BOOL initiatedDrag;
- (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]
// 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"
[NSNumber numberWithBool:NO], WebKitTabToLinksPreferenceKey,
[NSNumber numberWithBool:NO], WebKitPrivateBrowsingEnabledPreferenceKey,
[NSNumber numberWithBool:NO], WebKitRespectStandardStyleKeyEquivalentsPreferenceKey,
+ [NSNumber numberWithBool:NO], WebKitShowsURLsInToolTipsPreferenceKey,
nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
[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];
- (BOOL)respectStandardStyleKeyEquivalents;
- (void)setRespectStandardStyleKeyEquivalents:(BOOL)flag;
+- (BOOL)showsURLsInToolTips;
+- (void)setShowsURLsInToolTips:(BOOL)flag;
+
// Other private methods
- (int)_pageCacheSize;
- (int)_objectCacheSize;
[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;