| Index: ash/common/system/tray/tray_popup_layout_factory.cc
|
| diff --git a/ash/common/system/tray/tray_popup_layout_factory.cc b/ash/common/system/tray/tray_popup_layout_factory.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..aff4d41dc60e63c2b8f0e602ae6839cc7206b42e
|
| --- /dev/null
|
| +++ b/ash/common/system/tray/tray_popup_layout_factory.cc
|
| @@ -0,0 +1,92 @@
|
| +// 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/tray_popup_layout_factory.h"
|
| +
|
| +#include "ash/common/material_design/material_design_controller.h"
|
| +#include "ash/common/system/tray/three_view_layout.h"
|
| +#include "ash/common/system/tray/tray_constants.h"
|
| +#include "ui/views/controls/button/label_button.h"
|
| +#include "ui/views/layout/box_layout.h"
|
| +
|
| +namespace ash {
|
| +
|
| +namespace {
|
| +
|
| +// Creates a layout manager that positions Views vertically. The Views will be
|
| +// stretched horizontally and centered vertically.
|
| +std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() {
|
| + // TODO(bruthig): Use constants instead of magic numbers.
|
| + views::BoxLayout* box_layout =
|
| + new views::BoxLayout(views::BoxLayout::kVertical, 4, 8, 4);
|
| + box_layout->set_main_axis_alignment(
|
| + views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
|
| + box_layout->set_cross_axis_alignment(
|
| + views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
|
| + return std::unique_ptr<views::LayoutManager>(box_layout);
|
| +}
|
| +
|
| +// Creates a layout manager that positions Views horizontally. The Views will be
|
| +// centered along the horizontal and vertical axis.
|
| +std::unique_ptr<views::LayoutManager> CreateDefaultEndsLayoutManager() {
|
| + views::BoxLayout* box_layout =
|
| + new views::BoxLayout(views::BoxLayout::kHorizontal, 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);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +ThreeViewLayout* TrayPopupLayoutFactory::InstallDefaultLayout(
|
| + views::View* host) {
|
| + ThreeViewLayout* layout = new ThreeViewLayout(0 /* padding_between_items */);
|
| +
|
| + // views::BoxLayout::SetFlexForView() fails on a DCHECK() if it has not yet
|
| + // been installed on a View. Evaluate whether this is necessary or if it can
|
| + // be removed. This would allow us to drop the |host| parameter from this
|
| + // function.
|
| + host->SetLayoutManager(layout);
|
| +
|
| + layout->SetInsets(gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET),
|
| + 0,
|
| + GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET)));
|
| + layout->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
|
| +
|
| + ConfigureDefaultLayout(layout, ThreeViewLayout::START);
|
| + ConfigureDefaultLayout(layout, ThreeViewLayout::CENTER);
|
| + ConfigureDefaultLayout(layout, ThreeViewLayout::END);
|
| +
|
| + return layout;
|
| +}
|
| +
|
| +void TrayPopupLayoutFactory::ConfigureDefaultLayout(
|
| + ThreeViewLayout* layout,
|
| + ThreeViewLayout::Container container) {
|
| + switch (container) {
|
| + case ThreeViewLayout::START:
|
| + layout->SetLayoutManager(ThreeViewLayout::START,
|
| + CreateDefaultEndsLayoutManager());
|
| + layout->SetMinSize(
|
| + ThreeViewLayout::START,
|
| + gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0));
|
| + break;
|
| + case ThreeViewLayout::CENTER:
|
| + layout->SetLayoutManager(ThreeViewLayout::CENTER,
|
| + CreateDefaultCenterLayoutManager());
|
| + layout->SetFlexForView(ThreeViewLayout::CENTER, 1.f);
|
| + break;
|
| + case ThreeViewLayout::END:
|
| + layout->SetLayoutManager(ThreeViewLayout::END,
|
| + CreateDefaultEndsLayoutManager());
|
| + layout->SetMinSize(
|
| + ThreeViewLayout::END,
|
| + gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0));
|
| + break;
|
| + }
|
| +}
|
| +
|
| +} // namespace ash
|
|
|