Revert "Fix WRT Runtimes: Add CloseWindows CallBack"
[platform/framework/web/wrt.git] / src / wrt-client / auto_rotation_support.cpp
1 /*
2   * Copyright 2013  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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  * @file    auto_rotation_support.cpp
18  * @author  Jihoon Chung (jihoon.chung@samsung.com)
19  * @version 1.0
20  * @brief   source file to support auto rotation of web application
21  */
22
23 #include "auto_rotation_support.h"
24
25 #include <Elementary.h>
26 #include <EWebKit2.h>
27 #include <dpl/log/log.h>
28 #include <widget_data_types.h>
29
30 namespace {
31 const char* const WM_ROTATION_CHANGED_CALLBACK =  "wm,rotation,changed";
32 }
33
34 void AutoRotationSupport::setOrientation(Evas_Object* window, Evas_Object* ewkView, SplashScreenSupport* splashScreen)
35 {
36     LogDebug("setOrientation");
37     int winAngle = elm_win_rotation_get(window);
38
39     if (splashScreen && splashScreen->isShowing())
40     {
41         splashScreen->resizeSplashScreen();
42     }
43
44     if (winAngle == OrientationAngle::Window::Portrait::PRIMARY) {
45         ewk_view_orientation_send(
46             ewkView,
47             OrientationAngle::W3C::Portrait::PRIMARY);
48     } else if (winAngle == OrientationAngle::Window::Portrait::SECONDARY) {
49         ewk_view_orientation_send(
50             ewkView,
51             OrientationAngle::W3C::Portrait::SECONDARY);
52     } else if (winAngle == OrientationAngle::Window::Landscape::PRIMARY) {
53         ewk_view_orientation_send(
54             ewkView,
55             OrientationAngle::W3C::Landscape::PRIMARY);
56     } else if (winAngle == OrientationAngle::Window::Landscape::SECONDARY) {
57         ewk_view_orientation_send(
58             ewkView,
59             OrientationAngle::W3C::Landscape::SECONDARY);
60     } else {
61         LogDebug("unknown angle is returned");
62     }
63 }
64
65 bool AutoRotationSupport::setAutoRotation(Evas_Object* window, Evas_Smart_Cb callback, const void *data)
66 {
67     Assert(window);
68
69     if (elm_win_wm_rotation_supported_get(window)) {
70         const int rots[4] = {OrientationAngle::Window::Portrait::PRIMARY,
71                              OrientationAngle::Window::Portrait::SECONDARY,
72                              OrientationAngle::Window::Landscape::PRIMARY,
73                              OrientationAngle::Window::Landscape::SECONDARY};
74         elm_win_wm_rotation_available_rotations_set(window, rots, 4);
75         evas_object_smart_callback_add(window,
76                                        WM_ROTATION_CHANGED_CALLBACK,
77                                        callback,
78                                        data);
79         return true;
80     }
81     return false;
82 }
83
84 void AutoRotationSupport::unsetAutoRotation(Evas_Object* window, Evas_Smart_Cb callback)
85 {
86     Assert(window);
87     evas_object_smart_callback_del(window,
88                                    WM_ROTATION_CHANGED_CALLBACK,
89                                    callback);
90 }
91