Skip to content

Commit

Permalink
Merge pull request #667 from numbersint/feature/event-flags
Browse files Browse the repository at this point in the history
Use the typed enum CefEventFlags for modifiers in keyboard events.
  • Loading branch information
amaitland committed Dec 4, 2014
2 parents 69de937 + 04e1290 commit 2c4723e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
21 changes: 2 additions & 19 deletions CefSharp.Core/Internals/ClientAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,6 @@ namespace CefSharp
_browserControl->OnStatusMessage(valueStr);
}

KeyType KeyTypeToManaged(cef_key_event_type_t keytype)
{
switch (keytype)
{
case KEYEVENT_RAWKEYDOWN:
return KeyType::RawKeyDown;
case KEYEVENT_KEYDOWN:
return KeyType::KeyDown;
case KEYEVENT_KEYUP:
return KeyType::KeyUp;
case KEYEVENT_CHAR:
return KeyType::Char;
default:
throw gcnew ArgumentOutOfRangeException("keytype", String::Format("'{0}' is not a valid keytype", gcnew array<Object^>(keytype)));
}
}

bool ClientAdapter::OnKeyEvent(CefRefPtr<CefBrowser> browser, const CefKeyEvent& event, CefEventHandle os_event)
{
IKeyboardHandler^ handler = _browserControl->KeyboardHandler;
Expand All @@ -140,7 +123,7 @@ namespace CefSharp

// TODO: windows_key_code could possibly be the wrong choice here (the OnKeyEvent signature has changed since CEF1). The
// other option would be native_key_code.
return handler->OnKeyEvent(_browserControl, KeyTypeToManaged(event.type), event.windows_key_code, event.modifiers, event.is_system_key == 1);
return handler->OnKeyEvent(_browserControl, (KeyType)event.type, event.windows_key_code, (CefEventFlags)event.modifiers, event.is_system_key == 1);
}

bool ClientAdapter::OnPreKeyEvent(CefRefPtr<CefBrowser> browser, const CefKeyEvent& event, CefEventHandle os_event, bool* is_keyboard_shortcut)
Expand All @@ -152,7 +135,7 @@ namespace CefSharp
return false;
}

return handler->OnPreKeyEvent(_browserControl, (KeyType)event.type, event.windows_key_code, event.native_key_code, event.modifiers, event.is_system_key == 1, *is_keyboard_shortcut);
return handler->OnPreKeyEvent(_browserControl, (KeyType)event.type, event.windows_key_code, event.native_key_code, (CefEventFlags)event.modifiers, event.is_system_key == 1, *is_keyboard_shortcut);
}

void ClientAdapter::OnLoadStart(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame)
Expand Down
4 changes: 2 additions & 2 deletions CefSharp/IKeyboardHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace CefSharp
{
public interface IKeyboardHandler
{
bool OnKeyEvent(IWebBrowser browser, KeyType type, int code, int modifiers, bool isSystemKey);
bool OnPreKeyEvent(IWebBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, int modifiers, bool isSystemKey, bool isKeyboardShortcut);
bool OnKeyEvent(IWebBrowser browser, KeyType type, int code, CefEventFlags modifiers, bool isSystemKey);
bool OnPreKeyEvent(IWebBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, bool isKeyboardShortcut);
}
}
2 changes: 1 addition & 1 deletion CefSharp/KeyType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace CefSharp
{
public enum KeyType
{
RawKeyDown,
RawKeyDown = 0,
KeyDown,
KeyUp,
Char,
Expand Down

0 comments on commit 2c4723e

Please sign in to comment.