26#if SO3_WEB_NAVIGATOR_BUILD == 1
27#include "include/cef_task.h"
28#include "include/wrapper/cef_helpers.h"
32 namespace EmbeddedWebNavigator
34 WebNavigator::WebNavigator(
const unsigned long navigatorUniqueId,
const ScolWindowHandle& scolMainWindow,
const ScolWindowHandle& parentWindowHandleInstance,
int xPosition,
int yPosition,
int width,
int height, std::string url) : uniqueId(navigatorUniqueId),
35 scolMainWindowHandle(scolMainWindow),
36 parentWindowHandle(parentWindowHandleInstance),
40 CommonConstructorSequence(std::pair<int, int>(xPosition, yPosition), std::pair<int, int>(width, height), url);
43 WebNavigator::WebNavigator(
const unsigned long navigatorUniqueId,
const ScolWindowHandle& scolMainWindow,
const ScolWindowHandle& parentWindowHandleInstance,
int width,
int height, std::string url,
bool transparency) : uniqueId(navigatorUniqueId),
44 scolMainWindowHandle(scolMainWindow),
45 parentWindowHandle(parentWindowHandleInstance),
47 mTransparency(transparency)
49 CommonConstructorSequence(std::pair<int, int>(0, 0), std::pair<int, int>(width, height), url);
52 void WebNavigator::CommonConstructorSequence(std::pair<int, int> newWebNavigatorPosition, std::pair<int, int> newWebNavigatorSize, std::string url)
55 actualPosition = newWebNavigatorPosition;
56 actualSize = newWebNavigatorSize;
63 CefWindowInfo windowInfo;
64 CefBrowserSettings settings;
70 windowInfo.SetAsWindowless(parentWindowHandle);
76 GetClientRect(parentWindowHandle, &clientArea);
77 windowInfo.SetAsChild(parentWindowHandle, clientArea);
82 settings.background_color = CefColorSetARGB(255, 255, 255, 255);
85 synchroEventCanGoBack = CreateEvent(NULL, TRUE, FALSE, NULL);
86 synchroEventCanGoForward = CreateEvent(NULL, TRUE, FALSE, NULL);
87 synchroEventGetZoomLevel = CreateEvent(NULL, TRUE, FALSE, NULL);
88 synchroEventGetSource = CreateEvent(NULL, TRUE, FALSE, NULL);
89 synchroEventGetURL = CreateEvent(NULL, TRUE, FALSE, NULL);
90 synchroEventGetText = CreateEvent(NULL, TRUE, FALSE, NULL);
93 CefBrowserHost::CreateBrowser(windowInfo, webNavigatorClient.get(), url, settings, NULL);
96 WebNavigator::WebNavigator() : uniqueId(0),
97 scolMainWindowHandle(0),
98 parentWindowHandle(0),
108 webNavigatorClient->_Cleanup();
109 webNavigatorClient = 0;
112 CloseHandle(synchroEventCanGoBack);
113 synchroEventCanGoBack = 0;
114 CloseHandle(synchroEventCanGoForward);
115 synchroEventCanGoForward = 0;
116 CloseHandle(synchroEventGetZoomLevel);
117 synchroEventGetZoomLevel = 0;
118 CloseHandle(synchroEventGetSource);
119 synchroEventGetSource = 0;
120 CloseHandle(synchroEventGetURL);
121 synchroEventGetURL = 0;
122 CloseHandle(synchroEventGetText);
123 synchroEventGetText = 0;
133 return webNavigatorClient;
138 return parentWindowHandle;
158 ResetEvent(synchroEventCanGoBack);
159 bool canGoBack =
false;
161 WaitForSingleObject(synchroEventCanGoBack, WEB_NAVIGATOR_SYNCHRO_DEFAULT_WAITING_TIME);
172 ResetEvent(synchroEventCanGoForward);
173 bool canGoForward =
false;
175 WaitForSingleObject(synchroEventCanGoForward, WEB_NAVIGATOR_SYNCHRO_DEFAULT_WAITING_TIME);
199 void WebNavigator::Find(
int identifier,
const CefString& searchText,
bool forward,
bool matchCase,
bool findNext)
201 CefPostTask(TID_UI, base::Bind(&
WebNavigatorThread::Find, uniqueId, identifier, searchText, forward, matchCase, findNext));
211 ResetEvent(synchroEventGetZoomLevel);
212 double zoomFactor = 0.0;
214 WaitForSingleObject(synchroEventGetZoomLevel, WEB_NAVIGATOR_SYNCHRO_DEFAULT_WAITING_TIME);
245 actualSize = newSize;
246 ApplyPositionAndSize();
251 return actualPosition;
256 actualPosition = newPosition;
257 ApplyPositionAndSize();
260 void WebNavigator::ApplyPositionAndSize()
262 CefRefPtr<CefBrowser> cefBrowser = webNavigatorClient->GetBrowser();
263 if (cefBrowser.get())
267 CefWindowHandle cefBrowserWindowHandle = cefBrowser->GetHost()->GetWindowHandle();
268 if (cefBrowserWindowHandle)
271 GetClientRect(parentWindowHandle, &clientArea);
272 SetWindowPos(cefBrowserWindowHandle, 0,
273 clientArea.left + actualPosition.first, clientArea.top + actualPosition.second,
274 actualSize.first, actualSize.second, SWP_NOZORDER);
280 cefBrowser->GetHost()->WasResized();
287 ResetEvent(synchroEventGetURL);
288 std::string url =
"";
290 WaitForSingleObject(synchroEventGetURL, WEB_NAVIGATOR_SYNCHRO_DEFAULT_WAITING_TIME);
341 ResetEvent(synchroEventGetSource);
342 std::string sourceText =
"";
344 WaitForSingleObject(synchroEventGetSource, WEB_NAVIGATOR_SYNCHRO_DEFAULT_WAITING_TIME);
350 ResetEvent(synchroEventGetText);
351 std::string text =
"";
353 WaitForSingleObject(synchroEventGetText, WEB_NAVIGATOR_SYNCHRO_DEFAULT_WAITING_TIME);
369 CefRefPtr<CefBrowser> cefBrowser = webNavigatorClient->GetBrowser();
370 if (cefBrowser.get())
373 event.windows_key_code =
wparam;
374 event.native_key_code =
lparam;
375 event.is_system_key = msg == WM_SYSCHAR || msg == WM_SYSKEYDOWN || msg == WM_SYSKEYUP;
377 if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN)
378 event.type = KEYEVENT_RAWKEYDOWN;
379 else if (msg == WM_KEYUP || msg == WM_SYSKEYUP)
380 event.type = KEYEVENT_KEYUP;
382 event.type = KEYEVENT_CHAR;
383 event.modifiers = GetCefKeyboardModifiers(
wparam,
lparam);
385 cefBrowser->GetHost()->SendKeyEvent(
event);
391 CefRefPtr<CefBrowser> cefBrowser = webNavigatorClient->GetBrowser();
393 event.is_system_key =
false;
396 BYTE VkCode = LOBYTE(VkKeyScanA(scanCode));
397 event.native_key_code = MapVirtualKey(scanCode, 1) << 16 | 1;
398 event.windows_key_code = VkCode;
399 event.type = KEYEVENT_KEYDOWN;
403 event.native_key_code |= 0xC0000000;
404 event.type = KEYEVENT_KEYUP;
407 if (cefBrowser.get())
408 cefBrowser->GetHost()->SendKeyEvent(
event);
413 CefRefPtr<CefBrowser> cefBrowser = webNavigatorClient->GetBrowser();
415 event.is_system_key =
false;
418 BYTE VkCode = LOBYTE(VkKeyScanA(keydata));
419 event.native_key_code = keydata;
420 event.windows_key_code = VkCode;
421 event.type = KEYEVENT_CHAR;
423 if (cefBrowser.get())
424 cefBrowser->GetHost()->SendKeyEvent(
event);
429 CefRefPtr<CefBrowser> cefBrowser = webNavigatorClient->GetBrowser();
435 if (cefBrowser.get())
436 cefBrowser->GetHost()->SendMouseClickEvent(
event, ConvertMouseButton(buttonType), mouseUp, clickCount);
441 CefRefPtr<CefBrowser> cefBrowser = webNavigatorClient->GetBrowser();
447 if (cefBrowser.get())
449 cefBrowser->GetHost()->SendMouseMoveEvent(
event, mouseLeave);
456 CefRefPtr<CefBrowser> cefBrowser = webNavigatorClient->GetBrowser();
462 if (cefBrowser.get())
463 cefBrowser->GetHost()->SendMouseWheelEvent(
event, 0, delta * 100);
468 CefRefPtr<CefBrowser> cefBrowser = webNavigatorClient->GetBrowser();
469 if (cefBrowser.get())
470 cefBrowser->GetHost()->SendFocusEvent(setFocus);
473 CefBrowserHost::MouseButtonType WebNavigator::ConvertMouseButton(
int scolButton)
494 listener = newListener;
SCOL_EXPORT void SCOL_PTR_TYPE WPARAM LPARAM lparam
SCOL_EXPORT void SCOL_PTR_TYPE WPARAM wparam
SCOL_EXPORT void SCOL_PTR_TYPE event
void Cut(const std::string &frameName="")
void InjectMouseClick(int x, int y, int buttonType, bool mouseUp, int clickCount)
void StopFinding(bool clearSelection)
unsigned long GetUniqueId()
void SetZoomLevel(double zoomLevel)
void LoadFile(const std::string &file, const std::string &frameName="")
WebNavigatorListener * GetListener()
std::string GetText(const std::string &frameName="")
void InjectMouseWheel(int x, int y, int delta)
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 InjectFocus(bool setFocus)
void SetSize(std::pair< int, int > newSize)
ScolWindowHandle GetParentWindowHandle()
void ViewSource(const std::string &frameName="")
std::string GetURL(const std::string &frameName="")
std::pair< int, int > GetPosition()
void SelectAll(const std::string &frameName="")
std::pair< int, int > GetSize()
void LoadURL(const std::string &url, const std::string &frameName="")
void InjectChar(int scanCode, int keydata)
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)
static void Delete(unsigned long webNavigatorId, const std::string frameName="")
static void ClearHistory(unsigned long webNavigatorId)
static void Find(unsigned long webNavigatorId, int identifier, const CefString searchText, bool forward, bool matchCase, bool findNext)
static void ReloadIgnoreCache(unsigned long webNavigatorId)
static void GetSource(unsigned long webNavigatorId, std::string *frameSource, HANDLE synchro, const std::string frameName="")
static void CanGoBack(unsigned long webNavigatorId, bool *canGoBack, HANDLE synchro)
static void Cut(unsigned long webNavigatorId, const std::string frameName="")
static void CloseDevTools(unsigned long webNavigatorId)
static void GoForward(unsigned long webNavigatorId)
static void LoadHTML(unsigned long webNavigatorId, const std::string html, const std::string frameName="")
static void LoadFile(unsigned long webNavigatorId, const std::string file, const std::string frameName="")
static void StopLoad(unsigned long webNavigatorId)
static void LoadURL(unsigned long webNavigatorId, const std::string url, const std::string frameName="")
static void Reload(unsigned long webNavigatorId)
static void Print(unsigned long webNavigatorId, const std::string frameName="")
static void SelectAll(unsigned long webNavigatorId, const std::string frameName="")
static void GoBack(unsigned long webNavigatorId)
static void StopFinding(unsigned long webNavigatorId, bool clearSelection)
static void CanGoForward(unsigned long webNavigatorId, bool *canGoForward, HANDLE synchro)
static void Copy(unsigned long webNavigatorId, const std::string frameName="")
static void GetZoomLevel(unsigned long webNavigatorId, double *zoomFactor, HANDLE synchro)
static void GetURL(unsigned long webNavigatorId, std::string *frameUrl, HANDLE synchro, const std::string frameName="")
static void Undo(unsigned long webNavigatorId, const std::string frameName="")
static void GetText(unsigned long webNavigatorId, std::string *frameText, HANDLE synchro, const std::string frameName="")
static void ShowDevTools(unsigned long webNavigatorId)
static void Redo(unsigned long webNavigatorId, const std::string frameName="")
static void ViewSource(unsigned long webNavigatorId, const std::string frameName="")
static void Paste(unsigned long webNavigatorId, const std::string frameName="")
static void ExecuteJavaScript(unsigned long webNavigatorId, const std::string jsCode, const std::string scriptUrl, int startLine, const std::string frameName="")
static void SetZoomLevel(unsigned long webNavigatorId, double zoomLevel)