2022-06-02 11:49:50 +02:00
|
|
|
// Copyright (c) 2019 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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/alloy/dialogs/alloy_web_contents_dialog_helper.h"
|
2022-06-02 11:49:50 +02:00
|
|
|
|
|
|
|
#include "base/notreached.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/browser_platform_delegate.h"
|
2022-06-02 11:49:50 +02:00
|
|
|
#include "chrome/browser/platform_util.h"
|
|
|
|
#include "components/web_modal/web_contents_modal_dialog_manager.h"
|
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
|
|
|
|
AlloyWebContentsDialogHelper::AlloyWebContentsDialogHelper(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
CefBrowserPlatformDelegate* browser_delegate)
|
|
|
|
: browser_delegate_(browser_delegate), weak_factory_(this) {
|
|
|
|
web_modal::WebContentsModalDialogManager::CreateForWebContents(web_contents);
|
|
|
|
web_modal::WebContentsModalDialogManager::FromWebContents(web_contents)
|
|
|
|
->SetDelegate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
base::RepeatingClosure
|
|
|
|
AlloyWebContentsDialogHelper::GetBoundsChangedCallback() {
|
|
|
|
return base::BindRepeating(&AlloyWebContentsDialogHelper::OnBoundsChanged,
|
|
|
|
weak_factory_.GetWeakPtr());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AlloyWebContentsDialogHelper::IsWebContentsVisible(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
if (browser_delegate_->IsWindowless()) {
|
|
|
|
return !browser_delegate_->IsHidden();
|
|
|
|
} else if (auto native_view = web_contents->GetNativeView()) {
|
|
|
|
return platform_util::IsVisible(native_view);
|
|
|
|
}
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false);
|
2022-06-02 11:49:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
web_modal::WebContentsModalDialogHost*
|
|
|
|
AlloyWebContentsDialogHelper::GetWebContentsModalDialogHost() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::NativeView AlloyWebContentsDialogHelper::GetHostView() const {
|
2023-09-15 21:51:43 +02:00
|
|
|
// Windowless rendering uses GetAcceleratedWidget() instead.
|
2024-04-17 18:01:26 +02:00
|
|
|
if (!browser_delegate_->IsWindowless()) {
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
|
|
|
// This is supported with all configurations except MacOS with external
|
|
|
|
// parent because we can't provide a gfx::NativeView or a
|
|
|
|
// gfx::AcceleratedWidget on that platform (it's an arbitrary internal
|
|
|
|
// Chromium type). This code should not be reached in that case because
|
|
|
|
// print preview is disabled.
|
|
|
|
DCHECK(!browser_delegate_->HasExternalParent());
|
|
|
|
#endif
|
|
|
|
if (auto widget = browser_delegate_->GetWindowWidget()) {
|
|
|
|
return widget->GetNativeView();
|
|
|
|
}
|
2022-06-02 11:49:50 +02:00
|
|
|
}
|
2024-04-17 18:01:26 +02:00
|
|
|
NOTIMPLEMENTED();
|
2022-06-02 11:49:50 +02:00
|
|
|
return gfx::NativeView();
|
|
|
|
}
|
|
|
|
|
2023-09-15 21:51:43 +02:00
|
|
|
gfx::AcceleratedWidget AlloyWebContentsDialogHelper::GetAcceleratedWidget()
|
|
|
|
const {
|
2022-06-02 11:49:50 +02:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
// Windowed rendering uses GetHostView() instead.
|
2024-04-17 18:01:26 +02:00
|
|
|
if (browser_delegate_->IsWindowless()) {
|
|
|
|
if (auto parent_widget = browser_delegate_->GetHostWindowHandle()) {
|
|
|
|
return parent_widget;
|
|
|
|
}
|
2022-06-02 11:49:50 +02:00
|
|
|
}
|
|
|
|
#endif // defined(USE_AURA)
|
2024-04-17 18:01:26 +02:00
|
|
|
NOTIMPLEMENTED();
|
2022-06-02 11:49:50 +02:00
|
|
|
return gfx::kNullAcceleratedWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point AlloyWebContentsDialogHelper::GetDialogPosition(
|
|
|
|
const gfx::Size& size) {
|
|
|
|
return browser_delegate_->GetDialogPosition(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size AlloyWebContentsDialogHelper::GetMaximumDialogSize() {
|
|
|
|
return browser_delegate_->GetMaximumDialogSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlloyWebContentsDialogHelper::AddObserver(
|
|
|
|
web_modal::ModalDialogHostObserver* observer) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (observer && !observer_list_.HasObserver(observer)) {
|
2022-06-02 11:49:50 +02:00
|
|
|
observer_list_.AddObserver(observer);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-06-02 11:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AlloyWebContentsDialogHelper::RemoveObserver(
|
|
|
|
web_modal::ModalDialogHostObserver* observer) {
|
|
|
|
observer_list_.RemoveObserver(observer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlloyWebContentsDialogHelper::OnBoundsChanged() {
|
2023-01-02 23:59:03 +01:00
|
|
|
for (auto& observer : observer_list_) {
|
2022-06-02 11:49:50 +02:00
|
|
|
observer.OnPositionRequiresUpdate();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-06-02 11:49:50 +02:00
|
|
|
}
|