llfloaterhtml.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llfloaterhtml.h"
00035 
00036 // viewer includes
00037 #include "llvieweruictrlfactory.h"
00038 #include "llviewercontrol.h"
00039 #include "lllineeditor.h"
00040 
00041 #include "llwebbrowserctrl.h"
00042 
00043 LLFloaterHtml* LLFloaterHtml::sInstance = 0;
00044 
00046 //
00047 LLFloaterHtml* LLFloaterHtml::getInstance()
00048 {
00049     if ( ! sInstance )
00050         sInstance = new LLFloaterHtml;
00051 
00052         return sInstance;
00053 }
00054 
00056 //
00057 LLFloaterHtml::LLFloaterHtml()
00058 :       LLFloater( "HTML Floater" )
00059 
00060 #if LL_LIBXUL_ENABLED
00061         ,
00062         mWebBrowser( 0 )
00063 #endif // LL_LIBXUL_ENABLED
00064 {
00065         // create floater from its XML definition
00066         gUICtrlFactory->buildFloater( this, "floater_html.xml" );
00067 
00068         childSetAction("back_btn", onClickBack, this);
00069         childSetAction("home_btn", onClickHome, this);
00070         childSetAction("forward_btn", onClickForward, this);
00071         childSetAction("close_btn", onClickClose, this);
00072         childSetCommitCallback("url_edit", onCommitUrlEdit, this );
00073         childSetAction("go_btn", onClickGo, this );
00074 
00075         // reposition floater from saved settings
00076         LLRect rect = gSavedSettings.getRect( "HtmlFloaterRect" );
00077         reshape( rect.getWidth(), rect.getHeight(), FALSE );
00078         setRect( rect );
00079 
00080 #if LL_LIBXUL_ENABLED
00081         mWebBrowser = LLViewerUICtrlFactory::getWebBrowserByName(this,  "html_floater_browser" );
00082         if ( mWebBrowser )
00083         {
00084                 // open links in internal browser
00085                 mWebBrowser->setOpenInExternalBrowser( false );
00086 
00087                 // don't automatically open secondlife links since we want to catch
00088                 // special ones that do other stuff (like open F1 Help)
00089                 mWebBrowser->setOpenSLURLsInMap( false );
00090         }
00091 #endif // LL_LIBXUL_ENABLED
00092 }
00093 
00095 //
00096 LLFloaterHtml::~LLFloaterHtml()
00097 {
00098         // save position of floater
00099         gSavedSettings.setRect( "HtmlFloaterRect", mRect );
00100 
00101         sInstance = 0;
00102 }
00103 
00105 // virtual 
00106 void LLFloaterHtml::draw()
00107 {
00108 #if LL_LIBXUL_ENABLED
00109         // enable/disable buttons depending on state
00110         if ( mWebBrowser )
00111         {
00112                 bool enable_back = mWebBrowser->canNavigateBack();      
00113                 childSetEnabled( "back_btn", enable_back );
00114 
00115                 bool enable_forward = mWebBrowser->canNavigateForward();        
00116                 childSetEnabled( "forward_btn", enable_forward );
00117         };
00118 #endif // LL_LIBXUL_ENABLED
00119 
00120         LLFloater::draw();
00121 }
00122 
00124 //
00125 void LLFloaterHtml::show( LLString content_id )
00126 {
00127         // calculate the XML labels we'll need (if only XML folders worked)
00128         LLString title_str = content_id + "_title";
00129         LLString url_str = content_id + "_url";
00130 
00131         std::string title = childGetValue( title_str ).asString();
00132         std::string url = childGetValue( url_str ).asString();
00133         show( url, title );
00134 }
00135 
00137 //
00138 void LLFloaterHtml::show( std::string start_url, std::string title )
00139 {
00140         // set the title 
00141         setTitle( title );
00142 
00143 #if LL_LIBXUL_ENABLED
00144         // navigate to the URL
00145         if ( mWebBrowser )
00146                 mWebBrowser->navigateTo( start_url );
00147 #endif // LL_LIBXUL_ENABLED
00148 
00149         // make floater appear
00150         setVisibleAndFrontmost();
00151 }
00152 
00154 //
00155 void LLFloaterHtml::onClose( bool app_quitting )
00156 {
00157         setVisible( false );
00158 }
00159 
00161 //
00162 void LLFloaterHtml::onClickClose( void* data )
00163 {
00164         LLFloaterHtml* self = ( LLFloaterHtml* )data;
00165 
00166         self->setVisible( false );
00167 }
00168 
00170 // static
00171 void LLFloaterHtml::onClickBack( void* data )
00172 {
00173 #if LL_LIBXUL_ENABLED
00174         LLFloaterHtml* self = ( LLFloaterHtml* )data;
00175         if ( self )
00176         {
00177                 if ( self->mWebBrowser )
00178                 {
00179                         self->mWebBrowser->navigateBack();
00180                 };
00181         };
00182 #endif // LL_LIBXUL_ENABLED
00183 }
00184 
00186 //
00187 void LLFloaterHtml::onClickHome( void* data )
00188 {
00189         LLFloaterHtml* self = ( LLFloaterHtml* )data;
00190         if ( self )
00191         {
00192 #if LL_LIBXUL_ENABLED
00193                 if ( self->mWebBrowser )
00194                 {
00195                         std::string home_url = self->childGetText("home_page_url");
00196                         if ( home_url.length() > 4 )
00197                         {
00198                                 self->mWebBrowser->navigateTo( home_url );
00199                         }
00200                         else
00201                         {
00202                                 llwarns << "Invalid home page specified for HTML floater - navigating to default" << llendl;
00203                                 self->mWebBrowser->navigateTo( "http://google.com" );
00204                         }
00205                 };
00206 #endif // LL_LIBXUL_ENABLED
00207         };
00208 }
00209 
00211 // static
00212 void LLFloaterHtml::onClickForward( void* data )
00213 {
00214         LLFloaterHtml* self = ( LLFloaterHtml* )data;
00215         if ( self )
00216         {
00217 #if LL_LIBXUL_ENABLED
00218                 if ( self->mWebBrowser )
00219                 {
00220                         self->mWebBrowser->navigateForward();
00221                 };
00222 #endif // LL_LIBXUL_ENABLED
00223         };
00224 }
00225 
00227 // static
00228 void LLFloaterHtml::onCommitUrlEdit(LLUICtrl* ctrl, void* user_data)
00229 {
00230 #if LL_LIBXUL_ENABLED
00231         LLFloaterHtml* self = (LLFloaterHtml*)user_data;
00232 
00233         LLLineEditor* editor = (LLLineEditor*)ctrl;
00234         std::string url = editor->getText();
00235 
00236         if ( self->mWebBrowser )
00237         {
00238                 self->mWebBrowser->navigateTo( url );
00239         };
00240 #endif // LL_LIBXUL_ENABLED
00241 }
00242 
00244 //  static
00245 void LLFloaterHtml::onClickGo( void* data )
00246 {
00247         LLFloaterHtml* self = ( LLFloaterHtml* )data;
00248         if ( self )
00249         {
00250                 std::string url = self->childGetValue( "url_edit" ).asString();
00251                 if ( url.length() )
00252                 {
00253 #if LL_LIBXUL_ENABLED
00254                         if ( self->mWebBrowser )
00255                         {
00256                                 self->mWebBrowser->navigateTo( url );
00257                         };
00258 #endif // LL_LIBXUL_ENABLED
00259                 };
00260         };
00261 }

Generated on Thu Jul 1 06:08:34 2010 for Second Life Viewer by  doxygen 1.4.7