00001
00032 #include "llmediaimplllmozlib.h"
00033
00034 #if LL_LLMOZLIB_ENABLED
00035
00036 #include "llmediaimplregister.h"
00037 #include "llmediamanager.h"
00038
00039 #ifdef WIN32
00040
00041 #include <windows.h>
00042 #include <GL/gl.h>
00043 #elif defined(__APPLE__)
00044
00045 #include <OpenGL/gl.h>
00046 #else // Assume this is linux
00047
00048
00049 #include "GL/gl.h"
00050 #endif
00051
00052 #if LL_LINUX
00053 #include <locale.h>
00054 #endif
00055
00056 #include <iostream>
00057
00058
00059 static LLMediaImplRegister sLLMediaImplLLMozLibReg( "LLMediaImplLLMozLib", new LLMediaImplLLMozLibMaker() );
00060
00062
00063 LLMediaImplLLMozLibMaker::LLMediaImplLLMozLibMaker()
00064 {
00065
00066 mMimeTypes.push_back( "image/svg+xml" );
00067 mMimeTypeCategories.push_back( "text" );
00068 #if !LL_QUICKTIME_ENABLED
00069 mMimeTypeCategories.push_back( "image" );
00070 #endif
00071 }
00072
00074
00075 LLMediaImplLLMozLib::LLMediaImplLLMozLib() :
00076 mBrowserWindowWidth( 800 ),
00077 mBrowserWindowHeight( 600 ),
00078 mMediaDataWidth( 0 ),
00079 mMediaDataHeight( 0 ),
00080 mWindowId( 0 ),
00081 mNeedsUpdate( false )
00082 {
00083 setRequestedMediaSize( mBrowserWindowWidth, mBrowserWindowHeight );
00084
00085 setMediaDepth( 4 );
00086 }
00087
00089
00090 bool LLMediaImplLLMozLib::startup( LLMediaManagerData* init_data )
00091 {
00092 #if LL_LINUX
00093
00094
00095
00096
00097 static std::string saved_locale;
00098 saved_locale = setlocale(LC_ALL, NULL);
00099 #endif // LL_LINUX
00100
00101 bool result = LLMozLib::getInstance()->init( init_data->getBrowserApplicationDir(),
00102 init_data->getBrowserComponentDir(),
00103 init_data->getBrowserProfileDir(),
00104 init_data->getBrowserParentWindow() );
00105
00106
00107 LLMozLib::getInstance()->setBrowserAgentId( init_data->getBrowserUserAgentId() );
00108
00109 #if LL_LINUX
00110 setlocale(LC_ALL, saved_locale.c_str() );
00111 #endif // LL_LINUX
00112
00113 return result;
00114 }
00115
00117
00118 bool LLMediaImplLLMozLib::closedown()
00119 {
00120
00121 LLMozLib::getInstance()->reset();
00122
00123 return true;
00124 }
00125
00127
00128 bool LLMediaImplLLMozLib::init()
00129 {
00130
00131
00132 if ( mWindowId )
00133 return false;
00134
00135 #if LL_LINUX
00136 static std::string saved_locale;
00137 saved_locale = setlocale(LC_ALL, NULL);
00138 #endif // LL_LINUX
00139
00140 mWindowId = LLMozLib::getInstance()->createBrowserWindow( mBrowserWindowWidth, mBrowserWindowHeight );
00141
00142 LLMozLib::getInstance()->setSize( mWindowId, mBrowserWindowWidth, mBrowserWindowHeight );
00143
00144 LLMozLib::getInstance()->setBackgroundColor( mWindowId, 0x00, 0x00, 0x00 );
00145
00146 LLMozLib::getInstance()->addObserver( mWindowId, this );
00147
00148
00149
00150 LLMozLib::getInstance()->enablePlugins( false );
00151
00152
00153 LLMozLib::getInstance()->flipWindow( mWindowId, true );
00154
00155
00156 setMediaDepth( LLMozLib::getInstance()->getBrowserDepth( mWindowId ) );
00157
00158 #if LL_LINUX
00159 setlocale(LC_ALL, saved_locale.c_str() );
00160 #endif // LL_LINUX
00161
00162 return true;
00163 }
00164
00166
00167 std::string LLMediaImplLLMozLib::getVersion()
00168 {
00169 std::string version_string = "[" + sLLMediaImplLLMozLibReg.getImplName() + "] - " + LLMozLib::getInstance()->getVersion();
00170
00171 return version_string;
00172 }
00173
00175
00176 bool LLMediaImplLLMozLib::set404RedirectUrl( std::string redirect_url )
00177 {
00178 return LLMozLib::getInstance()->set404RedirectUrl( mWindowId, redirect_url );
00179 }
00180
00182
00183
00184 bool LLMediaImplLLMozLib::clr404RedirectUrl()
00185 {
00186 return LLMozLib::getInstance()->clr404RedirectUrl( mWindowId );
00187 }
00188
00190
00191 bool LLMediaImplLLMozLib::setBackgroundColor( unsigned int red, unsigned int green, unsigned int blue ) const
00192 {
00193 return LLMozLib::getInstance()->setBackgroundColor( mWindowId, red, green, blue );
00194 }
00195
00197
00198 bool LLMediaImplLLMozLib::setCaretColor( unsigned int red, unsigned int green, unsigned int blue ) const
00199 {
00200 return LLMozLib::getInstance()->setCaretColor( mWindowId, red, green, blue );
00201 }
00202
00204
00205 bool LLMediaImplLLMozLib::navigateTo( const std::string url )
00206 {
00207
00208 LLMozLib::getInstance()->navigateTo( mWindowId, url );
00209
00210
00211 LLMediaEvent event( this );
00212 mEventEmitter.update( &LLMediaObserver::onMediaSizeChange, event );
00213
00214
00215 return true;
00216 }
00217
00219
00220 bool LLMediaImplLLMozLib::updateMedia()
00221 {
00222 if ( getStatus() == LLMediaBase::STATUS_STARTED )
00223 {
00224
00225 if ( mNeedsUpdate )
00226 {
00227
00228 LLMozLib::getInstance()->grabBrowserWindow( mWindowId );
00229
00230
00231 mMediaDataWidth = LLMozLib::getInstance()->getBrowserRowSpan( mWindowId ) / getMediaDepth();
00232 mMediaDataHeight = LLMozLib::getInstance()->getBrowserHeight( mWindowId );
00233
00234
00235 LLMediaEvent event( this );
00236 mEventEmitter.update( &LLMediaObserver::onMediaContentsChange, event );
00237
00238
00239 mNeedsUpdate = false;
00240 };
00241 };
00242
00243
00244 updateState();
00245
00246 return false;
00247 }
00248
00250
00251 bool LLMediaImplLLMozLib::updateState()
00252 {
00253 if ( nextCommand() == LLMediaBase::COMMAND_START )
00254 {
00255 setStatus( LLMediaBase::STATUS_STARTED );
00256 clearCommand();
00257 };
00258
00259 if ( nextCommand() == LLMediaBase::COMMAND_STOP )
00260 {
00261 setStatus( LLMediaBase::STATUS_STOPPED );
00262 clearCommand();
00263 };
00264
00265 if ( nextCommand() == LLMediaBase::COMMAND_BACK )
00266 {
00267 setStatus( LLMediaBase::STATUS_STARTED );
00268 LLMozLib::getInstance()->navigateBack( mWindowId );
00269 clearCommand();
00270 };
00271
00272 if ( nextCommand() == LLMediaBase::COMMAND_FORWARD )
00273 {
00274 setStatus( LLMediaBase::STATUS_STARTED );
00275 LLMozLib::getInstance()->navigateForward( mWindowId );
00276 clearCommand();
00277 };
00278
00279 return true;
00280 }
00281
00283
00284 void LLMediaImplLLMozLib::onPageChanged( const EventType& eventIn )
00285 {
00286
00287 mNeedsUpdate = true;
00288 }
00289
00291
00292 void LLMediaImplLLMozLib::onClickLinkHref( const EventType& eventIn )
00293 {
00294 LLMediaEvent event( this, eventIn.getStringValue(), eventIn.getStringValue2() );
00295 mEventEmitter.update( &LLMediaObserver::onClickLinkHref, event );
00296 }
00297
00299
00300 void LLMediaImplLLMozLib::onClickLinkNoFollow( const EventType& eventIn )
00301 {
00302 LLMediaEvent event( this, eventIn.getStringValue() );
00303 mEventEmitter.update( &LLMediaObserver::onClickLinkNoFollow, event );
00304 }
00305
00307
00308 void LLMediaImplLLMozLib::onUpdateProgress( const EventType& eventIn )
00309 {
00310 LLMediaEvent event( this, eventIn.getIntValue() );
00311 mEventEmitter.update( &LLMediaObserver::onUpdateProgress, event );
00312 }
00313
00315
00316 void LLMediaImplLLMozLib::onStatusTextChange( const EventType& eventIn )
00317 {
00318 LLMediaEvent event( this, eventIn.getStringValue() );
00319 mEventEmitter.update( &LLMediaObserver::onStatusTextChange, event );
00320 }
00321
00323
00324 void LLMediaImplLLMozLib::onLocationChange( const EventType& eventIn )
00325 {
00326 LLMediaEvent event( this, eventIn.getEventUri() );
00327 mEventEmitter.update( &LLMediaObserver::onLocationChange, event );
00328 }
00329
00331
00332 void LLMediaImplLLMozLib::onNavigateBegin( const EventType& eventIn )
00333 {
00334 LLMediaEvent event( this, eventIn.getEventUri() );
00335 mEventEmitter.update( &LLMediaObserver::onNavigateBegin, event );
00336 }
00337
00339
00340 void LLMediaImplLLMozLib::onNavigateComplete( const EventType& eventIn )
00341 {
00342
00343 mNeedsUpdate = true;
00344
00345
00346 LLMediaEvent event( this, eventIn.getEventUri(), eventIn.getIntValue() );
00347 mEventEmitter.update( &LLMediaObserver::onNavigateComplete, event );
00348 }
00349
00351
00352 unsigned char* LLMediaImplLLMozLib::getMediaData()
00353 {
00354 return (unsigned char*)LLMozLib::getInstance()->getBrowserWindowPixels( mWindowId );
00355 }
00356
00357
00358 bool LLMediaImplLLMozLib::recomputeSizes()
00359 {
00360 int new_width = mMediaRequestedWidth;
00361 int new_height = mMediaRequestedHeight;
00362
00363 if (new_width < 0)
00364 new_width = 512;
00365
00366 if (new_height < 0)
00367 new_height = 512;
00368
00369 if (mAutoScaled)
00370 {
00371 new_width = LLMediaManager::textureWidthFromMediaWidth( new_width );
00372 new_height = LLMediaManager::textureHeightFromMediaHeight( new_height );
00373 }
00374
00375 bool status = LLMozLib::getInstance()->setSize( mWindowId, new_width, new_height );
00376
00377 if (status)
00378 setMediaSize(new_width, new_height);
00379
00380 return status;
00381 }
00382
00383
00385
00386 int LLMediaImplLLMozLib::getMediaDataWidth() const
00387 {
00388 return mMediaDataWidth;
00389 }
00390
00392
00393 int LLMediaImplLLMozLib::getMediaDataHeight() const
00394 {
00395 return mMediaDataHeight;
00396 }
00397
00399
00400 bool LLMediaImplLLMozLib::setRequestedMediaSize(int width, int height)
00401 {
00402 LLMediaImplCommon::setRequestedMediaSize(width, height);
00403
00404 return recomputeSizes();
00405 }
00406
00408
00409 bool LLMediaImplLLMozLib::setAutoScaled( bool auto_scaled )
00410 {
00411 LLMediaImplCommon::setAutoScaled(auto_scaled);
00412
00413 return recomputeSizes();
00414 }
00415
00416
00418
00419 int LLMediaImplLLMozLib::getTextureFormatPrimary() const
00420 {
00421 #if defined(__APPLE__) || defined(MACOSX)
00422 return GL_BGRA_EXT;
00423 #else
00424 return LLMozLib::getInstance()->getBrowserDepth( mWindowId ) == 3 ? GL_BGR_EXT : GL_BGRA_EXT;
00425 #endif
00426 }
00427
00429
00430 int LLMediaImplLLMozLib::getTextureFormatType() const
00431 {
00432 #if defined(__APPLE__) || defined(MACOSX)
00433 #ifdef __BIG_ENDIAN__
00434 return GL_UNSIGNED_INT_8_8_8_8_REV;
00435 #else
00436 return GL_UNSIGNED_INT_8_8_8_8;
00437 #endif
00438 #else
00439 return GL_UNSIGNED_BYTE;
00440 #endif
00441 }
00442
00444
00445 bool LLMediaImplLLMozLib::mouseDown( int x_pos, int y_pos )
00446 {
00447 return LLMozLib::getInstance()->mouseDown( mWindowId, x_pos, y_pos );
00448 }
00449
00451
00452 bool LLMediaImplLLMozLib::mouseUp( int x_pos, int y_pos )
00453 {
00454 LLMozLib::getInstance()->mouseUp( mWindowId, x_pos, y_pos );
00455
00456
00457 LLMozLib::getInstance()->focusBrowser( mWindowId, true );
00458
00459 return true;
00460 }
00461
00463
00464 bool LLMediaImplLLMozLib::mouseMove( int x_pos, int y_pos )
00465 {
00466 return LLMozLib::getInstance()->mouseMove( mWindowId, x_pos, y_pos );
00467 }
00468
00470
00471 bool LLMediaImplLLMozLib::keyPress( int key_code )
00472 {
00473
00474
00475
00476
00477
00478 unsigned long moz_key;
00479
00480 switch(key_code)
00481 {
00482 case LL_MEDIA_KEY_BACKSPACE:
00483 moz_key = LL_DOM_VK_BACK_SPACE; break;
00484 case LL_MEDIA_KEY_TAB:
00485 moz_key = LL_DOM_VK_TAB; break;
00486 case LL_MEDIA_KEY_RETURN:
00487 moz_key = LL_DOM_VK_RETURN; break;
00488 case LL_MEDIA_KEY_PAD_RETURN:
00489 moz_key = LL_DOM_VK_ENTER; break;
00490 case LL_MEDIA_KEY_ESCAPE:
00491 moz_key = LL_DOM_VK_ESCAPE; break;
00492 case LL_MEDIA_KEY_PAGE_UP:
00493 moz_key = LL_DOM_VK_PAGE_UP; break;
00494 case LL_MEDIA_KEY_PAGE_DOWN:
00495 moz_key = LL_DOM_VK_PAGE_DOWN; break;
00496 case LL_MEDIA_KEY_END:
00497 moz_key = LL_DOM_VK_END; break;
00498 case LL_MEDIA_KEY_HOME:
00499 moz_key = LL_DOM_VK_HOME; break;
00500 case LL_MEDIA_KEY_LEFT:
00501 moz_key = LL_DOM_VK_LEFT; break;
00502 case LL_MEDIA_KEY_UP:
00503 moz_key = LL_DOM_VK_UP; break;
00504 case LL_MEDIA_KEY_RIGHT:
00505 moz_key = LL_DOM_VK_RIGHT; break;
00506 case LL_MEDIA_KEY_DOWN:
00507 moz_key = LL_DOM_VK_DOWN; break;
00508 case LL_MEDIA_KEY_INSERT:
00509 moz_key = LL_DOM_VK_INSERT; break;
00510 case LL_MEDIA_KEY_DELETE:
00511 moz_key = LL_DOM_VK_DELETE; break;
00512
00513 default:
00514 return false;
00515 }
00516
00517 return LLMozLib::getInstance()->keyPress( mWindowId, moz_key );
00518 }
00519
00521
00522 bool LLMediaImplLLMozLib::scrollByLines( int lines )
00523 {
00524 return LLMozLib::getInstance()->scrollByLines(mWindowId, lines);
00525 }
00526
00528
00529 bool LLMediaImplLLMozLib::focus( bool focus )
00530 {
00531 return LLMozLib::getInstance()->focusBrowser(mWindowId, focus);
00532 }
00533
00535
00536 bool LLMediaImplLLMozLib::unicodeInput( unsigned long uni_char )
00537 {
00538 return LLMozLib::getInstance()->unicodeInput(mWindowId, uni_char);
00539 }
00540
00542
00543 bool LLMediaImplLLMozLib::mouseLeftDoubleClick( int x_pos, int y_pos )
00544 {
00545 return LLMozLib::getInstance()->mouseLeftDoubleClick( mWindowId, x_pos, y_pos );
00546 }
00547
00549
00550 bool LLMediaImplLLMozLib::navigateForward()
00551 {
00552 return LLMozLib::getInstance()->navigateForward(mWindowId);
00553 }
00554
00556
00557 bool LLMediaImplLLMozLib::navigateBack()
00558 {
00559 return LLMozLib::getInstance()->navigateBack(mWindowId);
00560 }
00561
00563
00564 bool LLMediaImplLLMozLib::canNavigateForward()
00565 {
00566 return LLMozLib::getInstance()->canNavigateForward(mWindowId);
00567 }
00568
00570
00571 bool LLMediaImplLLMozLib::canNavigateBack()
00572 {
00573 return LLMozLib::getInstance()->canNavigateBack(mWindowId);
00574 }
00575
00577
00578 bool LLMediaImplLLMozLib::enableCookies(bool enable)
00579 {
00580 return LLMozLib::getInstance()->enableCookies(enable);
00581 }
00582
00584
00585 bool LLMediaImplLLMozLib::enableProxy(bool enable, std::string proxy_host_name, int proxy_port)
00586 {
00587 return LLMozLib::getInstance()->enableProxy(enable, proxy_host_name, proxy_port);
00588 }
00589
00591
00592 bool LLMediaImplLLMozLib::clearCache()
00593 {
00594 return LLMozLib::getInstance()->clearCache();
00595 }
00596
00598
00599 bool LLMediaImplLLMozLib::clearCookies()
00600 {
00601 return LLMozLib::getInstance()->clearAllCookies();
00602 }
00603
00605
00606 bool LLMediaImplLLMozLib::reset()
00607 {
00608 LLMozLib::getInstance()->remObserver( mWindowId, this );
00609
00610 LLMozLib::getInstance()->destroyBrowserWindow( mWindowId );
00611
00612 mWindowId = 0;
00613
00614 return true;
00615 }
00616
00617 #endif // LL_LLMOZLIB_ENABLED