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
+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:
__ZN7WebCore14RenderListItem17markerStringValueEv
__ZN7WebCore14ResourceLoader14cancelledErrorEv
__ZN7WebCore14ResourceLoader20inConnectionCallbackEv
-__ZN7WebCore16DeprecatedStringC1ERKS0_
__ZN7WebCore16DeprecatedString6appendENS_14DeprecatedCharE
__ZN7WebCore16DeprecatedString6appendERKS0_
__ZN7WebCore16DeprecatedString6appendEc
__ZN7WebCore16DeprecatedString7replaceENS_14DeprecatedCharES1_
__ZN7WebCore16DeprecatedStringC1EPKc
+__ZN7WebCore16DeprecatedStringC1ERKS0_
__ZN7WebCore16DeprecatedStringC1Ev
__ZN7WebCore16DeprecatedStringD1Ev
__ZN7WebCore16DeprecatedStringaSERKS0_
__ZN7WebCore5Frame23saveInterpreterBuiltinsERN3KJS13SavedBuiltinsE
__ZN7WebCore5Frame6indentEv
__ZN7WebCore5Frame7outdentEv
+__ZN7WebCore5Image10getNSImageEv
__ZN7WebCore5Image21getTIFFRepresentationEv
__ZN7WebCore5RangeC1EPNS_8DocumentEPNS_4NodeEiS4_i
__ZN7WebCore5RangeD1Ev
__ZNK7WebCore13HitTestResult11boundingBoxEv
__ZNK7WebCore13HitTestResult15spellingToolTipEv
__ZNK7WebCore13HitTestResult11targetFrameEv
+__ZNK7WebCore13HitTestResult11textContentEv
+__ZNK7WebCore13HitTestResult15absoluteLinkURLEv
+__ZNK7WebCore13HitTestResult16absoluteImageURLEv
+__ZNK7WebCore13HitTestResult16altDisplayStringEv
+__ZNK7WebCore13HitTestResult18titleDisplayStringEv
+__ZNK7WebCore13HitTestResult5imageEv
__ZNK7WebCore13HitTestResult5titleEv
__ZNK7WebCore14DocumentLoader10isStoppingEv
__ZNK7WebCore14DocumentLoader11frameLoaderEv
#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)
{
}
}
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
class Element;
class Frame;
+class Image;
+class KURL;
class IntRect;
class Node;
class PlatformScrollbar;
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;
+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.
#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)
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
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];
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
return _result->spellingToolTip();
}
-- (NSString *)_title
+- (NSImage *)_image
{
- return _result->title();
+ return _result->image()->getNSImage();
}
- (NSValue *)_imageRect
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