Make WebCore::EditorInsertAction an enum class
[WebKit-https.git] / Source / WebKit2 / WebProcess / InjectedBundle / API / c / WKBundleAPICast.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 #pragma once
27
28 #include "WKSharedAPICast.h"
29 #include "WKBundlePage.h"
30 #include "WKBundlePagePrivate.h"
31 #include "WKBundlePrivate.h"
32 #include <WebCore/EditorInsertAction.h>
33 #include <WebCore/TextAffinity.h>
34
35 namespace WebKit {
36
37 class InjectedBundle;
38 class InjectedBundleBackForwardList;
39 class InjectedBundleBackForwardListItem;
40 class InjectedBundleCSSStyleDeclarationHandle;
41 class InjectedBundleDOMWindowExtension;
42 class InjectedBundleFileHandle;
43 class InjectedBundleHitTestResult;
44 class InjectedBundleNavigationAction;
45 class InjectedBundleNodeHandle;
46 class InjectedBundleRangeHandle;
47 class InjectedBundleScriptWorld;
48 class PageBanner;
49 class WebFrame;
50 class WebInspector;
51 class WebPage;
52 class WebPageGroupProxy;
53 class WebPageOverlay;
54
55 WK_ADD_API_MAPPING(WKBundleBackForwardListItemRef, InjectedBundleBackForwardListItem)
56 WK_ADD_API_MAPPING(WKBundleBackForwardListRef, InjectedBundleBackForwardList)
57 WK_ADD_API_MAPPING(WKBundleCSSStyleDeclarationRef, InjectedBundleCSSStyleDeclarationHandle)
58 WK_ADD_API_MAPPING(WKBundleDOMWindowExtensionRef, InjectedBundleDOMWindowExtension)
59 WK_ADD_API_MAPPING(WKBundleFileHandleRef, InjectedBundleFileHandle)
60 WK_ADD_API_MAPPING(WKBundleFrameRef, WebFrame)
61 WK_ADD_API_MAPPING(WKBundleHitTestResultRef, InjectedBundleHitTestResult)
62 WK_ADD_API_MAPPING(WKBundleInspectorRef, WebInspector)
63 WK_ADD_API_MAPPING(WKBundleNavigationActionRef, InjectedBundleNavigationAction)
64 WK_ADD_API_MAPPING(WKBundleNodeHandleRef, InjectedBundleNodeHandle)
65 WK_ADD_API_MAPPING(WKBundlePageBannerRef, PageBanner)
66 WK_ADD_API_MAPPING(WKBundlePageGroupRef, WebPageGroupProxy)
67 WK_ADD_API_MAPPING(WKBundlePageOverlayRef, WebPageOverlay)
68 WK_ADD_API_MAPPING(WKBundlePageRef, WebPage)
69 WK_ADD_API_MAPPING(WKBundleRangeHandleRef, InjectedBundleRangeHandle)
70 WK_ADD_API_MAPPING(WKBundleRef, InjectedBundle)
71 WK_ADD_API_MAPPING(WKBundleScriptWorldRef, InjectedBundleScriptWorld)
72
73 inline WKInsertActionType toAPI(WebCore::EditorInsertAction action)
74 {
75     switch (action) {
76     case WebCore::EditorInsertAction::Typed:
77         return kWKInsertActionTyped;
78     case WebCore::EditorInsertAction::Pasted:
79         return kWKInsertActionPasted;
80     case WebCore::EditorInsertAction::Dropped:
81         return kWKInsertActionDropped;
82     }
83     ASSERT_NOT_REACHED();
84     return kWKInsertActionTyped;
85 }
86
87 inline WKAffinityType toAPI(WebCore::EAffinity affinity)
88 {
89     switch (affinity) {
90     case WebCore::UPSTREAM:
91         return kWKAffinityUpstream;
92     case WebCore::DOWNSTREAM:
93         return kWKAffinityDownstream;
94     }
95     ASSERT_NOT_REACHED();
96     return kWKAffinityUpstream;
97 }
98
99 } // namespace WebKit