Ginga  0.13.6
 All Classes Namespaces Functions Variables
AwesomiumHandler.h
1 /******************************************************************************
2 Este arquivo eh parte da implementacao do ambiente declarativo do middleware
3 Ginga (Ginga-NCL).
4 
5 Direitos Autorais Reservados (c) 1989-2007 PUC-Rio/Laboratorio TeleMidia
6 
7 Este programa eh software livre; voce pode redistribui-lo e/ou modificah-lo sob
8 os termos da Licenca Publica Geral GNU versao 2 conforme publicada pela Free
9 Software Foundation.
10 
11 Este programa eh distribuido na expectativa de que seja util, porem, SEM
12 NENHUMA GARANTIA; nem mesmo a garantia implicita de COMERCIABILIDADE OU
13 ADEQUACAO A UMA FINALIDADE ESPECIFICA. Consulte a Licenca Publica Geral do
14 GNU versao 2 para mais detalhes.
15 
16 Voce deve ter recebido uma copia da Licenca Publica Geral do GNU versao 2 junto
17 com este programa; se nao, escreva para a Free Software Foundation, Inc., no
18 endereco 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
19 
20 Para maiores informacoes:
21 ncl @ telemidia.puc-rio.br
22 http://www.ncl.org.br
23 http://www.ginga.org.br
24 http://www.telemidia.puc-rio.br
25 ******************************************************************************
26 This file is part of the declarative environment of middleware Ginga (Ginga-NCL)
27 
28 Copyright: 1989-2007 PUC-RIO/LABORATORIO TELEMIDIA, All Rights Reserved.
29 
30 This program is free software; you can redistribute it and/or modify it under
31 the terms of the GNU General Public License version 2 as published by
32 the Free Software Foundation.
33 
34 This program is distributed in the hope that it will be useful, but WITHOUT ANY
35 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
36 PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
37 details.
38 
39 You should have received a copy of the GNU General Public License version 2
40 along with this program; if not, write to the Free Software
41 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 
43 For further information contact:
44 ncl @ telemidia.puc-rio.br
45 http://www.ncl.org.br
46 http://www.ginga.org.br
47 http://www.telemidia.puc-rio.br
48 *******************************************************************************/
49 
50 #ifndef AwesomiumHandler_h_
51 #define AwesomiumHandler_h_
52 
53 #include "system/compat/SystemCompat.h"
54 using namespace ::br::pucrio::telemidia::ginga::core::system::compat;
55 
56 #include "util/functions.h"
57 using namespace ::br::pucrio::telemidia::util;
58 
59 #include "mb/ILocalScreenManager.h"
60 #include "mb/IInputManager.h"
61 #include "mb/interface/IWindow.h"
62 #include "mb/interface/IInputEventListener.h"
63 #include "mb/interface/IMotionEventListener.h"
64 using namespace ::br::pucrio::telemidia::ginga::core::mb;
65 
66 #include <stdio.h>
67 #include <string>
68 #include <sstream>
69 #include <map>
70 #include <iostream>
71 using namespace std;
72 
73 extern "C" {
74 #include <Awesomium/awesomium_capi.h>
75 }
76 
77 #include <Awesomium/KeyboardCodes.h>
78 using namespace Awesomium;
79 
80 namespace br {
81 namespace pucrio {
82 namespace telemidia {
83 namespace ginga {
84 namespace core {
85 namespace player {
86  typedef int AwesomiumHDR;
87 
88  class AwesomiumInfo :
89  public IInputEventListener,
90  public IMotionEventListener {
91 
92  public:
93  static const short ET_NONE = 0;
94  static const short ET_KEY = 1;
95  static const short ET_BUTTON = 2;
96  static const short ET_MOTION = 3;
97 
98  GingaScreenID myScreen;
99  AwesomiumHDR id;
100  string mURL;
101  ISurface* surface;
102  int mouseX, mouseY;
103  int x, y;
104  int w, h;
105  bool hasFocus;
106  bool setFocus;
107  string rFile;
108  bool update;
109  int eventCode;
110  short eventType;
111 
112  bool _eMVarW;
113  pthread_cond_t _eMVar;
114  pthread_mutex_t _eM;
115 
116  AwesomiumInfo(GingaScreenID screenId, AwesomiumHDR id);
117  virtual ~AwesomiumInfo();
118 
119  void waitEvent();
120  bool eventArrived();
121 
122  bool userEventReceived(IInputEvent* ev);
123  bool motionEventReceived(int x, int y, int z);
124  };
125 
127  private:
128  static map<int, int> fromGingaToAwesomium;
129  static pthread_mutex_t s_lMutex;
130  static map<AwesomiumHDR, AwesomiumInfo*> s_infos;
131  static AwesomiumHDR s_id;
132  static map<AwesomiumHDR, IInputManager*> s_ims;
133 
134  /* static since we have to respect browser isolation */
135  static bool initialized;
136  static awe_webview* webView;
137 
138  static ILocalScreenManager* dm;
139 
140  static void initCodeMap();
141 
142  static bool getAwesomeInfo(
143  AwesomiumHDR id,
144  AwesomiumInfo** aInfo,
145  bool removeInfo=false);
146 
147  static bool getAwesomeIM(
148  AwesomiumHDR id,
149  IInputManager** im,
150  bool removeInfo=false);
151 
152  static void onDOMReady(awe_webview* caller);
153 
154  public:
155  static AwesomiumHDR createAwesomium(GingaScreenID screenId);
156  static void destroyAwesomium(AwesomiumHDR id);
157  static void getSize(AwesomiumHDR id, int* w, int* h);
158 
159  static void setAwesomiumBounds(
160  AwesomiumHDR id, int x, int y, int w, int h);
161 
162  static void loadUrl(AwesomiumHDR id, string url);
163  static string getUrl(AwesomiumHDR id);
164  static ISurface* getSurface(AwesomiumHDR id);
165  static void setFocus(AwesomiumHDR id, bool focus);
166 
167  private:
168  static void setFocus(AwesomiumInfo* aInfo);
169  static void focus(AwesomiumInfo* aInfo);
170  static void unfocus(AwesomiumInfo* aInfo);
171 
172  public:
173  static void eventHandler(AwesomiumInfo* aInfo);
174 
175  private:
176  static void injectKey(AwesomiumInfo* aInfo, int keyCode);
177  static void refresh(AwesomiumHDR id);
178  static void update(AwesomiumInfo* aInfo, double value);
179 
180  public:
181  static bool stopUpdate(AwesomiumHDR id);
182  };
183 }
184 }
185 }
186 }
187 }
188 }
189 
190 #endif /*AwesomiumHandler_h_*/