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)
22 #include <Plugin/IBoxPluginFactory.h>
23 #include "Buffer/IRenderBuffer.h"
24 #include "Buffer/RenderBuffer.h"
25 #include "Buffer/RenderBufferFactory.h"
28 #include "IBoxState.h"
30 #include "Util/ITimer.h"
31 #include "BoxUpdateTimer.h"
32 #include "BoxSchemeHandler.h"
35 // This is used for informing context of box to web content as value of url parameter
36 static const std::string renderTypeCreate("create");
37 static const std::string renderTypeResize("resize");
38 static const std::string renderTypeOpenPd("pdopen");
39 static const std::string renderTypeUpdate("update");
41 Box::Box(BoxInfoPtr boxInfo, IBoxPluginFactoryPtr factory, EwkContextPtr ewkContext)
46 , m_updateNeeded(false)
50 m_boxBuffer = m_factory->createBoxRenderBuffer(
55 boxInfo->contentInfo);
56 m_boxBuffer->allocate();
57 m_view = m_factory->createRenderView(
58 boxInfo->boxId, boxInfo->instanceId,
59 m_boxBuffer->getWindow(),
61 m_updateTimer = BoxUpdateTimer::create(
65 BoxSchemeHandler::Instance()->registerBox(boxInfo->instanceId, this);
67 // TODO code regarding state needs more testing
68 //m_state = BoxInitState::create(
69 // IBoxContextPtr(dynamic_cast<IBoxContext*>(this)));
78 BoxSchemeHandler::Instance()->unregisterBox(m_boxInfo->instanceId);
84 CHECK_BOX_STATE(m_state, permitShow);
87 m_updateTimer->start();
88 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeCreate);
89 m_boxBuffer->stopCanvasUpdate();
90 m_view->showBox(renderInfo);
91 ecore_idler_add(startUpdateRenderBufferIdlerCallback, m_boxBuffer.get());
103 CHECK_BOX_STATE(m_state, permitHide);
106 m_updateTimer->stop();
107 m_boxBuffer->stopCanvasUpdate();
119 bool Box::resize(int width, int height)
122 CHECK_BOX_STATE(m_state, permitShow);
124 // reset box info to new width, height
125 m_boxInfo->boxWidth = width;
126 m_boxInfo->boxHeight = height;
129 m_updateTimer->restart();
130 m_boxBuffer->reallocate(
131 m_boxInfo->boxWidth, m_boxInfo->boxHeight);
132 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeResize);
133 m_view->showBox(renderInfo);
135 LogD("resize exception");
146 CHECK_BOX_STATE(m_state, permitResume);
152 if (m_updateNeeded) {
153 m_updateNeeded = false;
166 bool Box::pause(bool background)
169 CHECK_BOX_STATE(m_state, permitPause);
173 m_currentTab = false;
185 bool Box::openPd(int width, int height, double x, double y)
188 CHECK_BOX_STATE(m_state, permitOpenPd);
190 m_boxInfo->pdWidth = width;
191 m_boxInfo->pdHeight = height;
196 m_updateTimer->stop();
197 m_pdBuffer = RenderBufferFactory::create(
198 RenderBufferFactory::RENDER_BUFFER_TYPE_PD,
200 m_boxInfo->instanceId,
202 m_boxInfo->pdHeight);
203 m_pdBuffer->allocate();
204 m_pdBuffer->stopCanvasUpdate();
205 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeOpenPd);
206 m_view->showPd(m_pdBuffer->getWindow(), renderInfo);
207 ecore_idler_add(startUpdateRenderBufferIdlerCallback, m_pdBuffer.get());
219 CHECK_BOX_STATE(m_state, permitClosePd);
222 m_pdBuffer->stopCanvasUpdate();
226 m_updateTimer->restart();
240 // update is dalayed until this box goes to current tab
241 m_updateNeeded = true;
246 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeUpdate);
247 m_boxBuffer->stopCanvasUpdate();
248 m_view->showBox(renderInfo);
249 ecore_idler_add(startUpdateRenderBufferIdlerCallback, m_boxBuffer.get());
257 bool Box::changePeriod(float period)
262 m_boxInfo->period = period;
263 m_updateTimer->setPeriod(m_boxInfo->period);
268 bool Box::isCurrentTab()
273 RenderInfoPtr Box::makeRenderInfo(const std::string& renderType) const
276 RenderInfoPtr renderInfo(new RenderInfo);
278 // add width, height, operation type
279 renderInfo->defaultUrlParams = "?type=" + renderType;
282 if (renderType == renderTypeOpenPd) {
283 renderInfo->width = m_boxInfo->pdWidth;
284 renderInfo->height = m_boxInfo->pdHeight;
286 renderInfo->width = m_boxInfo->boxWidth;
287 renderInfo->height = m_boxInfo->boxHeight;
290 sprintf(buff, "&width=%d&height=%d", renderInfo->width, renderInfo->height);
291 renderInfo->defaultUrlParams += buff;
293 // if needed, set pd information
294 if (renderType == renderTypeOpenPd) {
295 renderInfo->defaultUrlParams += "&pdopen-direction=";
296 if (m_boxInfo->pdY == 0.0f) {
297 renderInfo->defaultUrlParams += "down";
299 renderInfo->defaultUrlParams += "up";
303 sprintf(buff, "&pdopen-arrow-xpos=%d",
304 static_cast<int>((m_boxInfo->pdX) * (m_boxInfo->pdWidth)));
305 renderInfo->defaultUrlParams += buff;
310 if (!m_boxInfo->contentInfo.empty()) {
311 renderInfo->defaultUrlParams += "&" + m_boxInfo->contentInfo;
314 LogD("default url param string: %s", renderInfo->defaultUrlParams.c_str());
318 void Box::setState(IBoxStatePtr state)
324 Eina_Bool Box::updateCallback(void* data)
327 Box* This = static_cast<Box*>(data);
330 return ECORE_CALLBACK_RENEW;
333 Eina_Bool Box::startUpdateRenderBufferIdlerCallback(void* data)
336 RenderBuffer* buffer = static_cast<RenderBuffer*>(data);
340 buffer->startCanvasUpdate();
343 return ECORE_CALLBACK_CANCEL;