WebClient.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include <Atomic/Container/List.h>
  3. #include <Atomic/Core/Object.h>
  4. #include "WebRenderHandler.h"
  5. class CefClient;
  6. namespace Atomic
  7. {
  8. class WebClientPrivate;
  9. class WebMessageHandler;
  10. /// WebClient is the main interface for communicating with a browser instance
  11. class ATOMIC_API WebClient : public Object
  12. {
  13. friend class WebBrowserHost;
  14. friend class WebClientPrivate;
  15. OBJECT(WebClient)
  16. public:
  17. /// Construct.
  18. WebClient(Context* context);
  19. /// Destruct.
  20. virtual ~WebClient();
  21. /// Create the browser, call only once initialized with handlers
  22. bool CreateBrowser(const String& initialURL, int width, int height);
  23. /// Set the browser's width and height
  24. void SetSize(int width, int height);
  25. /// Send a mouse click event to the browser
  26. void SendMouseClickEvent(int x, int y, unsigned button, bool mouseUp, unsigned modifier, int clickCount = 1) const;
  27. /// Send a mouse press event to the browser
  28. void SendMousePressEvent(int x, int y, unsigned button = 0, unsigned modifier = 0, int clickCount = 1) const;
  29. /// Send a mouse move event to the browser
  30. void SendMouseMoveEvent(int x, int y, unsigned modifier, bool mouseLeave = false) const;
  31. /// Send a mouse wheel event to the browser
  32. void SendMouseWheelEvent(int x, int y, unsigned modifier, int deltaX, int deltaY) const;
  33. /// Send a focus event to the browser
  34. void SendFocusEvent(bool focus = true);
  35. /// Send a TextInput event to the browser
  36. void SendTextInputEvent(const StringHash eventType, VariantMap& eventData);
  37. /// Send a key event to the browser
  38. void SendKeyEvent(const StringHash eventType, VariantMap& eventData);
  39. // Shortcuts, note that some web pages (notably some text editors)
  40. // only work with key events and not all shorcuts
  41. /// Invoke the Cut shortcut on the browser's main frame
  42. void ShortcutCut();
  43. /// Invoke the Copy shortcut on the browser's main frame
  44. void ShortcutCopy();
  45. /// Invoke the Paste shortcut on the browser's main frame
  46. void ShortcutPaste();
  47. /// Invoke the SelectAll shortcut on the browser's main frame
  48. void ShortcutSelectAll();
  49. /// Invoke the Undo shortcut on the browser's main frame
  50. void ShortcutUndo();
  51. /// Invoke the Redo shortcut on the browser's main frame
  52. void ShortcutRedo();
  53. /// Invoke the Delete shortcut on the browser's main frame
  54. void ShortcutDelete();
  55. /// Add a message handler to the WebClient
  56. void AddMessageHandler(WebMessageHandler* handler, bool first = false);
  57. /// Remove a message handler to the WebClient
  58. void RemoveMessageHandler(WebMessageHandler* handler);
  59. /// Execute some JavaScript in the browser
  60. void ExecuteJavaScript(const String& script);
  61. // Navigation
  62. /// Returns true if the page is currently loading
  63. bool IsLoading();
  64. /// Load the specified url into the main frame of the browser
  65. void LoadURL(const String& url);
  66. /// Go back in page history
  67. void GoBack();
  68. /// Go forward in page history
  69. void GoForward();
  70. /// Reload the current page
  71. void Reload();
  72. /// Set the render handler for this client
  73. void SetWebRenderHandler(WebRenderHandler* handler);
  74. /// Get the (internal) CefClient for this WebClient
  75. CefClient* GetCefClient();
  76. private:
  77. void WasResized();
  78. SharedPtr<WebRenderHandler> renderHandler_;
  79. List<SharedPtr<WebMessageHandler>> messageHandlers_;
  80. WebClientPrivate* d_;
  81. };
  82. }