Fixed Nabi issues N_SE-49218, N_SE-49706
[apps/osp/Internet.git] / src / IntMainForm.cpp
index d0085e0..5cc4010 100644 (file)
@@ -68,8 +68,8 @@ static const wchar_t* IDB_CONTRLBAR_ICON_NEW_WINDOW_PRESS = L"I01_icon_plus_pres
 static const wchar_t* IDB_CONTROLBAR_ICON_CREATE_DISABLE = L"I01_controlbar_icon_create_disable.png";
 static const wchar_t* IDB_BUTTON_ON = L"00_button_on.png";
 static const wchar_t* IDB_BUTTON_OFF = L"00_button_off.png";
-static const wchar_t* IDB_ICON_BOOKMARK_OFF_TEMP = L"I01_icon_bookmark_off_temp.png";
-static const wchar_t* IDB_ICON_BOOKMARK_ON_TEMP = L"I01_icon_bookmark_on_temp.png";
+static const wchar_t* IDB_ICON_BOOKMARK_OFF_TEMP =L"00_icon_favorite_off_74x74.png";
+static const wchar_t* IDB_ICON_BOOKMARK_ON_TEMP = L"00_icon_favorite_on_74x74.png";
 static const wchar_t* IDS_TIZEN_SERVICE = L"tizen-service";
 static const wchar_t* IDS_APPID = L"AppID";
 static const wchar_t* IDS_KEY = L"key";
@@ -486,10 +486,9 @@ MainForm::InitWebControl()
        else
        {
                r = AddControl(__pWebViewer);
-
                if (IsFailed(r))
                {
-                       delete __pWebViewer;
+                       __pWebViewer->Destroy();
                        __pWebViewer = null;
                        AppLogDebug("Web addcontrol failed with %s", GetErrorMessage(r));
                        return r;
@@ -753,6 +752,8 @@ MainForm::InitFooter(void)
        }
        else
                __pFooterPanel->SetShowState(false);
+
+       SetAddressbarMode(GetAddressbarMode());
        AppLogDebug("MainForm::InitFooter exit");
        return E_SUCCESS;
 }
@@ -892,6 +893,8 @@ MainForm::InitSelectTextContextMenu(Point p, bool pasteOption, bool onlyPasteOpt
                delete __pImageMenu;
                __pImageMenu = null;
        }
+//     Point q(0,0);
+//     __pWebViewer->GetBlockRange(p,q);
 
        if(p.y < 150)
        {
@@ -975,7 +978,8 @@ MainForm::InitSelectTextContextMenuF(FloatPoint p, bool pasteOption, bool onlyPa
                delete __pImageMenu;
                __pImageMenu = null;
        }
-
+//     FloatPoint q(0.0,0.0);
+//             __pWebViewer->GetBlockRange(p,q);
        if(p.y < 150)
        {
                p.y = p.y + 50;
@@ -1577,7 +1581,8 @@ MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
                                                }
                                                else
                                                {
-                                                       r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
+                                                       r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE,SCENE_HISTORY_OPTION_ADD_HISTORY,SCENE_DESTROY_OPTION_DESTROY));
+//                                                     r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
                                                        if (IsFailed(r))
                                                        {
                                                                AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
@@ -2500,6 +2505,10 @@ MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
                        String nameElement = __pHitElementResult->GetAttributeValue(L"name");
                        String tagElement  = __pHitElementResult->GetTagName();
                        AppLog("MainForm::IDA_PASTE_TEXT_CLICKED id is %ls",idElement.GetPointer());
+                       String str = L"document.getElementsByName('";
+                       str.Append(nameElement);
+                       str.Append("').length");
+                       String* pCount = __pWebViewer->EvaluateJavascriptN(str);
 
                        String script;
                        if(idElement.GetLength() != 0)
@@ -2512,9 +2521,9 @@ MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
                                script.Append(*pString);
                                script.Append("\");");
                        }
-                       else if (nameElement.GetLength() != 0)
+                       else if (nameElement.GetLength() != 0 && pCount->Equals("1",false) == true)
                        {
-                               script = L"function insertAtCursor(myField, myValue) {  if (document.selection) {   document.getElementByName(myField)[0].focus();   sel = document.selection.createRange();   sel.text = myValue;  }   else if (myField.selectionStart || myField.selectionStart == '0'){   var startPos = myField.selectionStart;   var endPos = myField.selectionEnd;   myField.value = myField.value.substring(0, startPos)+ myValue + myField.value.substring(endPos, myField.value.length);   } else {    document.getElementByName(myField)[0].value += myValue;   }  } ";
+                               script = L"function insertAtCursor(myField, myValue) {  if (document.selection) {   myField.focus();   sel = document.selection.createRange();   sel.text = myValue;  }   else if (myField.selectionStart || myField.selectionStart == '0'){   var startPos = myField.selectionStart;   var endPos = myField.selectionEnd;   myField.value = myField.value.substring(0, startPos)+ myValue + myField.value.substring(endPos, myField.value.length);   } else {    myField.value += myValue;   }  } ";
                                script.Append("insertAtCursor(document.getElementsByName('");
                                script.Append(nameElement);
                                script.Append("')[0],");
@@ -2522,7 +2531,7 @@ MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
                                script.Append(*pString);
                                script.Append("\");");
                        }
-                       else//adding for twitter post page
+                       else if(tagElement.GetLength() != 0) //adding for twitter post page
                        {
                                script = L"function insertAtCursor(myField, myValue) {  if (document.selection) {   document.getElementsByTagName(myField)[0].focus();   sel = document.selection.createRange();   sel.text = myValue;  }   else if (myField.selectionStart || myField.selectionStart == '0'){   var startPos = myField.selectionStart;   var endPos = myField.selectionEnd;   myField.value = myField.value.substring(0, startPos)+ myValue + myField.value.substring(endPos, myField.value.length);   } else {    document.getElementsByTagName(myField)[0].value += myValue;   }  } ";
                                script.Append("insertAtCursor(document.getElementsByTagName('");
@@ -2535,6 +2544,7 @@ MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
                        AppLog("MainForm::OnTouchLongPressed script is %ls",script.GetPointer());
                        String* pStr = __pWebViewer->EvaluateJavascriptN(script);
                        delete pStr;
+                       delete pCount;
                }
                delete pItem;
        }
@@ -2691,7 +2701,7 @@ MainForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
                                                return;
                                        }
                                        r = pAllWindowList->RemoveAt(count, true);
-//                                     __pWindowInfo = null;
+                                       __pWindowInfo = null;
                                        if (IsFailed(r))
                                        {
                                                AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
@@ -3605,7 +3615,8 @@ MainForm::OnBackClicked(/*const Addressbar& addBar*/)
                                }
                                else
                                {
-                                       r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
+                                       r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE,SCENE_HISTORY_OPTION_ADD_HISTORY,SCENE_DESTROY_OPTION_DESTROY));
+//                                     r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
                                        if (IsFailed(r))
                                        {
                                                AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
@@ -3728,6 +3739,10 @@ MainForm::OnAddressBarKeypadClosed(const Addressbar& addBar, bool footerState)
                __pFooterPanel->SetShowState(true);
        }
        __isKeypadOpened = false;
+       if(__pNotification && __pNotification->GetShowState())
+       {
+               __pNotification->SetPosition(0,GetClientAreaBounds().height - __pNotification->GetHeight());
+       }
 
        RelayoutControls(false,footerState);
 }
@@ -3737,6 +3752,10 @@ MainForm::OnAddressBarKeypadOpened(const Addressbar& addBar)
 {
        AppLog("XYZ::MainForm::OnAddressBarKeypadOpened");
        __isKeypadOpened = true;
+       if(__pNotification && __pNotification->GetShowState())
+       {
+               __pNotification->SetPosition(0,GetClientAreaBounds().height - __pNotification->GetHeight());
+       }
        RelayoutControls(false);
 }
 
@@ -3792,7 +3811,8 @@ MainForm::UpdateFavicon(void)
                        if (url.GetHost().GetLength() == 0)
                        {
                                Uri webUrl;
-                               webUrl.SetUri(__pWebViewer->GetUrl());
+                               if(__pWebViewer)
+                                       webUrl.SetUri(__pWebViewer->GetUrl());
                                result r = url.SetHost(webUrl.GetHost());
                                if(IsFailed(r))
                                {
@@ -3803,7 +3823,8 @@ MainForm::UpdateFavicon(void)
                        if (url.GetScheme().GetLength() == 0)
                        {
                                Uri webUrl;
-                               webUrl.SetUri(__pWebViewer->GetUrl());
+                               if(__pWebViewer)
+                                       webUrl.SetUri(__pWebViewer->GetUrl());
                                url.SetScheme(webUrl.GetScheme());
                        }
                        __pWindowInfo->faviconUrl = url.ToString();
@@ -4083,6 +4104,97 @@ MainForm::OnWebWindowCreateRequested(void)
        return pNewWindowInfo->pCurrentWeb;
 }
 
+void MainForm::OnWebWindowCloseRequested(Tizen::Web::Controls::Web& source)
+{
+       AppLog("OnWebWindowCloseRequested");
+       ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
+       SceneManager* pSceneManager = SceneManager::GetInstance();
+       WindowInfo* pWindowInfo = null;
+       WindowInfo* pNewWindowInfo = null;
+       int totalCount = 0;
+       UiApp* pApp = null;
+       result r = E_FAILURE;
+
+       if (pAllWindowList != null)
+       {
+               totalCount = pAllWindowList->GetCount();
+       }
+
+       for (int count = 0; count < totalCount; count++)
+       {
+               pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
+               if (pSceneManager != null && pWindowInfo != null && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID)
+               {
+                       r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
+                       if (IsFailed(r))
+                       {
+                               AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
+                               return;
+                       }
+
+                       r = pAllWindowList->RemoveAt(count, true);
+
+                       if(count > 0)
+                       {
+                               pNewWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
+                       }
+                       else if(pAllWindowList->GetCount() > 0)
+                       {
+                               pNewWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
+                       }
+                       else
+                       {
+                               WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN();
+
+                               if (pNewWindowInfo == null)
+                               {
+                                       return;
+                               }
+                               result r = E_SUCCESS;
+                               SceneManager* pSceneManager = SceneManager::GetInstance();
+                               if (pSceneManager == NULL)
+                               {
+                                       return;
+                               }
+                               ArrayList* pArgList = new(std::nothrow) ArrayList();
+                               if (pArgList == NULL)
+                               {
+                                       return;
+                               }
+                               r = pArgList->Construct();
+                               if (r == E_SUCCESS)
+                               {
+                                       pArgList->Add(*pNewWindowInfo);
+                                       result r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
+                                       if (pArgList != null)
+                                       {
+                                               delete pArgList;
+                                               pArgList = null;
+                                       }
+                                       if(IsFailed(r))
+                                       {
+                                               AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
+                                               return;
+                                       }
+                               }
+
+                               pApp = UiApp::GetInstance();
+                               if (pApp != null)
+                               {
+                                       r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
+                                       return;
+                               }
+
+                       }
+                       r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE,SCENE_HISTORY_OPTION_ADD_HISTORY,SCENE_DESTROY_OPTION_DESTROY));
+
+                       __pWindowInfo = null;
+                       break;
+               }
+       }
+
+}
+
 void
 MainForm::RelayoutControls(bool showAddressbar,bool relayoutFooter)
 {
@@ -4239,8 +4351,12 @@ MainForm::StartWordSearch()
 
        __pFindWordPrev->SetEnabled(false);
        String *pCountStr = null;
-       result r = __pWebViewer->SearchTextAllAsync(__currentSearchStr, false);
-       AppLog("Search Result %s",GetErrorMessage(r));
+       if (__pWebViewer)
+       {
+               result r = __pWebViewer->SearchTextAllAsync(__currentSearchStr, false);
+               AppLog("Search Result %s",GetErrorMessage(r));
+       }
+
        /*__pWebViewer->EvaluateJavascriptN(L"document.body.textContent.match(/"  + __currentSearchStr + "/gi).length;");
        if (pCountStr != null)
        {
@@ -4258,21 +4374,38 @@ void MainForm::OnTextFound(int totalCount, int currentOrdinal)
        AppLog("MainForm::OnTextFound totalCount %d",totalCount);
        AppLog("MainForm::OnTextFound currentOrdinal %d",currentOrdinal);
 
-       if(totalCount == -1 || totalCount == 0)
+       if(totalCount <= 9)
        {
-               __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
-               __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
-//             return;
+               if (__pFindWordCountLabel)
+               {
+                       __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
+               }
+               if (__pFindWordEditField)
+               {
+                       __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
+               }
        }
-       else if(totalCount > 100)
+       else if(totalCount >= 100)
        {
-               __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
-               __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
+               if (__pFindWordCountLabel)
+               {
+                       __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
+               }
+               if (__pFindWordEditField)
+               {
+                       __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
+               }
        }
        else
        {
-               __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
-               __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
+               if (__pFindWordCountLabel)
+               {
+                       __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
+               }
+               if (__pFindWordEditField)
+               {
+                       __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
+               }
        }
 
        __maxOccurrances = totalCount;
@@ -4319,16 +4452,20 @@ void MainForm::OnTextFound(int totalCount, int currentOrdinal)
        __pFindWordCountLabel->Invalidate(false);
        __pFindWordCountLabel->Invalidate(false);
        }
-       else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
+       else if (__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
        {
                __pFindWordCountLabelRightToLeft->SetText(countStr);
                __pFindWordCountLabelRightToLeft->Invalidate(false);
                __pFindWordCountLabelRightToLeft->Invalidate(false);
        }
-       //FindNextWord(true);
-       //Update the controls
-       __pFindWordNext->Invalidate(false);
-       __pFindWordPrev->Invalidate(false);
+       if (__pFindWordNext)
+       {
+               __pFindWordNext->Invalidate(false);
+       }
+       if (__pFindWordPrev)
+       {
+               __pFindWordPrev->Invalidate(false);
+       }
 
 }
 
@@ -4451,12 +4588,28 @@ MainForm::OnWebKeypadOpened(Tizen::Web::Controls::Web& source)
 void
 MainForm::OnWebKeypadClosed(Tizen::Web::Controls::Web& source)
 {
+       AppLog("abcde::MainForm::OnWebKeypadClosed");
        AppLog("xyz::MainForm::OnWebKeypadClosed");
        AppLog("akjshdasd 4");
        __pFooterPanel->SetShowState(true);
 //     OnAddressBarKeypadClosed(*__pAddressbar);
        RelayoutControls(false);
        __isKeypadOpened = false;
+
+
+       if(__pImageMenu && __pImageMenu->GetShowState() == true)
+       {
+               AppLog("abcde: imagemenu visible.");
+               Point p(0,0);
+               Point q(0,0);
+               __pWebViewer->GetBlockRange(p,q);
+               if (p == Point(0,0) && q == Point(0,0))
+                       return;
+
+               __pImageMenu->SetAnchorPosition(p);
+               __pImageMenu->Show();
+               Invalidate(true);
+       }
 }
 
 void
@@ -4493,7 +4646,7 @@ MainForm::OnTouchDoublePressed(const Control& source, const Point& currentPositi
 void MainForm::OnTouchLongPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
 {
        AppLog("abcde::MainForm::OnTouchLongPressed %d, %d" ,currentPosition.x,currentPosition.y);
-       if(TouchEventManager::GetInstance()->GetTouchInfoListN()->GetCount() >1)
+       if(TouchEventManager::GetInstance() && TouchEventManager::GetInstance()->GetTouchInfoListN() && TouchEventManager::GetInstance()->GetTouchInfoListN()->GetCount() >1)
        {
                AppLog("Returning because of more than one touch point.");
                return;