Merge branch 'devel/master' into devel/graphics
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / web-view / web-view-impl.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "web-view-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/web-engine-back-forward-list.h>
23 #include <dali/devel-api/adaptor-framework/web-engine-context.h>
24 #include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-settings.h>
26 #include <dali/devel-api/common/stage.h>
27 #include <dali/devel-api/scripting/enum-helper.h>
28 #include <dali/devel-api/scripting/scripting.h>
29 #include <dali/public-api/adaptor-framework/native-image-source.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali/public-api/object/type-registry.h>
32 #include <cstring>
33
34 // INTERNAL INCLUDES
35 #include <dali-toolkit/devel-api/controls/control-devel.h>
36 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h>
37 #include <dali-toolkit/devel-api/controls/web-view/web-context.h>
38 #include <dali-toolkit/devel-api/controls/web-view/web-cookie-manager.h>
39 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
40 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
41 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
42 #include <dali-toolkit/public-api/image-loader/image.h>
43 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
44
45 namespace Dali
46 {
47 namespace Toolkit
48 {
49 namespace Internal
50 {
51 namespace
52 {
53 BaseHandle Create()
54 {
55   return Toolkit::WebView::New();
56 }
57
58 // clang-format off
59 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create)
60
61 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url",                STRING,  URL                 )
62 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent",          STRING,  USER_AGENT          )
63 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition",     VECTOR2, SCROLL_POSITION     )
64 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize",         VECTOR2, SCROLL_SIZE         )
65 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize",        VECTOR2, CONTENT_SIZE        )
66 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title",              STRING,  TITLE               )
67 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled",   BOOLEAN, VIDEO_HOLE_ENABLED  )
68 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled", BOOLEAN, MOUSE_EVENTS_ENABLED)
69 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled",   BOOLEAN, KEY_EVENTS_ENABLED  )
70
71 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadStarted",    PAGE_LOAD_STARTED_SIGNAL    )
72 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadInProgress", PAGE_LOAD_IN_PROGRESS_SIGNAL)
73 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadFinished",   PAGE_LOAD_FINISHED_SIGNAL   )
74 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadError",      PAGE_LOAD_ERROR_SIGNAL      )
75 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "scrollEdgeReached",  SCROLL_EDGE_REACHED_SIGNAL  )
76 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "urlChanged",         URL_CHANGED_SIGNAL          )
77
78 DALI_TYPE_REGISTRATION_END()
79 // clang-format on
80
81 const std::string kEmptyString;
82
83 } // namespace
84
85 #define GET_ENUM_STRING(structName, inputExp) \
86   Scripting::GetLinearEnumerationName<Toolkit::WebView::structName::Type>(static_cast<Toolkit::WebView::structName::Type>(inputExp), structName##_TABLE, structName##_TABLE_COUNT)
87
88 #define GET_ENUM_VALUE(structName, inputExp, outputExp) \
89   Scripting::GetEnumerationProperty<Toolkit::WebView::structName::Type>(inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp)
90
91 WebView::WebView(const std::string& locale, const std::string& timezoneId)
92 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
93   mUrl(),
94   mVisual(),
95   mWebViewSize(Stage::GetCurrent().GetSize()),
96   mWebEngine(),
97   mPageLoadStartedSignal(),
98   mPageLoadFinishedSignal(),
99   mPageLoadErrorSignal(),
100   mVideoHoleEnabled(true),
101   mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
102   mUrlChangedSignal(),
103   mMouseEventsEnabled(true),
104   mKeyEventsEnabled(true)
105 {
106   mWebEngine = Dali::WebEngine::New();
107
108   // WebEngine is empty when it is not properly initialized.
109   if(mWebEngine)
110   {
111     mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
112   }
113 }
114
115 WebView::WebView(int argc, char** argv)
116 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
117   mUrl(),
118   mVisual(),
119   mWebViewSize(Stage::GetCurrent().GetSize()),
120   mWebEngine(),
121   mPageLoadStartedSignal(),
122   mPageLoadFinishedSignal(),
123   mPageLoadErrorSignal(),
124   mVideoHoleEnabled(true),
125   mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
126   mUrlChangedSignal(),
127   mMouseEventsEnabled(true),
128   mKeyEventsEnabled(true)
129 {
130   mWebEngine = Dali::WebEngine::New();
131
132   // WebEngine is empty when it is not properly initialized.
133   if(mWebEngine)
134   {
135     mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
136   }
137 }
138
139 WebView::WebView()
140 : WebView("", "")
141 {
142 }
143
144 WebView::~WebView()
145 {
146   if(mWebEngine)
147   {
148     mWebEngine.Destroy();
149   }
150 }
151
152 Toolkit::WebView WebView::New()
153 {
154   WebView*         impl   = new WebView();
155   Toolkit::WebView handle = Toolkit::WebView(*impl);
156
157   impl->Initialize();
158   return handle;
159 }
160
161 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
162 {
163   WebView*         impl   = new WebView(locale, timezoneId);
164   Toolkit::WebView handle = Toolkit::WebView(*impl);
165
166   impl->Initialize();
167   return handle;
168 }
169
170 Toolkit::WebView WebView::New(int argc, char** argv)
171 {
172   WebView*         impl   = new WebView(argc, argv);
173   Toolkit::WebView handle = Toolkit::WebView(*impl);
174
175   impl->Initialize();
176   return handle;
177 }
178
179 void WebView::OnInitialize()
180 {
181   Actor self = Self();
182
183   self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
184   self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
185   self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
186   self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
187
188   mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
189   mSizeUpdateNotification     = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
190   mScaleUpdateNotification    = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
191   mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
192   mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
193   mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
194
195   if(mWebEngine)
196   {
197     mWebEngine.PageLoadStartedSignal().Connect(this, &WebView::OnPageLoadStarted);
198     mWebEngine.PageLoadInProgressSignal().Connect(this, &WebView::OnPageLoadInProgress);
199     mWebEngine.PageLoadFinishedSignal().Connect(this, &WebView::OnPageLoadFinished);
200     mWebEngine.PageLoadErrorSignal().Connect(this, &WebView::OnPageLoadError);
201     mWebEngine.ScrollEdgeReachedSignal().Connect(this, &WebView::OnScrollEdgeReached);
202     mWebEngine.UrlChangedSignal().Connect(this, &WebView::OnUrlChanged);
203
204     mWebContext         = std::unique_ptr<Dali::Toolkit::WebContext>(new WebContext(mWebEngine.GetContext()));
205     mWebCookieManager   = std::unique_ptr<Dali::Toolkit::WebCookieManager>(new WebCookieManager(mWebEngine.GetCookieManager()));
206     mWebSettings        = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
207     mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
208   }
209 }
210
211 Dali::Toolkit::WebSettings* WebView::GetSettings() const
212 {
213   return mWebSettings.get();
214 }
215
216 Dali::Toolkit::WebContext* WebView::GetContext() const
217 {
218   return mWebContext.get();
219 }
220
221 Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const
222 {
223   return mWebCookieManager.get();
224 }
225
226 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
227 {
228   return mWebBackForwardList.get();
229 }
230
231 Dali::Toolkit::ImageView& WebView::GetFavicon()
232 {
233   if(mWebEngine)
234   {
235     Dali::PixelData pixelData = mWebEngine.GetFavicon();
236     std::string     url       = Dali::Toolkit::Image::GenerateUrl(pixelData);
237     mFaviconView              = Dali::Toolkit::ImageView::New(url);
238     mFaviconView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
239     mFaviconView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixelData.GetWidth(), pixelData.GetHeight()));
240   }
241   return mFaviconView;
242 }
243
244 void WebView::LoadUrl(const std::string& url)
245 {
246   mUrl = url;
247   if(mWebEngine)
248   {
249     Texture           texture        = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
250     const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
251     mVisual                          = Toolkit::VisualFactory::Get().CreateVisual(
252       {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
253        {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
254
255     if(mVisual)
256     {
257       // Clean up previously registered visual and add new one.
258       DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
259       mWebEngine.LoadUrl(url);
260     }
261
262     if(mVideoHoleEnabled)
263     {
264       EnableBlendMode(false);
265     }
266   }
267 }
268
269 void WebView::LoadHtmlString(const std::string& htmlString)
270 {
271   if(mWebEngine)
272   {
273     Texture           texture        = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
274     const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
275     mVisual                          = Toolkit::VisualFactory::Get().CreateVisual(
276       {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
277        {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
278
279     if(mVisual)
280     {
281       DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
282       mWebEngine.LoadHtmlString(htmlString);
283     }
284
285     if(mVideoHoleEnabled)
286     {
287       EnableBlendMode(false);
288     }
289   }
290 }
291
292 void WebView::Reload()
293 {
294   if(mWebEngine)
295   {
296     mWebEngine.Reload();
297   }
298 }
299
300 void WebView::StopLoading()
301 {
302   if(mWebEngine)
303   {
304     mWebEngine.StopLoading();
305   }
306 }
307
308 void WebView::Suspend()
309 {
310   if(mWebEngine)
311   {
312     mWebEngine.Suspend();
313   }
314 }
315
316 void WebView::Resume()
317 {
318   if(mWebEngine)
319   {
320     mWebEngine.Resume();
321   }
322 }
323
324 void WebView::ScrollBy(int deltaX, int deltaY)
325 {
326   if(mWebEngine)
327   {
328     mWebEngine.ScrollBy(deltaX, deltaY);
329   }
330 }
331
332 bool WebView::CanGoForward()
333 {
334   return mWebEngine ? mWebEngine.CanGoForward() : false;
335 }
336
337 void WebView::GoForward()
338 {
339   if(mWebEngine)
340   {
341     mWebEngine.GoForward();
342   }
343 }
344
345 bool WebView::CanGoBack()
346 {
347   return mWebEngine ? mWebEngine.CanGoBack() : false;
348 }
349
350 void WebView::GoBack()
351 {
352   if(mWebEngine)
353   {
354     mWebEngine.GoBack();
355   }
356 }
357
358 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
359 {
360   if(mWebEngine)
361   {
362     mWebEngine.EvaluateJavaScript(script, resultHandler);
363   }
364 }
365
366 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
367 {
368   if(mWebEngine)
369   {
370     mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
371   }
372 }
373
374 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
375 {
376   if(mWebEngine)
377   {
378     mWebEngine.RegisterJavaScriptAlertCallback(callback);
379   }
380 }
381
382 void WebView::JavaScriptAlertReply()
383 {
384   if(mWebEngine)
385   {
386     mWebEngine.JavaScriptAlertReply();
387   }
388 }
389
390 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
391 {
392   if(mWebEngine)
393   {
394     mWebEngine.RegisterJavaScriptConfirmCallback(callback);
395   }
396 }
397
398 void WebView::JavaScriptConfirmReply(bool confirmed)
399 {
400   if(mWebEngine)
401   {
402     mWebEngine.JavaScriptConfirmReply(confirmed);
403   }
404 }
405
406 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
407 {
408   if(mWebEngine)
409   {
410     mWebEngine.RegisterJavaScriptPromptCallback(callback);
411   }
412 }
413
414 void WebView::JavaScriptPromptReply(const std::string& result)
415 {
416   if(mWebEngine)
417   {
418     mWebEngine.JavaScriptPromptReply(result);
419   }
420 }
421
422 void WebView::ClearHistory()
423 {
424   if(mWebEngine)
425   {
426     mWebEngine.ClearHistory();
427   }
428 }
429
430 void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/)
431 {
432   if(!mWebEngine)
433     return;
434
435   Actor self(Self());
436
437   bool    positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
438   Vector3 actorSize               = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
439   Vector3 anchorPointOffSet       = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
440   Vector2 screenPosition          = self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
441
442   Dali::Rect<int> displayArea;
443   displayArea.x      = screenPosition.x - anchorPointOffSet.x;
444   displayArea.y      = screenPosition.y - anchorPointOffSet.y;
445   displayArea.width  = actorSize.x;
446   displayArea.height = actorSize.y;
447
448   Size displaySize = Size(displayArea.width, displayArea.height);
449   if(mWebViewSize != displaySize)
450   {
451     mWebViewSize = displaySize;
452   }
453
454   if(mWebViewArea != displayArea)
455   {
456     mWebViewArea = displayArea;
457     mWebEngine.UpdateDisplayArea(mWebViewArea);
458   }
459 }
460
461 void WebView::EnableVideoHole(bool enabled)
462 {
463   mVideoHoleEnabled = enabled;
464
465   EnableBlendMode(!mVideoHoleEnabled);
466
467   if(mWebEngine)
468   {
469     mWebEngine.EnableVideoHole(mVideoHoleEnabled);
470   }
471 }
472
473 void WebView::EnableBlendMode(bool blendEnabled)
474 {
475   Actor self = Self();
476   for(uint32_t i = 0; i < self.GetRendererCount(); i++)
477   {
478     Dali::Renderer render = self.GetRendererAt(i);
479     render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
480   }
481 }
482
483 void WebView::ClearAllTilesResources()
484 {
485   if(mWebEngine)
486   {
487     mWebEngine.ClearAllTilesResources();
488   }
489 }
490
491 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal()
492 {
493   return mPageLoadStartedSignal;
494 }
495
496 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadInProgressSignal()
497 {
498   return mPageLoadInProgressSignal;
499 }
500
501 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadFinishedSignal()
502 {
503   return mPageLoadFinishedSignal;
504 }
505
506 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& WebView::PageLoadErrorSignal()
507 {
508   return mPageLoadErrorSignal;
509 }
510
511 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& WebView::ScrollEdgeReachedSignal()
512 {
513   return mScrollEdgeReachedSignal;
514 }
515
516 Dali::Toolkit::WebView::WebViewUrlChangedSignalType& WebView::UrlChangedSignal()
517 {
518   return mUrlChangedSignal;
519 }
520
521 void WebView::OnPageLoadStarted(const std::string& url)
522 {
523   if(!mPageLoadStartedSignal.Empty())
524   {
525     Dali::Toolkit::WebView handle(GetOwner());
526     mPageLoadStartedSignal.Emit(handle, url);
527   }
528 }
529
530 void WebView::OnPageLoadInProgress(const std::string& url)
531 {
532   if(!mPageLoadInProgressSignal.Empty())
533   {
534     Dali::Toolkit::WebView handle(GetOwner());
535     mPageLoadInProgressSignal.Emit(handle, url);
536   }
537 }
538
539 void WebView::OnPageLoadFinished(const std::string& url)
540 {
541   if(!mPageLoadFinishedSignal.Empty())
542   {
543     Dali::Toolkit::WebView handle(GetOwner());
544     mPageLoadFinishedSignal.Emit(handle, url);
545   }
546 }
547
548 void WebView::OnPageLoadError(const std::string& url, int errorCode)
549 {
550   if(!mPageLoadErrorSignal.Empty())
551   {
552     Dali::Toolkit::WebView handle(GetOwner());
553     mPageLoadErrorSignal.Emit(handle, url, static_cast<Toolkit::WebView::LoadErrorCode>(errorCode));
554   }
555 }
556
557 void WebView::OnScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge edge)
558 {
559   if(!mScrollEdgeReachedSignal.Empty())
560   {
561     Dali::Toolkit::WebView handle(GetOwner());
562     mScrollEdgeReachedSignal.Emit(handle, edge);
563   }
564 }
565
566 void WebView::OnUrlChanged(const std::string& url)
567 {
568   if(!mUrlChangedSignal.Empty())
569   {
570     Dali::Toolkit::WebView handle(GetOwner());
571     mUrlChangedSignal.Emit(handle, url);
572   }
573 }
574
575 bool WebView::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
576 {
577   Dali::BaseHandle handle(object);
578
579   bool             connected = false;
580   Toolkit::WebView webView   = Toolkit::WebView::DownCast(handle);
581
582   if(0 == strcmp(signalName.c_str(), PAGE_LOAD_STARTED_SIGNAL))
583   {
584     webView.PageLoadStartedSignal().Connect(tracker, functor);
585     connected = true;
586   }
587   else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_IN_PROGRESS_SIGNAL))
588   {
589     webView.PageLoadInProgressSignal().Connect(tracker, functor);
590     connected = true;
591   }
592   else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_FINISHED_SIGNAL))
593   {
594     webView.PageLoadFinishedSignal().Connect(tracker, functor);
595     connected = true;
596   }
597   else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_ERROR_SIGNAL))
598   {
599     webView.PageLoadErrorSignal().Connect(tracker, functor);
600     connected = true;
601   }
602   else if(0 == strcmp(signalName.c_str(), SCROLL_EDGE_REACHED_SIGNAL))
603   {
604     webView.ScrollEdgeReachedSignal().Connect(tracker, functor);
605     connected = true;
606   }
607   else if(0 == strcmp(signalName.c_str(), URL_CHANGED_SIGNAL))
608   {
609     webView.UrlChangedSignal().Connect(tracker, functor);
610     connected = true;
611   }
612
613   return connected;
614 }
615
616 Vector3 WebView::GetNaturalSize()
617 {
618   if(mVisual)
619   {
620     Vector2 rendererNaturalSize;
621     mVisual.GetNaturalSize(rendererNaturalSize);
622     return Vector3(rendererNaturalSize);
623   }
624
625   return Vector3(mWebViewSize);
626 }
627
628 void WebView::OnSceneConnection(int depth)
629 {
630   Control::OnSceneConnection(depth);
631
632   EnableBlendMode(!mVideoHoleEnabled);
633 }
634
635 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
636 {
637   Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
638
639   if(webView)
640   {
641     WebView& impl = GetImpl(webView);
642     switch(index)
643     {
644       case Toolkit::WebView::Property::URL:
645       {
646         std::string url;
647         if(value.Get(url))
648         {
649           impl.LoadUrl(url);
650         }
651         break;
652       }
653       case Toolkit::WebView::Property::USER_AGENT:
654       {
655         std::string input;
656         if(value.Get(input))
657         {
658           impl.SetUserAgent(input);
659         }
660         break;
661       }
662       case Toolkit::WebView::Property::SCROLL_POSITION:
663       {
664         Vector2 input;
665         if(value.Get(input))
666         {
667           impl.SetScrollPosition(input.x, input.y);
668         }
669         break;
670       }
671       case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
672       {
673         bool input;
674         if(value.Get(input))
675         {
676           impl.EnableVideoHole(input);
677         }
678         break;
679       }
680       case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
681       {
682         bool input;
683         if(value.Get(input))
684         {
685           impl.EnableMouseEvents(input);
686         }
687         break;
688       }
689       case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
690       {
691         bool input;
692         if(value.Get(input))
693         {
694           impl.EnableKeyEvents(input);
695         }
696         break;
697       }
698     }
699   }
700 }
701
702 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
703 {
704   Property::Value value;
705
706   Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
707
708   if(webView)
709   {
710     WebView& impl = GetImpl(webView);
711     switch(propertyIndex)
712     {
713       case Toolkit::WebView::Property::URL:
714       {
715         value = impl.mUrl;
716         break;
717       }
718       case Toolkit::WebView::Property::USER_AGENT:
719       {
720         value = impl.GetUserAgent();
721         break;
722       }
723       case Toolkit::WebView::Property::SCROLL_POSITION:
724       {
725         value = impl.GetScrollPosition();
726         break;
727       }
728       case Toolkit::WebView::Property::SCROLL_SIZE:
729       {
730         value = impl.GetScrollSize();
731         break;
732       }
733       case Toolkit::WebView::Property::CONTENT_SIZE:
734       {
735         value = impl.GetContentSize();
736         break;
737       }
738       case Toolkit::WebView::Property::TITLE:
739       {
740         value = impl.GetTitle();
741         break;
742       }
743       case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
744       {
745         value = impl.mVideoHoleEnabled;
746         break;
747       }
748       case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
749       {
750         value = impl.mMouseEventsEnabled;
751         break;
752       }
753       case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
754       {
755         value = impl.mKeyEventsEnabled;
756         break;
757       }
758       default:
759         break;
760     }
761   }
762
763   return value;
764 }
765
766 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
767 {
768   bool result = false;
769
770   if(mWebEngine)
771   {
772     result = mWebEngine.SendTouchEvent(touch);
773   }
774   return result;
775 }
776
777 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
778 {
779   bool result = false;
780
781   if(mWebEngine)
782   {
783     result = mWebEngine.SendKeyEvent(event);
784   }
785   return result;
786 }
787
788 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
789 {
790   bool result = false;
791   if(mWebEngine)
792   {
793     result = mWebEngine.SendHoverEvent(hover);
794   }
795   return result;
796 }
797
798 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
799 {
800   bool result = false;
801   if(mWebEngine)
802   {
803     result = mWebEngine.SendWheelEvent(wheel);
804   }
805   return result;
806 }
807
808 void WebView::OnKeyInputFocusGained()
809 {
810   if(mWebEngine)
811   {
812     mWebEngine.SetFocus(true);
813   }
814
815   EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
816 }
817
818 void WebView::OnKeyInputFocusLost()
819 {
820   if(mWebEngine)
821   {
822     mWebEngine.SetFocus(false);
823   }
824
825   EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
826 }
827
828 void WebView::SetScrollPosition(int x, int y)
829 {
830   if(mWebEngine)
831   {
832     mWebEngine.SetScrollPosition(x, y);
833   }
834 }
835
836 Dali::Vector2 WebView::GetScrollPosition() const
837 {
838   return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
839 }
840
841 Dali::Vector2 WebView::GetScrollSize() const
842 {
843   return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
844 }
845
846 Dali::Vector2 WebView::GetContentSize() const
847 {
848   return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
849 }
850
851 std::string WebView::GetTitle() const
852 {
853   return mWebEngine ? mWebEngine.GetTitle() : kEmptyString;
854 }
855
856 const std::string& WebView::GetUserAgent() const
857 {
858   return mWebEngine ? mWebEngine.GetUserAgent() : kEmptyString;
859 }
860
861 void WebView::SetUserAgent(const std::string& userAgent)
862 {
863   if(mWebEngine)
864   {
865     mWebEngine.SetUserAgent(userAgent);
866   }
867 }
868
869 void WebView::EnableMouseEvents(bool enabled)
870 {
871   if(mWebEngine)
872   {
873     mMouseEventsEnabled = enabled;
874     mWebEngine.EnableMouseEvents(enabled);
875   }
876 }
877
878 void WebView::EnableKeyEvents(bool enabled)
879 {
880   if(mWebEngine)
881   {
882     mKeyEventsEnabled = enabled;
883     mWebEngine.EnableKeyEvents(enabled);
884   }
885 }
886
887 #undef GET_ENUM_STRING
888 #undef GET_ENUM_VALUE
889
890 } // namespace Internal
891
892 } // namespace Toolkit
893
894 } // namespace Dali