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://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)
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, double x, double y)
169 CHECK_BOX_STATE(m_state, permitOpenPd);
171 m_boxInfo->pdWidth = width;
172 m_boxInfo->pdHeight = height;
177 m_updateTimer->stop();
178 m_pdBuffer = RenderBufferFactory::create(
179 RenderBufferFactory::RENDER_BUFFER_TYPE_PD,
181 m_boxInfo->instanceId,
183 m_boxInfo->pdHeight);
184 m_pdBuffer->allocate();
185 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeOpenPd);
186 m_view->showPd(m_pdBuffer->getWindow(), renderInfo);
198 CHECK_BOX_STATE(m_state, permitClosePd);
203 m_updateTimer->start();
217 m_boxBuffer->startCanvasUpdate();
218 RenderInfoPtr renderInfo = makeRenderInfo(renderTypeUpdate);
219 m_view->showBox(renderInfo);
224 bool Box::changePeriod(float period)
229 m_boxInfo->period = period;
230 m_updateTimer->setPeriod(m_boxInfo->period);
235 RenderInfoPtr Box::makeRenderInfo(const std::string& renderType) const
238 RenderInfoPtr renderInfo(new RenderInfo);
240 // add width, height, operation type
241 renderInfo->defaultUrlParams = "?type=" + renderType;
244 if (renderType == renderTypeOpenPd) {
245 renderInfo->width = m_boxInfo->pdWidth;
246 renderInfo->height = m_boxInfo->pdHeight;
248 renderInfo->width = m_boxInfo->boxWidth;
249 renderInfo->height = m_boxInfo->boxHeight;
252 sprintf(buff, "&width=%d&height=%d", renderInfo->width, renderInfo->height);
253 renderInfo->defaultUrlParams += buff;
255 // if needed, set pd information
256 if (renderType == renderTypeOpenPd) {
257 renderInfo->defaultUrlParams += "&pdopen-direction=";
258 if (m_boxInfo->pdY == 0.0f) {
259 renderInfo->defaultUrlParams += "down";
261 renderInfo->defaultUrlParams += "up";
265 sprintf(buff, "&pdopen-arrow-xpos=%d",
266 static_cast<int>((m_boxInfo->pdX) * (m_boxInfo->pdWidth)));
267 renderInfo->defaultUrlParams += buff;
272 if (!m_boxInfo->contentInfo.empty()) {
273 renderInfo->defaultUrlParams += "&" + m_boxInfo->contentInfo;
276 LogD("default url param string: %s", renderInfo->defaultUrlParams.c_str());
280 void Box::setState(IBoxStatePtr state)
286 Eina_Bool Box::updateCallback(void* data)
289 Box* This = static_cast<Box*>(data);
292 return ECORE_CALLBACK_RENEW;