Project

General

Profile

SO3Engine
SO3EmbeddedWebNavigator.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2011 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21-----------------------------------------------------------------------------
22*/
23
24#ifndef _SCOL_EMBEDDED_WEB_NAVIGATOR_
25#define _SCOL_EMBEDDED_WEB_NAVIGATOR_
26
28#if SO3_WEB_NAVIGATOR_BUILD == 1
29#include "include/cef_client.h"
30
31namespace SO3
32{
33 namespace EmbeddedWebNavigator
34 {
35 static bool IsKeyDown(WPARAM wparam)
36 {
37 return (GetKeyState((int)wparam) & 0x8000) != 0;
38 }
39
40 static int GetCefKeyboardModifiers(WPARAM wparam, LPARAM lparam)
41 {
42 int modifiers = 0;
43 if (IsKeyDown(VK_SHIFT))
44 modifiers |= EVENTFLAG_SHIFT_DOWN;
45 if (IsKeyDown(VK_CONTROL))
46 modifiers |= EVENTFLAG_CONTROL_DOWN;
47 if (IsKeyDown(VK_MENU))
48 modifiers |= EVENTFLAG_ALT_DOWN;
49
50 // Low bit set from GetKeyState indicates "toggled".
51 if (::GetKeyState(VK_NUMLOCK) & 1)
52 modifiers |= EVENTFLAG_NUM_LOCK_ON;
53 if (::GetKeyState(VK_CAPITAL) & 1)
54 modifiers |= EVENTFLAG_CAPS_LOCK_ON;
55
56 switch (wparam) {
57 case VK_RETURN:
58 if ((lparam >> 16) & KF_EXTENDED)
59 modifiers |= EVENTFLAG_IS_KEY_PAD;
60 break;
61 case VK_INSERT:
62 case VK_DELETE:
63 case VK_HOME:
64 case VK_END:
65 case VK_PRIOR:
66 case VK_NEXT:
67 case VK_UP:
68 case VK_DOWN:
69 case VK_LEFT:
70 case VK_RIGHT:
71 if (!((lparam >> 16) & KF_EXTENDED))
72 modifiers |= EVENTFLAG_IS_KEY_PAD;
73 break;
74 case VK_NUMLOCK:
75 case VK_NUMPAD0:
76 case VK_NUMPAD1:
77 case VK_NUMPAD2:
78 case VK_NUMPAD3:
79 case VK_NUMPAD4:
80 case VK_NUMPAD5:
81 case VK_NUMPAD6:
82 case VK_NUMPAD7:
83 case VK_NUMPAD8:
84 case VK_NUMPAD9:
85 case VK_DIVIDE:
86 case VK_MULTIPLY:
87 case VK_SUBTRACT:
88 case VK_ADD:
89 case VK_DECIMAL:
90 case VK_CLEAR:
91 modifiers |= EVENTFLAG_IS_KEY_PAD;
92 break;
93 case VK_SHIFT:
94 if (IsKeyDown(VK_LSHIFT))
95 modifiers |= EVENTFLAG_IS_LEFT;
96 else if (IsKeyDown(VK_RSHIFT))
97 modifiers |= EVENTFLAG_IS_RIGHT;
98 break;
99 case VK_CONTROL:
100 if (IsKeyDown(VK_LCONTROL))
101 modifiers |= EVENTFLAG_IS_LEFT;
102 else if (IsKeyDown(VK_RCONTROL))
103 modifiers |= EVENTFLAG_IS_RIGHT;
104 break;
105 case VK_MENU:
106 if (IsKeyDown(VK_LMENU))
107 modifiers |= EVENTFLAG_IS_LEFT;
108 else if (IsKeyDown(VK_RMENU))
109 modifiers |= EVENTFLAG_IS_RIGHT;
110 break;
111 case VK_LWIN:
112 modifiers |= EVENTFLAG_IS_LEFT;
113 break;
114 case VK_RWIN:
115 modifiers |= EVENTFLAG_IS_RIGHT;
116 break;
117 }
118 return modifiers;
119 }
120
122 {
123 public:
124 protected:
125 private:
126 const unsigned long uniqueId;
127 const ScolWindowHandle scolMainWindowHandle;
128 const ScolWindowHandle parentWindowHandle;
129 const bool mOffscreen;
130 bool mTransparency;
131 CefRefPtr<WebNavigatorClient> webNavigatorClient;
132 std::pair<int, int> actualSize;
133 std::pair<int, int> actualPosition;
134 HANDLE synchroEventCanGoBack;
135 HANDLE synchroEventCanGoForward;
136 HANDLE synchroEventGetZoomLevel;
137 HANDLE synchroEventGetSource;
138 HANDLE synchroEventGetURL;
139 HANDLE synchroEventGetText;
140 WebNavigatorListener* listener; // Only one listener allowed
141
142 public:
146 WebNavigator(const unsigned long navigatorUniqueId, const ScolWindowHandle& scolMainWindow, const ScolWindowHandle& parentWindowHandleInstance, int xPosition, int yPosition, int width, int height, std::string url);
147
151 WebNavigator(const unsigned long navigatorUniqueId, const ScolWindowHandle& scolMainWindow, const ScolWindowHandle& parentWindowHandleInstance, int width, int height, std::string url, bool transparency);
152
156 virtual ~WebNavigator();
157
160 unsigned long GetUniqueId();
161
164 ScolWindowHandle GetParentWindowHandle();
165
168 CefRefPtr<WebNavigatorClient>& GetWebNavigatorClient();
169
175 void LoadURL(const std::string& url, const std::string& frameName = "");
176
183 void LoadFile(const std::string& file, const std::string& frameName = "");
184
185 /*
186 Loads a string of HTML.
187 @param url The html text to load
188 @param frameName The target frame, main frame will be used if empty.
189 @note Relative URLs will be resolved using the base directory.
190 */
191 void LoadHTML(const std::string& html, const std::string& frameName = "");
192
197 std::string GetURL(const std::string& frameName = "");
198
203 void Undo(const std::string& frameName = "");
204
209 void Redo(const std::string& frameName = "");
210
215 void Cut(const std::string& frameName = "");
216
221 void Copy(const std::string& frameName = "");
222
227 void Paste(const std::string& frameName = "");
228
233 void Delete(const std::string& frameName = "");
234
239 void SelectAll(const std::string& frameName = "");
240
245 void Print(const std::string& frameName = "");
246
251 void ViewSource(const std::string& frameName = "");
252
257 std::string GetSource(const std::string& frameName = "");
258
263 std::string GetText(const std::string& frameName = "");
264
272 void ExecuteJavaScript(const std::string& jsCode, const std::string& scriptUrl, int startLine, const std::string& frameName = "");
273
277 bool CanGoBack();
278
282 void GoBack();
283
287 bool CanGoForward();
288
292 void GoForward();
293
297 void Reload();
298
302 void ReloadIgnoreCache();
303
307 void StopLoad();
308
317 void Find(int identifier, const CefString& searchText, bool forward, bool matchCase, bool findNext);
318
322 void StopFinding(bool clearSelection);
323
327 double GetZoomLevel();
328
332 void SetZoomLevel(double zoomLevel);
333
337 void ClearHistory();
338
342 void ShowDevTools();
343
347 void CloseDevTools();
348
351 std::pair<int, int> GetSize();
352
355 void SetSize(std::pair<int, int> newSize);
356
359 std::pair<int, int> GetPosition();
360
363 void SetPosition(std::pair<int, int> newPosition);
364
367 bool IsOffscreen() const;
368
372 void InjectKeyMsg(int msg, LPARAM lparam, WPARAM wparam);
373
377 void InjectKey(int scanCode, int keydata, bool down);
378
382 void InjectChar(int scanCode, int keydata);
383
387 void InjectMouseClick(int x, int y, int buttonType, bool mouseUp, int clickCount);
388
392 void InjectMouseMove(int x, int y, bool mouseLeave);
393
397 void InjectMouseWheel(int x, int y, int delta);
398
402 void InjectFocus(bool setFocus);
403
407 //void InjectCaptureLostEvent();
408
411 void SetListener(WebNavigatorListener* newListener);
412
416 protected:
417 // the browser reference
418 CefRefPtr<CefBrowser> browser;
419
420 private:
424 WebNavigator();
425
429 void CommonConstructorSequence(std::pair<int, int> newWebNavigatorPosition, std::pair<int, int> newWebNavigatorSize, std::string url);
430
433 void ApplyPositionAndSize();
434
438 CefBrowserHost::MouseButtonType ConvertMouseButton(int scolButton);
439 };
440 }
441}
442
443#endif
444#endif
SCOL_EXPORT void SCOL_PTR_TYPE WPARAM LPARAM lparam
Definition SO3SCOL.cpp:5130
SCOL_EXPORT void SCOL_PTR_TYPE WPARAM wparam
Definition SO3SCOL.cpp:5128
void Cut(const std::string &frameName="")
void InjectMouseClick(int x, int y, int buttonType, bool mouseUp, int clickCount)
void LoadFile(const std::string &file, const std::string &frameName="")
std::string GetText(const std::string &frameName="")
void Delete(const std::string &frameName="")
void Redo(const std::string &frameName="")
void Undo(const std::string &frameName="")
std::string GetSource(const std::string &frameName="")
void SetSize(std::pair< int, int > newSize)
void ViewSource(const std::string &frameName="")
std::string GetURL(const std::string &frameName="")
void SelectAll(const std::string &frameName="")
void LoadURL(const std::string &url, const std::string &frameName="")
void SetPosition(std::pair< int, int > newPosition)
void InjectKeyMsg(int msg, LPARAM lparam, WPARAM wparam)
void InjectMouseMove(int x, int y, bool mouseLeave)
void Find(int identifier, const CefString &searchText, bool forward, bool matchCase, bool findNext)
void Print(const std::string &frameName="")
CefRefPtr< WebNavigatorClient > & GetWebNavigatorClient()
void Paste(const std::string &frameName="")
void SetListener(WebNavigatorListener *newListener)
void LoadHTML(const std::string &html, const std::string &frameName="")
void ExecuteJavaScript(const std::string &jsCode, const std::string &scriptUrl, int startLine, const std::string &frameName="")
void Copy(const std::string &frameName="")
void InjectKey(int scanCode, int keydata, bool down)