Change for alert popup with scrollable label
authorBINDUCHAITANYA TUMMALA <bc.tummala@samsung.com>
Thu, 29 Aug 2013 11:28:26 +0000 (16:58 +0530)
committerBINDUCHAITANYA TUMMALA <bc.tummala@samsung.com>
Fri, 30 Aug 2013 05:53:07 +0000 (11:23 +0530)
Change-Id: I87c956d39b55d5141d226c993c04008dea83693c
Signed-off-by: BINDUCHAITANYA TUMMALA <bc.tummala@samsung.com>
src/controls/FWebCtrl_UserConfirmPopup.cpp

index 524926c..ef242a3 100755 (executable)
@@ -25,6 +25,7 @@
 #include <FBaseSysLog.h>
 #include <FBaseUtilUri.h>
 #include <FGrpDimension.h>
+#include <FGrpFont.h>
 #include <FGrpRectangle.h>
 #include <FIoDbEnumerator.h>
 #include <FIoDbStatement.h>
 #include <FUiCtrlButton.h>
 #include <FUiCtrlLabel.h>
 #include <FUiCtrlPanel.h>
+#include <FUiCtrlScrollPanel.h>
 #include <FUiKeyEventInfo.h>
 #include <FUiLayout.h>
 #include <FUiVerticalBoxLayout.h>
+#include <FGrp_TextTextObject.h>
+#include <FGrp_TextTextSimple.h>
 #include <FIo_DatabaseImpl.h>
 #include <FSys_SystemResource.h>
 #include <FUi_ControlManager.h>
@@ -49,6 +53,7 @@ using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::Base::Utility;
 using namespace Tizen::Graphics;
+using namespace Tizen::Graphics::_Text;
 using namespace Tizen::Io;
 using namespace Tizen::Security::Cert;
 using namespace Tizen::System;
@@ -60,6 +65,9 @@ namespace Tizen { namespace Web { namespace Controls
 {
 
 
+static const int TEXT_SIZE_ADJUST = 1;
+
+
 _UserConfirmPopup::_UserConfirmPopup(void)
        : __pUserPolicyData(null)
        , __userConfirmMode(USER_CONFIRM_USERMEDIA)
@@ -126,15 +134,6 @@ _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo,
                SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_HEADER_SECURITY_WARNING_ABB"));
        }
 
-       Rectangle rect(0, 0, 0, 0);
-
-       //label
-       rect.height = 2*pPopupData->labelDim.height;
-       rect.width = pPopupData->labelDim.width;
-
-       std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
-       SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
-
        String message = L"";
        if (userConfirmMode >= USER_SCRIPT_ALERT && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED)
        {
@@ -144,15 +143,89 @@ _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo,
        {
                message = GetMessageFromPolicy();
        }
+
+       Rectangle rect(0, 0, 0, 0);
+
+       //label
+       rect.height = 2*pPopupData->labelDim.height;
+       rect.width = pPopupData->labelDim.width;
+
+       //With the font of label and width of label, required height is calculated
+       //      using textobject. TEXT_SIZE_ADJUST is used to increase font size and get bigger height
+       //      as the accurate height is not fitting text in some cases.
+       Font font;
+       r = font.Construct(FONT_STYLE_PLAIN, pPopupData->labelFontSize + TEXT_SIZE_ADJUST);
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       std::unique_ptr<TextObject> pTextObject(new (std::nothrow) TextObject());
+       SysTryReturnResult(NID_WEB_CTRL, pTextObject.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
+
+       r = pTextObject->Construct();
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       std::unique_ptr<TextSimple> pSimpleText(new (std::nothrow) TextSimple(message.GetPointer(), message.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, &font));
+       SysTryReturnResult(NID_WEB_CTRL, pSimpleText.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
+
+       r = pTextObject->AppendElement(*pSimpleText);
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       pSimpleText.release();
+
+       r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       r = pTextObject->SetBounds(rect);
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       r = pTextObject->SetFont(&font, 0, message.GetLength());
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       r = pTextObject->Compose();
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       int labelHeight = pTextObject->GetTotalHeight();
+
+       std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
+       SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
+
        r = pLabel->Construct(rect, message);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
 
-       r = AddControl(*pLabel);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       Control* pInfoLabel = null;
+
+       if (rect.height < labelHeight)
+       {
+               //message text is bigger than label, scroll is created to accomodate it.
+               std::unique_ptr<ScrollPanel> pScrollPanel(new (std::nothrow) ScrollPanel());
+               SysTryReturnResult(NID_WEB_CTRL, pScrollPanel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
+
+               r = pScrollPanel->Construct(rect);
+               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               r = AddControl(*pScrollPanel);
+               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               ScrollPanel* pSPanel = pScrollPanel.release();
+
+               r = pLabel->SetSize(Dimension(rect.width, labelHeight));
+               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               r = pSPanel->AddControl(*pLabel);
+               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               pLabel.release();
+               pInfoLabel = pSPanel;
+       }
+       else
+       {
+               r = AddControl(*pLabel);
+               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+               pInfoLabel = pLabel.release();
+       }
 
-       Label* pInfoLabel = pLabel.release();
        //checkbutton
        if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
        {
@@ -208,7 +281,11 @@ _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo,
        }
        pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
 
-       if ( __userConfirmMode != USER_SCRIPT_ALERT )
+       if ( __userConfirmMode == USER_SCRIPT_ALERT )
+       {
+               pLayout->SetSpacing(*pButtonPanel, pPopupData->sideMargin);
+       }
+       else
        {
                pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
        }