• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef WKSharedAPICast_h
27 #define WKSharedAPICast_h
28 
29 #include "ImageOptions.h"
30 #include "SameDocumentNavigationType.h"
31 #include "WKBase.h"
32 #include "WKContextMenuItemTypes.h"
33 #include "WKEvent.h"
34 #include "WKFindOptions.h"
35 #include "WKGeometry.h"
36 #include "WKImage.h"
37 #include "WKPageLoadTypes.h"
38 #include "WebError.h"
39 #include "WebEvent.h"
40 #include "WebFindOptions.h"
41 #include "WebNumber.h"
42 #include "WebString.h"
43 #include "WebURL.h"
44 #include "WebURLRequest.h"
45 #include "WebURLResponse.h"
46 #include <WebCore/ContextMenuItem.h>
47 #include <WebCore/FloatRect.h>
48 #include <WebCore/FrameLoaderTypes.h>
49 #include <WebCore/IntRect.h>
50 #include <wtf/TypeTraits.h>
51 
52 namespace WebKit {
53 
54 class ImmutableArray;
55 class ImmutableDictionary;
56 class MutableArray;
57 class MutableDictionary;
58 class WebCertificateInfo;
59 class WebContextMenuItem;
60 class WebData;
61 class WebGraphicsContext;
62 class WebImage;
63 class WebSecurityOrigin;
64 class WebSerializedScriptValue;
65 class WebURLRequest;
66 class WebURLResponse;
67 class WebUserContentURLPattern;
68 
69 template<typename APIType> struct APITypeInfo { };
70 template<typename ImplType> struct ImplTypeInfo { };
71 
72 #define WK_ADD_API_MAPPING(TheAPIType, TheImplType) \
73     template<> struct APITypeInfo<TheAPIType> { typedef TheImplType* ImplType; }; \
74     template<> struct ImplTypeInfo<TheImplType*> { typedef TheAPIType APIType; };
75 
WK_ADD_API_MAPPING(WKArrayRef,ImmutableArray)76 WK_ADD_API_MAPPING(WKArrayRef, ImmutableArray)
77 WK_ADD_API_MAPPING(WKBooleanRef, WebBoolean)
78 WK_ADD_API_MAPPING(WKCertificateInfoRef, WebCertificateInfo)
79 WK_ADD_API_MAPPING(WKContextMenuItemRef, WebContextMenuItem)
80 WK_ADD_API_MAPPING(WKDataRef, WebData)
81 WK_ADD_API_MAPPING(WKDictionaryRef, ImmutableDictionary)
82 WK_ADD_API_MAPPING(WKDoubleRef, WebDouble)
83 WK_ADD_API_MAPPING(WKErrorRef, WebError)
84 WK_ADD_API_MAPPING(WKGraphicsContextRef, WebGraphicsContext)
85 WK_ADD_API_MAPPING(WKImageRef, WebImage)
86 WK_ADD_API_MAPPING(WKMutableArrayRef, MutableArray)
87 WK_ADD_API_MAPPING(WKMutableDictionaryRef, MutableDictionary)
88 WK_ADD_API_MAPPING(WKSecurityOriginRef, WebSecurityOrigin)
89 WK_ADD_API_MAPPING(WKSerializedScriptValueRef, WebSerializedScriptValue)
90 WK_ADD_API_MAPPING(WKStringRef, WebString)
91 WK_ADD_API_MAPPING(WKTypeRef, APIObject)
92 WK_ADD_API_MAPPING(WKUInt64Ref, WebUInt64)
93 WK_ADD_API_MAPPING(WKURLRef, WebURL)
94 WK_ADD_API_MAPPING(WKURLRequestRef, WebURLRequest)
95 WK_ADD_API_MAPPING(WKURLResponseRef, WebURLResponse)
96 WK_ADD_API_MAPPING(WKUserContentURLPatternRef, WebUserContentURLPattern)
97 
98 template<typename ImplType, typename APIType = typename ImplTypeInfo<ImplType*>::APIType>
99 class ProxyingRefPtr {
100 public:
101     ProxyingRefPtr(PassRefPtr<ImplType> impl)
102         : m_impl(impl)
103     {
104     }
105 
106     operator APIType() { return toAPI(m_impl.get()); }
107 
108 private:
109     RefPtr<ImplType> m_impl;
110 };
111 
112 /* Opaque typing convenience methods */
113 
114 template<typename T>
toImpl(T t)115 inline typename APITypeInfo<T>::ImplType toImpl(T t)
116 {
117     // An example of the conversions that take place:
118     // const struct OpaqueWKArray* -> const struct OpaqueWKArray -> struct OpaqueWKArray -> struct OpaqueWKArray* -> ImmutableArray*
119 
120     typedef typename WTF::RemovePointer<T>::Type PotentiallyConstValueType;
121     typedef typename WTF::RemoveConst<PotentiallyConstValueType>::Type NonConstValueType;
122 
123     return reinterpret_cast<typename APITypeInfo<T>::ImplType>(const_cast<NonConstValueType*>(t));
124 }
125 
126 template<typename T>
toAPI(T t)127 inline typename ImplTypeInfo<T>::APIType toAPI(T t)
128 {
129     return reinterpret_cast<typename ImplTypeInfo<T>::APIType>(t);
130 }
131 
132 /* Special cases. */
133 
toAPI(StringImpl * string)134 inline ProxyingRefPtr<WebString> toAPI(StringImpl* string)
135 {
136     return ProxyingRefPtr<WebString>(WebString::create(string));
137 }
138 
toCopiedAPI(const String & string)139 inline WKStringRef toCopiedAPI(const String& string)
140 {
141     RefPtr<WebString> webString = WebString::create(string);
142     return toAPI(webString.release().releaseRef());
143 }
144 
toURLRef(StringImpl * string)145 inline ProxyingRefPtr<WebURL> toURLRef(StringImpl* string)
146 {
147     if (!string)
148         ProxyingRefPtr<WebURL>(0);
149     return ProxyingRefPtr<WebURL>(WebURL::create(String(string)));
150 }
151 
toCopiedURLAPI(const String & string)152 inline WKURLRef toCopiedURLAPI(const String& string)
153 {
154     if (!string)
155         return 0;
156     RefPtr<WebURL> webURL = WebURL::create(string);
157     return toAPI(webURL.release().releaseRef());
158 }
159 
toWTFString(WKStringRef stringRef)160 inline String toWTFString(WKStringRef stringRef)
161 {
162     if (!stringRef)
163         return String();
164     return toImpl(stringRef)->string();
165 }
166 
toWTFString(WKURLRef urlRef)167 inline String toWTFString(WKURLRef urlRef)
168 {
169     if (!urlRef)
170         return String();
171     return toImpl(urlRef)->string();
172 }
173 
toAPI(const WebCore::ResourceError & error)174 inline ProxyingRefPtr<WebError> toAPI(const WebCore::ResourceError& error)
175 {
176     return ProxyingRefPtr<WebError>(WebError::create(error));
177 }
178 
toAPI(const WebCore::ResourceRequest & request)179 inline ProxyingRefPtr<WebURLRequest> toAPI(const WebCore::ResourceRequest& request)
180 {
181     return ProxyingRefPtr<WebURLRequest>(WebURLRequest::create(request));
182 }
183 
toAPI(const WebCore::ResourceResponse & response)184 inline ProxyingRefPtr<WebURLResponse> toAPI(const WebCore::ResourceResponse& response)
185 {
186     return ProxyingRefPtr<WebURLResponse>(WebURLResponse::create(response));
187 }
188 
189 /* Geometry conversions */
190 
toFloatRect(const WKRect & wkRect)191 inline WebCore::FloatRect toFloatRect(const WKRect& wkRect)
192 {
193     return WebCore::FloatRect(static_cast<float>(wkRect.origin.x), static_cast<float>(wkRect.origin.y),
194                               static_cast<float>(wkRect.size.width), static_cast<float>(wkRect.size.height));
195 }
196 
toIntSize(const WKSize & wkSize)197 inline WebCore::IntSize toIntSize(const WKSize& wkSize)
198 {
199     return WebCore::IntSize(static_cast<int>(wkSize.width), static_cast<int>(wkSize.height));
200 }
201 
toIntPoint(const WKPoint & wkPoint)202 inline WebCore::IntPoint toIntPoint(const WKPoint& wkPoint)
203 {
204     return WebCore::IntPoint(static_cast<int>(wkPoint.x), static_cast<int>(wkPoint.y));
205 }
206 
toIntRect(const WKRect & wkRect)207 inline WebCore::IntRect toIntRect(const WKRect& wkRect)
208 {
209     return WebCore::IntRect(static_cast<int>(wkRect.origin.x), static_cast<int>(wkRect.origin.y),
210                             static_cast<int>(wkRect.size.width), static_cast<int>(wkRect.size.height));
211 }
212 
toAPI(const WebCore::FloatRect & rect)213 inline WKRect toAPI(const WebCore::FloatRect& rect)
214 {
215     WKRect wkRect;
216     wkRect.origin.x = rect.x();
217     wkRect.origin.y = rect.y();
218     wkRect.size.width = rect.width();
219     wkRect.size.height = rect.height();
220     return wkRect;
221 }
222 
toAPI(const WebCore::IntRect & rect)223 inline WKRect toAPI(const WebCore::IntRect& rect)
224 {
225     WKRect wkRect;
226     wkRect.origin.x = rect.x();
227     wkRect.origin.y = rect.y();
228     wkRect.size.width = rect.width();
229     wkRect.size.height = rect.height();
230     return wkRect;
231 }
232 
toAPI(const WebCore::IntSize & size)233 inline WKSize toAPI(const WebCore::IntSize& size)
234 {
235     WKSize wkSize;
236     wkSize.width = size.width();
237     wkSize.height = size.height();
238     return wkSize;
239 }
240 
toAPI(const WebCore::IntPoint & point)241 inline WKPoint toAPI(const WebCore::IntPoint& point)
242 {
243     WKPoint wkPoint;
244     wkPoint.x = point.x();
245     wkPoint.y = point.y();
246     return wkPoint;
247 }
248 
249 /* Enum conversions */
250 
toAPI(APIObject::Type type)251 inline WKTypeID toAPI(APIObject::Type type)
252 {
253     return static_cast<WKTypeID>(type);
254 }
255 
toAPI(WebEvent::Modifiers modifiers)256 inline WKEventModifiers toAPI(WebEvent::Modifiers modifiers)
257 {
258     WKEventModifiers wkModifiers = 0;
259     if (modifiers & WebEvent::ShiftKey)
260         wkModifiers |= kWKEventModifiersShiftKey;
261     if (modifiers & WebEvent::ControlKey)
262         wkModifiers |= kWKEventModifiersControlKey;
263     if (modifiers & WebEvent::AltKey)
264         wkModifiers |= kWKEventModifiersAltKey;
265     if (modifiers & WebEvent::MetaKey)
266         wkModifiers |= kWKEventModifiersMetaKey;
267     return wkModifiers;
268 }
269 
toAPI(WebMouseEvent::Button mouseButton)270 inline WKEventMouseButton toAPI(WebMouseEvent::Button mouseButton)
271 {
272     WKEventMouseButton wkMouseButton = kWKEventMouseButtonNoButton;
273 
274     switch (mouseButton) {
275     case WebMouseEvent::NoButton:
276         wkMouseButton = kWKEventMouseButtonNoButton;
277         break;
278     case WebMouseEvent::LeftButton:
279         wkMouseButton = kWKEventMouseButtonLeftButton;
280         break;
281     case WebMouseEvent::MiddleButton:
282         wkMouseButton = kWKEventMouseButtonMiddleButton;
283         break;
284     case WebMouseEvent::RightButton:
285         wkMouseButton = kWKEventMouseButtonRightButton;
286         break;
287     }
288 
289     return wkMouseButton;
290 }
291 
toAPI(WebCore::ContextMenuAction action)292 inline WKContextMenuItemTag toAPI(WebCore::ContextMenuAction action)
293 {
294     switch (action) {
295     case WebCore::ContextMenuItemTagNoAction:
296         return kWKContextMenuItemTagNoAction;
297     case WebCore::ContextMenuItemTagOpenLinkInNewWindow:
298         return kWKContextMenuItemTagOpenLinkInNewWindow;
299     case WebCore::ContextMenuItemTagDownloadLinkToDisk:
300         return kWKContextMenuItemTagDownloadLinkToDisk;
301     case WebCore::ContextMenuItemTagCopyLinkToClipboard:
302         return kWKContextMenuItemTagCopyLinkToClipboard;
303     case WebCore::ContextMenuItemTagOpenImageInNewWindow:
304         return kWKContextMenuItemTagOpenImageInNewWindow;
305     case WebCore::ContextMenuItemTagDownloadImageToDisk:
306         return kWKContextMenuItemTagDownloadImageToDisk;
307     case WebCore::ContextMenuItemTagCopyImageToClipboard:
308         return kWKContextMenuItemTagCopyImageToClipboard;
309     case WebCore::ContextMenuItemTagOpenFrameInNewWindow:
310         return kWKContextMenuItemTagOpenFrameInNewWindow;
311     case WebCore::ContextMenuItemTagCopy:
312         return kWKContextMenuItemTagCopy;
313     case WebCore::ContextMenuItemTagGoBack:
314         return kWKContextMenuItemTagGoBack;
315     case WebCore::ContextMenuItemTagGoForward:
316         return kWKContextMenuItemTagGoForward;
317     case WebCore::ContextMenuItemTagStop:
318         return kWKContextMenuItemTagStop;
319     case WebCore::ContextMenuItemTagReload:
320         return kWKContextMenuItemTagReload;
321     case WebCore::ContextMenuItemTagCut:
322         return kWKContextMenuItemTagCut;
323     case WebCore::ContextMenuItemTagPaste:
324         return kWKContextMenuItemTagPaste;
325     case WebCore::ContextMenuItemTagSpellingGuess:
326         return kWKContextMenuItemTagSpellingGuess;
327     case WebCore::ContextMenuItemTagNoGuessesFound:
328         return kWKContextMenuItemTagNoGuessesFound;
329     case WebCore::ContextMenuItemTagIgnoreSpelling:
330         return kWKContextMenuItemTagIgnoreSpelling;
331     case WebCore::ContextMenuItemTagLearnSpelling:
332         return kWKContextMenuItemTagLearnSpelling;
333     case WebCore::ContextMenuItemTagOther:
334         return kWKContextMenuItemTagOther;
335     case WebCore::ContextMenuItemTagSearchInSpotlight:
336         return kWKContextMenuItemTagSearchInSpotlight;
337     case WebCore::ContextMenuItemTagSearchWeb:
338         return kWKContextMenuItemTagSearchWeb;
339     case WebCore::ContextMenuItemTagLookUpInDictionary:
340         return kWKContextMenuItemTagLookUpInDictionary;
341     case WebCore::ContextMenuItemTagOpenWithDefaultApplication:
342         return kWKContextMenuItemTagOpenWithDefaultApplication;
343     case WebCore::ContextMenuItemPDFActualSize:
344         return kWKContextMenuItemTagPDFActualSize;
345     case WebCore::ContextMenuItemPDFZoomIn:
346         return kWKContextMenuItemTagPDFZoomIn;
347     case WebCore::ContextMenuItemPDFZoomOut:
348         return kWKContextMenuItemTagPDFZoomOut;
349     case WebCore::ContextMenuItemPDFAutoSize:
350         return kWKContextMenuItemTagPDFAutoSize;
351     case WebCore::ContextMenuItemPDFSinglePage:
352         return kWKContextMenuItemTagPDFSinglePage;
353     case WebCore::ContextMenuItemPDFFacingPages:
354         return kWKContextMenuItemTagPDFFacingPages;
355     case WebCore::ContextMenuItemPDFContinuous:
356         return kWKContextMenuItemTagPDFContinuous;
357     case WebCore::ContextMenuItemPDFNextPage:
358         return kWKContextMenuItemTagPDFNextPage;
359     case WebCore::ContextMenuItemPDFPreviousPage:
360         return kWKContextMenuItemTagPDFPreviousPage;
361     case WebCore::ContextMenuItemTagOpenLink:
362         return kWKContextMenuItemTagOpenLink;
363     case WebCore::ContextMenuItemTagIgnoreGrammar:
364         return kWKContextMenuItemTagIgnoreGrammar;
365     case WebCore::ContextMenuItemTagSpellingMenu:
366         return kWKContextMenuItemTagSpellingMenu;
367     case WebCore::ContextMenuItemTagShowSpellingPanel:
368         return kWKContextMenuItemTagShowSpellingPanel;
369     case WebCore::ContextMenuItemTagCheckSpelling:
370         return kWKContextMenuItemTagCheckSpelling;
371     case WebCore::ContextMenuItemTagCheckSpellingWhileTyping:
372         return kWKContextMenuItemTagCheckSpellingWhileTyping;
373     case WebCore::ContextMenuItemTagCheckGrammarWithSpelling:
374         return kWKContextMenuItemTagCheckGrammarWithSpelling;
375     case WebCore::ContextMenuItemTagFontMenu:
376         return kWKContextMenuItemTagFontMenu;
377     case WebCore::ContextMenuItemTagShowFonts:
378         return kWKContextMenuItemTagShowFonts;
379     case WebCore::ContextMenuItemTagBold:
380         return kWKContextMenuItemTagBold;
381     case WebCore::ContextMenuItemTagItalic:
382         return kWKContextMenuItemTagItalic;
383     case WebCore::ContextMenuItemTagUnderline:
384         return kWKContextMenuItemTagUnderline;
385     case WebCore::ContextMenuItemTagOutline:
386         return kWKContextMenuItemTagOutline;
387     case WebCore::ContextMenuItemTagStyles:
388         return kWKContextMenuItemTagStyles;
389     case WebCore::ContextMenuItemTagShowColors:
390         return kWKContextMenuItemTagShowColors;
391     case WebCore::ContextMenuItemTagSpeechMenu:
392         return kWKContextMenuItemTagSpeechMenu;
393     case WebCore::ContextMenuItemTagStartSpeaking:
394         return kWKContextMenuItemTagStartSpeaking;
395     case WebCore::ContextMenuItemTagStopSpeaking:
396         return kWKContextMenuItemTagStopSpeaking;
397     case WebCore::ContextMenuItemTagWritingDirectionMenu:
398         return kWKContextMenuItemTagWritingDirectionMenu;
399     case WebCore::ContextMenuItemTagDefaultDirection:
400         return kWKContextMenuItemTagDefaultDirection;
401     case WebCore::ContextMenuItemTagLeftToRight:
402         return kWKContextMenuItemTagLeftToRight;
403     case WebCore::ContextMenuItemTagRightToLeft:
404         return kWKContextMenuItemTagRightToLeft;
405     case WebCore::ContextMenuItemTagPDFSinglePageScrolling:
406         return kWKContextMenuItemTagPDFSinglePageScrolling;
407     case WebCore::ContextMenuItemTagPDFFacingPagesScrolling:
408         return kWKContextMenuItemTagPDFFacingPagesScrolling;
409 #if ENABLE(INSPECTOR)
410     case WebCore::ContextMenuItemTagInspectElement:
411         return kWKContextMenuItemTagInspectElement;
412 #endif
413     case WebCore::ContextMenuItemTagTextDirectionMenu:
414         return kWKContextMenuItemTagTextDirectionMenu;
415     case WebCore::ContextMenuItemTagTextDirectionDefault:
416         return kWKContextMenuItemTagTextDirectionDefault;
417     case WebCore::ContextMenuItemTagTextDirectionLeftToRight:
418         return kWKContextMenuItemTagTextDirectionLeftToRight;
419     case WebCore::ContextMenuItemTagTextDirectionRightToLeft:
420         return kWKContextMenuItemTagTextDirectionRightToLeft;
421     case WebCore::ContextMenuItemTagOpenMediaInNewWindow:
422         return kWKContextMenuItemTagOpenMediaInNewWindow;
423     case WebCore::ContextMenuItemTagCopyMediaLinkToClipboard:
424         return kWKContextMenuItemTagCopyMediaLinkToClipboard;
425     case WebCore::ContextMenuItemTagToggleMediaControls:
426         return kWKContextMenuItemTagToggleMediaControls;
427     case WebCore::ContextMenuItemTagToggleMediaLoop:
428         return kWKContextMenuItemTagToggleMediaLoop;
429     case WebCore::ContextMenuItemTagEnterVideoFullscreen:
430         return kWKContextMenuItemTagEnterVideoFullscreen;
431     case WebCore::ContextMenuItemTagMediaPlayPause:
432         return kWKContextMenuItemTagMediaPlayPause;
433     case WebCore::ContextMenuItemTagMediaMute:
434         return kWKContextMenuItemTagMediaMute;
435 #if PLATFORM(MAC)
436     case WebCore::ContextMenuItemTagCorrectSpellingAutomatically:
437         return kWKContextMenuItemTagCorrectSpellingAutomatically;
438     case WebCore::ContextMenuItemTagSubstitutionsMenu:
439         return kWKContextMenuItemTagSubstitutionsMenu;
440     case WebCore::ContextMenuItemTagShowSubstitutions:
441         return kWKContextMenuItemTagShowSubstitutions;
442     case WebCore::ContextMenuItemTagSmartCopyPaste:
443         return kWKContextMenuItemTagSmartCopyPaste;
444     case WebCore::ContextMenuItemTagSmartQuotes:
445         return kWKContextMenuItemTagSmartQuotes;
446     case WebCore::ContextMenuItemTagSmartDashes:
447         return kWKContextMenuItemTagSmartDashes;
448     case WebCore::ContextMenuItemTagSmartLinks:
449         return kWKContextMenuItemTagSmartLinks;
450     case WebCore::ContextMenuItemTagTextReplacement:
451         return kWKContextMenuItemTagTextReplacement;
452     case WebCore::ContextMenuItemTagTransformationsMenu:
453         return kWKContextMenuItemTagTransformationsMenu;
454     case WebCore::ContextMenuItemTagMakeUpperCase:
455         return kWKContextMenuItemTagMakeUpperCase;
456     case WebCore::ContextMenuItemTagMakeLowerCase:
457         return kWKContextMenuItemTagMakeLowerCase;
458     case WebCore::ContextMenuItemTagCapitalize:
459         return kWKContextMenuItemTagCapitalize;
460     case WebCore::ContextMenuItemTagChangeBack:
461         return kWKContextMenuItemTagChangeBack;
462 #endif
463     default:
464         if (action < WebCore::ContextMenuItemBaseApplicationTag)
465             LOG_ERROR("ContextMenuAction %i is an unknown tag but is below the allowable custom tag value of %i", action, WebCore::  ContextMenuItemBaseApplicationTag);
466         return static_cast<WKContextMenuItemTag>(action);
467     }
468 }
469 
toImpl(WKContextMenuItemTag tag)470 inline WebCore::ContextMenuAction toImpl(WKContextMenuItemTag tag)
471 {
472     switch (tag) {
473     case kWKContextMenuItemTagNoAction:
474         return WebCore::ContextMenuItemTagNoAction;
475     case kWKContextMenuItemTagOpenLinkInNewWindow:
476         return WebCore::ContextMenuItemTagOpenLinkInNewWindow;
477     case kWKContextMenuItemTagDownloadLinkToDisk:
478         return WebCore::ContextMenuItemTagDownloadLinkToDisk;
479     case kWKContextMenuItemTagCopyLinkToClipboard:
480         return WebCore::ContextMenuItemTagCopyLinkToClipboard;
481     case kWKContextMenuItemTagOpenImageInNewWindow:
482         return WebCore::ContextMenuItemTagOpenImageInNewWindow;
483     case kWKContextMenuItemTagDownloadImageToDisk:
484         return WebCore::ContextMenuItemTagDownloadImageToDisk;
485     case kWKContextMenuItemTagCopyImageToClipboard:
486         return WebCore::ContextMenuItemTagCopyImageToClipboard;
487     case kWKContextMenuItemTagOpenFrameInNewWindow:
488         return WebCore::ContextMenuItemTagOpenFrameInNewWindow;
489     case kWKContextMenuItemTagCopy:
490         return WebCore::ContextMenuItemTagCopy;
491     case kWKContextMenuItemTagGoBack:
492         return WebCore::ContextMenuItemTagGoBack;
493     case kWKContextMenuItemTagGoForward:
494         return WebCore::ContextMenuItemTagGoForward;
495     case kWKContextMenuItemTagStop:
496         return WebCore::ContextMenuItemTagStop;
497     case kWKContextMenuItemTagReload:
498         return WebCore::ContextMenuItemTagReload;
499     case kWKContextMenuItemTagCut:
500         return WebCore::ContextMenuItemTagCut;
501     case kWKContextMenuItemTagPaste:
502         return WebCore::ContextMenuItemTagPaste;
503     case kWKContextMenuItemTagSpellingGuess:
504         return WebCore::ContextMenuItemTagSpellingGuess;
505     case kWKContextMenuItemTagNoGuessesFound:
506         return WebCore::ContextMenuItemTagNoGuessesFound;
507     case kWKContextMenuItemTagIgnoreSpelling:
508         return WebCore::ContextMenuItemTagIgnoreSpelling;
509     case kWKContextMenuItemTagLearnSpelling:
510         return WebCore::ContextMenuItemTagLearnSpelling;
511     case kWKContextMenuItemTagOther:
512         return WebCore::ContextMenuItemTagOther;
513     case kWKContextMenuItemTagSearchInSpotlight:
514         return WebCore::ContextMenuItemTagSearchInSpotlight;
515     case kWKContextMenuItemTagSearchWeb:
516         return WebCore::ContextMenuItemTagSearchWeb;
517     case kWKContextMenuItemTagLookUpInDictionary:
518         return WebCore::ContextMenuItemTagLookUpInDictionary;
519     case kWKContextMenuItemTagOpenWithDefaultApplication:
520         return WebCore::ContextMenuItemTagOpenWithDefaultApplication;
521     case kWKContextMenuItemTagPDFActualSize:
522         return WebCore::ContextMenuItemPDFActualSize;
523     case kWKContextMenuItemTagPDFZoomIn:
524         return WebCore::ContextMenuItemPDFZoomIn;
525     case kWKContextMenuItemTagPDFZoomOut:
526         return WebCore::ContextMenuItemPDFZoomOut;
527     case kWKContextMenuItemTagPDFAutoSize:
528         return WebCore::ContextMenuItemPDFAutoSize;
529     case kWKContextMenuItemTagPDFSinglePage:
530         return WebCore::ContextMenuItemPDFSinglePage;
531     case kWKContextMenuItemTagPDFFacingPages:
532         return WebCore::ContextMenuItemPDFFacingPages;
533     case kWKContextMenuItemTagPDFContinuous:
534         return WebCore::ContextMenuItemPDFContinuous;
535     case kWKContextMenuItemTagPDFNextPage:
536         return WebCore::ContextMenuItemPDFNextPage;
537     case kWKContextMenuItemTagPDFPreviousPage:
538         return WebCore::ContextMenuItemPDFPreviousPage;
539     case kWKContextMenuItemTagOpenLink:
540         return WebCore::ContextMenuItemTagOpenLink;
541     case kWKContextMenuItemTagIgnoreGrammar:
542         return WebCore::ContextMenuItemTagIgnoreGrammar;
543     case kWKContextMenuItemTagSpellingMenu:
544         return WebCore::ContextMenuItemTagSpellingMenu;
545     case kWKContextMenuItemTagShowSpellingPanel:
546         return WebCore::ContextMenuItemTagShowSpellingPanel;
547     case kWKContextMenuItemTagCheckSpelling:
548         return WebCore::ContextMenuItemTagCheckSpelling;
549     case kWKContextMenuItemTagCheckSpellingWhileTyping:
550         return WebCore::ContextMenuItemTagCheckSpellingWhileTyping;
551     case kWKContextMenuItemTagCheckGrammarWithSpelling:
552         return WebCore::ContextMenuItemTagCheckGrammarWithSpelling;
553     case kWKContextMenuItemTagFontMenu:
554         return WebCore::ContextMenuItemTagFontMenu;
555     case kWKContextMenuItemTagShowFonts:
556         return WebCore::ContextMenuItemTagShowFonts;
557     case kWKContextMenuItemTagBold:
558         return WebCore::ContextMenuItemTagBold;
559     case kWKContextMenuItemTagItalic:
560         return WebCore::ContextMenuItemTagItalic;
561     case kWKContextMenuItemTagUnderline:
562         return WebCore::ContextMenuItemTagUnderline;
563     case kWKContextMenuItemTagOutline:
564         return WebCore::ContextMenuItemTagOutline;
565     case kWKContextMenuItemTagStyles:
566         return WebCore::ContextMenuItemTagStyles;
567     case kWKContextMenuItemTagShowColors:
568         return WebCore::ContextMenuItemTagShowColors;
569     case kWKContextMenuItemTagSpeechMenu:
570         return WebCore::ContextMenuItemTagSpeechMenu;
571     case kWKContextMenuItemTagStartSpeaking:
572         return WebCore::ContextMenuItemTagStartSpeaking;
573     case kWKContextMenuItemTagStopSpeaking:
574         return WebCore::ContextMenuItemTagStopSpeaking;
575     case kWKContextMenuItemTagWritingDirectionMenu:
576         return WebCore::ContextMenuItemTagWritingDirectionMenu;
577     case kWKContextMenuItemTagDefaultDirection:
578         return WebCore::ContextMenuItemTagDefaultDirection;
579     case kWKContextMenuItemTagLeftToRight:
580         return WebCore::ContextMenuItemTagLeftToRight;
581     case kWKContextMenuItemTagRightToLeft:
582         return WebCore::ContextMenuItemTagRightToLeft;
583     case kWKContextMenuItemTagPDFSinglePageScrolling:
584         return WebCore::ContextMenuItemTagPDFSinglePageScrolling;
585     case kWKContextMenuItemTagPDFFacingPagesScrolling:
586         return WebCore::ContextMenuItemTagPDFFacingPagesScrolling;
587 #if ENABLE(INSPECTOR)
588     case kWKContextMenuItemTagInspectElement:
589         return WebCore::ContextMenuItemTagInspectElement;
590 #endif
591     case kWKContextMenuItemTagTextDirectionMenu:
592         return WebCore::ContextMenuItemTagTextDirectionMenu;
593     case kWKContextMenuItemTagTextDirectionDefault:
594         return WebCore::ContextMenuItemTagTextDirectionDefault;
595     case kWKContextMenuItemTagTextDirectionLeftToRight:
596         return WebCore::ContextMenuItemTagTextDirectionLeftToRight;
597     case kWKContextMenuItemTagTextDirectionRightToLeft:
598         return WebCore::ContextMenuItemTagTextDirectionRightToLeft;
599     case kWKContextMenuItemTagOpenMediaInNewWindow:
600         return WebCore::ContextMenuItemTagOpenMediaInNewWindow;
601     case kWKContextMenuItemTagCopyMediaLinkToClipboard:
602         return WebCore::ContextMenuItemTagCopyMediaLinkToClipboard;
603     case kWKContextMenuItemTagToggleMediaControls:
604         return WebCore::ContextMenuItemTagToggleMediaControls;
605     case kWKContextMenuItemTagToggleMediaLoop:
606         return WebCore::ContextMenuItemTagToggleMediaLoop;
607     case kWKContextMenuItemTagEnterVideoFullscreen:
608         return WebCore::ContextMenuItemTagEnterVideoFullscreen;
609     case kWKContextMenuItemTagMediaPlayPause:
610         return WebCore::ContextMenuItemTagMediaPlayPause;
611     case kWKContextMenuItemTagMediaMute:
612         return WebCore::ContextMenuItemTagMediaMute;
613 #if PLATFORM(MAC)
614     case kWKContextMenuItemTagCorrectSpellingAutomatically:
615         return WebCore::ContextMenuItemTagCorrectSpellingAutomatically;
616     case kWKContextMenuItemTagSubstitutionsMenu:
617         return WebCore::ContextMenuItemTagSubstitutionsMenu;
618     case kWKContextMenuItemTagShowSubstitutions:
619         return WebCore::ContextMenuItemTagShowSubstitutions;
620     case kWKContextMenuItemTagSmartCopyPaste:
621         return WebCore::ContextMenuItemTagSmartCopyPaste;
622     case kWKContextMenuItemTagSmartQuotes:
623         return WebCore::ContextMenuItemTagSmartQuotes;
624     case kWKContextMenuItemTagSmartDashes:
625         return WebCore::ContextMenuItemTagSmartDashes;
626     case kWKContextMenuItemTagSmartLinks:
627         return WebCore::ContextMenuItemTagSmartLinks;
628     case kWKContextMenuItemTagTextReplacement:
629         return WebCore::ContextMenuItemTagTextReplacement;
630     case kWKContextMenuItemTagTransformationsMenu:
631         return WebCore::ContextMenuItemTagTransformationsMenu;
632     case kWKContextMenuItemTagMakeUpperCase:
633         return WebCore::ContextMenuItemTagMakeUpperCase;
634     case kWKContextMenuItemTagMakeLowerCase:
635         return WebCore::ContextMenuItemTagMakeLowerCase;
636     case kWKContextMenuItemTagCapitalize:
637         return WebCore::ContextMenuItemTagCapitalize;
638     case kWKContextMenuItemTagChangeBack:
639         return WebCore::ContextMenuItemTagChangeBack;
640 #endif
641     default:
642         if (tag < kWKContextMenuItemBaseApplicationTag)
643             LOG_ERROR("WKContextMenuItemTag %i is an unknown tag but is below the allowable custom tag value of %i", tag, kWKContextMenuItemBaseApplicationTag);
644         return static_cast<WebCore::ContextMenuAction>(tag);
645     }
646 }
647 
toAPI(WebCore::ContextMenuItemType type)648 inline WKContextMenuItemType toAPI(WebCore::ContextMenuItemType type)
649 {
650     switch(type) {
651     case WebCore::ActionType:
652         return kWKContextMenuItemTypeAction;
653     case WebCore::CheckableActionType:
654         return kWKContextMenuItemTypeCheckableAction;
655     case WebCore::SeparatorType:
656         return kWKContextMenuItemTypeSeparator;
657     case WebCore::SubmenuType:
658         return kWKContextMenuItemTypeSubmenu;
659     default:
660         ASSERT_NOT_REACHED();
661         return kWKContextMenuItemTypeAction;
662     }
663 }
664 
toFindOptions(WKFindOptions wkFindOptions)665 inline FindOptions toFindOptions(WKFindOptions wkFindOptions)
666 {
667     unsigned findOptions = 0;
668 
669     if (wkFindOptions & kWKFindOptionsCaseInsensitive)
670         findOptions |= FindOptionsCaseInsensitive;
671     if (wkFindOptions & kWKFindOptionsAtWordStarts)
672         findOptions |= FindOptionsAtWordStarts;
673     if (wkFindOptions & kWKFindOptionsTreatMedialCapitalAsWordStart)
674         findOptions |= FindOptionsTreatMedialCapitalAsWordStart;
675     if (wkFindOptions & kWKFindOptionsBackwards)
676         findOptions |= FindOptionsBackwards;
677     if (wkFindOptions & kWKFindOptionsWrapAround)
678         findOptions |= FindOptionsWrapAround;
679     if (wkFindOptions & kWKFindOptionsShowOverlay)
680         findOptions |= FindOptionsShowOverlay;
681     if (wkFindOptions & kWKFindOptionsShowFindIndicator)
682         findOptions |= FindOptionsShowFindIndicator;
683 
684     return static_cast<FindOptions>(findOptions);
685 }
686 
toAPI(WebCore::NavigationType type)687 inline WKFrameNavigationType toAPI(WebCore::NavigationType type)
688 {
689     WKFrameNavigationType wkType = kWKFrameNavigationTypeOther;
690 
691     switch (type) {
692     case WebCore::NavigationTypeLinkClicked:
693         wkType = kWKFrameNavigationTypeLinkClicked;
694         break;
695     case WebCore::NavigationTypeFormSubmitted:
696         wkType = kWKFrameNavigationTypeFormSubmitted;
697         break;
698     case WebCore::NavigationTypeBackForward:
699         wkType = kWKFrameNavigationTypeBackForward;
700         break;
701     case WebCore::NavigationTypeReload:
702         wkType = kWKFrameNavigationTypeReload;
703         break;
704     case WebCore::NavigationTypeFormResubmitted:
705         wkType = kWKFrameNavigationTypeFormResubmitted;
706         break;
707     case WebCore::NavigationTypeOther:
708         wkType = kWKFrameNavigationTypeOther;
709         break;
710     }
711 
712     return wkType;
713 }
714 
toAPI(SameDocumentNavigationType type)715 inline WKSameDocumentNavigationType toAPI(SameDocumentNavigationType type)
716 {
717     WKFrameNavigationType wkType = kWKSameDocumentNavigationAnchorNavigation;
718 
719     switch (type) {
720     case SameDocumentNavigationAnchorNavigation:
721         wkType = kWKSameDocumentNavigationAnchorNavigation;
722         break;
723     case SameDocumentNavigationSessionStatePush:
724         wkType = kWKSameDocumentNavigationSessionStatePush;
725         break;
726     case SameDocumentNavigationSessionStateReplace:
727         wkType = kWKSameDocumentNavigationSessionStateReplace;
728         break;
729     case SameDocumentNavigationSessionStatePop:
730         wkType = kWKSameDocumentNavigationSessionStatePop;
731         break;
732     }
733 
734     return wkType;
735 }
736 
toImageOptions(WKImageOptions wkImageOptions)737 inline ImageOptions toImageOptions(WKImageOptions wkImageOptions)
738 {
739     unsigned imageOptions = 0;
740 
741     if (wkImageOptions & kWKImageOptionsShareable)
742         imageOptions |= ImageOptionsShareable;
743 
744     return static_cast<ImageOptions>(imageOptions);
745 }
746 
747 } // namespace WebKit
748 
749 #endif // WKSharedAPICast_h
750