1/*
2 * Copyright (C) 2013 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 WKBundlePageEditorClient_h
27#define WKBundlePageEditorClient_h
28
29#include <WebKit/WKBase.h>
30
31enum {
32    kWKInsertActionTyped = 0,
33    kWKInsertActionPasted = 1,
34    kWKInsertActionDropped = 2
35};
36typedef uint32_t WKInsertActionType;
37
38enum {
39    kWKAffinityUpstream,
40    kWKAffinityDownstream
41};
42typedef uint32_t WKAffinityType;
43
44enum {
45    WKInputFieldActionTypeMoveUp,
46    WKInputFieldActionTypeMoveDown,
47    WKInputFieldActionTypeCancel,
48    WKInputFieldActionTypeInsertTab,
49    WKInputFieldActionTypeInsertBacktab,
50    WKInputFieldActionTypeInsertNewline,
51    WKInputFieldActionTypeInsertDelete
52};
53typedef uint32_t WKInputFieldActionType;
54
55enum {
56    WKFullScreenNoKeyboard,
57    WKFullScreenKeyboard,
58};
59typedef uint32_t WKFullScreenKeyboardRequestType;
60
61typedef bool (*WKBundlePageShouldBeginEditingCallback)(WKBundlePageRef page, WKBundleRangeHandleRef range, const void* clientInfo);
62typedef bool (*WKBundlePageShouldEndEditingCallback)(WKBundlePageRef page, WKBundleRangeHandleRef range, const void* clientInfo);
63typedef bool (*WKBundlePageShouldInsertNodeCallback)(WKBundlePageRef page, WKBundleNodeHandleRef node, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType action, const void* clientInfo);
64typedef bool (*WKBundlePageShouldInsertTextCallback)(WKBundlePageRef page, WKStringRef string, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType action, const void* clientInfo);
65typedef bool (*WKBundlePageShouldDeleteRangeCallback)(WKBundlePageRef page, WKBundleRangeHandleRef range, const void* clientInfo);
66typedef bool (*WKBundlePageShouldChangeSelectedRange)(WKBundlePageRef page, WKBundleRangeHandleRef fromRange, WKBundleRangeHandleRef toRange, WKAffinityType affinity, bool stillSelecting, const void* clientInfo);
67typedef bool (*WKBundlePageShouldApplyStyle)(WKBundlePageRef page, WKBundleCSSStyleDeclarationRef style, WKBundleRangeHandleRef range, const void* clientInfo);
68typedef void (*WKBundlePageEditingNotification)(WKBundlePageRef page, WKStringRef notificationName, const void* clientInfo);
69typedef void (*WKBundlePageWillWriteToPasteboard)(WKBundlePageRef page, WKBundleRangeHandleRef range,  const void* clientInfo);
70typedef void (*WKBundlePageGetPasteboardDataForRange)(WKBundlePageRef page, WKBundleRangeHandleRef range, WKArrayRef* pasteboardTypes, WKArrayRef* pasteboardData, const void* clientInfo);
71typedef void (*WKBundlePageDidWriteToPasteboard)(WKBundlePageRef page, const void* clientInfo);
72
73typedef struct WKBundlePageEditorClientBase {
74    int                                                                 version;
75    const void *                                                        clientInfo;
76} WKBundlePageEditorClientBase;
77
78typedef struct WKBundlePageEditorClientV0 {
79    WKBundlePageEditorClientBase                                        base;
80
81    // Version 0.
82    WKBundlePageShouldBeginEditingCallback                              shouldBeginEditing;
83    WKBundlePageShouldEndEditingCallback                                shouldEndEditing;
84    WKBundlePageShouldInsertNodeCallback                                shouldInsertNode;
85    WKBundlePageShouldInsertTextCallback                                shouldInsertText;
86    WKBundlePageShouldDeleteRangeCallback                               shouldDeleteRange;
87    WKBundlePageShouldChangeSelectedRange                               shouldChangeSelectedRange;
88    WKBundlePageShouldApplyStyle                                        shouldApplyStyle;
89    WKBundlePageEditingNotification                                     didBeginEditing;
90    WKBundlePageEditingNotification                                     didEndEditing;
91    WKBundlePageEditingNotification                                     didChange;
92    WKBundlePageEditingNotification                                     didChangeSelection;
93} WKBundlePageEditorClientV0;
94
95typedef struct WKBundlePageEditorClientV1 {
96    WKBundlePageEditorClientBase                                        base;
97
98    // Version 0.
99    WKBundlePageShouldBeginEditingCallback                              shouldBeginEditing;
100    WKBundlePageShouldEndEditingCallback                                shouldEndEditing;
101    WKBundlePageShouldInsertNodeCallback                                shouldInsertNode;
102    WKBundlePageShouldInsertTextCallback                                shouldInsertText;
103    WKBundlePageShouldDeleteRangeCallback                               shouldDeleteRange;
104    WKBundlePageShouldChangeSelectedRange                               shouldChangeSelectedRange;
105    WKBundlePageShouldApplyStyle                                        shouldApplyStyle;
106    WKBundlePageEditingNotification                                     didBeginEditing;
107    WKBundlePageEditingNotification                                     didEndEditing;
108    WKBundlePageEditingNotification                                     didChange;
109    WKBundlePageEditingNotification                                     didChangeSelection;
110
111    // Version 1.
112    WKBundlePageWillWriteToPasteboard                                   willWriteToPasteboard;
113    WKBundlePageGetPasteboardDataForRange                               getPasteboardDataForRange;
114    WKBundlePageDidWriteToPasteboard                                    didWriteToPasteboard;
115} WKBundlePageEditorClientV1;
116
117enum { kWKBundlePageEditorClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 1 };
118typedef struct WKBundlePageEditorClient {
119    int                                                                 version;
120    const void *                                                        clientInfo;
121
122    // Version 0.
123    WKBundlePageShouldBeginEditingCallback                              shouldBeginEditing;
124    WKBundlePageShouldEndEditingCallback                                shouldEndEditing;
125    WKBundlePageShouldInsertNodeCallback                                shouldInsertNode;
126    WKBundlePageShouldInsertTextCallback                                shouldInsertText;
127    WKBundlePageShouldDeleteRangeCallback                               shouldDeleteRange;
128    WKBundlePageShouldChangeSelectedRange                               shouldChangeSelectedRange;
129    WKBundlePageShouldApplyStyle                                        shouldApplyStyle;
130    WKBundlePageEditingNotification                                     didBeginEditing;
131    WKBundlePageEditingNotification                                     didEndEditing;
132    WKBundlePageEditingNotification                                     didChange;
133    WKBundlePageEditingNotification                                     didChangeSelection;
134
135    // Version 1.
136    WKBundlePageWillWriteToPasteboard                                   willWriteToPasteboard;
137    WKBundlePageGetPasteboardDataForRange                               getPasteboardDataForRange;
138    WKBundlePageDidWriteToPasteboard                                    didWriteToPasteboard;
139} WKBundlePageEditorClient WK_DEPRECATED("Use an explicit versioned struct instead");
140
141#endif // WKBundlePageEditorClient_h
142