Changeset 17511 in webkit


Ignore:
Timestamp:
Oct 31, 2006, 7:22:12 PM (18 years ago)
Author:
bdakin
Message:

WebCore:

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.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r17509 r17511  
     12006-10-31  Beth Dakin  <bdakin@apple.com>
     2
     3        Reviewed by Maciej.
     4
     5        This adds the back-end of the remaining WebElementDictionary
     6        functions into HitTestResult.
     7
     8        * WebCore.exp:
     9        * rendering/HitTestResult.cpp:
     10        (WebCore::HitTestResult::title):
     11        (WebCore::displayString): This is nearly identical to the
     12        displayString() defined in DOMInternal.mm except that it returns a
     13        String instead of an NSString. The old code path used the
     14        DOMInternal method, so I made a new one here for the new code path.
     15        (WebCore::HitTestResult::altDisplayString):
     16        (WebCore::HitTestResult::image):
     17        (WebCore::HitTestResult::absoluteImageURL):
     18        (WebCore::HitTestResult::absoluteLinkURL):
     19        (WebCore::HitTestResult::titleDisplayString):
     20        (WebCore::HitTestResult::textContent):
     21        * rendering/HitTestResult.h:
     22
    1232006-10-31  John Sullivan  <sullivan@apple.com>
    224
  • trunk/WebCore/WebCore.exp

    r17504 r17511  
    175175__ZN7WebCore14ResourceLoader14cancelledErrorEv
    176176__ZN7WebCore14ResourceLoader20inConnectionCallbackEv
    177 __ZN7WebCore16DeprecatedStringC1ERKS0_
    178177__ZN7WebCore16DeprecatedString6appendENS_14DeprecatedCharE
    179178__ZN7WebCore16DeprecatedString6appendERKS0_
     
    181180__ZN7WebCore16DeprecatedString7replaceENS_14DeprecatedCharES1_
    182181__ZN7WebCore16DeprecatedStringC1EPKc
     182__ZN7WebCore16DeprecatedStringC1ERKS0_
    183183__ZN7WebCore16DeprecatedStringC1Ev
    184184__ZN7WebCore16DeprecatedStringD1Ev
     
    211211__ZN7WebCore5Frame6indentEv
    212212__ZN7WebCore5Frame7outdentEv
     213__ZN7WebCore5Image10getNSImageEv
    213214__ZN7WebCore5Image21getTIFFRepresentationEv
    214215__ZN7WebCore5RangeC1EPNS_8DocumentEPNS_4NodeEiS4_i
     
    295296__ZNK7WebCore13HitTestResult15spellingToolTipEv
    296297__ZNK7WebCore13HitTestResult11targetFrameEv
     298__ZNK7WebCore13HitTestResult11textContentEv
     299__ZNK7WebCore13HitTestResult15absoluteLinkURLEv
     300__ZNK7WebCore13HitTestResult16absoluteImageURLEv
     301__ZNK7WebCore13HitTestResult16altDisplayStringEv
     302__ZNK7WebCore13HitTestResult18titleDisplayStringEv
     303__ZNK7WebCore13HitTestResult5imageEv
    297304__ZNK7WebCore13HitTestResult5titleEv
    298305__ZNK7WebCore14DocumentLoader10isStoppingEv
  • trunk/WebCore/rendering/HitTestResult.cpp

    r17508 r17511  
    2424#include "HitTestResult.h"
    2525
     26#include "csshelper.h"
    2627#include "Document.h"
    2728#include "Frame.h"
    2829#include "FrameTree.h"
    2930#include "HTMLElement.h"
     31#include "HTMLImageElement.h"
     32#include "HTMLInputElement.h"
     33#include "HTMLNames.h"
     34#include "KURL.h"
    3035#include "PlatformScrollBar.h"
    3136#include "RenderObject.h"
     37#include "RenderImage.h"
    3238#include "SelectionController.h"
    3339
    3440namespace WebCore {
     41
     42using namespace HTMLNames;
    3543
    3644HitTestResult::HitTestResult(const IntPoint& point)
     
    141149    }
    142150    return String();
    143 }
     151}
     152
     153static String displayString(const String& string, const Node* node)
     154{
     155    if (!node)
     156        return string;
     157    Document* document = node->document();
     158    if (!document)
     159        return string;
     160    String copy(string);
     161    copy.replace('\\', document->backslashAsCurrencySymbol());
     162    return copy;
     163}
     164
     165String HitTestResult::altDisplayString() const
     166{
     167    if (!m_innerNonSharedNode)
     168        return String();
     169   
     170    if (m_innerNonSharedNode->hasTagName(imageTag)) {
     171        HTMLImageElement* image = static_cast<HTMLImageElement*>(m_innerNonSharedNode.get());
     172        return displayString(image->alt(), m_innerNonSharedNode.get());
     173    }
     174   
     175    if (m_innerNonSharedNode->hasTagName(inputTag)) {
     176        HTMLInputElement* input = static_cast<HTMLInputElement*>(m_innerNonSharedNode.get());
     177        return displayString(input->alt(), m_innerNonSharedNode.get());
     178    }
     179   
     180    return String();
     181}
     182
     183Image* HitTestResult::image() const
     184{
     185    if (!m_innerNonSharedNode)
     186        return 0;
     187   
     188    RenderObject* renderer = m_innerNonSharedNode->renderer();
     189    if (renderer && renderer->isImage()) {
     190        RenderImage* image = static_cast<WebCore::RenderImage*>(renderer);
     191        if (image->cachedImage() && !image->cachedImage()->isErrorImage())
     192            return image->cachedImage()->image();
     193    }
     194
     195    return 0;
     196}
     197
     198KURL HitTestResult::absoluteImageURL() const
     199{
     200    if (!(m_innerNonSharedNode && m_innerNonSharedNode->document()))
     201        return KURL();
     202
     203    if (!(m_innerNonSharedNode->renderer() && m_innerNonSharedNode->renderer()->isImage()))
     204        return KURL();
     205
     206    String name;
     207    if (m_innerNonSharedNode->hasTagName(imageTag) || m_innerNonSharedNode->hasTagName(inputTag))
     208        name = "src";
     209    else if (m_innerNonSharedNode->hasTagName(objectTag))
     210        name = "data";
     211    else
     212        return KURL();
     213   
     214    return KURL(m_innerNonSharedNode->document()->completeURL(parseURL(
     215        static_cast<Element*>(m_innerNonSharedNode.get())->getAttribute(name)).deprecatedString()));
     216}
     217
     218KURL HitTestResult::absoluteLinkURL() const
     219{
     220    if (!(m_innerURLElement && m_innerURLElement->document()))
     221        return KURL();
     222
     223    if (!(m_innerURLElement->hasTagName(aTag) || m_innerURLElement->hasTagName(areaTag)
     224            || m_innerURLElement->hasTagName(linkTag)))
     225        return KURL();
     226
     227    return KURL(m_innerURLElement->document()->completeURL(parseURL(
     228        static_cast<Element*>(m_innerURLElement.get())->getAttribute("href")).deprecatedString()));
     229}
     230
     231String HitTestResult::titleDisplayString() const
     232{
     233    if (!(m_innerURLElement && m_innerURLElement->isHTMLElement()))
     234        return String();
     235
     236    HTMLElement* element = static_cast<HTMLElement*>(m_innerURLElement.get());
     237    return displayString(element->title(), element);
     238}
     239
     240String HitTestResult::textContent() const
     241{
     242    if (!m_innerURLElement)
     243        return String();
     244    return m_innerURLElement->textContent();
     245}
    144246
    145247} // namespace WebCore
  • trunk/WebCore/rendering/HitTestResult.h

    r17501 r17511  
    3030class Element;
    3131class Frame;
     32class Image;
     33class KURL;
    3234class IntRect;
    3335class Node;
     
    5961    String spellingToolTip() const;
    6062    String title() const;
     63    String altDisplayString() const;
     64    Image* image() const;
     65    KURL absoluteImageURL() const;
     66    KURL absoluteLinkURL() const;
     67    String titleDisplayString() const;
     68    String textContent() const;
    6169
    6270private:
  • trunk/WebKit/ChangeLog

    r17504 r17511  
     12006-10-31  Beth Dakin  <bdakin@apple.com>
     2
     3        Reviewed by Maciej.
     4
     5        This creates local functions for the remaining WebElementDictionary
     6        members that calls into HitTestResult instead of doing magical
     7        things with the Objective-C DOM classes.
     8
     9        * ChangeLog:
     10        * Misc/WebElementDictionary.m:
     11        (addLookupKey): The values of the dictionary are now just
     12        selectors. They used to be WebElementMethods which were
     13        WebElementTargetObjects associated with selectors, but none of that
     14        is needed any more.
     15        (+[WebElementDictionary initializeLookupTable]): All selectors are
     16        now local functions, no more WebElementTargetObjects.
     17        (-[WebElementDictionary objectForKey:]): No more target objects!
     18        (-[WebElementDictionary _domNode]): Call into HitTestResult member
     19        variable.
     20        (-[WebElementDictionary _altDisplayString]): Same.
     21        (-[WebElementDictionary _image]): Same.
     22        (-[WebElementDictionary _absoluteImageURL]): Same.
     23        (-[WebElementDictionary _title]): Same.
     24        (-[WebElementDictionary _absoluteLinkURL]): Same.
     25        (-[WebElementDictionary _targetWebFrame]): Same.
     26        (-[WebElementDictionary _titleDisplayString]): Same.
     27        (-[WebElementDictionary _textContent]): Same.
     28
    1292006-10-31  Geoffrey Garen  <ggaren@apple.com>
    230
  • trunk/WebKit/Misc/WebElementDictionary.m

    r17501 r17511  
    4040#import <WebCore/FrameMac.h>
    4141#import <WebCore/HitTestResult.h>
     42#import <WebCore/Image.h>
     43#import <WebCore/KURL.h>
    4244
    4345using namespace WebCore;
    4446
    45 typedef enum {
    46     WebElementSelf,
    47     WebElementInnerNode,
    48     WebElementInnerNonSharedNode,
    49     WebElementURLElement
    50 } WebElementTargetObject;
    51 
    52 typedef struct WebElementMethod {
    53     WebElementTargetObject target;
    54     SEL selector;
    55 } WebElementMethod;
    56 
    5747static CFMutableDictionaryRef lookupTable = NULL;
    5848
    59 static void addLookupKey(NSString *key, SEL selector, WebElementTargetObject target)
    60 {
    61     WebElementMethod* elementMethod = static_cast<WebElementMethod*>(malloc(sizeof(WebElementMethod)));
    62     elementMethod->target = target;
    63     elementMethod->selector = selector;
    64     CFDictionaryAddValue(lookupTable, key, elementMethod);
     49static void addLookupKey(NSString *key, SEL selector)
     50{
     51    CFDictionaryAddValue(lookupTable, key, selector);
    6552}
    6653
     
    7966    lookupTable = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFCopyStringDictionaryKeyCallBacks, NULL);
    8067
    81     addLookupKey(WebElementDOMNodeKey, @selector(_domNode), WebElementSelf);
    82     addLookupKey(WebElementFrameKey, @selector(_webFrame), WebElementSelf);
    83     addLookupKey(WebElementImageAltStringKey, @selector(altDisplayString), WebElementInnerNonSharedNode);
    84     addLookupKey(WebElementImageKey, @selector(image), WebElementInnerNonSharedNode);
    85     addLookupKey(WebElementImageRectKey, @selector(_imageRect), WebElementSelf);
    86     addLookupKey(WebElementImageURLKey, @selector(absoluteImageURL), WebElementInnerNonSharedNode);
    87     addLookupKey(WebElementIsSelectedKey, @selector(_isSelected), WebElementSelf);
    88     addLookupKey(WebElementSpellingToolTipKey, @selector(_spellingToolTip), WebElementSelf);
    89     addLookupKey(WebElementTitleKey, @selector(_title), WebElementSelf);
    90     addLookupKey(WebElementLinkURLKey, @selector(absoluteLinkURL), WebElementURLElement);
    91     addLookupKey(WebElementLinkTargetFrameKey, @selector(_targetWebFrame), WebElementSelf);
    92     addLookupKey(WebElementLinkTitleKey, @selector(titleDisplayString), WebElementURLElement);
    93     addLookupKey(WebElementLinkLabelKey, @selector(textContent), WebElementURLElement);
     68    addLookupKey(WebElementDOMNodeKey, @selector(_domNode));
     69    addLookupKey(WebElementFrameKey, @selector(_webFrame));
     70    addLookupKey(WebElementImageAltStringKey, @selector(_altDisplayString));
     71    addLookupKey(WebElementImageKey, @selector(_image));
     72    addLookupKey(WebElementImageRectKey, @selector(_imageRect));
     73    addLookupKey(WebElementImageURLKey, @selector(_absoluteImageURL));
     74    addLookupKey(WebElementIsSelectedKey, @selector(_isSelected));
     75    addLookupKey(WebElementSpellingToolTipKey, @selector(_spellingToolTip));
     76    addLookupKey(WebElementTitleKey, @selector(_title));
     77    addLookupKey(WebElementLinkURLKey, @selector(_absoluteLinkURL));
     78    addLookupKey(WebElementLinkTargetFrameKey, @selector(_targetWebFrame));
     79    addLookupKey(WebElementLinkTitleKey, @selector(_titleDisplayString));
     80    addLookupKey(WebElementLinkLabelKey, @selector(_textContent));
    9481}
    9582
     
    136123}
    137124
    138 - (DOMNode *)_domNode
    139 {
    140     return kit(_result->innerNonSharedNode());
    141 }
    142 
    143125- (id)objectForKey:(id)key
    144126{
     
    147129        return value;
    148130
    149     WebElementMethod *elementMethod = (WebElementMethod *)CFDictionaryGetValue(lookupTable, key);
    150     if (!elementMethod)
     131    SEL selector = (SEL)CFDictionaryGetValue(lookupTable, key);
     132    if (!selector)
    151133        return nil;
    152 
    153     id target = nil;
    154     switch (elementMethod->target) {
    155         case WebElementSelf:
    156             target = self;
    157             break;
    158         case WebElementInnerNonSharedNode:
    159             target = [self _domNode];
    160             break;
    161         case WebElementInnerNode:
    162             target = kit(_result->innerNode());
    163             break;
    164         case WebElementURLElement:
    165             target = kit(_result->URLElement());
    166             break;
    167     }
    168 
    169     if (target && [target respondsToSelector:elementMethod->selector])
    170         value = [target performSelector:elementMethod->selector];
     134    value = [self performSelector:selector];
    171135
    172136    unsigned lookupTableCount = CFDictionaryGetCount(lookupTable);
    173 
    174137    if (value) {
    175138        if (!_cache)
     
    187150}
    188151
     152- (DOMNode *)_domNode
     153{
     154    return kit(_result->innerNonSharedNode());
     155}
     156
    189157- (WebFrame *)_webFrame
    190158{
     
    192160}
    193161
    194 - (WebFrame *)_targetWebFrame
    195 {
    196     FrameMac* webCoreFrame = Mac(_result->targetFrame());
    197     return kit(webCoreFrame);
     162- (NSString *)_altDisplayString
     163{
     164    return _result->altDisplayString();
    198165}
    199166
     
    203170}
    204171
    205 - (NSString *)_title
    206 {
    207     return _result->title();
     172- (NSImage *)_image
     173{
     174    return _result->image()->getNSImage();
    208175}
    209176
     
    215182}
    216183
     184- (NSURL *)_absoluteImageURL
     185{
     186    return _result->absoluteImageURL().getNSURL();
     187}
     188
    217189- (NSNumber *)_isSelected
    218190{
    219191    return [NSNumber numberWithBool:_result->isSelected()];
    220192}
     193
     194- (NSString *)_title
     195{
     196    return _result->title();
     197}
     198
     199- (NSURL *)_absoluteLinkURL
     200{
     201    return _result->absoluteLinkURL().getNSURL();
     202}
     203
     204- (WebFrame *)_targetWebFrame
     205{
     206    FrameMac* webCoreFrame = Mac(_result->targetFrame());
     207    return kit(webCoreFrame);
     208}
     209
     210- (NSString *)_titleDisplayString
     211{
     212    return _result->titleDisplayString();
     213}
     214
     215- (NSString *)_textContent
     216{
     217    return _result->textContent();
     218}
     219
    221220@end
Note: See TracChangeset for help on using the changeset viewer.