CefKeyboardHandler.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. using Xilium.CefGlue.Interop;
  8. /// <summary>
  9. /// Implement this interface to handle events related to keyboard input. The
  10. /// methods of this class will be called on the UI thread.
  11. /// </summary>
  12. public abstract unsafe partial class CefKeyboardHandler
  13. {
  14. private int on_pre_key_event(cef_keyboard_handler_t* self, cef_browser_t* browser, cef_key_event_t* @event, IntPtr os_event, int* is_keyboard_shortcut)
  15. {
  16. CheckSelf(self);
  17. var m_browser = CefBrowser.FromNative(browser);
  18. var m_event = CefKeyEvent.FromNative(@event); // TODO dispose?
  19. // TODO: wrap cef_event_handle_t (os_event)
  20. IntPtr m_os_event = IntPtr.Zero;
  21. if (os_event != IntPtr.Zero)
  22. {
  23. }
  24. var m_is_keyboard_shortcut = *is_keyboard_shortcut != 0;
  25. var result = OnPreKeyEvent(m_browser, m_event, m_os_event, out m_is_keyboard_shortcut);
  26. *is_keyboard_shortcut = m_is_keyboard_shortcut ? 1 : 0;
  27. return result ? 1 : 0;
  28. }
  29. /// <summary>
  30. /// Called before a keyboard event is sent to the renderer. |event| contains
  31. /// information about the keyboard event. |os_event| is the operating system
  32. /// event message, if any. Return true if the event was handled or false
  33. /// otherwise. If the event will be handled in OnKeyEvent() as a keyboard
  34. /// shortcut set |is_keyboard_shortcut| to true and return false.
  35. /// </summary>
  36. protected virtual bool OnPreKeyEvent(CefBrowser browser, CefKeyEvent keyEvent, IntPtr os_event, out bool isKeyboardShortcut)
  37. {
  38. isKeyboardShortcut = false;
  39. return false;
  40. }
  41. private int on_key_event(cef_keyboard_handler_t* self, cef_browser_t* browser, cef_key_event_t* @event, IntPtr os_event)
  42. {
  43. CheckSelf(self);
  44. var m_browser = CefBrowser.FromNative(browser);
  45. var m_event = CefKeyEvent.FromNative(@event); // TODO dispose?
  46. // TODO: wrap cef_event_handle_t (os_event)
  47. IntPtr m_os_event = IntPtr.Zero;
  48. if (os_event != IntPtr.Zero)
  49. {
  50. }
  51. var result = OnKeyEvent(m_browser, m_event, m_os_event);
  52. return result ? 1 : 0;
  53. }
  54. /// <summary>
  55. /// Called after the renderer and JavaScript in the page has had a chance to
  56. /// handle the event. |event| contains information about the keyboard event.
  57. /// |os_event| is the operating system event message, if any. Return true if
  58. /// the keyboard event was handled or false otherwise.
  59. /// </summary>
  60. protected virtual bool OnKeyEvent(CefBrowser browser, CefKeyEvent keyEvent, IntPtr osEvent)
  61. {
  62. return false;
  63. }
  64. }
  65. }