Move tooltip logic down into WebCore so that it can be shared cross-platform
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2007 03:00:55 +0000 (03:00 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2007 03:00:55 +0000 (03:00 +0000)
WebCore:

        Move tooltip logic down into WebCore so that it can be shared cross-platform

        Reviewed by Sam.

        * page/Chrome.cpp:
        (WebCore::Chrome::setToolTip): Added.
        * page/Chrome.h:
        * page/ChromeClient.h:
        * page/EventHandler.cpp:
        (WebCore::EventHandler::mouseMoved): Call Chrome::setToolTip.
        * platform/graphics/svg/SVGImageEmptyClients.h:

        Added stubs for Gdk:

        * platform/gdk/ChromeClientGdk.h:
        * platform/gdk/TemporaryLinkStubs.cpp:
        (ChromeClientGdk::setToolTip):

WebKit:

        Move tooltip logic down into WebCore so that it can be shared cross-platform

        Reviewed by Sam.

        * WebCoreSupport/WebChromeClient.h:
        * WebCoreSupport/WebChromeClient.mm:
        (WebChromeClient::setToolTip): Added.
        * WebView/WebHTMLView.mm: Removed _resetCachedWebPreferences.
        (-[WebHTMLView _updateMouseoverWithEvent:]): Removed tooltip code.
        (-[WebHTMLView initWithFrame:]): Removed call to
        _resetCachedWebPreferences.
        (-[WebHTMLView setDataSource:]): Ditto.
        * WebView/WebHTMLViewInternal.h: Removed showsURLsInToolTips ivar.
        * WebView/WebHTMLViewPrivate.h: Added declaration for _setTooltip so
        that WebChromeClient can call it.

WebKit/win:

        Added a stub for WebChromeClient::setToolTip

        Reviewed by Sam.

        * WebChromeClient.cpp:
        * WebChromeClient.h:

WebKitQt:

        Added a stub for ChromeClientQt::setToolTip

        Reviewed by Sam.

        * WebCoreSupport/ChromeClientQt.cpp:
        (WebCore::ChromeClientQt::setToolTip):
        * WebCoreSupport/ChromeClientQt.h:

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

20 files changed:
WebCore/ChangeLog
WebCore/page/Chrome.cpp
WebCore/page/Chrome.h
WebCore/page/ChromeClient.h
WebCore/page/EventHandler.cpp
WebCore/platform/gdk/ChromeClientGdk.h
WebCore/platform/gdk/TemporaryLinkStubs.cpp
WebCore/platform/graphics/svg/SVGImageEmptyClients.h
WebKit/ChangeLog
WebKit/WebCoreSupport/WebChromeClient.h
WebKit/WebCoreSupport/WebChromeClient.mm
WebKit/WebView/WebHTMLView.mm
WebKit/WebView/WebHTMLViewInternal.h
WebKit/WebView/WebHTMLViewPrivate.h
WebKit/win/ChangeLog
WebKit/win/WebChromeClient.cpp
WebKit/win/WebChromeClient.h
WebKitQt/ChangeLog
WebKitQt/WebCoreSupport/ChromeClientQt.cpp
WebKitQt/WebCoreSupport/ChromeClientQt.h

index c1dfff79cae901ca4d9bbc44e137c205d2ff5291..817b5f7ca43c85af3fc928b64a6dfe9d5b793f14 100644 (file)
@@ -1,3 +1,23 @@
+2007-07-04  Adam Roben  <aroben@apple.com>
+
+        Move tooltip logic down into WebCore so that it can be shared cross-platform
+
+        Reviewed by Sam.
+
+        * page/Chrome.cpp:
+        (WebCore::Chrome::setToolTip): Added.
+        * page/Chrome.h:
+        * page/ChromeClient.h:
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::mouseMoved): Call Chrome::setToolTip.
+        * platform/graphics/svg/SVGImageEmptyClients.h:
+
+        Added stubs for Gdk:
+
+        * platform/gdk/ChromeClientGdk.h:
+        * platform/gdk/TemporaryLinkStubs.cpp:
+        (ChromeClientGdk::setToolTip):
+
 2007-07-04  Adam Roben  <aroben@apple.com>
 
         Add Settings::showsURLsInToolTips
index dc7d70fbd0b7b8cb2e9a2d1a1c85ed7e5f3425ef..31fdcf078fb275c2d44aa38c4c8feb5bac22d333 100644 (file)
 #include "ChromeClient.h"
 #include "FloatRect.h"
 #include "Frame.h"
+#include "HTMLFormElement.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
 #include "InspectorController.h"
 #include "Page.h"
 #include "ResourceHandle.h"
+#include "Settings.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
+using namespace HTMLNames;
+
 class PageGroupLoadDeferrer : Noncopyable {
 public:
     PageGroupLoadDeferrer(Page*, bool deferSelf);
@@ -298,6 +304,36 @@ void Chrome::mouseDidMoveOverElement(const HitTestResult& result, unsigned modif
     m_client->mouseDidMoveOverElement(result, modifierFlags);
 }
 
+void Chrome::setToolTip(const HitTestResult& result)
+{
+    // First priority is a potential toolTip representing a spelling or grammar error
+    String toolTip = result.spellingToolTip();
+
+    // Next priority is a toolTip from a URL beneath the mouse (if preference is set to show those).
+    if (toolTip.isEmpty() && m_page->settings()->showsURLsInToolTips()) {
+        if (Node* node = result.innerNonSharedNode()) {
+            // Get tooltip representing form action, if relevant
+            if (node->hasTagName(inputTag)) {
+                HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
+                if (input->inputType() == HTMLInputElement::SUBMIT)
+                    if (HTMLFormElement* form = input->form())
+                        toolTip = form->action();
+            }
+        }
+
+        // Get tooltip representing link's URL
+        if (toolTip.isEmpty())
+            // FIXME: Need to pass this URL through userVisibleString once that's in WebCore
+            toolTip = result.absoluteLinkURL().url();
+    }
+
+    // Lastly we'll consider a tooltip for element with "title" attribute
+    if (toolTip.isEmpty())
+        toolTip = result.title();
+
+    m_client->setToolTip(toolTip);
+}
+
 PageGroupLoadDeferrer::PageGroupLoadDeferrer(Page* page, bool deferSelf)
 {
     if (const HashSet<Page*>* group = page->frameNamespace()) {
index 82fa4eda4a0debaa1f1f8e84476220d20d7ed54a..ffc2955c76f625afd4e9f97338f65c210b00ff3c 100644 (file)
@@ -121,6 +121,8 @@ namespace WebCore {
 
         void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags);
 
+        void setToolTip(const HitTestResult&);
+
 #if PLATFORM(MAC)
         void focusNSView(NSView*);
 #endif
index db883395cf2ab0bd4a262732c1855df31bf7b8c7..e69b0fab5b88d2f790e6979b9f1bafa944ec0a18 100644 (file)
@@ -98,6 +98,8 @@ namespace WebCore {
         virtual void updateBackingStore() = 0;
 
         virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) = 0;
+
+        virtual void setToolTip(const String&) = 0;
 };
 
 }
index 194d1a159f0423c6c5a953015362b8dccc82babb..c5d5b75a8da9d4b6186edd561cd3702a977a0c5f 100644 (file)
@@ -893,6 +893,7 @@ bool EventHandler::mouseMoved(const PlatformMouseEvent& event)
 
     hoveredNode.setToNonShadowAncestor();
     page->chrome()->mouseDidMoveOverElement(hoveredNode, event.modifierFlags());
+    page->chrome()->setToolTip(hoveredNode);
     return result;
 }
 
index 7c91d54506fd95f973e1768abd409861c249f3da..ed30241ffc42b576402e60ad0655c06ec175d8e9 100644 (file)
@@ -89,6 +89,8 @@ namespace WebCore {
         virtual void updateBackingStore();
 
         virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags);
+
+        virtual void setToolTip(const String&);
     };
 }
 
index f73fdb2a3929d318e63070cfecdd9720a54bb917..19ea0533b3310bac9051fbc0281546195dd10c7b 100644 (file)
@@ -173,6 +173,11 @@ void ChromeClientGdk::mouseDidMoveOverElement(const HitTestResult&, unsigned mod
     notImplemented();
 }
 
+void ChromeClientGdk::setToolTip(const String&)
+{
+    notImplemented();
+}
+
 /********************************************************/
 /* Completely empty stubs (mostly to allow DRT to run): */
 /********************************************************/
index 3e78fdbb32ea154d32026ae2d2b6e855b515604f..fc362fd77f26bd83a47024170f9e4e16dc134417 100644 (file)
@@ -112,6 +112,7 @@ public:
 
     virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) { }
     
+    virtual void setToolTip(const String&) { }
 };
 
 class SVGEmptyFrameLoaderClient : public FrameLoaderClient {
index 26571b25c3f72077a33ecd9fe365eb7067881c8a..47aed07fc9e7d7a1eb556b96f30d5ed509b493cc 100644 (file)
@@ -1,3 +1,21 @@
+2007-07-04  Adam Roben  <aroben@apple.com>
+
+        Move tooltip logic down into WebCore so that it can be shared cross-platform
+
+        Reviewed by Sam.
+
+        * WebCoreSupport/WebChromeClient.h:
+        * WebCoreSupport/WebChromeClient.mm:
+        (WebChromeClient::setToolTip): Added.
+        * WebView/WebHTMLView.mm: Removed _resetCachedWebPreferences.
+        (-[WebHTMLView _updateMouseoverWithEvent:]): Removed tooltip code.
+        (-[WebHTMLView initWithFrame:]): Removed call to
+        _resetCachedWebPreferences.
+        (-[WebHTMLView setDataSource:]): Ditto.
+        * WebView/WebHTMLViewInternal.h: Removed showsURLsInToolTips ivar.
+        * WebView/WebHTMLViewPrivate.h: Added declaration for _setTooltip so
+        that WebChromeClient can call it.
+
 2007-07-04  Adam Roben  <aroben@apple.com>
 
         Initialize Settings::showsURLsInToolTips
index 145dfe3535b72a5f31f81e7d2cf326294f8b1335..9c53d3871e5baca292dd00528e4754e03ae2f17f 100644 (file)
@@ -97,6 +97,8 @@ public:
 
     virtual void mouseDidMoveOverElement(const WebCore::HitTestResult&, unsigned modifierFlags);
 
+    virtual void setToolTip(const WebCore::String&);
+
 private:
     WebView *m_webView;
 };
index b77f60957b294fbfdfc27b245be6b93b98077693..531169625379e2e932e282dff4df90ac210db34f 100644 (file)
@@ -34,6 +34,7 @@
 #import "WebFrameInternal.h"
 #import "WebFrameView.h"
 #import "WebHTMLView.h"
+#import "WebHTMLViewPrivate.h"
 #import "WebNSURLRequestExtras.h"
 #import "WebUIDelegate.h"
 #import "WebUIDelegatePrivate.h"
@@ -376,3 +377,8 @@ void WebChromeClient::mouseDidMoveOverElement(const HitTestResult& result, unsig
     [m_webView _mouseDidMoveOverElement:element modifierFlags:modifierFlags];
     [element release];
 }
+
+void WebChromeClient::setToolTip(const String& toolTip)
+{
+    [(WebHTMLView *)[[[m_webView mainFrame] frameView] documentView] _setToolTip:toolTip];
+}
index 4004c6c6a1ba5c51532c7ed9142167c0a453c4be..6afd6194b6b0ccf36cec10442450c295811c1c37 100644 (file)
@@ -1185,35 +1185,6 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart)
         if (Frame* coreFrame = core([view _frame]))
             coreFrame->eventHandler()->mouseMoved(event);
 
-        NSPoint point = [view convertPoint:[event locationInWindow] fromView:nil];
-        NSDictionary *element = [view elementAtPoint:point];
-
-        // Set a tool tip; it won't show up right away but will if the user pauses.
-
-        // First priority is a potential toolTip representing a spelling or grammar error
-        NSString *newToolTip = [element objectForKey:WebElementSpellingToolTipKey];
-        
-        // Next priority is a toolTip from a URL beneath the mouse (if preference is set to show those).
-        if ([newToolTip length] == 0 && _private->showsURLsInToolTips) {
-            DOMHTMLElement *domElement = [element objectForKey:WebElementDOMNodeKey];
-            
-            // Get tooltip representing form action, if relevant
-            if ([domElement isKindOfClass:[DOMHTMLInputElement class]]) {
-                if ([[(DOMHTMLInputElement *)domElement type] isEqualToString:@"submit"])
-                    newToolTip = [[(DOMHTMLInputElement *) domElement form] action];
-            }
-            
-            // Get tooltip representing link's URL
-            if ([newToolTip length] == 0)
-                newToolTip = [[element objectForKey:WebElementLinkURLKey] _web_userVisibleString];
-        }
-        
-        // Lastly we'll consider a tooltip for element with "title" attribute
-        if ([newToolTip length] == 0)
-            newToolTip = [element objectForKey:WebElementTitleKey];
-        
-        [view _setToolTip:newToolTip];
-
         [view release];
     }
 }
@@ -1848,16 +1819,6 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart)
 #endif
 }
 
-- (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
 {
     self = [super initWithFrame:frame];
@@ -1873,10 +1834,6 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart)
 
     _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;
 }
@@ -3053,7 +3010,6 @@ noPromisedData:
         [_private->pluginController setDataSource:dataSource];
         [self addMouseMovedObserver];
     }
-    [self _resetCachedWebPreferences:nil];
 }
 
 - (void)dataSourceUpdated:(WebDataSource *)dataSource
index ea1d6d6fcf4798b992e3295da30bf7e0ac7ce873..88261d962e7006ac7e1c04136e13f680c1282218 100644 (file)
@@ -47,7 +47,6 @@ struct WebHTMLViewInterpretKeyEventsParameters;
     BOOL closed;
     BOOL needsLayout;
     BOOL needsToApplyStyles;
-    BOOL showsURLsInToolTips;
     BOOL ignoringMouseDraggedEvents;
     BOOL printing;
     
index 26285fc5f4c5dcce6d0376fc64c46b3eacc55c34..9c3c69a3f0c45832a3c9099aedfcb59d80b6c666 100644 (file)
@@ -95,6 +95,8 @@
 - (BOOL)_transparentBackground;
 - (void)_setTransparentBackground:(BOOL)f;
 
+- (void)_setToolTip:(NSString *)string;
+
 // SPI's for Mail.
 - (NSImage *)_selectionDraggingImage;
 - (NSRect)_selectionDraggingRect;
index 25f2fb62777fd397ca9454963b0de213a3cc77fc..47568daee210182912b3d287511642630cf22020 100644 (file)
@@ -1,3 +1,12 @@
+2007-07-04  Adam Roben  <aroben@apple.com>
+
+        Added a stub for WebChromeClient::setToolTip
+
+        Reviewed by Sam.
+
+        * WebChromeClient.cpp:
+        * WebChromeClient.h:
+
 2007-07-04  Adam Roben  <aroben@apple.com>
 
         Initialize Settings::showsURLsInToolTips
index 915cf75b890af35d4d2303329c8d85d30badb0b1..3cf8dd78a0cd7e8babe299f3d6c263f9f8da7a7c 100644 (file)
@@ -437,3 +437,7 @@ void WebChromeClient::mouseDidMoveOverElement(const HitTestResult& result, unsig
 
     uiDelegate->mouseDidMoveOverElement(m_webView, element.get(), modifierFlags);
 }
+
+void WebChromeClient::setToolTip(const String&)
+{
+}
index c085213e4b2c82a5ff5a08f4fb8ecaf22257725a..e190239663e2d622fde0a901eb82e54d50b7e6d5 100644 (file)
@@ -90,6 +90,8 @@ public:
 
     virtual void mouseDidMoveOverElement(const WebCore::HitTestResult&, unsigned modifierFlags);
 
+    virtual void setToolTip(const WebCore::String&);
+
 private:
     WebView* m_webView;
 };
index 28910c85daa5a9d9057c30139b5a269c8e0c5de1..dca398fb27e01708a9d0a0dd3a60d528012681c8 100644 (file)
@@ -1,3 +1,13 @@
+2007-07-04  Adam Roben  <aroben@apple.com>
+
+        Added a stub for ChromeClientQt::setToolTip
+
+        Reviewed by Sam.
+
+        * WebCoreSupport/ChromeClientQt.cpp:
+        (WebCore::ChromeClientQt::setToolTip):
+        * WebCoreSupport/ChromeClientQt.h:
+
 2007-07-04  Adam Roben  <aroben@apple.com>
 
         Added a stub for ChromeClientQt::mouseDidMoveOverElement
index 6716d17d13b551547e220fd92434a4873650f5c3..e15f18e15836b2bdadb744a6f25f73c3368bec13 100644 (file)
@@ -299,6 +299,11 @@ void ChromeClientQt::mouseDidMoveOverElement(const HitTestResult&, unsigned /*mo
     notImplemented();
 }
 
+void ChromeClientQt::setToolTip(const String&)
+{
+    notImplemented();
+}
+
 }
 
 
index 5000d2dda9ffabf07c663e37c127acadb36a3a73..9bd39805fe6d26014962b56bb04374d83783e598 100644 (file)
@@ -104,6 +104,8 @@ namespace WebCore {
 
         virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags);
 
+        virtual void setToolTip(const String&);
+
         QWebPage* m_webPage;
     };
 }