root/trunk/llmozlib2/llembeddedbrowserwindow.h

Revision 15, 8.2 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 LLEMBEDDEDBROWSERWINDOW_H
40 #define LLEMBEDDEDBROWSERWINDOW_H
41
42 // Mozilla code has non-virtual destructors
43 #ifdef WIN32
44 #pragma warning( disable : 4265 ) // "class has virtual functions, but destructor is not virtual"
45 #endif
46
47 #include "nsIBaseWindow.h"
48 #include "nsIDOMEventListener.h"
49 #include "nsIDOMEventTarget.h"
50 #include "nsIInterfaceRequestor.h"
51 #include "nsIWebBrowserChrome.h"
52 #include "nsIWebNavigation.h"
53 #include "nsIWebProgressListener.h"
54 #include "nsIURIContentListener.h"
55 #include "nsWeakReference.h"
56 #include "nsIWebBrowser.h"
57 #include "nsIToolkit.h"
58 #include "nsIScriptGlobalObject.h"
59 #include "nsIScriptGlobalObjectOwner.h"
60 #include "nsIScriptContext.h"
61
62 #ifdef WIN32
63 #pragma warning( 3 : 4265 ) // "class has virtual functions, but destructor is not virtual"
64 #endif
65
66 #include <string>
67 #include <list>
68 #include <algorithm>
69
70 #include "llmozlib2.h"
71
72 ///////////////////////////////////////////////////////////////////////////////
73 // manages the process of storing and emitting events that the consumer
74 // of the embedding class can observe
75 template< class T >
76 class LLEmbeddedBrowserWindowEmitter
77 {
78         public:
79                 LLEmbeddedBrowserWindowEmitter() { };
80                 ~LLEmbeddedBrowserWindowEmitter() { };
81
82                 typedef typename T::EventType EventType;
83                 typedef std::list< T* > ObserverContainer;
84                 typedef void( T::*observerMethod )( const EventType& );
85
86                 ///////////////////////////////////////////////////////////////////////////////
87                 //
88                 bool addObserver( T* observerIn )
89                 {
90                         if ( ! observerIn )
91                                 return false;
92
93                         if ( std::find( observers.begin(), observers.end(), observerIn ) != observers.end() )
94                                 return false;
95
96                         observers.push_back( observerIn );
97
98                         return true;
99                 };
100
101                 ///////////////////////////////////////////////////////////////////////////////
102                 //
103                 bool remObserver( T* observerIn )
104                 {
105                         if ( ! observerIn )
106                                 return false;
107
108                         observers.remove( observerIn );
109
110                         return true;
111                 };
112
113                 ///////////////////////////////////////////////////////////////////////////////
114                 //
115                 void update( observerMethod method, const EventType& msgIn )
116                 {
117                         typename std::list< T* >::iterator iter = observers.begin();
118
119                         while( iter != observers.end() )
120                         {
121                                 ( ( *iter )->*method )( msgIn );
122
123                                 ++iter;
124                         };
125                 };
126
127         protected:
128                 ObserverContainer observers;
129 };
130
131 class LLEmbeddedBrowser;
132
133 ////////////////////////////////////////////////////////////////////////////////
134 // class for a "window" that holds a browser - there can be lots of these
135 class LLEmbeddedBrowserWindow :
136         public nsIInterfaceRequestor,
137         public nsIWebBrowserChrome,
138         public nsIWebProgressListener,
139         public nsIURIContentListener,
140         public nsSupportsWeakReference,
141         public nsIDOMEventListener,
142         public nsIToolkitObserver
143 {
144         public:
145                 LLEmbeddedBrowserWindow();
146                 virtual ~LLEmbeddedBrowserWindow();
147
148                 NS_DECL_ISUPPORTS
149                 NS_DECL_NSIINTERFACEREQUESTOR
150                 NS_DECL_NSIWEBBROWSERCHROME
151                 NS_DECL_NSIWEBPROGRESSLISTENER
152                 NS_DECL_NSIURICONTENTLISTENER
153                 NS_DECL_NSIDOMEVENTLISTENER
154                 NS_DECL_NSITOOLKITOBSERVER
155
156                 // housekeeping
157                 nsresult createBrowser( void* nativeWindowHandleIn, PRInt32 widthIn, PRInt32 heightIn, nsIWebBrowser** aBrowser );
158                 void setParent( LLEmbeddedBrowser* parentIn ) { mParent = parentIn; };
159                 PRBool setSize( PRInt16 widthIn, PRInt16 heightIn );
160                 void focusBrowser( PRBool focusBrowserIn );
161                 void scrollByLines( PRInt16 linesIn );
162                 void setWindowId( int windowIdIn );
163                 int getWindowId();
164
165                 // random accessors
166                 const PRInt16 getPercentComplete();
167                 const std::string& getStatusMsg();
168                 const std::string& getCurrentUri();
169                 const std::string& getClickLinkHref();
170                 const std::string& getClickLinkTarget();
171
172                 // memory buffer management
173                 unsigned char* grabWindow( int xIn, int yIn, int widthIn, int heightIn );
174                 PRBool flipWindow( PRBool flip );
175                 unsigned char* getPageBuffer();
176                 PRInt16 getBrowserWidth();
177                 PRInt16 getBrowserHeight();
178                 PRInt16 getBrowserDepth();
179                 PRInt32 getBrowserRowSpan();
180
181                 // set background color that you see in between pages - default is white but sometimes useful to change
182                 void setBackgroundColor( const PRUint8 redIn, const PRUint8 greenIn, const PRUint8 blueIn );
183
184                 // change the caret color (we have different backgrounds to edit fields - black caret on black background == bad)
185                 void setCaretColor( const PRUint8 redIn, const PRUint8 greenIn, const PRUint8 blueIn );
186
187                 // can turn off updates to a page - e.g. when it's hidden by your windowing system
188                 void setEnabled( PRBool enabledIn );
189
190                 // navigation
191                 void navigateStop();
192                 PRBool navigateTo( const std::string uriIn );
193                 PRBool canNavigateBack();
194                 void navigateBack();
195                 PRBool canNavigateForward();
196                 void navigateForward();
197                 void navigateReload();
198
199                 // javascript access/control
200                 std::string evaluateJavascript( std::string scriptIn );
201
202                 // redirection when you hit a missing page
203                 bool set404RedirectUrl( std::string redirect_url );
204                 bool clr404RedirectUrl();
205
206                 // mouse & keyboard events
207                 void mouseDown( PRInt16 xPosIn, PRInt16 yPosIn );
208                 void mouseUp( PRInt16 xPosIn, PRInt16 yPosIn );
209                 void mouseMove( PRInt16 xPosIn, PRInt16 yPosIn );
210                 void mouseLeftDoubleClick( PRInt16 xPosIn, PRInt16 yPosIn );
211                 void keyPress( PRInt16 keyCode );
212                 void unicodeInput( PRUint32 uni_char );
213
214                 // allow consumers of this class and to observe browser events
215                 bool addObserver( LLEmbeddedBrowserWindowObserver* observerIn );
216                 bool remObserver( LLEmbeddedBrowserWindowObserver* observerIn );
217
218                 // accessor/mutator for scheme that browser doesn't follow - e.g. secondlife.com://
219                 void setNoFollowScheme( std::string schemeIn );
220                 std::string getNoFollowScheme();
221
222         private:
223                 PRBool sendMozillaMouseEvent( PRInt16 eventIn, PRInt16 xPosIn, PRInt16 yPosIn, PRUint32 clickCountIn );
224                 PRBool sendMozillaKeyboardEvent( PRUint32 keyIn, PRUint32 ns_vk_code );
225                 PRBool renderCaret();
226                 PRBool enableToolkitObserver( PRBool enableIn );
227
228                 LLEmbeddedBrowserWindowEmitter< LLEmbeddedBrowserWindowObserver > mEventEmitter;
229
230                 LLEmbeddedBrowser* mParent;
231                 PRInt16 mPercentComplete;
232                 std::string mStatusText;
233                 std::string mCurrentUri;
234                 std::string mClickHref;
235                 std::string mClickTarget;
236                 std::string mNoFollowScheme;
237                 nsCOMPtr< nsIWebBrowser > mWebBrowser;
238                 nsCOMPtr< nsIBaseWindow > mBaseWindow;
239                 nsCOMPtr< nsIWebNavigation > mWebNav;
240                 int mWindowId;
241                 unsigned char* mPageBuffer;
242                 std::string m404RedirectUrl;
243                 PRBool mEnabled;
244                 PRBool mFlipBitmap;
245                 PRInt32 mBrowserRowSpan;
246                 PRInt16 mBrowserWidth;
247                 PRInt16 mBrowserHeight;
248                 PRInt16 mBrowserDepth;
249                 PRUint8 mBkgRed;
250                 PRUint8 mBkgGreen;
251                 PRUint8 mBkgBlue;
252                 PRUint8 mCaretRed;
253                 PRUint8 mCaretGreen;
254                 PRUint8 mCaretBlue;
255 };
256
257 #endif // LLEMBEDEDDBROWSERWINDOW_H
Note: See TracBrowser for help on using the browser.