2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Elementary.h>
19 #include <boost/format.hpp>
20 #include "WebPageUI.h"
21 #include "BrowserLogger.h"
22 #include "ServiceManager.h"
23 #include "BrowserAssert.h"
25 namespace tizen_browser {
28 EXPORT_SERVICE(WebPageUI, "org.tizen.browser.webpageui")
30 WebPageUI::WebPageUI()
32 , m_mainLayout(nullptr)
33 , m_errorLayout(nullptr)
34 , m_progressBar(nullptr)
35 , m_URIEntry(new URIEntry())
36 , m_homePageActive(false)
38 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
41 WebPageUI::~WebPageUI()
43 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
46 void WebPageUI::init(Evas_Object* parent)
48 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
53 Evas_Object* WebPageUI::getContent()
55 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
63 void WebPageUI::showUI()
65 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
68 void WebPageUI::hideUI()
70 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
71 elm_object_focus_custom_chain_unset(m_mainLayout);
74 void WebPageUI::loadStarted()
76 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
78 elm_object_signal_emit(m_URIEntry->getContent(), "shiftright_uribg", "ui");
79 elm_object_signal_emit(m_mainLayout, "shiftright_uri", "ui");
80 m_leftButtonBar->setActionForButton("refresh_stop_button", m_stopLoading);
83 void WebPageUI::progressChanged(double progress)
85 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
86 if (progress == 1.0) {
89 elm_progressbar_value_set(m_progressBar, progress);
93 void WebPageUI::loadFinished()
95 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
96 elm_object_signal_emit(m_mainLayout, "hide_progressbar_bg", "ui");
97 m_leftButtonBar->setActionForButton("refresh_stop_button", m_reload);
100 bool WebPageUI::isErrorPageActive()
102 return elm_object_part_content_get(m_mainLayout, "web_view") == m_errorLayout;
105 void WebPageUI::setMainContent(Evas_Object* content)
107 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
110 elm_object_part_content_set(m_mainLayout, "web_view", content);
111 evas_object_show(content);
113 // set custom focus chain
114 elm_object_focus_custom_chain_unset(m_mainLayout);
115 elm_object_focus_custom_chain_append(m_mainLayout, m_rightButtonBar->getContent(), NULL);
116 if (!isHomePageActive())
117 elm_object_focus_custom_chain_append(m_mainLayout, m_leftButtonBar->getContent(), NULL);
118 elm_object_focus_custom_chain_append(m_mainLayout, m_URIEntry->getContent(), NULL);
121 void WebPageUI::switchViewToErrorPage()
123 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
124 m_homePageActive = false;
125 setMainContent(m_errorLayout);
126 evas_object_show(m_leftButtonBar->getContent());
130 void WebPageUI::switchViewToWebPage(Evas_Object* content, const std::string uri)
132 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
133 m_homePageActive = false;
134 setMainContent(content);
135 evas_object_show(m_leftButtonBar->getContent());
137 elm_object_focus_custom_chain_append(m_mainLayout, content, NULL);
140 void WebPageUI::switchViewToQuickAccess(Evas_Object* content)
142 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
143 m_homePageActive = true;
144 setMainContent(content);
146 m_URIEntry->changeUri("");
147 m_leftButtonBar->setActionForButton("refresh_stop_button", m_reload);
148 evas_object_hide(m_leftButtonBar->getContent());
149 elm_object_signal_emit(m_mainLayout, "shiftback_uri", "ui");
150 elm_object_signal_emit(m_URIEntry->getContent(), "shiftback_uribg", "ui");
154 void WebPageUI::faviconClicked(void* data, Evas_Object*, const char*, const char*)
156 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
157 WebPageUI* self = reinterpret_cast<WebPageUI*>(data);
158 if (!self->isHomePageActive() && !self->isErrorPageActive()) {
159 self->getURIEntry().clearFocus();
163 void WebPageUI::setTabsNumber(int tabs)
165 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
167 elm_object_part_text_set(m_rightButtonBar->getContent(), "tabs_number", "");
169 elm_object_part_text_set(m_rightButtonBar->getContent(), "tabs_number", (boost::format("%1%") % tabs).str().c_str());
173 void WebPageUI::createLayout()
175 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
178 m_mainLayout = elm_layout_add(m_parent);
179 evas_object_size_hint_weight_set(m_mainLayout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
180 elm_layout_file_set(m_mainLayout, edjePath("WebPageUI/WebPageUI.edj").c_str(), "main_layout");
186 m_leftButtonBar = std::unique_ptr<ButtonBar>(new ButtonBar(m_mainLayout, "WebPageUI/LeftButtonBar.edj", "left_button_bar"));
187 m_leftButtonBar->addAction(m_back, "prev_button");
188 m_leftButtonBar->addAction(m_forward, "next_button");
189 m_leftButtonBar->addAction(m_reload, "refresh_stop_button");
191 //register action that will be used later by buttons"
192 m_leftButtonBar->registerEnabledChangedCallback(m_stopLoading, "refresh_stop_button");
195 m_rightButtonBar = std::unique_ptr<ButtonBar>(new ButtonBar(m_mainLayout, "WebPageUI/RightButtonBar.edj", "right_button_bar"));
196 m_rightButtonBar->addAction(m_tab, "tab_button");
197 m_rightButtonBar->addAction(m_showMoreMenu, "setting_button");
200 m_progressBar = elm_progressbar_add(m_mainLayout);
201 elm_object_style_set(m_progressBar, "play_buffer");
203 //URL bar (Evas Object is shipped by URIEntry object)
204 m_URIEntry->init(m_mainLayout);
205 elm_object_part_content_set(m_mainLayout, "uri_entry", m_URIEntry->getContent());
206 elm_object_part_content_set(m_mainLayout, "uri_bar_buttons_left", m_leftButtonBar->getContent());
207 elm_object_part_content_set(m_mainLayout, "uri_bar_buttons_right", m_rightButtonBar->getContent());
209 elm_layout_signal_callback_add(m_URIEntry->getContent(), "slide_websearch", "elm", faviconClicked, this);
214 void WebPageUI::createErrorLayout()
216 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
217 m_errorLayout = elm_layout_add(m_mainLayout);
218 evas_object_size_hint_weight_set(m_errorLayout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
219 evas_object_size_hint_align_set(m_errorLayout, EVAS_HINT_FILL, EVAS_HINT_FILL);
220 elm_layout_file_set(m_errorLayout, edjePath("WebPageUI/ErrorMessage.edj").c_str(), "error_message");
223 void WebPageUI::createActions()
225 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
226 m_back = sharedAction(new Action("Back"));
227 m_back->setToolTip("Previous");
228 m_back->setIcon("browser/toolbar_prev");
230 m_forward = sharedAction(new Action("Next"));
231 m_forward->setToolTip("Next");
232 m_forward->setIcon("browser/toolbar_next");
234 m_stopLoading = sharedAction(new Action("Stop"));
235 m_stopLoading->setToolTip("Stop");
236 m_stopLoading->setIcon("browser/toolbar_stop");
238 m_reload = sharedAction(new Action("Reload"));
239 m_reload->setToolTip("Reload");
240 m_reload->setIcon("browser/toolbar_reload");
241 m_tab = sharedAction(new Action("Tabs"));
242 m_tab->setToolTip("Tab page");
243 m_tab->setIcon("browser/toolbar_tab");
245 m_showMoreMenu = sharedAction(new Action("Settings"));
246 m_showMoreMenu->setToolTip("Settings");
247 m_showMoreMenu->setIcon("browser/toolbar_setting");
250 void WebPageUI::connectActions()
252 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
254 m_back->triggered.connect(boost::bind(&WebPageUI::backPageConnect, this));
255 m_forward->triggered.connect(boost::bind(&WebPageUI::forwardPageConnect, this));
256 m_stopLoading->triggered.connect(boost::bind(&WebPageUI::stopLoadingPageConnect, this));
257 m_reload->triggered.connect(boost::bind(&WebPageUI::reloadPageConnect, this));
260 m_tab->triggered.connect(boost::bind(&WebPageUI::showTabUIConnect, this));
261 m_showMoreMenu->triggered.connect(boost::bind(&WebPageUI::showMoreMenuConnect, this));
264 void WebPageUI::showProgressBar()
266 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
267 elm_object_signal_emit(m_mainLayout, "show_progressbar_bg", "ui");
268 elm_object_part_content_set(m_mainLayout, "progress_bar", m_progressBar);
271 void WebPageUI::hideProgressBar()
273 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
274 elm_object_signal_emit(m_mainLayout, "hide_progressbar_bg", "ui");
275 elm_progressbar_value_set(m_progressBar, 0.0);
276 elm_object_part_content_unset(m_mainLayout, "progress_bar");
277 evas_object_hide(m_progressBar);
280 void WebPageUI::hideWebView()
282 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
283 evas_object_hide(elm_object_part_content_get(m_mainLayout, "web_view"));
284 elm_object_part_content_unset(m_mainLayout, "web_view");
287 void WebPageUI::setErrorButtons()
289 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
290 m_leftButtonBar->setActionForButton("refresh_stop_button", m_reload);
291 m_stopLoading->setEnabled(false);
292 m_reload->setEnabled(true);
293 m_forward->setEnabled(false);
294 evas_object_hide(m_progressBar);
297 void WebPageUI::updateURIBar(const std::string& uri)
299 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
300 m_URIEntry->changeUri(uri);
301 m_leftButtonBar->setActionForButton("refresh_stop_button", m_reload);
303 m_stopLoading->setEnabled(true);
304 m_reload->setEnabled(true);
308 std::string WebPageUI::edjePath(const std::string& file)
310 return std::string(EDJE_DIR) + file;
313 void WebPageUI::showTabUIConnect()
318 void WebPageUI::showMoreMenuConnect()
324 } // namespace tizen_browser
325 } // namespace base_ui