CefMenuModelDelegate.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 menu model events. The methods of this
  10. /// class will be called on the browser process UI thread unless otherwise
  11. /// indicated.
  12. /// </summary>
  13. public abstract unsafe partial class CefMenuModelDelegate
  14. {
  15. private void execute_command(cef_menu_model_delegate_t* self, cef_menu_model_t* menu_model, int command_id, CefEventFlags event_flags)
  16. {
  17. CheckSelf(self);
  18. var m_menuModel = CefMenuModel.FromNative(menu_model); // TODO dispose?
  19. ExecuteCommand(m_menuModel, command_id, event_flags);
  20. }
  21. /// <summary>
  22. /// Perform the action associated with the specified |command_id| and
  23. /// optional |event_flags|.
  24. /// </summary>
  25. protected abstract void ExecuteCommand(CefMenuModel menuModel, int commandId, CefEventFlags eventFlags);
  26. private void mouse_outside_menu(cef_menu_model_delegate_t* self, cef_menu_model_t* menu_model, cef_point_t* screen_point)
  27. {
  28. CheckSelf(self);
  29. var m_menuModel = CefMenuModel.FromNative(menu_model); // TODO dispose?
  30. var m_screenPoint = new CefPoint(screen_point->x, screen_point->y);
  31. MouseOutsideMenu(m_menuModel, m_screenPoint);
  32. }
  33. /// <summary>
  34. /// Called when the user moves the mouse outside the menu and over the owning
  35. /// window.
  36. /// </summary>
  37. protected virtual void MouseOutsideMenu(CefMenuModel menuModel, CefPoint screenPoint) { }
  38. private void unhandled_open_submenu(cef_menu_model_delegate_t* self, cef_menu_model_t* menu_model, int is_rtl)
  39. {
  40. CheckSelf(self);
  41. var m_menuModel = CefMenuModel.FromNative(menu_model); // TODO dispose?
  42. UnhandledOpenSubmenu(m_menuModel, is_rtl != 0);
  43. }
  44. /// <summary>
  45. /// Called on unhandled open submenu keyboard commands. |is_rtl| will be true
  46. /// if the menu is displaying a right-to-left language.
  47. /// </summary>
  48. protected virtual void UnhandledOpenSubmenu(CefMenuModel menuModel, bool isRtl) { }
  49. private void unhandled_close_submenu(cef_menu_model_delegate_t* self, cef_menu_model_t* menu_model, int is_rtl)
  50. {
  51. CheckSelf(self);
  52. var m_menuModel = CefMenuModel.FromNative(menu_model); // TODO dispose?
  53. UnhandledCloseSubmenu(m_menuModel, is_rtl != 0);
  54. }
  55. /// <summary>
  56. /// Called on unhandled close submenu keyboard commands. |is_rtl| will be true
  57. /// if the menu is displaying a right-to-left language.
  58. /// </summary>
  59. protected virtual void UnhandledCloseSubmenu(CefMenuModel menuModel, bool isRtl) { }
  60. private void menu_will_show(cef_menu_model_delegate_t* self, cef_menu_model_t* menu_model)
  61. {
  62. CheckSelf(self);
  63. var m_menuModel = CefMenuModel.FromNative(menu_model); // TODO dispose?
  64. MenuWillShow(m_menuModel);
  65. }
  66. /// <summary>
  67. /// The menu is about to show.
  68. /// </summary>
  69. protected abstract void MenuWillShow(CefMenuModel menuModel);
  70. private void menu_closed(cef_menu_model_delegate_t* self, cef_menu_model_t* menu_model)
  71. {
  72. CheckSelf(self);
  73. var m_menuModel = CefMenuModel.FromNative(menu_model); // TODO dispose?
  74. MenuClosed(m_menuModel);
  75. }
  76. /// <summary>
  77. /// The menu has closed.
  78. /// </summary>
  79. protected abstract void MenuClosed(CefMenuModel menuModel);
  80. private int format_label(cef_menu_model_delegate_t* self, cef_menu_model_t* menu_model, cef_string_t* label)
  81. {
  82. CheckSelf(self);
  83. var m_menuModel = CefMenuModel.FromNative(menu_model); // TODO dispose?
  84. var m_label = cef_string_t.ToString(label);
  85. if (FormatLabel(m_menuModel, ref m_label))
  86. {
  87. cef_string_t.Copy(m_label, label);
  88. return 1;
  89. }
  90. else
  91. {
  92. return 0;
  93. }
  94. }
  95. /// <summary>
  96. /// Optionally modify a menu item label. Return true if |label| was modified.
  97. /// </summary>
  98. protected abstract bool FormatLabel(CefMenuModel menuModel, ref string label);
  99. }
  100. }