WebPageUI class refactoring. Adding states manager. 95/50495/6
authorAdam Skobodzinski <a.skobodzins@partner.samsung.com>
Thu, 29 Oct 2015 09:30:07 +0000 (10:30 +0100)
committerJanusz Majnert <j.majnert@samsung.com>
Thu, 29 Oct 2015 12:33:09 +0000 (05:33 -0700)
[Issue]    n/a
[Problem]  States of WebPageUI were indicated based on the scattered
           variables or a content of the web_view edc part.
[Solution] Introducting WebPageUIStatesManager which clearly indicates
           state of WebPageUI.
[Verify]   Functionality related to removed variables and methods,
           should not change.

Change-Id: I4722958c5507a34867aa5bced8a22fb9fda1ba1e
Signed-off-by: Adam Skobodzinski <a.skobodzins@partner.samsung.com>
services/SimpleUI/SimpleUI.cpp
services/SimpleUI/SimpleUI.h
services/WebPageUI/CMakeLists.txt
services/WebPageUI/UrlHistoryList/GenlistItemsManager.cpp
services/WebPageUI/UrlHistoryList/GenlistItemsManager.h
services/WebPageUI/WebPageUI.cpp
services/WebPageUI/WebPageUI.h
services/WebPageUI/WebPageUIStatesManager.cpp [new file with mode: 0644]
services/WebPageUI/WebPageUIStatesManager.h [new file with mode: 0644]

index 461d89a..f810ddd 100644 (file)
@@ -37,6 +37,7 @@
 #include "Tools/EflTools.h"
 #include "BrowserImage.h"
 #include "SimpleUI.h"
+#include "WebPageUIStatesManager.h"
 #include "BookmarkItem.h"
 #include "Tools/EflTools.h"
 #include "BrowserImage.h"
@@ -447,11 +448,6 @@ void SimpleUI::switchToTab(const tizen_browser::basic_webengine::TabId& tabId)
     m_zoomUI->showNavigation();
 }
 
-bool SimpleUI::isErrorPageActive()
-{
-    return m_webPageUI->isErrorPageActive();
-}
-
 void SimpleUI::showQuickAccess()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
@@ -506,7 +502,7 @@ void SimpleUI::closeTab(const tizen_browser::basic_webengine::TabId& id)
 bool SimpleUI::checkBookmark()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    if (m_webPageUI->isHomePageActive())
+    if(m_webPageUI->stateEquals(WPUState::QUICK_ACCESS))
         return false;
 
     if(m_favoriteService->bookmarkExists(m_webEngine->getURI())) {
@@ -617,7 +613,7 @@ void SimpleUI::onBackPressed()
         m_zoomUI->escapeZoom();
     } else if ((m_viewManager->topOfStack() == m_tabUI.get()) && m_tabUI->isEditMode()) {
         m_tabUI->onBackKey();
-    } else if (m_webPageUI->isHomePageActive()) {
+    } else if (m_webPageUI->stateEquals(WPUState::QUICK_ACCESS)) {
         m_quickAccess->backButtonClicked();
     } else if ((m_viewManager->topOfStack() == m_webPageUI.get()) && !m_webPageUI->getURIEntry().hasFocus() && !m_wvIMEStatus) {
         m_webEngine->backButtonClicked();
@@ -706,7 +702,7 @@ void SimpleUI::filterURL(const std::string& url)
 
     //no filtering
 
-        if (m_webPageUI->isHomePageActive())
+        if (m_webPageUI->stateEquals(WPUState::QUICK_ACCESS))
             openNewTab(url);
         else
             m_webEngine->setURI(url);
@@ -749,7 +745,7 @@ void SimpleUI::webEngineURLChanged(const std::string url)
 void SimpleUI::showZoomUI()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    if(! m_webPageUI->isHomePageActive()) {
+    if(! m_webPageUI->stateEquals(WPUState::QUICK_ACCESS)) {
         M_ASSERT(m_viewManager);
         m_viewManager->popStackTo(m_webPageUI.get());
         m_webPageUI->showTabUI.connect(boost::bind(&SimpleUI::closeZoomUI, this));
@@ -948,12 +944,12 @@ void SimpleUI::showMoreMenu()
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
     M_ASSERT(m_viewManager);
 
-    bool desktopMode = m_webPageUI->isHomePageActive() ? m_quickAccess->isDesktopMode() : m_webEngine->isDesktopMode();
+    bool desktopMode = m_webPageUI->stateEquals(WPUState::QUICK_ACCESS) ? m_quickAccess->isDesktopMode() : m_webEngine->isDesktopMode();
     m_moreMenuUI->setDesktopMode(desktopMode);
     m_viewManager->pushViewToStack(m_moreMenuUI.get());
     m_moreMenuUI->showCurrentTab();
 
-    if (!m_webPageUI->isHomePageActive()) {
+    if (!m_webPageUI->stateEquals(WPUState::QUICK_ACCESS)) {
         m_moreMenuUI->setFavIcon(m_webEngine->getFavicon());
         m_moreMenuUI->setWebTitle(m_webEngine->getTitle());
         m_moreMenuUI->setURL(m_webEngine->getURI());
@@ -976,7 +972,7 @@ void SimpleUI::closeMoreMenu()
 void SimpleUI::switchToMobileMode()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    if (!m_webPageUI->isHomePageActive()) {
+    if (!m_webPageUI->stateEquals(WPUState::QUICK_ACCESS)) {
         m_webEngine->switchToMobileMode();
         m_viewManager->popStackTo(m_webPageUI.get());
         m_webEngine->reload();
@@ -988,7 +984,7 @@ void SimpleUI::switchToMobileMode()
 void SimpleUI::switchToDesktopMode()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    if (!m_webPageUI->isHomePageActive()) {
+    if (!m_webPageUI->stateEquals(WPUState::QUICK_ACCESS)) {
         m_webEngine->switchToDesktopMode();
         m_webEngine->reload();
     } else {
@@ -1124,7 +1120,7 @@ void SimpleUI::updateView() {
     BROWSER_LOGD("[%s] Opened tabs: %d", __func__, tabs);
     if (tabs == 0) {
         switchViewToQuickAccess();
-    } else if (!m_webPageUI->isHomePageActive()) {
+    } else if (!m_webPageUI->stateEquals(WPUState::QUICK_ACCESS)) {
         switchViewToWebPage();
     }
     m_webPageUI->setTabsNumber(tabs);
index 4924296..7c15a39 100644 (file)
@@ -98,7 +98,6 @@ private:
 
     void loadError();
     void setErrorButtons();
-    bool isErrorPageActive();
 
     void bookmarkAdded();
     void bookmarkDeleted();
index 802541a..ac08dcf 100644 (file)
@@ -2,6 +2,7 @@ project(WebPageUI)
 
 set(WebPageUI_SRCS
     WebPageUI.cpp
+    WebPageUIStatesManager.cpp
     ButtonBar.cpp
     URIEntry.cpp
     UrlHistoryList/UrlHistoryList.cpp
index b868747..22609a1 100644 (file)
@@ -1,8 +1,17 @@
 /*
- * GenlistItemsManager.cpp
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  *
- *  Created on: Oct 23, 2015
- *      Author: a.skobodzins
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 #include "GenlistItemsManager.h"
index b8901d3..1029786 100644 (file)
@@ -1,8 +1,17 @@
 /*
- * GenlistItemsManager.h
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  *
- *  Created on: Oct 23, 2015
- *      Author: a.skobodzins
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 #ifndef GENLISTITEMSMANAGER_H_
index 37be2eb..a065678 100644 (file)
@@ -22,6 +22,7 @@
 #include "ServiceManager.h"
 #include "BrowserAssert.h"
 #include "UrlHistoryList/UrlHistoryList.h"
+#include "WebPageUIStatesManager.h"
 
 namespace tizen_browser {
 namespace base_ui {
@@ -37,7 +38,7 @@ WebPageUI::WebPageUI()
     , m_bookmarkManagerButton(nullptr)
     , m_URIEntry(new URIEntry())
     , m_urlHistoryList(std::make_shared<UrlHistoryList>())
-    , m_homePageActive(false)
+    , m_statesMgr(std::make_shared<WebPageUIStatesManager>(WPUState::MAIN_WEB_PAGE))
     , m_webviewLocked(false)
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
@@ -81,7 +82,7 @@ void WebPageUI::showUI()
     evas_object_show(elm_object_part_content_get(m_mainLayout, "uri_bar_buttons_left"));
     evas_object_show(elm_object_part_content_get(m_mainLayout, "uri_bar_buttons_right"));
 
-    if (m_homePageActive)
+    if(m_statesMgr->equals(WPUState::QUICK_ACCESS))
         showQuickAccess();
     else
         m_URIEntry->showPageTitle();
@@ -101,7 +102,7 @@ void WebPageUI::hideUI()
     elm_object_focus_custom_chain_unset(m_mainLayout);
     evas_object_hide(m_mainLayout);
 
-    if (m_homePageActive)
+    if(m_statesMgr->equals(WPUState::QUICK_ACCESS))
         hideQuickAccess();
 
     evas_object_hide(elm_object_part_content_get(m_mainLayout, "web_view"));
@@ -136,6 +137,16 @@ void WebPageUI::progressChanged(double progress)
     }
 }
 
+bool WebPageUI::stateEquals(WPUState state) const
+{
+    return m_statesMgr->equals(state);
+}
+
+bool WebPageUI::stateEquals(std::initializer_list<WPUState> states) const
+{
+    return m_statesMgr->equals(states);
+}
+
 void WebPageUI::loadFinished()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
@@ -152,22 +163,12 @@ void WebPageUI::loadStopped()
     m_URIEntry->showPageTitle();
 }
 
-bool WebPageUI::isErrorPageActive()
-{
-    return elm_object_part_content_get(m_mainLayout, "web_view") == m_errorLayout;
-}
-
 void WebPageUI::setPageTitle(const std::string& title)
 {
      BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
      m_URIEntry->setPageTitle(title);
 }
 
-bool WebPageUI::isIncognitoPageActive()
-{
-    return elm_object_part_content_get(m_mainLayout, "web_view") == m_privateLayout;
-}
-
 void WebPageUI::toIncognito(bool incognito)
 {
     BROWSER_LOGD("[%s:%d,%d] ", __PRETTY_FUNCTION__, __LINE__, incognito);
@@ -189,7 +190,7 @@ void WebPageUI::setMainContent(Evas_Object* content)
 void WebPageUI::switchViewToErrorPage()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    m_homePageActive = false;
+    m_statesMgr->set(WPUState::MAIN_ERROR_PAGE);
     setMainContent(m_errorLayout);
     evas_object_show(m_leftButtonBar->getContent());
     elm_object_signal_emit(m_mainLayout, "shiftright_uri", "ui");
@@ -200,8 +201,8 @@ void WebPageUI::switchViewToErrorPage()
 
 void WebPageUI::switchViewToIncognitoPage()
 {
-    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    m_homePageActive = false;
+    BROWSER_LOGD("@@ [%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    m_statesMgr->set(WPUState::MAIN_INCOGNITO_PAGE);
     setMainContent(m_privateLayout);
     evas_object_show(m_leftButtonBar->getContent());
     elm_object_signal_emit(m_mainLayout, "shiftright_uri", "ui");
@@ -215,11 +216,11 @@ void WebPageUI::switchViewToIncognitoPage()
 
 void WebPageUI::switchViewToWebPage(Evas_Object* content, const std::string uri, const std::string title)
 {
-    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    if (m_homePageActive)
+    BROWSER_LOGD("@@ [%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    if(m_statesMgr->equals(WPUState::QUICK_ACCESS))
     {
         hideQuickAccess();
-        m_homePageActive = false;
+        m_statesMgr->set(WPUState::MAIN_WEB_PAGE);
     }
     setMainContent(content);
     updateURIBar(uri);
@@ -237,7 +238,7 @@ void WebPageUI::switchViewToQuickAccess(Evas_Object* content)
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
 
-    m_homePageActive = true;
+    m_statesMgr->set(WPUState::QUICK_ACCESS);
     setMainContent(content);
     evas_object_hide(m_leftButtonBar->getContent());
     elm_object_signal_emit(m_mainLayout, "shiftback_uri", "ui");
@@ -254,7 +255,7 @@ void WebPageUI::faviconClicked(void* data, Evas_Object*, const char*, const char
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
     WebPageUI* self = reinterpret_cast<WebPageUI*>(data);
-    if (!self->isHomePageActive() && !self->isErrorPageActive()) {
+    if(!self->stateEquals({ WPUState::QUICK_ACCESS, WPUState::MAIN_ERROR_PAGE })) {
         self->getURIEntry().clearFocus();
     }
 }
@@ -287,7 +288,7 @@ void WebPageUI::lockWebview()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
     if(isWebPageUIvisible()) {
-        if(!isHomePageActive() && !isErrorPageActive()) {
+        if(m_statesMgr->equals(WPUState::MAIN_WEB_PAGE)) {
             elm_object_focus_custom_chain_unset(m_mainLayout);
             elm_object_focus_custom_chain_append(m_mainLayout, elm_object_part_content_get(m_mainLayout, "web_view"), NULL);
             m_webviewLocked = true;
@@ -299,7 +300,7 @@ void WebPageUI::onRedKeyPressed()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
     if(isWebPageUIvisible()) {
-        if(!isHomePageActive()) {
+        if(m_statesMgr->equals(WPUState::MAIN_WEB_PAGE)) {
             if(m_webviewLocked) {
                 refreshFocusChain();
                 m_URIEntry->setFocus();
@@ -503,7 +504,7 @@ void WebPageUI::refreshFocusChain()
     // set custom focus chain
     elm_object_focus_custom_chain_unset(m_mainLayout);
     elm_object_focus_custom_chain_append(m_mainLayout, m_rightButtonBar->getContent(), NULL);
-    if (!m_homePageActive) {
+    if(!m_statesMgr->equals(WPUState::QUICK_ACCESS)) {
         elm_object_focus_custom_chain_append(m_mainLayout, m_leftButtonBar->getContent(), NULL);
         elm_object_focus_custom_chain_append(m_mainLayout, m_bookmarkManagerButton, NULL);
     } else {
index 0e88f30..aa5d695 100644 (file)
 namespace tizen_browser {
 namespace base_ui {
 
+class WebPageUIStatesManager;
+enum class WPUState;
+typedef std::shared_ptr<WebPageUIStatesManager> WPUStatesManagerPtr;
+typedef std::shared_ptr<const WebPageUIStatesManager> WPUStatesManagerPtrConst;
 class UrlHistoryList;
 typedef std::shared_ptr<UrlHistoryList> UrlHistoryPtr;
 
@@ -46,9 +50,17 @@ public:
     void loadStarted();
     void progressChanged(double progress);
     void loadFinished();
-    bool isErrorPageActive();
-    bool isIncognitoPageActive();
-    bool isHomePageActive() { return m_homePageActive; }
+    WPUStatesManagerPtrConst getStatesMgr() {return m_statesMgr;}
+    /**
+     * @param state The state to compare
+     * @returns True if manager's state equals to given state
+     */
+    bool stateEquals(WPUState state) const;
+    /**
+     * @param states The states to compare
+     * @returns True if one of the given states equals to the manager's state
+     */
+    bool stateEquals(std::initializer_list<WPUState> states) const;
     bool isWebPageUIvisible() { return m_WebPageUIvisible; }
     void toIncognito(bool);
     void switchViewToErrorPage();
@@ -116,7 +128,7 @@ private:
     std::unique_ptr<ButtonBar> m_rightButtonBar;
     std::unique_ptr<URIEntry> m_URIEntry;
     UrlHistoryPtr m_urlHistoryList;
-    bool m_homePageActive;
+    WPUStatesManagerPtr m_statesMgr;
     bool m_webviewLocked;
     bool m_WebPageUIvisible;
 
diff --git a/services/WebPageUI/WebPageUIStatesManager.cpp b/services/WebPageUI/WebPageUIStatesManager.cpp
new file mode 100644 (file)
index 0000000..4c22e6f
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "WebPageUIStatesManager.h"
+#include "BrowserLogger.h"
+
+namespace tizen_browser {
+namespace base_ui {
+
+WebPageUIStatesManager::WebPageUIStatesManager(WPUState initialState) :
+        m_state(initialState)
+{
+    namesMap = {
+        { WPUState::QUICK_ACCESS, "QUICK_ACCESS" },
+        { WPUState::MAIN_WEB_PAGE, "MAIN_WEB_PAGE" },
+        { WPUState::MAIN_ERROR_PAGE, "MAIN_ERROR_PAGE" },
+        { WPUState::MAIN_INCOGNITO_PAGE, "MAIN_INCOGNITO_PAGE" }
+    };
+}
+
+void WebPageUIStatesManager::set(WPUState state) {
+    m_state = state;
+}
+
+bool WebPageUIStatesManager::equals(WPUState state) const
+{
+    return (m_state == state);
+}
+
+bool WebPageUIStatesManager::equals(std::initializer_list<WPUState> states) const
+{
+    for (auto s : states) {
+        if (equals(s))
+            return true;
+    }
+    return false;
+}
+
+std::string WebPageUIStatesManager::toString(WPUState state) const
+{
+    return namesMap.find(state)->second;
+}
+
+} /* namespace base_ui */
+} /* namespace tizen_browser */
diff --git a/services/WebPageUI/WebPageUIStatesManager.h b/services/WebPageUI/WebPageUIStatesManager.h
new file mode 100644 (file)
index 0000000..92a3446
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WEBPAGEUISTATESMANAGER_H_
+#define WEBPAGEUISTATESMANAGER_H_
+
+#include <map>
+#include <string>
+#include <initializer_list>
+
+namespace tizen_browser {
+namespace base_ui {
+
+enum class WPUState {
+    QUICK_ACCESS,
+    // displaying web page content
+    MAIN_WEB_PAGE,
+    MAIN_ERROR_PAGE,
+    // displaying incognito message page
+    MAIN_INCOGNITO_PAGE
+};
+
+class WebPageUIStatesManager
+{
+public:
+    WebPageUIStatesManager(WPUState initialState);
+    virtual ~WebPageUIStatesManager() {}
+
+    void set(WPUState state);
+
+    /**
+     * @param state The state to compare.
+     * @return True if current state equals the passed state
+     */
+    bool equals(WPUState state) const;
+
+    /**
+     * @param states The states to compare.
+     * @return True if current state is included in states to compare
+     */
+    bool equals(std::initializer_list<WPUState> states) const;
+
+private:
+    std::string toString(WPUState state) const;
+    WPUState m_state;
+    std::map<WPUState, std::string> namesMap;
+
+};
+
+} /* namespace base_ui */
+} /* namespace tizen_browser */
+
+#endif /* WEBPAGEUISTATESMANAGER_H_ */