| Index: ash/common/system/tray/tri_view.cc
|
| diff --git a/ash/common/system/tray/tri_view.cc b/ash/common/system/tray/tri_view.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..075695d5caecba231f15dc4a017b999364211063
|
| --- /dev/null
|
| +++ b/ash/common/system/tray/tri_view.cc
|
| @@ -0,0 +1,165 @@
|
| +// 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/tri_view.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"
|
| +#include "ui/views/layout/layout_manager.h"
|
| +
|
| +namespace ash {
|
| +namespace {
|
| +
|
| +// Converts TriView::Orientation values to views::BoxLayout::Orientation values.
|
| +views::BoxLayout::Orientation GetOrientation(TriView::Orientation orientation) {
|
| + switch (orientation) {
|
| + case TriView::Orientation::HORIZONTAL:
|
| + return views::BoxLayout::kHorizontal;
|
| + case TriView::Orientation::VERTICAL:
|
| + return views::BoxLayout::kVertical;
|
| + }
|
| + // Required for some compilers.
|
| + NOTREACHED();
|
| + return views::BoxLayout::kHorizontal;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +TriView::TriView() : TriView(0) {}
|
| +
|
| +TriView::TriView(int padding_between_containers)
|
| + : TriView(Orientation::HORIZONTAL, padding_between_containers) {}
|
| +
|
| +TriView::TriView(Orientation orientation) : TriView(orientation, 0) {}
|
| +
|
| +TriView::TriView(Orientation orientation, int padding_between_containers)
|
| + : box_layout_(new views::BoxLayout(GetOrientation(orientation),
|
| + 0,
|
| + 0,
|
| + padding_between_containers)),
|
| + start_container_layout_manager_(new SizeRangeLayout),
|
| + center_container_layout_manager_(new SizeRangeLayout),
|
| + end_container_layout_manager_(new SizeRangeLayout) {
|
| + AddChildView(new views::View);
|
| + AddChildView(new views::View);
|
| + AddChildView(new views::View);
|
| +
|
| + GetContainer(Container::START)
|
| + ->SetLayoutManager(GetLayoutManager(Container::START));
|
| + GetContainer(Container::CENTER)
|
| + ->SetLayoutManager(GetLayoutManager(Container::CENTER));
|
| + GetContainer(Container::END)
|
| + ->SetLayoutManager(GetLayoutManager(Container::END));
|
| +
|
| + GetLayoutManager(Container::START)
|
| + ->SetLayoutManager(CreateDefaultLayoutManager(orientation));
|
| + GetLayoutManager(Container::CENTER)
|
| + ->SetLayoutManager(CreateDefaultLayoutManager(orientation));
|
| + GetLayoutManager(Container::END)
|
| + ->SetLayoutManager(CreateDefaultLayoutManager(orientation));
|
| +
|
| + SetLayoutManager(box_layout_);
|
| +
|
| + enable_hierarchy_changed_dcheck_ = true;
|
| +}
|
| +
|
| +TriView::~TriView() {
|
| + enable_hierarchy_changed_dcheck_ = false;
|
| +}
|
| +
|
| +void TriView::SetMinCrossAxisSize(int min_size) {
|
| + box_layout_->set_minimum_cross_axis_size(min_size);
|
| +}
|
| +
|
| +void TriView::SetMinSize(Container container, const gfx::Size& size) {
|
| + GetLayoutManager(container)->SetMinSize(size);
|
| +}
|
| +
|
| +void TriView::SetMaxSize(Container container, const gfx::Size& size) {
|
| + GetLayoutManager(container)->SetMaxSize(size);
|
| +}
|
| +
|
| +void TriView::AddView(Container container, views::View* view) {
|
| + GetContainer(container)->AddChildView(view);
|
| +}
|
| +
|
| +void TriView::RemoveAllChildren(Container container, bool delete_children) {
|
| + GetContainer(container)->RemoveAllChildViews(delete_children);
|
| +}
|
| +
|
| +void TriView::SetInsets(const gfx::Insets& insets) {
|
| + box_layout_->set_inside_border_insets(insets);
|
| +}
|
| +
|
| +void TriView::SetContainerBorder(Container container,
|
| + std::unique_ptr<views::Border> border) {
|
| + GetContainer(container)->SetBorder(std::move(border));
|
| +}
|
| +
|
| +void TriView::SetContainerVisible(Container container, bool visible) {
|
| + GetContainer(container)->SetVisible(visible);
|
| +}
|
| +
|
| +void TriView::SetFlexForContainer(Container container, int flex) {
|
| + box_layout_->SetFlexForView(GetContainer(container), flex);
|
| +}
|
| +
|
| +void TriView::SetContainerLayout(
|
| + Container container,
|
| + std::unique_ptr<views::LayoutManager> layout_manager) {
|
| + GetLayoutManager(container)->SetLayoutManager(std::move(layout_manager));
|
| + if (GetLayoutManager(container))
|
| + GetLayoutManager(container)->Installed(GetContainer(container));
|
| +}
|
| +
|
| +void TriView::ViewHierarchyChanged(
|
| + const views::View::ViewHierarchyChangedDetails& details) {
|
| + views::View::ViewHierarchyChanged(details);
|
| + if (!enable_hierarchy_changed_dcheck_)
|
| + return;
|
| +
|
| + if (details.parent == this) {
|
| + if (details.is_add) {
|
| + DCHECK(false)
|
| + << "Child views should not be added directly. They should be added "
|
| + "using TriView::AddView().";
|
| + } else {
|
| + DCHECK(false) << "Container views should not be removed.";
|
| + }
|
| + }
|
| +}
|
| +
|
| +std::unique_ptr<views::LayoutManager> TriView::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* TriView::GetContainer(Container container) const {
|
| + return const_cast<views::View*>(child_at(static_cast<int>(container)));
|
| +}
|
| +
|
| +SizeRangeLayout* TriView::GetLayoutManager(Container container) const {
|
| + switch (container) {
|
| + case Container::START:
|
| + return start_container_layout_manager_;
|
| + case Container::CENTER:
|
| + return center_container_layout_manager_;
|
| + case Container::END:
|
| + return end_container_layout_manager_;
|
| + }
|
| + // Required for some compilers.
|
| + NOTREACHED();
|
| + return nullptr;
|
| +}
|
| +
|
| +} // namespace ash
|
|
|