Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Unified Diff: ash/common/system/tray/tray_popup_layout_factory.cc

Issue 2439093002: Reland of "Added common layout framework for system menu rows." (Closed)
Patch Set: Addressed review comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/common/system/tray/tray_popup_layout_factory.h ('k') | ash/common/system/tray/tri_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..16941c23835d874ac235768e8b51fb82837c5614
--- /dev/null
+++ b/ash/common/system/tray/tray_popup_layout_factory.cc
@@ -0,0 +1,85 @@
+// 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/tray_constants.h"
+#include "ash/common/system/tray/tri_view.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
+
+TriView* TrayPopupLayoutFactory::CreateDefaultRowView() {
+ TriView* tri_view = new TriView(0 /* padding_between_items */);
+
+ tri_view->SetInsets(
+ gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0,
+ GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET)));
+ tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
+
+ ConfigureDefaultLayout(tri_view, TriView::Container::START);
+ ConfigureDefaultLayout(tri_view, TriView::Container::CENTER);
+ ConfigureDefaultLayout(tri_view, TriView::Container::END);
+
+ return tri_view;
+}
+
+void TrayPopupLayoutFactory::ConfigureDefaultLayout(
+ TriView* tri_view,
+ TriView::Container container) {
+ switch (container) {
+ case TriView::Container::START:
+ tri_view->SetContainerLayout(TriView::Container::START,
+ CreateDefaultEndsLayoutManager());
+ tri_view->SetMinSize(
+ TriView::Container::START,
+ gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0));
+ break;
+ case TriView::Container::CENTER:
+ tri_view->SetContainerLayout(TriView::Container::CENTER,
+ CreateDefaultCenterLayoutManager());
+ tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f);
+ break;
+ case TriView::Container::END:
+ tri_view->SetContainerLayout(TriView::Container::END,
+ CreateDefaultEndsLayoutManager());
+ tri_view->SetMinSize(
+ TriView::Container::END,
+ gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0));
+ break;
+ }
+}
+
+} // namespace ash
« no previous file with comments | « ash/common/system/tray/tray_popup_layout_factory.h ('k') | ash/common/system/tray/tri_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698