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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/views/box_layout_impl.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/thread_util.h"
|
|
|
|
#include "cef/libcef/browser/views/view_util.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefBoxLayoutImpl> CefBoxLayoutImpl::Create(
|
|
|
|
const CefBoxLayoutSettings& settings,
|
|
|
|
views::View* owner_view) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(nullptr);
|
|
|
|
CefRefPtr<CefBoxLayoutImpl> impl = new CefBoxLayoutImpl(settings);
|
|
|
|
impl->Initialize(owner_view);
|
|
|
|
return impl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBoxLayoutImpl::SetFlexForView(CefRefPtr<CefView> view, int flex) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
DCHECK_GE(flex, 0);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (flex < 0) {
|
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
|
|
|
|
|
|
|
DCHECK(view && view->IsValid() && view->IsAttached());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view || !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_EQ(view_ptr->parent(), owner_view());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (view_ptr->parent() != owner_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
|
|
|
|
|
|
|
layout()->SetFlexForView(view_ptr, flex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBoxLayoutImpl::ClearFlexForView(CefRefPtr<CefView> view) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
DCHECK(view && view->IsValid() && view->IsAttached());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view || !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_EQ(view_ptr->parent(), owner_view());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (view_ptr->parent() != owner_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
|
|
|
|
|
|
|
layout()->ClearFlexForView(view_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefBoxLayoutImpl::CefBoxLayoutImpl(const CefBoxLayoutSettings& settings)
|
2017-05-17 11:29:28 +02:00
|
|
|
: settings_(settings) {}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
views::BoxLayout* CefBoxLayoutImpl::CreateLayout() {
|
2017-07-27 01:19:27 +02:00
|
|
|
views::BoxLayout* layout = new views::BoxLayout(
|
2019-09-04 17:13:32 +02:00
|
|
|
settings_.horizontal ? views::BoxLayout::Orientation::kHorizontal
|
|
|
|
: views::BoxLayout::Orientation::kVertical,
|
2022-04-21 20:58:48 +02:00
|
|
|
gfx::Insets::VH(settings_.inside_border_vertical_spacing,
|
|
|
|
settings_.inside_border_horizontal_spacing),
|
2017-07-27 01:19:27 +02:00
|
|
|
settings_.between_child_spacing);
|
2016-01-19 21:09:01 +01:00
|
|
|
layout->set_main_axis_alignment(
|
|
|
|
static_cast<views::BoxLayout::MainAxisAlignment>(
|
|
|
|
settings_.main_axis_alignment));
|
|
|
|
layout->set_cross_axis_alignment(
|
|
|
|
static_cast<views::BoxLayout::CrossAxisAlignment>(
|
|
|
|
settings_.cross_axis_alignment));
|
2022-04-21 20:58:48 +02:00
|
|
|
layout->set_inside_border_insets(gfx::Insets::TLBR(
|
2017-05-17 11:29:28 +02:00
|
|
|
settings_.inside_border_insets.top, settings_.inside_border_insets.left,
|
2016-01-19 21:09:01 +01:00
|
|
|
settings_.inside_border_insets.bottom,
|
|
|
|
settings_.inside_border_insets.right));
|
|
|
|
layout->set_minimum_cross_axis_size(settings_.minimum_cross_axis_size);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (settings_.default_flex > 0) {
|
2016-01-19 21:09:01 +01:00
|
|
|
layout->SetDefaultFlex(settings_.default_flex);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return layout;
|
|
|
|
}
|