~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit2/Shared/API/c/WKSharedAPICast.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

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