1 // Copyright 2015 The Chromium Embedded Framework Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_BROWSER_OSR_BROWSER_PLATFORM_DELEGATE_OSR_H_ 6 #define CEF_LIBCEF_BROWSER_OSR_BROWSER_PLATFORM_DELEGATE_OSR_H_ 7 8 #include "libcef/browser/alloy/browser_platform_delegate_alloy.h" 9 #include "libcef/browser/native/browser_platform_delegate_native.h" 10 11 class CefRenderWidgetHostViewOSR; 12 class CefWebContentsViewOSR; 13 14 namespace content { 15 class RenderWidgetHostImpl; 16 } 17 18 // Base implementation of windowless browser functionality. 19 class CefBrowserPlatformDelegateOsr 20 : public CefBrowserPlatformDelegateAlloy, 21 public CefBrowserPlatformDelegateNative::WindowlessHandler { 22 public: 23 // CefBrowserPlatformDelegate methods: 24 void CreateViewForWebContents( 25 content::WebContentsView** view, 26 content::RenderViewHostDelegateView** delegate_view) override; 27 void WebContentsCreated(content::WebContents* web_contents, 28 bool owned) override; 29 void RenderViewCreated(content::RenderViewHost* render_view_host) override; 30 void BrowserCreated(CefBrowserHostBase* browser) override; 31 void NotifyBrowserDestroyed() override; 32 void BrowserDestroyed(CefBrowserHostBase* browser) override; 33 SkColor GetBackgroundColor() const override; 34 void WasResized() override; 35 void SendKeyEvent(const CefKeyEvent& event) override; 36 void SendMouseClickEvent(const CefMouseEvent& event, 37 CefBrowserHost::MouseButtonType type, 38 bool mouseUp, 39 int clickCount) override; 40 void SendMouseMoveEvent(const CefMouseEvent& event, bool mouseLeave) override; 41 void SendMouseWheelEvent(const CefMouseEvent& event, 42 int deltaX, 43 int deltaY) override; 44 void SendTouchEvent(const CefTouchEvent& event) override; 45 void SetFocus(bool setFocus) override; 46 gfx::Point GetScreenPoint(const gfx::Point& view) const override; 47 void ViewText(const std::string& text) override; 48 bool HandleKeyboardEvent( 49 const content::NativeWebKeyboardEvent& event) override; 50 CefEventHandle GetEventHandle( 51 const content::NativeWebKeyboardEvent& event) const override; 52 std::unique_ptr<CefFileDialogRunner> CreateFileDialogRunner() override; 53 std::unique_ptr<CefJavaScriptDialogRunner> CreateJavaScriptDialogRunner() 54 override; 55 std::unique_ptr<CefMenuRunner> CreateMenuRunner() override; 56 bool IsWindowless() const override; 57 void WasHidden(bool hidden) override; 58 void NotifyScreenInfoChanged() override; 59 void Invalidate(cef_paint_element_type_t type) override; 60 void SendExternalBeginFrame() override; 61 void SetWindowlessFrameRate(int frame_rate) override; 62 void ImeSetComposition(const CefString& text, 63 const std::vector<CefCompositionUnderline>& underlines, 64 const CefRange& replacement_range, 65 const CefRange& selection_range) override; 66 void ImeCommitText(const CefString& text, 67 const CefRange& replacement_range, 68 int relative_cursor_pos) override; 69 void ImeFinishComposingText(bool keep_selection) override; 70 void ImeCancelComposition() override; 71 void DragTargetDragEnter(CefRefPtr<CefDragData> drag_data, 72 const CefMouseEvent& event, 73 cef_drag_operations_mask_t allowed_ops) override; 74 void DragTargetDragOver(const CefMouseEvent& event, 75 cef_drag_operations_mask_t allowed_ops) override; 76 void DragTargetDragLeave() override; 77 void DragTargetDrop(const CefMouseEvent& event) override; 78 void StartDragging(const content::DropData& drop_data, 79 blink::DragOperationsMask allowed_ops, 80 const gfx::ImageSkia& image, 81 const gfx::Vector2d& image_offset, 82 const blink::mojom::DragEventSourceInfo& event_info, 83 content::RenderWidgetHostImpl* source_rwh) override; 84 void UpdateDragCursor(ui::mojom::DragOperation operation) override; 85 void DragSourceEndedAt(int x, int y, cef_drag_operations_mask_t op) override; 86 void DragSourceSystemDragEnded() override; 87 void AccessibilityEventReceived( 88 const content::AXEventNotificationDetails& eventData) override; 89 void AccessibilityLocationChangesReceived( 90 const std::vector<content::AXLocationChangeNotificationDetails>& locData) 91 override; 92 93 // CefBrowserPlatformDelegateNative::WindowlessHandler methods: 94 CefWindowHandle GetParentWindowHandle() const override; 95 gfx::Point GetParentScreenPoint(const gfx::Point& view) const override; 96 97 protected: 98 // Platform-specific behaviors will be delegated to |native_delegate|. 99 CefBrowserPlatformDelegateOsr( 100 std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate, 101 bool use_shared_texture, 102 bool use_external_begin_frame); 103 104 // Returns the primary OSR host view for the underlying browser. If a 105 // full-screen host view currently exists then it will be returned. Otherwise, 106 // the main host view will be returned. 107 CefRenderWidgetHostViewOSR* GetOSRHostView() const; 108 109 std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate_; 110 const bool use_shared_texture_; 111 const bool use_external_begin_frame_; 112 113 CefWebContentsViewOSR* view_osr_ = nullptr; // Not owned by this class. 114 115 // Pending drag/drop data. 116 CefRefPtr<CefDragData> drag_data_; 117 cef_drag_operations_mask_t drag_allowed_ops_; 118 119 // We keep track of the RenderWidgetHost we're dragging over. If it changes 120 // during a drag, we need to re-send the DragEnter message. 121 base::WeakPtr<content::RenderWidgetHostImpl> current_rwh_for_drag_; 122 123 // We also keep track of the RenderViewHost we're dragging over to avoid 124 // sending the drag exited message after leaving the current 125 // view. |current_rvh_for_drag_| should not be dereferenced. 126 void* current_rvh_for_drag_; 127 128 // We keep track of the RenderWidgetHost from which the current drag started, 129 // in order to properly route the drag end message to it. 130 base::WeakPtr<content::RenderWidgetHostImpl> drag_start_rwh_; 131 }; 132 133 #endif // CEF_LIBCEF_BROWSER_OSR_BROWSER_PLATFORM_DELEGATE_OSR_H_ 134