8439dbca447a7325ce473ae6193af92c14f1b921
[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 "APIError.h"
30 #include "APINumber.h"
31 #include "APISession.h"
32 #include "APIString.h"
33 #include "APIURL.h"
34 #include "APIURLRequest.h"
35 #include "APIURLResponse.h"
36 #include "ImageOptions.h"
37 #include "SameDocumentNavigationType.h"
38 #include "WKBase.h"
39 #include "WKContextMenuItemTypes.h"
40 #include "WKEvent.h"
41 #include "WKFindOptions.h"
42 #include "WKGeometry.h"
43 #include "WKImage.h"
44 #include "WKPageLoadTypes.h"
45 #include "WKPageLoadTypesPrivate.h"
46 #include "WKPageVisibilityTypes.h"
47 #include "WKUserContentInjectedFrames.h"
48 #include "WKUserScriptInjectionTime.h"
49 #include "WebEvent.h"
50 #include "WebFindOptions.h"
51 #include "WebSecurityOrigin.h"
52 #include <WebCore/ContextMenuItem.h>
53 #include <WebCore/FloatRect.h>
54 #include <WebCore/FrameLoaderTypes.h>
55 #include <WebCore/IntRect.h>
56 #include <WebCore/LayoutMilestones.h>
57 #include <WebCore/PageVisibilityState.h>
58 #include <WebCore/SecurityOrigin.h>
59 #include <WebCore/UserContentTypes.h>
60 #include <WebCore/UserScriptTypes.h>
61
62 namespace API {
63 class Array;
64 class Data;
65 class Point;
66 class Rect;
67 class Size;
68 }
69
70 namespace WebKit {
71
72 class ImmutableDictionary;
73 class MutableDictionary;
74 class ObjCObjectGraph;
75 class WebArchive;
76 class WebArchiveResource;
77 class WebCertificateInfo;
78 class WebConnection;
79 class WebContextMenuItem;
80 class WebGraphicsContext;
81 class WebImage;
82 class WebSecurityOrigin;
83 class WebSerializedScriptValue;
84 class WebUserContentURLPattern;
85
86 template<typename APIType> struct APITypeInfo { };
87 template<typename ImplType> struct ImplTypeInfo { };
88
89 #define WK_ADD_API_MAPPING(TheAPIType, TheImplType) \
90     template<> struct APITypeInfo<TheAPIType> { typedef TheImplType* ImplType; }; \
91     template<> struct ImplTypeInfo<TheImplType*> { typedef TheAPIType APIType; };
92
93 WK_ADD_API_MAPPING(WKArrayRef, API::Array)
94 WK_ADD_API_MAPPING(WKBooleanRef, API::Boolean)
95 WK_ADD_API_MAPPING(WKCertificateInfoRef, WebCertificateInfo)
96 WK_ADD_API_MAPPING(WKConnectionRef, WebConnection)
97 WK_ADD_API_MAPPING(WKContextMenuItemRef, WebContextMenuItem)
98 WK_ADD_API_MAPPING(WKDataRef, API::Data)
99 WK_ADD_API_MAPPING(WKDictionaryRef, ImmutableDictionary)
100 WK_ADD_API_MAPPING(WKDoubleRef, API::Double)
101 WK_ADD_API_MAPPING(WKErrorRef, API::Error)
102 WK_ADD_API_MAPPING(WKGraphicsContextRef, WebGraphicsContext)
103 WK_ADD_API_MAPPING(WKImageRef, WebImage)
104 WK_ADD_API_MAPPING(WKMutableDictionaryRef, MutableDictionary)
105 WK_ADD_API_MAPPING(WKPointRef, API::Point)
106 WK_ADD_API_MAPPING(WKRectRef, API::Rect)
107 WK_ADD_API_MAPPING(WKSecurityOriginRef, WebSecurityOrigin)
108 WK_ADD_API_MAPPING(WKSerializedScriptValueRef, WebSerializedScriptValue)
109 WK_ADD_API_MAPPING(WKSizeRef, API::Size)
110 WK_ADD_API_MAPPING(WKStringRef, API::String)
111 WK_ADD_API_MAPPING(WKTypeRef, API::Object)
112 WK_ADD_API_MAPPING(WKUInt64Ref, API::UInt64)
113 WK_ADD_API_MAPPING(WKURLRef, API::URL)
114 WK_ADD_API_MAPPING(WKURLRequestRef, API::URLRequest)
115 WK_ADD_API_MAPPING(WKURLResponseRef, API::URLResponse)
116 WK_ADD_API_MAPPING(WKUserContentURLPatternRef, WebUserContentURLPattern)
117 WK_ADD_API_MAPPING(WKSessionRef, API::Session)
118
119 template<> struct APITypeInfo<WKMutableArrayRef> { typedef API::Array* ImplType; };
120
121 #if PLATFORM(MAC)
122 WK_ADD_API_MAPPING(WKWebArchiveRef, WebArchive)
123 WK_ADD_API_MAPPING(WKWebArchiveResourceRef, WebArchiveResource)
124 WK_ADD_API_MAPPING(WKObjCTypeWrapperRef, ObjCObjectGraph)
125 #endif
126
127 template<typename T>
128 inline typename ImplTypeInfo<T>::APIType toAPI(T t)
129 {
130     return reinterpret_cast<typename ImplTypeInfo<T>::APIType>(t);
131 }
132
133 template<typename ImplType, typename APIType = typename ImplTypeInfo<ImplType*>::APIType>
134 class ProxyingRefPtr {
135 public:
136     ProxyingRefPtr(PassRefPtr<ImplType> impl)
137         : m_impl(impl)
138     {
139     }
140
141     operator APIType() { return toAPI(m_impl.get()); }
142
143 private:
144     RefPtr<ImplType> m_impl;
145 };
146
147 /* Opaque typing convenience methods */
148
149 template<typename T>
150 inline typename APITypeInfo<T>::ImplType toImpl(T t)
151 {
152     // An example of the conversions that take place:
153     // const struct OpaqueWKArray* -> const struct OpaqueWKArray -> struct OpaqueWKArray -> struct OpaqueWKArray* -> API::Array*
154     
155     typedef typename std::remove_pointer<T>::type PotentiallyConstValueType;
156     typedef typename std::remove_const<PotentiallyConstValueType>::type NonConstValueType;
157
158     return reinterpret_cast<typename APITypeInfo<T>::ImplType>(const_cast<NonConstValueType*>(t));
159 }
160
161 /* Special cases. */
162
163 inline ProxyingRefPtr<API::String> toAPI(StringImpl* string)
164 {
165     return ProxyingRefPtr<API::String>(API::String::create(string));
166 }
167
168 inline WKStringRef toCopiedAPI(const String& string)
169 {
170     RefPtr<API::String> apiString = API::String::create(string);
171     return toAPI(apiString.release().leakRef());
172 }
173
174 inline ProxyingRefPtr<API::URL> toURLRef(StringImpl* string)
175 {
176     if (!string)
177         return ProxyingRefPtr<API::URL>(0);
178     return ProxyingRefPtr<API::URL>(API::URL::create(String(string)));
179 }
180
181 inline WKURLRef toCopiedURLAPI(const String& string)
182 {
183     if (!string)
184         return 0;
185     RefPtr<API::URL> url = API::URL::create(string);
186     return toAPI(url.release().leakRef());
187 }
188
189 inline String toWTFString(WKStringRef stringRef)
190 {
191     if (!stringRef)
192         return String();
193     return toImpl(stringRef)->string();
194 }
195
196 inline String toWTFString(WKURLRef urlRef)
197 {
198     if (!urlRef)
199         return String();
200     return toImpl(urlRef)->string();
201 }
202
203 inline ProxyingRefPtr<API::Error> toAPI(const WebCore::ResourceError& error)
204 {
205     return ProxyingRefPtr<API::Error>(API::Error::create(error));
206 }
207
208 inline ProxyingRefPtr<API::URLRequest> toAPI(const WebCore::ResourceRequest& request)
209 {
210     return ProxyingRefPtr<API::URLRequest>(API::URLRequest::create(request));
211 }
212
213 inline ProxyingRefPtr<API::URLResponse> toAPI(const WebCore::ResourceResponse& response)
214 {
215     return ProxyingRefPtr<API::URLResponse>(API::URLResponse::create(response));
216 }
217
218 inline WKSecurityOriginRef toCopiedAPI(WebCore::SecurityOrigin* origin)
219 {
220     if (!origin)
221         return 0;
222     return toAPI(WebSecurityOrigin::create(origin).leakRef());
223 }
224
225 /* Geometry conversions */
226
227 inline WebCore::FloatRect toFloatRect(const WKRect& wkRect)
228 {
229     return WebCore::FloatRect(static_cast<float>(wkRect.origin.x), static_cast<float>(wkRect.origin.y),
230                               static_cast<float>(wkRect.size.width), static_cast<float>(wkRect.size.height));
231 }
232
233 inline WebCore::IntSize toIntSize(const WKSize& wkSize)
234 {
235     return WebCore::IntSize(static_cast<int>(wkSize.width), static_cast<int>(wkSize.height));
236 }
237
238 inline WebCore::IntPoint toIntPoint(const WKPoint& wkPoint)
239 {
240     return WebCore::IntPoint(static_cast<int>(wkPoint.x), static_cast<int>(wkPoint.y));
241 }
242
243 inline WebCore::IntRect toIntRect(const WKRect& wkRect)
244 {
245     return WebCore::IntRect(static_cast<int>(wkRect.origin.x), static_cast<int>(wkRect.origin.y),
246                             static_cast<int>(wkRect.size.width), static_cast<int>(wkRect.size.height));
247 }
248
249 inline WKRect toAPI(const WebCore::FloatRect& rect)
250 {
251     WKRect wkRect;
252     wkRect.origin.x = rect.x();
253     wkRect.origin.y = rect.y();
254     wkRect.size.width = rect.width();
255     wkRect.size.height = rect.height();
256     return wkRect;
257 }
258
259 inline WKRect toAPI(const WebCore::IntRect& rect)
260 {
261     WKRect wkRect;
262     wkRect.origin.x = rect.x();
263     wkRect.origin.y = rect.y();
264     wkRect.size.width = rect.width();
265     wkRect.size.height = rect.height();
266     return wkRect;
267 }
268
269 inline WKSize toAPI(const WebCore::IntSize& size)
270 {
271     WKSize wkSize;
272     wkSize.width = size.width();
273     wkSize.height = size.height();
274     return wkSize;
275 }
276
277 inline WKPoint toAPI(const WebCore::IntPoint& point)
278 {
279     WKPoint wkPoint;
280     wkPoint.x = point.x();
281     wkPoint.y = point.y();
282     return wkPoint;
283 }
284
285 /* Enum conversions */
286
287 inline WKTypeID toAPI(API::Object::Type type)
288 {
289     return static_cast<WKTypeID>(type);
290 }
291
292 inline WKEventModifiers toAPI(WebEvent::Modifiers modifiers)
293 {
294     WKEventModifiers wkModifiers = 0;
295     if (modifiers & WebEvent::ShiftKey)
296         wkModifiers |= kWKEventModifiersShiftKey;
297     if (modifiers & WebEvent::ControlKey)
298         wkModifiers |= kWKEventModifiersControlKey;
299     if (modifiers & WebEvent::AltKey)
300         wkModifiers |= kWKEventModifiersAltKey;
301     if (modifiers & WebEvent::MetaKey)
302         wkModifiers |= kWKEventModifiersMetaKey;
303     return wkModifiers;
304 }
305
306 inline WKEventMouseButton toAPI(WebMouseEvent::Button mouseButton)
307 {
308     WKEventMouseButton wkMouseButton = kWKEventMouseButtonNoButton;
309
310     switch (mouseButton) {
311     case WebMouseEvent::NoButton:
312         wkMouseButton = kWKEventMouseButtonNoButton;
313         break;
314     case WebMouseEvent::LeftButton:
315         wkMouseButton = kWKEventMouseButtonLeftButton;
316         break;
317     case WebMouseEvent::MiddleButton:
318         wkMouseButton = kWKEventMouseButtonMiddleButton;
319         break;
320     case WebMouseEvent::RightButton:
321         wkMouseButton = kWKEventMouseButtonRightButton;
322         break;
323     }
324
325     return wkMouseButton;
326 }
327
328 inline WKContextMenuItemTag toAPI(WebCore::ContextMenuAction action)
329 {
330     switch (action) {
331     case WebCore::ContextMenuItemTagNoAction:
332         return kWKContextMenuItemTagNoAction;
333     case WebCore::ContextMenuItemTagOpenLinkInNewWindow:
334         return kWKContextMenuItemTagOpenLinkInNewWindow;
335     case WebCore::ContextMenuItemTagDownloadLinkToDisk:
336         return kWKContextMenuItemTagDownloadLinkToDisk;
337     case WebCore::ContextMenuItemTagCopyLinkToClipboard:
338         return kWKContextMenuItemTagCopyLinkToClipboard;
339     case WebCore::ContextMenuItemTagOpenImageInNewWindow:
340         return kWKContextMenuItemTagOpenImageInNewWindow;
341     case WebCore::ContextMenuItemTagDownloadImageToDisk:
342         return kWKContextMenuItemTagDownloadImageToDisk;
343     case WebCore::ContextMenuItemTagCopyImageToClipboard:
344         return kWKContextMenuItemTagCopyImageToClipboard;
345 #if PLATFORM(EFL) || PLATFORM(GTK)
346     case WebCore::ContextMenuItemTagCopyImageUrlToClipboard:
347         return kWKContextMenuItemTagCopyImageUrlToClipboard;
348 #endif
349     case WebCore::ContextMenuItemTagOpenFrameInNewWindow:
350         return kWKContextMenuItemTagOpenFrameInNewWindow;
351     case WebCore::ContextMenuItemTagCopy:
352         return kWKContextMenuItemTagCopy;
353     case WebCore::ContextMenuItemTagGoBack:
354         return kWKContextMenuItemTagGoBack;
355     case WebCore::ContextMenuItemTagGoForward:
356         return kWKContextMenuItemTagGoForward;
357     case WebCore::ContextMenuItemTagStop:
358         return kWKContextMenuItemTagStop;
359     case WebCore::ContextMenuItemTagReload:
360         return kWKContextMenuItemTagReload;
361     case WebCore::ContextMenuItemTagCut:
362         return kWKContextMenuItemTagCut;
363     case WebCore::ContextMenuItemTagPaste:
364         return kWKContextMenuItemTagPaste;
365 #if PLATFORM(EFL) || PLATFORM(GTK)
366     case WebCore::ContextMenuItemTagSelectAll:
367         return kWKContextMenuItemTagSelectAll;
368 #endif
369     case WebCore::ContextMenuItemTagSpellingGuess:
370         return kWKContextMenuItemTagSpellingGuess;
371     case WebCore::ContextMenuItemTagNoGuessesFound:
372         return kWKContextMenuItemTagNoGuessesFound;
373     case WebCore::ContextMenuItemTagIgnoreSpelling:
374         return kWKContextMenuItemTagIgnoreSpelling;
375     case WebCore::ContextMenuItemTagLearnSpelling:
376         return kWKContextMenuItemTagLearnSpelling;
377     case WebCore::ContextMenuItemTagOther:
378         return kWKContextMenuItemTagOther;
379     case WebCore::ContextMenuItemTagSearchInSpotlight:
380         return kWKContextMenuItemTagSearchInSpotlight;
381     case WebCore::ContextMenuItemTagSearchWeb:
382         return kWKContextMenuItemTagSearchWeb;
383     case WebCore::ContextMenuItemTagLookUpInDictionary:
384         return kWKContextMenuItemTagLookUpInDictionary;
385     case WebCore::ContextMenuItemTagOpenWithDefaultApplication:
386         return kWKContextMenuItemTagOpenWithDefaultApplication;
387     case WebCore::ContextMenuItemPDFActualSize:
388         return kWKContextMenuItemTagPDFActualSize;
389     case WebCore::ContextMenuItemPDFZoomIn:
390         return kWKContextMenuItemTagPDFZoomIn;
391     case WebCore::ContextMenuItemPDFZoomOut:
392         return kWKContextMenuItemTagPDFZoomOut;
393     case WebCore::ContextMenuItemPDFAutoSize:
394         return kWKContextMenuItemTagPDFAutoSize;
395     case WebCore::ContextMenuItemPDFSinglePage:
396         return kWKContextMenuItemTagPDFSinglePage;
397     case WebCore::ContextMenuItemPDFFacingPages:
398         return kWKContextMenuItemTagPDFFacingPages;
399     case WebCore::ContextMenuItemPDFContinuous:
400         return kWKContextMenuItemTagPDFContinuous;
401     case WebCore::ContextMenuItemPDFNextPage:
402         return kWKContextMenuItemTagPDFNextPage;
403     case WebCore::ContextMenuItemPDFPreviousPage:
404         return kWKContextMenuItemTagPDFPreviousPage;
405     case WebCore::ContextMenuItemTagOpenLink:
406         return kWKContextMenuItemTagOpenLink;
407     case WebCore::ContextMenuItemTagIgnoreGrammar:
408         return kWKContextMenuItemTagIgnoreGrammar;
409     case WebCore::ContextMenuItemTagSpellingMenu:
410         return kWKContextMenuItemTagSpellingMenu;
411     case WebCore::ContextMenuItemTagShowSpellingPanel:
412         return kWKContextMenuItemTagShowSpellingPanel;
413     case WebCore::ContextMenuItemTagCheckSpelling:
414         return kWKContextMenuItemTagCheckSpelling;
415     case WebCore::ContextMenuItemTagCheckSpellingWhileTyping:
416         return kWKContextMenuItemTagCheckSpellingWhileTyping;
417     case WebCore::ContextMenuItemTagCheckGrammarWithSpelling:
418         return kWKContextMenuItemTagCheckGrammarWithSpelling;
419     case WebCore::ContextMenuItemTagFontMenu:
420         return kWKContextMenuItemTagFontMenu;
421     case WebCore::ContextMenuItemTagShowFonts:
422         return kWKContextMenuItemTagShowFonts;
423     case WebCore::ContextMenuItemTagBold:
424         return kWKContextMenuItemTagBold;
425     case WebCore::ContextMenuItemTagItalic:
426         return kWKContextMenuItemTagItalic;
427     case WebCore::ContextMenuItemTagUnderline:
428         return kWKContextMenuItemTagUnderline;
429     case WebCore::ContextMenuItemTagOutline:
430         return kWKContextMenuItemTagOutline;
431     case WebCore::ContextMenuItemTagStyles:
432         return kWKContextMenuItemTagStyles;
433     case WebCore::ContextMenuItemTagShowColors:
434         return kWKContextMenuItemTagShowColors;
435     case WebCore::ContextMenuItemTagSpeechMenu:
436         return kWKContextMenuItemTagSpeechMenu;
437     case WebCore::ContextMenuItemTagStartSpeaking:
438         return kWKContextMenuItemTagStartSpeaking;
439     case WebCore::ContextMenuItemTagStopSpeaking:
440         return kWKContextMenuItemTagStopSpeaking;
441     case WebCore::ContextMenuItemTagWritingDirectionMenu:
442         return kWKContextMenuItemTagWritingDirectionMenu;
443     case WebCore::ContextMenuItemTagDefaultDirection:
444         return kWKContextMenuItemTagDefaultDirection;
445     case WebCore::ContextMenuItemTagLeftToRight:
446         return kWKContextMenuItemTagLeftToRight;
447     case WebCore::ContextMenuItemTagRightToLeft:
448         return kWKContextMenuItemTagRightToLeft;
449     case WebCore::ContextMenuItemTagPDFSinglePageScrolling:
450         return kWKContextMenuItemTagPDFSinglePageScrolling;
451     case WebCore::ContextMenuItemTagPDFFacingPagesScrolling:
452         return kWKContextMenuItemTagPDFFacingPagesScrolling;
453     case WebCore::ContextMenuItemTagDictationAlternative:
454         return kWKContextMenuItemTagDictationAlternative;
455 #if ENABLE(INSPECTOR)
456     case WebCore::ContextMenuItemTagInspectElement:
457         return kWKContextMenuItemTagInspectElement;
458 #endif
459     case WebCore::ContextMenuItemTagTextDirectionMenu:
460         return kWKContextMenuItemTagTextDirectionMenu;
461     case WebCore::ContextMenuItemTagTextDirectionDefault:
462         return kWKContextMenuItemTagTextDirectionDefault;
463     case WebCore::ContextMenuItemTagTextDirectionLeftToRight:
464         return kWKContextMenuItemTagTextDirectionLeftToRight;
465     case WebCore::ContextMenuItemTagTextDirectionRightToLeft:
466         return kWKContextMenuItemTagTextDirectionRightToLeft;
467     case WebCore::ContextMenuItemTagOpenMediaInNewWindow:
468         return kWKContextMenuItemTagOpenMediaInNewWindow;
469     case WebCore::ContextMenuItemTagDownloadMediaToDisk:
470         return kWKContextMenuItemTagDownloadMediaToDisk;
471     case WebCore::ContextMenuItemTagCopyMediaLinkToClipboard:
472         return kWKContextMenuItemTagCopyMediaLinkToClipboard;
473     case WebCore::ContextMenuItemTagToggleMediaControls:
474         return kWKContextMenuItemTagToggleMediaControls;
475     case WebCore::ContextMenuItemTagToggleMediaLoop:
476         return kWKContextMenuItemTagToggleMediaLoop;
477     case WebCore::ContextMenuItemTagToggleVideoFullscreen:
478         return kWKContextMenuItemTagToggleVideoFullscreen;
479     case WebCore::ContextMenuItemTagEnterVideoFullscreen:
480         return kWKContextMenuItemTagEnterVideoFullscreen;
481     case WebCore::ContextMenuItemTagMediaPlayPause:
482         return kWKContextMenuItemTagMediaPlayPause;
483     case WebCore::ContextMenuItemTagMediaMute:
484         return kWKContextMenuItemTagMediaMute;
485 #if PLATFORM(MAC)
486     case WebCore::ContextMenuItemTagCorrectSpellingAutomatically:
487         return kWKContextMenuItemTagCorrectSpellingAutomatically;
488     case WebCore::ContextMenuItemTagSubstitutionsMenu:
489         return kWKContextMenuItemTagSubstitutionsMenu;
490     case WebCore::ContextMenuItemTagShowSubstitutions:
491         return kWKContextMenuItemTagShowSubstitutions;
492     case WebCore::ContextMenuItemTagSmartCopyPaste:
493         return kWKContextMenuItemTagSmartCopyPaste;
494     case WebCore::ContextMenuItemTagSmartQuotes:
495         return kWKContextMenuItemTagSmartQuotes;
496     case WebCore::ContextMenuItemTagSmartDashes:
497         return kWKContextMenuItemTagSmartDashes;
498     case WebCore::ContextMenuItemTagSmartLinks:
499         return kWKContextMenuItemTagSmartLinks;
500     case WebCore::ContextMenuItemTagTextReplacement:
501         return kWKContextMenuItemTagTextReplacement;
502     case WebCore::ContextMenuItemTagTransformationsMenu:
503         return kWKContextMenuItemTagTransformationsMenu;
504     case WebCore::ContextMenuItemTagMakeUpperCase:
505         return kWKContextMenuItemTagMakeUpperCase;
506     case WebCore::ContextMenuItemTagMakeLowerCase:
507         return kWKContextMenuItemTagMakeLowerCase;
508     case WebCore::ContextMenuItemTagCapitalize:
509         return kWKContextMenuItemTagCapitalize;
510     case WebCore::ContextMenuItemTagChangeBack:
511         return kWKContextMenuItemTagChangeBack;
512 #endif
513     case WebCore::ContextMenuItemTagOpenLinkInThisWindow:
514         return kWKContextMenuItemTagOpenLinkInThisWindow;
515     default:
516         if (action < WebCore::ContextMenuItemBaseApplicationTag)
517             LOG_ERROR("ContextMenuAction %i is an unknown tag but is below the allowable custom tag value of %i", action, WebCore::  ContextMenuItemBaseApplicationTag);
518         return static_cast<WKContextMenuItemTag>(action);
519     }
520 }
521
522 inline WebCore::ContextMenuAction toImpl(WKContextMenuItemTag tag)
523 {
524     switch (tag) {
525     case kWKContextMenuItemTagNoAction:
526         return WebCore::ContextMenuItemTagNoAction;
527     case kWKContextMenuItemTagOpenLinkInNewWindow:
528         return WebCore::ContextMenuItemTagOpenLinkInNewWindow;
529     case kWKContextMenuItemTagDownloadLinkToDisk:
530         return WebCore::ContextMenuItemTagDownloadLinkToDisk;
531     case kWKContextMenuItemTagCopyLinkToClipboard:
532         return WebCore::ContextMenuItemTagCopyLinkToClipboard;
533     case kWKContextMenuItemTagOpenImageInNewWindow:
534         return WebCore::ContextMenuItemTagOpenImageInNewWindow;
535     case kWKContextMenuItemTagDownloadImageToDisk:
536         return WebCore::ContextMenuItemTagDownloadImageToDisk;
537     case kWKContextMenuItemTagCopyImageToClipboard:
538         return WebCore::ContextMenuItemTagCopyImageToClipboard;
539     case kWKContextMenuItemTagOpenFrameInNewWindow:
540 #if PLATFORM(EFL) || PLATFORM(GTK)
541     case kWKContextMenuItemTagCopyImageUrlToClipboard:
542         return WebCore::ContextMenuItemTagCopyImageUrlToClipboard;
543 #endif
544         return WebCore::ContextMenuItemTagOpenFrameInNewWindow;
545     case kWKContextMenuItemTagCopy:
546         return WebCore::ContextMenuItemTagCopy;
547     case kWKContextMenuItemTagGoBack:
548         return WebCore::ContextMenuItemTagGoBack;
549     case kWKContextMenuItemTagGoForward:
550         return WebCore::ContextMenuItemTagGoForward;
551     case kWKContextMenuItemTagStop:
552         return WebCore::ContextMenuItemTagStop;
553     case kWKContextMenuItemTagReload:
554         return WebCore::ContextMenuItemTagReload;
555     case kWKContextMenuItemTagCut:
556         return WebCore::ContextMenuItemTagCut;
557     case kWKContextMenuItemTagPaste:
558         return WebCore::ContextMenuItemTagPaste;
559 #if PLATFORM(EFL) || PLATFORM(GTK)
560     case kWKContextMenuItemTagSelectAll:
561         return WebCore::ContextMenuItemTagSelectAll;
562 #endif
563     case kWKContextMenuItemTagSpellingGuess:
564         return WebCore::ContextMenuItemTagSpellingGuess;
565     case kWKContextMenuItemTagNoGuessesFound:
566         return WebCore::ContextMenuItemTagNoGuessesFound;
567     case kWKContextMenuItemTagIgnoreSpelling:
568         return WebCore::ContextMenuItemTagIgnoreSpelling;
569     case kWKContextMenuItemTagLearnSpelling:
570         return WebCore::ContextMenuItemTagLearnSpelling;
571     case kWKContextMenuItemTagOther:
572         return WebCore::ContextMenuItemTagOther;
573     case kWKContextMenuItemTagSearchInSpotlight:
574         return WebCore::ContextMenuItemTagSearchInSpotlight;
575     case kWKContextMenuItemTagSearchWeb:
576         return WebCore::ContextMenuItemTagSearchWeb;
577     case kWKContextMenuItemTagLookUpInDictionary:
578         return WebCore::ContextMenuItemTagLookUpInDictionary;
579     case kWKContextMenuItemTagOpenWithDefaultApplication:
580         return WebCore::ContextMenuItemTagOpenWithDefaultApplication;
581     case kWKContextMenuItemTagPDFActualSize:
582         return WebCore::ContextMenuItemPDFActualSize;
583     case kWKContextMenuItemTagPDFZoomIn:
584         return WebCore::ContextMenuItemPDFZoomIn;
585     case kWKContextMenuItemTagPDFZoomOut:
586         return WebCore::ContextMenuItemPDFZoomOut;
587     case kWKContextMenuItemTagPDFAutoSize:
588         return WebCore::ContextMenuItemPDFAutoSize;
589     case kWKContextMenuItemTagPDFSinglePage:
590         return WebCore::ContextMenuItemPDFSinglePage;
591     case kWKContextMenuItemTagPDFFacingPages:
592         return WebCore::ContextMenuItemPDFFacingPages;
593     case kWKContextMenuItemTagPDFContinuous:
594         return WebCore::ContextMenuItemPDFContinuous;
595     case kWKContextMenuItemTagPDFNextPage:
596         return WebCore::ContextMenuItemPDFNextPage;
597     case kWKContextMenuItemTagPDFPreviousPage:
598         return WebCore::ContextMenuItemPDFPreviousPage;
599     case kWKContextMenuItemTagOpenLink:
600         return WebCore::ContextMenuItemTagOpenLink;
601     case kWKContextMenuItemTagIgnoreGrammar:
602         return WebCore::ContextMenuItemTagIgnoreGrammar;
603     case kWKContextMenuItemTagSpellingMenu:
604         return WebCore::ContextMenuItemTagSpellingMenu;
605     case kWKContextMenuItemTagShowSpellingPanel:
606         return WebCore::ContextMenuItemTagShowSpellingPanel;
607     case kWKContextMenuItemTagCheckSpelling:
608         return WebCore::ContextMenuItemTagCheckSpelling;
609     case kWKContextMenuItemTagCheckSpellingWhileTyping:
610         return WebCore::ContextMenuItemTagCheckSpellingWhileTyping;
611     case kWKContextMenuItemTagCheckGrammarWithSpelling:
612         return WebCore::ContextMenuItemTagCheckGrammarWithSpelling;
613     case kWKContextMenuItemTagFontMenu:
614         return WebCore::ContextMenuItemTagFontMenu;
615     case kWKContextMenuItemTagShowFonts:
616         return WebCore::ContextMenuItemTagShowFonts;
617     case kWKContextMenuItemTagBold:
618         return WebCore::ContextMenuItemTagBold;
619     case kWKContextMenuItemTagItalic:
620         return WebCore::ContextMenuItemTagItalic;
621     case kWKContextMenuItemTagUnderline:
622         return WebCore::ContextMenuItemTagUnderline;
623     case kWKContextMenuItemTagOutline:
624         return WebCore::ContextMenuItemTagOutline;
625     case kWKContextMenuItemTagStyles:
626         return WebCore::ContextMenuItemTagStyles;
627     case kWKContextMenuItemTagShowColors:
628         return WebCore::ContextMenuItemTagShowColors;
629     case kWKContextMenuItemTagSpeechMenu:
630         return WebCore::ContextMenuItemTagSpeechMenu;
631     case kWKContextMenuItemTagStartSpeaking:
632         return WebCore::ContextMenuItemTagStartSpeaking;
633     case kWKContextMenuItemTagStopSpeaking:
634         return WebCore::ContextMenuItemTagStopSpeaking;
635     case kWKContextMenuItemTagWritingDirectionMenu:
636         return WebCore::ContextMenuItemTagWritingDirectionMenu;
637     case kWKContextMenuItemTagDefaultDirection:
638         return WebCore::ContextMenuItemTagDefaultDirection;
639     case kWKContextMenuItemTagLeftToRight:
640         return WebCore::ContextMenuItemTagLeftToRight;
641     case kWKContextMenuItemTagRightToLeft:
642         return WebCore::ContextMenuItemTagRightToLeft;
643     case kWKContextMenuItemTagPDFSinglePageScrolling:
644         return WebCore::ContextMenuItemTagPDFSinglePageScrolling;
645     case kWKContextMenuItemTagPDFFacingPagesScrolling:
646         return WebCore::ContextMenuItemTagPDFFacingPagesScrolling;
647     case kWKContextMenuItemTagDictationAlternative:
648         return WebCore::ContextMenuItemTagDictationAlternative;
649 #if ENABLE(INSPECTOR)
650     case kWKContextMenuItemTagInspectElement:
651         return WebCore::ContextMenuItemTagInspectElement;
652 #endif
653     case kWKContextMenuItemTagTextDirectionMenu:
654         return WebCore::ContextMenuItemTagTextDirectionMenu;
655     case kWKContextMenuItemTagTextDirectionDefault:
656         return WebCore::ContextMenuItemTagTextDirectionDefault;
657     case kWKContextMenuItemTagTextDirectionLeftToRight:
658         return WebCore::ContextMenuItemTagTextDirectionLeftToRight;
659     case kWKContextMenuItemTagTextDirectionRightToLeft:
660         return WebCore::ContextMenuItemTagTextDirectionRightToLeft;
661     case kWKContextMenuItemTagOpenMediaInNewWindow:
662         return WebCore::ContextMenuItemTagOpenMediaInNewWindow;
663     case kWKContextMenuItemTagDownloadMediaToDisk:
664         return WebCore::ContextMenuItemTagDownloadMediaToDisk;
665     case kWKContextMenuItemTagCopyMediaLinkToClipboard:
666         return WebCore::ContextMenuItemTagCopyMediaLinkToClipboard;
667     case kWKContextMenuItemTagToggleMediaControls:
668         return WebCore::ContextMenuItemTagToggleMediaControls;
669     case kWKContextMenuItemTagToggleMediaLoop:
670         return WebCore::ContextMenuItemTagToggleMediaLoop;
671     case kWKContextMenuItemTagToggleVideoFullscreen:
672         return WebCore::ContextMenuItemTagToggleVideoFullscreen;
673     case kWKContextMenuItemTagEnterVideoFullscreen:
674         return WebCore::ContextMenuItemTagEnterVideoFullscreen;
675     case kWKContextMenuItemTagMediaPlayPause:
676         return WebCore::ContextMenuItemTagMediaPlayPause;
677     case kWKContextMenuItemTagMediaMute:
678         return WebCore::ContextMenuItemTagMediaMute;
679 #if PLATFORM(MAC)
680     case kWKContextMenuItemTagCorrectSpellingAutomatically:
681         return WebCore::ContextMenuItemTagCorrectSpellingAutomatically;
682     case kWKContextMenuItemTagSubstitutionsMenu:
683         return WebCore::ContextMenuItemTagSubstitutionsMenu;
684     case kWKContextMenuItemTagShowSubstitutions:
685         return WebCore::ContextMenuItemTagShowSubstitutions;
686     case kWKContextMenuItemTagSmartCopyPaste:
687         return WebCore::ContextMenuItemTagSmartCopyPaste;
688     case kWKContextMenuItemTagSmartQuotes:
689         return WebCore::ContextMenuItemTagSmartQuotes;
690     case kWKContextMenuItemTagSmartDashes:
691         return WebCore::ContextMenuItemTagSmartDashes;
692     case kWKContextMenuItemTagSmartLinks:
693         return WebCore::ContextMenuItemTagSmartLinks;
694     case kWKContextMenuItemTagTextReplacement:
695         return WebCore::ContextMenuItemTagTextReplacement;
696     case kWKContextMenuItemTagTransformationsMenu:
697         return WebCore::ContextMenuItemTagTransformationsMenu;
698     case kWKContextMenuItemTagMakeUpperCase:
699         return WebCore::ContextMenuItemTagMakeUpperCase;
700     case kWKContextMenuItemTagMakeLowerCase:
701         return WebCore::ContextMenuItemTagMakeLowerCase;
702     case kWKContextMenuItemTagCapitalize:
703         return WebCore::ContextMenuItemTagCapitalize;
704     case kWKContextMenuItemTagChangeBack:
705         return WebCore::ContextMenuItemTagChangeBack;
706 #endif
707     case kWKContextMenuItemTagOpenLinkInThisWindow:
708         return WebCore::ContextMenuItemTagOpenLinkInThisWindow;
709     default:
710         if (tag < kWKContextMenuItemBaseApplicationTag)
711             LOG_ERROR("WKContextMenuItemTag %i is an unknown tag but is below the allowable custom tag value of %i", tag, kWKContextMenuItemBaseApplicationTag);
712         return static_cast<WebCore::ContextMenuAction>(tag);
713     }
714 }
715
716 inline WKContextMenuItemType toAPI(WebCore::ContextMenuItemType type)
717 {
718     switch(type) {
719     case WebCore::ActionType:
720         return kWKContextMenuItemTypeAction;
721     case WebCore::CheckableActionType:
722         return kWKContextMenuItemTypeCheckableAction;
723     case WebCore::SeparatorType:
724         return kWKContextMenuItemTypeSeparator;
725     case WebCore::SubmenuType:
726         return kWKContextMenuItemTypeSubmenu;
727     default:
728         ASSERT_NOT_REACHED();
729         return kWKContextMenuItemTypeAction;
730     }
731 }
732
733 inline FindOptions toFindOptions(WKFindOptions wkFindOptions)
734 {
735     unsigned findOptions = 0;
736
737     if (wkFindOptions & kWKFindOptionsCaseInsensitive)
738         findOptions |= FindOptionsCaseInsensitive;
739     if (wkFindOptions & kWKFindOptionsAtWordStarts)
740         findOptions |= FindOptionsAtWordStarts;
741     if (wkFindOptions & kWKFindOptionsTreatMedialCapitalAsWordStart)
742         findOptions |= FindOptionsTreatMedialCapitalAsWordStart;
743     if (wkFindOptions & kWKFindOptionsBackwards)
744         findOptions |= FindOptionsBackwards;
745     if (wkFindOptions & kWKFindOptionsWrapAround)
746         findOptions |= FindOptionsWrapAround;
747     if (wkFindOptions & kWKFindOptionsShowOverlay)
748         findOptions |= FindOptionsShowOverlay;
749     if (wkFindOptions & kWKFindOptionsShowFindIndicator)
750         findOptions |= FindOptionsShowFindIndicator;
751     if (wkFindOptions & kWKFindOptionsShowHighlight)
752         findOptions |= FindOptionsShowHighlight;
753
754     return static_cast<FindOptions>(findOptions);
755 }
756
757 inline WKFrameNavigationType toAPI(WebCore::NavigationType type)
758 {
759     WKFrameNavigationType wkType = kWKFrameNavigationTypeOther;
760
761     switch (type) {
762     case WebCore::NavigationTypeLinkClicked:
763         wkType = kWKFrameNavigationTypeLinkClicked;
764         break;
765     case WebCore::NavigationTypeFormSubmitted:
766         wkType = kWKFrameNavigationTypeFormSubmitted;
767         break;
768     case WebCore::NavigationTypeBackForward:
769         wkType = kWKFrameNavigationTypeBackForward;
770         break;
771     case WebCore::NavigationTypeReload:
772         wkType = kWKFrameNavigationTypeReload;
773         break;
774     case WebCore::NavigationTypeFormResubmitted:
775         wkType = kWKFrameNavigationTypeFormResubmitted;
776         break;
777     case WebCore::NavigationTypeOther:
778         wkType = kWKFrameNavigationTypeOther;
779         break;
780     }
781     
782     return wkType;
783 }
784
785 inline WKSameDocumentNavigationType toAPI(SameDocumentNavigationType type)
786 {
787     WKFrameNavigationType wkType = kWKSameDocumentNavigationAnchorNavigation;
788
789     switch (type) {
790     case SameDocumentNavigationAnchorNavigation:
791         wkType = kWKSameDocumentNavigationAnchorNavigation;
792         break;
793     case SameDocumentNavigationSessionStatePush:
794         wkType = kWKSameDocumentNavigationSessionStatePush;
795         break;
796     case SameDocumentNavigationSessionStateReplace:
797         wkType = kWKSameDocumentNavigationSessionStateReplace;
798         break;
799     case SameDocumentNavigationSessionStatePop:
800         wkType = kWKSameDocumentNavigationSessionStatePop;
801         break;
802     }
803     
804     return wkType;
805 }
806
807 inline WKLayoutMilestones toWKLayoutMilestones(WebCore::LayoutMilestones milestones)
808 {
809     unsigned wkMilestones = 0;
810
811     if (milestones & WebCore::DidFirstLayout)
812         wkMilestones |= kWKDidFirstLayout;
813     if (milestones & WebCore::DidFirstVisuallyNonEmptyLayout)
814         wkMilestones |= kWKDidFirstVisuallyNonEmptyLayout;
815     if (milestones & WebCore::DidHitRelevantRepaintedObjectsAreaThreshold)
816         wkMilestones |= kWKDidHitRelevantRepaintedObjectsAreaThreshold;
817     if (milestones & WebCore::DidFirstFlushForHeaderLayer)
818         wkMilestones |= kWKDidFirstFlushForHeaderLayer;
819     if (milestones & WebCore::DidFirstLayoutAfterSuppressedIncrementalRendering)
820         wkMilestones |= kWKDidFirstLayoutAfterSuppressedIncrementalRendering;
821     if (milestones & WebCore::DidFirstPaintAfterSuppressedIncrementalRendering)
822         wkMilestones |= kWKDidFirstPaintAfterSuppressedIncrementalRendering;
823     
824     return wkMilestones;
825 }
826
827 inline WebCore::LayoutMilestones toLayoutMilestones(WKLayoutMilestones wkMilestones)
828 {
829     WebCore::LayoutMilestones milestones = 0;
830
831     if (wkMilestones & kWKDidFirstLayout)
832         milestones |= WebCore::DidFirstLayout;
833     if (wkMilestones & kWKDidFirstVisuallyNonEmptyLayout)
834         milestones |= WebCore::DidFirstVisuallyNonEmptyLayout;
835     if (wkMilestones & kWKDidHitRelevantRepaintedObjectsAreaThreshold)
836         milestones |= WebCore::DidHitRelevantRepaintedObjectsAreaThreshold;
837     if (wkMilestones & kWKDidFirstFlushForHeaderLayer)
838         milestones |= WebCore::DidFirstFlushForHeaderLayer;
839     if (wkMilestones & kWKDidFirstLayoutAfterSuppressedIncrementalRendering)
840         milestones |= WebCore::DidFirstLayoutAfterSuppressedIncrementalRendering;
841     if (wkMilestones & kWKDidFirstPaintAfterSuppressedIncrementalRendering)
842         milestones |= WebCore::DidFirstPaintAfterSuppressedIncrementalRendering;
843     
844     return milestones;
845 }
846
847 inline WebCore::PageVisibilityState toPageVisibilityState(WKPageVisibilityState wkPageVisibilityState)
848 {
849     switch (wkPageVisibilityState) {
850     case kWKPageVisibilityStateVisible:
851         return WebCore::PageVisibilityStateVisible;
852     case kWKPageVisibilityStateHidden:
853         return WebCore::PageVisibilityStateHidden;
854     case kWKPageVisibilityStatePrerender:
855         return WebCore::PageVisibilityStatePrerender;
856     }
857
858     ASSERT_NOT_REACHED();
859     return WebCore::PageVisibilityStateVisible;
860 }
861
862 inline ImageOptions toImageOptions(WKImageOptions wkImageOptions)
863 {
864     unsigned imageOptions = 0;
865
866     if (wkImageOptions & kWKImageOptionsShareable)
867         imageOptions |= ImageOptionsShareable;
868
869     return static_cast<ImageOptions>(imageOptions);
870 }
871
872 inline SnapshotOptions snapshotOptionsFromImageOptions(WKImageOptions wkImageOptions)
873 {
874     unsigned snapshotOptions = 0;
875
876     if (wkImageOptions & kWKImageOptionsShareable)
877         snapshotOptions |= SnapshotOptionsShareable;
878
879     return snapshotOptions;
880 }
881
882 inline SnapshotOptions toSnapshotOptions(WKSnapshotOptions wkSnapshotOptions)
883 {
884     unsigned snapshotOptions = 0;
885
886     if (wkSnapshotOptions & kWKSnapshotOptionsShareable)
887         snapshotOptions |= SnapshotOptionsShareable;
888     if (wkSnapshotOptions & kWKSnapshotOptionsExcludeSelectionHighlighting)
889         snapshotOptions |= SnapshotOptionsExcludeSelectionHighlighting;
890     if (wkSnapshotOptions & kWKSnapshotOptionsInViewCoordinates)
891         snapshotOptions |= SnapshotOptionsInViewCoordinates;
892     if (wkSnapshotOptions & kWKSnapshotOptionsPaintSelectionRectangle)
893         snapshotOptions |= SnapshotOptionsPaintSelectionRectangle;
894
895     return snapshotOptions;
896 }
897
898 inline WebCore::UserScriptInjectionTime toUserScriptInjectionTime(WKUserScriptInjectionTime wkInjectedTime)
899 {
900     switch (wkInjectedTime) {
901     case kWKInjectAtDocumentStart:
902         return WebCore::InjectAtDocumentStart;
903     case kWKInjectAtDocumentEnd:
904         return WebCore::InjectAtDocumentEnd;
905     }
906
907     ASSERT_NOT_REACHED();
908     return WebCore::InjectAtDocumentStart;
909 }
910
911 inline WebCore::UserContentInjectedFrames toUserContentInjectedFrames(WKUserContentInjectedFrames wkInjectedFrames)
912 {
913     switch (wkInjectedFrames) {
914     case kWKInjectInAllFrames:
915         return WebCore::InjectInAllFrames;
916     case kWKInjectInTopFrameOnly:
917         return WebCore::InjectInTopFrameOnly;
918     }
919
920     ASSERT_NOT_REACHED();
921     return WebCore::InjectInAllFrames;
922 }
923
924 } // namespace WebKit
925
926 #endif // WKSharedAPICast_h