Changeset 17511 in webkit
- Timestamp:
- Oct 31, 2006, 7:22:12 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r17509 r17511 1 2006-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 1 23 2006-10-31 John Sullivan <sullivan@apple.com> 2 24 -
trunk/WebCore/WebCore.exp
r17504 r17511 175 175 __ZN7WebCore14ResourceLoader14cancelledErrorEv 176 176 __ZN7WebCore14ResourceLoader20inConnectionCallbackEv 177 __ZN7WebCore16DeprecatedStringC1ERKS0_178 177 __ZN7WebCore16DeprecatedString6appendENS_14DeprecatedCharE 179 178 __ZN7WebCore16DeprecatedString6appendERKS0_ … … 181 180 __ZN7WebCore16DeprecatedString7replaceENS_14DeprecatedCharES1_ 182 181 __ZN7WebCore16DeprecatedStringC1EPKc 182 __ZN7WebCore16DeprecatedStringC1ERKS0_ 183 183 __ZN7WebCore16DeprecatedStringC1Ev 184 184 __ZN7WebCore16DeprecatedStringD1Ev … … 211 211 __ZN7WebCore5Frame6indentEv 212 212 __ZN7WebCore5Frame7outdentEv 213 __ZN7WebCore5Image10getNSImageEv 213 214 __ZN7WebCore5Image21getTIFFRepresentationEv 214 215 __ZN7WebCore5RangeC1EPNS_8DocumentEPNS_4NodeEiS4_i … … 295 296 __ZNK7WebCore13HitTestResult15spellingToolTipEv 296 297 __ZNK7WebCore13HitTestResult11targetFrameEv 298 __ZNK7WebCore13HitTestResult11textContentEv 299 __ZNK7WebCore13HitTestResult15absoluteLinkURLEv 300 __ZNK7WebCore13HitTestResult16absoluteImageURLEv 301 __ZNK7WebCore13HitTestResult16altDisplayStringEv 302 __ZNK7WebCore13HitTestResult18titleDisplayStringEv 303 __ZNK7WebCore13HitTestResult5imageEv 297 304 __ZNK7WebCore13HitTestResult5titleEv 298 305 __ZNK7WebCore14DocumentLoader10isStoppingEv -
trunk/WebCore/rendering/HitTestResult.cpp
r17508 r17511 24 24 #include "HitTestResult.h" 25 25 26 #include "csshelper.h" 26 27 #include "Document.h" 27 28 #include "Frame.h" 28 29 #include "FrameTree.h" 29 30 #include "HTMLElement.h" 31 #include "HTMLImageElement.h" 32 #include "HTMLInputElement.h" 33 #include "HTMLNames.h" 34 #include "KURL.h" 30 35 #include "PlatformScrollBar.h" 31 36 #include "RenderObject.h" 37 #include "RenderImage.h" 32 38 #include "SelectionController.h" 33 39 34 40 namespace WebCore { 41 42 using namespace HTMLNames; 35 43 36 44 HitTestResult::HitTestResult(const IntPoint& point) … … 141 149 } 142 150 return String(); 143 } 151 } 152 153 static 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 165 String 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 183 Image* 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 198 KURL 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 218 KURL 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 231 String 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 240 String HitTestResult::textContent() const 241 { 242 if (!m_innerURLElement) 243 return String(); 244 return m_innerURLElement->textContent(); 245 } 144 246 145 247 } // namespace WebCore -
trunk/WebCore/rendering/HitTestResult.h
r17501 r17511 30 30 class Element; 31 31 class Frame; 32 class Image; 33 class KURL; 32 34 class IntRect; 33 35 class Node; … … 59 61 String spellingToolTip() const; 60 62 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; 61 69 62 70 private: -
trunk/WebKit/ChangeLog
r17504 r17511 1 2006-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 1 29 2006-10-31 Geoffrey Garen <ggaren@apple.com> 2 30 -
trunk/WebKit/Misc/WebElementDictionary.m
r17501 r17511 40 40 #import <WebCore/FrameMac.h> 41 41 #import <WebCore/HitTestResult.h> 42 #import <WebCore/Image.h> 43 #import <WebCore/KURL.h> 42 44 43 45 using namespace WebCore; 44 46 45 typedef enum {46 WebElementSelf,47 WebElementInnerNode,48 WebElementInnerNonSharedNode,49 WebElementURLElement50 } WebElementTargetObject;51 52 typedef struct WebElementMethod {53 WebElementTargetObject target;54 SEL selector;55 } WebElementMethod;56 57 47 static CFMutableDictionaryRef lookupTable = NULL; 58 48 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); 49 static void addLookupKey(NSString *key, SEL selector) 50 { 51 CFDictionaryAddValue(lookupTable, key, selector); 65 52 } 66 53 … … 79 66 lookupTable = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFCopyStringDictionaryKeyCallBacks, NULL); 80 67 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)); 94 81 } 95 82 … … 136 123 } 137 124 138 - (DOMNode *)_domNode139 {140 return kit(_result->innerNonSharedNode());141 }142 143 125 - (id)objectForKey:(id)key 144 126 { … … 147 129 return value; 148 130 149 WebElementMethod *elementMethod = (WebElementMethod *)CFDictionaryGetValue(lookupTable, key);150 if (! elementMethod)131 SEL selector = (SEL)CFDictionaryGetValue(lookupTable, key); 132 if (!selector) 151 133 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]; 171 135 172 136 unsigned lookupTableCount = CFDictionaryGetCount(lookupTable); 173 174 137 if (value) { 175 138 if (!_cache) … … 187 150 } 188 151 152 - (DOMNode *)_domNode 153 { 154 return kit(_result->innerNonSharedNode()); 155 } 156 189 157 - (WebFrame *)_webFrame 190 158 { … … 192 160 } 193 161 194 - (WebFrame *)_targetWebFrame 195 { 196 FrameMac* webCoreFrame = Mac(_result->targetFrame()); 197 return kit(webCoreFrame); 162 - (NSString *)_altDisplayString 163 { 164 return _result->altDisplayString(); 198 165 } 199 166 … … 203 170 } 204 171 205 - (NS String *)_title206 { 207 return _result-> title();172 - (NSImage *)_image 173 { 174 return _result->image()->getNSImage(); 208 175 } 209 176 … … 215 182 } 216 183 184 - (NSURL *)_absoluteImageURL 185 { 186 return _result->absoluteImageURL().getNSURL(); 187 } 188 217 189 - (NSNumber *)_isSelected 218 190 { 219 191 return [NSNumber numberWithBool:_result->isSelected()]; 220 192 } 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 221 220 @end
Note:
See TracChangeset
for help on using the changeset viewer.