CefContextMenuParams.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. /// Provides information about the context menu state. The ethods of this class
  10. /// can only be accessed on browser process the UI thread.
  11. /// </summary>
  12. public sealed unsafe partial class CefContextMenuParams
  13. {
  14. /// <summary>
  15. /// Returns the X coordinate of the mouse where the context menu was invoked.
  16. /// Coords are relative to the associated RenderView's origin.
  17. /// </summary>
  18. public int X
  19. {
  20. get { return cef_context_menu_params_t.get_xcoord(_self); }
  21. }
  22. /// <summary>
  23. /// Returns the Y coordinate of the mouse where the context menu was invoked.
  24. /// Coords are relative to the associated RenderView's origin.
  25. /// </summary>
  26. public int Y
  27. {
  28. get { return cef_context_menu_params_t.get_ycoord(_self); }
  29. }
  30. /// <summary>
  31. /// Returns flags representing the type of node that the context menu was
  32. /// invoked on.
  33. /// </summary>
  34. public CefContextMenuTypeFlags ContextMenuType
  35. {
  36. get { return cef_context_menu_params_t.get_type_flags(_self); }
  37. }
  38. /// <summary>
  39. /// Returns the URL of the link, if any, that encloses the node that the
  40. /// context menu was invoked on.
  41. /// </summary>
  42. public string LinkUrl
  43. {
  44. get
  45. {
  46. var n_result = cef_context_menu_params_t.get_link_url(_self);
  47. return cef_string_userfree.ToString(n_result);
  48. }
  49. }
  50. /// <summary>
  51. /// Returns the link URL, if any, to be used ONLY for "copy link address". We
  52. /// don't validate this field in the frontend process.
  53. /// </summary>
  54. public string UnfilteredLinkUrl
  55. {
  56. get
  57. {
  58. var n_result = cef_context_menu_params_t.get_unfiltered_link_url(_self);
  59. return cef_string_userfree.ToString(n_result);
  60. }
  61. }
  62. /// <summary>
  63. /// Returns the source URL, if any, for the element that the context menu was
  64. /// invoked on. Example of elements with source URLs are img, audio, and video.
  65. /// </summary>
  66. public string SourceUrl
  67. {
  68. get
  69. {
  70. var n_result = cef_context_menu_params_t.get_source_url(_self);
  71. return cef_string_userfree.ToString(n_result);
  72. }
  73. }
  74. /// <summary>
  75. /// Returns true if the context menu was invoked on an image which has
  76. /// non-empty contents.
  77. /// </summary>
  78. public bool HasImageContents
  79. {
  80. get { return cef_context_menu_params_t.has_image_contents(_self) != 0; }
  81. }
  82. /// <summary>
  83. /// Returns the title text or the alt text if the context menu was invoked on
  84. /// an image.
  85. /// </summary>
  86. public string TitleText
  87. {
  88. get
  89. {
  90. var n_result = cef_context_menu_params_t.get_title_text(_self);
  91. return cef_string_userfree.ToString(n_result);
  92. }
  93. }
  94. /// <summary>
  95. /// Returns the URL of the top level page that the context menu was invoked on.
  96. /// </summary>
  97. public string PageUrl
  98. {
  99. get
  100. {
  101. var n_result = cef_context_menu_params_t.get_page_url(_self);
  102. return cef_string_userfree.ToString(n_result);
  103. }
  104. }
  105. /// <summary>
  106. /// Returns the URL of the subframe that the context menu was invoked on.
  107. /// </summary>
  108. public string FrameUrl
  109. {
  110. get
  111. {
  112. var n_result = cef_context_menu_params_t.get_frame_url(_self);
  113. return cef_string_userfree.ToString(n_result);
  114. }
  115. }
  116. /// <summary>
  117. /// Returns the character encoding of the subframe that the context menu was
  118. /// invoked on.
  119. /// </summary>
  120. public string FrameCharset
  121. {
  122. get
  123. {
  124. var n_result = cef_context_menu_params_t.get_frame_charset(_self);
  125. return cef_string_userfree.ToString(n_result);
  126. }
  127. }
  128. /// <summary>
  129. /// Returns the type of context node that the context menu was invoked on.
  130. /// </summary>
  131. public CefContextMenuMediaType MediaType
  132. {
  133. get { return cef_context_menu_params_t.get_media_type(_self); }
  134. }
  135. /// <summary>
  136. /// Returns flags representing the actions supported by the media element, if
  137. /// any, that the context menu was invoked on.
  138. /// </summary>
  139. public CefContextMenuMediaStateFlags MediaState
  140. {
  141. get { return cef_context_menu_params_t.get_media_state_flags(_self); }
  142. }
  143. /// <summary>
  144. /// Returns the text of the selection, if any, that the context menu was
  145. /// invoked on.
  146. /// </summary>
  147. public string SelectionText
  148. {
  149. get
  150. {
  151. var n_result = cef_context_menu_params_t.get_selection_text(_self);
  152. return cef_string_userfree.ToString(n_result);
  153. }
  154. }
  155. /// <summary>
  156. /// Returns the text of the misspelled word, if any, that the context menu was
  157. /// invoked on.
  158. /// </summary>
  159. public string GetMisspelledWord()
  160. {
  161. var n_result = cef_context_menu_params_t.get_misspelled_word(_self);
  162. return cef_string_userfree.ToString(n_result);
  163. }
  164. /// <summary>
  165. /// Returns true if suggestions exist, false otherwise. Fills in |suggestions|
  166. /// from the spell check service for the misspelled word if there is one.
  167. /// </summary>
  168. public string[] GetDictionarySuggestions()
  169. {
  170. var n_suggestions = libcef.string_list_alloc();
  171. cef_context_menu_params_t.get_dictionary_suggestions(_self, n_suggestions);
  172. var suggestions = cef_string_list.ToArray(n_suggestions);
  173. libcef.string_list_free(n_suggestions);
  174. return suggestions;
  175. }
  176. /// <summary>
  177. /// Returns true if the context menu was invoked on an editable node.
  178. /// </summary>
  179. public bool IsEditable
  180. {
  181. get { return cef_context_menu_params_t.is_editable(_self) != 0; }
  182. }
  183. /// <summary>
  184. /// Returns true if the context menu was invoked on an editable node where
  185. /// spell-check is enabled.
  186. /// </summary>
  187. public bool IsSpellCheckEnabled
  188. {
  189. get { return cef_context_menu_params_t.is_spell_check_enabled(_self) != 0; }
  190. }
  191. /// <summary>
  192. /// Returns flags representing the actions supported by the editable node, if
  193. /// any, that the context menu was invoked on.
  194. /// </summary>
  195. public CefContextMenuEditStateFlags EditState
  196. {
  197. get { return cef_context_menu_params_t.get_edit_state_flags(_self); }
  198. }
  199. /// <summary>
  200. /// Returns true if the context menu contains items specified by the renderer
  201. /// process (for example, plugin placeholder or pepper plugin menu items).
  202. /// </summary>
  203. public bool IsCustomMenu
  204. {
  205. get { return cef_context_menu_params_t.is_custom_menu(_self) != 0; }
  206. }
  207. }
  208. }