Project

General

Profile

SO3Engine
SO3WebNavigatorWidget.cpp
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) 2012 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
25#include <scolPlugin.h>
30#include "SO3Renderer/SO3Root.h"
33#if SO3_WEB_NAVIGATOR_BUILD == 1
34
35namespace SO3
36{
37
39{
40 targetWidget = targetWidgetInstance;
41}
42
44{
45 // Send event information
46 SWidgetManager::getSingleton()._FireScriptWidgetEvent(targetWidget, functionCalled);
47}
48
50{
51 // Send event information
52 SWidgetManager::getSingleton()._FireScriptWidgetEvent(targetWidget, functionCalled);
53}
54
55void SO3WebNavigatorWidgetListener::OnLoadStart(SO3::EmbeddedWebNavigator::WebNavigator* sourceWebNavigator, const std::string& frameName)
56{
58}
59
60void SO3WebNavigatorWidgetListener::OnLoadEnd(SO3::EmbeddedWebNavigator::WebNavigator* sourceWebNavigator, const std::string& frameName, int httpStatusCode)
61{
63}
64
65void SO3WebNavigatorWidgetListener::OnLoadError(SO3::EmbeddedWebNavigator::WebNavigator* sourceWebNavigator, const std::string& frameName, int errorCode, const std::string& failedUrl, std::string& errorText)
66{
67 SWidgetManager::getSingleton()._FireOnLoadError(targetWidget, errorCode, failedUrl);
68}
69
71{
72 targetWidget->_SetCurrentMouseCursor(newCursor);
73}
74
75SWebNavigatorWidget::SWebNavigatorWidget(SScene* targetScene, const std::string& webNavigatorName, const int& xPos, const int& yPos, const unsigned short& widgetWidth, const unsigned short& widgetHeight, SViewPort* targetViewport, const unsigned int& widgetZOrder) : SWidget(targetScene, webNavigatorName, xPos, yPos, widgetWidth, widgetHeight, targetViewport, widgetZOrder, SO3_WEB_NAVIGATOR_WIDGET_TYPE)
76{
77 CommonConstructorSequence();
78}
79
80SWebNavigatorWidget::SWebNavigatorWidget(SScene* targetScene, const std::string& webNavigatorName, const int& xPos, const int& yPos, const unsigned short& widgetWidth, const unsigned short& widgetHeight, SViewPort* targetViewport) : SWidget(targetScene, webNavigatorName, xPos, yPos, widgetWidth, widgetHeight, targetViewport, SO3_WEB_NAVIGATOR_WIDGET_TYPE)
81{
82 CommonConstructorSequence();
83}
84
85SWebNavigatorWidget::SWebNavigatorWidget(SScene* targetScene, const std::string& webNavigatorName, const unsigned short& widgetWidth, const unsigned short& widgetHeight, SMaterial* targetMaterial, const unsigned short& targetTechnique, const unsigned short& targetPass, const unsigned short& targetTextureUnit) : SWidget(targetScene, webNavigatorName, widgetWidth, widgetHeight, targetMaterial, targetTechnique, targetPass, targetTextureUnit, SO3_WEB_NAVIGATOR_WIDGET_TYPE)
86{
87 CommonConstructorSequence();
88}
89
90void SWebNavigatorWidget::CommonConstructorSequence()
91{
92 // Create WebNavigator instance
93 embeddedWebNavigator = 0;
94 webNavigatorListener = 0;
95 lastCursor = 0;
96 parentWindow = 0;
97
98 //TODO windowHandler
99 CreateWebNavigator();
100}
101
103{
104 DestroyWebNavigator();
105}
106
107void SWebNavigatorWidget::CreateWebNavigator()
108{
109 DestroyWebNavigator();
110 const SWindow* pwin = (viewport != 0) ? viewport->GetParentWindow() : 0;
111 ScolWindowHandle parent = (pwin != 0) ? pwin->GetWindowHandle() : 0;
112 // Create a parent window in any case to avoid crash on popup events on plugins like flash
113 parentWindow = CreateWindow("ScolClass", GetName().c_str(), WS_CHILD, CW_USEDEFAULT, CW_USEDEFAULT, 1, 1, parent, 0, (HINSTANCE)SCgetExtra("this_inst"), 0);
114
115 embeddedWebNavigator = EmbeddedWebNavigator::WebNavigatorManager::GetSingleton().CreateNavigator(const_cast<ScolWindowHandle&>(parentWindow), width, height, "google.com", GetTransparency());
116
117 // Javascript external call listener
118 webNavigatorListener = new SO3WebNavigatorWidgetListener(this);
119 embeddedWebNavigator->SetListener(webNavigatorListener);
120}
121
122void SWebNavigatorWidget::DestroyWebNavigator()
123{
124 if(embeddedWebNavigator != 0)
125 {
126 // Remove Javascript external call listener
127 embeddedWebNavigator->SetListener(0);
128 delete(webNavigatorListener);
129 webNavigatorListener = 0;
130
132 embeddedWebNavigator = 0;
133
134 if(parentWindow)
135 {
136 DestroyWindow(parentWindow);
137 parentWindow = 0;
138 }
139 }
140}
141
142void SWebNavigatorWidget::LoadURL(const std::string& url)
143{
144 if(embeddedWebNavigator != 0)
145 embeddedWebNavigator->LoadURL(url);
146}
147
148void SWebNavigatorWidget::LoadFile(const std::string& file)
149{
150 if(embeddedWebNavigator != 0)
151 embeddedWebNavigator->LoadFile(file);
152}
153
154void SWebNavigatorWidget::LoadHTML(const std::string& html)
155{
156 if(embeddedWebNavigator != 0)
157 embeddedWebNavigator->LoadHTML(html);
158}
159
160void SWebNavigatorWidget::InjectMouseMove(const int& xPos, const int& yPos, const MouseButtonId& button)
161{
162 if(embeddedWebNavigator != 0)
163 embeddedWebNavigator->InjectMouseMove(xPos, yPos, false);
164}
165
166void SWebNavigatorWidget::InjectMouseWheel(const int& scrollX, const int& scrollY, const int& relativeScroll)
167{
168 if(embeddedWebNavigator != 0)
169 embeddedWebNavigator->InjectMouseWheel(scrollX, scrollY, relativeScroll);
170}
171
172void SWebNavigatorWidget::InjectMouseDown(const int& xPos, const int& yPos, const MouseButtonId& button)
173{
174 if(embeddedWebNavigator != 0)
175 embeddedWebNavigator->InjectMouseClick(xPos, yPos, button, false, 1);
176}
177
178void SWebNavigatorWidget::InjectMouseUp(const int& xPos, const int& yPos, const MouseButtonId& button)
179{
180 if(embeddedWebNavigator != 0)
181 embeddedWebNavigator->InjectMouseClick(xPos, yPos, button, true, 1);
182}
183
184void SWebNavigatorWidget::InjectTouchAdd(const int& xPos, const int& yPos, const int& touchid)
185{
186 // Nothing to do
187}
188
190{
191 // Nothing to do
192}
193
194void SWebNavigatorWidget::InjectTouchUpdate(const int& xPos, const int& yPos, const int& vx, const int& vy, const int& touchid)
195{
196 // Nothing to do
197}
198
199void SWebNavigatorWidget::InjectKeyEvent(const UINT& msg, const ScolWindowHandle& hwnd, const WPARAM& wParam, const LPARAM& lParam)
200{
201 if(embeddedWebNavigator != 0)
202 embeddedWebNavigator->InjectKeyMsg(msg, lParam, wParam);
203}
204
205void SWebNavigatorWidget::InjectTextEvent(const std::string& utf8)
206{
207 /*std::wstring wstringUtf8(utf8.length(),L' ');
208 std::copy(utf8.begin(), utf8.end(), wstringUtf8.begin());
209 navigatorWindow->injectTextEvent(wstringUtf8);*/
210}
211
212void SWebNavigatorWidget::SetTransparencyImpl(const bool& enableTransparency)
213{
214 CreateWebNavigator();
215}
216
217void SWebNavigatorWidget::SetFocusImpl(const bool& focusOnWidget)
218{
219 if(embeddedWebNavigator != 0)
220 embeddedWebNavigator->InjectFocus(focusOnWidget);
221}
222
223void SWebNavigatorWidget::SetKeyboardEnableImpl(const bool& enableKeyboardOnWidget)
224{
225 // TODO
226}
227
228void SWebNavigatorWidget::SetMouseEnableImpl(const bool& enableMouseOnWidget)
229{
230 // TODO
231}
232
233void SWebNavigatorWidget::SetSizeImpl(const unsigned short& newWidth, const unsigned short& newHeight)
234{
235 if(embeddedWebNavigator != 0)
236 embeddedWebNavigator->SetSize(std::pair<int, int>(newWidth, newHeight));
237}
238
239void SWebNavigatorWidget::Update(const bool& forceUpdate)
240{
241 bool updateCurrentFrame = forceRenderingUpdate || forceUpdate;
242 if(embeddedWebNavigator != 0)
243 {
244 if(GetVisible())
245 {
247 {
248 if(HasFocus())
249 updateCurrentFrame = true;
250 }
251 else
252 {
253 updateCurrentFrame = true;
254 }
255 }
256
257 if(updateCurrentFrame)
258 embeddedWebNavigator->GetWebNavigatorClient()->BlitOffscreenTexture(renderingTexture, forceRenderingUpdate || forceUpdate);
259 }
260
261 forceRenderingUpdate = false;
262}
263
264void SWebNavigatorWidget::RunScriptFunction(const std::string& functionName, const std::vector<std::string>& argumentList)
265{
266 if(embeddedWebNavigator != 0)
267 {
268 bool firstArgument = true;
269 std::string javaScriptCommand = functionName + "(";
270 std::vector<std::string>::const_iterator iArguments = argumentList.begin();
271 while(iArguments != argumentList.end())
272 {
273 if(!firstArgument)
274 javaScriptCommand += ", ";
275
276 javaScriptCommand += (*iArguments);
277 firstArgument = false;
278 iArguments++;
279 }
280 javaScriptCommand += ");";
281 embeddedWebNavigator->ExecuteJavaScript(javaScriptCommand, "", 1);
282 }
283}
284
285bool SWebNavigatorWidget::CheckPixelAlpha(const int& posX, const int& posY)
286{
287 if(embeddedWebNavigator != 0)
288 return embeddedWebNavigator->GetWebNavigatorClient()->CheckPixelAlpha(posX, posY, transparentTresholdColor);
289 else
290 return false;
291}
292
294{
295 if(embeddedWebNavigator != 0)
296 return embeddedWebNavigator->CanGoBack();
297 else
298 return false;
299}
300
302{
303 if(embeddedWebNavigator != 0)
304 embeddedWebNavigator->GoBack();
305}
306
308{
309 if(embeddedWebNavigator != 0)
310 return embeddedWebNavigator->CanGoForward();
311 else
312 return false;
313}
314
316{
317 if(embeddedWebNavigator != 0)
318 embeddedWebNavigator->GoForward();
319}
320
322{
323 if(embeddedWebNavigator != 0)
324 embeddedWebNavigator->Reload();
325}
326
328{
329 if(embeddedWebNavigator != 0)
330 embeddedWebNavigator->ReloadIgnoreCache();
331}
332
334{
335 if(embeddedWebNavigator != 0)
336 embeddedWebNavigator->StopLoad();
337}
338
339void SWebNavigatorWidget::Find(const int& identifier, const std::string& searchText, const bool& forward, const bool& matchCase, const bool& findNext)
340{
341 if(embeddedWebNavigator != 0)
342 embeddedWebNavigator->Find(identifier, searchText, forward, matchCase, findNext);
343}
344
345void SWebNavigatorWidget::StopFinding(const bool& clearSelection)
346{
347 if(embeddedWebNavigator != 0)
348 embeddedWebNavigator->StopFinding(clearSelection);
349}
350
352{
353 if(embeddedWebNavigator != 0)
354 return static_cast<float>(embeddedWebNavigator->GetZoomLevel());
355 else
356 return 0.0f;
357}
358
359void SWebNavigatorWidget::SetZoomLevel(const float& zoomLevel)
360{
361 if(embeddedWebNavigator != 0)
362 embeddedWebNavigator->SetZoomLevel(static_cast<double>(zoomLevel));
363}
364
366{
367 if(embeddedWebNavigator != 0)
368 embeddedWebNavigator->ClearHistory();
369}
370
372{
373 if(embeddedWebNavigator != 0)
374 embeddedWebNavigator->ShowDevTools();
375}
376
378{
379 if(embeddedWebNavigator != 0)
380 embeddedWebNavigator->CloseDevTools();
381}
382
383std::string SWebNavigatorWidget::GetURL(const std::string& frameName)
384{
385 if(embeddedWebNavigator != 0)
386 return embeddedWebNavigator->GetURL(frameName);
387 else
388 return "";
389}
390
391void SWebNavigatorWidget::Undo(const std::string& frameName)
392{
393 if(embeddedWebNavigator != 0)
394 embeddedWebNavigator->Undo(frameName);
395}
396
397void SWebNavigatorWidget::Redo(const std::string& frameName)
398{
399 if(embeddedWebNavigator != 0)
400 embeddedWebNavigator->Redo(frameName);
401}
402
403void SWebNavigatorWidget::Cut(const std::string& frameName)
404{
405 if(embeddedWebNavigator != 0)
406 embeddedWebNavigator->Cut(frameName);
407}
408
409void SWebNavigatorWidget::Copy(const std::string& frameName)
410{
411 if(embeddedWebNavigator != 0)
412 embeddedWebNavigator->Copy(frameName);
413}
414
415void SWebNavigatorWidget::Paste(const std::string& frameName)
416{
417 if(embeddedWebNavigator != 0)
418 embeddedWebNavigator->Paste(frameName);
419}
420
421void SWebNavigatorWidget::Delete(const std::string& frameName)
422{
423 if(embeddedWebNavigator != 0)
424 embeddedWebNavigator->Delete(frameName);
425}
426
427void SWebNavigatorWidget::SelectAll(const std::string& frameName)
428{
429 if(embeddedWebNavigator != 0)
430 embeddedWebNavigator->SelectAll(frameName);
431}
432
433void SWebNavigatorWidget::Print(const std::string& frameName)
434{
435 if(embeddedWebNavigator != 0)
436 embeddedWebNavigator->Print(frameName);
437}
438
439void SWebNavigatorWidget::ViewSource(const std::string& frameName)
440{
441 if(embeddedWebNavigator != 0)
442 embeddedWebNavigator->ViewSource(frameName);
443}
444
445std::string SWebNavigatorWidget::GetSource(const std::string& frameName)
446{
447 if(embeddedWebNavigator != 0)
448 return embeddedWebNavigator->GetSource(frameName);
449 else
450 return "";
451}
452
453std::string SWebNavigatorWidget::GetText(const std::string& frameName)
454{
455 if(embeddedWebNavigator != 0)
456 return embeddedWebNavigator->GetText(frameName);
457 else
458 return "";
459}
460
462{
463 return lastCursor;
464}
465
467{
468 lastCursor = newCursor;
469}
470
471}
472
473#endif
unsigned int UINT
Definition SO3Android.h:58
void * HCURSOR
Definition SO3Android.h:60
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 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="")
WebNavigator * CreateNavigator(const ScolWindowHandle &parentWindowHandle, int xPosition, int yPosition, int width, int height, std::string url)
std::string GetName() const
virtual void OnCursorChange(SO3::EmbeddedWebNavigator::WebNavigator *sourceWebNavigator, HCURSOR newCursor)
virtual void OnExternalCallStr(SO3::EmbeddedWebNavigator::WebNavigator *sourceWebNavigator, const SO3::SScriptFunction &functionCalled)
virtual void OnLoadStart(SO3::EmbeddedWebNavigator::WebNavigator *sourceWebNavigator, const std::string &frameName)
SO3WebNavigatorWidgetListener(SWebNavigatorWidget *targetWidgetInstance)
virtual void OnExternalCall(SO3::EmbeddedWebNavigator::WebNavigator *sourceWebNavigator, const SO3::SScriptFunction &functionCalled)
virtual void OnLoadError(SO3::EmbeddedWebNavigator::WebNavigator *sourceWebNavigator, const std::string &frameName, int errorCode, const std::string &failedUrl, std::string &errorText)
virtual void OnLoadEnd(SO3::EmbeddedWebNavigator::WebNavigator *sourceWebNavigator, const std::string &frameName, int httpStatusCode)
SWindow * GetParentWindow() const
void _SetCurrentMouseCursor(const HCURSOR &newCursor)
virtual void RunScriptFunction(const std::string &functionName, const std::vector< std::string > &argumentList)
void Redo(const std::string &frameName="")
virtual void LoadFile(const std::string &file)
void Paste(const std::string &frameName="")
void SetZoomLevel(const float &zoomLevel)
void Delete(const std::string &frameName="")
virtual void InjectTextEvent(const std::string &utf8)
void ViewSource(const std::string &frameName="")
void Update(const bool &forceUpdate)
virtual void InjectMouseMove(const int &xPos, const int &yPos, const MouseButtonId &button)
void Copy(const std::string &frameName="")
virtual void InjectMouseUp(const int &xPos, const int &yPos, const MouseButtonId &button)
virtual void InjectTouchRemove(const int &touchid)
void StopFinding(const bool &clearSelection)
virtual void InjectMouseDown(const int &xPos, const int &yPos, const MouseButtonId &button)
virtual void InjectTouchAdd(const int &xPos, const int &yPos, const int &touchid)
virtual void InjectTouchUpdate(const int &xPos, const int &yPos, const int &vx, const int &vy, const int &touchid)
virtual void InjectKeyEvent(const UINT &msg, const ScolWindowHandle &hwnd, const WPARAM &wParam, const LPARAM &lParam)
void Print(const std::string &frameName="")
void Undo(const std::string &frameName="")
void SelectAll(const std::string &frameName="")
void LoadHTML(const std::string &html)
virtual void InjectMouseWheel(const int &scrollX, const int &scrollY, const int &relativeScroll)
virtual void LoadURL(const std::string &url)
std::string GetURL(const std::string &frameName="")
std::string GetSource(const std::string &frameName="")
void Cut(const std::string &frameName="")
std::string GetText(const std::string &frameName="")
void Find(const int &identifier, const std::string &searchText, const bool &forward, const bool &matchCase, const bool &findNext)
bool forceRenderingUpdate
Definition SO3Widget.h:89
float transparentTresholdColor
Definition SO3Widget.h:90
bool HasFocus()
unsigned short width
Definition SO3Widget.h:80
Ogre::TexturePtr renderingTexture
Definition SO3Widget.h:88
unsigned short height
Definition SO3Widget.h:81
bool GetTransparency()
SViewPort * viewport
Definition SO3Widget.h:86
bool GetVisible()
bool GetUpdateOnFocusOnly()
void _FireOnLoadStart(SWidget *targetedWidget)
void _FireScriptWidgetEvent(SWidget *targetedWidget, const SScriptFunction &functionCalled)
void _FireOnLoadError(SWidget *targetedWidget, const int &errorCode, const std::string &failedUrl)
void _FireOnLoadEnd(SWidget *targetedWidget)
static SWidgetManager & getSingleton()
ScolWindowHandle GetWindowHandle() const