1 module awebview.wrapper.webview;
2 
3 public import awebview.wrapper.cpp : WebViewType, MouseButton;
4 import awebview.wrapper.cpp;
5 import awebview.wrapper.weburl : WebURL;
6 import awebview.wrapper.webstring : WebString;
7 import awebview.wrapper.webstring;
8 import awebview.wrapper.jsvalue : JSValue;
9 import awebview.wrapper.jsobject : JSObject, JSMethodHandler;
10 import awebview.wrapper.weakref;
11 import awebview.wrapper.surface : Surface;
12 
13 import std.traits;
14 
15 
16 struct WebView
17 {
18     this(awebview.wrapper.cpp.WebView cppObj)
19     {
20         _cppObj = cppObj;
21     }
22 
23 
24     @property
25     inout(awebview.wrapper.cpp.WebView) cppObj() inout pure nothrow @safe @nogc
26     { return _cppObj; }
27 
28 
29     void destroy() { WebViewMember.Destroy(_cppObj); }
30 
31     @property
32     WebViewType type() { return WebViewMember.type(_cppObj); }
33 
34     @property
35     int processId() { return WebViewMember.process_id(_cppObj); }
36 
37     @property
38     int routingId() { return WebViewMember.routing_id(_cppObj); }
39 
40     @property
41     int nextRoutingId() { return WebViewMember.next_routing_id(_cppObj); }
42 
43     @property
44     ProcessHandle processHandle() { return WebViewMember.process_handle(_cppObj); }
45 
46     @property
47     void parentWindow(NativeWindow parent)
48     { WebViewMember.set_parent_window(_cppObj, parent); }
49 
50     @property
51     NativeWindow parentWindow()
52     { return WebViewMember.parent_window(_cppObj); }
53 
54     @property
55     NativeWindow window() { return WebViewMember.window(_cppObj); }
56 
57     void setViewListener(Awesomium.WebViewListener.View vl)
58     { WebViewMember.set_view_listener(_cppObj, vl); }
59 
60     //void setLoadListener(Awesomium.WebViewListener.Load);
61     //void setProcessListener(Awesomium.WebViewListener.Process);
62 
63     void setMenuListener(Awesomium.WebViewListener.Menu ml)
64     { WebViewMember.set_menu_listener(_cppObj, ml); }
65 
66     //void setDialogListener(Awesomium.WebViewListener.Dialog);
67     //void setPrintListener(Awesomium.WebViewListener.Print);
68     //void setDonwloadListener(Awesomium.WebViewListener.Download);
69     //void setInputMethodEditorListener(Awesomium.WebViewListener.InputMethodEditor);
70     //Awesomium.WebViewListener.View viewListener();
71     //Awesomium.WebViewListener.Load loadListener();
72     //Awesomium.WebViewListener.Process processListener();
73     //Awesomium.WebViewListener.Menu menuListener();
74     //Awesomium.WebViewListener.Dialog dialogListener();
75     //Awesomium.WebViewListener.Print printListener();
76     //Awesomium.WebViewListener.Download downloadListener();
77     //Awesomium.WebViewListener.InputMethodEditor inputMethodEditorListener();
78 
79 
80     void loadURL(in WebURL url) nothrow @nogc
81     {
82         WebViewMember.LoadURL(_cppObj, url.cppObj);
83     }
84 
85     //void goBack();
86     //void goForward();
87     //void goToHistoryOffset(int);
88     //void stop();
89     //void reload(bool);
90     //bool canGoBack();
91     //bool canGoForward();
92 
93 
94     Surface surface() nothrow @nogc @property
95     {
96         return Surface(WebViewMember.surface(_cppObj));
97     }
98 
99 
100     //void getUrl(Awesomium.WebURL);
101     //void getTitle(Awesomium.WebString);
102     //WebSession session();
103 
104     @property
105     bool isLoading() nothrow @nogc
106     {
107         return WebViewMember.IsLoading(_cppObj);
108     }
109 
110 
111     //bool isCrashed();
112     void resize(int w, int h) nothrow @nogc
113     {
114         WebViewMember.Resize(_cppObj, w, h);
115     }
116 
117     //void setTransparent(bool);
118     //bool isTransparent();
119     //void pauseRendering();
120     //void resumeRendering();
121     //void focus();
122     //void unfocus();
123     //FocusedElementType focusedElementType();
124     //void zoomIn();
125     //void zoomOut();
126     //void setZoom(int);
127     //void resetZoom();
128     //int getZoom();
129     //void injectMouseMove(int, int);
130     //void injectMouseDown(MouseButton);
131     //void injectMouseUp(MouseButton);
132     //void injectMouseWheel(int, int);
133     //void injectKeyboardEvent(const WebKeyboardEvent*);
134     //void injectTouchEvent(const WebTouchEvent*);
135     //void activateIME(bool);
136     //void setIMEComposition(const Awesomium.WebString, int, int, int);
137     //void confirmIMEComposition(const Awesomium.WebString);
138     //void cancelIMEComposition();
139     //void undo();
140     //void redo();
141     //void cut();
142     //void copy();
143     //void copyImageAt(int, int);
144     //void paste();
145     //void pasteAndMatchStyle();
146     //void selectAll();
147     //int printToFile(const Awesomium.WebString, const PrintConfig*);
148     //Awesomium.Error lastError() const;
149     JSValue createGlobalJSObject(WebString name)
150     {
151         JSValue dst;
152         WebViewMember.CreateGlobalJavascriptObject(_cppObj, name.cppObj, dst.cppObj);
153         return dst;
154     }
155 
156 
157     void executeJS(const awebview.wrapper.cpp.WebString script, const awebview.wrapper.cpp.WebString frameXPath)
158     {
159         WebViewMember.ExecuteJavascript(_cppObj, script, frameXPath);
160     }
161 
162 
163     void executeJS(S1, S2)(S1 script, S2 frameXpath)
164     if(hasCppWebString!S1 && hasCppWebString!S2)
165     {
166         WebViewMember.ExecuteJavascript(_cppObj, script.cppObj, frameXPath.cppObj);
167     }
168 
169 
170     void executeJS(S1, S2)(S1 script, S2 frameXPath)
171     if(isSomeString!S1 && isSomeString!S2)
172     {
173         WebStringCpp s = script;
174         WebStringCpp f = frameXPath;
175         WebViewMember.ExecuteJavascript(_cppObj, s.cppObj, f.cppObj);
176     }
177 
178 
179     JSValue executeJSWithRV(const Awesomium.WebString script, const Awesomium.WebString frameXPath)
180     {
181         JSValue jv;
182         WebViewMember.ExecuteJavascriptWithResult(_cppObj, script, frameXPath, jv.cppObj);
183         return jv;
184     }
185 
186 
187     JSValue executeJSWithRV(S1, S2)(S1 script, S2 frameXPath)
188     if(hasCppWebString!S1 && hasCppWebString!S2)
189     {
190         return executeJSWithRV(script.cppObj, frameXPath.cppObj);
191     }
192 
193 
194     JSValue executeJSWithRV(S1, S2)(S1 script, S2 frameXPath)
195     if(isSomeString!S1 && isSomeString!S2)
196     {
197         WebString ws1 = script;
198         WebString ws2 = frameXPath;
199         return executeJSWithRV(ws1, ws2);
200     }
201 
202 
203     @property
204     void jsMethodHandler(awebview.wrapper.cpp.JSMethodHandler h)
205     {
206         WebViewMember.set_js_method_handler(_cppObj, h);
207     }
208 
209 
210     @property
211     void jsMethodHandler(JSMethodHandler h)
212     {
213         jsMethodHandler = h.cppObj;
214     }
215 
216     //Awesomium.JSMethodHandler jsMethodHandler();
217     //void setSyncMessageTimeout(int);
218     //int syncMessageTimeout();
219     //void didSelectPopupMenuItem(int);
220     //void didCancelPopupMenu();
221     //void didChooseFiles(const Awesomium.WebStringArray, bool);
222     //void didLogin(int, const Awesomium.WebString, const Awesomium.WebString);
223     //void didCancelLogin(int);
224     //void didChooseDownloadPath(int, const Awesomium.WebString);
225     //void didCancelDownload(int);
226     //void didOverrideCertificateError();
227     //void requestPageInfo();
228     //void reduceMemoryUsage();
229 
230 
231   private:
232     awebview.wrapper.cpp.WebView _cppObj;
233 
234 
235     //static class Listener
236     //{
237     //    static class InputMethodEditor : IInputMethodEditorD
238     //    {
239     //        this(){}
240 
241 
242     //        override
243     //        void onUpdateIME(awebview.wrapper.cpp.WebView wv,
244     //                         TextInputType type, int caret_x, int caret_y)
245     //        {
246     //            _onUpdateIME.emit(this, WebView(wv), type, caret_x, caret_y);
247     //        }
248 
249 
250     //        ref RestrictedSignal!
251 
252 
253     //        override
254     //        void onCancelIME(awebview.wrapper.cpp.WebView wv)
255     //        {
256     //            _onCancelIME.emit(this, WebView(wv));
257     //        }
258 
259 
260     //        override
261     //        void onChangeIMERange(awebview.wrapper.cpp.WebView view,
262     //                              uint start, uint end)
263     //        {
264     //            _onChangeIMERange.emit(this, WebView(wv), start, end);
265     //        }
266 
267 
268 
269     //      private:
270     //        EventManager!(WebView, TextInputType, int, int) _onUpdateIME;
271     //        EventManager!(WebView) _onCancelIME;
272     //        EventManager!(WebView, uint, uint) _onChangeIMERange;
273     //    }
274 
275 
276     //  private:
277     //    InputMethodEditor _ime;
278     //}
279 }