00001
00032 #ifndef LL_LLWEBBROWSERCTRL_H
00033 #define LL_LLWEBBROWSERCTRL_H
00034
00035 #include "lluictrlfactory.h"
00036
00038
00039 class LLWebBrowserCtrlEvent
00040 {
00041 public:
00042 LLWebBrowserCtrlEvent()
00043 {
00044 };
00045
00046 LLWebBrowserCtrlEvent( int intValIn ) :
00047 mIntVal( intValIn )
00048 {
00049 };
00050
00051 LLWebBrowserCtrlEvent( std::string stringValIn ) :
00052 mStringVal( stringValIn )
00053 {
00054 };
00055
00056 virtual ~LLWebBrowserCtrlEvent()
00057 {
00058 };
00059
00060 int getIntValue() const
00061 {
00062 return mIntVal;
00063 };
00064
00065 std::string getStringValue() const
00066 {
00067 return mStringVal;
00068 };
00069
00070 private:
00071 int mIntVal;
00072 std::string mStringVal;
00073 };
00074
00076
00077
00078 class LLWebBrowserCtrlObserver
00079 {
00080 public:
00081 virtual ~LLWebBrowserCtrlObserver() { };
00082
00083 typedef LLWebBrowserCtrlEvent EventType;
00084 virtual void onNavigateBegin( const EventType& eventIn ) { };
00085 virtual void onNavigateComplete( const EventType& eventIn ) { };
00086 virtual void onUpdateProgress( const EventType& eventIn ) { };
00087 virtual void onStatusTextChange( const EventType& eventIn ) { };
00088 virtual void onLocationChange( const EventType& eventIn ) { };
00089 virtual void onClickLinkHref( const EventType& eventIn ) { };
00090 virtual void onClickLinkSecondLife( const EventType& eventIn ) { };
00091 };
00092
00093 #if LL_LIBXUL_ENABLED
00094
00095 #include "lluictrl.h"
00096 #include "llframetimer.h"
00097 #include "lldynamictexture.h"
00098 #include "llmozlib.h"
00099
00100 class LLViewBorder;
00101 class LLWebBrowserTexture;
00102
00104
00105
00106 template< class T >
00107 class LLWebBrowserCtrlEventEmitter
00108 {
00109 public:
00110 LLWebBrowserCtrlEventEmitter() { };
00111 ~LLWebBrowserCtrlEventEmitter() { };
00112
00113 typedef typename T::EventType EventType;
00114 typedef std::list< T* > ObserverContainer;
00115 typedef void( T::*observerMethod )( const EventType& );
00116
00118
00119 bool addObserver( T* observerIn )
00120 {
00121 if ( ! observerIn )
00122 return false;
00123
00124 if ( std::find( observers.begin(), observers.end(), observerIn ) != observers.end() )
00125 return false;
00126
00127 observers.push_back( observerIn );
00128
00129 return true;
00130 };
00131
00133
00134 bool remObserver( T* observerIn )
00135 {
00136 if ( ! observerIn )
00137 return false;
00138
00139 observers.remove( observerIn );
00140
00141 return true;
00142 };
00143
00145
00146 void update( observerMethod method, const EventType& msgIn )
00147 {
00148 typename std::list< T* >::iterator iter = observers.begin();
00149
00150 while( iter != observers.end() )
00151 {
00152 ( ( *iter )->*method )( msgIn );
00153
00154 ++iter;
00155 };
00156 };
00157
00158 protected:
00159 ObserverContainer observers;
00160 };
00161
00162 class LLUICtrlFactory;
00163
00165
00166 class LLWebBrowserCtrl :
00167 public LLUICtrl,
00168 public LLEmbeddedBrowserWindowObserver
00169 {
00170 public:
00171 LLWebBrowserCtrl( const std::string& name, const LLRect& rect );
00172 virtual ~LLWebBrowserCtrl();
00173
00174 void setBorderVisible( BOOL border_visible );
00175
00176 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
00177
00178
00179 virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_WEBBROWSER; }
00180 virtual LLString getWidgetTag() const { return LL_WEB_BROWSER_CTRL_TAG; }
00181
00182
00183 virtual BOOL handleHover( S32 x, S32 y, MASK mask );
00184 virtual BOOL handleMouseUp( S32 x, S32 y, MASK mask );
00185 virtual BOOL handleMouseDown( S32 x, S32 y, MASK mask );
00186 virtual BOOL handleScrollWheel( S32 x, S32 y, S32 clicks );
00187
00188
00189 void navigateTo( std::string urlIn );
00190 void navigateBack();
00191 void navigateHome();
00192 void navigateForward();
00193 bool canNavigateBack();
00194 bool canNavigateForward();
00195 void setOpenInExternalBrowser( bool valIn );
00196 void setOpenInInternalBrowser( bool valIn );
00197 void setOpenSLURLsInMap( bool valIn );
00198 void setOpenSLURLsViaTeleport( bool valIn );
00199 void setHomePageUrl( const std::string urlIn );
00200 std::string getHomePageUrl();
00201
00202
00203 bool set404RedirectUrl( std::string redirect_url );
00204 bool clr404RedirectUrl();
00205
00206
00207 bool getFrequentUpdates() { return mFrequentUpdates; };
00208 void setFrequentUpdates( bool frequentUpdatesIn ) { mFrequentUpdates = frequentUpdatesIn; };
00209
00210 void setIgnoreUIScale(bool ignore) { mIgnoreUIScale = ignore; }
00211 bool getIgnoreUIScale() { return mIgnoreUIScale; }
00212
00213 void setAlwaysRefresh(bool refresh) { mAlwaysRefresh = refresh; }
00214 bool getAlwaysRefresh() { return mAlwaysRefresh; }
00215
00216
00217 virtual BOOL handleKey( KEY key, MASK mask, BOOL called_from_parent );
00218 virtual BOOL handleUnicodeChar(llwchar uni_char, BOOL called_from_parent);
00219 virtual void reshape( S32 width, S32 height, BOOL called_from_parent );
00220 virtual void draw();
00221 virtual void onVisibilityChange ( BOOL curVisibilityIn );
00222
00223
00224 void onFocusLost();
00225 void onFocusReceived();
00226
00227
00228 bool addObserver( LLWebBrowserCtrlObserver* subjectIn );
00229 bool remObserver( LLWebBrowserCtrlObserver* subjectIn );
00230
00231
00232 virtual void onNavigateBegin( const EventType& eventIn );
00233 virtual void onNavigateComplete( const EventType& eventIn );
00234 virtual void onUpdateProgress( const EventType& eventIn );
00235 virtual void onStatusTextChange( const EventType& eventIn );
00236 virtual void onLocationChange( const EventType& eventIn );
00237 virtual void onClickLinkHref( const EventType& eventIn );
00238 virtual void onClickLinkSecondLife( const EventType& eventIn );
00239
00240 protected:
00241 void convertInputCoords(S32& x, S32& y);
00242
00243 private:
00244 LLWebBrowserCtrlEventEmitter< LLWebBrowserCtrlObserver > mEventEmitter;
00245 const S32 mTextureDepthBytes;
00246 int mEmbeddedBrowserWindowId;
00247 LLWebBrowserTexture* mWebBrowserImage;
00248 LLViewBorder* mBorder;
00249 bool mFrequentUpdates;
00250 bool mOpenLinksInExternalBrowser;
00251 bool mOpenLinksInInternalBrowser;
00252 bool mOpenSLURLsInMap;
00253 bool mOpenSLURLsViaTeleport;
00254 std::string mHomePageUrl;
00255 bool mIgnoreUIScale;
00256 bool mAlwaysRefresh;
00257 };
00258
00260
00261 class LLWebBrowserTexture : public LLDynamicTexture
00262 {
00263 public:
00264 LLWebBrowserTexture( S32 width, S32 height, LLWebBrowserCtrl* browserCtrl, int browserWindow );
00265 virtual ~LLWebBrowserTexture();
00266
00267 virtual void preRender( BOOL clear_depth = TRUE ) {};
00268 virtual void postRender( BOOL success ) {};
00269 virtual BOOL render();
00270
00271 S32 getBrowserWidth();
00272 S32 getBrowserHeight();
00273
00274 void resize( S32 new_width, S32 new_height );
00275
00276 protected:
00277 S32 mBrowserWidth;
00278 S32 mBrowserHeight;
00279 S32 mLastBrowserDepth;
00280 LLFrameTimer mElapsedTime;
00281 LLWebBrowserCtrl* mWebBrowserCtrl;
00282 int mEmbeddedBrowserWindowId;
00283 };
00284
00285 #endif // // LL_LIBXUL_ENABLED
00286
00287 #endif // LL_LLWEBBROWSERCTRL_H