aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloaterhtml.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llfloaterhtml.cpp')
-rw-r--r--linden/indra/newview/llfloaterhtml.cpp253
1 files changed, 253 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterhtml.cpp b/linden/indra/newview/llfloaterhtml.cpp
new file mode 100644
index 0000000..21f34de
--- /dev/null
+++ b/linden/indra/newview/llfloaterhtml.cpp
@@ -0,0 +1,253 @@
1/**
2 * @file llfloaterhtml.cpp
3 * @brief In-world HTML dialog
4 *
5 * $LicenseInfo:firstyear=2005&license=viewergpl$
6 *
7 * Copyright (c) 2005-2009, 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://secondlifegrid.net/programs/open_source/licensing/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://secondlifegrid.net/programs/open_source/licensing/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#include "llviewerprecompiledheaders.h"
33
34#include "llfloaterhtml.h"
35
36// viewer includes
37#include "lluictrlfactory.h"
38#include "llviewercontrol.h"
39#include "lllineeditor.h"
40#include "llviewerwindow.h"
41#include "llweb.h"
42
43#include "llwebbrowserctrl.h"
44
45LLFloaterHtml* LLFloaterHtml::sInstance = 0;
46
47////////////////////////////////////////////////////////////////////////////////
48//
49LLFloaterHtml* LLFloaterHtml::getInstance()
50{
51 if ( ! sInstance )
52 sInstance = new LLFloaterHtml();
53
54 return sInstance;
55}
56
57////////////////////////////////////////////////////////////////////////////////
58//
59LLFloaterHtml::LLFloaterHtml()
60: LLFloater( std::string("HTML Floater") )
61
62 ,
63 mWebBrowser( 0 )
64{
65 LLUICtrlFactory::getInstance()->buildFloater( this, "floater_html.xml" );
66
67 childSetAction("back_btn", onClickBack, this);
68 childSetAction("home_btn", onClickHome, this);
69 childSetAction("forward_btn", onClickForward, this);
70 childSetAction("close_btn", onClickClose, this);
71 childSetCommitCallback("url_edit", onCommitUrlEdit, this );
72 childSetAction("go_btn", onClickGo, this );
73
74 // reposition floater from saved settings
75 LLRect rect = gSavedSettings.getRect( "FloaterHtmlRect" );
76 reshape( rect.getWidth(), rect.getHeight(), FALSE );
77 setRect( rect );
78
79 mWebBrowser = getChild<LLWebBrowserCtrl>("html_floater_browser" );
80 if ( mWebBrowser )
81 {
82 // open links in internal browser
83 mWebBrowser->setOpenInExternalBrowser( false );
84 }
85}
86
87////////////////////////////////////////////////////////////////////////////////
88//
89LLFloaterHtml::~LLFloaterHtml()
90{
91 // save position of floater
92 gSavedSettings.setRect( "FloaterHtmlRect", getRect() );
93
94 sInstance = 0;
95}
96
97////////////////////////////////////////////////////////////////////////////////
98// virtual
99void LLFloaterHtml::draw()
100{
101 // enable/disable buttons depending on state
102 if ( mWebBrowser )
103 {
104 bool enable_back = mWebBrowser->canNavigateBack();
105 childSetEnabled( "back_btn", enable_back );
106
107 bool enable_forward = mWebBrowser->canNavigateForward();
108 childSetEnabled( "forward_btn", enable_forward );
109 };
110
111 LLFloater::draw();
112}
113
114////////////////////////////////////////////////////////////////////////////////
115//
116void LLFloaterHtml::show( std::string content_id, bool open_link_external, bool open_app_slurls )
117{
118 // calculate the XML labels we'll need (if only XML folders worked)
119 std::string title_str = content_id + "_title";
120 std::string url_str = content_id + "_url";
121
122 std::string title = getString( title_str );
123 std::string url = getString( url_str );
124
125 show( url, title, open_link_external, open_app_slurls );
126}
127
128////////////////////////////////////////////////////////////////////////////////
129//
130void LLFloaterHtml::show( std::string start_url, std::string title, bool open_link_external, bool open_app_slurls )
131{
132 // set the title
133 setTitle( title );
134
135 // navigate to the URL
136 if ( mWebBrowser )
137 {
138 mWebBrowser->setOpenAppSLURLs( open_app_slurls );
139 mWebBrowser->setOpenInExternalBrowser( open_link_external );
140 mWebBrowser->navigateTo( start_url );
141 }
142
143 // make floater appear
144 setVisibleAndFrontmost();
145}
146
147////////////////////////////////////////////////////////////////////////////////
148//
149std::string LLFloaterHtml::getSupportUrl()
150{
151 return getString("support_page_url");
152}
153
154////////////////////////////////////////////////////////////////////////////////
155//
156void LLFloaterHtml::onClose( bool app_quitting )
157{
158 setVisible( false );
159 // HACK for fast XML iteration replace with:
160 // destroy();
161}
162
163////////////////////////////////////////////////////////////////////////////////
164//
165void LLFloaterHtml::onClickClose( void* data )
166{
167 LLFloaterHtml* self = ( LLFloaterHtml* )data;
168 self->close();
169}
170
171////////////////////////////////////////////////////////////////////////////////
172// static
173void LLFloaterHtml::onClickBack( void* data )
174{
175 LLFloaterHtml* self = ( LLFloaterHtml* )data;
176 if ( self )
177 {
178 if ( self->mWebBrowser )
179 {
180 self->mWebBrowser->navigateBack();
181 };
182 };
183}
184
185////////////////////////////////////////////////////////////////////////////////
186//
187void LLFloaterHtml::onClickHome( void* data )
188{
189 LLFloaterHtml* self = ( LLFloaterHtml* )data;
190 if ( self )
191 {
192 if ( self->mWebBrowser )
193 {
194 std::string home_url = self->getString("home_page_url");
195 if ( home_url.length() > 4 )
196 {
197 self->mWebBrowser->navigateTo( home_url );
198 }
199 else
200 {
201 llwarns << "Invalid home page specified for HTML floater - navigating to default" << llendl;
202 self->mWebBrowser->navigateTo( "http://secondlife.com" );
203 }
204 };
205 };
206}
207
208////////////////////////////////////////////////////////////////////////////////
209// static
210void LLFloaterHtml::onClickForward( void* data )
211{
212 LLFloaterHtml* self = ( LLFloaterHtml* )data;
213 if ( self )
214 {
215 if ( self->mWebBrowser )
216 {
217 self->mWebBrowser->navigateForward();
218 };
219 };
220}
221
222////////////////////////////////////////////////////////////////////////////////
223// static
224void LLFloaterHtml::onCommitUrlEdit(LLUICtrl* ctrl, void* user_data)
225{
226 LLFloaterHtml* self = (LLFloaterHtml*)user_data;
227
228 LLLineEditor* editor = (LLLineEditor*)ctrl;
229 std::string url = editor->getText();
230
231 if ( self->mWebBrowser )
232 {
233 self->mWebBrowser->navigateTo( url );
234 };
235}
236
237////////////////////////////////////////////////////////////////////////////////
238// static
239void LLFloaterHtml::onClickGo( void* data )
240{
241 LLFloaterHtml* self = ( LLFloaterHtml* )data;
242 if ( self )
243 {
244 std::string url = self->childGetValue( "url_edit" ).asString();
245 if ( url.length() )
246 {
247 if ( self->mWebBrowser )
248 {
249 self->mWebBrowser->navigateTo( url );
250 }
251 }
252 }
253}