97b545e176dbed9fec22f5d867306d937eff46b6
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / web-view / web-view-impl.cpp
1 /*
2  * Copyright (c) 2020 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 <cstring>
23 #include <dali/devel-api/adaptor-framework/web-engine-back-forward-list.h>
24 #include <dali/devel-api/adaptor-framework/web-engine-context.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
26 #include <dali/devel-api/adaptor-framework/web-engine-settings.h>
27 #include <dali/devel-api/scripting/enum-helper.h>
28 #include <dali/devel-api/scripting/scripting.h>
29 #include <dali/devel-api/common/stage.h>
30 #include <dali/public-api/adaptor-framework/native-image-source.h>
31 #include <dali/public-api/object/type-registry.h>
32 #include <dali/public-api/object/type-registry-helper.h>
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
48 namespace Toolkit
49 {
50
51 namespace Internal
52 {
53
54 namespace
55 {
56
57 BaseHandle Create()
58 {
59   return Toolkit::WebView::New();
60 }
61
62 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::WebView, Toolkit::Control, Create )
63
64 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "url",                     STRING,  URL                        )
65 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "userAgent",               STRING,  USER_AGENT                 )
66 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "scrollPosition",          VECTOR2, SCROLL_POSITION            )
67 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "scrollSize",              VECTOR2, SCROLL_SIZE                )
68 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "contentSize",             VECTOR2, CONTENT_SIZE               )
69 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "title",                   STRING,  TITLE                      )
70 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "videoHoleEnabled",        BOOLEAN, VIDEO_HOLE_ENABLED         )
71
72 DALI_SIGNAL_REGISTRATION(   Toolkit, WebView, "pageLoadStarted",         PAGE_LOAD_STARTED_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
77 DALI_TYPE_REGISTRATION_END()
78
79 const std::string kEmptyString;
80
81 const char* DEFAULT_SAMPLER_TYPENAME = "sampler2D";
82
83 const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER(
84   varying mediump vec2 vTexCoord;\n
85   uniform sampler2D sTexture;\n
86   uniform lowp vec4 uColor;\n
87   uniform lowp vec3 mixColor;\n
88   uniform lowp float preMultipliedAlpha;\n
89   \n
90   void main()\n
91   {\n
92       gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n
93   }\n
94 );
95
96 Dali::Toolkit::Visual::Base CreateNativeImageVisual( NativeImageInterfacePtr nativeImageInterface )
97 {
98   std::string fragmentShader;
99
100   const char* fragmentPrefix = nativeImageInterface->GetCustomFragmentPrefix();
101   if( fragmentPrefix )
102   {
103     fragmentShader = fragmentPrefix;
104     fragmentShader += FRAGMENT_SHADER_TEXTURE;
105   }
106   else
107   {
108     fragmentShader = FRAGMENT_SHADER_TEXTURE;
109   }
110
111   const char* customSamplerTypename = nativeImageInterface->GetCustomSamplerTypename();
112   if( customSamplerTypename )
113   {
114     fragmentShader.replace( fragmentShader.find( DEFAULT_SAMPLER_TYPENAME ), strlen( DEFAULT_SAMPLER_TYPENAME ), customSamplerTypename );
115   }
116
117   Texture texture = Dali::Texture::New( *nativeImageInterface );
118   const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture( texture );
119
120   return Toolkit::VisualFactory::Get().CreateVisual(
121     { { Toolkit::Visual::Property::TYPE,  Toolkit::Visual::IMAGE } ,
122       { Toolkit::Visual::Property::SHADER, { { Toolkit::Visual::Shader::Property::FRAGMENT_SHADER, fragmentShader } } },
123       { Toolkit::ImageVisual::Property::URL, nativeImageUrl } } );
124 }
125
126 } // anonymous namepsace
127
128 #define GET_ENUM_STRING( structName, inputExp ) \
129   Scripting::GetLinearEnumerationName< Toolkit::WebView::structName::Type >( static_cast< Toolkit::WebView::structName::Type >( inputExp ), structName##_TABLE, structName##_TABLE_COUNT )
130
131 #define GET_ENUM_VALUE( structName, inputExp, outputExp ) \
132   Scripting::GetEnumerationProperty< Toolkit::WebView::structName::Type >( inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp )
133
134 WebView::WebView( const std::string& locale, const std::string& timezoneId )
135 : Control( ControlBehaviour( ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS ) ),
136   mUrl(),
137   mVisual(),
138   mWebViewSize( Stage::GetCurrent().GetSize() ),
139   mWebEngine(),
140   mPageLoadStartedSignal(),
141   mPageLoadFinishedSignal(),
142   mPageLoadErrorSignal(),
143   mVideoHoleEnabled( true ),
144   mWebViewArea ( 0, 0, mWebViewSize.width, mWebViewSize.height )
145 {
146   mWebEngine = Dali::WebEngine::New();
147
148   // WebEngine is empty when it is not properly initialized.
149   if( mWebEngine )
150   {
151     mWebEngine.Create( mWebViewSize.width, mWebViewSize.height, locale, timezoneId );
152   }
153 }
154
155 WebView::WebView( int argc, char** argv )
156 : Control( ControlBehaviour( ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS ) ),
157   mUrl(),
158   mVisual(),
159   mWebViewSize( Stage::GetCurrent().GetSize() ),
160   mWebEngine(),
161   mPageLoadStartedSignal(),
162   mPageLoadFinishedSignal(),
163   mPageLoadErrorSignal(),
164   mVideoHoleEnabled( true ),
165   mWebViewArea ( 0, 0, mWebViewSize.width, mWebViewSize.height )
166 {
167   mWebEngine = Dali::WebEngine::New();
168
169   // WebEngine is empty when it is not properly initialized.
170   if ( mWebEngine )
171   {
172     mWebEngine.Create( mWebViewSize.width, mWebViewSize.height, argc, argv );
173   }
174 }
175
176 WebView::WebView()
177 : WebView( "", "" )
178 {
179 }
180
181 WebView::~WebView()
182 {
183   if( mWebEngine )
184   {
185     mWebEngine.Destroy();
186   }
187 }
188
189 Toolkit::WebView WebView::New()
190 {
191   WebView* impl = new WebView();
192   Toolkit::WebView handle = Toolkit::WebView( *impl );
193
194   impl->Initialize();
195   return handle;
196 }
197
198 Toolkit::WebView WebView::New( const std::string& locale, const std::string& timezoneId )
199 {
200   WebView* impl = new WebView( locale, timezoneId );
201   Toolkit::WebView handle = Toolkit::WebView( *impl );
202
203   impl->Initialize();
204   return handle;
205 }
206
207 Toolkit::WebView WebView::New( int argc, char** argv )
208 {
209   WebView* impl = new WebView( argc, argv );
210   Toolkit::WebView handle = Toolkit::WebView( *impl );
211
212   impl->Initialize();
213   return handle;
214 }
215
216 void WebView::OnInitialize()
217 {
218   Actor self = Self();
219
220   self.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
221   self.TouchedSignal().Connect( this, &WebView::OnTouchEvent );
222
223   mPositionUpdateNotification = self.AddPropertyNotification( Actor::Property::WORLD_POSITION, StepCondition( 1.0f, 1.0f ) );
224   mSizeUpdateNotification = self.AddPropertyNotification( Actor::Property::SIZE, StepCondition( 1.0f, 1.0f ) );
225   mScaleUpdateNotification = self.AddPropertyNotification( Actor::Property::WORLD_SCALE, StepCondition( 0.1f, 1.0f ) );
226   mPositionUpdateNotification.NotifySignal().Connect( this, &WebView::UpdateDisplayArea );
227   mSizeUpdateNotification.NotifySignal().Connect( this, &WebView::UpdateDisplayArea );
228   mScaleUpdateNotification.NotifySignal().Connect( this, &WebView::UpdateDisplayArea );
229
230   if( mWebEngine )
231   {
232     mWebEngine.PageLoadStartedSignal().Connect( this, &WebView::OnPageLoadStarted );
233     mWebEngine.PageLoadFinishedSignal().Connect( this, &WebView::OnPageLoadFinished );
234     mWebEngine.PageLoadErrorSignal().Connect( this, &WebView::OnPageLoadError );
235     mWebEngine.ScrollEdgeReachedSignal().Connect( this, &WebView::OnScrollEdgeReached );
236
237     mWebContext = std::unique_ptr<Dali::Toolkit::WebContext>( new WebContext( mWebEngine.GetContext() ) );
238     mWebCookieManager = std::unique_ptr<Dali::Toolkit::WebCookieManager>( new WebCookieManager( mWebEngine.GetCookieManager() ) );
239     mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>( new WebSettings( mWebEngine.GetSettings() ) );
240     mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>( new WebBackForwardList( mWebEngine.GetBackForwardList() ) );
241   }
242 }
243
244 Dali::Toolkit::WebSettings* WebView::GetSettings() const
245 {
246   return mWebSettings.get();
247 }
248
249 Dali::Toolkit::WebContext* WebView::GetContext() const
250 {
251   return mWebContext.get();
252 }
253
254 Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const
255 {
256   return mWebCookieManager.get();
257 }
258
259 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
260 {
261   return mWebBackForwardList.get();
262 }
263
264 Dali::Toolkit::ImageView WebView::GetFavicon() const
265 {
266   Dali::Toolkit::ImageView faviconView;
267   if(mWebEngine)
268   {
269     Dali::PixelData pixelData = mWebEngine.GetFavicon();
270     if(pixelData)
271     {
272       std::string url = Dali::Toolkit::Image::GenerateUrl(pixelData);
273       faviconView     = Dali::Toolkit::ImageView::New(url);
274       faviconView.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
275     }
276   }
277   return faviconView;
278 }
279
280 void WebView::LoadUrl( const std::string& url )
281 {
282   mUrl = url;
283   if( mWebEngine )
284   {
285     mVisual = CreateNativeImageVisual( mWebEngine.GetNativeImageSource() );
286
287     if( mVisual )
288     {
289       // Clean up previously registered visual and add new one.
290       DevelControl::RegisterVisual( *this, Toolkit::WebView::Property::URL, mVisual );
291       mWebEngine.LoadUrl( url );
292     }
293
294     if ( mVideoHoleEnabled )
295     {
296       EnableBlendMode( false );
297     }
298   }
299 }
300
301 void WebView::LoadHtmlString( const std::string& htmlString )
302 {
303   if( mWebEngine )
304   {
305     mVisual = CreateNativeImageVisual( mWebEngine.GetNativeImageSource() );
306
307     if( mVisual )
308     {
309       DevelControl::RegisterVisual( *this, Toolkit::WebView::Property::URL, mVisual );
310       mWebEngine.LoadHtmlString( htmlString );
311     }
312
313     if ( mVideoHoleEnabled )
314     {
315       EnableBlendMode( false );
316     }
317   }
318 }
319
320 void WebView::Reload()
321 {
322   if( mWebEngine )
323   {
324     mWebEngine.Reload();
325   }
326 }
327
328 void WebView::StopLoading()
329 {
330   if( mWebEngine )
331   {
332     mWebEngine.StopLoading();
333   }
334 }
335
336 void WebView::Suspend()
337 {
338   if( mWebEngine )
339   {
340     mWebEngine.Suspend();
341   }
342 }
343
344 void WebView::Resume()
345 {
346   if( mWebEngine )
347   {
348     mWebEngine.Resume();
349   }
350 }
351
352 void WebView::ScrollBy( int deltaX, int deltaY )
353 {
354   if ( mWebEngine )
355   {
356     mWebEngine.ScrollBy( deltaX, deltaY );
357   }
358 }
359
360 bool WebView::CanGoForward()
361 {
362   return mWebEngine ? mWebEngine.CanGoForward() : false;
363 }
364
365 void WebView::GoForward()
366 {
367   if( mWebEngine )
368   {
369     mWebEngine.GoForward();
370   }
371 }
372
373 bool WebView::CanGoBack()
374 {
375   return mWebEngine ? mWebEngine.CanGoBack() : false;
376 }
377
378 void WebView::GoBack()
379 {
380   if( mWebEngine )
381   {
382     mWebEngine.GoBack();
383   }
384 }
385
386 void WebView::EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler )
387 {
388   if( mWebEngine )
389   {
390     mWebEngine.EvaluateJavaScript( script, resultHandler );
391   }
392 }
393
394 void WebView::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler )
395 {
396   if( mWebEngine )
397   {
398     mWebEngine.AddJavaScriptMessageHandler( exposedObjectName, handler );
399   }
400 }
401
402 void WebView::ClearAllTilesResources()
403 {
404   if( mWebEngine )
405   {
406     mWebEngine.ClearAllTilesResources();
407   }
408 }
409
410 void WebView::ClearHistory()
411 {
412   if( mWebEngine )
413   {
414     mWebEngine.ClearHistory();
415   }
416 }
417
418 void WebView::SetTtsFocus(bool focused)
419 {
420   if(mWebEngine && !HasKeyInputFocus())
421   {
422     mWebEngine.SetFocus(focused);
423   }
424 }
425
426 void WebView::UpdateDisplayArea( Dali::PropertyNotification& /*source*/ )
427 {
428   if( !mWebEngine )
429     return;
430
431   Actor self( Self() );
432
433   bool positionUsesAnchorPoint = self.GetProperty< bool >( Actor::Property::POSITION_USES_ANCHOR_POINT );
434   Vector3 actorSize = self.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) * self.GetCurrentProperty< Vector3 >( Actor::Property::SCALE );
435   Vector3 anchorPointOffSet = actorSize * ( positionUsesAnchorPoint ? self.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ) : AnchorPoint::TOP_LEFT );
436   Vector2 screenPosition = self.GetProperty< Vector2 >( Actor::Property::SCREEN_POSITION );
437
438   Dali::Rect< int > displayArea;
439   displayArea.x = screenPosition.x - anchorPointOffSet.x;
440   displayArea.y = screenPosition.y - anchorPointOffSet.y;
441   displayArea.width = actorSize.x;
442   displayArea.height = actorSize.y;
443
444   Size displaySize = Size( displayArea.width, displayArea.height );
445   if ( mWebViewSize != displaySize )
446   {
447     mWebViewSize = displaySize;
448   }
449
450   if (mWebViewArea != displayArea )
451   {
452     mWebViewArea = displayArea;
453     mWebEngine.UpdateDisplayArea( mWebViewArea );
454   }
455 }
456
457 void WebView::EnableVideoHole( bool enabled )
458 {
459   mVideoHoleEnabled = enabled;
460
461   EnableBlendMode( !mVideoHoleEnabled );
462
463   if( mWebEngine )
464   {
465     mWebEngine.EnableVideoHole( mVideoHoleEnabled );
466   }
467 }
468
469 void WebView::EnableBlendMode( bool blendEnabled )
470 {
471   Actor self = Self();
472   for (uint32_t i = 0; i < self.GetRendererCount(); i++)
473   {
474     Dali::Renderer render = self.GetRendererAt( i );
475     render.SetProperty( Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF );
476   }
477 }
478
479 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal()
480 {
481   return mPageLoadStartedSignal;
482 }
483
484 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadFinishedSignal()
485 {
486   return mPageLoadFinishedSignal;
487 }
488
489 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& WebView::PageLoadErrorSignal()
490 {
491   return mPageLoadErrorSignal;
492 }
493
494 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& WebView::ScrollEdgeReachedSignal()
495 {
496   return mScrollEdgeReachedSignal;
497 }
498
499 void WebView::OnPageLoadStarted( const std::string& url )
500 {
501   if( !mPageLoadStartedSignal.Empty() )
502   {
503     Dali::Toolkit::WebView handle( GetOwner() );
504     mPageLoadStartedSignal.Emit( handle, url );
505   }
506 }
507
508 void WebView::OnPageLoadFinished( const std::string& url )
509 {
510   if( !mPageLoadFinishedSignal.Empty() )
511   {
512     Dali::Toolkit::WebView handle( GetOwner() );
513     mPageLoadFinishedSignal.Emit( handle, url );
514   }
515 }
516
517 void WebView::OnPageLoadError( const std::string& url, int errorCode )
518 {
519   if( !mPageLoadErrorSignal.Empty() )
520   {
521     Dali::Toolkit::WebView handle( GetOwner() );
522     mPageLoadErrorSignal.Emit( handle, url, static_cast< Toolkit::WebView::LoadErrorCode >( errorCode ) );
523   }
524 }
525
526 void WebView::OnScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge )
527 {
528   if( !mScrollEdgeReachedSignal.Empty() )
529   {
530     Dali::Toolkit::WebView handle( GetOwner() );
531     mScrollEdgeReachedSignal.Emit( handle, edge );
532   }
533 }
534
535 bool WebView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
536 {
537   Dali::BaseHandle handle( object );
538
539   bool connected = false;
540   Toolkit::WebView webView = Toolkit::WebView::DownCast( handle );
541
542   if( 0 == strcmp( signalName.c_str(), PAGE_LOAD_STARTED_SIGNAL ) )
543   {
544     webView.PageLoadStartedSignal().Connect( tracker, functor );
545     connected = true;
546   }
547   else if( 0 == strcmp( signalName.c_str(), PAGE_LOAD_FINISHED_SIGNAL ) )
548   {
549     webView.PageLoadFinishedSignal().Connect( tracker, functor );
550     connected = true;
551   }
552   else if( 0 == strcmp( signalName.c_str(), PAGE_LOAD_ERROR_SIGNAL ) )
553   {
554     webView.PageLoadErrorSignal().Connect( tracker, functor );
555     connected = true;
556   }
557   else if( 0 == strcmp( signalName.c_str(), SCROLL_EDGE_REACHED_SIGNAL ) )
558   {
559     webView.ScrollEdgeReachedSignal().Connect( tracker, functor );
560     connected = true;
561   }
562
563   return connected;
564 }
565
566 Vector3 WebView::GetNaturalSize()
567 {
568   if( mVisual )
569   {
570     Vector2 rendererNaturalSize;
571     mVisual.GetNaturalSize( rendererNaturalSize );
572     return Vector3( rendererNaturalSize );
573   }
574
575   return Vector3( mWebViewSize );
576 }
577
578 void WebView::OnSceneConnection( int depth )
579 {
580   Control::OnSceneConnection( depth );
581
582   EnableBlendMode( !mVideoHoleEnabled );
583 }
584
585 void WebView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
586 {
587   Toolkit::WebView webView = Toolkit::WebView::DownCast( Dali::BaseHandle( object ) );
588
589   if( webView )
590   {
591     WebView& impl = GetImpl( webView );
592     switch( index )
593     {
594       case Toolkit::WebView::Property::URL:
595       {
596         std::string url;
597         if( value.Get( url ) )
598         {
599           impl.LoadUrl( url );
600         }
601         break;
602       }
603       case Toolkit::WebView::Property::USER_AGENT:
604       {
605         std::string input;
606         if( value.Get( input ) )
607         {
608           impl.SetUserAgent( input );
609         }
610         break;
611       }
612       case Toolkit::WebView::Property::SCROLL_POSITION:
613       {
614         Vector2 input;
615         if ( value.Get( input ) )
616         {
617           impl.SetScrollPosition( input.x, input.y );
618         }
619         break;
620       }
621       case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
622       {
623         bool input;
624         if( value.Get( input ) )
625         {
626           impl.EnableVideoHole( input );
627         }
628         break;
629       }
630     }
631   }
632 }
633
634 Property::Value WebView::GetProperty( BaseObject* object, Property::Index propertyIndex )
635 {
636   Property::Value value;
637
638   Toolkit::WebView webView = Toolkit::WebView::DownCast( Dali::BaseHandle( object ) );
639
640   if( webView )
641   {
642     WebView& impl = GetImpl( webView );
643     switch( propertyIndex )
644     {
645       case Toolkit::WebView::Property::URL:
646       {
647         value = impl.mUrl;
648         break;
649       }
650       case Toolkit::WebView::Property::USER_AGENT:
651       {
652         value = impl.GetUserAgent();
653         break;
654       }
655       case Toolkit::WebView::Property::SCROLL_POSITION:
656       {
657         int x, y;
658         impl.GetScrollPosition( x, y );
659         value = Vector2( x, y );
660         break;
661       }
662       case Toolkit::WebView::Property::SCROLL_SIZE:
663       {
664         int width, height;
665         impl.GetScrollSize( width, height );
666         value = Vector2( width, height );
667         break;
668       }
669       case Toolkit::WebView::Property::CONTENT_SIZE:
670       {
671         int width, height;
672         impl.GetContentSize( width, height );
673         value = Vector2( width, height );
674         break;
675       }
676       case Toolkit::WebView::Property::TITLE:
677       {
678         value = impl.GetTitle();
679         break;
680       }
681       case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
682       {
683         value = impl.mVideoHoleEnabled;
684         break;
685       }
686       default:
687          break;
688     }
689   }
690
691   return value;
692 }
693
694 bool WebView::OnTouchEvent( Actor actor, const Dali::TouchEvent& touch )
695 {
696   bool result = false;
697
698   if( mWebEngine )
699   {
700     result = mWebEngine.SendTouchEvent( touch );
701   }
702   return result;
703 }
704
705 bool WebView::OnKeyEvent( const Dali::KeyEvent& event )
706 {
707   bool result = false;
708
709   if( mWebEngine )
710   {
711     result = mWebEngine.SendKeyEvent( event );
712   }
713   return result;
714 }
715
716 void WebView::OnKeyInputFocusGained()
717 {
718   if( mWebEngine )
719   {
720     mWebEngine.SetFocus( true );
721   }
722
723   EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
724 }
725
726 void WebView::OnKeyInputFocusLost()
727 {
728   if( mWebEngine )
729   {
730     mWebEngine.SetFocus( false );
731   }
732
733   EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
734 }
735
736 void WebView::SetScrollPosition( int x, int y )
737 {
738   if( mWebEngine )
739   {
740     mWebEngine.SetScrollPosition( x, y );
741   }
742 }
743
744 void WebView::GetScrollPosition( int& x, int& y ) const
745 {
746   if( mWebEngine )
747   {
748     mWebEngine.GetScrollPosition( x, y );
749   }
750 }
751
752 void WebView::GetScrollSize( int& width, int& height ) const
753 {
754   if( mWebEngine )
755   {
756     mWebEngine.GetScrollSize( width, height );
757   }
758 }
759
760 void WebView::GetContentSize( int& width, int& height ) const
761 {
762   if( mWebEngine )
763   {
764     mWebEngine.GetContentSize( width, height );
765   }
766 }
767
768 std::string WebView::GetTitle() const
769 {
770   return mWebEngine ?  mWebEngine.GetTitle() : kEmptyString;
771 }
772
773 const std::string& WebView::GetUserAgent() const
774 {
775   return mWebEngine ? mWebEngine.GetUserAgent() : kEmptyString;
776 }
777
778 void WebView::SetUserAgent( const std::string& userAgent )
779 {
780   if( mWebEngine )
781   {
782     mWebEngine.SetUserAgent( userAgent );
783   }
784 }
785
786 #undef GET_ENUM_STRING
787 #undef GET_ENUM_VALUE
788
789 } // namespace Internal
790
791 } // namespace Toolkit
792
793 } // namespace Dali