1/* 2 * Copyright (C) 2012 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#if defined(__LP64__) && defined(__clang__) 27 28#import "WKDOMNode.h" 29#import "WKDOMRange.h" 30#import <WebCore/Node.h> 31#import <WebCore/Range.h> 32#import <wtf/HashMap.h> 33 34namespace WebCore { 35class Element; 36class Document; 37} 38 39@class WKDOMElement; 40@class WKDOMDocument; 41@class WKDOMText; 42 43@interface WKDOMNode () { 44@public 45 RefPtr<WebCore::Node> _impl; 46} 47 48- (id)_initWithImpl:(WebCore::Node*)impl; 49@end 50 51@interface WKDOMRange () { 52@public 53 RefPtr<WebCore::Range> _impl; 54} 55 56- (id)_initWithImpl:(WebCore::Range*)impl; 57@end 58 59namespace WebKit { 60 61template<typename WebCoreType, typename WKDOMType> 62class DOMCache { 63public: 64 DOMCache() 65 { 66 } 67 68 void add(WebCoreType core, WKDOMType kit) 69 { 70 m_map.add(core, kit); 71 } 72 73 WKDOMType get(WebCoreType core) 74 { 75 return m_map.get(core); 76 } 77 78 void remove(WebCoreType core) 79 { 80 m_map.remove(core); 81 } 82 83private: 84 // This class should only ever be used as a singleton. 85 ~DOMCache() = delete; 86 87 HashMap<WebCoreType, WKDOMType> m_map; 88}; 89 90// -- Caches -- 91 92DOMCache<WebCore::Node*, WKDOMNode *>& WKDOMNodeCache(); 93DOMCache<WebCore::Range*, WKDOMRange *>& WKDOMRangeCache(); 94 95// -- Node and classes derived from Node. -- 96 97WebCore::Node* toWebCoreNode(WKDOMNode *); 98WKDOMNode *toWKDOMNode(WebCore::Node*); 99 100WebCore::Element* toWebCoreElement(WKDOMElement *); 101WKDOMElement *toWKDOMElement(WebCore::Element*); 102 103WebCore::Document* toWebCoreDocument(WKDOMDocument *); 104WKDOMDocument *toWKDOMDocument(WebCore::Document*); 105 106WebCore::Text* toWebCoreText(WKDOMText *); 107WKDOMText *toWKDOMText(WebCore::Text*); 108 109// -- Range. -- 110 111WebCore::Range* toWebCoreRange(WKDOMRange *); 112WKDOMRange *toWKDOMRange(WebCore::Range*); 113 114// -- Helpers -- 115 116NSArray *toNSArray(const Vector<WebCore::IntRect>&); 117 118} // namespace WebKit 119 120#endif // defined(__LP64__) && defined(__clang__) 121