Tizen 2.2.1
[framework/osp/web.git] / src / controls / FWebCtrl_AuthConfirmPopup.cpp
index d2ed471..eeaa139 100755 (executable)
  * @file               FWebCtrl_AuthConfirmPopup.cpp
  * @brief              The file contains the definition of _AuthConfirmPopup class.
  */
+#include <FBaseColArrayList.h>
+#include <FBaseSysLog.h>
 #include <FGrpDimension.h>
 #include <FGrpRectangle.h>
+#include <FSysVibrator.h>
 #include <FUiCtrlButton.h>
 #include <FUiCtrlEditField.h>
 #include <FUiCtrlLabel.h>
 #include <FUiCtrlPanel.h>
-#include <FUiIActionEventListener.h>
+#include <FUiKeyEventInfo.h>
 #include <FUiLayout.h>
 #include <FUiVerticalBoxLayout.h>
 #include <FWebCtrlAuthenticationChallenge.h>
-#include <FBaseSysLog.h>
-#include <FUiCtrl_PopupImpl.h>
+#include <FSys_SystemResource.h>
+#include <FSys_VibratorImpl.h>
 #include <FUi_ControlManager.h>
 #include <FUi_ResourceManager.h>
-#include <FSys_SystemResource.h>
-#include "FWebCtrl_WebImpl.h"
 #include "FWebCtrl_AuthConfirmPopup.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 AUTH_POPUP_TMP_LABLE_HEIGHT = 10;
 
 namespace Tizen { namespace Web { namespace Controls
 {
 
 
+static const int EDIT_TEXT_SIZE = 35;
+
+
 _AuthConfirmPopup::_AuthConfirmPopup(void)
-       : __pPopup(null)
-       , __pIdEditField(null)
+       : __pIdEditField(null)
        , __pPwdEditField(null)
-       , __pPanel(null)
        , __pAuthHandler(null)
-       , __modal(0)
 {
 }
 
+
 _AuthConfirmPopup::~_AuthConfirmPopup(void)
 {
+       if (IsModalPopup())
+       {
+               __pAuthHandler->Cancel();
+       }
 }
 
 
 // Authentication popup
 result
-_AuthConfirmPopup::Construct(const Tizen::Base::String& host, const Tizen::Base::String& realm, AuthenticationChallenge* pAuth)
+_AuthConfirmPopup::Construct(const String& host, const String& realm, AuthenticationChallenge* pAuth)
 {
-       SysTryReturnResult(NID_WEB_CTRL, pAuth != null, E_INVALID_ARG, "[%s] invalid argument(s) is used. The AuthenticationChallenge is null.", GetErrorMessage(E_INVALID_ARG));
+       SysTryReturnResult(NID_WEB_CTRL, pAuth != null, E_INVALID_ARG, "invalid argument(s) is used. The AuthenticationChallenge is null.");
 
        __pAuthHandler = pAuth;
 
-       VerticalBoxLayout layout;
-       result r = layout.Construct(VERTICAL_DIRECTION_DOWNWARD);
-       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");
+
+       result r = E_SUCCESS;
+       _WebPopupData* pPopupData = _WebPopup::GetPopupData();
+       SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
 
-       Dimension dim;
-       Dimension editDim;
        Rectangle rect(0, 0, 0, 0);
+       rect.width = pPopupData->popupDim.width;
+       rect.height = (2*pPopupData->spacePad) + (pPopupData->editDim.height*2) + pPopupData->panelHeight + (2*pPopupData->labelDim.height);
+       r = _WebPopup::Construct(true, Dimension(rect.width, rect.height));
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_HEADER_ENTER_CREDENTIALS_ABB"));
 
-       int spacePad = 0;
-       int buttonHeight = 0;
-       int sideMargin = 0;
-       int buttonWidth = 0;
+       //host realm label
+       rect.height = 2*pPopupData->labelDim.height;
 
-       _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
+       std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
+       SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
 
-       GET_SHAPE_CONFIG(MESSAGEBOX::DEFAULT_WIDTH, orientation, rect.width);
-       GET_SHAPE_CONFIG(MESSAGEBOX::MIN_HEIGHT, orientation, rect.height);
-       GET_SHAPE_CONFIG(POPUP::SIDE_BORDER, orientation, sideMargin);
-       GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_SIDE_MARGIN_02, orientation, spacePad);
-       GET_DIMENSION_CONFIG(EDIT::MIN_SIZE, orientation, editDim);
-       GET_SHAPE_CONFIG(MESSAGEBOX::BUTTON_HEIGHT, orientation, buttonHeight);
+       String hostRealm(host);
+       hostRealm.Append(L": \n ");
+       hostRealm.Append(realm);
+       r = pLabel->Construct(rect, hostRealm);
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       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));
+       pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
 
-       rect.height = ((5*spacePad) + (editDim.height*2) + buttonHeight);
-       r = pPopup->Construct(layout,layout, true, Tizen::Graphics::Dimension(rect.width, rect.height));
+       r = AddControl(*pLabel);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       pPopup->SetTitleText("Authentication Dialog");
+       Label* pHostLabel = pLabel.release();
 
        // Id Edit Field
        rect.x = 0;
        rect.y = 0;
-       rect.height = editDim.height;
+       rect.height = pPopupData->editDim.height;
+       rect.width = pPopupData->labelDim.width;
 
        std::unique_ptr<EditField> pIdEditField(new (std::nothrow) EditField());
-       SysTryReturnResult(NID_WEB_CTRL, pIdEditField.get(), r = E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.",GetErrorMessage(E_OUT_OF_MEMORY));
+       SysTryReturnResult(NID_WEB_CTRL, pIdEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
 
        r = pIdEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       pIdEditField->SetGuideText(L"id");
-       pIdEditField->SetGuideTextColor(Color(95, 95, 95));
+       pIdEditField->SetGuideText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_WIFI_BODY_ENTER_YOUR_ID"));
+       pIdEditField->SetGuideTextColor(Color::GetColor(COLOR_ID_GREY));
+       pIdEditField->SetTextSize(EDIT_TEXT_SIZE);;
 
-       r = pPopup->AddControl(*pIdEditField);
+       r = AddControl(*pIdEditField);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        __pIdEditField = pIdEditField.release();
 
-       // Pwd Edit Field
-       rect.y = spacePad + editDim.height;
-
        std::unique_ptr<EditField> pPwdEditField(new (std::nothrow) EditField());
-       SysTryReturnResult(NID_WEB_CTRL, pPwdEditField.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.",GetErrorMessage(E_OUT_OF_MEMORY));
+       SysTryReturnResult(NID_WEB_CTRL, pPwdEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
 
        r = pPwdEditField->Construct(rect, EDIT_FIELD_STYLE_PASSWORD);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       pPwdEditField->SetGuideText(L"Password");
-       pPwdEditField->SetGuideTextColor(Color(95, 95, 95));
+       pPwdEditField->SetGuideText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BODY_ENTER_YOUR_PASSWORD_ABB"));
+       pPwdEditField->SetGuideTextColor(Color::GetColor(COLOR_ID_GREY));
+       pPwdEditField->SetTextSize(EDIT_TEXT_SIZE);;
 
-       r = pPopup->AddControl(*pPwdEditField);
+       r = AddControl(*pPwdEditField);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        __pPwdEditField = pPwdEditField.release();
        __pIdEditField->SetFocus();
-       __pPopup = std::move(pPopup);
-
-       r = AddButtons(spacePad, sideMargin, buttonHeight, rect);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(__pPopup->GetLayoutN()));
-       SysTryReturn(NID_WEB_CTRL, pLayout.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
-       pLayout->SetHorizontalFitPolicy(*__pIdEditField, FIT_POLICY_PARENT);
-       pLayout->SetHorizontalFitPolicy(*__pPwdEditField, FIT_POLICY_PARENT);
-       pLayout->SetHorizontalFitPolicy(*__pPanel, FIT_POLICY_PARENT);
-
-       pLayout->SetHorizontalAlignment(*__pIdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
-       pLayout->SetHorizontalAlignment(*__pPwdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
-       pLayout->SetHorizontalAlignment(*__pPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
-
-       pLayout->SetHorizontalAlignment(*__pIdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
-       pLayout->SetHorizontalAlignment(*__pPwdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
-       pLayout->SetHorizontalAlignment(*__pPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
-
-       pLayout->SetSpacing(*__pPwdEditField, spacePad);
-       pLayout->SetSpacing(*__pPanel, spacePad);
-
-       return E_SUCCESS;
-}
-
-
-result
-_AuthConfirmPopup::AddButtons(int spacePad, int sideMargin, int buttonHeight, Rectangle& rect)
-{
-       result r = E_SUCCESS;
-       int buttonWidth = 0;
-       String buttonStr;
-       Dimension editDim;
-
-       _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();//_CONTROL_ORIENTATION_PORTRAIT;
-       GET_DIMENSION_CONFIG(EDIT::MIN_SIZE, orientation, editDim);
-
-       //Button Left
-       buttonWidth = (rect.width / 2) - (spacePad) - (sideMargin * 2);
-
-       Tizen::System::_SystemResource* pSysResource = Tizen::System::_SystemResource::GetInstance();
-       SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
-
-       buttonStr = pSysResource->GetString("sys_string", "IDS_COM_SK_OK");
-
-       std::unique_ptr<Panel> pPanel(new (std::nothrow) 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, 2 * (spacePad + editDim.height), rect.width, buttonHeight + spacePad));
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       Panel* pButtonPanel = CreateAndAddPanel();
+       SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
 
-       r = __pPopup->AddControl(*pPanel);
+       //Add Buttons
+       ArrayList idList;
+       r = idList.Construct();
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       idList.Add(*(new Integer(ID_BUTTON_AUTH_CANCEL)));
+       idList.Add(*(new Integer(ID_BUTTON_AUTH_PROCESS)));
 
-       __pPanel = pPanel.release();
-
-       std::unique_ptr<Button> pBtnSelection(new (std::nothrow) Button());
-       SysTryReturnResult(NID_WEB_CTRL, pBtnSelection.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.",GetErrorMessage(E_OUT_OF_MEMORY));
-
-       r = pBtnSelection->Construct(Rectangle(sideMargin, 0, 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_CONTINUE_ABB"))));
 
-       pBtnSelection->SetActionId(ID_BUTTON_AUTH_PROCESS);
-
-       r = __pPanel->AddControl(*pBtnSelection);
+       r = CreateAndAddButtons(idList, titleList, pButtonPanel);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       pBtnSelection->AddActionEventListener(*this);
-       pBtnSelection.release();
-
-       // Button Right
-       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, 0, buttonWidth, buttonHeight), buttonStr);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
+       SysTryReturn(NID_WEB_CTRL, pLayout.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       pBtnCancel->SetActionId(ID_BUTTON_AUTH_CANCEL);
+       pLayout->SetHorizontalAlignment(*pHostLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
+       pLayout->SetHorizontalAlignment(*__pIdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
+       pLayout->SetHorizontalAlignment(*__pPwdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
 
-       r = __pPanel->AddControl(*pBtnCancel);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       pLayout->SetSpacing(*__pPwdEditField, pPopupData->spacePad);
+       pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
 
-       pBtnCancel->AddActionEventListener(*this);      
-       pBtnCancel.release();
+       SetPropagatedKeyEventListener(this);
 
        return E_SUCCESS;
 }
 
 
 void
-_AuthConfirmPopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
+_AuthConfirmPopup::OnActionPerformed(const Control& source, int actionId)
 {
        result r = E_SUCCESS;
 
+       r = HidePopup();
+       SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+
        switch (actionId)
        {
        case ID_BUTTON_AUTH_PROCESS:
@@ -250,42 +207,47 @@ _AuthConfirmPopup::OnActionPerformed(const Tizen::Ui::Control& source, int actio
        default:
                break;
        }
-
-       r = HidePopup();
-       SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
 }
 
+bool
+_AuthConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
 
-result
-_AuthConfirmPopup::ShowPopup(void)
+bool
+_AuthConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
 {
        result r = E_SUCCESS;
+       if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
+       {
+               __pAuthHandler->Cancel();
+               r = HidePopup();
+               if (IsFailed(r))
+               {
+                       SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
+               }
+       }
 
-       r = __pPopup->SetShowState(true);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       r = __pPopup->Show();
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       r = __pPopup->DoModal(__modal);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
-       return E_SUCCESS;
+       return false;
 }
 
-
-result
-_AuthConfirmPopup::HidePopup(void)
+bool
+_AuthConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
 {
-       result r = E_SUCCESS;
-
-       r = __pPopup->SetShowState(false);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       return false;
+}
 
-       r = __pPopup->EndModal(__modal);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+bool
+_AuthConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
 
-       return E_SUCCESS;
+bool
+_AuthConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
+{
+       return false;
 }