mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-25 21:48:57 -05:00
Feature/cef speedup (#806)
* Improve cmake errors * Calling doMessageLoopWork more often to increase gui performance * Introduce frequent callbacks * Restructure browser update callbacks * Cleanup cef speedup * Add flag to toggle updating browser between renderable calls * CEF should not be used in single process mode * Update CEF version * Postbuild step for finding framework from web helper * Load libcef dynamically to fix issue with CEF update * Only include dynamic library loader on mac * Improve keyboard mapping support on MacOS * Add arrow keys * Rename manifest * Fix bug with missing blinking cursor in text fields * Bump minimum cmake version * CEF fixes: Runtime and correct helper path * Be true to actual sandbox compatibility specified by CEF * Cleanup
This commit is contained in:
committed by
Alexander Bock
parent
ba1aaa1672
commit
0dcf65ce4f
@@ -34,13 +34,13 @@ namespace {
|
||||
constexpr const char* _loggerCat = "WebBrowser:EventHandler";
|
||||
|
||||
/**
|
||||
* Map from GLFW key codes to "regular" key codes, supported by JS and CEF.
|
||||
* Map from GLFW key codes to windows key codes, supported by JS and CEF.
|
||||
* See http://keycode.info/ for lookup
|
||||
*
|
||||
* \param key
|
||||
* \return the key code, if mapped or the GLFW key code
|
||||
*/
|
||||
int mapFromGlfwToNative(openspace::Key key) {
|
||||
int mapFromGlfwToWindows(openspace::Key key) {
|
||||
switch (key) {
|
||||
case openspace::Key::BackSpace: return 8;
|
||||
case openspace::Key::Tab: return 9;
|
||||
@@ -54,6 +54,51 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
// Map from GLFW key codes to native key codes for Mac.
|
||||
// The keys inserted here are based from setting breakpoints in
|
||||
// the CEF-bundled 'cefclient' (browser_window_osr_mac.mm)
|
||||
// as well as trial and error.
|
||||
// There is an issue for proper cross-platform key events in CEF:
|
||||
// https://bitbucket.org/chromiumembedded/cef/issues/1750
|
||||
// For now, the 'important' keys are inserted here manually.
|
||||
int mapFromGlfwToNative(openspace::Key key) {
|
||||
switch (key) {
|
||||
case openspace::Key::BackSpace: return 51;
|
||||
case openspace::Key::LeftControl: return 59;
|
||||
case openspace::Key::LeftSuper: return 55;
|
||||
case openspace::Key::Enter: return 36;
|
||||
case openspace::Key::Left: return 123;
|
||||
case openspace::Key::Right: return 124;
|
||||
case openspace::Key::Up: return 126;
|
||||
case openspace::Key::Down: return 127;
|
||||
case openspace::Key::A: return 97;
|
||||
case openspace::Key::Num0: return 82;
|
||||
case openspace::Key::Num1: return 83;
|
||||
case openspace::Key::Num2: return 84;
|
||||
case openspace::Key::Num3: return 85;
|
||||
case openspace::Key::Num4: return 86;
|
||||
case openspace::Key::Num5: return 87;
|
||||
case openspace::Key::Num6: return 88;
|
||||
case openspace::Key::Num7: return 89;
|
||||
case openspace::Key::Num8: return 91; // Note: 91, not 90.
|
||||
case openspace::Key::Num9: return 92;
|
||||
default: return static_cast<int>(key);
|
||||
}
|
||||
}
|
||||
|
||||
int16_t mapFromGlfwToCharacter(openspace::Key key) {
|
||||
return static_cast<int16_t>(key);
|
||||
}
|
||||
|
||||
// This is needed to avoid the backspace up event to trigger backspace.
|
||||
int16_t mapFromGlfwToUnmodifiedCharacter(openspace::Key key) {
|
||||
switch (key) {
|
||||
case openspace::Key::BackSpace: return 127;
|
||||
case openspace::Key::A: return 97;
|
||||
default: return static_cast<int16_t>(key);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t mapToCefModifiers(openspace::KeyModifier modifiers) {
|
||||
uint32_t cefModifiers = 0;
|
||||
// Based on cef_event_flags_t in cef_types.h
|
||||
@@ -66,6 +111,9 @@ namespace {
|
||||
if (hasKeyModifier(modifiers, openspace::KeyModifier::Alt)) {
|
||||
cefModifiers |= 1 << 3;
|
||||
}
|
||||
if (hasKeyModifier(modifiers, openspace::KeyModifier::Super)) {
|
||||
cefModifiers |= 1 << 7;
|
||||
}
|
||||
return cefModifiers;
|
||||
}
|
||||
|
||||
@@ -238,33 +286,43 @@ bool EventHandler::mouseWheelCallback(glm::ivec2 delta) {
|
||||
|
||||
bool EventHandler::charCallback(unsigned int charCode, KeyModifier modifier) {
|
||||
CefKeyEvent keyEvent;
|
||||
keyEvent.windows_key_code = charCode;
|
||||
keyEvent.character = charCode;
|
||||
keyEvent.windows_key_code = mapFromGlfwToWindows(Key(charCode));
|
||||
keyEvent.character = mapFromGlfwToCharacter(Key(charCode));
|
||||
keyEvent.native_key_code = mapFromGlfwToNative(Key(charCode));
|
||||
keyEvent.modifiers = static_cast<uint32>(modifier);
|
||||
keyEvent.type = KEYEVENT_CHAR;
|
||||
// TODO(klas): figure out when to block
|
||||
|
||||
return _browserInstance->sendKeyEvent(keyEvent);
|
||||
}
|
||||
|
||||
bool EventHandler::keyboardCallback(Key key, KeyModifier modifier, KeyAction action) {
|
||||
if (specialKeyEvent(key)) {
|
||||
if (specialKeyEvent(key, modifier, action)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
CefKeyEvent keyEvent;
|
||||
|
||||
// TODO(klas): Use something less platform specific?
|
||||
keyEvent.windows_key_code = mapFromGlfwToNative(key);
|
||||
keyEvent.modifiers = mapToCefModifiers(modifier);
|
||||
keyEvent.type = keyEventType(action);
|
||||
// TODO(klas): figure out when to block
|
||||
keyEvent.windows_key_code = mapFromGlfwToWindows(key);
|
||||
keyEvent.native_key_code = mapFromGlfwToNative(key);
|
||||
keyEvent.unmodified_character = mapFromGlfwToUnmodifiedCharacter(key);
|
||||
keyEvent.modifiers = mapToCefModifiers(modifier);
|
||||
keyEvent.type = keyEventType(action);
|
||||
|
||||
return _browserInstance->sendKeyEvent(keyEvent);
|
||||
}
|
||||
|
||||
bool EventHandler::specialKeyEvent(Key key) {
|
||||
bool EventHandler::specialKeyEvent(Key key, KeyModifier mod, KeyAction) {
|
||||
switch (key) {
|
||||
case Key::F5:
|
||||
_browserInstance->reloadBrowser();
|
||||
return true;
|
||||
case Key::A:
|
||||
if (hasKeyModifier(mod, KeyModifier::Super)) {
|
||||
_browserInstance->selectAll();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user