• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "libcef/browser/views/box_layout_impl.h"
6 
7 #include "libcef/browser/thread_util.h"
8 #include "libcef/browser/views/view_util.h"
9 
10 // static
Create(const CefBoxLayoutSettings & settings,views::View * owner_view)11 CefRefPtr<CefBoxLayoutImpl> CefBoxLayoutImpl::Create(
12     const CefBoxLayoutSettings& settings,
13     views::View* owner_view) {
14   CEF_REQUIRE_UIT_RETURN(nullptr);
15   CefRefPtr<CefBoxLayoutImpl> impl = new CefBoxLayoutImpl(settings);
16   impl->Initialize(owner_view);
17   return impl;
18 }
19 
SetFlexForView(CefRefPtr<CefView> view,int flex)20 void CefBoxLayoutImpl::SetFlexForView(CefRefPtr<CefView> view, int flex) {
21   CEF_REQUIRE_VALID_RETURN_VOID();
22   DCHECK_GE(flex, 0);
23   if (flex < 0)
24     return;
25 
26   DCHECK(view && view->IsValid() && view->IsAttached());
27   if (!view || !view->IsValid() || !view->IsAttached())
28     return;
29 
30   views::View* view_ptr = view_util::GetFor(view);
31   DCHECK_EQ(view_ptr->parent(), owner_view());
32   if (view_ptr->parent() != owner_view())
33     return;
34 
35   layout()->SetFlexForView(view_ptr, flex);
36 }
37 
ClearFlexForView(CefRefPtr<CefView> view)38 void CefBoxLayoutImpl::ClearFlexForView(CefRefPtr<CefView> view) {
39   CEF_REQUIRE_VALID_RETURN_VOID();
40   DCHECK(view && view->IsValid() && view->IsAttached());
41   if (!view || !view->IsValid() || !view->IsAttached())
42     return;
43 
44   views::View* view_ptr = view_util::GetFor(view);
45   DCHECK_EQ(view_ptr->parent(), owner_view());
46   if (view_ptr->parent() != owner_view())
47     return;
48 
49   layout()->ClearFlexForView(view_ptr);
50 }
51 
CefBoxLayoutImpl(const CefBoxLayoutSettings & settings)52 CefBoxLayoutImpl::CefBoxLayoutImpl(const CefBoxLayoutSettings& settings)
53     : settings_(settings) {}
54 
CreateLayout()55 views::BoxLayout* CefBoxLayoutImpl::CreateLayout() {
56   views::BoxLayout* layout = new views::BoxLayout(
57       settings_.horizontal ? views::BoxLayout::Orientation::kHorizontal
58                            : views::BoxLayout::Orientation::kVertical,
59       gfx::Insets(settings_.inside_border_vertical_spacing,
60                   settings_.inside_border_horizontal_spacing),
61       settings_.between_child_spacing);
62   layout->set_main_axis_alignment(
63       static_cast<views::BoxLayout::MainAxisAlignment>(
64           settings_.main_axis_alignment));
65   layout->set_cross_axis_alignment(
66       static_cast<views::BoxLayout::CrossAxisAlignment>(
67           settings_.cross_axis_alignment));
68   layout->set_inside_border_insets(gfx::Insets(
69       settings_.inside_border_insets.top, settings_.inside_border_insets.left,
70       settings_.inside_border_insets.bottom,
71       settings_.inside_border_insets.right));
72   layout->set_minimum_cross_axis_size(settings_.minimum_cross_axis_size);
73   if (settings_.default_flex > 0)
74     layout->SetDefaultFlex(settings_.default_flex);
75   return layout;
76 }
77