2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
21 #include <Plugin/IBoxPluginFactory.h>
22 #include "Buffer/IRenderBuffer.h"
23 #include "Buffer/RenderBufferFactory.h"
26 #include "IBoxState.h"
28 #include "Util/ITimer.h"
29 #include "BoxUpdateTimer.h"
30 #include "BoxSchemeHandler.h"
33 // This is used for informing context of box to web content as value of url parameter
34 static const std::string renderTypeCreate("create");
35 static const std::string renderTypeResize("resize");
36 static const std::string renderTypeOpenPd("pdopen");
37 static const std::string renderTypeUpdate("update");
39 Box::Box(BoxInfoPtr boxInfo, IBoxPluginFactoryPtr factory, EwkContextPtr ewkContext)
46 m_boxBuffer = m_factory->createBoxRenderBuffer(
51 boxInfo->contentInfo);
52 m_boxBuffer->allocate();
53 m_view = m_factory->createRenderView(
54 boxInfo->boxId, boxInfo->instanceId,
55 m_boxBuffer->getWindow(),
57 m_updateTimer = BoxUpdateTimer::create(
61 BoxSchemeHandler::Instance()->registerBox(boxInfo->instanceId, this);
63 // TODO code regarding state needs more testing
64 //m_state = BoxInitState::create(
65 // IBoxContextPtr(dynamic_cast<IBoxContext*>(this)));
74 BoxSchemeHandler::Instance()->unregisterBox(m_boxInfo->instanceId);
80 CHECK_BOX_STATE(m_state, permitShow);
83 m_updateTimer->start();
84 m_boxBuffer->startCanvasUpdate();
85 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeCreate);
86 m_view->showBox(renderInfo);
98 CHECK_BOX_STATE(m_state, permitHide);
101 m_updateTimer->stop();
112 bool Box::resize(int width, int height)
115 CHECK_BOX_STATE(m_state, permitShow);
117 // reset box info to new width, height
118 m_boxInfo->boxWidth = width;
119 m_boxInfo->boxHeight = height;
122 m_updateTimer->restart();
123 m_boxBuffer->reallocate(
124 m_boxInfo->boxWidth, m_boxInfo->boxHeight);
125 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeResize);
126 m_view->showBox(renderInfo);
128 LogD("resize exception");
139 CHECK_BOX_STATE(m_state, permitResume);
143 m_updateTimer->resume();
153 bool Box::pause(bool background)
156 CHECK_BOX_STATE(m_state, permitPause);
160 m_currentTab = false;
162 m_updateTimer->pause();
172 bool Box::openPd(int width, int height, double x, double y)
175 CHECK_BOX_STATE(m_state, permitOpenPd);
177 m_boxInfo->pdWidth = width;
178 m_boxInfo->pdHeight = height;
183 m_updateTimer->stop();
184 m_pdBuffer = RenderBufferFactory::create(
185 RenderBufferFactory::RENDER_BUFFER_TYPE_PD,
187 m_boxInfo->instanceId,
189 m_boxInfo->pdHeight);
190 m_pdBuffer->allocate();
191 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeOpenPd);
192 m_view->showPd(m_pdBuffer->getWindow(), renderInfo);
204 CHECK_BOX_STATE(m_state, permitClosePd);
209 m_updateTimer->start();
222 m_boxBuffer->startCanvasUpdate();
223 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeUpdate);
224 m_view->showBox(renderInfo);
229 bool Box::changePeriod(float period)
234 m_boxInfo->period = period;
235 m_updateTimer->setPeriod(m_boxInfo->period);
240 bool Box::isCurrentTab()
245 RenderInfoPtr Box::makeRenderInfo(const std::string& renderType) const
248 RenderInfoPtr renderInfo(new RenderInfo);
250 // add width, height, operation type
251 renderInfo->defaultUrlParams = "?type=" + renderType;
254 if (renderType == renderTypeOpenPd) {
255 renderInfo->width = m_boxInfo->pdWidth;
256 renderInfo->height = m_boxInfo->pdHeight;
258 renderInfo->width = m_boxInfo->boxWidth;
259 renderInfo->height = m_boxInfo->boxHeight;
262 sprintf(buff, "&width=%d&height=%d", renderInfo->width, renderInfo->height);
263 renderInfo->defaultUrlParams += buff;
265 // if needed, set pd information
266 if (renderType == renderTypeOpenPd) {
267 renderInfo->defaultUrlParams += "&pdopen-direction=";
268 if (m_boxInfo->pdY == 0.0f) {
269 renderInfo->defaultUrlParams += "down";
271 renderInfo->defaultUrlParams += "up";
275 sprintf(buff, "&pdopen-arrow-xpos=%d",
276 static_cast<int>((m_boxInfo->pdX) * (m_boxInfo->pdWidth)));
277 renderInfo->defaultUrlParams += buff;
282 if (!m_boxInfo->contentInfo.empty()) {
283 renderInfo->defaultUrlParams += "&" + m_boxInfo->contentInfo;
286 LogD("default url param string: %s", renderInfo->defaultUrlParams.c_str());
290 void Box::setState(IBoxStatePtr state)
296 Eina_Bool Box::updateCallback(void* data)
299 Box* This = static_cast<Box*>(data);
302 return ECORE_CALLBACK_RENEW;