root/trunk/llmozlib2/llmozlib2.h

Revision 15, 15.8 kB (checked in by callum.linden, 1 year ago)

Updates before new site released. Minor changes to LLMozLib and some new bookmarks for uBrowser.
Reviewed by cricket ball

  • Property svn:eol-style set to native
Line 
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Linden Lab Inc. (http://lindenlab.com) code.
15  *
16  * The Initial Developer of the Original Code is:
17  *   Callum Prentice (callum@ubrowser.com)
18  *
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *  Callum Prentice (callum@ubrowser.com)
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 #ifndef LLMOZLIB_H
40 #define LLMOZLIB_H
41
42 #include <string>
43 #include <map>
44
45 class LLEmbeddedBrowser;
46 class LLEmbeddedBrowserWindow;
47
48 ////////////////////////////////////////////////////////////////////////////////
49 // data class that is passed with an event
50 class LLEmbeddedBrowserWindowEvent
51 {
52         public:
53                 LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn ) :
54                         mEventWindowId( eventWindowIdIn ),
55                         mEventUri( uriIn )
56                 {
57                 };
58
59                 // single int passed with the event - e.g. progress
60                 LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn, int intValIn ) :
61                         mEventWindowId( eventWindowIdIn ),
62                         mEventUri( uriIn ),
63                         mIntVal( intValIn )
64                 {
65                 };
66
67                 // string passed with the event
68                 LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn, std::string stringValIn ) :
69                         mEventWindowId( eventWindowIdIn ),
70                         mEventUri( uriIn ),
71                         mStringVal( stringValIn )
72                 {
73                 };
74
75                 // 2 strings passed with the event
76                 LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn, std::string stringValIn, std::string stringVal2In ) :
77                         mEventWindowId( eventWindowIdIn ),
78                         mEventUri( uriIn ),
79                         mStringVal( stringValIn ),
80                         mStringVal2( stringVal2In )
81                 {
82                 };
83
84                 // string and an int passed with the event
85                 LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn, std::string stringValIn, int intValIn ) :
86                         mEventWindowId( eventWindowIdIn ),
87                         mEventUri( uriIn ),
88                         mStringVal( stringValIn ),
89                         mIntVal( intValIn )
90                 {
91                 };
92
93                 // 4 ints passed (semantically as a rectangle but could be anything - didn't want to make a RECT type structure)
94                 LLEmbeddedBrowserWindowEvent( int eventWindowIdIn, std::string uriIn, int xIn, int yIn, int widthIn, int heightIn ) :
95                         mEventWindowId( eventWindowIdIn ),
96                         mEventUri( uriIn ),
97                         mXVal( xIn ),
98                         mYVal( yIn ),
99                         mWidthVal( widthIn ),
100                         mHeightVal( heightIn )
101                 {
102                 };
103
104                 virtual ~LLEmbeddedBrowserWindowEvent()
105                 {
106                 };
107
108                 int getEventWindowId() const
109                 {
110                         return mEventWindowId;
111                 };
112
113                 std::string getEventUri() const
114                 {
115                         return mEventUri;
116                 };
117
118                 int getIntValue() const
119                 {
120                         return mIntVal;
121                 };
122
123                 std::string getStringValue() const
124                 {
125                         return mStringVal;
126                 };
127
128                 std::string getStringValue2() const
129                 {
130                         return mStringVal2;
131                 };
132
133                 void getRectValue( int& xOut, int& yOut, int& widthOut, int& heightOut ) const
134                 {
135                         xOut = mXVal;
136                         yOut = mYVal;
137                         widthOut = mWidthVal;
138                         heightOut = mHeightVal;
139                 };
140
141         private:
142                 int mEventWindowId;
143                 std::string mEventUri;
144                 int mIntVal;
145                 std::string mStringVal;
146                 std::string mStringVal2;
147                 int mXVal;
148                 int mYVal;
149                 int mWidthVal;
150                 int mHeightVal;
151 };
152
153 ////////////////////////////////////////////////////////////////////////////////
154 // derrive from this class and override these methods to observe these events
155 class LLEmbeddedBrowserWindowObserver
156 {
157         public:
158                 virtual ~LLEmbeddedBrowserWindowObserver() { };
159                 typedef LLEmbeddedBrowserWindowEvent EventType;
160
161                 virtual void onPageChanged( const EventType& eventIn ) { };
162                 virtual void onNavigateBegin( const EventType& eventIn ) { };
163                 virtual void onNavigateComplete( const EventType& eventIn ) { };
164                 virtual void onUpdateProgress( const EventType& eventIn ) { };
165                 virtual void onStatusTextChange( const EventType& eventIn ) { };
166                 virtual void onLocationChange( const EventType& eventIn ) { };
167                 virtual void onClickLinkHref( const EventType& eventIn ) { };
168                 virtual void onClickLinkNoFollow( const EventType& eventIn ) { };
169 };
170
171 ////////////////////////////////////////////////////////////////////////////////
172 // main library class
173 class LLMozLib
174 {
175         public:
176                 virtual ~LLMozLib();
177
178                 // singleton access
179                 static LLMozLib* getInstance();
180
181                 // housekeeping
182                 bool init( std::string applicationDir, std::string componentDir, std::string profileDir, void* nativeWindowHandleIn );
183                 bool reset();
184                 bool clearCache();
185                 int getLastError();
186                 const std::string getVersion();
187                 void setBrowserAgentId( std::string idIn );
188                 bool enableProxy( bool proxyEnabledIn, std::string proxyHostNameIn, int proxyPortIn );
189                 bool enableCookies( bool enabledIn );
190                 bool clearAllCookies();
191                 bool enablePlugins( bool enabledIn );
192
193                 // browser window - creation/deletion, mutation etc.
194                 int createBrowserWindow( int browserWindowWidthIn, int browserWindowHeightIn );
195                 bool destroyBrowserWindow( int browserWindowIdIn );
196                 bool setSize( int browserWindowIdIn, int widthIn, int heightIn );
197                 bool scrollByLines( int browserWindowIdIn, int linesIn );
198                 bool setBackgroundColor( int browserWindowIdIn, const int redIn, const int greenIn, const int blueIn );
199                 bool setCaretColor( int browserWindowIdIn, const int redIn, const int greenIn, const int blueIn );
200                 bool setEnabled( int browserWindowIdIn, bool enabledIn );
201
202                 // add/remove yourself as an observer on browser events - see LLEmbeddedBrowserWindowObserver declaration
203                 bool addObserver( int browserWindowIdIn, LLEmbeddedBrowserWindowObserver* subjectIn );
204                 bool remObserver( int browserWindowIdIn, LLEmbeddedBrowserWindowObserver* subjectIn );
205
206                 // navigation - self explanatory
207                 bool navigateTo( int browserWindowIdIn, const std::string uriIn );
208                 bool navigateStop( int browserWindowIdIn );
209                 bool canNavigateBack( int browserWindowIdIn );
210                 bool navigateBack( int browserWindowIdIn );
211                 bool canNavigateForward( int browserWindowIdIn );
212                 bool navigateForward( int browserWindowIdIn );
213                 bool navigateReload( int browserWindowIdIn );
214
215                 // javascript access/control
216                 std::string evaluateJavascript( int browserWindowIdIn, const std::string scriptIn );
217
218                 // set/clear URL to redirect to when a 404 page is reached
219                 bool set404RedirectUrl( int browser_window_in, std::string redirect_url );
220                 bool clr404RedirectUrl( int browser_window_in );
221
222                 // access to rendered bitmap data
223                 const unsigned char* grabBrowserWindow( int browserWindowIdIn );                // renders page to memory and returns pixels
224                 const unsigned char* getBrowserWindowPixels( int browserWindowIdIn );   // just returns pixels - no render
225                 const bool flipWindow( int browserWindowIdIn, bool flipIn );                    // optionally flip window (pixels) you get back
226                 const int getBrowserWidth( int browserWindowIdIn );                                             // current browser width (can vary slightly after page is rendered)
227                 const int getBrowserHeight( int browserWindowIdIn );                                    // current height
228                 const int getBrowserDepth( int browserWindowIdIn );                                             // depth in bytes
229                 const int getBrowserRowSpan( int browserWindowIdIn );                                   // width in pixels * depth in bytes
230
231                 // mouse/keyboard interaction
232                 bool mouseDown( int browserWindowIdIn, int xPosIn, int yPosIn );                        // send a mouse down event to a browser window at given XY in browser space
233                 bool mouseUp( int browserWindowIdIn, int xPosIn, int yPosIn );                          // send a mouse up event to a browser window at given XY in browser space
234                 bool mouseMove( int browserWindowIdIn, int xPosIn, int yPosIn );                        // send a mouse move event to a browser window at given XY in browser space
235                 bool mouseLeftDoubleClick( int browserWindowIdIn, int xPosIn, int yPosIn );     // send a mouse left button double click to a browser window at given XY in browser space
236                 bool keyPress( int browserWindowIdIn, int keyCodeIn );                                          // send a key press event to a browser window
237                 bool unicodeInput ( int browserWindowIdIn, unsigned long uni_char );            // send a unicode keypress event to a browser window
238                 bool focusBrowser( int browserWindowIdIn, bool focusBrowserIn );                        // set/remove focus to given browser window
239
240                 // accessor/mutator for scheme that browser doesn't follow - e.g. secondlife.com://
241                 void setNoFollowScheme( int browserWindowIdIn, std::string schemeIn );
242                 std::string getNoFollowScheme( int browserWindowIdIn );
243
244         private:
245                 LLMozLib();
246                 LLEmbeddedBrowserWindow* getBrowserWindowFromWindowId( int browserWindowIdIn );
247                 static LLMozLib* sInstance;
248                 const int mMaxBrowserWindows;
249                 typedef std::map< int, LLEmbeddedBrowserWindow* > BrowserWindowMap;
250                 typedef std::map< int, LLEmbeddedBrowserWindow* >::iterator BrowserWindowMapIter;
251                 BrowserWindowMap mBrowserWindowMap;
252 };
253
254 // Mozilla virtual keycodes.
255 // We don't want to suck in Mozilla headers so we copy these consts
256 // from nsIDOMKeyEvent.idl.
257
258 const unsigned long LL_DOM_VK_CANCEL         = 0x03;
259 const unsigned long LL_DOM_VK_HELP           = 0x06;
260 const unsigned long LL_DOM_VK_BACK_SPACE     = 0x08;
261 const unsigned long LL_DOM_VK_TAB            = 0x09;
262 const unsigned long LL_DOM_VK_CLEAR          = 0x0C;
263 const unsigned long LL_DOM_VK_RETURN         = 0x0D;
264 const unsigned long LL_DOM_VK_ENTER          = 0x0E;
265 const unsigned long LL_DOM_VK_SHIFT          = 0x10;
266 const unsigned long LL_DOM_VK_CONTROL        = 0x11;
267 const unsigned long LL_DOM_VK_ALT            = 0x12;
268 const unsigned long LL_DOM_VK_PAUSE          = 0x13;
269 const unsigned long LL_DOM_VK_CAPS_LOCK      = 0x14;
270 const unsigned long LL_DOM_VK_ESCAPE         = 0x1B;
271 const unsigned long LL_DOM_VK_SPACE          = 0x20;
272 const unsigned long LL_DOM_VK_PAGE_UP        = 0x21;
273 const unsigned long LL_DOM_VK_PAGE_DOWN      = 0x22;
274 const unsigned long LL_DOM_VK_END            = 0x23;
275 const unsigned long LL_DOM_VK_HOME           = 0x24;
276 const unsigned long LL_DOM_VK_LEFT           = 0x25;
277 const unsigned long LL_DOM_VK_UP             = 0x26;
278 const unsigned long LL_DOM_VK_RIGHT          = 0x27;
279 const unsigned long LL_DOM_VK_DOWN           = 0x28;
280 const unsigned long LL_DOM_VK_PRINTSCREEN    = 0x2C;
281 const unsigned long LL_DOM_VK_INSERT         = 0x2D;
282 const unsigned long LL_DOM_VK_DELETE         = 0x2E;
283
284 // LL_DOM_VK_0 - LL_DOM_VK_9 match their ASCII values
285 const unsigned long LL_DOM_VK_0              = 0x30;
286 const unsigned long LL_DOM_VK_1              = 0x31;
287 const unsigned long LL_DOM_VK_2              = 0x32;
288 const unsigned long LL_DOM_VK_3              = 0x33;
289 const unsigned long LL_DOM_VK_4              = 0x34;
290 const unsigned long LL_DOM_VK_5              = 0x35;
291 const unsigned long LL_DOM_VK_6              = 0x36;
292 const unsigned long LL_DOM_VK_7              = 0x37;
293 const unsigned long LL_DOM_VK_8              = 0x38;
294 const unsigned long LL_DOM_VK_9              = 0x39;
295
296 const unsigned long LL_DOM_VK_SEMICOLON      = 0x3B;
297 const unsigned long LL_DOM_VK_EQUALS         = 0x3D;
298
299 // LL_DOM_VK_A - LL_DOM_VK_Z match their ASCII values
300 const unsigned long LL_DOM_VK_A              = 0x41;
301 const unsigned long LL_DOM_VK_B              = 0x42;
302 const unsigned long LL_DOM_VK_C              = 0x43;
303 const unsigned long LL_DOM_VK_D              = 0x44;
304 const unsigned long LL_DOM_VK_E              = 0x45;
305 const unsigned long LL_DOM_VK_F              = 0x46;
306 const unsigned long LL_DOM_VK_G              = 0x47;
307 const unsigned long LL_DOM_VK_H              = 0x48;
308 const unsigned long LL_DOM_VK_I              = 0x49;
309 const unsigned long LL_DOM_VK_J              = 0x4A;
310 const unsigned long LL_DOM_VK_K              = 0x4B;
311 const unsigned long LL_DOM_VK_L              = 0x4C;
312 const unsigned long LL_DOM_VK_M              = 0x4D;
313 const unsigned long LL_DOM_VK_N              = 0x4E;
314 const unsigned long LL_DOM_VK_O              = 0x4F;
315 const unsigned long LL_DOM_VK_P              = 0x50;
316 const unsigned long LL_DOM_VK_Q              = 0x51;
317 const unsigned long LL_DOM_VK_R              = 0x52;
318 const unsigned long LL_DOM_VK_S              = 0x53;
319 const unsigned long LL_DOM_VK_T              = 0x54;
320 const unsigned long LL_DOM_VK_U              = 0x55;
321 const unsigned long LL_DOM_VK_V              = 0x56;
322 const unsigned long LL_DOM_VK_W              = 0x57;
323 const unsigned long LL_DOM_VK_X              = 0x58;
324 const unsigned long LL_DOM_VK_Y              = 0x59;
325 const unsigned long LL_DOM_VK_Z              = 0x5A;
326
327 const unsigned long LL_DOM_VK_CONTEXT_MENU   = 0x5D;
328
329 const unsigned long LL_DOM_VK_NUMPAD0        = 0x60;
330 const unsigned long LL_DOM_VK_NUMPAD1        = 0x61;
331 const unsigned long LL_DOM_VK_NUMPAD2        = 0x62;
332 const unsigned long LL_DOM_VK_NUMPAD3        = 0x63;
333 const unsigned long LL_DOM_VK_NUMPAD4        = 0x64;
334 const unsigned long LL_DOM_VK_NUMPAD5        = 0x65;
335 const unsigned long LL_DOM_VK_NUMPAD6        = 0x66;
336 const unsigned long LL_DOM_VK_NUMPAD7        = 0x67;
337 const unsigned long LL_DOM_VK_NUMPAD8        = 0x68;
338 const unsigned long LL_DOM_VK_NUMPAD9        = 0x69;
339 const unsigned long LL_DOM_VK_MULTIPLY       = 0x6A;
340 const unsigned long LL_DOM_VK_ADD            = 0x6B;
341 const unsigned long LL_DOM_VK_SEPARATOR      = 0x6C;
342 const unsigned long LL_DOM_VK_SUBTRACT       = 0x6D;
343 const unsigned long LL_DOM_VK_DECIMAL        = 0x6E;
344 const unsigned long LL_DOM_VK_DIVIDE         = 0x6F;
345 const unsigned long LL_DOM_VK_F1             = 0x70;
346 const unsigned long LL_DOM_VK_F2             = 0x71;
347 const unsigned long LL_DOM_VK_F3             = 0x72;
348 const unsigned long LL_DOM_VK_F4             = 0x73;
349 const unsigned long LL_DOM_VK_F5             = 0x74;
350 const unsigned long LL_DOM_VK_F6             = 0x75;
351 const unsigned long LL_DOM_VK_F7             = 0x76;
352 const unsigned long LL_DOM_VK_F8             = 0x77;
353 const unsigned long LL_DOM_VK_F9             = 0x78;
354 const unsigned long LL_DOM_VK_F10            = 0x79;
355 const unsigned long LL_DOM_VK_F11            = 0x7A;
356 const unsigned long LL_DOM_VK_F12            = 0x7B;
357 const unsigned long LL_DOM_VK_F13            = 0x7C;
358 const unsigned long LL_DOM_VK_F14            = 0x7D;
359 const unsigned long LL_DOM_VK_F15            = 0x7E;
360 const unsigned long LL_DOM_VK_F16            = 0x7F;
361 const unsigned long LL_DOM_VK_F17            = 0x80;
362 const unsigned long LL_DOM_VK_F18            = 0x81;
363 const unsigned long LL_DOM_VK_F19            = 0x82;
364 const unsigned long LL_DOM_VK_F20            = 0x83;
365 const unsigned long LL_DOM_VK_F21            = 0x84;
366 const unsigned long LL_DOM_VK_F22            = 0x85;
367 const unsigned long LL_DOM_VK_F23            = 0x86;
368 const unsigned long LL_DOM_VK_F24            = 0x87;
369
370 const unsigned long LL_DOM_VK_NUM_LOCK       = 0x90;
371 const unsigned long LL_DOM_VK_SCROLL_LOCK    = 0x91;
372
373 const unsigned long LL_DOM_VK_COMMA          = 0xBC;
374 const unsigned long LL_DOM_VK_PERIOD         = 0xBE;
375 const unsigned long LL_DOM_VK_SLASH          = 0xBF;
376 const unsigned long LL_DOM_VK_BACK_QUOTE     = 0xC0;
377 const unsigned long LL_DOM_VK_OPEN_BRACKET   = 0xDB;
378 const unsigned long LL_DOM_VK_BACK_SLASH     = 0xDC;
379 const unsigned long LL_DOM_VK_CLOSE_BRACKET  = 0xDD;
380 const unsigned long LL_DOM_VK_QUOTE          = 0xDE;
381
382 const unsigned long LL_DOM_VK_META           = 0xE0;
383
384 #endif // LLMOZLIB_H
Note: See TracBrowser for help on using the browser.