2021-02-18 02:58:25 +01:00
|
|
|
// Copyright 2021 The Chromium Embedded Framework Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found
|
|
|
|
// in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/chrome/views/chrome_browser_view.h"
|
|
|
|
|
|
|
|
#include "libcef/browser/chrome/views/chrome_browser_frame.h"
|
|
|
|
#include "libcef/browser/views/browser_view_impl.h"
|
|
|
|
|
2023-09-07 19:28:27 +02:00
|
|
|
ChromeBrowserView::ChromeBrowserView(CefBrowserViewImpl* cef_browser_view)
|
|
|
|
: ParentClass(cef_browser_view->delegate()),
|
|
|
|
cef_browser_view_(cef_browser_view) {}
|
2021-02-18 02:58:25 +01:00
|
|
|
|
2023-09-07 19:28:27 +02:00
|
|
|
void ChromeBrowserView::InitBrowser(std::unique_ptr<Browser> browser) {
|
2021-02-18 02:58:25 +01:00
|
|
|
DCHECK(!web_view_);
|
|
|
|
|
|
|
|
// Initialize the BrowserFrame and BrowserView.
|
|
|
|
auto chrome_widget = static_cast<ChromeBrowserFrame*>(GetWidget());
|
|
|
|
chrome_widget->Init(this, std::move(browser));
|
|
|
|
|
|
|
|
// Retrieve the views::WebView that was created by the above initializations.
|
2023-09-07 19:28:27 +02:00
|
|
|
web_view_ = cef_browser_view_->web_view();
|
2021-02-18 02:58:25 +01:00
|
|
|
DCHECK(web_view_);
|
|
|
|
|
|
|
|
ParentClass::AddedToWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeBrowserView::Destroyed() {
|
|
|
|
DCHECK(!destroyed_);
|
|
|
|
destroyed_ = true;
|
|
|
|
web_view_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeBrowserView::ViewHierarchyChanged(
|
|
|
|
const views::ViewHierarchyChangedDetails& details) {
|
|
|
|
ParentClass::ViewHierarchyChanged(details);
|
|
|
|
if (details.is_add && details.child == this) {
|
|
|
|
gfx::Size size = GetPreferredSize();
|
|
|
|
if (size.IsEmpty()) {
|
|
|
|
// No size was provided for this View. Size it to the parent by default
|
|
|
|
// or, depending on the Layout, the browser may be initially 0x0 size and
|
|
|
|
// will not display until the parent is next resized (resulting in a call
|
|
|
|
// to WebView::OnBoundsChanged). For example, this can happen when adding
|
|
|
|
// this View to a CefWindow with FillLayout and then calling
|
|
|
|
// CefWindow::Show() without first resizing the CefWindow.
|
|
|
|
size = details.parent->GetPreferredSize();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!size.IsEmpty()) {
|
2021-02-18 02:58:25 +01:00
|
|
|
SetSize(size);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-02-18 02:58:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeBrowserView::AddedToWidget() {
|
2024-03-29 17:48:33 +01:00
|
|
|
// Create the Browser and ChromeBrowserHostImpl.
|
2021-02-18 02:58:25 +01:00
|
|
|
// Results in a call to InitBrowser which calls ParentClass::AddedToWidget.
|
2023-09-07 19:28:27 +02:00
|
|
|
cef_browser_view_->OnBrowserViewAdded();
|
2024-03-29 17:48:33 +01:00
|
|
|
|
|
|
|
// Call after ChromeBrowserHostImpl creation.
|
|
|
|
cef_browser_view_->AddedToWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeBrowserView::RemovedFromWidget() {
|
|
|
|
ParentClass::RemovedFromWidget();
|
|
|
|
cef_browser_view_->RemovedFromWidget();
|
2021-02-18 02:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeBrowserView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
|
|
|
|
ParentClass::OnBoundsChanged(previous_bounds);
|
2023-09-07 19:28:27 +02:00
|
|
|
cef_browser_view_->OnBoundsChanged();
|
2021-02-18 02:58:25 +01:00
|
|
|
}
|
2021-04-11 22:10:11 +02:00
|
|
|
|
2023-08-31 19:16:46 +02:00
|
|
|
void ChromeBrowserView::OnGestureEvent(ui::GestureEvent* event) {
|
2023-09-07 19:28:27 +02:00
|
|
|
if (cef_browser_view_->OnGestureEvent(event)) {
|
2023-08-31 19:16:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ParentClass::OnGestureEvent(event);
|
|
|
|
}
|
|
|
|
|
2023-09-07 19:28:27 +02:00
|
|
|
ToolbarView* ChromeBrowserView::OverrideCreateToolbar() {
|
2021-04-11 22:10:11 +02:00
|
|
|
if (cef_delegate()) {
|
2023-09-07 19:28:27 +02:00
|
|
|
auto toolbar_type = cef_delegate()->GetChromeToolbarType(cef_browser_view_);
|
2024-03-19 22:11:42 +01:00
|
|
|
std::optional<ToolbarView::DisplayMode> display_mode;
|
2021-04-11 22:10:11 +02:00
|
|
|
switch (toolbar_type) {
|
|
|
|
case CEF_CTT_NORMAL:
|
|
|
|
display_mode = ToolbarView::DisplayMode::NORMAL;
|
|
|
|
break;
|
|
|
|
case CEF_CTT_LOCATION:
|
|
|
|
display_mode = ToolbarView::DisplayMode::LOCATION;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (display_mode) {
|
2023-09-07 19:28:27 +02:00
|
|
|
cef_toolbar_ =
|
|
|
|
CefToolbarViewImpl::Create(nullptr, browser(), this, display_mode);
|
2021-04-11 22:10:11 +02:00
|
|
|
// Ownership will be taken by BrowserView.
|
|
|
|
view_util::PassOwnership(cef_toolbar_).release();
|
|
|
|
return cef_toolbar_->root_view();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|