00001
00032 #ifndef LL_LLWEBBROWSERCTRL_H
00033 #define LL_LLWEBBROWSERCTRL_H
00034
00036
00037 class LLWebBrowserCtrlEvent
00038 {
00039 public:
00040 LLWebBrowserCtrlEvent()
00041 {
00042 };
00043
00044 LLWebBrowserCtrlEvent( int intValIn ) :
00045 mIntVal( intValIn )
00046 {
00047 };
00048
00049 LLWebBrowserCtrlEvent( std::string stringValIn ) :
00050 mIntVal(-1),
00051 mStringVal( stringValIn )
00052 {
00053 };
00054
00055 LLWebBrowserCtrlEvent( std::string stringValIn, std::string stringValExIn ) :
00056 mIntVal(-1),
00057 mStringVal( stringValIn ),
00058 mStringValEx( stringValExIn )
00059 {
00060 };
00061
00062 virtual ~LLWebBrowserCtrlEvent()
00063 {
00064 };
00065
00066 int getIntValue() const
00067 {
00068 return mIntVal;
00069 };
00070
00071 std::string getStringValue() const
00072 {
00073 return mStringVal;
00074 };
00075
00076 std::string getStringValueEx() const
00077 {
00078 return mStringValEx;
00079 };
00080
00081 private:
00082 int mIntVal;
00083 std::string mStringVal;
00084 std::string mStringValEx;
00085 };
00086
00088
00089
00090 class LLWebBrowserCtrlObserver
00091 {
00092 public:
00093 virtual ~LLWebBrowserCtrlObserver() { };
00094
00095 typedef LLWebBrowserCtrlEvent EventType;
00096 virtual void onNavigateBegin( const EventType& eventIn ) { };
00097 virtual void onNavigateComplete( const EventType& eventIn ) { };
00098 virtual void onUpdateProgress( const EventType& eventIn ) { };
00099 virtual void onStatusTextChange( const EventType& eventIn ) { };
00100 virtual void onLocationChange( const EventType& eventIn ) { };
00101 virtual void onClickLinkHref( const EventType& eventIn ) { };
00102 virtual void onClickLinkNoFollow( const EventType& eventIn ) { };
00103 };
00104
00105 #include "lluictrl.h"
00106 #include "llframetimer.h"
00107 #include "lldynamictexture.h"
00108 #include "llmediamanager.h"
00109 #include "llmediaobserver.h"
00110
00111 class LLViewBorder;
00112 class LLWebBrowserTexture;
00113
00115
00116
00117 template< class T >
00118 class LLWebBrowserCtrlEventEmitter
00119 {
00120 public:
00121 LLWebBrowserCtrlEventEmitter() { };
00122 ~LLWebBrowserCtrlEventEmitter() { };
00123
00124 typedef typename T::EventType EventType;
00125 typedef std::list< T* > ObserverContainer;
00126 typedef void( T::*observerMethod )( const EventType& );
00127
00129
00130 bool addObserver( T* observerIn )
00131 {
00132 if ( ! observerIn )
00133 return false;
00134
00135 if ( std::find( observers.begin(), observers.end(), observerIn ) != observers.end() )
00136 return false;
00137
00138 observers.push_back( observerIn );
00139
00140 return true;
00141 };
00142
00144
00145 bool remObserver( T* observerIn )
00146 {
00147 if ( ! observerIn )
00148 return false;
00149
00150 observers.remove( observerIn );
00151
00152 return true;
00153 };
00154
00156
00157 void update( observerMethod method, const EventType& msgIn )
00158 {
00159 typename std::list< T* >::iterator iter = observers.begin();
00160
00161 while( iter != observers.end() )
00162 {
00163 ( ( *iter )->*method )( msgIn );
00164
00165 ++iter;
00166 };
00167 };
00168
00169 protected:
00170 ObserverContainer observers;
00171 };
00172
00173 class LLUICtrlFactory;
00174
00176
00177 class LLWebBrowserCtrl :
00178 public LLUICtrl,
00179 public LLMediaObserver
00180 {
00181 public:
00182 LLWebBrowserCtrl( const std::string& name, const LLRect& rect );
00183 virtual ~LLWebBrowserCtrl();
00184
00185 void setBorderVisible( BOOL border_visible );
00186
00187
00188
00189
00190
00191 void setTakeFocusOnClick( bool take_focus );
00192
00193 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
00194
00195
00196 virtual BOOL handleHover( S32 x, S32 y, MASK mask );
00197 virtual BOOL handleMouseUp( S32 x, S32 y, MASK mask );
00198 virtual BOOL handleMouseDown( S32 x, S32 y, MASK mask );
00199 virtual BOOL handleDoubleClick( S32 x, S32 y, MASK mask );
00200 virtual BOOL handleScrollWheel( S32 x, S32 y, S32 clicks );
00201
00202
00203 void navigateTo( std::string urlIn );
00204 void navigateBack();
00205 void navigateHome();
00206 void navigateForward();
00207 void navigateToLocalPage( const std::string& subdir, const std::string& filename_in );
00208 bool canNavigateBack();
00209 bool canNavigateForward();
00210 void setOpenInExternalBrowser( bool valIn );
00211 void setOpenInInternalBrowser( bool valIn );
00212
00213
00214
00215
00216
00217
00218
00219 void setOpenAppSLURLs( bool valIn );
00220
00221 void setHomePageUrl( const std::string urlIn );
00222 std::string getHomePageUrl();
00223
00224
00225 bool set404RedirectUrl( std::string redirect_url );
00226 bool clr404RedirectUrl();
00227
00228
00229 bool getFrequentUpdates() { return mFrequentUpdates; };
00230 void setFrequentUpdates( bool frequentUpdatesIn ) { mFrequentUpdates = frequentUpdatesIn; };
00231
00232 void setIgnoreUIScale(bool ignore) { mIgnoreUIScale = ignore; }
00233 bool getIgnoreUIScale() { return mIgnoreUIScale; }
00234
00235 void setAlwaysRefresh(bool refresh) { mAlwaysRefresh = refresh; }
00236 bool getAlwaysRefresh() { return mAlwaysRefresh; }
00237
00238 void setForceUpdate(bool force_update) { mForceUpdate = force_update; }
00239 bool getForceUpdate() { return mForceUpdate; }
00240
00241 bool setCaretColor( unsigned int red, unsigned int green, unsigned int blue );
00242
00243
00244
00245 virtual BOOL handleKeyHere( KEY key, MASK mask);
00246 virtual BOOL handleUnicodeCharHere(llwchar uni_char);
00247 virtual void reshape( S32 width, S32 height, BOOL called_from_parent = TRUE);
00248 virtual void draw();
00249 virtual void onVisibilityChange ( BOOL curVisibilityIn );
00250
00251
00252 void onFocusLost();
00253 void onFocusReceived();
00254
00255
00256 bool addObserver( LLWebBrowserCtrlObserver* subjectIn );
00257 bool remObserver( LLWebBrowserCtrlObserver* subjectIn );
00258
00259
00260 virtual void onNavigateBegin( const EventType& eventIn );
00261 virtual void onNavigateComplete( const EventType& eventIn );
00262 virtual void onUpdateProgress( const EventType& eventIn );
00263 virtual void onStatusTextChange( const EventType& eventIn );
00264 virtual void onLocationChange( const EventType& eventIn );
00265 virtual void onClickLinkHref( const EventType& eventIn );
00266 virtual void onClickLinkNoFollow( const EventType& eventIn );
00267 virtual void onMediaContentsChange( const EventType& event_in );
00268
00269 protected:
00270 void convertInputCoords(S32& x, S32& y);
00271
00272 private:
00273 static void onClickLinkExternalTarget( S32 option, void* userdata );
00274
00275 LLWebBrowserCtrlEventEmitter< LLWebBrowserCtrlObserver > mEventEmitter;
00276 const S32 mTextureDepthBytes;
00277 int mEmbeddedBrowserWindowId;
00278 LLWebBrowserTexture* mWebBrowserImage;
00279 LLViewBorder* mBorder;
00280 bool mFrequentUpdates;
00281 bool mForceUpdate;
00282 bool mOpenLinksInExternalBrowser;
00283 bool mOpenLinksInInternalBrowser;
00284 bool mOpenAppSLURLs;
00285 std::string mHomePageUrl;
00286 std::string mExternalUrl;
00287 bool mIgnoreUIScale;
00288 bool mAlwaysRefresh;
00289 LLMediaBase* mMediaSource;
00290 bool mTakeFocusOnClick;
00291 };
00292
00294
00295 class LLWebBrowserTexture : public LLDynamicTexture
00296 {
00297 public:
00298 LLWebBrowserTexture( S32 width, S32 height, LLWebBrowserCtrl* browserCtrl, LLMediaBase *media_source );
00299 virtual ~LLWebBrowserTexture();
00300
00301 virtual BOOL needsRender();
00302 virtual void preRender( BOOL clear_depth = TRUE ) {};
00303 virtual void postRender( BOOL success ) {};
00304 virtual BOOL render();
00305
00306 S32 getBrowserWidth();
00307 S32 getBrowserHeight();
00308 void setNeedsUpdate();
00309
00310 void resize( S32 new_width, S32 new_height );
00311
00312 protected:
00313 S32 mBrowserWidth;
00314 S32 mBrowserHeight;
00315 S32 mLastBrowserDepth;
00316 bool mNeedsUpdate;
00317 LLFrameTimer mElapsedTime;
00318 LLWebBrowserCtrl* mWebBrowserCtrl;
00319 LLMediaBase *mMediaSource;
00320 };
00321
00322 #endif // LL_LLWEBBROWSERCTRL_H