root/trunk/llmozlib2/llembeddedbrowserwindow.h

Revision 8, 8.2 kB (checked in by rob.linden, 2 years ago)

Latest internal snapshot
Last Changed Rev: 80909
Last Changed Date: 2008-02-27 15:08:55 -0800 (Wed, 27 Feb 2008)

  • 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
198                 // javascript access/control
199                 std::string evaluateJavascript( std::string scriptIn );
200
201                 // redirection when you hit a missing page
202                 bool set404RedirectUrl( std::string redirect_url );
203                 bool clr404RedirectUrl();
204
205                 // mouse & keyboard events
206                 void mouseDown( PRInt16 xPosIn, PRInt16 yPosIn );
207                 void mouseUp( PRInt16 xPosIn, PRInt16 yPosIn );
208                 void mouseMove( PRInt16 xPosIn, PRInt16 yPosIn );
209                 void mouseLeftDoubleClick( PRInt16 xPosIn, PRInt16 yPosIn );
210                 void keyPress( PRInt16 keyCode );
211                 void unicodeInput( PRUint32 uni_char );
212
213                 // allow consumers of this class and to observe browser events
214                 bool addObserver( LLEmbeddedBrowserWindowObserver* observerIn );
215                 bool remObserver( LLEmbeddedBrowserWindowObserver* observerIn );
216
217                 // accessor/mutator for scheme that browser doesn't follow - e.g. secondlife.com://
218                 void setNoFollowScheme( std::string schemeIn );
219                 std::string getNoFollowScheme();
220
221         private:
222                 PRBool sendMozillaMouseEvent( PRInt16 eventIn, PRInt16 xPosIn, PRInt16 yPosIn, PRUint32 clickCountIn );
223                 PRBool sendMozillaKeyboardEvent( PRUint32 keyIn, PRUint32 ns_vk_code );
224                 PRBool renderCaret();
225                 PRBool enableToolkitObserver( PRBool enableIn );
226
227                 LLEmbeddedBrowserWindowEmitter< LLEmbeddedBrowserWindowObserver > mEventEmitter;
228
229                 LLEmbeddedBrowser* mParent;
230                 PRInt16 mPercentComplete;
231                 std::string mStatusText;
232                 std::string mCurrentUri;
233                 std::string mClickHref;
234                 std::string mClickTarget;
235                 std::string mNoFollowScheme;
236                 nsCOMPtr< nsIWebBrowser > mWebBrowser;
237                 nsCOMPtr< nsIBaseWindow > mBaseWindow;
238                 nsCOMPtr< nsIWebNavigation > mWebNav;
239                 int mWindowId;
240                 unsigned char* mPageBuffer;
241                 std::string m404RedirectUrl;
242                 PRBool mEnabled;
243                 PRBool mFlipBitmap;
244                 PRInt32 mBrowserRowSpan;
245                 PRInt16 mBrowserWidth;
246                 PRInt16 mBrowserHeight;
247                 PRInt16 mBrowserDepth;
248                 PRUint8 mBkgRed;
249                 PRUint8 mBkgGreen;
250                 PRUint8 mBkgBlue;
251                 PRUint8 mCaretRed;
252                 PRUint8 mCaretGreen;
253                 PRUint8 mCaretBlue;
254 };
255
256 #endif // LLEMBEDEDDBROWSERWINDOW_H
Note: See TracBrowser for help on using the browser.