Fix for keypad issue
[framework/osp/web.git] / src / controls / FWebCtrl_WebImpl.cpp
index 2b78f55..c106aa0 100755 (executable)
@@ -73,6 +73,7 @@
 #include <FGrp_Screen.h>
 #include <FIo_DatabaseImpl.h>
 #include <FIo_NormalFile.h>
+#include <FSys_SettingInfoImpl.h>
 #include <FSys_SystemResource.h>
 #include <FSys_VibratorImpl.h>
 #include <FUi_Control.h>
@@ -158,7 +159,7 @@ AddHttpAttributeData(const Eina_Hash* pHash, const void* pKey, void* pValue, voi
        std::unique_ptr<String> pAttrValue(new (std::nothrow) String(reinterpret_cast< char* >(pValue)));
        SysTryReturn(NID_WEB_CTRL, pAttrKey.get() && pAttrValue.get(), EINA_FALSE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       SysLog(NID_WEB_CTRL, "The current value of key is %ls, value is %ls", pAttrKey->GetPointer(), pAttrValue->GetPointer());
+       SysSecureLog(NID_WEB_CTRL, "The current value of key is %ls, value is %ls", pAttrKey->GetPointer(), pAttrValue->GetPointer());
 
        r = reinterpret_cast< HashMap* >(pUserData)->Add(*pAttrKey, *pAttrValue);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
@@ -374,7 +375,7 @@ OnScriptPromptRequested(Evas_Object* pView, const char* pMessage, const char* pD
 CATCH:
        ewk_view_javascript_prompt_reply(pView, null);
 
-       return EINA_FALSE;
+       return EINA_TRUE;
 }
 
 
@@ -971,15 +972,8 @@ OnLoadingRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
        String uriScheme(uri.GetScheme());
        SysSecureLog(NID_WEB_CTRL, "The current value of scheme is %ls", uriScheme.GetPointer());
 
-       if ((uriScheme != L"http") && (uriScheme != L"https") && (uriScheme != L"file"))
+       if ((uriScheme != L"http") && (uriScheme != L"https") && (uriScheme != L"file") && (uriScheme != L""))
        {
-               ewk_policy_decision_ignore(pPolicy);
-
-               if (uriScheme == L"")
-               {
-                       return;
-               }
-
                result r = E_SUCCESS;
 
                if (uriScheme == L"tel")
@@ -997,9 +991,13 @@ OnLoadingRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
                        String operationId(L"http://tizen.org/appcontrol/operation/view");
                        r = _AppControlImpl::FindAndStart(operationId, &url, null, null, null, null);
                }
-               SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
 
-               return;
+               if (r == E_SUCCESS)
+               {
+                       ewk_policy_decision_ignore(pPolicy);
+
+                       return;
+               }
        }
 
        ewk_policy_decision_use(pPolicy);
@@ -1311,7 +1309,6 @@ OnLoadingCompleted(void* pUserData, Evas_Object* pView, void* pEventInfo)
                SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
                pEventArg.release();
        }
-
 }
 
 
@@ -1669,6 +1666,7 @@ OnWebKeypadStateChanged(void* pUserData, Evas_Object* pView, void* pEventInfo)
                                pImpl->GetWebKeypadEventListener()->OnWebKeypadWillOpen(*dynamic_cast< Web* >(&pImpl->GetPublic()));
                        }
                }
+
                pImpl->SetPreviousKeypadBounds(rect);
        }
        else
@@ -1759,11 +1757,6 @@ OnWindowObjectFocusGained(void* pUserData, Evas_Object* pWin, void* pEvent_info)
 
                if (pImpl->IsWinFocusLost() == true)
                {
-                       if (pImpl->IsKeypadOpened() == true)
-                       {
-                               evas_object_focus_set(pWebCore->GetWebNativeNode(), EINA_TRUE);
-                       }
-
                        Ewk_Settings* pSettings = ewk_view_settings_get(pWebCore->GetWebNativeNode());
                        SysAssertf(pSettings, "Failed to get settings instance.");
 
@@ -1773,6 +1766,10 @@ OnWindowObjectFocusGained(void* pUserData, Evas_Object* pWin, void* pEvent_info)
 
                                evas_object_focus_set(pWebCore->GetWebNativeNode(), EINA_TRUE);
                        }
+                       else if (pImpl->IsKeypadOpened() == true)
+                       {
+                               evas_object_focus_set(pWebCore->GetWebNativeNode(), EINA_TRUE);
+                       }
                }
        }
 
@@ -1790,6 +1787,13 @@ OnWebNativeNodeFocusGained(void* pUserData, Evas* pCanvas, Evas_Object* pView, v
        {
                pImpl->SetKeypadOpened(false);
        }
+       /*else if (pImpl->IsWinFocusLost() == true)
+       {
+               _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
+               SysAssertf(pWebCore, "Failed to get Web core object");
+
+               evas_object_focus_set(pWebCore->GetWebNativeNode(), EINA_FALSE);
+       }*/
 }
 
 
@@ -1799,11 +1803,17 @@ OnWebNativeNodeFocusLost(void* pUserData, Evas* pCanvas, Evas_Object* pView, voi
        _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
        SysAssertf(pImpl, "Failed to request");
 
-       if (pImpl->IsWinFocusLost() == true)
-       {
-               _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
-               SysAssertf(pWebCore, "Failed to get Web core object");
+       _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
+       SysAssertf(pWebCore, "Failed to get Web core object");
+
+       Eina_Rectangle leftHandle;
+       Eina_Rectangle rightHandle;
+
+       EINA_RECTANGLE_SET(&leftHandle, 0, 0, 0, 0);
+       EINA_RECTANGLE_SET(&rightHandle, 0, 0, 0, 0);
 
+       if (pImpl->IsWinFocusLost() == true && ewk_view_text_selection_range_get(pWebCore->GetWebNativeNode(), &leftHandle, &rightHandle))
+       {
                Ewk_Settings* pSettings = ewk_view_settings_get(pWebCore->GetWebNativeNode());
                SysAssertf(pSettings, "Failed to get settings instance.");
 
@@ -2427,7 +2437,7 @@ _WebImpl::LoadUrl(const String& url, const HttpHeader& header)
 {
        std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(url));
        SysTryReturn(NID_WEB_CTRL, pUrl.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-       
+
        Eina_Hash* pHttpHeader = ConvertToSlpHeaderN(header);
 
        ewk_view_url_request_set(__pWebCore->GetWebNativeNode(), pUrl.get(), EWK_HTTP_METHOD_GET, pHttpHeader, null);
@@ -2496,7 +2506,7 @@ _WebImpl::ShowSelectBoxPopup(bool isMultiSelect, const String& title, Eina_List*
        std::unique_ptr<_SelectBox> pSelectBox(new (std::nothrow) _SelectBox());
        SysTryReturnResult(NID_WEB_CTRL, pSelectBox.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
 
-       r = pSelectBox->Construct(isMultiSelect, title, DEFAULT_LIST_ITEM_COUNT, pWebView);
+       r = pSelectBox->Construct(this, isMultiSelect, title, DEFAULT_LIST_ITEM_COUNT, pWebView);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        r = pSelectBox->UpdateList(pItems, selectedIndex, false, false);
@@ -4881,6 +4891,8 @@ _WebImpl::OnPreAttachedToMainTree(void)
                r = InitializeSetting();
                SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
+               SettingInfo::AddSettingEventListener(*this);
+
                _WebManager* pWebManager = _WebManager::GetInstance();
                pWebManager->AddWeb(reinterpret_cast< int >(this));
        }
@@ -4905,8 +4917,30 @@ _WebImpl::OnDetachingFromMainTree(void)
 
 
 void
+_WebImpl::OnSettingChanged(String& key)
+{
+       Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
+       if (!pWebview)
+       {
+               return;
+       }
+
+       if (key == L"http://tizen.org/setting/font.type")
+       {
+               ewk_view_use_settings_font(pWebview);
+       }
+}
+
+
+void
 _WebImpl::OnChangeLayout(_ControlRotation rotation)
 {
+       Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
+       if (!pWebview)
+       {
+               return;
+       }
+
        int degree = 0;
 
        switch (rotation)
@@ -4926,7 +4960,7 @@ _WebImpl::OnChangeLayout(_ControlRotation rotation)
                default:
                        SysAssert(false);
        }
-       ewk_view_orientation_send(__pWebCore->GetWebNativeNode(), degree);
+       ewk_view_orientation_send(pWebview, degree);
 }
 
 
@@ -4950,22 +4984,37 @@ _WebImpl::OnChangeLayout(_ControlOrientation orientation)
                pWebNotification = static_cast< _WebNotification* >(pEnum->GetCurrent());
                pWebNotification->OnChangeLayout();
        }
+
+       if (IsKeypadVisible())
+       {
+               _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
+               SysAssertf(pXformer, "Failed to get CoordinateTransformer");
+
+               _FormImpl* pFormImpl = GetParentFormImpl(dynamic_cast< _ControlImpl* >(this));
+               pFormImpl->DeflateClientRectHeight(pXformer->TransformVertical(GetPreviousKeypadBounds().height));
+       }
 }
 
 
 void
 _WebImpl::OnAncestorVisibleStateChanged(const _Control& control)
 {
+       Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
+       if (!pWebview)
+       {
+               return;
+       }
+
        _WebManager* pWebManager = _WebManager::GetInstance();
        if (IsVisible() == true)
        {
                pWebManager->SetActiveWeb(this);
-               ewk_view_page_visibility_state_set(__pWebCore->GetWebNativeNode(), EWK_PAGE_VISIBILITY_STATE_VISIBLE, false);
+               ewk_view_page_visibility_state_set(pWebview, EWK_PAGE_VISIBILITY_STATE_VISIBLE, false);
        }
        else
        {
                pWebManager->RemoveActiveWeb(this);
-               ewk_view_page_visibility_state_set(__pWebCore->GetWebNativeNode(), EWK_PAGE_VISIBILITY_STATE_HIDDEN, false);
+               ewk_view_page_visibility_state_set(pWebview, EWK_PAGE_VISIBILITY_STATE_HIDDEN, false);
        }
 }
 
@@ -4998,6 +5047,9 @@ _WebImpl::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::ILi
        case ID_USER_SCRIPT_CONFIRM_CLOSE:
                __pScriptConfirmPopup.reset();
                break;
+       case ID_USER_SCRIPT_SELECTBOX_CLOSE:
+               __pSelectBox.reset();
+               break;
        default:
                break;
        }