diff options
Diffstat (limited to 'linden/indra/newview/llfloaterhtml.cpp')
-rw-r--r-- | linden/indra/newview/llfloaterhtml.cpp | 178 |
1 files changed, 137 insertions, 41 deletions
diff --git a/linden/indra/newview/llfloaterhtml.cpp b/linden/indra/newview/llfloaterhtml.cpp index 0c5bdcd..ebcf29f 100644 --- a/linden/indra/newview/llfloaterhtml.cpp +++ b/linden/indra/newview/llfloaterhtml.cpp | |||
@@ -2,6 +2,8 @@ | |||
2 | * @file llfloaterhtml.cpp | 2 | * @file llfloaterhtml.cpp |
3 | * @brief In-world HTML dialog | 3 | * @brief In-world HTML dialog |
4 | * | 4 | * |
5 | * $LicenseInfo:firstyear=2005&license=viewergpl$ | ||
6 | * | ||
5 | * Copyright (c) 2005-2007, Linden Research, Inc. | 7 | * Copyright (c) 2005-2007, Linden Research, Inc. |
6 | * | 8 | * |
7 | * Second Life Viewer Source Code | 9 | * Second Life Viewer Source Code |
@@ -24,15 +26,19 @@ | |||
24 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | 26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO |
25 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | 27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, |
26 | * COMPLETENESS OR PERFORMANCE. | 28 | * COMPLETENESS OR PERFORMANCE. |
29 | * $/LicenseInfo$ | ||
27 | */ | 30 | */ |
28 | 31 | ||
29 | #include "llviewerprecompiledheaders.h" | 32 | #include "llviewerprecompiledheaders.h" |
30 | 33 | ||
34 | #include "llfloaterhtml.h" | ||
35 | |||
36 | // viewer includes | ||
31 | #include "llvieweruictrlfactory.h" | 37 | #include "llvieweruictrlfactory.h" |
32 | #include "llviewerwindow.h" | ||
33 | #include "llviewercontrol.h" | 38 | #include "llviewercontrol.h" |
34 | #include "llfloaterhtml.h" | 39 | #include "lllineeditor.h" |
35 | #include "llfloaterhtmlhelp.h" | 40 | |
41 | #include "llwebbrowserctrl.h" | ||
36 | 42 | ||
37 | LLFloaterHtml* LLFloaterHtml::sInstance = 0; | 43 | LLFloaterHtml* LLFloaterHtml::sInstance = 0; |
38 | 44 | ||
@@ -59,6 +65,13 @@ LLFloaterHtml::LLFloaterHtml() | |||
59 | // create floater from its XML definition | 65 | // create floater from its XML definition |
60 | gUICtrlFactory->buildFloater( this, "floater_html.xml" ); | 66 | gUICtrlFactory->buildFloater( this, "floater_html.xml" ); |
61 | 67 | ||
68 | childSetAction("back_btn", onClickBack, this); | ||
69 | childSetAction("home_btn", onClickHome, this); | ||
70 | childSetAction("forward_btn", onClickForward, this); | ||
71 | childSetAction("close_btn", onClickClose, this); | ||
72 | childSetCommitCallback("url_edit", onCommitUrlEdit, this ); | ||
73 | childSetAction("go_btn", onClickGo, this ); | ||
74 | |||
62 | // reposition floater from saved settings | 75 | // reposition floater from saved settings |
63 | LLRect rect = gSavedSettings.getRect( "HtmlFloaterRect" ); | 76 | LLRect rect = gSavedSettings.getRect( "HtmlFloaterRect" ); |
64 | reshape( rect.getWidth(), rect.getHeight(), FALSE ); | 77 | reshape( rect.getWidth(), rect.getHeight(), FALSE ); |
@@ -68,32 +81,21 @@ LLFloaterHtml::LLFloaterHtml() | |||
68 | mWebBrowser = LLViewerUICtrlFactory::getWebBrowserByName(this, "html_floater_browser" ); | 81 | mWebBrowser = LLViewerUICtrlFactory::getWebBrowserByName(this, "html_floater_browser" ); |
69 | if ( mWebBrowser ) | 82 | if ( mWebBrowser ) |
70 | { | 83 | { |
71 | // observe browser events | 84 | // open links in internal browser |
72 | mWebBrowser->addObserver( this ); | 85 | mWebBrowser->setOpenInExternalBrowser( false ); |
73 | |||
74 | // make links open in external browser | ||
75 | mWebBrowser->setOpenInExternalBrowser( true ); | ||
76 | 86 | ||
77 | // don't automatically open secondlife links since we want to catch | 87 | // *FIX: code in merge sl-search-8 |
78 | // special ones that do other stuff (like open F1 Help) | 88 | // // don't automatically open secondlife links since we want to catch |
79 | mWebBrowser->setOpenSecondLifeLinksInMap( false ); | 89 | // // special ones that do other stuff (like open F1 Help) |
90 | // mWebBrowser->setOpenSLURLsInMap( false ); | ||
80 | } | 91 | } |
81 | #endif // LL_LIBXUL_ENABLED | 92 | #endif // LL_LIBXUL_ENABLED |
82 | |||
83 | childSetAction("close_btn", onClickClose, this); | ||
84 | setDefaultBtn("close_btn"); | ||
85 | } | 93 | } |
86 | 94 | ||
87 | //////////////////////////////////////////////////////////////////////////////// | 95 | //////////////////////////////////////////////////////////////////////////////// |
88 | // | 96 | // |
89 | LLFloaterHtml::~LLFloaterHtml() | 97 | LLFloaterHtml::~LLFloaterHtml() |
90 | { | 98 | { |
91 | #if LL_LIBXUL_ENABLED | ||
92 | // stop observing browser events | ||
93 | if ( mWebBrowser ) | ||
94 | mWebBrowser->remObserver( this ); | ||
95 | #endif // LL_LIBXUL_ENABLED | ||
96 | |||
97 | // save position of floater | 99 | // save position of floater |
98 | gSavedSettings.setRect( "HtmlFloaterRect", mRect ); | 100 | gSavedSettings.setRect( "HtmlFloaterRect", mRect ); |
99 | 101 | ||
@@ -101,6 +103,25 @@ LLFloaterHtml::~LLFloaterHtml() | |||
101 | } | 103 | } |
102 | 104 | ||
103 | //////////////////////////////////////////////////////////////////////////////// | 105 | //////////////////////////////////////////////////////////////////////////////// |
106 | // virtual | ||
107 | void LLFloaterHtml::draw() | ||
108 | { | ||
109 | #if LL_LIBXUL_ENABLED | ||
110 | // enable/disable buttons depending on state | ||
111 | if ( mWebBrowser ) | ||
112 | { | ||
113 | bool enable_back = mWebBrowser->canNavigateBack(); | ||
114 | childSetEnabled( "back_btn", enable_back ); | ||
115 | |||
116 | bool enable_forward = mWebBrowser->canNavigateForward(); | ||
117 | childSetEnabled( "forward_btn", enable_forward ); | ||
118 | }; | ||
119 | #endif | ||
120 | |||
121 | LLFloater::draw(); | ||
122 | } | ||
123 | |||
124 | //////////////////////////////////////////////////////////////////////////////// | ||
104 | // | 125 | // |
105 | void LLFloaterHtml::show( LLString content_id ) | 126 | void LLFloaterHtml::show( LLString content_id ) |
106 | { | 127 | { |
@@ -108,13 +129,22 @@ void LLFloaterHtml::show( LLString content_id ) | |||
108 | LLString title_str = content_id + "_title"; | 129 | LLString title_str = content_id + "_title"; |
109 | LLString url_str = content_id + "_url"; | 130 | LLString url_str = content_id + "_url"; |
110 | 131 | ||
132 | std::string title = childGetValue( title_str ).asString(); | ||
133 | std::string url = childGetValue( url_str ).asString(); | ||
134 | show( url, title ); | ||
135 | } | ||
136 | |||
137 | //////////////////////////////////////////////////////////////////////////////// | ||
138 | // | ||
139 | void LLFloaterHtml::show( std::string start_url, std::string title ) | ||
140 | { | ||
111 | // set the title | 141 | // set the title |
112 | setTitle( childGetValue( title_str ).asString() ); | 142 | setTitle( title ); |
113 | 143 | ||
114 | #if LL_LIBXUL_ENABLED | 144 | #if LL_LIBXUL_ENABLED |
115 | // navigate to the URL | 145 | // navigate to the URL |
116 | if ( mWebBrowser ) | 146 | if ( mWebBrowser ) |
117 | mWebBrowser->navigateTo( childGetValue( url_str ).asString() ); | 147 | mWebBrowser->navigateTo( start_url ); |
118 | #endif // LL_LIBXUL_ENABLED | 148 | #endif // LL_LIBXUL_ENABLED |
119 | 149 | ||
120 | // make floater appear | 150 | // make floater appear |
@@ -138,29 +168,95 @@ void LLFloaterHtml::onClickClose( void* data ) | |||
138 | } | 168 | } |
139 | 169 | ||
140 | //////////////////////////////////////////////////////////////////////////////// | 170 | //////////////////////////////////////////////////////////////////////////////// |
141 | // | 171 | // static |
142 | void LLFloaterHtml::onClickLinkSecondLife( const EventType& eventIn ) | 172 | void LLFloaterHtml::onClickBack( void* data ) |
143 | { | 173 | { |
144 | #if LL_LIBXUL_ENABLED | 174 | #if LL_LIBXUL_ENABLED |
145 | const std::string protocol( "secondlife://app." ); | 175 | LLFloaterHtml* self = ( LLFloaterHtml* )data; |
176 | if ( self ) | ||
177 | { | ||
178 | if ( self->mWebBrowser ) | ||
179 | { | ||
180 | self->mWebBrowser->navigateBack(); | ||
181 | }; | ||
182 | }; | ||
183 | #endif | ||
184 | } | ||
146 | 185 | ||
147 | // special 'app' secondlife link (using a different protocol - one that isn't registered in the browser) causes bad | 186 | //////////////////////////////////////////////////////////////////////////////// |
148 | // things to happen and Mozilla stops responding because it can't display the "invalid protocol dialog) | 187 | // |
149 | if ( LLString::compareInsensitive( eventIn.getStringValue().substr( 0, protocol.length() ).c_str(), protocol.c_str() ) == 0 ) | 188 | void LLFloaterHtml::onClickHome( void* data ) |
189 | { | ||
190 | LLFloaterHtml* self = ( LLFloaterHtml* )data; | ||
191 | if ( self ) | ||
150 | { | 192 | { |
151 | // extract the command string | 193 | #if LL_LIBXUL_ENABLED |
152 | LLString cmd = eventIn.getStringValue().substr( protocol.length() ); | 194 | if ( self->mWebBrowser ) |
195 | { | ||
196 | std::string home_url = self->childGetText("home_page_url"); | ||
197 | if ( home_url.length() > 4 ) | ||
198 | { | ||
199 | self->mWebBrowser->navigateTo( home_url ); | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | llwarns << "Invalid home page specified for HTML floater - navigating to default" << llendl; | ||
204 | self->mWebBrowser->navigateTo( "http://google.com" ); | ||
205 | } | ||
206 | }; | ||
207 | #endif | ||
208 | }; | ||
209 | } | ||
153 | 210 | ||
154 | // command is open the F1 Help floater | 211 | //////////////////////////////////////////////////////////////////////////////// |
155 | if ( LLString::compareInsensitive( cmd.c_str() , "floater.html.help" ) == 0 ) | 212 | // static |
213 | void LLFloaterHtml::onClickForward( void* data ) | ||
214 | { | ||
215 | LLFloaterHtml* self = ( LLFloaterHtml* )data; | ||
216 | if ( self ) | ||
217 | { | ||
218 | #if LL_LIBXUL_ENABLED | ||
219 | if ( self->mWebBrowser ) | ||
156 | { | 220 | { |
157 | gViewerHtmlHelp.show(); | 221 | self->mWebBrowser->navigateForward(); |
158 | } | 222 | }; |
159 | } | 223 | #endif |
160 | else | 224 | }; |
161 | // regular secondlife link - just open the map as normal | 225 | } |
226 | |||
227 | //////////////////////////////////////////////////////////////////////////////// | ||
228 | // static | ||
229 | void LLFloaterHtml::onCommitUrlEdit(LLUICtrl* ctrl, void* user_data) | ||
230 | { | ||
231 | LLFloaterHtml* self = (LLFloaterHtml*)user_data; | ||
232 | |||
233 | LLLineEditor* editor = (LLLineEditor*)ctrl; | ||
234 | std::string url = editor->getText(); | ||
235 | |||
236 | #if LL_LIBXUL_ENABLED | ||
237 | if ( self->mWebBrowser ) | ||
162 | { | 238 | { |
163 | mWebBrowser->openMapAtlocation( eventIn.getStringValue() ); | 239 | self->mWebBrowser->navigateTo( url ); |
164 | } | 240 | }; |
165 | #endif // LL_LIBXUL_ENABLED | 241 | #endif |
166 | }; | 242 | } |
243 | |||
244 | //////////////////////////////////////////////////////////////////////////////// | ||
245 | // static | ||
246 | void LLFloaterHtml::onClickGo( void* data ) | ||
247 | { | ||
248 | LLFloaterHtml* self = ( LLFloaterHtml* )data; | ||
249 | if ( self ) | ||
250 | { | ||
251 | std::string url = self->childGetValue( "url_edit" ).asString(); | ||
252 | if ( url.length() ) | ||
253 | { | ||
254 | #if LL_LIBXUL_ENABLED | ||
255 | if ( self->mWebBrowser ) | ||
256 | { | ||
257 | self->mWebBrowser->navigateTo( url ); | ||
258 | }; | ||
259 | #endif | ||
260 | }; | ||
261 | }; | ||
262 | } | ||