1 // Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_OSR_H_ 6 #define CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_OSR_H_ 7 #pragma once 8 9 #include "tests/cefclient/browser/client_handler.h" 10 11 namespace client { 12 13 // Client handler implementation for windowless browsers. There will only ever 14 // be one browser per handler instance. 15 class ClientHandlerOsr : public ClientHandler, 16 public CefAccessibilityHandler, 17 public CefRenderHandler { 18 public: 19 // Implement this interface to receive notification of ClientHandlerOsr 20 // events. The methods of this class will be called on the CEF UI thread. 21 class OsrDelegate { 22 public: 23 // These methods match the CefLifeSpanHandler interface. 24 virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) = 0; 25 virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) = 0; 26 27 // These methods match the CefRenderHandler interface. 28 virtual bool GetRootScreenRect(CefRefPtr<CefBrowser> browser, 29 CefRect& rect) = 0; 30 virtual void GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) = 0; 31 virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser, 32 int viewX, 33 int viewY, 34 int& screenX, 35 int& screenY) = 0; 36 virtual bool GetScreenInfo(CefRefPtr<CefBrowser> browser, 37 CefScreenInfo& screen_info) = 0; 38 virtual void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) = 0; 39 virtual void OnPopupSize(CefRefPtr<CefBrowser> browser, 40 const CefRect& rect) = 0; 41 virtual void OnPaint(CefRefPtr<CefBrowser> browser, 42 CefRenderHandler::PaintElementType type, 43 const CefRenderHandler::RectList& dirtyRects, 44 const void* buffer, 45 int width, 46 int height) = 0; OnAcceleratedPaint(CefRefPtr<CefBrowser> browser,CefRenderHandler::PaintElementType type,const CefRenderHandler::RectList & dirtyRects,void * share_handle)47 virtual void OnAcceleratedPaint( 48 CefRefPtr<CefBrowser> browser, 49 CefRenderHandler::PaintElementType type, 50 const CefRenderHandler::RectList& dirtyRects, 51 void* share_handle) {} 52 virtual bool StartDragging(CefRefPtr<CefBrowser> browser, 53 CefRefPtr<CefDragData> drag_data, 54 CefRenderHandler::DragOperationsMask allowed_ops, 55 int x, 56 int y) = 0; 57 virtual void UpdateDragCursor( 58 CefRefPtr<CefBrowser> browser, 59 CefRenderHandler::DragOperation operation) = 0; 60 virtual void OnImeCompositionRangeChanged( 61 CefRefPtr<CefBrowser> browser, 62 const CefRange& selection_range, 63 const CefRenderHandler::RectList& character_bounds) = 0; 64 65 // These methods match the CefDisplayHandler interface. 66 virtual void OnCursorChange(CefRefPtr<CefBrowser> browser, 67 CefCursorHandle cursor, 68 cef_cursor_type_t type, 69 const CefCursorInfo& custom_cursor_info) = 0; 70 71 virtual void UpdateAccessibilityTree(CefRefPtr<CefValue> value) = 0; 72 virtual void UpdateAccessibilityLocation(CefRefPtr<CefValue> value) = 0; 73 74 protected: ~OsrDelegate()75 virtual ~OsrDelegate() {} 76 }; 77 78 ClientHandlerOsr(Delegate* delegate, 79 OsrDelegate* osr_delegate, 80 const std::string& startup_url); 81 82 // This object may outlive the OsrDelegate object so it's necessary for the 83 // OsrDelegate to detach itself before destruction. 84 void DetachOsrDelegate(); 85 86 // CefClient methods. GetRenderHandler()87 CefRefPtr<CefRenderHandler> GetRenderHandler() override { return this; } GetAccessibilityHandler()88 CefRefPtr<CefAccessibilityHandler> GetAccessibilityHandler() override { 89 return this; 90 } 91 92 // CefLifeSpanHandler methods. 93 void OnAfterCreated(CefRefPtr<CefBrowser> browser) override; 94 void OnBeforeClose(CefRefPtr<CefBrowser> browser) override; 95 96 // CefRenderHandler methods. 97 bool GetRootScreenRect(CefRefPtr<CefBrowser> browser, CefRect& rect) override; 98 void GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) override; 99 bool GetScreenPoint(CefRefPtr<CefBrowser> browser, 100 int viewX, 101 int viewY, 102 int& screenX, 103 int& screenY) override; 104 bool GetScreenInfo(CefRefPtr<CefBrowser> browser, 105 CefScreenInfo& screen_info) override; 106 void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) override; 107 void OnPopupSize(CefRefPtr<CefBrowser> browser, const CefRect& rect) override; 108 void OnPaint(CefRefPtr<CefBrowser> browser, 109 CefRenderHandler::PaintElementType type, 110 const CefRenderHandler::RectList& dirtyRects, 111 const void* buffer, 112 int width, 113 int height) override; 114 void OnAcceleratedPaint(CefRefPtr<CefBrowser> browser, 115 CefRenderHandler::PaintElementType type, 116 const CefRenderHandler::RectList& dirtyRects, 117 void* share_handle) override; 118 bool StartDragging(CefRefPtr<CefBrowser> browser, 119 CefRefPtr<CefDragData> drag_data, 120 CefRenderHandler::DragOperationsMask allowed_ops, 121 int x, 122 int y) override; 123 void UpdateDragCursor(CefRefPtr<CefBrowser> browser, 124 CefRenderHandler::DragOperation operation) override; 125 void OnImeCompositionRangeChanged( 126 CefRefPtr<CefBrowser> browser, 127 const CefRange& selection_range, 128 const CefRenderHandler::RectList& character_bounds) override; 129 130 // CefDisplayHandler methods. 131 bool OnCursorChange(CefRefPtr<CefBrowser> browser, 132 CefCursorHandle cursor, 133 cef_cursor_type_t type, 134 const CefCursorInfo& custom_cursor_info) override; 135 136 // CefAccessibilityHandler methods. 137 void OnAccessibilityTreeChange(CefRefPtr<CefValue> value) override; 138 void OnAccessibilityLocationChange(CefRefPtr<CefValue> value) override; 139 140 private: 141 // Only accessed on the UI thread. 142 OsrDelegate* osr_delegate_; 143 144 // Include the default reference counting implementation. 145 IMPLEMENT_REFCOUNTING(ClientHandlerOsr); 146 DISALLOW_COPY_AND_ASSIGN(ClientHandlerOsr); 147 }; 148 149 } // namespace client 150 151 #endif // CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_OSR_H_ 152