Fix ewk_view_orientation_send API
authorLukasz Krok <l.krok@samsung.com>
Thu, 18 Dec 2014 15:24:23 +0000 (16:24 +0100)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
The ewk_view_orientation_send API did not triggered orientationchanged event.
This patch fixes that.
Additionally, coresponding unit tests were refactored.

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=9541
Reviewed by: Min-Soo Koo, Piotr Tworek

Change-Id: I94ee975eb6cde25391a37dbfe370212e6b49cc17
Signed-off-by: Lukasz Krok <l.krok@samsung.com>
tizen_src/ewk/unittest/resources/ewk_view/orientation_test.html
tizen_src/ewk/unittest/utc_blink_ewk_view_orientation_send_func.cpp
tizen_src/impl/browser/renderer_host/render_widget_host_view_efl.cc
tizen_src/impl/browser/web_contents/web_contents_view_efl.cc
tizen_src/impl/common/render_messages_efl.h
tizen_src/impl/eweb_view.cc
tizen_src/impl/eweb_view.h
tizen_src/impl/renderer/render_view_observer_efl.cc
tizen_src/impl/renderer/render_view_observer_efl.h

index f609318..8e07700 100755 (executable)
@@ -4,12 +4,12 @@
         <script type="text/javascript">
             function onLoad() { 
               window.addEventListener("orientationchange", updateOrientation);
+              document.title=window.orientation;
             } 
 
             function updateOrientation()
             {
               console.log(window.orientation);
-              alert(window.orientation);
             }
         </script>
     </head>
index e9d81b5..175db89 100755 (executable)
@@ -4,6 +4,8 @@
 
 #include "utc_blink_ewk_base.h"
 
+#define URL  ("ewk_view/orientation_test.html")
+
 class utc_blink_ewk_view_orientation_send : public utc_blink_ewk_base
 {
 protected:
@@ -15,46 +17,28 @@ protected:
 
   void LoadFinished(Evas_Object* webview)
   {
+    g_orientation = atol(ewk_view_title_get(GetEwkWebView()));
     EventLoopStop(utc_blink_ewk_base::Success);
   }
 
-  static Eina_Bool alert_callback(Evas_Object* webview ,const char* alert_text, void* user_data)
-  {
-    if (user_data) {
-      utc_blink_ewk_view_orientation_send* owner = NULL;
-      OwnerFromVoid(user_data, &owner);
-
-      long int orientation = strtol(alert_text, NULL, 10);
-      // TODO: check errno
-
-      fprintf(stderr,"[alert_callback] :: %ld\n", orientation);
-      switch (orientation) {
-      case -90:
-      case 0:
-      case 90:
-      case 180:
-        owner->g_orientation = orientation;
-        break;
-      }
-
-      owner->EventLoopStop(Success);
-      utc_message("[alert_callback] :: going out");
-    }
 
-    // behave like dialog was closed
-    return EINA_FALSE;
-  }
-
-  /* Startup function */
-  void PostSetUp()
+  void ConsoleMessage(Evas_Object* webview, const Ewk_Console_Message* msg)
   {
-    ewk_view_javascript_alert_callback_set(GetEwkWebView(), alert_callback, this);
+    utc_blink_ewk_base::ConsoleMessage(webview, msg);
+
+    const char* message_text = ewk_console_message_text_get(msg);
+    long int orientation = atol(message_text);
+
+    switch (orientation) {
+    case -90:
+    case 0:
+    case 90:
+    case 180:
+      g_orientation = orientation;
+      break;
+    }
 
-    // All TCs require same page to load
-    std::string full_path = GetResourceUrl("ewk_view/orientation_test.html");
-    ASSERT_FALSE(full_path.empty());
-    ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
-    ASSERT_EQ(Success, EventLoopStart());
+    EventLoopStop(utc_blink_ewk_base::Success);
   }
 
 protected:
@@ -66,6 +50,11 @@ protected:
  */
 TEST_F(utc_blink_ewk_view_orientation_send, TEST_90DG)
 {
+  std::string full_path = GetResourceUrl(URL);
+  ASSERT_FALSE(full_path.empty());
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+
   utc_message("[utc_blink_ewk_view_orientation_send TEST_90DG] :: ewk_view_orientation_send");
   ewk_view_orientation_send(GetEwkWebView(), 90);
 
@@ -78,6 +67,11 @@ TEST_F(utc_blink_ewk_view_orientation_send, TEST_90DG)
  */
 TEST_F(utc_blink_ewk_view_orientation_send, TEST_180DG)
 {
+  std::string full_path = GetResourceUrl(URL);
+  ASSERT_FALSE(full_path.empty());
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+
   utc_message("[utc_blink_ewk_view_orientation_send TEST_180DG] :: ewk_view_orientation_send");
   ewk_view_orientation_send(GetEwkWebView(), 180);
 
@@ -90,6 +84,11 @@ TEST_F(utc_blink_ewk_view_orientation_send, TEST_180DG)
  */
 TEST_F(utc_blink_ewk_view_orientation_send, TEST_0DG)
 {
+  std::string full_path = GetResourceUrl(URL);
+  ASSERT_FALSE(full_path.empty());
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+
   utc_message("[utc_blink_ewk_view_orientation_send TEST_0DG] :: ewk_view_orientation_send");
   ewk_view_orientation_send(GetEwkWebView(), 0);
 
@@ -102,6 +101,11 @@ TEST_F(utc_blink_ewk_view_orientation_send, TEST_0DG)
  */
 TEST_F(utc_blink_ewk_view_orientation_send, TEST_MINUS90DG)
 {
+  std::string full_path = GetResourceUrl(URL);
+  ASSERT_FALSE(full_path.empty());
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+
   utc_message("[utc_blink_ewk_view_orientation_send TEST_MINUS90DG] :: ewk_view_orientation_send");
   ewk_view_orientation_send(GetEwkWebView(), -90);
 
@@ -114,9 +118,31 @@ TEST_F(utc_blink_ewk_view_orientation_send, TEST_MINUS90DG)
  */
 TEST_F(utc_blink_ewk_view_orientation_send, INVALID_ARGS)
 {
+  std::string full_path = GetResourceUrl(URL);
+  ASSERT_FALSE(full_path.empty());
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
+  ASSERT_EQ(Success, EventLoopStart());
+
   ewk_view_orientation_send(NULL, EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY);
-  EXPECT_EQ(Failure, EventLoopStart(5.0));
+  EXPECT_EQ(Timeout, EventLoopStart(2.0));
 
   ewk_view_orientation_send(GetEwkWebView(), 22);
-  EXPECT_EQ(Failure, EventLoopStart(5.0));
+  EXPECT_EQ(Timeout, EventLoopStart(2.0));
 }
+
+/**
+ * @brief Checking whether function works properly in case of no render widget
+ *        host view object, that is if information about the orientation set
+ *        is not lost when function is called before setting the url.
+ */
+TEST_F(utc_blink_ewk_view_orientation_send, BEFOREURLSET)
+{
+  std::string full_path = GetResourceUrl(URL);
+  ASSERT_FALSE(full_path.empty());
+
+  ewk_view_orientation_send(GetEwkWebView(), 90);
+
+  ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), full_path.c_str()));
+  EXPECT_EQ(Success, EventLoopStart());
+  ASSERT_EQ(g_orientation, 90);
+}
\ No newline at end of file
index b27c5d6..b8b46fb 100644 (file)
@@ -31,6 +31,7 @@
 #include "content/common/gpu/client/gl_helper.h"
 #include "content/common/input/did_overscroll_params.h"
 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
+#include "content/public/browser/screen_orientation_dispatcher_host.h"
 #include "content/public/common/content_switches.h"
 #include "content/common/view_messages.h"
 #include "content/common/gpu/gpu_messages.h"
@@ -78,7 +79,15 @@ void RenderWidgetHostViewBase::GetDefaultScreenInfo(
   results->rect = display.bounds();
   results->availableRect = display.work_area();
   results->deviceScaleFactor = display.device_scale_factor();
-  results->orientationAngle = display.rotation();
+  results->orientationAngle = display.RotationAsDegree();
+#if defined(OS_TIZEN_MOBILE)
+  results->orientationType =
+      RenderWidgetHostViewBase::GetOrientationTypeForMobile(display);
+#else
+  results->orientationType =
+      RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display);
+#endif
+
   // TODO(derat|oshima): Don't hardcode this. Get this from display object.
   results->depth = 24;
   results->depthPerComponent = 8;
@@ -422,7 +431,6 @@ bool RenderWidgetHostViewEfl::OnMessageReceived(const IPC::Message& message) {
     IPC_MESSAGE_HANDLER(EwkHostMsg_WebAppIconUrlsGet, OnWebAppIconUrlsGet)
     IPC_MESSAGE_HANDLER(EwkHostMsg_WebAppCapableGet, OnWebAppCapableGet)
     IPC_MESSAGE_HANDLER(EwkHostMsg_DidChangeContentsSize, OnDidChangeContentsSize)
-    IPC_MESSAGE_HANDLER(EwkHostMsg_OrientationChangeEvent, OnOrientationChangeEvent)
     IPC_MESSAGE_HANDLER(EwkViewMsg_SelectionTextStyleState, OnSelectionTextStyleState)
     IPC_MESSAGE_HANDLER(EwkHostMsg_DidChangeMaxScrollOffset, OnDidChangeMaxScrollOffset)
     IPC_MESSAGE_HANDLER(EwkHostMsg_DidChangeScrollOffset, OnDidChangeScrollOffset)
index bfe6247..e904e37 100644 (file)
@@ -53,10 +53,12 @@ RenderWidgetHostViewBase* WebContentsViewEfl::CreateViewForWidget(
   view->Init(native_view_);
   view->Show();
 
- if (view_mode_ != tizen_webview::TW_VIEW_MODE_WINDOWED) {
 if (view_mode_ != tizen_webview::TW_VIEW_MODE_WINDOWED) {
     view->SetViewMode(view_mode_);
- }
+  }
+
+  GetEWebView()->SetOrientation(EWebView::GetOrientation());
+
   return view;
 }
 
index d54e959..19e847a 100644 (file)
@@ -287,9 +287,6 @@ IPC_MESSAGE_ROUTED2(EwkHostMsg_DidChangePageScaleRange,
 IPC_MESSAGE_ROUTED1(EwkViewMsg_SetDrawsTransparentBackground,
                     bool /* enabled */)
 
-IPC_MESSAGE_ROUTED1(EwkHostMsg_OrientationChangeEvent,
-                    int /* orientation */)
-
 // Notifies the browser to form submit
 IPC_MESSAGE_ROUTED1(EwkHostMsg_FormSubmit, GURL)
 
index 179c14d..ae0ea64 100644 (file)
@@ -34,6 +34,7 @@
 #include "content/public/browser/navigation_controller.h"
 #include "content/public/browser/navigation_entry.h"
 #include "content/public/browser/resource_dispatcher_host.h"
+#include "content/public/browser/screen_orientation_dispatcher_host.h"
 #include "content/public/common/content_client.h"
 #include "content/public/common/user_agent.h"
 #include "content/public/browser/browser_thread.h"
@@ -543,6 +544,30 @@ void EWebView::SetOrientation(int orientation) {
   if (orientation == -90)
     orientation = 270;
   screen_orientation_ = orientation;
+
+  RenderWidgetHostViewEfl* view = rwhv();
+  if (view && (
+      screen_orientation_ == 0   ||
+      screen_orientation_ == 90  ||
+      screen_orientation_ == 180 ||
+      screen_orientation_ == 270
+      )
+     ) {
+    RenderWidgetHost* rwh = view->GetRenderWidgetHost();
+
+    blink::WebScreenInfo screen_info;
+    rwh->GetWebScreenInfo(&screen_info);
+    screen_info.orientationAngle = screen_orientation_;
+
+    ViewMsg_Resize_Params params;
+    params.screen_info = screen_info;
+
+    rwh->Send(new ViewMsg_Resize(rwh->GetRoutingID(), params));
+    view->UpdateScreenInfo(view->GetNativeView());
+
+    WebContentsImpl& contents_impl = static_cast<WebContentsImpl&>(web_contents());
+    contents_impl.screen_orientation_dispatcher_host()->OnOrientationChange();
+  }
 }
 
 int EWebView::GetOrientation() {
index 0598a29..d653733 100644 (file)
@@ -207,7 +207,6 @@ class WebViewGeolocationPermissionCallback;
 class EWebView {
  public:
   static EWebView* FromEvasObject(Evas_Object* eo);
-  static void SetOrientation(int orientation);
   static int GetOrientation();
 
   // initialize data members and activate event handlers.
@@ -253,6 +252,7 @@ class EWebView {
   double GetTextZoomFactor() const;
   void SetTextZoomFactor(double text_zoom_factor);
   void ExecuteEditCommand(const char* command, const char* value);
+  void SetOrientation(int orientation);
   void SendOrientationChangeEventIfNeeded(int orientation);
   void SetOrientationLockCallback(tizen_webview::Orientation_Lock_Cb func, void* data);
   bool TouchEventsEnabled() const;
index 016f0be..be87fdd 100644 (file)
@@ -572,16 +572,6 @@ void RenderViewObserverEfl::OnWebAppCapableGet(int callback_id) {
   Send(new EwkHostMsg_WebAppCapableGet(render_view()->GetRoutingID(), capable, callback_id));
 }
 
-void RenderViewObserverEfl::OrientationChangeEvent()
-{
-#if !defined(EWK_BRINGUP)
-  // Previosly OrientationChangeEvent() had orientation parameter.
-  // Now it was removed. Thanks Mounir.
-  // Need to figure out how to get orientation.
-  Send(new EwkHostMsg_OrientationChangeEvent(render_view()->GetRoutingID(), orientation));
-#endif
-}
-
 void RenderViewObserverEfl::WillSubmitForm(blink::WebLocalFrame* frame, const blink::WebFormElement& form)
 {
   GURL url(form.action());
index 6953743..a4d0b74 100644 (file)
@@ -48,7 +48,6 @@ class RenderViewObserverEfl: public content::RenderViewObserver {
   void DidChangeScrollOffset(blink::WebLocalFrame* frame) override;
   bool OnMessageReceived(const IPC::Message& message) override;
   virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) override;
-  virtual void OrientationChangeEvent() override;
 #if !defined(EWK_BRINGUP)
   virtual void DidChangePageScaleFactor() override;
 #endif