Merge "Make depth-index as 'AUTO' instead of CONTENT change as default, and clamp...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / web-view / web-view-impl.cpp
1 /*
2  * Copyright (c) 2024 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 <dali-toolkit/internal/controls/web-view/web-view-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-back-forward-list.h>
23 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-certificate.h>
24 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-console-message.h>
25 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-context-menu-item.h>
26 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-context-menu.h>
27 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-context.h>
28 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-cookie-manager.h>
29 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-form-repost-decision.h>
30 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-hit-test.h>
31 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-http-auth-handler.h>
32 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-load-error.h>
33 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-policy-decision.h>
34 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-settings.h>
35 #include <dali/devel-api/adaptor-framework/window-devel.h>
36 #include <dali/devel-api/common/stage.h>
37 #include <dali/devel-api/scripting/enum-helper.h>
38 #include <dali/devel-api/scripting/scripting.h>
39 #include <dali/public-api/adaptor-framework/native-image-source.h>
40 #include <dali/public-api/object/type-registry-helper.h>
41 #include <dali/public-api/object/type-registry.h>
42
43 // INTERNAL INCLUDES
44 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
45 #include <dali-toolkit/devel-api/controls/control-devel.h>
46 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h>
47 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
48 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
49 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
50 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
51 #include <dali-toolkit/public-api/image-loader/image-url.h>
52 #include <dali-toolkit/public-api/image-loader/image.h>
53 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
54
55 #include <functional>
56 #include <memory>
57 #include <unordered_map>
58
59 namespace Dali
60 {
61 namespace Toolkit
62 {
63 namespace Internal
64 {
65 namespace
66 {
67 BaseHandle Create()
68 {
69   return Toolkit::WebView::New();
70 }
71
72 // clang-format off
73 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create)
74
75 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url",                     STRING,  URL                       )
76 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent",               STRING,  USER_AGENT                )
77 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition",          VECTOR2, SCROLL_POSITION           )
78 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize",              VECTOR2, SCROLL_SIZE               )
79 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize",             VECTOR2, CONTENT_SIZE              )
80 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title",                   STRING,  TITLE                     )
81 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled",        BOOLEAN, VIDEO_HOLE_ENABLED        )
82 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled",      BOOLEAN, MOUSE_EVENTS_ENABLED      )
83 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled",        BOOLEAN, KEY_EVENTS_ENABLED        )
84 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "documentBackgroundColor", VECTOR4, DOCUMENT_BACKGROUND_COLOR )
85 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tilesClearedWhenHidden",  BOOLEAN, TILES_CLEARED_WHEN_HIDDEN )
86 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tileCoverAreaMultiplier", FLOAT,   TILE_COVER_AREA_MULTIPLIER)
87 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "cursorEnabledByClient",   BOOLEAN, CURSOR_ENABLED_BY_CLIENT  )
88 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "selectedText",            STRING,  SELECTED_TEXT             )
89 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "pageZoomFactor",          FLOAT,   PAGE_ZOOM_FACTOR          )
90 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "textZoomFactor",          FLOAT,   TEXT_ZOOM_FACTOR          )
91 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage",  FLOAT,   LOAD_PROGRESS_PERCENTAGE  )
92
93 DALI_TYPE_REGISTRATION_END()
94 // clang-format on
95
96 std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>>& GetPluginWebViewTable()
97 {
98   static std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>> pluginWebViewMap;
99   return pluginWebViewMap;
100 }
101
102 enum class DisplayAreaCalculateOption
103 {
104   PROPERTY         = 0, ///< Calculate display update area by property
105   CURRENT_PROPERTY = 1, ///< Calculate display update area by current property
106 };
107
108 /**
109  * @brief Helper function to calculate exact display area, offset and size.
110  * It will be useful when view size is not integer value, or view size is not matched with texture size.
111  *
112  * @param[in] self The view itself.
113  * @param[in] option Option of this calculation. Let we decide what kind of property will be used.
114  * @return DisplayArea for this view.
115  */
116 Rect<int32_t> CalculateDisplayArea(Dali::Actor self, DisplayAreaCalculateOption option)
117 {
118   bool    positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
119   Vector3 actorSize               = (option == DisplayAreaCalculateOption::CURRENT_PROPERTY) ? self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE)
120                                                                                              : self.GetProperty<Vector3>(Actor::Property::SIZE) * self.GetProperty<Vector3>(Actor::Property::SCALE);
121   Vector3 anchorPointOffSet       = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
122   Vector2 screenPosition          = (option == DisplayAreaCalculateOption::CURRENT_PROPERTY) ? self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION)
123                                                                                              : Dali::DevelActor::CalculateScreenPosition(self);
124
125   Dali::Rect<int32_t> displayArea;
126   displayArea.x      = screenPosition.x - anchorPointOffSet.x;
127   displayArea.y      = screenPosition.y - anchorPointOffSet.y;
128   displayArea.width  = actorSize.x;
129   displayArea.height = actorSize.y;
130
131   return displayArea;
132 }
133
134 constexpr Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
135
136 /**
137  * @brief Helper function to calculate exact pixel area value by view and texture size.
138  * It will be useful when view size is not integer value, or view size is not matched with texture size.
139  *
140  * @param[in] viewSize The size of view.
141  * @param[in] textureWidth The width of texture, that must be integer type.
142  * @param[in] textureHeight The height of texture, that must be integer type.
143  * @return PixelArea value that image visual can use.
144  */
145 Vector4 CalculatePixelArea(const Size& viewSize, const uint32_t textureWidth, const uint32_t textureHeight)
146 {
147   float widthRatio  = textureWidth == 0u ? 1.0f : viewSize.width / static_cast<float>(textureWidth);
148   float heightRatio = textureHeight == 0u ? 1.0f : viewSize.height / static_cast<float>(textureHeight);
149   return Vector4(0.0f, 0.0f, widthRatio, heightRatio);
150 }
151
152 } // namespace
153
154 WebView::WebView(const std::string& locale, const std::string& timezoneId)
155 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
156   mVisual(),
157   mWebViewSize(Stage::GetCurrent().GetSize()),
158   mWebEngine(),
159   mLastRenderedNativeImageWidth(0u),
160   mLastRenderedNativeImageHeight(0u),
161   mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
162   mVideoHoleEnabled(false),
163   mMouseEventsEnabled(true),
164   mKeyEventsEnabled(true),
165   mVisualChangeRequired(false),
166   mScreenshotCapturedCallback{nullptr},
167   mFrameRenderedCallback{nullptr}
168 {
169   mWebEngine = Dali::WebEngine::New();
170
171   // WebEngine is empty when it is not properly initialized.
172   if(mWebEngine)
173   {
174     mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
175   }
176 }
177
178 WebView::WebView(uint32_t argc, char** argv)
179 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
180   mVisual(),
181   mWebViewSize(Stage::GetCurrent().GetSize()),
182   mWebEngine(),
183   mLastRenderedNativeImageWidth(0u),
184   mLastRenderedNativeImageHeight(0u),
185   mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
186   mVideoHoleEnabled(false),
187   mMouseEventsEnabled(true),
188   mKeyEventsEnabled(true),
189   mVisualChangeRequired(false),
190   mScreenshotCapturedCallback{nullptr},
191   mFrameRenderedCallback{nullptr}
192 {
193   mWebEngine = Dali::WebEngine::New();
194
195   // WebEngine is empty when it is not properly initialized.
196   if(mWebEngine)
197   {
198     mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
199   }
200 }
201
202 WebView::WebView()
203 : WebView("", "")
204 {
205 }
206
207 WebView::~WebView()
208 {
209   if(mWebEngine)
210   {
211     auto iter = GetPluginWebViewTable().find(mWebEngine.GetPlugin());
212     if(iter != GetPluginWebViewTable().end())
213     {
214       GetPluginWebViewTable().erase(iter);
215     }
216     mWebEngine.Destroy();
217   }
218 }
219
220 Toolkit::WebView WebView::New()
221 {
222   WebView*         impl   = new WebView();
223   Toolkit::WebView handle = Toolkit::WebView(*impl);
224   if(impl->GetPlugin())
225   {
226     GetPluginWebViewTable()[impl->GetPlugin()] = handle;
227   }
228   impl->Initialize();
229   return handle;
230 }
231
232 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
233 {
234   WebView*         impl   = new WebView(locale, timezoneId);
235   Toolkit::WebView handle = Toolkit::WebView(*impl);
236   if(impl->GetPlugin())
237   {
238     GetPluginWebViewTable()[impl->GetPlugin()] = handle;
239   }
240   impl->Initialize();
241   return handle;
242 }
243
244 Toolkit::WebView WebView::New(uint32_t argc, char** argv)
245 {
246   WebView*         impl   = new WebView(argc, argv);
247   Toolkit::WebView handle = Toolkit::WebView(*impl);
248   if(impl->GetPlugin())
249   {
250     GetPluginWebViewTable()[impl->GetPlugin()] = handle;
251   }
252   impl->Initialize();
253   return handle;
254 }
255
256 Toolkit::WebView WebView::FindWebView(Dali::WebEnginePlugin* plugin)
257 {
258   auto iter = GetPluginWebViewTable().find(plugin);
259   if(iter != GetPluginWebViewTable().end())
260   {
261     return iter->second.GetHandle();
262   }
263   return Toolkit::WebView();
264 }
265
266 Dali::WebEngineContext* WebView::GetContext()
267 {
268   return Dali::WebEngine::GetContext();
269 }
270
271 Dali::WebEngineCookieManager* WebView::GetCookieManager()
272 {
273   return Dali::WebEngine::GetCookieManager();
274 }
275
276 void WebView::OnInitialize()
277 {
278   Actor self = Self();
279
280   self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
281   self.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
282   self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
283   self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
284   self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
285   Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
286
287   mWebViewVisibleState |= WebViewVisibleStateFlag::SELF_SHOW;
288
289   mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
290   mSizeUpdateNotification     = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
291   mScaleUpdateNotification    = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
292   mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
293   mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
294   mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
295
296   if(mWebEngine)
297   {
298     mWebEngine.RegisterFrameRenderedCallback(std::bind(&WebView::OnFrameRendered, this));
299     mWebSettings        = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
300     mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
301   }
302
303   self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::FILLER);
304 }
305
306 DevelControl::ControlAccessible* WebView::CreateAccessibleObject()
307 {
308   return new WebViewAccessible(Self(), mWebEngine);
309 }
310
311 void WebView::OnRelayout(const Vector2& size, RelayoutContainer& container)
312 {
313   if(!mWebEngine)
314   {
315     return;
316   }
317
318   auto displayArea = CalculateDisplayArea(Self(), DisplayAreaCalculateOption::PROPERTY);
319
320   SetDisplayArea(displayArea);
321 }
322
323 Dali::Toolkit::WebSettings* WebView::GetSettings() const
324 {
325   return mWebSettings.get();
326 }
327
328 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
329 {
330   return mWebBackForwardList.get();
331 }
332
333 Dali::WebEnginePlugin* WebView::GetPlugin() const
334 {
335   return mWebEngine ? mWebEngine.GetPlugin() : nullptr;
336 }
337
338 Dali::Toolkit::ImageView WebView::GetFavicon() const
339 {
340   Dali::Toolkit::ImageView faviconView;
341   if(mWebEngine)
342   {
343     Dali::PixelData pixelData = mWebEngine.GetFavicon();
344     faviconView               = CreateImageView(pixelData);
345   }
346   return faviconView;
347 }
348
349 void WebView::LoadUrl(const std::string& url)
350 {
351   if(mWebEngine)
352   {
353     mWebEngine.LoadUrl(url);
354   }
355 }
356
357 void WebView::LoadHtmlString(const std::string& htmlString)
358 {
359   if(mWebEngine)
360   {
361     mWebEngine.LoadHtmlString(htmlString);
362   }
363 }
364
365 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
366 {
367   if(!mWebEngine)
368     return false;
369
370   return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
371 }
372
373 bool WebView::LoadContents(const int8_t* contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
374 {
375   if(!mWebEngine)
376     return false;
377
378   return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
379 }
380
381 void WebView::Reload()
382 {
383   if(mWebEngine)
384   {
385     mWebEngine.Reload();
386   }
387 }
388
389 bool WebView::ReloadWithoutCache()
390 {
391   return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
392 }
393
394 void WebView::StopLoading()
395 {
396   if(mWebEngine)
397   {
398     mWebEngine.StopLoading();
399   }
400 }
401
402 void WebView::Suspend()
403 {
404   if(mWebEngine)
405   {
406     mWebEngine.Suspend();
407   }
408 }
409
410 void WebView::Resume()
411 {
412   if(mWebEngine)
413   {
414     mWebEngine.Resume();
415   }
416 }
417
418 void WebView::SuspendNetworkLoading()
419 {
420   if(mWebEngine)
421   {
422     mWebEngine.SuspendNetworkLoading();
423   }
424 }
425
426 void WebView::ResumeNetworkLoading()
427 {
428   if(mWebEngine)
429   {
430     mWebEngine.ResumeNetworkLoading();
431   }
432 }
433
434 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
435 {
436   return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
437 }
438
439 bool WebView::RemoveCustomHeader(const std::string& name)
440 {
441   return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
442 }
443
444 uint32_t WebView::StartInspectorServer(uint32_t port)
445 {
446   return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
447 }
448
449 bool WebView::StopInspectorServer()
450 {
451   return mWebEngine ? mWebEngine.StopInspectorServer() : false;
452 }
453
454 void WebView::ScrollBy(int32_t deltaX, int32_t deltaY)
455 {
456   if(mWebEngine)
457   {
458     mWebEngine.ScrollBy(deltaX, deltaY);
459   }
460 }
461
462 bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY)
463 {
464   return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
465 }
466
467 bool WebView::CanGoForward()
468 {
469   return mWebEngine ? mWebEngine.CanGoForward() : false;
470 }
471
472 void WebView::GoForward()
473 {
474   if(mWebEngine)
475   {
476     mWebEngine.GoForward();
477   }
478 }
479
480 bool WebView::CanGoBack()
481 {
482   return mWebEngine ? mWebEngine.CanGoBack() : false;
483 }
484
485 void WebView::GoBack()
486 {
487   if(mWebEngine)
488   {
489     mWebEngine.GoBack();
490   }
491 }
492
493 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
494 {
495   if(mWebEngine)
496   {
497     mWebEngine.EvaluateJavaScript(script, std::move(resultHandler));
498   }
499 }
500
501 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
502 {
503   if(mWebEngine)
504   {
505     mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, std::move(handler));
506   }
507 }
508
509 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
510 {
511   if(mWebEngine)
512   {
513     mWebEngine.RegisterJavaScriptAlertCallback(std::move(callback));
514   }
515 }
516
517 void WebView::JavaScriptAlertReply()
518 {
519   if(mWebEngine)
520   {
521     mWebEngine.JavaScriptAlertReply();
522   }
523 }
524
525 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
526 {
527   if(mWebEngine)
528   {
529     mWebEngine.RegisterJavaScriptConfirmCallback(std::move(callback));
530   }
531 }
532
533 void WebView::JavaScriptConfirmReply(bool confirmed)
534 {
535   if(mWebEngine)
536   {
537     mWebEngine.JavaScriptConfirmReply(confirmed);
538   }
539 }
540
541 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
542 {
543   if(mWebEngine)
544   {
545     mWebEngine.RegisterJavaScriptPromptCallback(std::move(callback));
546   }
547 }
548
549 void WebView::JavaScriptPromptReply(const std::string& result)
550 {
551   if(mWebEngine)
552   {
553     mWebEngine.JavaScriptPromptReply(result);
554   }
555 }
556
557 std::unique_ptr<Dali::WebEngineHitTest> WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode)
558 {
559   std::unique_ptr<Dali::WebEngineHitTest> webHitTest;
560   if(!mWebEngine)
561   {
562     return webHitTest;
563   }
564
565   return mWebEngine.CreateHitTest(x, y, mode);
566 }
567
568 bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback)
569 {
570   bool result = false;
571   if(mWebEngine)
572   {
573     result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, std::move(callback));
574   }
575   return result;
576 }
577
578 void WebView::ClearHistory()
579 {
580   if(mWebEngine)
581   {
582     mWebEngine.ClearHistory();
583   }
584 }
585
586 void WebView::ClearAllTilesResources()
587 {
588   if(mWebEngine)
589   {
590     mWebEngine.ClearAllTilesResources();
591   }
592 }
593
594 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
595 {
596   if(mWebEngine)
597   {
598     mWebEngine.SetScaleFactor(scaleFactor, point);
599   }
600 }
601
602 float WebView::GetScaleFactor() const
603 {
604   return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
605 }
606
607 void WebView::ActivateAccessibility(bool activated)
608 {
609   if(mWebEngine)
610   {
611     mWebEngine.ActivateAccessibility(activated);
612   }
613 }
614
615 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
616 {
617   return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
618 }
619
620 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
621 {
622   if(mWebEngine)
623   {
624     mWebEngine.AddDynamicCertificatePath(host, certPath);
625   }
626 }
627
628 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor)
629 {
630   Dali::Toolkit::ImageView imageView;
631   if(mWebEngine)
632   {
633     Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
634     imageView                 = CreateImageView(pixelData);
635   }
636   return imageView;
637 }
638
639 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
640 {
641   mScreenshotCapturedCallback = std::move(callback);
642   return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
643 }
644
645 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
646 {
647   return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(std::move(callback)) : false;
648 }
649
650 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
651 {
652   if(mWebEngine)
653   {
654     mWebEngine.RegisterGeolocationPermissionCallback(std::move(callback));
655   }
656 }
657
658 void WebView::SetTtsFocus(bool focused)
659 {
660   if(mWebEngine && !HasKeyInputFocus())
661   {
662     mWebEngine.SetFocus(focused);
663   }
664 }
665
666 void WebView::EnableVideoHole(bool enabled)
667 {
668   mVideoHoleEnabled = enabled;
669
670   EnableBlendMode(!mVideoHoleEnabled);
671
672   if(mWebEngine)
673   {
674     mWebEngine.EnableVideoHole(mVideoHoleEnabled);
675   }
676 }
677
678 void WebView::EnableBlendMode(bool blendEnabled)
679 {
680   Actor self = Self();
681   for(uint32_t i = 0; i < self.GetRendererCount(); i++)
682   {
683     Dali::Renderer render = self.GetRendererAt(i);
684     render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
685   }
686 }
687
688 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
689 {
690   if(!pixel)
691   {
692     return Dali::Toolkit::ImageView();
693   }
694
695   Dali::Toolkit::ImageUrl  url       = Dali::Toolkit::Image::GenerateUrl(pixel);
696   Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url.GetUrl());
697   imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
698   return imageView;
699 }
700
701 void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
702 {
703   if(mWebEngine)
704   {
705     mWebEngine.RegisterPageLoadStartedCallback(std::move(callback));
706   }
707 }
708
709 void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
710 {
711   if(mWebEngine)
712   {
713     mWebEngine.RegisterPageLoadInProgressCallback(std::move(callback));
714   }
715 }
716
717 void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
718 {
719   if(mWebEngine)
720   {
721     mWebEngine.RegisterPageLoadFinishedCallback(std::move(callback));
722   }
723 }
724
725 void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback)
726 {
727   if(mWebEngine)
728   {
729     mWebEngine.RegisterPageLoadErrorCallback(std::move(callback));
730   }
731 }
732
733 void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback)
734 {
735   if(mWebEngine)
736   {
737     mWebEngine.RegisterScrollEdgeReachedCallback(std::move(callback));
738   }
739 }
740
741 void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback)
742 {
743   if(mWebEngine)
744   {
745     mWebEngine.RegisterUrlChangedCallback(std::move(callback));
746   }
747 }
748
749 void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback)
750 {
751   if(mWebEngine)
752   {
753     mWebEngine.RegisterFormRepostDecidedCallback(std::move(callback));
754   }
755 }
756
757 void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback)
758 {
759   mFrameRenderedCallback = std::move(callback);
760 }
761
762 void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
763 {
764   if(mWebEngine)
765   {
766     mWebEngine.RegisterConsoleMessageReceivedCallback(std::move(callback));
767   }
768 }
769
770 void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback)
771 {
772   if(mWebEngine)
773   {
774     mWebEngine.RegisterResponsePolicyDecidedCallback(std::move(callback));
775   }
776 }
777
778 void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback)
779 {
780   if(mWebEngine)
781   {
782     mWebEngine.RegisterNavigationPolicyDecidedCallback(std::move(callback));
783   }
784 }
785
786 void WebView::RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback)
787 {
788   if(mWebEngine)
789   {
790     mWebEngine.RegisterNewWindowCreatedCallback(std::move(callback));
791   }
792 }
793
794 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
795 {
796   if(mWebEngine)
797   {
798     mWebEngine.RegisterCertificateConfirmedCallback(std::move(callback));
799   }
800 }
801
802 void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
803 {
804   if(mWebEngine)
805   {
806     mWebEngine.RegisterSslCertificateChangedCallback(std::move(callback));
807   }
808 }
809
810 void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback)
811 {
812   if(mWebEngine)
813   {
814     mWebEngine.RegisterHttpAuthHandlerCallback(std::move(callback));
815   }
816 }
817
818 void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback)
819 {
820   if(mWebEngine)
821   {
822     mWebEngine.RegisterContextMenuShownCallback(std::move(callback));
823   }
824 }
825
826 void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback)
827 {
828   if(mWebEngine)
829   {
830     mWebEngine.RegisterContextMenuHiddenCallback(std::move(callback));
831   }
832 }
833
834 void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
835 {
836   if(mWebEngine)
837   {
838     mWebEngine.GetPlainTextAsynchronously(std::move(callback));
839   }
840 }
841
842 void WebView::OnFrameRendered()
843 {
844   if(mFrameRenderedCallback)
845   {
846     mFrameRenderedCallback();
847   }
848
849   // Make sure that mVisual is created only if required.
850   if(mVisualChangeRequired || !mVisual)
851   {
852     // Reset flag
853     mVisualChangeRequired = false;
854
855     auto nativeImageSourcePtr = mWebEngine.GetNativeImageSource();
856
857     mLastRenderedNativeImageWidth  = nativeImageSourcePtr->GetWidth();
858     mLastRenderedNativeImageHeight = nativeImageSourcePtr->GetHeight();
859
860     Dali::Toolkit::ImageUrl nativeImageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSourcePtr);
861
862     mVisual = Toolkit::VisualFactory::Get().CreateVisual(
863       {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
864        {Toolkit::ImageVisual::Property::URL, nativeImageUrl.GetUrl()},
865        {Toolkit::ImageVisual::Property::PIXEL_AREA, FULL_TEXTURE_RECT},
866        {Toolkit::ImageVisual::Property::WRAP_MODE_U, Dali::WrapMode::CLAMP_TO_EDGE},
867        {Toolkit::ImageVisual::Property::WRAP_MODE_V, Dali::WrapMode::CLAMP_TO_EDGE}});
868
869     if(mVisual)
870     {
871       DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual, DepthIndex::CONTENT);
872       EnableBlendMode(!mVideoHoleEnabled);
873     }
874   }
875 }
876
877 void WebView::OnDisplayAreaUpdated(Dali::PropertyNotification& /*source*/)
878 {
879   if(!mWebEngine)
880   {
881     return;
882   }
883
884   auto displayArea = CalculateDisplayArea(Self(), DisplayAreaCalculateOption::CURRENT_PROPERTY);
885
886   SetDisplayArea(displayArea);
887 }
888
889 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
890 {
891   if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
892   {
893     if(isVisible)
894     {
895       mWebViewVisibleState |= WebViewVisibleStateFlag::SELF_SHOW;
896     }
897     else
898     {
899       mWebViewVisibleState &= ~WebViewVisibleStateFlag::SELF_SHOW;
900     }
901   }
902   else if(type == Dali::DevelActor::VisibilityChange::Type::PARENT)
903   {
904     if(isVisible)
905     {
906       mWebViewVisibleState |= WebViewVisibleStateFlag::PARENT_SHOW;
907       // TODO : We should consider double-hide called from parent
908     }
909     else
910     {
911       mWebViewVisibleState &= ~WebViewVisibleStateFlag::PARENT_SHOW;
912     }
913   }
914   ApplyVisibilityCheck();
915 }
916
917 void WebView::OnWindowVisibilityChanged(Window window, bool visible)
918 {
919   if(visible)
920   {
921     mWebViewVisibleState |= WebViewVisibleStateFlag::WINDOW_SHOW;
922   }
923   else
924   {
925     mWebViewVisibleState &= ~WebViewVisibleStateFlag::WINDOW_SHOW;
926   }
927   ApplyVisibilityCheck();
928 }
929
930 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
931 {
932   if(mScreenshotCapturedCallback)
933   {
934     Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
935     mScreenshotCapturedCallback(imageView);
936   }
937 }
938
939 void WebView::SetDisplayArea(const Dali::Rect<int32_t>& displayArea)
940 {
941   Size displaySize = Size(displayArea.width, displayArea.height);
942   if(mWebViewSize != displaySize)
943   {
944     mWebViewSize = displaySize;
945   }
946
947   if(mWebViewArea != displayArea)
948   {
949     // WebEngine visual size changed. we have to re-create visual.
950     mVisualChangeRequired = true;
951
952     // Change old visual's pixel area matched as changed web view size
953     if(mVisual)
954     {
955       auto pixelArea = CalculatePixelArea(mWebViewSize, mLastRenderedNativeImageWidth, mLastRenderedNativeImageHeight);
956       Toolkit::GetImplementation(mVisual).DoAction(Toolkit::DevelVisual::Action::UPDATE_PROPERTY, {{Toolkit::ImageVisual::Property::PIXEL_AREA, pixelArea}});
957     }
958
959     mWebViewArea = displayArea;
960     mWebEngine.UpdateDisplayArea(mWebViewArea);
961   }
962 }
963
964 void WebView::OnSceneConnection(int depth)
965 {
966   mWebViewVisibleState |= WebViewVisibleStateFlag::SCENE_ON;
967   mWebViewVisibleState |= WebViewVisibleStateFlag::PARENT_SHOW;
968   // TODO : We should consider already hided parent
969   Window window = DevelWindow::Get(Self());
970   if(window)
971   {
972     // Hold the weak handle of the placement window.
973     mPlacementWindow = window;
974     if(window.IsVisible())
975     {
976       mWebViewVisibleState |= WebViewVisibleStateFlag::WINDOW_SHOW;
977     }
978     else
979     {
980       mWebViewVisibleState &= ~WebViewVisibleStateFlag::WINDOW_SHOW;
981     }
982     DevelWindow::VisibilityChangedSignal(window).Connect(this, &WebView::OnWindowVisibilityChanged);
983   }
984   ApplyVisibilityCheck();
985   Control::OnSceneConnection(depth);
986   EnableBlendMode(!mVideoHoleEnabled);
987 }
988
989 void WebView::OnSceneDisconnection()
990 {
991   mWebViewVisibleState &= ~WebViewVisibleStateFlag::SCENE_ON;
992   mWebViewVisibleState &= ~WebViewVisibleStateFlag::WINDOW_SHOW;
993   mWebViewVisibleState &= ~WebViewVisibleStateFlag::PARENT_SHOW;
994   Window window = mPlacementWindow.GetHandle();
995   if(window)
996   {
997     DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &WebView::OnWindowVisibilityChanged);
998     mPlacementWindow.Reset();
999   }
1000   ApplyVisibilityCheck();
1001   Control::OnSceneDisconnection();
1002 }
1003
1004 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
1005 {
1006   bool result = false;
1007
1008   if(mWebEngine)
1009   {
1010     result = mWebEngine.SendTouchEvent(touch);
1011   }
1012   return result;
1013 }
1014
1015 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
1016 {
1017   bool result = false;
1018
1019   if(mWebEngine)
1020   {
1021     result = mWebEngine.SendKeyEvent(event);
1022   }
1023   return result;
1024 }
1025
1026 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
1027 {
1028   bool result = false;
1029   if(mWebEngine && mMouseEventsEnabled)
1030   {
1031     result = mWebEngine.SendHoverEvent(hover);
1032   }
1033   return result;
1034 }
1035
1036 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
1037 {
1038   bool result = false;
1039   if(mWebEngine && mMouseEventsEnabled)
1040   {
1041     result = mWebEngine.SendWheelEvent(wheel);
1042   }
1043   return result;
1044 }
1045
1046 void WebView::OnKeyInputFocusGained()
1047 {
1048   if(mWebEngine)
1049   {
1050     mWebEngine.SetFocus(true);
1051   }
1052
1053   EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
1054 }
1055
1056 void WebView::OnKeyInputFocusLost()
1057 {
1058   if(mWebEngine)
1059   {
1060     mWebEngine.SetFocus(false);
1061   }
1062
1063   EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
1064 }
1065
1066 Vector3 WebView::GetNaturalSize()
1067 {
1068   if(mVisual)
1069   {
1070     Vector2 rendererNaturalSize;
1071     mVisual.GetNaturalSize(rendererNaturalSize);
1072     return Vector3(rendererNaturalSize);
1073   }
1074
1075   return Vector3(mWebViewSize);
1076 }
1077
1078 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
1079 {
1080   Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1081
1082   if(webView)
1083   {
1084     WebView& impl = GetImpl(webView);
1085     switch(index)
1086     {
1087       case Toolkit::WebView::Property::URL:
1088       {
1089         std::string url;
1090         if(value.Get(url))
1091         {
1092           impl.LoadUrl(url);
1093         }
1094         break;
1095       }
1096       case Toolkit::WebView::Property::USER_AGENT:
1097       {
1098         std::string input;
1099         if(value.Get(input))
1100         {
1101           impl.SetUserAgent(input);
1102         }
1103         break;
1104       }
1105       case Toolkit::WebView::Property::SCROLL_POSITION:
1106       {
1107         Vector2 input;
1108         if(value.Get(input))
1109         {
1110           impl.SetScrollPosition(input.x, input.y);
1111         }
1112         break;
1113       }
1114       case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1115       {
1116         bool input;
1117         if(value.Get(input))
1118         {
1119           impl.EnableVideoHole(input);
1120         }
1121         break;
1122       }
1123       case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1124       {
1125         bool input;
1126         if(value.Get(input))
1127         {
1128           impl.EnableMouseEvents(input);
1129         }
1130         break;
1131       }
1132       case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1133       {
1134         bool input;
1135         if(value.Get(input))
1136         {
1137           impl.EnableKeyEvents(input);
1138         }
1139         break;
1140       }
1141       case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
1142       {
1143         Vector4 input;
1144         if(value.Get(input))
1145         {
1146           impl.SetDocumentBackgroundColor(input);
1147         }
1148         break;
1149       }
1150       case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
1151       {
1152         bool input;
1153         if(value.Get(input))
1154         {
1155           impl.ClearTilesWhenHidden(input);
1156         }
1157         break;
1158       }
1159       case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
1160       {
1161         float input;
1162         if(value.Get(input))
1163         {
1164           impl.SetTileCoverAreaMultiplier(input);
1165         }
1166         break;
1167       }
1168       case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
1169       {
1170         bool input;
1171         if(value.Get(input))
1172         {
1173           impl.EnableCursorByClient(input);
1174         }
1175         break;
1176       }
1177       case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1178       {
1179         float input;
1180         if(value.Get(input))
1181         {
1182           impl.SetPageZoomFactor(input);
1183         }
1184         break;
1185       }
1186       case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1187       {
1188         float input;
1189         if(value.Get(input))
1190         {
1191           impl.SetTextZoomFactor(input);
1192         }
1193         break;
1194       }
1195       default:
1196         break;
1197     }
1198   }
1199 }
1200
1201 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1202 {
1203   Property::Value value;
1204
1205   Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1206
1207   if(webView)
1208   {
1209     WebView& impl = GetImpl(webView);
1210     switch(propertyIndex)
1211     {
1212       case Toolkit::WebView::Property::URL:
1213       {
1214         value = impl.GetUrl();
1215         break;
1216       }
1217       case Toolkit::WebView::Property::USER_AGENT:
1218       {
1219         value = impl.GetUserAgent();
1220         break;
1221       }
1222       case Toolkit::WebView::Property::SCROLL_POSITION:
1223       {
1224         value = impl.GetScrollPosition();
1225         break;
1226       }
1227       case Toolkit::WebView::Property::SCROLL_SIZE:
1228       {
1229         value = impl.GetScrollSize();
1230         break;
1231       }
1232       case Toolkit::WebView::Property::CONTENT_SIZE:
1233       {
1234         value = impl.GetContentSize();
1235         break;
1236       }
1237       case Toolkit::WebView::Property::TITLE:
1238       {
1239         value = impl.GetTitle();
1240         break;
1241       }
1242       case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1243       {
1244         value = impl.mVideoHoleEnabled;
1245         break;
1246       }
1247       case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1248       {
1249         value = impl.mMouseEventsEnabled;
1250         break;
1251       }
1252       case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1253       {
1254         value = impl.mKeyEventsEnabled;
1255         break;
1256       }
1257       case Toolkit::WebView::Property::SELECTED_TEXT:
1258       {
1259         value = impl.GetSelectedText();
1260         break;
1261       }
1262       case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1263       {
1264         value = impl.GetPageZoomFactor();
1265         break;
1266       }
1267       case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1268       {
1269         value = impl.GetTextZoomFactor();
1270         break;
1271       }
1272       case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1273       {
1274         value = impl.GetLoadProgressPercentage();
1275         break;
1276       }
1277       default:
1278         break;
1279     }
1280   }
1281
1282   return value;
1283 }
1284
1285 void WebView::SetScrollPosition(int32_t x, int32_t y)
1286 {
1287   if(mWebEngine)
1288   {
1289     mWebEngine.SetScrollPosition(x, y);
1290   }
1291 }
1292
1293 Dali::Vector2 WebView::GetScrollPosition() const
1294 {
1295   return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1296 }
1297
1298 Dali::Vector2 WebView::GetScrollSize() const
1299 {
1300   return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1301 }
1302
1303 Dali::Vector2 WebView::GetContentSize() const
1304 {
1305   return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1306 }
1307
1308 std::string WebView::GetTitle() const
1309 {
1310   return mWebEngine ? mWebEngine.GetTitle() : std::string();
1311 }
1312
1313 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1314 {
1315   if(mWebEngine)
1316   {
1317     mWebEngine.SetDocumentBackgroundColor(color);
1318   }
1319 }
1320
1321 void WebView::ClearTilesWhenHidden(bool cleared)
1322 {
1323   if(mWebEngine)
1324   {
1325     mWebEngine.ClearTilesWhenHidden(cleared);
1326   }
1327 }
1328
1329 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1330 {
1331   if(mWebEngine)
1332   {
1333     mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1334   }
1335 }
1336
1337 void WebView::EnableCursorByClient(bool enabled)
1338 {
1339   if(mWebEngine)
1340   {
1341     mWebEngine.EnableCursorByClient(enabled);
1342   }
1343 }
1344
1345 std::string WebView::GetSelectedText() const
1346 {
1347   return mWebEngine ? mWebEngine.GetSelectedText() : std::string();
1348 }
1349
1350 std::string WebView::GetUrl() const
1351 {
1352   return mWebEngine ? mWebEngine.GetUrl() : std::string();
1353 }
1354
1355 std::string WebView::GetUserAgent() const
1356 {
1357   return mWebEngine ? mWebEngine.GetUserAgent() : std::string();
1358 }
1359
1360 void WebView::SetUserAgent(const std::string& userAgent)
1361 {
1362   if(mWebEngine)
1363   {
1364     mWebEngine.SetUserAgent(userAgent);
1365   }
1366 }
1367
1368 void WebView::EnableMouseEvents(bool enabled)
1369 {
1370   if(mWebEngine)
1371   {
1372     mMouseEventsEnabled = enabled;
1373     mWebEngine.EnableMouseEvents(enabled);
1374   }
1375 }
1376
1377 void WebView::EnableKeyEvents(bool enabled)
1378 {
1379   if(mWebEngine)
1380   {
1381     mKeyEventsEnabled = enabled;
1382     mWebEngine.EnableKeyEvents(enabled);
1383   }
1384 }
1385
1386 void WebView::SetPageZoomFactor(float zoomFactor)
1387 {
1388   if(mWebEngine)
1389   {
1390     mWebEngine.SetPageZoomFactor(zoomFactor);
1391   }
1392 }
1393
1394 float WebView::GetPageZoomFactor() const
1395 {
1396   return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1397 }
1398
1399 void WebView::SetTextZoomFactor(float zoomFactor)
1400 {
1401   if(mWebEngine)
1402   {
1403     mWebEngine.SetTextZoomFactor(zoomFactor);
1404   }
1405 }
1406
1407 float WebView::GetTextZoomFactor() const
1408 {
1409   return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1410 }
1411
1412 float WebView::GetLoadProgressPercentage() const
1413 {
1414   return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1415 }
1416
1417 bool WebView::SetVisibility(bool visible)
1418 {
1419   return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1420 }
1421
1422 void WebView::ApplyVisibilityCheck()
1423 {
1424   SetVisibility(mWebViewVisibleState == WebViewVisibleStateFlag::VISIBLE);
1425 }
1426
1427 WebView::WebViewAccessible::WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine)
1428 : ControlAccessible(self),
1429   mRemoteChild{},
1430   mWebEngine{webEngine}
1431 {
1432   mRemoteChild.SetParent(this);
1433
1434   Dali::Accessibility::Bridge::EnabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityEnabled);
1435   Dali::Accessibility::Bridge::DisabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityDisabled);
1436
1437   if(Dali::Accessibility::IsUp())
1438   {
1439     OnAccessibilityEnabled();
1440   }
1441   else
1442   {
1443     OnAccessibilityDisabled();
1444   }
1445 }
1446
1447 Dali::Accessibility::Attributes WebView::WebViewAccessible::GetAttributes() const
1448 {
1449   auto attributes = DevelControl::ControlAccessible::GetAttributes();
1450
1451   if(mRemoteChild.GetAddress())
1452   {
1453     attributes.insert_or_assign("child_bus", mRemoteChild.GetAddress().GetBus());
1454   }
1455
1456   return attributes;
1457 }
1458
1459 void WebView::WebViewAccessible::DoGetChildren(std::vector<Dali::Accessibility::Accessible*>& children)
1460 {
1461   if(mRemoteChild.GetAddress())
1462   {
1463     // DoGetChildren is called at most once per every OnChildrenChanged.
1464     // We have only one OnChildrenChanged in this case, so EmbedAtkSocket will be called only once.
1465     Accessibility::Bridge::GetCurrentBridge()->EmbedAtkSocket(GetAddress(), mRemoteChild.GetAddress());
1466     children.push_back(&mRemoteChild);
1467   }
1468 }
1469
1470 void WebView::WebViewAccessible::OnAccessibilityEnabled()
1471 {
1472   if(!mWebEngine)
1473   {
1474     return;
1475   }
1476
1477   mWebEngine.ActivateAccessibility(true);
1478   SetRemoteChildAddress(mWebEngine.GetAccessibilityAddress());
1479 }
1480
1481 void WebView::WebViewAccessible::OnAccessibilityDisabled()
1482 {
1483   if(!mWebEngine)
1484   {
1485     return;
1486   }
1487
1488   SetRemoteChildAddress({});
1489   mWebEngine.ActivateAccessibility(false);
1490 }
1491
1492 void WebView::WebViewAccessible::SetRemoteChildAddress(Dali::Accessibility::Address address)
1493 {
1494   mRemoteChild.SetAddress(address);
1495   OnChildrenChanged();
1496 }
1497
1498 } // namespace Internal
1499
1500 } // namespace Toolkit
1501
1502 } // namespace Dali