1 // Copyright 2016 The Chromium Embedded Framework Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be found 3 // in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_BROWSER_VIEWS_WINDOW_VIEW_H_ 6 #define CEF_LIBCEF_BROWSER_VIEWS_WINDOW_VIEW_H_ 7 #pragma once 8 9 #include <vector> 10 11 #include "include/views/cef_window.h" 12 #include "include/views/cef_window_delegate.h" 13 14 #include "libcef/browser/views/overlay_view_host.h" 15 #include "libcef/browser/views/panel_view.h" 16 17 #include "third_party/skia/include/core/SkRegion.h" 18 #include "ui/display/display.h" 19 #include "ui/views/widget/widget_delegate.h" 20 #include "ui/views/widget/widget_observer.h" 21 22 // Manages the views-based root window. This object will be deleted 23 // automatically when the associated root window is destroyed. 24 class CefWindowView 25 : public CefPanelView<views::WidgetDelegateView, CefWindowDelegate>, 26 public views::WidgetObserver { 27 public: 28 using ParentClass = 29 CefPanelView<views::WidgetDelegateView, CefWindowDelegate>; 30 31 class Delegate { 32 public: 33 // Returns true to signal that the Widget can be closed. 34 virtual bool CanWidgetClose() = 0; 35 36 // Called when the underlying platform window is closing. 37 virtual void OnWindowClosing() = 0; 38 39 // Called when the WindowView is about to be deleted. 40 virtual void OnWindowViewDeleted() = 0; 41 42 protected: ~Delegate()43 virtual ~Delegate() {} 44 }; 45 46 // |cef_delegate| may be nullptr. 47 // |window_delegate| must be non-nullptr. 48 CefWindowView(CefWindowDelegate* cef_delegate, Delegate* window_delegate); 49 50 CefWindowView(const CefWindowView&) = delete; 51 CefWindowView& operator=(const CefWindowView&) = delete; 52 53 // Create the Widget. 54 void CreateWidget(); 55 56 // Returns the CefWindow associated with this view. See comments on 57 // CefViewView::GetCefView. 58 CefRefPtr<CefWindow> GetCefWindow() const; 59 60 // views::WidgetDelegate methods: 61 bool CanMinimize() const override; 62 bool CanMaximize() const override; 63 std::u16string GetWindowTitle() const override; 64 ui::ImageModel GetWindowIcon() override; 65 ui::ImageModel GetWindowAppIcon() override; 66 void WindowClosing() override; 67 views::View* GetContentsView() override; 68 views::ClientView* CreateClientView(views::Widget* widget) override; 69 std::unique_ptr<views::NonClientFrameView> CreateNonClientFrameView( 70 views::Widget* widget) override; 71 bool ShouldDescendIntoChildForEventHandling( 72 gfx::NativeView child, 73 const gfx::Point& location) override; 74 bool MaybeGetMinimumSize(gfx::Size* size) const override; 75 bool MaybeGetMaximumSize(gfx::Size* size) const override; 76 77 // views::View methods: 78 void ViewHierarchyChanged( 79 const views::ViewHierarchyChangedDetails& details) override; 80 81 // views::WidgetObserver methods: 82 void OnWidgetBoundsChanged(views::Widget* widget, 83 const gfx::Rect& new_bounds) override; 84 85 // Returns the Display containing this Window. 86 display::Display GetDisplay() const; 87 88 // Set/get the window title. 89 void SetTitle(const std::u16string& title); title()90 std::u16string title() const { return title_; } 91 92 // Set/get the window icon. This should be a 16x16 icon suitable for use in 93 // the Windows's title bar. 94 void SetWindowIcon(CefRefPtr<CefImage> window_icon); window_icon()95 CefRefPtr<CefImage> window_icon() const { return window_icon_; } 96 97 // Set/get the window app icon. This should be a larger icon for use in the 98 // host environment app switching UI. On Windows, this is the ICON_BIG used in 99 // Alt-Tab list and Windows taskbar. The Window icon will be used by default 100 // if no Window App icon is specified. 101 void SetWindowAppIcon(CefRefPtr<CefImage> window_app_icon); window_app_icon()102 CefRefPtr<CefImage> window_app_icon() const { return window_app_icon_; } 103 104 CefRefPtr<CefOverlayController> AddOverlayView( 105 CefRefPtr<CefView> view, 106 cef_docking_mode_t docking_mode); 107 108 // Set/get the draggable regions. 109 void SetDraggableRegions(const std::vector<CefDraggableRegion>& regions); draggable_region()110 SkRegion* draggable_region() const { return draggable_region_.get(); } 111 112 // Returns the NonClientFrameView for this Window. May be nullptr. 113 views::NonClientFrameView* GetNonClientFrameView() const; 114 115 private: 116 // Called when removed from the Widget and before |this| is deleted. 117 void DeleteDelegate(); 118 119 void MoveOverlaysIfNecessary(); 120 121 // Not owned by this object. 122 Delegate* window_delegate_; 123 124 // True if the window is frameless. It might still be resizable and draggable. 125 bool is_frameless_; 126 127 std::u16string title_; 128 CefRefPtr<CefImage> window_icon_; 129 CefRefPtr<CefImage> window_app_icon_; 130 131 std::unique_ptr<SkRegion> draggable_region_; 132 133 // Hosts for overlay widgets. 134 std::vector<std::unique_ptr<CefOverlayViewHost>> overlay_hosts_; 135 }; 136 137 #endif // CEF_LIBCEF_BROWSER_VIEWS_WINDOW_VIEW_H_ 138