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)
44 , m_updateNeeded(false)
48 m_boxBuffer = m_factory->createBoxRenderBuffer(
53 boxInfo->contentInfo);
54 m_boxBuffer->allocate();
55 m_view = m_factory->createRenderView(
56 boxInfo->boxId, boxInfo->instanceId,
57 m_boxBuffer->getWindow(),
59 m_updateTimer = BoxUpdateTimer::create(
63 BoxSchemeHandler::Instance()->registerBox(boxInfo->instanceId, this);
65 // TODO code regarding state needs more testing
66 //m_state = BoxInitState::create(
67 // IBoxContextPtr(dynamic_cast<IBoxContext*>(this)));
76 BoxSchemeHandler::Instance()->unregisterBox(m_boxInfo->instanceId);
82 CHECK_BOX_STATE(m_state, permitShow);
85 m_updateTimer->start();
86 m_boxBuffer->startCanvasUpdate();
87 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeCreate);
88 m_view->showBox(renderInfo);
100 CHECK_BOX_STATE(m_state, permitHide);
103 m_updateTimer->stop();
114 bool Box::resize(int width, int height)
117 CHECK_BOX_STATE(m_state, permitShow);
119 // reset box info to new width, height
120 m_boxInfo->boxWidth = width;
121 m_boxInfo->boxHeight = height;
124 m_updateTimer->restart();
125 m_boxBuffer->reallocate(
126 m_boxInfo->boxWidth, m_boxInfo->boxHeight);
127 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeResize);
128 m_view->showBox(renderInfo);
130 LogD("resize exception");
141 CHECK_BOX_STATE(m_state, permitResume);
147 if (m_updateNeeded) {
148 m_updateNeeded = false;
161 bool Box::pause(bool background)
164 CHECK_BOX_STATE(m_state, permitPause);
168 m_currentTab = false;
180 bool Box::openPd(int width, int height, double x, double y)
183 CHECK_BOX_STATE(m_state, permitOpenPd);
185 m_boxInfo->pdWidth = width;
186 m_boxInfo->pdHeight = height;
191 m_updateTimer->stop();
192 m_pdBuffer = RenderBufferFactory::create(
193 RenderBufferFactory::RENDER_BUFFER_TYPE_PD,
195 m_boxInfo->instanceId,
197 m_boxInfo->pdHeight);
198 m_pdBuffer->allocate();
199 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeOpenPd);
200 m_view->showPd(m_pdBuffer->getWindow(), renderInfo);
212 CHECK_BOX_STATE(m_state, permitClosePd);
217 m_updateTimer->restart();
231 // update is dalayed until this box goes to current tab
232 m_updateNeeded = true;
236 m_boxBuffer->startCanvasUpdate();
237 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeUpdate);
238 m_view->showBox(renderInfo);
243 bool Box::changePeriod(float period)
248 m_boxInfo->period = period;
249 m_updateTimer->setPeriod(m_boxInfo->period);
254 bool Box::isCurrentTab()
259 RenderInfoPtr Box::makeRenderInfo(const std::string& renderType) const
262 RenderInfoPtr renderInfo(new RenderInfo);
264 // add width, height, operation type
265 renderInfo->defaultUrlParams = "?type=" + renderType;
268 if (renderType == renderTypeOpenPd) {
269 renderInfo->width = m_boxInfo->pdWidth;
270 renderInfo->height = m_boxInfo->pdHeight;
272 renderInfo->width = m_boxInfo->boxWidth;
273 renderInfo->height = m_boxInfo->boxHeight;
276 sprintf(buff, "&width=%d&height=%d", renderInfo->width, renderInfo->height);
277 renderInfo->defaultUrlParams += buff;
279 // if needed, set pd information
280 if (renderType == renderTypeOpenPd) {
281 renderInfo->defaultUrlParams += "&pdopen-direction=";
282 if (m_boxInfo->pdY == 0.0f) {
283 renderInfo->defaultUrlParams += "down";
285 renderInfo->defaultUrlParams += "up";
289 sprintf(buff, "&pdopen-arrow-xpos=%d",
290 static_cast<int>((m_boxInfo->pdX) * (m_boxInfo->pdWidth)));
291 renderInfo->defaultUrlParams += buff;
296 if (!m_boxInfo->contentInfo.empty()) {
297 renderInfo->defaultUrlParams += "&" + m_boxInfo->contentInfo;
300 LogD("default url param string: %s", renderInfo->defaultUrlParams.c_str());
304 void Box::setState(IBoxStatePtr state)
310 Eina_Bool Box::updateCallback(void* data)
313 Box* This = static_cast<Box*>(data);
316 return ECORE_CALLBACK_RENEW;