From 9f3e7bb1050c6f98caa9a79f86fdd9661a887e06 Mon Sep 17 00:00:00 2001 From: Yunchan Cho Date: Wed, 31 Oct 2012 17:17:59 +0900 Subject: [PATCH] Add specific interface for support of custom js event [Issue#] Requirement for custom js event should be applied to WRT [Bug] N/A [Cause] N/A [Solution] New interface is created for registering custom js event internally and firing the js event to web contents on specific timing. Especially this interface is needed from custom js event regarding ime show/hide including existing appservice event. [Verification] register "imeshow" js event on your javascipt source using addEventListener() and then use input tag of 'text' type to show ime or hide it Change-Id: Ia14867d13b3569b598d69e558db7828876439ef0 --- src/js-overlay/CMakeLists.txt | 2 +- .../JSClass/JSSoftKeyboardChangeEvent.cpp | 202 +++++++++++++++++++++ src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.h | 99 ++++++++++ src/js-overlay/js_overlay_addEventListener.cpp | 53 +++--- src/js-overlay/js_overlay_addEventListener.h | 5 +- src/js-overlay/js_overlay_types.h | 18 ++ src/modules/API/CMakeLists.txt | 5 +- .../ISoftKeyboardChangeEvent.h | 49 +++++ .../SoftKeyboardChangeEvent.cpp | 57 ++++++ .../SoftKeyboardChangeEvent.h | 57 ++++++ .../API/SoftKeyboardChangeEvent/config.cmake | 11 ++ src/modules/CMakeLists.txt | 3 - src/modules/packages/CMakeLists.txt | 6 +- .../SoftKeyboardChangeEvent/CMakeLists.txt | 26 +++ src/plugin-loading/CMakeLists.txt | 7 +- src/plugin-loading/explorer.cpp | 70 +++++-- src/plugin-loading/explorer.h | 2 +- src/plugin-loading/js_page_session.cpp | 10 +- src/plugin-loading/js_page_session.h | 2 +- src/plugin-loading/plugin_logic.cpp | 13 +- src/plugin-loading/plugin_logic.h | 3 +- 21 files changed, 633 insertions(+), 67 deletions(-) create mode 100644 src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.cpp create mode 100644 src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.h create mode 100644 src/modules/API/SoftKeyboardChangeEvent/ISoftKeyboardChangeEvent.h create mode 100644 src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.cpp create mode 100644 src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.h create mode 100644 src/modules/API/SoftKeyboardChangeEvent/config.cmake create mode 100644 src/modules/packages/SoftKeyboardChangeEvent/CMakeLists.txt diff --git a/src/js-overlay/CMakeLists.txt b/src/js-overlay/CMakeLists.txt index 7553aaa..dd68584 100644 --- a/src/js-overlay/CMakeLists.txt +++ b/src/js-overlay/CMakeLists.txt @@ -35,6 +35,7 @@ SET(SRCS ${CMAKE_CURRENT_SOURCE_DIR}/js_iframe_support.cpp ${CMAKE_CURRENT_SOURCE_DIR}/JSClass/JSStorageEvent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/JSClass/JSTizenServiceEvent.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/JSClass/JSSoftKeyboardChangeEvent.cpp ) INCLUDE_DIRECTORIES( @@ -50,7 +51,6 @@ TARGET_LINK_LIBRARIES(${TARGET_NAME} ${webkit2_LIBRARIES} ${TARGET_COMMONS} ${TARGET_COMMONS_JAVASCRIPT} - wrt-plugins-tizen-service-event ) SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES diff --git a/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.cpp b/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.cpp new file mode 100644 index 0000000..048c149 --- /dev/null +++ b/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.cpp @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * + * @file JSSoftKeyboardChangeEvent.cpp + * @author Yunchan Cho (yunchan.cho@samsung.com) + * @version 0.1 + */ + +#include "JSSoftKeyboardChangeEvent.h" +#include +#include +#include +#include +#include + +using namespace WrtDeviceApis; +using namespace WrtDeviceApis::Commons; +using namespace WrtDeviceApis::CommonsJavaScript; +using namespace WrtDeviceApis::SoftKeyboardChangeEvent::Api; + +#define WIDGET_PLUGIN_NAME "SoftKeyboardChangeEvent" +#define SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_STATE "state" +#define SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_WIDTH "width" +#define SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_HEIGHT "height" + +#define CATCH_EXCEPTION_CONVERSION \ + Catch(Commons::ConversionException) {\ + LogError("Error on conversion");\ + return JSDOMExceptionFactory::\ + UnknownException.make(context, exception);\ + } + +#define CATCH_EXCEPTION_NULL_PTR \ + Catch(Commons::NullPointerException) {\ + LogError("Error on pointer, null value");\ + return JSDOMExceptionFactory::\ + UnknownException.make(context, exception);\ + } + +#define CATCH_EXCEPTION_PLATFORM_ERROR \ + Catch(Commons::PlatformException){\ + LogError("PlatformException occured");\ + return JSDOMExceptionFactory::\ + UnknownException.make(context, exception);\ + } + +namespace WrtPlugins { +namespace Tizen { +JSClassDefinition JSSoftKeyboardChangeEvent::m_classInfo = { + 0, + kJSClassAttributeNone, + WIDGET_PLUGIN_NAME, + 0, + m_property, + NULL, + initialize, + finalize, + NULL, //HasProperty, + NULL, //GetProperty, + NULL, //SetProperty, + NULL, //DeleteProperty, + NULL, //GetPropertyNames, + NULL, //CallAsFunction, + NULL, //CallAsConstructor, + NULL, //HasInstance, + NULL, //ConvertToType, +}; + +JSStaticValue JSSoftKeyboardChangeEvent::m_property[] = { + { SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_STATE, JSSoftKeyboardChangeEvent::getState, + 0, kJSPropertyAttributeReadOnly }, + { SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_WIDTH, JSSoftKeyboardChangeEvent::getWidth, + 0, kJSPropertyAttributeReadOnly }, + { SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_HEIGHT, JSSoftKeyboardChangeEvent::getHeight, + 0, kJSPropertyAttributeReadOnly }, + { 0, 0, 0, 0 } +}; + +const JSClassRef JSSoftKeyboardChangeEvent::getClassRef() +{ + if (!m_jsClassRef) { + m_jsClassRef = JSClassCreate(&m_classInfo); + } + return m_jsClassRef; +} + +const JSClassDefinition* JSSoftKeyboardChangeEvent::getClassInfo() +{ + return &m_classInfo; +} + +JSClassRef JSSoftKeyboardChangeEvent::m_jsClassRef = JSClassCreate(JSSoftKeyboardChangeEvent::getClassInfo()); + +void JSSoftKeyboardChangeEvent::initialize(JSContextRef context, JSObjectRef object) +{ + LogDebug("entered"); + + JSSoftKeyboardChangeEventPrivateObject* priv = + static_cast(JSObjectGetPrivate(object)); + + Assert(priv && "Missing private object"); +} + +void JSSoftKeyboardChangeEvent::finalize(JSObjectRef object) +{ + LogDebug("entered"); + JSSoftKeyboardChangeEventPrivateObject* priv = + static_cast(JSObjectGetPrivate(object)); + + delete priv; + LogDebug("private object is realised"); + +} + +JSValueRef JSSoftKeyboardChangeEvent::getState( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + LogDebug("entered!"); + + Try + { + Converter converter(context); + return converter.toJSValueRef(getPrivateObject(object)->getState()); + } + CATCH_EXCEPTION_CONVERSION + CATCH_EXCEPTION_NULL_PTR + CATCH_EXCEPTION_PLATFORM_ERROR +} + +JSValueRef JSSoftKeyboardChangeEvent::getWidth( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + LogDebug("entered!"); + + Try + { + Converter converter(context); + return converter.toJSValueRef(getPrivateObject(object)->getWidth()); + } + CATCH_EXCEPTION_CONVERSION + CATCH_EXCEPTION_NULL_PTR + CATCH_EXCEPTION_PLATFORM_ERROR +} + +JSValueRef JSSoftKeyboardChangeEvent::getHeight( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + LogDebug("entered"); + + Try + { + Converter converter(context); + return converter.toJSValueRef(getPrivateObject(object)->getHeight()); + } + CATCH_EXCEPTION_CONVERSION + CATCH_EXCEPTION_NULL_PTR + CATCH_EXCEPTION_PLATFORM_ERROR +} + +ISoftKeyboardChangeEventPtr JSSoftKeyboardChangeEvent::getPrivateObject(JSObjectRef arg) +{ + JSSoftKeyboardChangeEventPrivateObject* priv = + static_cast(JSObjectGetPrivate(arg)); + + if (!priv) { + LogError("Private object not initialized"); + ThrowMsg(Commons::NullPointerException, + "Private object not initialized"); + } + + return priv->getObject(); +} + +#undef CATCH_EXCEPTION_CONVERSION +#undef CATCH_EXCEPTION_NULL_PTR +#undef CATCH_EXCEPTION_PLATFORM_ERROR + +} +} diff --git a/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.h b/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.h new file mode 100644 index 0000000..f9dce7f --- /dev/null +++ b/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * + * @file JSSoftKeyboardChangeEvent.h + * @author Yunchan Cho (yunchan.cho@samsung.com) + * @version 0.1 + * @brief + */ + +#ifndef WRT_PLUGIN_JS_SOFTKEYBOARD_CHANGE_EVENT_H +#define WRT_PLUGIN_JS_SOFTKEYBOARD_CHANGE_EVENT_H + +#include +#include +#include + +namespace WrtPlugins { +namespace Tizen { + +typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT< + WrtDeviceApis::SoftKeyboardChangeEvent::Api::ISoftKeyboardChangeEventPtr>::Type + JSSoftKeyboardChangeEventPrivateObject; + +class JSSoftKeyboardChangeEvent +{ + public: + /** + * This method initializes this in the JS Engine. + */ + static const JSClassRef getClassRef(); + + /** + * Gets object's class description. + */ + static const JSClassDefinition* getClassInfo(); + + private: + /** + * The callback invoked when an object is first created. + */ + static void initialize(JSContextRef context, JSObjectRef object); + + /** + * The callback invoked when an object is finalized. + */ + static void finalize(JSObjectRef object); + + /** + * This structure describes a statically declared value property. + */ + static JSStaticValue m_property[]; + + /** + * This structure contains properties and callbacks that define a type of object. + */ + static JSClassDefinition m_classInfo; + + static JSClassRef m_jsClassRef; + + // getters for properties + static JSValueRef getState( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + + static JSValueRef getWidth( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + + static JSValueRef getHeight( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + + static WrtDeviceApis::SoftKeyboardChangeEvent::Api::ISoftKeyboardChangeEventPtr + getPrivateObject(JSObjectRef arg); +}; +} // Tizen +} // WrtPlugins + +#endif // WRT_PLUGIN_JS_SOFTKEYBOARD_CHANGE_EVENT_H diff --git a/src/js-overlay/js_overlay_addEventListener.cpp b/src/js-overlay/js_overlay_addEventListener.cpp index 8ec4ae6..c14fe5f 100644 --- a/src/js-overlay/js_overlay_addEventListener.cpp +++ b/src/js-overlay/js_overlay_addEventListener.cpp @@ -29,12 +29,15 @@ #include #include #include -#include "JSStorageEvent.h" -#include "JSTizenServiceEvent.h" +#include namespace WrtPlugins { namespace W3C { +const std::string storageEventName = "storage"; +const std::string appServiceEventName = "appservice"; +const std::string softKeyboardChangeEventName = "softkeyboardchange"; + AddEventListenerSupport::IFramesListeners AddEventListenerSupport::m_listeners = AddEventListenerSupport::IFramesListeners(); @@ -82,8 +85,9 @@ AddEventListener(JSContextRef context, Converter(context).toString(arguments[0]); LogDebug("Event name: " << eventName); - if(eventName != "storage" && - eventName != "appservice"){ + if(eventName != storageEventName && + eventName != appServiceEventName && + eventName != softKeyboardChangeEventName) { LogDebug("Event type not supported"); return JSValueMakeUndefined(context); } @@ -99,22 +103,21 @@ AddEventListener(JSContextRef context, return JSValueMakeUndefined(context); } //add object to Listeners - //set event information according to each event type - if(eventName == "storage") { - CallbackData data = { - StorageCustomEvent, - objectCb, - thisObject}; - getIFrameListeners(thisObject)->push_back(data); - } else if (eventName == "appservice") { - CallbackData data = { - ServiceCustomEvent, - objectCb, - thisObject}; - getIFrameListeners(thisObject)->push_back(data); + CallbackData data; + data.object = objectCb; + data.thisObject = thisObject; + + if(eventName == storageEventName) { + data.eventType = StorageCustomEvent; + } else if (eventName == appServiceEventName) { + data.eventType = ServiceCustomEvent; + } else if (eventName == softKeyboardChangeEventName) { + data.eventType = SoftKeyboardChangeCustomEvent; } + getIFrameListeners(thisObject)->push_back(data); + return JSValueMakeUndefined(context); } @@ -166,10 +169,11 @@ CallStorageListenersFromDifferentIFrames( }; void AddEventListenerSupport:: -CallServiceListenersFromIFrame(JSObjectRef iframe, - const WrtDeviceApis::TizenServiceEvent::Api::ITizenServiceEventPtr& event) +CallCustomEventListenersFromIFrame( + JSObjectRef iframe, + CustomEventType eventType, + JSObjectRef eventObject) { - using namespace WrtPlugins::Tizen; LogDebug("Invoked callbacks"); IFramesListeners::iterator it = m_listeners.find(iframe); @@ -178,20 +182,13 @@ CallServiceListenersFromIFrame(JSObjectRef iframe, return; } - auto eventPriv = - new JSTizenServiceEventPrivateObject(m_context, event); - - JSObjectRef eventObject = - JSObjectMake(m_context, JSTizenServiceEvent::getClassRef(), eventPriv); const size_t argc = 1; JSValueRef argv[argc] = {eventObject}; JSValueProtect(m_context, eventObject); FOREACH(listener, *it->second) { - if (listener->eventType == - ServiceCustomEvent) - { + if (listener->eventType == eventType) { LogDebug("Call"); JSObjectCallAsFunction( m_context, diff --git a/src/js-overlay/js_overlay_addEventListener.h b/src/js-overlay/js_overlay_addEventListener.h index dbdd1fb..d8ea74a 100644 --- a/src/js-overlay/js_overlay_addEventListener.h +++ b/src/js-overlay/js_overlay_addEventListener.h @@ -55,9 +55,10 @@ class AddEventListenerSupport JSObjectRef iframe, const WrtDeviceApis::StorageEvent::Api::IStorageEventPtr& event); - static void CallServiceListenersFromIFrame( + static void CallCustomEventListenersFromIFrame( JSObjectRef iframe, - const WrtDeviceApis::TizenServiceEvent::Api::ITizenServiceEventPtr& event); + CustomEventType eventType, + JSObjectRef eventObject); private: diff --git a/src/js-overlay/js_overlay_types.h b/src/js-overlay/js_overlay_types.h index 199a2b5..c913f62 100644 --- a/src/js-overlay/js_overlay_types.h +++ b/src/js-overlay/js_overlay_types.h @@ -24,14 +24,32 @@ #ifndef _WRT_PLUGINS_JS_OVERLAY_TYPES_H_ #define _WRT_PLUGINS_JS_OVERLAY_TYPES_H_ +#include + namespace WrtPlugins { namespace W3C { +// If needed, enum for new custom event should be defined here enum CustomEventType { StorageCustomEvent, ServiceCustomEvent, + SoftKeyboardChangeCustomEvent, }; +// Argument structure of SoftKeyboardChangeCustomEvent +typedef struct SoftKeyboardChangeArgs { + std::string state; // value is 'on' or 'off' + int width; + int height; + SoftKeyboardChangeArgs(): + width(0), + height(0) + { + } +} SoftKeyboardChangeArgs; + +// If needed, argument structure of other custom events should be defined here + } // W3C } // WrtPlugins #endif // _WRT_PLUGINS_JS_OVERLAY_TYPES_H_ diff --git a/src/modules/API/CMakeLists.txt b/src/modules/API/CMakeLists.txt index 6893517..cba823c 100644 --- a/src/modules/API/CMakeLists.txt +++ b/src/modules/API/CMakeLists.txt @@ -16,7 +16,8 @@ include_config_file(Filesystem) include_config_file(Cpu) include_config_file(Widget) include_config_file(LocalStorage) -include_config_file(StorageEvent) -include_config_file(TizenServiceEvent) include_config_file(WidgetDB) include_config_file(PluginManager) +include_config_file(StorageEvent) +include_config_file(TizenServiceEvent) +include_config_file(SoftKeyboardChangeEvent) diff --git a/src/modules/API/SoftKeyboardChangeEvent/ISoftKeyboardChangeEvent.h b/src/modules/API/SoftKeyboardChangeEvent/ISoftKeyboardChangeEvent.h new file mode 100644 index 0000000..2bc752b --- /dev/null +++ b/src/modules/API/SoftKeyboardChangeEvent/ISoftKeyboardChangeEvent.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * + * @file ISoftKeyboardChangeEvent.h + * @author Yunchan Cho (yunchan.cho@samsung.com) + * @version 0.1 + * @brief softkeyboardchange event interfece + */ + +#ifndef WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_INTERFACE_H +#define WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_INTERFACE_H + +#include + +namespace WrtDeviceApis { +namespace SoftKeyboardChangeEvent { +namespace Api { + +class ISoftKeyboardChangeEvent +{ + public : + virtual std::string getState() const = 0; + virtual int getWidth() const = 0; + virtual int getHeight() const = 0; + + virtual ~ISoftKeyboardChangeEvent() {}; +}; + +typedef std::shared_ptr ISoftKeyboardChangeEventPtr; + +} // Api +} // SoftKeyboardChangeEvent +} // WrtDeviceApis + +#endif // WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_INTERFACE_H diff --git a/src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.cpp b/src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.cpp new file mode 100644 index 0000000..154a014 --- /dev/null +++ b/src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * + * @file SoftKeyboardChangeEvent.cpp + * @author Yunchan Cho (yunchan.cho@samsung.com) + * @version 0.1 + * @brief softkeyboardchange event class implementation + */ + +#include "SoftKeyboardChangeEvent.h" + +namespace WrtDeviceApis { +namespace SoftKeyboardChangeEvent { +namespace Api { + +SoftKeyboardChangeEvent::SoftKeyboardChangeEvent( + std::string state, int width, int height): + m_state(state), m_width(width), m_height(height) +{ +} + +SoftKeyboardChangeEvent::~SoftKeyboardChangeEvent() +{ +} + +std::string SoftKeyboardChangeEvent::getState() const +{ + return m_state; +} + +int SoftKeyboardChangeEvent::getWidth() const +{ + return m_width; +} + +int SoftKeyboardChangeEvent::getHeight() const +{ + return m_height; +} + +} // Api +} // SoftKeyboardChangeEvent +} // WrtDeviceApis diff --git a/src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.h b/src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.h new file mode 100644 index 0000000..ef28353 --- /dev/null +++ b/src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * + * @file SoftKeyboardChangeEvent.h + * @author Yunchan Cho (yunchan.cho@samsung.com) + * @version 0.1 + * @brief softkeyboardchange event class + */ + +#ifndef WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_CLASS_H +#define WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_CLASS_H + +#include +#include "ISoftKeyboardChangeEvent.h" + +namespace WrtDeviceApis { +namespace SoftKeyboardChangeEvent { +namespace Api { + +class SoftKeyboardChangeEvent : public ISoftKeyboardChangeEvent +{ + public : + explicit SoftKeyboardChangeEvent( + std::string state, + int width, + int height); + ~SoftKeyboardChangeEvent(); + + std::string getState() const; + int getWidth() const; + int getHeight() const; + + private : + std::string m_state; + int m_width; + int m_height; +}; + +} // Api +} // SoftKeyboardChangeEvent +} // WrtDeviceApis + +#endif // WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_CLASS_H diff --git a/src/modules/API/SoftKeyboardChangeEvent/config.cmake b/src/modules/API/SoftKeyboardChangeEvent/config.cmake new file mode 100644 index 0000000..398a39b --- /dev/null +++ b/src/modules/API/SoftKeyboardChangeEvent/config.cmake @@ -0,0 +1,11 @@ +get_current_path() + +set(API_SOFTKEYBOARD_CHANGE_EVENT_PATH + ${CURRENT_PATH} + PARENT_SCOPE + ) + +set(SRCS_API_SOFTKEYBOARD_CHANGE_EVENT + ${CURRENT_PATH}/SoftKeyboardChangeEvent.cpp + PARENT_SCOPE +) diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 0d64dbb..85db759 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -17,9 +17,6 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/${PLATFORM} ) -include_config_file(API) -include_config_file(${PLATFORM}) - add_subdirectory(API) add_subdirectory(${PLATFORM}) add_subdirectory(packages) diff --git a/src/modules/packages/CMakeLists.txt b/src/modules/packages/CMakeLists.txt index 85b28b0..4d566f4 100644 --- a/src/modules/packages/CMakeLists.txt +++ b/src/modules/packages/CMakeLists.txt @@ -32,6 +32,7 @@ set(TARGET_MODULE_LOCALSTORAGE "wrt-plugins-localstorage") set(TARGET_MODULE_WIDGET_INTERFACE_DAO "wrt-plugins-widget-interface-dao") set(TARGET_MODULE_STORAGEEVENT "wrt-plugins-storageevent") set(TARGET_MODULE_TIZEN_SERVICE_EVENT "wrt-plugins-tizen-service-event") +set(TARGET_MODULE_SOFTKEYBOARD_CHANGE_EVENT "wrt-plugins-softkeyboardchange-event") set(TARGET_MODULE_WIDGETDB "wrt-plugins-widgetdb") set(TARGET_MODULE_PLUGIN_MANAGER "wrt-plugins-plugin-manager") @@ -40,7 +41,8 @@ add_subdirectory(Cpu) add_subdirectory(Widget) add_subdirectory(LocalStorage) add_subdirectory(WidgetInterfaceDAO) -add_subdirectory(StorageEvent) -add_subdirectory(TizenServiceEvent) add_subdirectory(WidgetDB) add_subdirectory(PluginManager) +add_subdirectory(StorageEvent) +add_subdirectory(TizenServiceEvent) +add_subdirectory(SoftKeyboardChangeEvent) diff --git a/src/modules/packages/SoftKeyboardChangeEvent/CMakeLists.txt b/src/modules/packages/SoftKeyboardChangeEvent/CMakeLists.txt new file mode 100644 index 0000000..84b9944 --- /dev/null +++ b/src/modules/packages/SoftKeyboardChangeEvent/CMakeLists.txt @@ -0,0 +1,26 @@ +# Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# @file CMakeLists.txt +# @author Yunchan Cho (yunchan.cho@samsung.com) +# @version 0.1 + +set(TARGET_NAME ${TARGET_MODULE_SOFTKEYBOARD_CHANGE_EVENT}) + +set(SRCS + ${SRCS_API_SOFTKEYBOARD_CHANGE_EVENT} +) + +add_library(${TARGET_NAME} STATIC ${SRCS}) diff --git a/src/plugin-loading/CMakeLists.txt b/src/plugin-loading/CMakeLists.txt index 135b224..fbcf48a 100644 --- a/src/plugin-loading/CMakeLists.txt +++ b/src/plugin-loading/CMakeLists.txt @@ -24,8 +24,6 @@ pkg_search_module(dpl-event REQUIRED dpl-event-efl) pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro) pkg_search_module(webkit2 REQUIRED ewebkit2) -#set(PLUGIN_MODULE_SRC_DIR ${PROJECT_SOURCE_DIR}/src/plugin-service) - set(PLUGIN_LOADING_SOURCES ${PLUGIN_LOADING_DIRS}/plugin_logic.cpp ${PLUGIN_LOADING_DIRS}/plugin.cpp @@ -36,11 +34,10 @@ set(PLUGIN_LOADING_SOURCES ${PLUGIN_LOADING_DIRS}/plugin_property_support.cpp ${PLUGIN_LOADING_DIRS}/javascript_interface.cpp ${PLUGIN_LOADING_DIRS}/js_page_session.cpp - # ${PLUGIN_MODULE_SRC_DIR}/wrt_plugin_module.cpp ) INCLUDE_DIRECTORIES( - # ${PLUGIN_MODULE_SRC_DIR} + ${PLUGIN_MODULE_SRC_DIR} ${PLUGIN_LOADING_DIRS} ${webkit2_INCLUDE_DIRS} ${plugin-types_INCLUDE_DIRS} @@ -66,6 +63,8 @@ target_link_libraries(${TARGET_PLUGIN_LOADING_LIB} ${dpl-wrt-dao-ro_LIBRARIES} ${TARGET_COMMONS} ${TARGET_JS_OVERLAY} + wrt-plugins-tizen-service-event # static lib + wrt-plugins-softkeyboardchange-event # static lib ) INSTALL(TARGETS ${TARGET_PLUGIN_LOADING_LIB} diff --git a/src/plugin-loading/explorer.cpp b/src/plugin-loading/explorer.cpp index d755777..bbb22d4 100644 --- a/src/plugin-loading/explorer.cpp +++ b/src/plugin-loading/explorer.cpp @@ -33,6 +33,11 @@ #include #include #include +#include +#include +#include +#include + namespace { //const char* SEPARATOR = "."; @@ -402,20 +407,19 @@ void Explorer::cleanIframesData() m_iframeSupport.clean(); } -void Explorer::callEventListeners(CustomEventType eventType) +void Explorer::callEventListeners(CustomEventType eventType, void* data) { - if (eventType == ServiceCustomEvent) - { - using namespace WrtDeviceApis::TizenServiceEvent::Api; + using namespace WrtPlugins::Tizen; + // get iframe objects from javascript global context + JavaScriptInterface::ObjectsListPtr frameLists = + JavaScriptInterfaceSingleton::Instance().getIframesList(m_context); - // get iframe objects from javascript global context - JavaScriptInterface::ObjectsListPtr frameLists = - JavaScriptInterfaceSingleton::Instance().getIframesList(m_context); - - // get main frame object from javascript global context - JSObjectRef mainFrame = JSContextGetGlobalObject(m_context); - frameLists->push_back(JSObjectPtr(new JSObject(mainFrame))); + // get main frame object from javascript global context + JSObjectRef mainFrame = JSContextGetGlobalObject(m_context); + frameLists->push_back(JSObjectPtr(new JSObject(mainFrame))); + if (eventType == ServiceCustomEvent) { + using namespace WrtDeviceApis::TizenServiceEvent::Api; // set user data of js callback function for 'appservice' js event ITizenServiceEventPtr event = ITizenServiceEventPtr(new TizenServiceEvent()); event->setScale(m_propertySupport->getScale()); @@ -425,11 +429,53 @@ void Explorer::callEventListeners(CustomEventType eventType) FOREACH(it, *frameLists) { JSObjectRef frame = static_cast((*it).Get()->getObject()); - AddEventListenerSupport::CallServiceListenersFromIFrame(frame, event); + + auto eventPriv = + new JSTizenServiceEventPrivateObject(m_context, event); + JSObjectRef eventObject = + JSObjectMake(m_context, JSTizenServiceEvent::getClassRef(), eventPriv); + + AddEventListenerSupport::CallCustomEventListenersFromIFrame( + frame, eventType, eventObject); + } + } else if (eventType == SoftKeyboardChangeCustomEvent) { + using namespace WrtDeviceApis::SoftKeyboardChangeEvent::Api; + if (!data) { + LogDebug("no ime size"); + return; + } + + // set user data of js callback function for 'softkeyboardchange' js event + SoftKeyboardChangeArgs* args = static_cast(data); + ISoftKeyboardChangeEventPtr event = + ISoftKeyboardChangeEventPtr( + new SoftKeyboardChangeEvent( + args->state, + args->width, + args->height)); + LogInfo("softkeyboard event's state: " << args->state); + + // call js callback function for 'softkeyboardchange' js event on each frame + FOREACH(it, *frameLists) + { + JSObjectRef frame = static_cast((*it).Get()->getObject()); + + auto eventPriv = + new JSSoftKeyboardChangeEventPrivateObject(m_context, event); + JSObjectRef eventObject = + JSObjectMake( + m_context, + JSSoftKeyboardChangeEvent::getClassRef(), + eventPriv); + + AddEventListenerSupport::CallCustomEventListenersFromIFrame( + frame, eventType, eventObject); } } else { LogInfo("Not supported custom event type"); + return; } + } WindowPropertySupport* Explorer::getWindowPropertySupport() diff --git a/src/plugin-loading/explorer.h b/src/plugin-loading/explorer.h index e6f8cac..0c81dcf 100644 --- a/src/plugin-loading/explorer.h +++ b/src/plugin-loading/explorer.h @@ -65,7 +65,7 @@ class Explorer : private DPL::Noncopyable void removePluginsFromIframes(); void cleanIframesData(); - void callEventListeners(CustomEventType eventType); + void callEventListeners(CustomEventType eventType, void* data); WindowPropertySupport* getWindowPropertySupport(); diff --git a/src/plugin-loading/js_page_session.cpp b/src/plugin-loading/js_page_session.cpp index 4f4a5ff..04841bf 100644 --- a/src/plugin-loading/js_page_session.cpp +++ b/src/plugin-loading/js_page_session.cpp @@ -139,7 +139,7 @@ class JSPageSession::Impl const char* encodedBundle, const char* theme); - void dispatchJavaScriptEvent(CustomEventType eventType); + void dispatchJavaScriptEvent(CustomEventType eventType, void* data); }; @@ -385,7 +385,7 @@ void JSPageSession::Impl::setCustomProperties(double scaleFactor, ->setThemeToNavigatorProperty(theme); } -void JSPageSession::Impl::dispatchJavaScriptEvent(CustomEventType eventType) +void JSPageSession::Impl::dispatchJavaScriptEvent(CustomEventType eventType, void* data) { // Check if session is already started if (!m_sessionStarted) { @@ -394,7 +394,7 @@ void JSPageSession::Impl::dispatchJavaScriptEvent(CustomEventType eventType) } LogInfo("Request dispatching javascript event"); - m_objectExplorer->callEventListeners(eventType); + m_objectExplorer->callEventListeners(eventType, data); } void JSPageSession::Impl::loadInjectedJavaScript() @@ -746,9 +746,9 @@ void JSPageSession::setCustomProperties(double scaleFactor, m_impl->setCustomProperties(scaleFactor, encodedBundle, theme); } -void JSPageSession::dispatchJavaScriptEvent(CustomEventType eventType) +void JSPageSession::dispatchJavaScriptEvent(CustomEventType eventType, void* data) { - m_impl->dispatchJavaScriptEvent(eventType); + m_impl->dispatchJavaScriptEvent(eventType, data); } void JSPageSession::loadFrame(JSGlobalContextRef context) diff --git a/src/plugin-loading/js_page_session.h b/src/plugin-loading/js_page_session.h index 5f1ebc2..3580287 100644 --- a/src/plugin-loading/js_page_session.h +++ b/src/plugin-loading/js_page_session.h @@ -55,7 +55,7 @@ class JSPageSession const char* encodedBundle, const char* theme); - void dispatchJavaScriptEvent(CustomEventType eventType); + void dispatchJavaScriptEvent(CustomEventType eventType, void* data); JSPageSession(const PluginContainerSupportPtr& containerSupport); diff --git a/src/plugin-loading/plugin_logic.cpp b/src/plugin-loading/plugin_logic.cpp index e97b593..c4da42e 100644 --- a/src/plugin-loading/plugin_logic.cpp +++ b/src/plugin-loading/plugin_logic.cpp @@ -106,7 +106,8 @@ class PluginLogic::Impl const char* theme); void dispatchJavaScriptEvent(JSGlobalContextRef ctx, - CustomEventType eventType); + CustomEventType eventType, + void* data); }; @@ -189,9 +190,10 @@ void PluginLogic::dispatchJavaScriptEvent(CustomEventType eventType) } void PluginLogic::dispatchJavaScriptEvent(JSGlobalContextRef context, - CustomEventType eventType) + CustomEventType eventType, + void *data) { - m_impl->dispatchJavaScriptEvent(context, eventType); + m_impl->dispatchJavaScriptEvent(context, eventType, data); } void PluginLogic::loadFrame(JSGlobalContextRef context) @@ -328,7 +330,8 @@ void PluginLogic::Impl::setCustomProperties(JSGlobalContextRef context, } void PluginLogic::Impl::dispatchJavaScriptEvent(JSGlobalContextRef context, - CustomEventType eventType) + CustomEventType eventType, + void* data) { LogDebug("Dispatch event"); @@ -339,7 +342,7 @@ void PluginLogic::Impl::dispatchJavaScriptEvent(JSGlobalContextRef context, return; } - sessionIt->second->dispatchJavaScriptEvent(eventType); + sessionIt->second->dispatchJavaScriptEvent(eventType, data); } diff --git a/src/plugin-loading/plugin_logic.h b/src/plugin-loading/plugin_logic.h index 1d19415..bccc865 100644 --- a/src/plugin-loading/plugin_logic.h +++ b/src/plugin-loading/plugin_logic.h @@ -76,7 +76,8 @@ class PluginLogic : DPL::Noncopyable WRT_PLUGINS_DEPRECATED void dispatchJavaScriptEvent(CustomEventType eventType); void dispatchJavaScriptEvent(JSGlobalContextRef ctx, - CustomEventType eventType); + CustomEventType eventType, + void* data); private: PluginLogic(); -- 2.7.4