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