WebCore:
authorbdakin <bdakin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Nov 2006 03:22:12 +0000 (03:22 +0000)
committerbdakin <bdakin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Nov 2006 03:22:12 +0000 (03:22 +0000)
        Reviewed by Maciej.

        This adds the back-end of the remaining WebElementDictionary
        functions into HitTestResult.

        * WebCore.exp:
        * rendering/HitTestResult.cpp:
        (WebCore::HitTestResult::title):
        (WebCore::displayString): This is nearly identical to the
        displayString() defined in DOMInternal.mm except that it returns a
        String instead of an NSString. The old code path used the
        DOMInternal method, so I made a new one here for the new code path.
        (WebCore::HitTestResult::altDisplayString):
        (WebCore::HitTestResult::image):
        (WebCore::HitTestResult::absoluteImageURL):
        (WebCore::HitTestResult::absoluteLinkURL):
        (WebCore::HitTestResult::titleDisplayString):
        (WebCore::HitTestResult::textContent):
        * rendering/HitTestResult.h:

WebKit:
        Reviewed by Maciej.

        This creates local functions for the remaining WebElementDictionary
        members that calls into HitTestResult instead of doing magical
        things with the Objective-C DOM classes.

        * ChangeLog:
        * Misc/WebElementDictionary.m:
        (addLookupKey): The values of the dictionary are now just
        selectors. They used to be WebElementMethods which were
        WebElementTargetObjects associated with selectors, but none of that
        is needed any more.
        (+[WebElementDictionary initializeLookupTable]): All selectors are
        now local functions, no more WebElementTargetObjects.
        (-[WebElementDictionary objectForKey:]): No more target objects!
        (-[WebElementDictionary _domNode]): Call into HitTestResult member
        variable.
        (-[WebElementDictionary _altDisplayString]): Same.
        (-[WebElementDictionary _image]): Same.
        (-[WebElementDictionary _absoluteImageURL]): Same.
        (-[WebElementDictionary _title]): Same.
        (-[WebElementDictionary _absoluteLinkURL]): Same.
        (-[WebElementDictionary _targetWebFrame]): Same.
        (-[WebElementDictionary _titleDisplayString]): Same.
        (-[WebElementDictionary _textContent]): Same.

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

WebCore/ChangeLog
WebCore/WebCore.exp
WebCore/rendering/HitTestResult.cpp
WebCore/rendering/HitTestResult.h
WebKit/ChangeLog
WebKit/Misc/WebElementDictionary.m

index 204d299bf56f9d80c0d89feca957f44affa51586..540d8405f5ded1f0a8ea8c09f6f758b284f60114 100644 (file)
@@ -1,3 +1,25 @@
+2006-10-31  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Maciej.
+
+        This adds the back-end of the remaining WebElementDictionary 
+        functions into HitTestResult.
+
+        * WebCore.exp:
+        * rendering/HitTestResult.cpp:
+        (WebCore::HitTestResult::title):
+        (WebCore::displayString): This is nearly identical to the 
+        displayString() defined in DOMInternal.mm except that it returns a 
+        String instead of an NSString. The old code path used the 
+        DOMInternal method, so I made a new one here for the new code path.
+        (WebCore::HitTestResult::altDisplayString):
+        (WebCore::HitTestResult::image):
+        (WebCore::HitTestResult::absoluteImageURL):
+        (WebCore::HitTestResult::absoluteLinkURL):
+        (WebCore::HitTestResult::titleDisplayString):
+        (WebCore::HitTestResult::textContent):
+        * rendering/HitTestResult.h:
+
 2006-10-31  John Sullivan  <sullivan@apple.com>
 
         * bridge/mac/FrameMac.mm:
index 1ad40f37e00c59a21e48a88ea7a3d62602aa2eaf..16f349cab89b9f809a3b59da562b28ed4215f650 100644 (file)
@@ -174,12 +174,12 @@ __ZN7WebCore14DocumentLoaderD2Ev
 __ZN7WebCore14RenderListItem17markerStringValueEv
 __ZN7WebCore14ResourceLoader14cancelledErrorEv
 __ZN7WebCore14ResourceLoader20inConnectionCallbackEv
-__ZN7WebCore16DeprecatedStringC1ERKS0_
 __ZN7WebCore16DeprecatedString6appendENS_14DeprecatedCharE
 __ZN7WebCore16DeprecatedString6appendERKS0_
 __ZN7WebCore16DeprecatedString6appendEc
 __ZN7WebCore16DeprecatedString7replaceENS_14DeprecatedCharES1_
 __ZN7WebCore16DeprecatedStringC1EPKc
+__ZN7WebCore16DeprecatedStringC1ERKS0_
 __ZN7WebCore16DeprecatedStringC1Ev
 __ZN7WebCore16DeprecatedStringD1Ev
 __ZN7WebCore16DeprecatedStringaSERKS0_
@@ -210,6 +210,7 @@ __ZN7WebCore5Frame22saveLocationPropertiesEPN3KJS15SavedPropertiesE
 __ZN7WebCore5Frame23saveInterpreterBuiltinsERN3KJS13SavedBuiltinsE
 __ZN7WebCore5Frame6indentEv
 __ZN7WebCore5Frame7outdentEv
+__ZN7WebCore5Image10getNSImageEv
 __ZN7WebCore5Image21getTIFFRepresentationEv
 __ZN7WebCore5RangeC1EPNS_8DocumentEPNS_4NodeEiS4_i
 __ZN7WebCore5RangeD1Ev
@@ -294,6 +295,12 @@ __ZNK7WebCore13HitTestResult10isSelectedEv
 __ZNK7WebCore13HitTestResult11boundingBoxEv
 __ZNK7WebCore13HitTestResult15spellingToolTipEv
 __ZNK7WebCore13HitTestResult11targetFrameEv
+__ZNK7WebCore13HitTestResult11textContentEv
+__ZNK7WebCore13HitTestResult15absoluteLinkURLEv
+__ZNK7WebCore13HitTestResult16absoluteImageURLEv
+__ZNK7WebCore13HitTestResult16altDisplayStringEv
+__ZNK7WebCore13HitTestResult18titleDisplayStringEv
+__ZNK7WebCore13HitTestResult5imageEv
 __ZNK7WebCore13HitTestResult5titleEv
 __ZNK7WebCore14DocumentLoader10isStoppingEv
 __ZNK7WebCore14DocumentLoader11frameLoaderEv
index 71eed4734d8e76f8b1b7b4c8db7fbc6cbc540341..8cc94ca5086347f4ad8a75d005ff37337a2895f3 100644 (file)
 #include "config.h"
 #include "HitTestResult.h"
 
+#include "csshelper.h"
 #include "Document.h"
 #include "Frame.h"
 #include "FrameTree.h"
 #include "HTMLElement.h"
+#include "HTMLImageElement.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
+#include "KURL.h"
 #include "PlatformScrollBar.h"
 #include "RenderObject.h"
+#include "RenderImage.h"
 #include "SelectionController.h"
 
 namespace WebCore {
 
+using namespace HTMLNames;
+
 HitTestResult::HitTestResult(const IntPoint& point)
     : m_point(point)
 {
@@ -140,6 +148,100 @@ String HitTestResult::title() const
         }
     }
     return String();
-} 
+}
+
+static String displayString(const String& string, const Node* node)
+{
+    if (!node)
+        return string;
+    Document* document = node->document();
+    if (!document)
+        return string;
+    String copy(string);
+    copy.replace('\\', document->backslashAsCurrencySymbol());
+    return copy;
+}
+
+String HitTestResult::altDisplayString() const
+{
+    if (!m_innerNonSharedNode)
+        return String();
+    
+    if (m_innerNonSharedNode->hasTagName(imageTag)) {
+        HTMLImageElement* image = static_cast<HTMLImageElement*>(m_innerNonSharedNode.get());
+        return displayString(image->alt(), m_innerNonSharedNode.get());
+    }
+    
+    if (m_innerNonSharedNode->hasTagName(inputTag)) {
+        HTMLInputElement* input = static_cast<HTMLInputElement*>(m_innerNonSharedNode.get());
+        return displayString(input->alt(), m_innerNonSharedNode.get());
+    }
+    
+    return String();
+}
+
+Image* HitTestResult::image() const
+{
+    if (!m_innerNonSharedNode)
+        return 0;
+    
+    RenderObject* renderer = m_innerNonSharedNode->renderer();
+    if (renderer && renderer->isImage()) {
+        RenderImage* image = static_cast<WebCore::RenderImage*>(renderer);
+        if (image->cachedImage() && !image->cachedImage()->isErrorImage())
+            return image->cachedImage()->image();
+    }
+
+    return 0;
+}
+
+KURL HitTestResult::absoluteImageURL() const
+{
+    if (!(m_innerNonSharedNode && m_innerNonSharedNode->document()))
+        return KURL();
+
+    if (!(m_innerNonSharedNode->renderer() && m_innerNonSharedNode->renderer()->isImage()))
+        return KURL();
+
+    String name;
+    if (m_innerNonSharedNode->hasTagName(imageTag) || m_innerNonSharedNode->hasTagName(inputTag))
+        name = "src";
+    else if (m_innerNonSharedNode->hasTagName(objectTag))
+        name = "data";
+    else
+        return KURL();
+    
+    return KURL(m_innerNonSharedNode->document()->completeURL(parseURL(
+        static_cast<Element*>(m_innerNonSharedNode.get())->getAttribute(name)).deprecatedString()));
+}
+
+KURL HitTestResult::absoluteLinkURL() const
+{
+    if (!(m_innerURLElement && m_innerURLElement->document()))
+        return KURL();
+
+    if (!(m_innerURLElement->hasTagName(aTag) || m_innerURLElement->hasTagName(areaTag)
+            || m_innerURLElement->hasTagName(linkTag)))
+        return KURL();
+
+    return KURL(m_innerURLElement->document()->completeURL(parseURL(
+        static_cast<Element*>(m_innerURLElement.get())->getAttribute("href")).deprecatedString()));
+}
+
+String HitTestResult::titleDisplayString() const
+{
+    if (!(m_innerURLElement && m_innerURLElement->isHTMLElement()))
+        return String();
+
+    HTMLElement* element = static_cast<HTMLElement*>(m_innerURLElement.get());
+    return displayString(element->title(), element);
+}
+
+String HitTestResult::textContent() const
+{
+    if (!m_innerURLElement)
+        return String();
+    return m_innerURLElement->textContent();
+}
 
 } // namespace WebCore
index 4f2bc71abbe6d7f0f23e46d15752cf5a1bb9d1b2..a68526c3854abcab90ff3de34d2837a708ca29ff 100644 (file)
@@ -29,6 +29,8 @@ namespace WebCore {
 
 class Element;
 class Frame;
+class Image;
+class KURL;
 class IntRect;
 class Node;
 class PlatformScrollbar;
@@ -58,6 +60,12 @@ public:
     bool isSelected() const;
     String spellingToolTip() const;
     String title() const;
+    String altDisplayString() const;
+    Image* image() const;
+    KURL absoluteImageURL() const;
+    KURL absoluteLinkURL() const;
+    String titleDisplayString() const;
+    String textContent() const;
 
 private:
     RefPtr<Node> m_innerNode;
index 7329df08cf8ac46900229b83b0509133c54d3d00..572fdbd28bc4879d455482d9bd95ab83c3380751 100644 (file)
@@ -1,3 +1,31 @@
+2006-10-31  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Maciej.
+
+        This creates local functions for the remaining WebElementDictionary 
+        members that calls into HitTestResult instead of doing magical 
+        things with the Objective-C DOM classes.
+
+        * ChangeLog:
+        * Misc/WebElementDictionary.m:
+        (addLookupKey): The values of the dictionary are now just 
+        selectors. They used to be WebElementMethods which were 
+        WebElementTargetObjects associated with selectors, but none of that 
+        is needed any more.
+        (+[WebElementDictionary initializeLookupTable]): All selectors are 
+        now local functions, no more WebElementTargetObjects.
+        (-[WebElementDictionary objectForKey:]): No more target objects!
+        (-[WebElementDictionary _domNode]): Call into HitTestResult member 
+        variable.
+        (-[WebElementDictionary _altDisplayString]): Same.
+        (-[WebElementDictionary _image]): Same.
+        (-[WebElementDictionary _absoluteImageURL]): Same.
+        (-[WebElementDictionary _title]): Same.
+        (-[WebElementDictionary _absoluteLinkURL]): Same.
+        (-[WebElementDictionary _targetWebFrame]): Same.
+        (-[WebElementDictionary _titleDisplayString]): Same.
+        (-[WebElementDictionary _textContent]): Same.
+
 2006-10-31  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Alice.
index e80115afdf01212261b4c263dfb853a469e70a13..5798c035d37ab3f6874bc17f398582dfd6eccaf8 100644 (file)
 #import <WebKit/DOMExtensions.h>
 #import <WebCore/FrameMac.h>
 #import <WebCore/HitTestResult.h>
+#import <WebCore/Image.h>
+#import <WebCore/KURL.h>
 
 using namespace WebCore;
 
-typedef enum {
-    WebElementSelf,
-    WebElementInnerNode,
-    WebElementInnerNonSharedNode,
-    WebElementURLElement
-} WebElementTargetObject;
-
-typedef struct WebElementMethod {
-    WebElementTargetObject target;
-    SEL selector;
-} WebElementMethod;
-
 static CFMutableDictionaryRef lookupTable = NULL;
 
-static void addLookupKey(NSString *key, SEL selector, WebElementTargetObject target)
+static void addLookupKey(NSString *key, SEL selector)
 {
-    WebElementMethod* elementMethod = static_cast<WebElementMethod*>(malloc(sizeof(WebElementMethod)));
-    elementMethod->target = target;
-    elementMethod->selector = selector;
-    CFDictionaryAddValue(lookupTable, key, elementMethod);
+    CFDictionaryAddValue(lookupTable, key, selector);
 }
 
 static void cacheValueForKey(const void *key, const void *value, void *self)
@@ -78,19 +65,19 @@ static void cacheValueForKey(const void *key, const void *value, void *self)
 
     lookupTable = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFCopyStringDictionaryKeyCallBacks, NULL);
 
-    addLookupKey(WebElementDOMNodeKey, @selector(_domNode), WebElementSelf);
-    addLookupKey(WebElementFrameKey, @selector(_webFrame), WebElementSelf);
-    addLookupKey(WebElementImageAltStringKey, @selector(altDisplayString), WebElementInnerNonSharedNode);
-    addLookupKey(WebElementImageKey, @selector(image), WebElementInnerNonSharedNode);
-    addLookupKey(WebElementImageRectKey, @selector(_imageRect), WebElementSelf);
-    addLookupKey(WebElementImageURLKey, @selector(absoluteImageURL), WebElementInnerNonSharedNode);
-    addLookupKey(WebElementIsSelectedKey, @selector(_isSelected), WebElementSelf);
-    addLookupKey(WebElementSpellingToolTipKey, @selector(_spellingToolTip), WebElementSelf);
-    addLookupKey(WebElementTitleKey, @selector(_title), WebElementSelf);
-    addLookupKey(WebElementLinkURLKey, @selector(absoluteLinkURL), WebElementURLElement);
-    addLookupKey(WebElementLinkTargetFrameKey, @selector(_targetWebFrame), WebElementSelf);
-    addLookupKey(WebElementLinkTitleKey, @selector(titleDisplayString), WebElementURLElement);
-    addLookupKey(WebElementLinkLabelKey, @selector(textContent), WebElementURLElement);
+    addLookupKey(WebElementDOMNodeKey, @selector(_domNode));
+    addLookupKey(WebElementFrameKey, @selector(_webFrame));
+    addLookupKey(WebElementImageAltStringKey, @selector(_altDisplayString));
+    addLookupKey(WebElementImageKey, @selector(_image));
+    addLookupKey(WebElementImageRectKey, @selector(_imageRect));
+    addLookupKey(WebElementImageURLKey, @selector(_absoluteImageURL));
+    addLookupKey(WebElementIsSelectedKey, @selector(_isSelected));
+    addLookupKey(WebElementSpellingToolTipKey, @selector(_spellingToolTip));
+    addLookupKey(WebElementTitleKey, @selector(_title));
+    addLookupKey(WebElementLinkURLKey, @selector(_absoluteLinkURL));
+    addLookupKey(WebElementLinkTargetFrameKey, @selector(_targetWebFrame));
+    addLookupKey(WebElementLinkTitleKey, @selector(_titleDisplayString));
+    addLookupKey(WebElementLinkLabelKey, @selector(_textContent));
 }
 
 - (id)initWithHitTestResult:(const HitTestResult&)result
@@ -135,42 +122,18 @@ static void cacheValueForKey(const void *key, const void *value, void *self)
     return [_cache keyEnumerator];
 }
 
-- (DOMNode *)_domNode
-{
-    return kit(_result->innerNonSharedNode());
-}
-
 - (id)objectForKey:(id)key
 {
     id value = [_cache objectForKey:key];
     if (value || _cacheComplete || [_nilValues containsObject:key])
         return value;
 
-    WebElementMethod *elementMethod = (WebElementMethod *)CFDictionaryGetValue(lookupTable, key);
-    if (!elementMethod)
+    SEL selector = (SEL)CFDictionaryGetValue(lookupTable, key);
+    if (!selector)
         return nil;
-
-    id target = nil;
-    switch (elementMethod->target) {
-        case WebElementSelf:
-            target = self;
-            break;
-        case WebElementInnerNonSharedNode:
-            target = [self _domNode];
-            break;
-        case WebElementInnerNode:
-            target = kit(_result->innerNode());
-            break;
-        case WebElementURLElement:
-            target = kit(_result->URLElement());
-            break;
-    }
-
-    if (target && [target respondsToSelector:elementMethod->selector])
-        value = [target performSelector:elementMethod->selector];
+    value = [self performSelector:selector];
 
     unsigned lookupTableCount = CFDictionaryGetCount(lookupTable);
-
     if (value) {
         if (!_cache)
             _cache = [[NSMutableDictionary alloc] initWithCapacity:lookupTableCount];
@@ -186,15 +149,19 @@ static void cacheValueForKey(const void *key, const void *value, void *self)
     return value;
 }
 
+- (DOMNode *)_domNode
+{
+    return kit(_result->innerNonSharedNode());
+}
+
 - (WebFrame *)_webFrame
 {
     return [[[self _domNode] ownerDocument] webFrame];
 }
 
-- (WebFrame *)_targetWebFrame
+- (NSString *)_altDisplayString
 {
-    FrameMac* webCoreFrame = Mac(_result->targetFrame());
-    return kit(webCoreFrame);
+    return _result->altDisplayString();
 }
 
 - (NSString *)_spellingToolTip
@@ -202,9 +169,9 @@ static void cacheValueForKey(const void *key, const void *value, void *self)
     return _result->spellingToolTip();
 }
 
-- (NSString *)_title
+- (NSImage *)_image
 {
-    return _result->title();
+    return _result->image()->getNSImage();
 }
 
 - (NSValue *)_imageRect
@@ -214,8 +181,40 @@ static void cacheValueForKey(const void *key, const void *value, void *self)
     return nil;
 }
 
+- (NSURL *)_absoluteImageURL
+{
+    return _result->absoluteImageURL().getNSURL();
+}
+
 - (NSNumber *)_isSelected
 {
     return [NSNumber numberWithBool:_result->isSelected()];
 }
+
+- (NSString *)_title
+{
+    return _result->title();
+}
+
+- (NSURL *)_absoluteLinkURL
+{
+    return _result->absoluteLinkURL().getNSURL();
+}
+
+- (WebFrame *)_targetWebFrame
+{
+    FrameMac* webCoreFrame = Mac(_result->targetFrame());
+    return kit(webCoreFrame);
+}
+
+- (NSString *)_titleDisplayString
+{
+    return _result->titleDisplayString();
+}
+
+- (NSString *)_textContent
+{
+    return _result->textContent();
+}
+
 @end