Tizen 2.2.1
[framework/osp/web.git] / src / controls / FWebCtrl_PromptPopup.cpp
index 00f3994..9a6ab1a 100755 (executable)
@@ -19,6 +19,7 @@
  * @file               FWebCtrl_AuthConfirmPopup.cpp
  * @brief              The file contains the definition of _AuthConfirmPopup class.
  */
+#include <ewk_view.h>
 #include <FBaseColIList.h>
 #include <FBaseSysLog.h>
 #include <FGrpColor.h>
 #include <FUiCtrlLabel.h>
 #include <FUiCtrlPanel.h>
 #include <FUiCtrlTextBox.h>
+#include <FUiKeyEventInfo.h>
 #include <FUiLayout.h>
 #include <FUiVerticalBoxLayout.h>
 #include <FWebCtrlAuthenticationChallenge.h>
+#include <FBase_StringConverter.h>
 #include <FSys_SystemResource.h>
 #include <FUi_ControlManager.h>
 #include <FUi_ResourceManager.h>
 #include <FUiCtrl_TextBoxImpl.h>
 #include "FWebCtrl_PromptPopup.h"
+#include "FWebCtrl_WebImpl.h"
 
 
 using namespace Tizen::Base;
@@ -47,18 +51,21 @@ using namespace Tizen::Ui;
 using namespace Tizen::Ui::Controls;
 
 
-static const int LABEL_HEIGHT = 10;
-
-
 namespace Tizen { namespace Web { namespace Controls
 {
 
 
+static const int EDIT_TEXT_SIZE = 35;
+
+
 _PromptPopup::_PromptPopup(void)
        : __pEditField(null)
+       , __pWebView(null)
+       , __pImpl(null)
 {
 }
 
+
 _PromptPopup::~_PromptPopup(void)
 {
 }
@@ -66,17 +73,20 @@ _PromptPopup::~_PromptPopup(void)
 
 // Prompt popup
 result
-_PromptPopup::Construct(const String& message, const String& defaultVale)
+_PromptPopup::Construct(const String& message, const String& defaultVale,  Evas_Object* pView, _WebImpl* pImpl)
 {
        result r = E_SUCCESS;
        Rectangle rect(0, 0, 0, 0);
 
        int popupHeight = 0;
 
+       __pImpl = pImpl;
+       __pWebView = pView;
+
        _WebPopupData* pPopupData = _WebPopup::GetPopupData();
        SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
 
-       popupHeight = LABEL_HEIGHT + (2 * pPopupData->editDim.height + pPopupData->spacePad)  + pPopupData->btnDim.height + (4 * pPopupData->spacePad) ;
+       popupHeight = pPopupData->editDim.height + pPopupData->labelDim.height + pPopupData->panelHeight + (2 * pPopupData->spacePad);
 
        r = _WebPopup::Construct(true, Dimension(pPopupData->popupDim.width, popupHeight));
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
@@ -84,9 +94,9 @@ _PromptPopup::Construct(const String& message, const String& defaultVale)
 
        //Text box
        rect = GetClientAreaBounds();
-       rect.width = pPopupData->popupDim.width - 2 * pPopupData->sideMargin;
+       rect.width = pPopupData->labelDim.width;
        rect.y = 0;
-       rect.height = pPopupData->editDim.height + 10;
+       rect.height = pPopupData->labelDim.height;
 
        std::unique_ptr<TextBox> pTextBox(new (std::nothrow) TextBox());
        SysTryReturnResult(NID_WEB_CTRL, pTextBox.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
@@ -94,6 +104,7 @@ _PromptPopup::Construct(const String& message, const String& defaultVale)
        r = pTextBox->Construct(rect, TEXT_BOX_BORDER_ROUNDED);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
+       pTextBox->SetTextSize(EDIT_TEXT_SIZE);
        pTextBox->SetText(message);
        pTextBox->SetColor(TEXT_BOX_STATUS_NORMAL, GetColor());
        pTextBox->SetColor(TEXT_BOX_STATUS_HIGHLIGHTED, GetColor());
@@ -103,10 +114,9 @@ _PromptPopup::Construct(const String& message, const String& defaultVale)
 
        TextBox* pTmpTextBox = pTextBox.release();
 
-
        //Edit Field
        rect.y = 0;
-       rect.height = pPopupData->editDim.height + 10;
+       rect.height = pPopupData->editDim.height;
 
        std::unique_ptr<EditField> pEditField(new (std::nothrow) EditField());
        SysTryReturnResult(NID_WEB_CTRL, pEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
@@ -114,6 +124,7 @@ _PromptPopup::Construct(const String& message, const String& defaultVale)
        r = pEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
+       pEditField->SetTextSize(EDIT_TEXT_SIZE);
        pEditField->SetText(defaultVale);
 
        r = AddControl(*pEditField);
@@ -132,14 +143,14 @@ _PromptPopup::Construct(const String& message, const String& defaultVale)
        ArrayList idList;
        r = idList.Construct();
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-       idList.Add(*(new Integer(ID_BUTTON_PROMPT_OK)));
        idList.Add(*(new Integer(ID_BUTTON_PROMPT_CANCEL)));
+       idList.Add(*(new Integer(ID_BUTTON_PROMPT_OK)));
 
        ArrayList titleList;
        r = titleList.Construct();
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-       titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_SK_OK"))));
-       titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_POP_CANCEL"))));
+       titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CANCEL_ABB"))));
+       titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_OK"))));
 
        r = CreateAndAddButtons(idList, titleList, pButtonPanel);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
@@ -149,15 +160,16 @@ _PromptPopup::Construct(const String& message, const String& defaultVale)
 
        pLayout->SetHorizontalAlignment(*pTmpTextBox, LAYOUT_HORIZONTAL_ALIGN_CENTER);
        pLayout->SetHorizontalAlignment(*__pEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
-       pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
 
-       pLayout->SetSpacing(*pTmpTextBox, pPopupData->spacePad);
        pLayout->SetSpacing(*__pEditField, pPopupData->spacePad);
        pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
 
+       SetPropagatedKeyEventListener(this);
+       
        return r;
 }
 
+
 const String
 _PromptPopup::GetPromptText()
 {
@@ -171,18 +183,59 @@ _PromptPopup::OnActionPerformed(const Control& source, int actionId)
        switch (actionId)
        {
        case ID_BUTTON_PROMPT_OK:
-               SetShowState(false);
+       {
                HidePopup(ID_BUTTON_PROMPT_OK);
+               std::unique_ptr<char[]> pResult(_StringConverter::CopyToCharArrayN(GetPromptText()));
+               ewk_view_javascript_prompt_reply(__pWebView, pResult.get());
                break;
-
+       }
        case ID_BUTTON_PROMPT_CANCEL:
-               SetShowState(false);
                HidePopup(ID_BUTTON_PROMPT_CANCEL);
+               ewk_view_javascript_prompt_reply(__pWebView, null);
                break;
 
        default:
+               SysAssertf(false, "unknown action ID used");
                break;
        }
+       __pImpl->SendUserEvent(ID_PROMPT_POPUP_CLOSE, null);
+}
+
+bool
+_PromptPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+bool
+_PromptPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
+       {
+               HidePopup(ID_BUTTON_PROMPT_CANCEL);
+               ewk_view_javascript_prompt_reply(__pWebView, null);
+               __pImpl->SendUserEvent(ID_PROMPT_POPUP_CLOSE, null);
+       }
+
+       return false;
+}
+
+bool
+_PromptPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+bool
+_PromptPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+bool
+_PromptPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
+{
+       return false;
 }