[Engine] Support custom js event regarding state change of softkeyboard(ime)
[platform/framework/web/wrt.git] / src / view / webkit / bundles / plugin_module_support.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file    plugin_module_support.cpp
18  * @author  Lukasz Wrzosek (l.wrzosek@samsung.com)
19  * @author  Yunchan Cho (yunchan.cho@samsung.com)
20  * @brief   Plugin module support for Webkit2 - implementation.
21  */
22 #include "plugin_module_support.h"
23 #include "messages_names.h"
24
25 #include <sstream>
26 #include <EWebKit2.h>
27 #include <dpl/wrt-dao-ro/wrt_db_types.h> // definition of WidgetHandle
28 #include <js_overlay_types.h>
29
30 namespace PluginModuleSupport {
31
32 void start(Ewk_Context* ewkContext,
33            WidgetHandle id,
34            double scale,
35            const char *encodedBundle,
36            const char *theme,
37            bool encrypted)
38 {
39     std::stringstream ssMsg;
40
41     ssMsg << id << " ";
42
43     ssMsg << "_" << scale << " ";
44
45     if(encodedBundle)
46     {
47         ssMsg << "_" << encodedBundle << " ";
48     }
49     else
50     {
51         ssMsg << "null" << " ";
52     }
53
54     if(theme)
55     {
56         ssMsg << "_" << theme << " ";
57     }
58     else
59     {
60         ssMsg << "null" << " ";
61     }
62
63     ssMsg << encrypted;
64
65     std::string msgString = ssMsg.str();
66
67     const char* msg = msgString.c_str();
68     const char* name = BundleMessages::START;
69
70     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
71 }
72
73 void shutdown(Ewk_Context* ewkContext)
74 {
75     const char* name = BundleMessages::SHUTDOWN;
76     ewk_context_message_post_to_injected_bundle(ewkContext, name, name);
77 }
78
79 void setCustomProperties(
80         Ewk_Context* ewkContext,
81         double* scale,
82         const char* encodedBundle,
83         const char* theme )
84 {
85     std::stringstream ssMsg;
86
87     if(scale)
88     {
89         ssMsg << "_" << *scale << " ";
90     }
91     else
92     {
93         ssMsg << "null" << " ";
94     }
95
96     if(encodedBundle)
97     {
98         ssMsg << "_" << encodedBundle << " ";
99     }
100     else
101     {
102         ssMsg << "null" << " ";
103     }
104
105     if(theme)
106     {
107         ssMsg << "_" << theme;
108     }
109     else
110     {
111         ssMsg << "null";
112     }
113
114     std::string msgString = ssMsg.str();
115
116     const char* msg = msgString.c_str();
117     const char* name = BundleMessages::SET_CUSTOM_PROPERTIES;
118
119     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
120 }
121
122 void dispatchJavaScriptEvent(
123         Ewk_Context* ewkContext,
124         WrtPlugins::W3C::CustomEventType eventType,
125         void *data)
126 {
127     using namespace WrtPlugins::W3C;
128     std::stringstream str;
129     str << eventType;
130
131     // if needed, arguments for event should be set here
132     if (eventType == SoftKeyboardChangeCustomEvent) {
133         if (data) {
134             SoftKeyboardChangeArgs* args =
135                 static_cast<SoftKeyboardChangeArgs *>(data);
136             str << " " << args->state;
137             str << " " << args->width;
138             str << " " << args->height;
139         }
140     }
141
142     std::string msgString = str.str();
143     const char* msg = msgString.c_str();
144     const char* name = BundleMessages::DISPATCH_JAVASCRIPT_EVENT;
145
146     ewk_context_message_post_to_injected_bundle(ewkContext, name, msg);
147 }
148
149 }//namespace PluginModuleSupport