fixup! [M120 Migration] Enable snapshot feature for EFL port 45/306445/3
authorManjeet <manjeet.1@partner.samsung.com>
Wed, 21 Feb 2024 10:40:05 +0000 (16:10 +0530)
committerBot Blink <blinkbot@samsung.com>
Fri, 23 Feb 2024 00:00:46 +0000 (00:00 +0000)
This commit adds sample code to test sync screenshot API in ubrowser.

Reference:
https://review.tizen.org/gerrit/298956

Change-Id: I9781243ac601361437d6330035f93a2d53aa9776
Signed-off-by: Manjeet <manjeet.1@partner.samsung.com>
tizen_src/ewk/ubrowser/window.cc
tizen_src/ewk/ubrowser/window.h
tizen_src/ewk/ubrowser/window_ui.cc
tizen_src/ewk/ubrowser/window_ui.h

index 416fc30..721139d 100644 (file)
@@ -434,13 +434,24 @@ void Window::SetAutoRotate() {
                                               (sizeof(rots) / sizeof(int)));
 }
 
-void Window::TakeScreenshotAsync() {
+void Window::TakeScreenshot(bool sync) {
   log_trace("%s", __PRETTY_FUNCTION__);
   Eina_Rectangle rect;
   EINA_RECTANGLE_SET(&rect, 0, 0, 400, 400);
-  ewk_view_screenshot_contents_get_async(web_view_, rect, 1.0,
-                                         evas_object_evas_get(web_view_),
-                                         &Window::OnScreenshotCaptured, NULL);
+  if (!sync) {
+    ewk_view_screenshot_contents_get_async(web_view_, rect, 1.0,
+                                           evas_object_evas_get(web_view_),
+                                           &Window::OnScreenshotCaptured, NULL);
+    return;
+  }
+
+  Evas_Object* snapshot = ewk_view_screenshot_contents_get(
+      web_view_, rect, 1.0, evas_object_evas_get(web_view_));
+  if (!snapshot) {
+    fprintf(stderr, "Failed to get snapshot sync\n");
+    return;
+  }
+  OnScreenshotCaptured(snapshot, NULL);
 }
 
 #if BUILDFLAG(IS_TIZEN_TV)
index 2eaad6a..d144a5e 100644 (file)
@@ -52,7 +52,7 @@ class Window {
   void ShowInspectorURL(const char* url);
   void SetGoogleDataProxyHeaders() const;
   void SetAutoRotate();
-  void TakeScreenshotAsync();
+  void TakeScreenshot(bool sync);
   void Exit() const;
 
   IdType Id() const;
index 7946def..ff28560 100644 (file)
@@ -316,6 +316,9 @@ Evas_Object* WindowUI::CreateExtraActionsMenu(Evas_Object* parent) {
   elm_ctxpopup_item_append(menu_, "Take screenshot async", NULL,
                            &WindowUI::OnTakeScreenshotAsync, this);
 
+  elm_ctxpopup_item_append(menu_, "Take screenshot sync", NULL,
+                           &WindowUI::OnTakeScreenshotSync, this);
+
   elm_ctxpopup_item_append(menu_, "Quit", NULL, &WindowUI::Exit, this);
 
   return menu_;
@@ -676,7 +679,14 @@ void WindowUI::OnShowZoomPopup(void* data, Evas_Object* obj, void*) {
 void WindowUI::OnTakeScreenshotAsync(void* data, Evas_Object* obj, void*) {
   log_trace("%s", __PRETTY_FUNCTION__);
   WindowUI* thiz = static_cast<WindowUI*>(data);
-  thiz->window_.TakeScreenshotAsync();
+  thiz->window_.TakeScreenshot(false);
+  thiz->CloseMenu();
+}
+
+void WindowUI::OnTakeScreenshotSync(void* data, Evas_Object* obj, void*) {
+  log_trace("%s", __PRETTY_FUNCTION__);
+  WindowUI* thiz = static_cast<WindowUI*>(data);
+  thiz->window_.TakeScreenshot(true);
   thiz->CloseMenu();
 }
 
index b7a4ebf..81bed26 100644 (file)
@@ -90,6 +90,7 @@ class WindowUI {
   static void ClosePopup(void* data, Evas_Object*, void*);
   static void OnShowZoomPopup(void* data, Evas_Object*, void*);
   static void OnTakeScreenshotAsync(void* data, Evas_Object*, void*);
+  static void OnTakeScreenshotSync(void* data, Evas_Object*, void*);
   static void OnZoomChanged(void* data, Evas_Object*, void*);
   static void OnRememberFormDataChange(void* data, Evas_Object*, void*);
   static void OnRememberPasswordChange(void* data, Evas_Object*, void*);