| Index: ash/common/system/tray/three_view_layout.cc
|
| diff --git a/ash/common/system/tray/three_view_layout.cc b/ash/common/system/tray/three_view_layout.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..db1ef699449b71cd57d66bf2abe4d828208ea249
|
| --- /dev/null
|
| +++ b/ash/common/system/tray/three_view_layout.cc
|
| @@ -0,0 +1,184 @@
|
| +// Copyright 2016 The Chromium 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 "ash/common/system/tray/three_view_layout.h"
|
| +
|
| +#include "ash/common/system/tray/size_range_layout.h"
|
| +#include "base/logging.h"
|
| +#include "ui/views/border.h"
|
| +#include "ui/views/layout/box_layout.h"
|
| +#include "ui/views/layout/fill_layout.h"
|
| +
|
| +namespace ash {
|
| +namespace {
|
| +
|
| +// Converts ThreeViewLayout::Orientation values to
|
| +// views::BoxLayout::Orientation values.
|
| +views::BoxLayout::Orientation GetOrientation(
|
| + ThreeViewLayout::Orientation orientation) {
|
| + switch (orientation) {
|
| + case ThreeViewLayout::HORIZONTAL:
|
| + return views::BoxLayout::kHorizontal;
|
| + case ThreeViewLayout::VERTICAL:
|
| + return views::BoxLayout::kVertical;
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +ThreeViewLayout::ThreeViewLayout(int padding_between_items)
|
| + : ThreeViewLayout(HORIZONTAL, padding_between_items) {}
|
| +
|
| +ThreeViewLayout::ThreeViewLayout(Orientation orientation,
|
| + int padding_between_items)
|
| + : box_layout_(new views::BoxLayout(GetOrientation(orientation),
|
| + 0,
|
| + 0,
|
| + padding_between_items)),
|
| + start_container_(new views::View),
|
| + start_container_layout_manager_(new SizeRangeLayout),
|
| + center_container_(new views::View),
|
| + center_container_layout_manager_(new SizeRangeLayout),
|
| + end_container_(new views::View),
|
| + end_container_layout_manager_(new SizeRangeLayout) {
|
| + start_container_->SetLayoutManager(GetLayoutManager(START));
|
| + center_container_->SetLayoutManager(GetLayoutManager(CENTER));
|
| + end_container_->SetLayoutManager(GetLayoutManager(END));
|
| + GetLayoutManager(START)->SetLayoutManager(
|
| + CreateDefaultLayoutManager(orientation));
|
| + GetLayoutManager(CENTER)->SetLayoutManager(
|
| + CreateDefaultLayoutManager(orientation));
|
| + GetLayoutManager(END)->SetLayoutManager(
|
| + CreateDefaultLayoutManager(orientation));
|
| +}
|
| +
|
| +ThreeViewLayout::~ThreeViewLayout() {}
|
| +
|
| +void ThreeViewLayout::SetMinCrossAxisSize(int min_size) {
|
| + box_layout_->set_minimum_cross_axis_size(min_size);
|
| +}
|
| +
|
| +void ThreeViewLayout::SetMinSize(Container container, const gfx::Size& size) {
|
| + GetLayoutManager(container)->set_min_size(size);
|
| +}
|
| +
|
| +void ThreeViewLayout::SetMaxSize(Container container, const gfx::Size& size) {
|
| + GetLayoutManager(container)->set_max_size(size);
|
| +}
|
| +
|
| +void ThreeViewLayout::AddView(Container container, views::View* view) {
|
| + views::View* container_view = GetContainer(container);
|
| + container_view->AddChildView(view);
|
| +}
|
| +
|
| +void ThreeViewLayout::SetView(Container container, views::View* view) {
|
| + views::View* container_view = GetContainer(container);
|
| + container_view->RemoveAllChildViews(true);
|
| + container_view->AddChildView(view);
|
| +}
|
| +
|
| +void ThreeViewLayout::SetInsets(const gfx::Insets& insets) {
|
| + box_layout_->set_inside_border_insets(insets);
|
| +}
|
| +
|
| +void ThreeViewLayout::SetInsets(Container container,
|
| + const gfx::Insets& insets) {
|
| + GetContainer(container)->SetBorder(views::Border::CreateEmptyBorder(insets));
|
| +}
|
| +
|
| +void ThreeViewLayout::SetContainerVisible(Container container, bool visible) {
|
| + GetContainer(container)->SetVisible(visible);
|
| +}
|
| +
|
| +void ThreeViewLayout::SetFlexForView(Container container, int flex) {
|
| + box_layout_->SetFlexForView(GetContainer(container), flex);
|
| +}
|
| +
|
| +void ThreeViewLayout::SetLayoutManager(
|
| + Container container,
|
| + std::unique_ptr<LayoutManager> layout_manager) {
|
| + if (GetLayoutManager(container))
|
| + GetLayoutManager(container)->Uninstalled(GetContainer(container));
|
| + GetLayoutManager(container)->SetLayoutManager(std::move(layout_manager));
|
| + if (GetLayoutManager(container))
|
| + GetLayoutManager(container)->Installed(GetContainer(container));
|
| +}
|
| +
|
| +void ThreeViewLayout::Installed(views::View* host) {
|
| + DCHECK(!host_);
|
| + host_ = host;
|
| + if (host_) {
|
| + host_->AddChildView(GetContainer(START));
|
| + host_->AddChildView(GetContainer(CENTER));
|
| + host_->AddChildView(GetContainer(END));
|
| + }
|
| + box_layout_->Installed(host_);
|
| +}
|
| +
|
| +void ThreeViewLayout::Uninstalled(views::View* host) {
|
| + DCHECK_EQ(host_, host);
|
| + if (host_) {
|
| + host_->RemoveChildView(GetContainer(START));
|
| + host_->RemoveChildView(GetContainer(CENTER));
|
| + host_->RemoveChildView(GetContainer(END));
|
| + }
|
| + box_layout_->Uninstalled(host);
|
| + host_ = nullptr;
|
| +}
|
| +
|
| +void ThreeViewLayout::Layout(views::View* host) {
|
| + box_layout_->Layout(host);
|
| +}
|
| +
|
| +gfx::Size ThreeViewLayout::GetPreferredSize(const views::View* host) const {
|
| + return box_layout_->GetPreferredSize(host);
|
| +}
|
| +
|
| +int ThreeViewLayout::GetPreferredHeightForWidth(const views::View* host,
|
| + int width) const {
|
| + return box_layout_->GetPreferredHeightForWidth(host, width);
|
| +}
|
| +
|
| +void ThreeViewLayout::ViewAdded(views::View* host, views::View* view) {
|
| + box_layout_->ViewAdded(host, view);
|
| +}
|
| +
|
| +void ThreeViewLayout::ViewRemoved(views::View* host, views::View* view) {
|
| + box_layout_->ViewRemoved(host, view);
|
| +}
|
| +
|
| +std::unique_ptr<views::LayoutManager>
|
| +ThreeViewLayout::CreateDefaultLayoutManager(Orientation orientation) const {
|
| + views::BoxLayout* box_layout =
|
| + new views::BoxLayout(GetOrientation(orientation), 0, 0, 0);
|
| + box_layout->set_main_axis_alignment(
|
| + views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
|
| + box_layout->set_cross_axis_alignment(
|
| + views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
|
| + return std::unique_ptr<views::LayoutManager>(box_layout);
|
| +}
|
| +
|
| +views::View* ThreeViewLayout::GetContainer(Container container) const {
|
| + switch (container) {
|
| + case START:
|
| + return start_container_;
|
| + case CENTER:
|
| + return center_container_;
|
| + case END:
|
| + return end_container_;
|
| + }
|
| +}
|
| +
|
| +SizeRangeLayout* ThreeViewLayout::GetLayoutManager(Container container) const {
|
| + switch (container) {
|
| + case START:
|
| + return start_container_layout_manager_;
|
| + case CENTER:
|
| + return center_container_layout_manager_;
|
| + case END:
|
| + return end_container_layout_manager_;
|
| + }
|
| +}
|
| +
|
| +} // namespace ash
|
|
|