diff options
author | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
commit | 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch) | |
tree | bcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/newview/llwebbrowserctrl.cpp | |
parent | Second Life viewer sources 1.13.3.2 (diff) | |
download | meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2 meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz |
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/newview/llwebbrowserctrl.cpp')
-rw-r--r-- | linden/indra/newview/llwebbrowserctrl.cpp | 172 |
1 files changed, 141 insertions, 31 deletions
diff --git a/linden/indra/newview/llwebbrowserctrl.cpp b/linden/indra/newview/llwebbrowserctrl.cpp index 6d1ee28..7df2da4 100644 --- a/linden/indra/newview/llwebbrowserctrl.cpp +++ b/linden/indra/newview/llwebbrowserctrl.cpp | |||
@@ -45,15 +45,32 @@ const S32 MAX_TEXTURE_DIMENSION = 2048; | |||
45 | 45 | ||
46 | LLWebBrowserCtrl::LLWebBrowserCtrl( const std::string& name, const LLRect& rect ) : | 46 | LLWebBrowserCtrl::LLWebBrowserCtrl( const std::string& name, const LLRect& rect ) : |
47 | LLUICtrl( name, rect, FALSE, NULL, NULL ), | 47 | LLUICtrl( name, rect, FALSE, NULL, NULL ), |
48 | mEmbeddedBrowserWindowId( 0 ), | ||
49 | mTextureDepthBytes( 4 ), | 48 | mTextureDepthBytes( 4 ), |
50 | mBorder( 0 ), | 49 | mEmbeddedBrowserWindowId( 0 ), |
50 | mBorder(NULL), | ||
51 | mFrequentUpdates( true ), | 51 | mFrequentUpdates( true ), |
52 | mOpenLinksInExternalBrowser( false ), | 52 | mOpenLinksInExternalBrowser( false ), |
53 | mHomePageUrl( "" ) | 53 | mHomePageUrl( "" ), |
54 | mIgnoreUIScale( true ) | ||
54 | { | 55 | { |
56 | S32 screen_width = mIgnoreUIScale ? llround((F32)mRect.getWidth() * LLUI::sGLScaleFactor.mV[VX]) : mRect.getWidth(); | ||
57 | S32 screen_height = mIgnoreUIScale ? llround((F32)mRect.getHeight() * LLUI::sGLScaleFactor.mV[VY]) : mRect.getHeight(); | ||
58 | |||
55 | // create a new browser window | 59 | // create a new browser window |
56 | mEmbeddedBrowserWindowId = LLMozLib::getInstance()->createBrowserWindow( gViewerWindow->getPlatformWindow(), mRect.getWidth(), mRect.getHeight() ); | 60 | { |
61 | #if LL_LINUX | ||
62 | // Yuck, Mozilla init plays with the locale - push/pop | ||
63 | // the locale to protect it, as exotic/non-C locales | ||
64 | // causes our code lots of general critical weirdness | ||
65 | // and crashness. (SL-35450) | ||
66 | char *saved_locale = setlocale(LC_ALL, NULL); | ||
67 | #endif // LL_LINUX | ||
68 | mEmbeddedBrowserWindowId = LLMozLib::getInstance()->createBrowserWindow( gViewerWindow->getPlatformWindow(), screen_width, screen_height ); | ||
69 | #if LL_LINUX | ||
70 | if (saved_locale) | ||
71 | setlocale(LC_ALL, saved_locale); | ||
72 | #endif // LL_LINUX | ||
73 | } | ||
57 | 74 | ||
58 | // change color to black so transisitons aren't so noticable (this should be in XML eventually) | 75 | // change color to black so transisitons aren't so noticable (this should be in XML eventually) |
59 | LLMozLib::getInstance()->setBackgroundColor( mEmbeddedBrowserWindowId, 0x00, 0x00, 0x00 ); | 76 | LLMozLib::getInstance()->setBackgroundColor( mEmbeddedBrowserWindowId, 0x00, 0x00, 0x00 ); |
@@ -62,7 +79,7 @@ LLWebBrowserCtrl::LLWebBrowserCtrl( const std::string& name, const LLRect& rect | |||
62 | LLMozLib::getInstance()->addObserver( mEmbeddedBrowserWindowId, this ); | 79 | LLMozLib::getInstance()->addObserver( mEmbeddedBrowserWindowId, this ); |
63 | 80 | ||
64 | // create a new texture (based on LLDynamic texture) that will be used to display the output | 81 | // create a new texture (based on LLDynamic texture) that will be used to display the output |
65 | mWebBrowserImage = new LLWebBrowserTexture( mRect.getWidth(), mRect.getHeight(), this, mEmbeddedBrowserWindowId ); | 82 | mWebBrowserImage = new LLWebBrowserTexture( screen_width, screen_height, this, mEmbeddedBrowserWindowId ); |
66 | 83 | ||
67 | LLRect border_rect( 0, mRect.getHeight() + 2, mRect.getWidth() + 2, 0 ); | 84 | LLRect border_rect( 0, mRect.getHeight() + 2, mRect.getWidth() + 2, 0 ); |
68 | mBorder = new LLViewBorder( "web control border", border_rect, LLViewBorder::BEVEL_IN ); | 85 | mBorder = new LLViewBorder( "web control border", border_rect, LLViewBorder::BEVEL_IN ); |
@@ -119,7 +136,8 @@ void LLWebBrowserCtrl::setOpenInExternalBrowser( bool valIn ) | |||
119 | // | 136 | // |
120 | BOOL LLWebBrowserCtrl::handleHover( S32 x, S32 y, MASK mask ) | 137 | BOOL LLWebBrowserCtrl::handleHover( S32 x, S32 y, MASK mask ) |
121 | { | 138 | { |
122 | LLMozLib::getInstance()->mouseMove( mEmbeddedBrowserWindowId, x, mRect.getHeight() - y ); | 139 | convertInputCoords(x, y); |
140 | LLMozLib::getInstance()->mouseMove( mEmbeddedBrowserWindowId, x, y ); | ||
123 | 141 | ||
124 | return TRUE; | 142 | return TRUE; |
125 | } | 143 | } |
@@ -142,7 +160,8 @@ BOOL LLWebBrowserCtrl::handleScrollWheel( S32 x, S32 y, S32 clicks ) | |||
142 | // | 160 | // |
143 | BOOL LLWebBrowserCtrl::handleMouseUp( S32 x, S32 y, MASK mask ) | 161 | BOOL LLWebBrowserCtrl::handleMouseUp( S32 x, S32 y, MASK mask ) |
144 | { | 162 | { |
145 | LLMozLib::getInstance()->mouseUp( mEmbeddedBrowserWindowId, x, mRect.getHeight() - y ); | 163 | convertInputCoords(x, y); |
164 | LLMozLib::getInstance()->mouseUp( mEmbeddedBrowserWindowId, x, y ); | ||
146 | 165 | ||
147 | gViewerWindow->setMouseCapture( 0, 0 ); | 166 | gViewerWindow->setMouseCapture( 0, 0 ); |
148 | 167 | ||
@@ -153,7 +172,8 @@ BOOL LLWebBrowserCtrl::handleMouseUp( S32 x, S32 y, MASK mask ) | |||
153 | // | 172 | // |
154 | BOOL LLWebBrowserCtrl::handleMouseDown( S32 x, S32 y, MASK mask ) | 173 | BOOL LLWebBrowserCtrl::handleMouseDown( S32 x, S32 y, MASK mask ) |
155 | { | 174 | { |
156 | LLMozLib::getInstance()->mouseDown( mEmbeddedBrowserWindowId, x, mRect.getHeight() - y ); | 175 | convertInputCoords(x, y); |
176 | LLMozLib::getInstance()->mouseDown( mEmbeddedBrowserWindowId, x, y ); | ||
157 | 177 | ||
158 | gViewerWindow->setMouseCapture( this, 0 ); | 178 | gViewerWindow->setMouseCapture( this, 0 ); |
159 | 179 | ||
@@ -184,9 +204,67 @@ void LLWebBrowserCtrl::onFocusLost() | |||
184 | // | 204 | // |
185 | BOOL LLWebBrowserCtrl::handleKey( KEY key, MASK mask, BOOL called_from_parent ) | 205 | BOOL LLWebBrowserCtrl::handleKey( KEY key, MASK mask, BOOL called_from_parent ) |
186 | { | 206 | { |
187 | LLMozLib::getInstance()->keyPress( mEmbeddedBrowserWindowId, key ); | 207 | unsigned long nskey; |
208 | |||
209 | // First, turn SL internal keycode enum into Mozilla keycode enum | ||
210 | |||
211 | // We don't have to deal with printable characters here - they should | ||
212 | // go through handleUnicodeChar(). This table could be more complete | ||
213 | // than it is, but I think this covers all of the important | ||
214 | // non-printables. | ||
215 | switch (key) | ||
216 | { | ||
217 | case KEY_BACKSPACE: | ||
218 | nskey = LL_DOM_VK_BACK_SPACE; break; | ||
219 | case KEY_TAB: | ||
220 | nskey = LL_DOM_VK_TAB; break; | ||
221 | case KEY_RETURN: | ||
222 | nskey = LL_DOM_VK_RETURN; break; | ||
223 | case KEY_PAD_RETURN: | ||
224 | nskey = LL_DOM_VK_ENTER; break; | ||
225 | case KEY_ESCAPE: | ||
226 | nskey = LL_DOM_VK_ESCAPE; break; | ||
227 | case KEY_PAGE_UP: | ||
228 | nskey = LL_DOM_VK_PAGE_UP; break; | ||
229 | case KEY_PAGE_DOWN: | ||
230 | nskey = LL_DOM_VK_PAGE_DOWN; break; | ||
231 | case KEY_END: | ||
232 | nskey = LL_DOM_VK_END; break; | ||
233 | case KEY_HOME: | ||
234 | nskey = LL_DOM_VK_HOME; break; | ||
235 | case KEY_LEFT: | ||
236 | nskey = LL_DOM_VK_LEFT; break; | ||
237 | case KEY_UP: | ||
238 | nskey = LL_DOM_VK_UP; break; | ||
239 | case KEY_RIGHT: | ||
240 | nskey = LL_DOM_VK_RIGHT; break; | ||
241 | case KEY_DOWN: | ||
242 | nskey = LL_DOM_VK_DOWN; break; | ||
243 | case KEY_INSERT: | ||
244 | nskey = LL_DOM_VK_INSERT; break; | ||
245 | case KEY_DELETE: | ||
246 | nskey = LL_DOM_VK_DELETE; break; | ||
247 | default: | ||
248 | llinfos << "Don't know how to map LL keycode " << U32(key) | ||
249 | << " to DOM key. Ignoring." << llendl; | ||
250 | return FALSE; // don't know how to map this key. | ||
251 | } | ||
188 | 252 | ||
189 | return FALSE; | 253 | LLMozLib::getInstance()->keyPress( mEmbeddedBrowserWindowId, nskey ); |
254 | |||
255 | return TRUE; | ||
256 | } | ||
257 | |||
258 | BOOL LLWebBrowserCtrl::handleUnicodeChar(llwchar uni_char, BOOL called_from_parent) | ||
259 | { | ||
260 | // only accept 'printable' characters, sigh... | ||
261 | if (uni_char >= 32 // discard 'control' characters | ||
262 | && uni_char != 127) // SDL thinks this is 'delete' - yuck. | ||
263 | { | ||
264 | LLMozLib::getInstance()->unicodeInput( mEmbeddedBrowserWindowId, uni_char ); | ||
265 | } | ||
266 | |||
267 | return TRUE; | ||
190 | } | 268 | } |
191 | 269 | ||
192 | //////////////////////////////////////////////////////////////////////////////// | 270 | //////////////////////////////////////////////////////////////////////////////// |
@@ -208,9 +286,13 @@ void LLWebBrowserCtrl::onVisibilityChange ( BOOL curVisibilityIn ) | |||
208 | // | 286 | // |
209 | void LLWebBrowserCtrl::reshape( S32 width, S32 height, BOOL called_from_parent ) | 287 | void LLWebBrowserCtrl::reshape( S32 width, S32 height, BOOL called_from_parent ) |
210 | { | 288 | { |
289 | S32 screen_width = mIgnoreUIScale ? llround((F32)width * LLUI::sGLScaleFactor.mV[VX]) : width; | ||
290 | S32 screen_height = mIgnoreUIScale ? llround((F32)height * LLUI::sGLScaleFactor.mV[VX]) : height; | ||
211 | // when floater is minimized, these sizes are negative | 291 | // when floater is minimized, these sizes are negative |
212 | if ( height > 0 && width > 0 ) | 292 | if ( screen_height > 0 && screen_width > 0 ) |
213 | mWebBrowserImage->resize( width, height ); | 293 | { |
294 | mWebBrowserImage->resize( screen_width, screen_height ); | ||
295 | } | ||
214 | 296 | ||
215 | LLUICtrl::reshape( width, height, called_from_parent ); | 297 | LLUICtrl::reshape( width, height, called_from_parent ); |
216 | } | 298 | } |
@@ -310,38 +392,60 @@ void LLWebBrowserCtrl::draw() | |||
310 | LLGLSUIDefault gls_ui; | 392 | LLGLSUIDefault gls_ui; |
311 | LLGLDisable gls_alphaTest( GL_ALPHA_TEST ); | 393 | LLGLDisable gls_alphaTest( GL_ALPHA_TEST ); |
312 | 394 | ||
313 | // scale texture to fit the space using texture coords | 395 | glPushMatrix(); |
314 | mWebBrowserImage->bindTexture(); | ||
315 | glColor4fv( LLColor4::white.mV ); | ||
316 | F32 max_u = ( F32 )mWebBrowserImage->getBrowserWidth() / ( F32 )mWebBrowserImage->getWidth(); | ||
317 | F32 max_v = ( F32 )mWebBrowserImage->getBrowserHeight() / ( F32 )mWebBrowserImage->getHeight(); | ||
318 | |||
319 | // draw the browser | ||
320 | glBlendFunc( GL_ONE, GL_ZERO ); | ||
321 | glBegin( GL_QUADS ); | ||
322 | { | 396 | { |
323 | glTexCoord2f( max_u, 0.f ); | 397 | if (mIgnoreUIScale) |
324 | glVertex2i( mRect.getWidth(), mRect.getHeight() ); | 398 | { |
399 | glLoadIdentity(); | ||
400 | // font system stores true screen origin, need to scale this by UI scale factor | ||
401 | // to get render origin for this view (with unit scale) | ||
402 | glTranslatef(floorf(LLFontGL::sCurOrigin.mX * LLUI::sGLScaleFactor.mV[VX]), | ||
403 | floorf(LLFontGL::sCurOrigin.mY * LLUI::sGLScaleFactor.mV[VY]), | ||
404 | LLFontGL::sCurOrigin.mZ); | ||
405 | } | ||
406 | |||
407 | // scale texture to fit the space using texture coords | ||
408 | mWebBrowserImage->bindTexture(); | ||
409 | glColor4fv( LLColor4::white.mV ); | ||
410 | F32 max_u = ( F32 )mWebBrowserImage->getBrowserWidth() / ( F32 )mWebBrowserImage->getWidth(); | ||
411 | F32 max_v = ( F32 )mWebBrowserImage->getBrowserHeight() / ( F32 )mWebBrowserImage->getHeight(); | ||
412 | |||
413 | // draw the browser | ||
414 | glBlendFunc( GL_ONE, GL_ZERO ); | ||
415 | glBegin( GL_QUADS ); | ||
416 | { | ||
417 | // render using web browser reported width and height, instead of trying to invert GL scale | ||
418 | glTexCoord2f( max_u, 0.f ); | ||
419 | glVertex2i( mWebBrowserImage->getBrowserWidth(), mWebBrowserImage->getBrowserHeight() ); | ||
325 | 420 | ||
326 | glTexCoord2f( 0.f, 0.f ); | 421 | glTexCoord2f( 0.f, 0.f ); |
327 | glVertex2i( 0, mRect.getHeight() ); | 422 | glVertex2i( 0, mWebBrowserImage->getBrowserHeight() ); |
328 | 423 | ||
329 | glTexCoord2f( 0.f, max_v ); | 424 | glTexCoord2f( 0.f, max_v ); |
330 | glVertex2i( 0, 0 ); | 425 | glVertex2i( 0, 0 ); |
331 | 426 | ||
332 | glTexCoord2f( max_u, max_v ); | 427 | glTexCoord2f( max_u, max_v ); |
333 | glVertex2i( mRect.getWidth(), 0 ); | 428 | glVertex2i( mWebBrowserImage->getBrowserWidth(), 0 ); |
429 | } | ||
430 | glEnd(); | ||
431 | glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); | ||
334 | } | 432 | } |
335 | glEnd(); | 433 | glPopMatrix(); |
336 | glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); | ||
337 | 434 | ||
338 | // highlight if keyboard focus here. (TODO: this needs some work) | 435 | // highlight if keyboard focus here. (TODO: this needs some work) |
339 | if ( mBorder->getVisible() ) | 436 | if ( mBorder->getVisible() ) |
340 | mBorder->setKeyboardFocusHighlight( gFocusMgr.childHasKeyboardFocus( this ) ); | 437 | mBorder->setKeyboardFocusHighlight( gFocusMgr.childHasKeyboardFocus( this ) ); |
341 | 438 | ||
439 | |||
342 | LLUICtrl::draw(); | 440 | LLUICtrl::draw(); |
343 | } | 441 | } |
344 | 442 | ||
443 | void LLWebBrowserCtrl::convertInputCoords(S32& x, S32& y) | ||
444 | { | ||
445 | x = mIgnoreUIScale ? llround((F32)x * LLUI::sGLScaleFactor.mV[VX]) : x; | ||
446 | y = mIgnoreUIScale ? llround((F32)(mRect.getHeight() - y) * LLUI::sGLScaleFactor.mV[VY]) : (mRect.getHeight() - y); | ||
447 | } | ||
448 | |||
345 | //////////////////////////////////////////////////////////////////////////////// | 449 | //////////////////////////////////////////////////////////////////////////////// |
346 | // virtual | 450 | // virtual |
347 | void LLWebBrowserCtrl::onNavigateBegin( const EventType& eventIn ) | 451 | void LLWebBrowserCtrl::onNavigateBegin( const EventType& eventIn ) |
@@ -551,6 +655,8 @@ void LLWebBrowserTexture::resize( S32 new_width, S32 new_height ) | |||
551 | if ( actual_rowspan < 1 || browser_depth < 2 ) | 655 | if ( actual_rowspan < 1 || browser_depth < 2 ) |
552 | return; | 656 | return; |
553 | 657 | ||
658 | releaseGLTexture(); | ||
659 | |||
554 | S32 pagebuffer_width = actual_rowspan / browser_depth; | 660 | S32 pagebuffer_width = actual_rowspan / browser_depth; |
555 | 661 | ||
556 | // calculate the next power of 2 bigger than reqquested size for width and height | 662 | // calculate the next power of 2 bigger than reqquested size for width and height |
@@ -635,6 +741,10 @@ LLView* LLWebBrowserCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFac | |||
635 | 741 | ||
636 | LLWebBrowserCtrl* web_browser = new LLWebBrowserCtrl( name, rect ); | 742 | LLWebBrowserCtrl* web_browser = new LLWebBrowserCtrl( name, rect ); |
637 | 743 | ||
744 | BOOL ignore_ui_scale = web_browser->getIgnoreUIScale(); | ||
745 | node->getAttributeBOOL("ignore_ui_scale", ignore_ui_scale); | ||
746 | web_browser->setIgnoreUIScale((bool)ignore_ui_scale); | ||
747 | |||
638 | web_browser->initFromXML(node, parent); | 748 | web_browser->initFromXML(node, parent); |
639 | 749 | ||
640 | web_browser->setHomePageUrl( start_url ); | 750 | web_browser->setHomePageUrl( start_url ); |