Tizen 2.2.1
[framework/osp/web.git] / src / controls / FWebCtrl_PromptPopup.cpp
index 7920137..9a6ab1a 100755 (executable)
  * @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 <FGrpDimension.h>
 #include <FGrpRectangle.h>
 #include <FUiCtrlButton.h>
 #include <FUiCtrlEditField.h>
 #include <FUiCtrlLabel.h>
 #include <FUiCtrlPanel.h>
+#include <FUiCtrlTextBox.h>
+#include <FUiKeyEventInfo.h>
 #include <FUiLayout.h>
 #include <FUiVerticalBoxLayout.h>
 #include <FWebCtrlAuthenticationChallenge.h>
-#include <FBaseSysLog.h>
-#include <FUiCtrl_PopupImpl.h>
+#include <FBase_StringConverter.h>
+#include <FSys_SystemResource.h>
 #include <FUi_ControlManager.h>
 #include <FUi_ResourceManager.h>
-#include <FGrpColor.h>
-#include <FUiCtrlTextBox.h>
 #include <FUiCtrl_TextBoxImpl.h>
-#include <FSys_SystemResource.h>
-#include "FWebCtrl_WebImpl.h"
 #include "FWebCtrl_PromptPopup.h"
+#include "FWebCtrl_WebImpl.h"
+
 
 using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
 using namespace Tizen::Graphics;
-using namespace Tizen::Web::Controls;
-using namespace Tizen::Ui::Controls;
+using namespace Tizen::System;
 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)
-       : __pPopup(null)
-       , __pEditField(null)
+       : __pEditField(null)
+       , __pWebView(null)
+       , __pImpl(null)
 {
 }
 
+
 _PromptPopup::~_PromptPopup(void)
 {
 }
@@ -64,172 +73,103 @@ _PromptPopup::~_PromptPopup(void)
 
 // Prompt popup
 result
-_PromptPopup::Construct(const Tizen::Base::String& message, const Tizen::Base::String& defaultVale)
+_PromptPopup::Construct(const String& message, const String& defaultVale,  Evas_Object* pView, _WebImpl* pImpl)
 {
        result r = E_SUCCESS;
-       String buttonStr;
-       Dimension dim;
-       Dimension editDim;
        Rectangle rect(0, 0, 0, 0);
 
-       int spacePad = 0;
-       int buttonHeight = 0;
-       int sideMargin = 0;
-       int buttonWidth = 0;
-       int popupWidth = 0;
        int popupHeight = 0;
-       int gapForControls = 0;
 
-       _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
+       __pImpl = pImpl;
+       __pWebView = pView;
 
-       GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, popupWidth);
-       GET_SHAPE_CONFIG(MESSAGEBOX::MAX_HEIGHT, orientation, popupHeight);
-       GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, buttonHeight);
-       GET_SHAPE_CONFIG(POPUP::SIDE_BORDER, orientation, sideMargin);
-       GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_02, orientation, spacePad);
-       r = GET_DIMENSION_CONFIG(EDIT::MIN_SIZE, orientation, editDim);
-       GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_TOP_MARGIN, orientation, gapForControls);
+       _WebPopupData* pPopupData = _WebPopup::GetPopupData();
+       SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
 
-       VerticalBoxLayout layout;
-       r = layout.Construct(VERTICAL_DIRECTION_DOWNWARD);
-
-       Tizen::System::_SystemResource* pSysResource = Tizen::System::_SystemResource::GetInstance();
-       SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
+       popupHeight = pPopupData->editDim.height + pPopupData->labelDim.height + pPopupData->panelHeight + (2 * pPopupData->spacePad);
 
-       std::unique_ptr<Popup> pPopup(new (std::nothrow) Popup());
-       SysTryReturnResult(NID_WEB_CTRL, pPopup.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-       popupHeight = LABEL_HEIGHT + (2 * editDim.height + gapForControls)  + buttonHeight + (4 * spacePad) ;
-
-       r = pPopup->Construct(layout, layout, true, Tizen::Graphics::Dimension(popupWidth, popupHeight));
+       r = _WebPopup::Construct(true, Dimension(pPopupData->popupDim.width, popupHeight));
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       pPopup->SetTitleText("Prompt Dialog");
-
-       //Temp Label for Y position adjustment using Vertical layout.
-       rect.x = 0;
-       rect.y = 0;
-       rect.height = LABEL_HEIGHT;
-       rect.width = popupWidth - 2*sideMargin;;
-
-       std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
-       SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-       r = pLabel->Construct(rect, L"");
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       r = pPopup->AddControl(*pLabel);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       Label* pTmpLabel = pLabel.release();
+       SetTitleText("Prompt Dialog");
 
        //Text box
-       rect = pPopup->GetClientAreaBounds();
-       rect.width = popupWidth - 2*sideMargin;
+       rect = GetClientAreaBounds();
+       rect.width = pPopupData->labelDim.width;
        rect.y = 0;
-       rect.height = editDim.height;
-       
+       rect.height = pPopupData->labelDim.height;
+
        std::unique_ptr<TextBox> pTextBox(new (std::nothrow) TextBox());
-       SysTryReturnResult(NID_WEB_CTRL, pTextBox.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       SysTryReturnResult(NID_WEB_CTRL, pTextBox.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
 
        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, pPopup->GetColor());
-       pTextBox->SetColor(TEXT_BOX_STATUS_HIGHLIGHTED, pPopup->GetColor());
+       pTextBox->SetColor(TEXT_BOX_STATUS_NORMAL, GetColor());
+       pTextBox->SetColor(TEXT_BOX_STATUS_HIGHLIGHTED, GetColor());
 
-       r = pPopup->AddControl(*pTextBox);
+       r = AddControl(*pTextBox);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        TextBox* pTmpTextBox = pTextBox.release();
 
-
        //Edit Field
        rect.y = 0;
-       rect.height = editDim.height;
+       rect.height = pPopupData->editDim.height;
 
        std::unique_ptr<EditField> pEditField(new (std::nothrow) EditField());
-       SysTryReturnResult(NID_WEB_CTRL, pEditField.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       SysTryReturnResult(NID_WEB_CTRL, pEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
 
        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 = pPopup->AddControl(*pEditField);
+       r = AddControl(*pEditField);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        __pEditField = pEditField.release();
+       __pEditField->SetFocus();
 
        //Panel
-       buttonWidth = (popupWidth / 2) - (spacePad) - (sideMargin * 2);
+       Panel* pButtonPanel = CreateAndAddPanel();
+       SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
 
-       std::unique_ptr<Panel> pPanel(new Panel());
-       SysTryReturnResult(NID_WEB_CTRL, pPanel.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-       r = pPanel->Construct(Rectangle(0, 0, rect.width, buttonHeight + gapForControls));
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       _SystemResource* pSysResource = _SystemResource::GetInstance();
+       SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
 
-       r = pPopup->AddControl(*pPanel);
+       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_CANCEL)));
+       idList.Add(*(new Integer(ID_BUTTON_PROMPT_OK)));
 
-       Panel* pTempPanel = pPanel.release();
-
-       //Button OK
-       buttonStr = pSysResource->GetString("sys_string", "IDS_COM_SK_OK");
-       std::unique_ptr<Button> pBtnOk(new (std::nothrow) Button());
-       SysTryReturnResult(NID_WEB_CTRL, pBtnOk.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-       r = pBtnOk->Construct(Rectangle(sideMargin, gapForControls, buttonWidth, buttonHeight), buttonStr);
+       ArrayList titleList;
+       r = titleList.Construct();
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       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"))));
 
-       pBtnOk->SetActionId(ID_BUTTON_PROMPT_OK);
-
-       r = pTempPanel->AddControl(*pBtnOk);
+       r = CreateAndAddButtons(idList, titleList, pButtonPanel);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       pBtnOk->AddActionEventListener(*this);
-       pBtnOk.release();
-
-       // Button Cancel
-       buttonStr = pSysResource->GetString("sys_string", "IDS_COM_POP_CANCEL");
-       std::unique_ptr<Button> pBtnCancel(new (std::nothrow) Button());
-       SysTryReturnResult(NID_WEB_CTRL, pBtnCancel.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-       r = pBtnCancel->Construct(Rectangle(buttonWidth + spacePad + sideMargin, gapForControls, buttonWidth, buttonHeight), buttonStr);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       pBtnCancel->SetActionId(ID_BUTTON_PROMPT_CANCEL);
-
-       r = pTempPanel->AddControl(*pBtnCancel);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       pBtnCancel->AddActionEventListener(*this);
-       pBtnCancel.release();
-
-       __pEditField->SetFocus();
-
-       std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(pPopup->GetLayoutN()));
+       std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
        SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       pLayout->SetHorizontalFitPolicy(*pTmpLabel, FIT_POLICY_PARENT);
-       pLayout->SetHorizontalFitPolicy(*pTempPanel, FIT_POLICY_PARENT);
-       pLayout->SetHorizontalFitPolicy(*__pEditField, FIT_POLICY_PARENT);
-
-       pLayout->SetHorizontalAlignment(*pTmpTextBox, LAYOUT_HORIZONTAL_ALIGN_LEFT);
-       pLayout->SetHorizontalAlignment(*__pEditField, LAYOUT_HORIZONTAL_ALIGN_LEFT);
-       pLayout->SetHorizontalAlignment(*pTempPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
+       pLayout->SetHorizontalAlignment(*pTmpTextBox, LAYOUT_HORIZONTAL_ALIGN_CENTER);
+       pLayout->SetHorizontalAlignment(*__pEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
 
-       pLayout->SetSpacing(*pTmpTextBox, gapForControls);
-       pLayout->SetSpacing(*__pEditField, gapForControls);
-       pLayout->SetSpacing(*pTempPanel, gapForControls);
-
-       __pPopup = std::move(pPopup);
+       pLayout->SetSpacing(*__pEditField, pPopupData->spacePad);
+       pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
 
+       SetPropagatedKeyEventListener(this);
+       
        return r;
 }
 
+
 const String
 _PromptPopup::GetPromptText()
 {
@@ -238,38 +178,65 @@ _PromptPopup::GetPromptText()
 
 
 void
-_PromptPopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
+_PromptPopup::OnActionPerformed(const Control& source, int actionId)
 {
        switch (actionId)
        {
        case ID_BUTTON_PROMPT_OK:
        {
-               __pPopup->SetShowState(false);
-               EndModal(ID_BUTTON_PROMPT_OK);
+               HidePopup(ID_BUTTON_PROMPT_OK);
+               std::unique_ptr<char[]> pResult(_StringConverter::CopyToCharArrayN(GetPromptText()));
+               ewk_view_javascript_prompt_reply(__pWebView, pResult.get());
+               break;
        }
-       break;
-
        case ID_BUTTON_PROMPT_CANCEL:
-               __pPopup->SetShowState(false);
-               EndModal(ID_BUTTON_PROMPT_CANCEL);
+               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);
 }
 
-result
-_PromptPopup::ShowAndWait(int& modalResult)
+bool
+_PromptPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
 {
-       return __pPopup->DoModal(modalResult);
+       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);
+       }
 
-result
-_PromptPopup::EndModal(int modalResult)
+       return false;
+}
+
+bool
+_PromptPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+bool
+_PromptPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
 {
-       return __pPopup->EndModal(modalResult);
+       return false;
 }
 
+bool
+_PromptPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+
 }}} // Tizen::Web::Controls