1/* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "config.h" 27#include "InjectedBundleHitTestResult.h" 28 29#include "InjectedBundleNodeHandle.h" 30#include "WebFrame.h" 31#include "WebFrameLoaderClient.h" 32#include <WebCore/Document.h> 33#include <WebCore/Frame.h> 34#include <WebCore/FrameLoader.h> 35#include <WebCore/KURL.h> 36#include <wtf/text/WTFString.h> 37 38using namespace WebCore; 39 40namespace WebKit { 41 42PassRefPtr<InjectedBundleHitTestResult> InjectedBundleHitTestResult::create(const WebCore::HitTestResult& hitTestResult) 43{ 44 return adoptRef(new InjectedBundleHitTestResult(hitTestResult)); 45} 46 47PassRefPtr<InjectedBundleNodeHandle> InjectedBundleHitTestResult::nodeHandle() const 48{ 49 return InjectedBundleNodeHandle::getOrCreate(m_hitTestResult.innerNonSharedNode()); 50} 51 52WebFrame* InjectedBundleHitTestResult::frame() const 53{ 54 Node* node = m_hitTestResult.innerNonSharedNode(); 55 if (!node) 56 return 0; 57 58 Document* document = node->document(); 59 if (!document) 60 return 0; 61 62 Frame* frame = document->frame(); 63 if (!frame) 64 return 0; 65 66 return static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame(); 67} 68 69WebFrame* InjectedBundleHitTestResult::targetFrame() const 70{ 71 Frame* frame = m_hitTestResult.targetFrame(); 72 if (!frame) 73 return 0; 74 75 return static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame(); 76} 77 78String InjectedBundleHitTestResult::absoluteImageURL() const 79{ 80 return m_hitTestResult.absoluteImageURL().string(); 81} 82 83String InjectedBundleHitTestResult::absoluteLinkURL() const 84{ 85 return m_hitTestResult.absoluteLinkURL().string(); 86} 87 88String InjectedBundleHitTestResult::absoluteMediaURL() const 89{ 90 return m_hitTestResult.absoluteMediaURL().string(); 91} 92 93String InjectedBundleHitTestResult::linkLabel() const 94{ 95 return m_hitTestResult.textContent(); 96} 97 98String InjectedBundleHitTestResult::linkTitle() const 99{ 100 return m_hitTestResult.titleDisplayString(); 101} 102 103WebCore::IntRect InjectedBundleHitTestResult::imageRect() const 104{ 105 return m_hitTestResult.imageRect(); 106} 107 108bool InjectedBundleHitTestResult::isSelected() const 109{ 110 return m_hitTestResult.isSelected(); 111} 112 113} // WebKit 114