root/trunk/llmozlib2/llembeddedbrowserwindow.h

Revision 3, 6.5 kB (checked in by rob.linden, 2 years ago)

I believe this is the version included in 1.18.6.3
Last Changed Rev: 76367
Last Changed Date: 2007-12-21 09:34:18 -0800 (Fri, 21 Dec 2007)

  • Property svn:eol-style set to native
Line 
1 /**
2  * @file llembeddedbrowserwindow.h
3  * @brief LLEmbeddedBrowserWindow and associated helpers declaration.
4  *
5  * $LicenseInfo:firstyear=2006&license=viewergpl$
6  *
7  * Copyright (c) 2006-2007, Linden Research, Inc.
8  *
9  * Second Life Viewer Source Code
10  * The source code in this file ("Source Code") is provided by Linden Lab
11  * to you under the terms of the GNU General Public License, version 2.0
12  * ("GPL"), unless you have obtained a separate licensing agreement
13  * ("Other License"), formally executed by you and Linden Lab.  Terms of
14  * the GPL can be found in doc/GPL-license.txt in this distribution, or
15  * online at http://secondlife.com/developers/opensource/gplv2
16  *
17  * There are special exceptions to the terms and conditions of the GPL as
18  * it is applied to this Source Code. View the full text of the exception
19  * in the file doc/FLOSS-exception.txt in this software distribution, or
20  * online at http://secondlife.com/developers/opensource/flossexception
21  *
22  * By copying, modifying or distributing this software, you acknowledge
23  * that you have read and understood your obligations described above,
24  * and agree to abide by those obligations.
25  *
26  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28  * COMPLETENESS OR PERFORMANCE.
29  * $/LicenseInfo$
30  */
31
32 #ifndef LLEMBEDDEDBROWSERWINDOW_H
33 #define LLEMBEDDEDBROWSERWINDOW_H
34
35 // Mozilla code has non-virtual destructors
36 #ifdef WIN32
37 #pragma warning( disable : 4265 ) // "class has virtual functions, but destructor is not virtual"
38 #endif
39
40 #include "nsIBaseWindow.h"
41 #include "nsIDOMEventListener.h"
42 #include "nsIDOMEventTarget.h"
43 #include "nsIInterfaceRequestor.h"
44 #include "nsIWebBrowserChrome.h"
45 #include "nsIWebNavigation.h"
46 #include "nsIWebProgressListener.h"
47 #include "nsIURIContentListener.h"
48 #include "nsWeakReference.h"
49 #include "nsIWebBrowser.h"
50
51 #include <string>
52 #include <list>
53 #include <algorithm>
54
55 #include "llmozlib.h"
56
57 ///////////////////////////////////////////////////////////////////////////////
58 // manages the process of sotring and emitting events that the consumer
59 // of the embedding class can observe
60 template< class T >
61 class LLEmbeddedBrowserWindowEmitter
62 {
63         public:
64                 LLEmbeddedBrowserWindowEmitter() { };
65                 ~LLEmbeddedBrowserWindowEmitter() { };
66
67                 typedef typename T::EventType EventType;
68                 typedef std::list< T* > ObserverContainer;
69                 typedef void( T::*observerMethod )( const EventType& );
70
71                 ///////////////////////////////////////////////////////////////////////////////
72                 //
73                 bool addObserver( T* observerIn )
74                 {
75                         if ( ! observerIn )
76                                 return false;
77
78                         if ( std::find( observers.begin(), observers.end(), observerIn ) != observers.end() )
79                                 return false;
80
81                         observers.push_back( observerIn );
82
83                         return true;
84                 };
85
86                 ///////////////////////////////////////////////////////////////////////////////
87                 //
88                 bool remObserver( T* observerIn )
89                 {
90                         if ( ! observerIn )
91                                 return false;
92
93                         observers.remove( observerIn );
94
95                         return true;
96                 };
97
98                 ///////////////////////////////////////////////////////////////////////////////
99                 //
100                 void update( observerMethod method, const EventType& msgIn )
101                 {
102                         typename std::list< T* >::iterator iter = observers.begin();
103
104                         while( iter != observers.end() )
105                         {
106                                 ( ( *iter )->*method )( msgIn );
107
108                                 ++iter;
109                         };
110                 };
111
112         protected:
113                 ObserverContainer observers;
114 };
115
116 class LLEmbeddedBrowser;
117
118 ////////////////////////////////////////////////////////////////////////////////
119 // class for a "window" that holds a browser - there can be lots of these
120 class LLEmbeddedBrowserWindow :
121         public nsIInterfaceRequestor,
122         public nsIWebBrowserChrome,
123         public nsIWebProgressListener,
124         public nsIURIContentListener,
125         public nsSupportsWeakReference,
126         public nsIDOMEventListener
127 {
128         public:
129                 LLEmbeddedBrowserWindow();
130                 virtual ~LLEmbeddedBrowserWindow();
131
132                 NS_DECL_ISUPPORTS
133                 NS_DECL_NSIINTERFACEREQUESTOR
134                 NS_DECL_NSIWEBBROWSERCHROME
135                 NS_DECL_NSIWEBPROGRESSLISTENER
136                 NS_DECL_NSIURICONTENTLISTENER
137                 NS_DECL_NSIDOMEVENTLISTENER
138
139                 nsresult createBrowser( void* nativeWindowHandleIn, PRInt32 widthIn, PRInt32 heightIn, nsIWebBrowser** aBrowser );
140                 PRBool setSize( PRInt16 widthIn, PRInt16 heightIn );
141                 void focusBrowser( PRBool focusBrowserIn );
142                 void scrollByLines( PRInt16 linesIn );
143                 void setWindowId( int windowIdIn );
144                 int getWindowId();
145
146                 const PRInt16 getPercentComplete();
147                 const std::string& getStatusMsg();
148                 const std::string& getCurrentUri();
149                 const std::string& getClickLinkHref();
150
151                 unsigned char* grabWindow();
152                 unsigned char* getPageBuffer();
153                 PRInt16 getBrowserWidth();
154                 PRInt16 getBrowserHeight();
155                 PRInt16 getBrowserDepth();
156                 PRInt32 getBrowserRowSpan();
157
158                 void setBackgroundColor( PRUint8 redIn, PRUint8 greenIn, PRUint8 blueIn );
159                 void setCaretColor( const PRUint8 redIn, const PRUint8 greenIn, const PRUint8 blueIn );
160
161                 void navigateStop();
162                 PRBool navigateTo( const std::string uriIn );
163                 PRBool canNavigateBack();
164                 void navigateBack();
165                 PRBool canNavigateForward();
166                 void navigateForward();
167
168                 bool set404RedirectUrl( std::string redirect_url );
169                 bool clr404RedirectUrl();
170
171                 void mouseDown( PRInt16 xPosIn, PRInt16 yPosIn );
172                 void mouseUp( PRInt16 xPosIn, PRInt16 yPosIn );
173                 void mouseMove( PRInt16 xPosIn, PRInt16 yPosIn );
174                 void mouseLeftDoubleClick( PRInt16 xPosIn, PRInt16 yPosIn );
175                 void keyPress( PRInt16 keyCode );
176                 void unicodeInput( PRUint32 uni_char );
177
178                 bool addObserver( LLEmbeddedBrowserWindowObserver* observerIn );
179                 bool remObserver( LLEmbeddedBrowserWindowObserver* observerIn );
180
181         private:
182                 PRBool sendMozillaMouseEvent( PRInt16 eventIn, PRInt16 xPosIn, PRInt16 yPosIn, PRUint32 clickCountIn );
183                 PRBool sendMozillaKeyboardEvent( PRUint32 keyIn, PRUint32 ns_vk_code );
184                 PRBool renderCaret();
185                 LLEmbeddedBrowserWindowEmitter< LLEmbeddedBrowserWindowObserver > mEventEmitter;
186                 PRInt16 mPercentComplete;
187                 std::string mStatusText;
188                 std::string mCurrentUri;
189                 std::string mClickHref;
190                 std::string m404RedirectUrl;
191
192                 nsCOMPtr< nsIWebBrowser > mWebBrowser;
193                 nsCOMPtr< nsIBaseWindow > mBaseWindow;
194                 nsCOMPtr< nsIWebNavigation > mWebNav;
195
196                 int mWindowId;
197
198                 PRUint8 mBackgroundRed;
199                 PRUint8 mBackgroundGreen;
200                 PRUint8 mBackgroundBlue;
201                 PRUint8 mCaretRed;
202                 PRUint8 mCaretGreen;
203                 PRUint8 mCaretBlue;
204
205                 unsigned char* mPageBuffer;
206                 size_t mPageBufferSize;
207                 PRInt32 mBrowserRowSpan;
208                 PRInt16 mBrowserWidth;
209                 PRInt16 mBrowserHeight;
210                 PRInt16 mBrowserDepth;
211 };
212
213 #ifdef WIN32
214 #pragma warning( 3 : 4265 ) // "class has virtual functions, but destructor is not virtual"
215 #endif
216
217 #endif // LLEMBEDEDDBROWSERWINDOW_H
Note: See TracBrowser for help on using the browser.