0c2d9c343d1077059abcfb17c7104a748d5515e9
[platform/framework/web/web-provider.git] / src / Plugin / AppBoxPlugin / AppBoxRenderBuffer.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://floralicense.org/license/
9  *
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.
15  */
16 /**
17  * @file    AppBoxRenderBuffer.cpp
18  * @author  Yunchan Cho (yunchan.cho@samsung.com)
19  */
20 #include <string>
21 #include <API/web_provider_livebox_info.h>
22 #include <Core/Buffer/RenderBuffer.h>
23 #include <Core/Util/Log.h>
24 #include "AppBoxRenderView.h"
25 #include "AppBoxRenderBuffer.h"
26 #include "AppBoxObserver.h"
27
28 #define MAX_WAIT_TIME 5.0  
29
30 AppBoxRenderBuffer::AppBoxRenderBuffer(
31         std::string boxId, std::string instanceId,
32         int width, int height, std::string data)
33     : BoxRenderBuffer(boxId, instanceId, width, height)
34     , m_boxId(boxId)
35     , m_instanceId(instanceId)
36     , m_mouseEventRecievable(false)
37     , m_touchTimer()
38     , m_renderView()
39 {
40     LogD("enter");
41     if (web_provider_livebox_get_mouse_event(m_boxId.c_str())) {
42         m_mouseEventRecievable = true;
43     }
44
45     AppBoxObserver::Instance()->registerRenderBuffer(m_instanceId, this);
46 }
47
48 AppBoxRenderBuffer::~AppBoxRenderBuffer()
49 {
50     LogD("enter");
51     AppBoxObserver::Instance()->unregisterRenderBuffer(m_instanceId);
52 }
53
54 void AppBoxRenderBuffer::didHandleTouchEvent(
55                 TouchType type, double timestamp, double x, double y)
56 {
57     LogD("enter");
58     if (!m_mouseEventRecievable) {
59         return;
60     }
61
62     m_renderView = AppBoxObserver::Instance()->getRenderView(m_instanceId);
63
64     if (!m_renderView || !(m_renderView->m_view)) {
65         LogD("no matched render view");
66         return;
67     }
68
69     // if needed, resume render view
70     if (m_renderView->m_fireRenderTimer) {
71         m_renderView->deleteRenderTimer();
72     } else {
73         if (!m_touchTimer) {
74             startCanvasUpdate();
75             m_renderView->m_view->Resume();
76         } else {
77             deleteTouchTimer();
78         }
79     }
80
81     BoxRenderBuffer::didHandleTouchEvent(type, timestamp, x, y);
82     m_touchTimer = ecore_timer_add(MAX_WAIT_TIME, fireTouchTimerCallback, this);
83 }
84
85 void AppBoxRenderBuffer::deleteTouchTimer()
86 {
87     LogD("enter");
88     if (m_touchTimer) {
89         ecore_timer_del(m_touchTimer);
90         m_touchTimer = NULL;
91     }
92 }
93
94 Eina_Bool AppBoxRenderBuffer::fireTouchTimerCallback(void* data)
95 {
96     LogD("enter");
97     AppBoxRenderBuffer* This = static_cast<AppBoxRenderBuffer*>(data); 
98     This->stopCanvasUpdate();
99     This->m_renderView->m_view->Suspend();
100     This->m_touchTimer = NULL;
101
102     return ECORE_CALLBACK_CANCEL;
103 }