2016-01-19 21:09:01 +01:00
|
|
|
// Copyright 2016 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.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_VIEWS_PANEL_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_VIEWS_PANEL_IMPL_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/views/cef_fill_layout.h"
|
|
|
|
#include "cef/include/views/cef_layout.h"
|
|
|
|
#include "cef/include/views/cef_panel.h"
|
|
|
|
#include "cef/include/views/cef_window.h"
|
|
|
|
#include "cef/libcef/browser/views/box_layout_impl.h"
|
|
|
|
#include "cef/libcef/browser/views/fill_layout_impl.h"
|
|
|
|
#include "cef/libcef/browser/views/layout_util.h"
|
|
|
|
#include "cef/libcef/browser/views/view_impl.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Helpers for template boiler-plate.
|
|
|
|
#define CEF_PANEL_IMPL_T CEF_VIEW_IMPL_T
|
|
|
|
#define CEF_PANEL_IMPL_A CEF_VIEW_IMPL_A
|
|
|
|
#define CEF_PANEL_IMPL_D CefPanelImpl<CEF_PANEL_IMPL_A>
|
|
|
|
|
|
|
|
// Template for implementing CefPanel-derived classes. See comments in
|
|
|
|
// view_impl.h for a usage overview.
|
|
|
|
CEF_PANEL_IMPL_T class CefPanelImpl : public CEF_VIEW_IMPL_D {
|
|
|
|
public:
|
2021-12-06 21:40:25 +01:00
|
|
|
using ParentClass = CEF_VIEW_IMPL_D;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefPanel methods. When adding new As*() methods make sure to update
|
|
|
|
// CefViewAdapter::GetFor() in view_adapter.cc.
|
|
|
|
CefRefPtr<CefWindow> AsWindow() override { return nullptr; }
|
|
|
|
CefRefPtr<CefFillLayout> SetToFillLayout() override;
|
|
|
|
CefRefPtr<CefBoxLayout> SetToBoxLayout(
|
|
|
|
const CefBoxLayoutSettings& settings) override;
|
|
|
|
CefRefPtr<CefLayout> GetLayout() override;
|
|
|
|
void Layout() override;
|
|
|
|
void AddChildView(CefRefPtr<CefView> view) override;
|
2017-05-17 11:29:28 +02:00
|
|
|
void AddChildViewAt(CefRefPtr<CefView> view, int index) override;
|
|
|
|
void ReorderChildView(CefRefPtr<CefView> view, int index) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
void RemoveChildView(CefRefPtr<CefView> view) override;
|
|
|
|
void RemoveAllChildViews() override;
|
|
|
|
size_t GetChildViewCount() override;
|
|
|
|
CefRefPtr<CefView> GetChildViewAt(int index) override;
|
|
|
|
|
|
|
|
// CefView methods:
|
|
|
|
CefRefPtr<CefPanel> AsPanel() override { return this; }
|
|
|
|
|
|
|
|
// CefViewAdapter methods:
|
2023-01-30 22:42:40 +01:00
|
|
|
void GetDebugInfo(base::Value::Dict* info, bool include_children) override {
|
2016-01-19 21:09:01 +01:00
|
|
|
ParentClass::GetDebugInfo(info, include_children);
|
|
|
|
if (include_children) {
|
2019-07-16 19:59:21 +02:00
|
|
|
const size_t count = ParentClass::content_view()->children().size();
|
2016-01-19 21:09:01 +01:00
|
|
|
if (count > 0U) {
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value::List children;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
for (size_t i = 0U; i < count; ++i) {
|
2019-07-16 19:59:21 +02:00
|
|
|
views::View* view = ParentClass::content_view()->children()[i];
|
2016-01-19 21:09:01 +01:00
|
|
|
CefViewAdapter* adapter = CefViewAdapter::GetFor(view);
|
|
|
|
if (adapter) {
|
2023-01-30 22:42:40 +01:00
|
|
|
base::Value::Dict child_info;
|
2022-06-17 15:28:55 +02:00
|
|
|
adapter->GetDebugInfo(&child_info, include_children);
|
2023-01-30 22:42:40 +01:00
|
|
|
children.Append(std::move(child_info));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info->Set("children", std::move(children));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Create a new implementation object.
|
|
|
|
// Always call Initialize() after creation.
|
|
|
|
// |delegate| may be nullptr.
|
|
|
|
explicit CefPanelImpl(CefRefPtr<CefViewDelegateClass> delegate)
|
2017-05-17 11:29:28 +02:00
|
|
|
: ParentClass(delegate) {}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
void Initialize() override {
|
|
|
|
ParentClass::Initialize();
|
|
|
|
|
|
|
|
// Create the default layout object.
|
|
|
|
SetToFillLayout();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CEF_PANEL_IMPL_T CefRefPtr<CefFillLayout> CEF_PANEL_IMPL_D::SetToFillLayout() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(nullptr);
|
|
|
|
return CefFillLayoutImpl::Create(ParentClass::content_view());
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_PANEL_IMPL_T CefRefPtr<CefBoxLayout> CEF_PANEL_IMPL_D::SetToBoxLayout(
|
|
|
|
const CefBoxLayoutSettings& settings) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(nullptr);
|
|
|
|
return CefBoxLayoutImpl::Create(settings, ParentClass::content_view());
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_PANEL_IMPL_T CefRefPtr<CefLayout> CEF_PANEL_IMPL_D::GetLayout() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(nullptr);
|
|
|
|
return layout_util::GetFor(ParentClass::content_view());
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_PANEL_IMPL_T void CEF_PANEL_IMPL_D::Layout() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2024-02-22 19:36:15 +01:00
|
|
|
ParentClass::root_view()->DeprecatedLayoutImmediately();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_PANEL_IMPL_T void CEF_PANEL_IMPL_D::AddChildView(CefRefPtr<CefView> view) {
|
2016-01-19 21:09:01 +01:00
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
DCHECK(view.get());
|
|
|
|
DCHECK(view->IsValid());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view.get() || !view->IsValid()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-04-11 22:10:11 +02:00
|
|
|
auto* view_ptr = view->IsAttached()
|
|
|
|
? view_util::GetFor(view)
|
|
|
|
: view_util::PassOwnership(view).release();
|
|
|
|
DCHECK(view_ptr);
|
|
|
|
ParentClass::content_view()->AddChildView(view_ptr);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_PANEL_IMPL_T void CEF_PANEL_IMPL_D::AddChildViewAt(CefRefPtr<CefView> view,
|
|
|
|
int index) {
|
2016-01-19 21:09:01 +01:00
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
DCHECK(view.get());
|
|
|
|
DCHECK(view->IsValid());
|
|
|
|
DCHECK_GE(index, 0);
|
2019-07-16 19:59:21 +02:00
|
|
|
DCHECK_LE(static_cast<unsigned int>(index),
|
|
|
|
ParentClass::content_view()->children().size());
|
2021-04-11 22:10:11 +02:00
|
|
|
if (!view.get() || !view->IsValid() || index < 0 ||
|
2019-07-16 19:59:21 +02:00
|
|
|
(static_cast<unsigned int>(index) >
|
|
|
|
ParentClass::content_view()->children().size())) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-11 22:10:11 +02:00
|
|
|
auto* view_ptr = view->IsAttached()
|
|
|
|
? view_util::GetFor(view)
|
|
|
|
: view_util::PassOwnership(view).release();
|
|
|
|
DCHECK(view_ptr);
|
|
|
|
ParentClass::content_view()->AddChildViewAt(view_ptr, index);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CEF_PANEL_IMPL_T void CEF_PANEL_IMPL_D::ReorderChildView(
|
|
|
|
CefRefPtr<CefView> view,
|
|
|
|
int index) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
DCHECK(view.get());
|
|
|
|
DCHECK(view->IsValid());
|
|
|
|
DCHECK(view->IsAttached());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view.get() || !view->IsValid() || !view->IsAttached()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
views::View* view_ptr = view_util::GetFor(view);
|
|
|
|
DCHECK(view_ptr);
|
|
|
|
DCHECK_EQ(view_ptr->parent(), ParentClass::content_view());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view_ptr || view_ptr->parent() != ParentClass::content_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
ParentClass::content_view()->ReorderChildView(view_ptr, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_PANEL_IMPL_T void CEF_PANEL_IMPL_D::RemoveChildView(
|
|
|
|
CefRefPtr<CefView> view) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
DCHECK(view.get());
|
|
|
|
DCHECK(view->IsValid());
|
|
|
|
DCHECK(view->IsAttached());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view.get() || !view->IsValid() || !view->IsAttached()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
views::View* view_ptr = view_util::GetFor(view);
|
|
|
|
DCHECK(view_ptr);
|
|
|
|
DCHECK_EQ(view_ptr->parent(), ParentClass::content_view());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view_ptr || view_ptr->parent() != ParentClass::content_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
ParentClass::content_view()->RemoveChildView(view_ptr);
|
|
|
|
view_util::ResumeOwnership(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_PANEL_IMPL_T void CEF_PANEL_IMPL_D::RemoveAllChildViews() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2019-04-16 16:38:48 +02:00
|
|
|
while (!ParentClass::content_view()->children().empty()) {
|
2019-07-16 19:59:21 +02:00
|
|
|
CefRefPtr<CefView> view = view_util::GetFor(
|
|
|
|
ParentClass::content_view()->children().front(), false);
|
2016-01-19 21:09:01 +01:00
|
|
|
RemoveChildView(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CEF_PANEL_IMPL_T size_t CEF_PANEL_IMPL_D::GetChildViewCount() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(0U);
|
2019-07-16 19:59:21 +02:00
|
|
|
return ParentClass::content_view()->children().size();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CEF_PANEL_IMPL_T CefRefPtr<CefView> CEF_PANEL_IMPL_D::GetChildViewAt(
|
|
|
|
int index) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(nullptr);
|
|
|
|
DCHECK_GE(index, 0);
|
2019-07-16 19:59:21 +02:00
|
|
|
DCHECK_LT(static_cast<unsigned int>(index),
|
|
|
|
ParentClass::content_view()->children().size());
|
|
|
|
if (index < 0 || (static_cast<unsigned int>(index) >=
|
2023-01-02 23:59:03 +01:00
|
|
|
ParentClass::content_view()->children().size())) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefView> view =
|
2019-07-16 19:59:21 +02:00
|
|
|
view_util::GetFor(ParentClass::content_view()->children()[index], false);
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(view);
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_VIEWS_PANEL_IMPL_H_
|