My Project
HTMLBrowserManager.h
1 #pragma once
2 #include "2dengine/EventBinding.h"
3 #include "IHTMLRenderer.h"
4 #include <string>
5 
6 namespace ParaEngine
7 {
8  using namespace std;
9  class CHTMLBrowserManager;
10  class IHTMLBrowserManager;
11  class CEventBinding;
12  class SimpleScript;
13 
16  {
17  public:
18  CHTMLBrowser(CHTMLBrowserManager* manager, int nBrowserWindowId);
19  ~CHTMLBrowser();
20  public:
22  // implementation of IEmbeddedBrowserWindowObserver interface
23  virtual void onPageChanged( const IEmbeddedBrowserWindowObserver::EventType& eventIn );
24  virtual void onNavigateBegin( const IEmbeddedBrowserWindowObserver::EventType& eventIn );
25  virtual void onNavigateComplete( const IEmbeddedBrowserWindowObserver::EventType& eventIn );
26  virtual void onUpdateProgress( const IEmbeddedBrowserWindowObserver::EventType& eventIn );
27  virtual void onStatusTextChange( const IEmbeddedBrowserWindowObserver::EventType& eventIn );
28  virtual void onLocationChange( const IEmbeddedBrowserWindowObserver::EventType& eventIn );
29  virtual void onClickLinkHref( const IEmbeddedBrowserWindowObserver::EventType& eventIn );
30 
31  public:
33  void Release();
34 
35  bool setSize( int widthIn, int heightIn );
36  bool scrollByLines( int linesIn );
37  bool setBackgroundColor( const int redIn, const int greenIn, const int blueIn );
38  bool setEnabled( bool enabledIn );
39 
40  // add/remove yourself as an observer on browser events - see IEmbeddedBrowserWindowObserver declaration
41  bool addObserver( IEmbeddedBrowserWindowObserver* subjectIn );
42  bool remObserver( IEmbeddedBrowserWindowObserver* subjectIn );
43 
44  // navigation - self explanatory
45  bool navigateTo( const std::string uriIn );
46  bool navigateStop();
47  bool canNavigateBack();
48  bool navigateBack();
49  bool canNavigateForward();
50  bool navigateForward();
51 
52  // access to rendered bitmap data
53  const unsigned char* grabBrowserWindow(); // renders page to memory and returns pixels
54  const unsigned char* getBrowserWindowPixels(); // just returns pixels - no render
55  const int getBrowserWidth(); // current browser width (can vary slightly after page is rendered)
56  const int getBrowserHeight(); // current height
57  const int getBrowserDepth(); // depth in bytes
58  const int getBrowserRowSpan(); // width in pixels * depth in bytes
59 
60  // mouse/keyboard interaction
61  bool mouseDown( int xPosIn, int yPosIn ); // send a mouse down event to a browser window at given XY in browser space
62  bool mouseUp( int xPosIn, int yPosIn ); // send a mouse up event to a browser window at given XY in browser space
63  bool mouseMove( int xPosIn, int yPosIn ); // send a mouse move event to a browser window at given XY in browser space
64  bool keyPress( int keyCodeIn ); // send a key press event to a browser window
65  bool focusBrowser( bool focusBrowserIn ); // set/remove focus to given browser window
66 
67  // accessor/mutator for scheme that browser doesn't follow - e.g. paraengine.com://
68  void setNoFollowScheme( std::string schemeIn );
69  std::string getNoFollowScheme();
70 
71  private:
75  HRESULT CreateTexture(LPDIRECT3DTEXTURE9 *ppTexture);
76 
79  HRESULT UpdateTexture(LPDIRECT3DTEXTURE9 pTexture);
80 
81  public:
83  int GetBrowserWindowID(){return m_nBrowserWindowId;}
84 
89  LRESULT SendMessage( UINT Msg,WPARAM wParam,LPARAM lParam);
94  LRESULT PostMessage( UINT Msg,WPARAM wParam,LPARAM lParam);
95 
97  const char* GetName();
98 
100  void InvalidateDeviceObjects();
101 
103  LPDIRECT3DTEXTURE9 GetTexture();
104 
106  const string& GetLastNavURL(){ return m_LastNavURL;}
107  public:
109  string m_filename;
111  string m_LastNavURL;
112 
113  int m_nBrowserWindowId;
114  CHTMLBrowserManager* m_manager;
115 
117  float m_fTimeOut;
120 
122  LPDIRECT3DTEXTURE9 m_pTexture;
123  D3DFORMAT m_TextureFormat;
124  bool m_bUseDynamicTextures;
125 
129 
132  };
133 
138  {
139  public:
140  CHTMLBrowserManager(void);
141  ~CHTMLBrowserManager(void);
142 
145  {
146  EM_onPageChanged = 0,
147  EM_onNavigateBegin,
148  EM_onNavigateComplete,
149  EM_onUpdateProgress,
150  EM_onStatusTextChange,
151  EM_onLocationChange,
152  EM_onClickLinkHref,
153  };
154  public:
155  bool LoadHTMLManagerPlugin();
156 
157  HRESULT InitDeviceObjects();// device independent
158  HRESULT RestoreDeviceObjects(); // device dependent
159  HRESULT InvalidateDeviceObjects();
160  HRESULT DeleteDeviceObjects();
162  void Cleanup();
164  void LoadAsset();
166  void UnloadAsset();
169  void GarbageCollectAll();
170 
172  // house keeping
173  bool init( std::string appBaseDirIn, std::string profileDirNameIn );
174  bool reset();
175  bool clearCache();
176  int getLastError();
177  const std::string getVersion();
178  void setBrowserAgentId( std::string idIn );
179  // how many browsers can be opened at the same time
180  int GetMaxWindowNum();
181  void SetMaxWindowNum(int nNum);
182 
184  // browser window - creation/deletion, mutation etc.
188  CHTMLBrowser* createBrowserWindow( const char* sFileName, int browserWindowWidthIn, int browserWindowHeightIn );
189  bool destroyBrowserWindow( int browserWindowIdIn );
191  CHTMLBrowser* GetBrowserWindow(const char* sFileName);
192 
194  CHTMLBrowser* GetBrowserWindow(int nWindowID);
195 
197  CHTMLBrowser* CreateGetBrowserWindow(const char* sFileName);
198 
200  IHTMLBrowserManager* GetInterface(){return m_pInterface;};
201 
203  // event handlers
204 
206  void SetEventScript(int nEvent,const SimpleScript *script);
207  const SimpleScript* GetEventScript(int nEvent)const;
210  bool HasEvent(int etype);
212  bool ActivateScript(int etype, const string &code);
213 
214  private:
215  vector <CHTMLBrowser*> m_browsers;
216  IHTMLBrowserManager* m_pInterface;
217  int m_nMaxWindowNum;
218  EventBinding_cow_type m_pEventbinding;
219  };
220 
221 }
string m_LastNavURL
the last url when navigateTo() is called.
Definition: HTMLBrowserManager.h:111
Definition: IHTMLRenderer.h:24
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: IHTMLRenderer.h:114
string m_filename
file name that the current texture is associated with.
Definition: HTMLBrowserManager.h:109
const string & GetLastNavURL()
the last url when navigateTo() is called.
Definition: HTMLBrowserManager.h:106
NPL interface of a XML Web service client proxy this class is implemented by ParaEngine.Net plug-in.
Definition: IHTMLRenderer.h:134
IHTMLBrowserManager * GetInterface()
get the main plugin interface
Definition: HTMLBrowserManager.h:200
an instance of HTML browser.
Definition: HTMLBrowserManager.h:15
Definition: EventBinding.h:42
HTMLBROWSER_EVENTS
HTML browser events.
Definition: HTMLBrowserManager.h:144
Definition: inftrees.h:24
LPDIRECT3DTEXTURE9 m_pTexture
dynamic d3d texture
Definition: HTMLBrowserManager.h:122
managing HTML browsers.
Definition: HTMLBrowserManager.h:137
bool m_bTextureUpdated
whether the texture has been update in this rendering frame.
Definition: HTMLBrowserManager.h:128
float m_fTimeOut
if a flash player is never used for this number of time, it will be deleted.
Definition: HTMLBrowserManager.h:117
float m_fLastUsedTime
last time the GetTexture() is called.
Definition: HTMLBrowserManager.h:119
int GetBrowserWindowID()
get window id
Definition: HTMLBrowserManager.h:83
bool m_bNeedUpdate
this flag is set to true every frame move. and set to false when the target image is saved to temp bu...
Definition: HTMLBrowserManager.h:131