1 // Copyright 2021 The Chromium Embedded Framework Authors. Portions copyright 2 // 2011 The Chromium Authors. All rights reserved. Use of this source code is 3 // governed by a BSD-style license that can be found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_BROWSER_VIEWS_OVERLAY_VIEW_HOST_H_ 6 #define CEF_LIBCEF_BROWSER_VIEWS_OVERLAY_VIEW_HOST_H_ 7 #pragma once 8 9 #include <memory> 10 11 #include "include/views/cef_overlay_controller.h" 12 #include "include/views/cef_view.h" 13 14 #include "base/compiler_specific.h" 15 #include "ui/views/view_observer.h" 16 #include "ui/views/widget/widget_delegate.h" 17 18 class CefWindowView; 19 20 // Host class for a child Widget that behaves as an overlay control. Based on 21 // Chrome's DropdownBarHost. 22 class CefOverlayViewHost : public views::WidgetDelegate, 23 public views::ViewObserver { 24 public: 25 // |window_view| is the top-level view that contains this overlay. 26 CefOverlayViewHost(CefWindowView* window_view, 27 cef_docking_mode_t docking_mode); 28 29 CefOverlayViewHost(const CefOverlayViewHost&) = delete; 30 CefOverlayViewHost& operator=(const CefOverlayViewHost&) = delete; 31 32 // Initializes the CefOverlayViewHost. This creates the Widget that |view| 33 // paints into. |host_view| is the view whose position in the |window_view_| 34 // view hierarchy determines the z-order of the widget relative to views with 35 // layers and views with associated NativeViews. 36 void Init(views::View* host_view, CefRefPtr<CefView> view); 37 38 void Destroy(); 39 40 void MoveIfNecessary(); 41 42 void SetOverlayBounds(const gfx::Rect& bounds); 43 void SetOverlayInsets(const CefInsets& insets); 44 45 // views::ViewObserver methods: 46 void OnViewBoundsChanged(views::View* observed_view) override; 47 docking_mode()48 cef_docking_mode_t docking_mode() const { return docking_mode_; } controller()49 CefRefPtr<CefOverlayController> controller() const { return cef_controller_; } window_view()50 CefWindowView* window_view() const { return window_view_; } widget()51 views::Widget* widget() const { return widget_.get(); } view()52 views::View* view() const { return view_; } bounds()53 gfx::Rect bounds() const { return bounds_; } insets()54 CefInsets insets() const { return insets_; } 55 56 private: 57 gfx::Rect ComputeBounds() const; 58 59 // The CefWindowView that created us. 60 CefWindowView* const window_view_; 61 62 const cef_docking_mode_t docking_mode_; 63 64 // Our view, which is responsible for drawing the UI. 65 views::View* view_ = nullptr; 66 67 // The Widget implementation that is created and maintained by the overlay. 68 // It contains |view_|. 69 std::unique_ptr<views::Widget> widget_; 70 71 CefRefPtr<CefOverlayController> cef_controller_; 72 73 gfx::Rect bounds_; 74 bool bounds_changing_ = false; 75 76 CefInsets insets_; 77 }; 78 79 #endif // CEF_LIBCEF_BROWSER_VIEWS_OVERLAY_VIEW_HOST_H_ 80