2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Flora License, Version 1.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.tizenopensource.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)
45 m_boxBuffer = m_factory->createBoxRenderBuffer(
50 boxInfo->contentInfo);
51 m_boxBuffer->allocate();
52 m_view = m_factory->createRenderView(
53 boxInfo->boxId, boxInfo->instanceId,
54 m_boxBuffer->getWindow(),
56 m_updateTimer = BoxUpdateTimer::create(
60 BoxSchemeHandler::Instance()->registerBox(boxInfo->instanceId, this);
62 // TODO code regarding state needs more testing
63 //m_state = BoxInitState::create(
64 // IBoxContextPtr(dynamic_cast<IBoxContext*>(this)));
73 BoxSchemeHandler::Instance()->unregisterBox(m_boxInfo->instanceId);
79 CHECK_BOX_STATE(m_state, permitShow);
82 m_updateTimer->start();
83 m_boxBuffer->startCanvasUpdate();
84 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeCreate);
85 m_view->showBox(renderInfo);
97 CHECK_BOX_STATE(m_state, permitHide);
100 m_updateTimer->stop();
111 bool Box::resize(int width, int height)
114 CHECK_BOX_STATE(m_state, permitShow);
116 // reset box info to new width, height
117 m_boxInfo->boxWidth = width;
118 m_boxInfo->boxHeight = height;
121 m_updateTimer->restart();
122 m_boxBuffer->reallocate(
123 m_boxInfo->boxWidth, m_boxInfo->boxHeight);
124 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeResize);
125 m_view->showBox(renderInfo);
137 CHECK_BOX_STATE(m_state, permitResume);
140 m_updateTimer->start();
153 CHECK_BOX_STATE(m_state, permitPause);
156 m_updateTimer->stop();
166 bool Box::openPd(int width, int height)
169 CHECK_BOX_STATE(m_state, permitOpenPd);
171 m_boxInfo->pdWidth = width;
172 m_boxInfo->pdHeight = height;
175 m_updateTimer->stop();
176 m_pdBuffer = RenderBufferFactory::create(
177 RenderBufferFactory::RENDER_BUFFER_TYPE_PD,
179 m_boxInfo->instanceId,
181 m_boxInfo->pdHeight);
182 m_pdBuffer->allocate();
183 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeOpenPd);
184 m_view->showPd(m_pdBuffer->getWindow(), renderInfo);
196 CHECK_BOX_STATE(m_state, permitClosePd);
201 m_updateTimer->start();
215 m_boxBuffer->startCanvasUpdate();
216 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeUpdate);
217 m_view->showBox(renderInfo);
222 bool Box::changePeriod(float period)
227 m_boxInfo->period = period;
228 m_updateTimer->setPeriod(m_boxInfo->period);
233 RenderInfoPtr Box::makeRenderInfo(const std::string& renderType) const
235 RenderInfoPtr renderInfo(new RenderInfo);
237 if (renderType == renderTypeOpenPd) {
238 renderInfo->width = m_boxInfo->pdWidth;
239 renderInfo->height = m_boxInfo->pdHeight;
241 renderInfo->width = m_boxInfo->boxWidth;
242 renderInfo->height = m_boxInfo->boxHeight;
244 // add width, height, operation type
245 renderInfo->defaultUrlParams = "?type=" + renderType;
247 sprintf(buff, "&width=%d&height=%d", renderInfo->width, renderInfo->height);
248 renderInfo->defaultUrlParams += buff;
251 if (!m_boxInfo->contentInfo.empty()) {
252 renderInfo->defaultUrlParams += "&" + m_boxInfo->contentInfo;
255 LogD("default url param string: %s", renderInfo->defaultUrlParams.c_str());
259 void Box::setState(IBoxStatePtr state)
265 Eina_Bool Box::updateCallback(void* data)
268 Box* This = static_cast<Box*>(data);
271 return ECORE_CALLBACK_RENEW;