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 WKBundleAPICast_h
27#define WKBundleAPICast_h
28
29#include "WKSharedAPICast.h"
30#include "WKBundlePage.h"
31#include "WKBundlePagePrivate.h"
32#include "WKBundlePrivate.h"
33#include <WebCore/EditorInsertAction.h>
34#include <WebCore/TextAffinity.h>
35#include <WebCore/UserContentTypes.h>
36#include <WebCore/UserScriptTypes.h>
37
38namespace WebCore {
39    class CSSStyleDeclaration;
40}
41
42namespace WebKit {
43
44class InjectedBundle;
45class InjectedBundleBackForwardList;
46class InjectedBundleBackForwardListItem;
47class InjectedBundleHitTestResult;
48class InjectedBundleNavigationAction;
49class InjectedBundleNodeHandle;
50class InjectedBundleRangeHandle;
51class InjectedBundleScriptWorld;
52class PageOverlay;
53class WebFrame;
54class WebInspector;
55class WebPage;
56class WebPageGroupProxy;
57
58WK_ADD_API_MAPPING(WKBundleBackForwardListItemRef, InjectedBundleBackForwardListItem)
59WK_ADD_API_MAPPING(WKBundleBackForwardListRef, InjectedBundleBackForwardList)
60WK_ADD_API_MAPPING(WKBundleCSSStyleDeclarationRef, WebCore::CSSStyleDeclaration)
61WK_ADD_API_MAPPING(WKBundleFrameRef, WebFrame)
62WK_ADD_API_MAPPING(WKBundleHitTestResultRef, InjectedBundleHitTestResult)
63WK_ADD_API_MAPPING(WKBundleInspectorRef, WebInspector)
64WK_ADD_API_MAPPING(WKBundleNavigationActionRef, InjectedBundleNavigationAction)
65WK_ADD_API_MAPPING(WKBundleNodeHandleRef, InjectedBundleNodeHandle)
66WK_ADD_API_MAPPING(WKBundlePageGroupRef, WebPageGroupProxy)
67WK_ADD_API_MAPPING(WKBundlePageOverlayRef, PageOverlay)
68WK_ADD_API_MAPPING(WKBundlePageRef, WebPage)
69WK_ADD_API_MAPPING(WKBundleRangeHandleRef, InjectedBundleRangeHandle)
70WK_ADD_API_MAPPING(WKBundleRef, InjectedBundle)
71WK_ADD_API_MAPPING(WKBundleScriptWorldRef, InjectedBundleScriptWorld)
72
73inline WKInsertActionType toAPI(WebCore::EditorInsertAction action)
74{
75    switch (action) {
76    case WebCore::EditorInsertActionTyped:
77        return kWKInsertActionTyped;
78        break;
79    case WebCore::EditorInsertActionPasted:
80        return kWKInsertActionPasted;
81        break;
82    case WebCore::EditorInsertActionDropped:
83        return kWKInsertActionDropped;
84        break;
85    }
86    ASSERT_NOT_REACHED();
87    return kWKInsertActionTyped;
88}
89
90inline WKAffinityType toAPI(WebCore::EAffinity affinity)
91{
92    switch (affinity) {
93    case WebCore::UPSTREAM:
94        return kWKAffinityUpstream;
95        break;
96    case WebCore::DOWNSTREAM:
97        return kWKAffinityDownstream;
98        break;
99    }
100    ASSERT_NOT_REACHED();
101    return kWKAffinityUpstream;
102}
103
104inline WebCore::UserScriptInjectionTime toUserScriptInjectionTime(WKUserScriptInjectionTime wkInjectedTime)
105{
106    switch (wkInjectedTime) {
107    case kWKInjectAtDocumentStart:
108        return WebCore::InjectAtDocumentStart;
109    case kWKInjectAtDocumentEnd:
110        return WebCore::InjectAtDocumentEnd;
111    }
112
113    ASSERT_NOT_REACHED();
114    return WebCore::InjectAtDocumentStart;
115}
116
117inline WebCore::UserContentInjectedFrames toUserContentInjectedFrames(WKUserContentInjectedFrames wkInjectedFrames)
118{
119    switch (wkInjectedFrames) {
120    case kWKInjectInAllFrames:
121        return WebCore::InjectInAllFrames;
122    case kWKInjectInTopFrameOnly:
123        return WebCore::InjectInTopFrameOnly;
124    }
125
126    ASSERT_NOT_REACHED();
127    return WebCore::InjectInAllFrames;
128}
129
130} // namespace WebKit
131
132#endif // WKBundleAPICast_h
133