diff options
author | Bryan O'Sullivan <bos@lindenlab.com> | 2009-11-03 13:39:02 -0800 |
---|---|---|
committer | Bryan O'Sullivan <bos@lindenlab.com> | 2009-11-03 13:39:02 -0800 |
commit | 28ed8f84d86403cf90b7963b147d2ac5c6cf37c7 (patch) | |
tree | cebb2895642b96aa64e8cf8c2eb402e8423165d6 /indra/media_plugins/webkit/media_plugin_webkit.cpp | |
parent | 9c3595465972ba4be916e871f6b0a62cc0c13d4a (diff) | |
parent | 63b9bd43ff41da01d549f630bd838caff0dffd97 (diff) |
Merge with SVN render-pipeline-8 branch
Diffstat (limited to 'indra/media_plugins/webkit/media_plugin_webkit.cpp')
-rw-r--r-- | indra/media_plugins/webkit/media_plugin_webkit.cpp | 186 |
1 files changed, 130 insertions, 56 deletions
diff --git a/indra/media_plugins/webkit/media_plugin_webkit.cpp b/indra/media_plugins/webkit/media_plugin_webkit.cpp index eb2457744a..3ce8ff3deb 100644 --- a/indra/media_plugins/webkit/media_plugin_webkit.cpp +++ b/indra/media_plugins/webkit/media_plugin_webkit.cpp @@ -48,6 +48,18 @@ #include <stdlib.h> #endif +#if LL_WINDOWS + // *NOTE:Mani - This captures the module handle fo rthe dll. This is used below + // to get the path to this dll for webkit initialization. + // I don't know how/if this can be done with apr... + namespace { HMODULE gModuleHandle;}; + BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) + { + gModuleHandle = (HMODULE) hinstDLL; + return TRUE; + } +#endif + //////////////////////////////////////////////////////////////////////////////// // class MediaPluginWebKit : @@ -69,6 +81,9 @@ private: bool mCanCut; bool mCanCopy; bool mCanPaste; + int mLastMouseX; + int mLastMouseY; + bool mFirstFocus; //////////////////////////////////////////////////////////////////////////////// // @@ -126,7 +141,31 @@ private: return false; } std::string application_dir = std::string( cwd ); + +#if LL_WINDOWS + //*NOTE:Mani - On windows, at least, the component path is the + // location of this dll's image file. + std::string component_dir; + char dll_path[_MAX_PATH]; + DWORD len = GetModuleFileNameA(gModuleHandle, (LPCH)&dll_path, _MAX_PATH); + while(len && dll_path[ len ] != ('\\') ) + { + len--; + } + if(len >= 0) + { + dll_path[len] = 0; + component_dir = dll_path; + } + else + { + // *NOTE:Mani - This case should be an rare exception. + // GetModuleFileNameA should always give you a full path, no? + component_dir = application_dir; + } +#else std::string component_dir = application_dir; +#endif std::string profileDir = application_dir + "/" + "browser_profile"; // cross platform? // window handle - needed on Windows and must be app window. @@ -147,7 +186,7 @@ private: #if LL_WINDOWS // Enable plugins - LLQtWebKit::getInstance()->enablePlugins(false); + LLQtWebKit::getInstance()->enablePlugins(true); #elif LL_DARWIN // Disable plugins LLQtWebKit::getInstance()->enablePlugins(false); @@ -168,14 +207,13 @@ private: // don't flip bitmap LLQtWebKit::getInstance()->flipWindow( mBrowserWindowId, true ); - // Set the background color to black - LLQtWebKit::getInstance()-> // set background color to be black - mostly for initial login page LLQtWebKit::getInstance()->setBackgroundColor( mBrowserWindowId, 0x00, 0x00, 0x00 ); - // go to the "home page" // Don't do this here -- it causes the dreaded "white flash" when loading a browser instance. -// LLQtWebKit::getInstance()->navigateTo( mBrowserWindowId, "about:blank" ); + // FIXME: Re-added this because navigating to a "page" initializes things correctly - especially + // for the HTTP AUTH dialog issues (DEV-41731). Will fix at a later date. + LLQtWebKit::getInstance()->navigateTo( mBrowserWindowId, "about:blank" ); // set flag so we don't do this again mBrowserInitialized = true; @@ -272,7 +310,16 @@ private: message.setValue("status", event.getStringValue()); sendMessage(message); } - + + //////////////////////////////////////////////////////////////////////////////// + // virtual + void onTitleChange(const EventType& event) + { + LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "name_text"); + message.setValue("name", event.getStringValue()); + sendMessage(message); + } + //////////////////////////////////////////////////////////////////////////////// // virtual void onLocationChange(const EventType& event) @@ -300,33 +347,30 @@ private: message.setValue("uri", event.getStringValue()); sendMessage(message); } - - //////////////////////////////////////////////////////////////////////////////// - // - void mouseDown( int x, int y ) - { - LLQtWebKit::getInstance()->mouseDown( mBrowserWindowId, x, y ); - }; - - //////////////////////////////////////////////////////////////////////////////// - // - void mouseUp( int x, int y ) + + LLQtWebKit::EKeyboardModifier decodeModifiers(std::string &modifiers) { - LLQtWebKit::getInstance()->mouseUp( mBrowserWindowId, x, y ); - LLQtWebKit::getInstance()->focusBrowser( mBrowserWindowId, true ); - checkEditState(); - }; + int result = 0; + + if(modifiers.find("shift") != std::string::npos) + result |= LLQtWebKit::KM_MODIFIER_SHIFT; - //////////////////////////////////////////////////////////////////////////////// - // - void mouseMove( int x, int y ) - { - LLQtWebKit::getInstance()->mouseMove( mBrowserWindowId, x, y ); - }; + if(modifiers.find("alt") != std::string::npos) + result |= LLQtWebKit::KM_MODIFIER_ALT; + + if(modifiers.find("control") != std::string::npos) + result |= LLQtWebKit::KM_MODIFIER_CONTROL; + + if(modifiers.find("meta") != std::string::npos) + result |= LLQtWebKit::KM_MODIFIER_META; + + return (LLQtWebKit::EKeyboardModifier)result; + } + //////////////////////////////////////////////////////////////////////////////// // - void keyPress( int key ) + void keyEvent(LLQtWebKit::EKeyEvent key_event, int key, LLQtWebKit::EKeyboardModifier modifiers) { int llqt_key; @@ -380,7 +424,7 @@ private: if(llqt_key != 0) { - LLQtWebKit::getInstance()->keyPress( mBrowserWindowId, llqt_key ); + LLQtWebKit::getInstance()->keyEvent( mBrowserWindowId, key_event, llqt_key, modifiers); } checkEditState(); @@ -388,7 +432,7 @@ private: //////////////////////////////////////////////////////////////////////////////// // - void unicodeInput( const std::string &utf8str ) + void unicodeInput( const std::string &utf8str, LLQtWebKit::EKeyboardModifier modifiers) { LLWString wstr = utf8str_to_wstring(utf8str); @@ -397,7 +441,7 @@ private: { // std::cerr << "unicode input, code = 0x" << std::hex << (unsigned long)(wstr[i]) << std::dec << std::endl; - LLQtWebKit::getInstance()->unicodeInput(mBrowserWindowId, wstr[i]); + LLQtWebKit::getInstance()->unicodeInput(mBrowserWindowId, wstr[i], modifiers); } checkEditState(); @@ -449,6 +493,9 @@ MediaPluginWebKit::MediaPluginWebKit(LLPluginInstance::sendMessageFunction host_ mCanCut = false; mCanCopy = false; mCanPaste = false; + mLastMouseX = 0; + mLastMouseY = 0; + mFirstFocus = true; } MediaPluginWebKit::~MediaPluginWebKit() @@ -633,66 +680,84 @@ void MediaPluginWebKit::receiveMessage(const char *message_string) else if(message_name == "mouse_event") { std::string event = message_in.getValue("event"); - S32 x = message_in.getValueS32("x"); - S32 y = message_in.getValueS32("y"); - // std::string modifiers = message.getValue("modifiers"); - + S32 button = message_in.getValueS32("button"); + mLastMouseX = message_in.getValueS32("x"); + mLastMouseY = message_in.getValueS32("y"); + std::string modifiers = message_in.getValue("modifiers"); + + // Treat unknown mouse events as mouse-moves. + LLQtWebKit::EMouseEvent mouse_event = LLQtWebKit::ME_MOUSE_MOVE; if(event == "down") { - mouseDown(x, y); - //std::cout << "Mouse down at " << x << " x " << y << std::endl; + mouse_event = LLQtWebKit::ME_MOUSE_DOWN; } else if(event == "up") { - mouseUp(x, y); - //std::cout << "Mouse up at " << x << " x " << y << std::endl; + mouse_event = LLQtWebKit::ME_MOUSE_UP; } - else if(event == "move") + else if(event == "double_click") { - mouseMove(x, y); - //std::cout << ">>>>>>>>>>>>>>>>>>>> Mouse move at " << x << " x " << y << std::endl; + mouse_event = LLQtWebKit::ME_MOUSE_DOUBLE_CLICK; } + + LLQtWebKit::getInstance()->mouseEvent( mBrowserWindowId, mouse_event, button, mLastMouseX, mLastMouseY, decodeModifiers(modifiers)); + checkEditState(); } else if(message_name == "scroll_event") { - // S32 x = message_in.getValueS32("x"); + S32 x = message_in.getValueS32("x"); S32 y = message_in.getValueS32("y"); - // std::string modifiers = message.getValue("modifiers"); + std::string modifiers = message_in.getValue("modifiers"); + + // Incoming scroll events are adjusted so that 1 detent is approximately 1 unit. + // Qt expects 1 detent to be 120 units. + // It also seems that our y scroll direction is inverted vs. what Qt expects. - // We currently ignore horizontal scrolling. - // The scroll values are roughly 1 per wheel click, so we need to magnify them by some factor. - // Arbitrarily, I choose 16. - y *= 16; - LLQtWebKit::getInstance()->scrollByLines(mBrowserWindowId, y); + x *= 120; + y *= -120; + + LLQtWebKit::getInstance()->scrollWheelEvent(mBrowserWindowId, mLastMouseX, mLastMouseY, x, y, decodeModifiers(modifiers)); } else if(message_name == "key_event") { std::string event = message_in.getValue("event"); - - // act on "key down" or "key repeat" - if ( (event == "down") || (event == "repeat") ) + S32 key = message_in.getValueS32("key"); + std::string modifiers = message_in.getValue("modifiers"); + + // Treat unknown events as key-up for safety. + LLQtWebKit::EKeyEvent key_event = LLQtWebKit::KE_KEY_UP; + if(event == "down") { - S32 key = message_in.getValueS32("key"); - keyPress( key ); - }; + key_event = LLQtWebKit::KE_KEY_DOWN; + } + else if(event == "repeat") + { + key_event = LLQtWebKit::KE_KEY_REPEAT; + } + + keyEvent(key_event, key, decodeModifiers(modifiers)); } else if(message_name == "text_event") { std::string text = message_in.getValue("text"); + std::string modifiers = message_in.getValue("modifiers"); - unicodeInput(text); + unicodeInput(text, decodeModifiers(modifiers)); } if(message_name == "edit_cut") { LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_EDIT_CUT ); + checkEditState(); } if(message_name == "edit_copy") { LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_EDIT_COPY ); + checkEditState(); } if(message_name == "edit_paste") { LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_EDIT_PASTE ); + checkEditState(); } else { @@ -705,6 +770,15 @@ void MediaPluginWebKit::receiveMessage(const char *message_string) { bool val = message_in.getValueBoolean("focused"); LLQtWebKit::getInstance()->focusBrowser( mBrowserWindowId, val ); + + if(mFirstFocus && val) + { + // On the first focus, post a tab key event. This fixes a problem with initial focus. + std::string empty; + keyEvent(LLQtWebKit::KE_KEY_DOWN, KEY_TAB, decodeModifiers(empty)); + keyEvent(LLQtWebKit::KE_KEY_UP, KEY_TAB, decodeModifiers(empty)); + mFirstFocus = false; + } } else if(message_name == "clear_cache") { |