Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/system/tray/tray_popup_utils.h" | 5 #include "ash/common/system/tray/tray_popup_utils.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_constants.h" | 7 #include "ash/common/ash_constants.h" |
| 8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/system/tray/fixed_sized_image_view.h" | 10 #include "ash/common/system/tray/fixed_sized_image_view.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 // TODO(bruthig): Use constants instead of magic numbers. | 32 // TODO(bruthig): Use constants instead of magic numbers. |
| 33 views::BoxLayout* box_layout = | 33 views::BoxLayout* box_layout = |
| 34 new views::BoxLayout(views::BoxLayout::kVertical, 4, 8, 4); | 34 new views::BoxLayout(views::BoxLayout::kVertical, 4, 8, 4); |
| 35 box_layout->set_main_axis_alignment( | 35 box_layout->set_main_axis_alignment( |
| 36 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | 36 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
| 37 box_layout->set_cross_axis_alignment( | 37 box_layout->set_cross_axis_alignment( |
| 38 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | 38 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); |
| 39 return std::unique_ptr<views::LayoutManager>(box_layout); | 39 return std::unique_ptr<views::LayoutManager>(box_layout); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Creates a layout manager that positions Views horizontally. The Views will be | 42 void ConfigureDefaultLayout(TriView* tri_view, TriView::Container container) { |
|
bruthig
2016/11/10 18:33:40
Just as a heads up this CL: https://codereview.chr
Evan Stade
2016/11/10 19:18:05
Acknowledged.
|
Evan Stade
2016/11/09 23:32:15
the rest of the changes in this file allow the cen
|
| 43 // centered along the horizontal and vertical axis. | 43 const int min_height = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); |
| 44 std::unique_ptr<views::LayoutManager> CreateDefaultEndsLayoutManager() { | 44 switch (container) { |
| 45 views::BoxLayout* box_layout = | 45 case TriView::Container::START: |
| 46 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 46 tri_view->SetMinSize( |
| 47 box_layout->set_main_axis_alignment( | 47 TriView::Container::START, |
| 48 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | 48 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), |
| 49 box_layout->set_cross_axis_alignment( | 49 min_height)); |
| 50 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | 50 break; |
|
Evan Stade
2016/11/09 23:32:15
The code does not match the comment above the func
| |
| 51 return std::unique_ptr<views::LayoutManager>(box_layout); | 51 case TriView::Container::CENTER: |
| 52 tri_view->SetContainerLayout(container, | |
| 53 CreateDefaultCenterLayoutManager()); | |
| 54 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f); | |
| 55 tri_view->SetMinSize(TriView::Container::CENTER, | |
| 56 gfx::Size(0, min_height)); | |
| 57 break; | |
| 58 case TriView::Container::END: | |
| 59 tri_view->SetMinSize( | |
| 60 TriView::Container::END, | |
| 61 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), | |
| 62 min_height)); | |
| 63 break; | |
| 64 } | |
| 52 } | 65 } |
| 53 | 66 |
| 54 class BorderlessLabelButton : public views::LabelButton { | 67 class BorderlessLabelButton : public views::LabelButton { |
| 55 public: | 68 public: |
| 56 BorderlessLabelButton(views::ButtonListener* listener, | 69 BorderlessLabelButton(views::ButtonListener* listener, |
| 57 const base::string16& text) | 70 const base::string16& text) |
| 58 : LabelButton(listener, text) { | 71 : LabelButton(listener, text) { |
| 59 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 72 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 60 SetInkDropMode(views::InkDropHostView::InkDropMode::ON); | 73 SetInkDropMode(views::InkDropHostView::InkDropMode::ON); |
| 61 set_has_ink_drop_action_on_click(true); | 74 set_has_ink_drop_action_on_click(true); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 }; | 110 }; |
| 98 | 111 |
| 99 } // namespace | 112 } // namespace |
| 100 | 113 |
| 101 TriView* TrayPopupUtils::CreateDefaultRowView() { | 114 TriView* TrayPopupUtils::CreateDefaultRowView() { |
| 102 TriView* tri_view = new TriView(0 /* padding_between_items */); | 115 TriView* tri_view = new TriView(0 /* padding_between_items */); |
| 103 | 116 |
| 104 tri_view->SetInsets( | 117 tri_view->SetInsets( |
| 105 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0, | 118 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0, |
| 106 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); | 119 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); |
| 107 tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | |
| 108 | 120 |
| 109 ConfigureDefaultLayout(tri_view, TriView::Container::START); | 121 ConfigureDefaultLayout(tri_view, TriView::Container::START); |
| 110 ConfigureDefaultLayout(tri_view, TriView::Container::CENTER); | 122 ConfigureDefaultLayout(tri_view, TriView::Container::CENTER); |
| 111 ConfigureDefaultLayout(tri_view, TriView::Container::END); | 123 ConfigureDefaultLayout(tri_view, TriView::Container::END); |
| 112 | 124 |
| 113 return tri_view; | 125 return tri_view; |
| 114 } | 126 } |
| 115 | 127 |
| 116 std::unique_ptr<views::LayoutManager> TrayPopupUtils::CreateLayoutManager( | |
| 117 TriView::Container container) { | |
| 118 switch (container) { | |
| 119 case TriView::Container::START: | |
| 120 case TriView::Container::END: | |
| 121 return CreateDefaultEndsLayoutManager(); | |
| 122 case TriView::Container::CENTER: | |
| 123 return CreateDefaultCenterLayoutManager(); | |
| 124 } | |
| 125 // Required by some compilers. | |
| 126 NOTREACHED(); | |
| 127 return nullptr; | |
| 128 } | |
| 129 | |
| 130 views::Label* TrayPopupUtils::CreateDefaultLabel() { | 128 views::Label* TrayPopupUtils::CreateDefaultLabel() { |
| 131 views::Label* label = new views::Label(); | 129 views::Label* label = new views::Label(); |
| 132 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 130 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 133 label->SetBorder(views::CreateEmptyBorder(0, kTrayPopupLabelHorizontalPadding, | 131 label->SetBorder(views::CreateEmptyBorder(0, kTrayPopupLabelHorizontalPadding, |
| 134 0, | 132 0, |
| 135 kTrayPopupLabelHorizontalPadding)); | 133 kTrayPopupLabelHorizontalPadding)); |
| 136 | 134 |
| 137 // TODO(bruthig): Fix this so that |label| uses the kBackgroundColor to | 135 // TODO(bruthig): Fix this so that |label| uses the kBackgroundColor to |
| 138 // perform subpixel rendering instead of disabling subpixel rendering. | 136 // perform subpixel rendering instead of disabling subpixel rendering. |
| 139 // | 137 // |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 184 |
| 187 bool TrayPopupUtils::CanOpenWebUISettings(LoginStatus status) { | 185 bool TrayPopupUtils::CanOpenWebUISettings(LoginStatus status) { |
| 188 // TODO(tdanderson): Consider moving this into WmShell, or introduce a | 186 // TODO(tdanderson): Consider moving this into WmShell, or introduce a |
| 189 // CanShowSettings() method in each delegate type that has a | 187 // CanShowSettings() method in each delegate type that has a |
| 190 // ShowSettings() method. | 188 // ShowSettings() method. |
| 191 return status != LoginStatus::NOT_LOGGED_IN && | 189 return status != LoginStatus::NOT_LOGGED_IN && |
| 192 status != LoginStatus::LOCKED && | 190 status != LoginStatus::LOCKED && |
| 193 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); | 191 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); |
| 194 } | 192 } |
| 195 | 193 |
| 196 void TrayPopupUtils::ConfigureDefaultLayout(TriView* tri_view, | |
| 197 TriView::Container container) { | |
| 198 switch (container) { | |
| 199 case TriView::Container::START: | |
| 200 tri_view->SetMinSize( | |
| 201 TriView::Container::START, | |
| 202 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0)); | |
| 203 break; | |
| 204 case TriView::Container::CENTER: | |
| 205 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f); | |
| 206 break; | |
| 207 case TriView::Container::END: | |
| 208 tri_view->SetMinSize( | |
| 209 TriView::Container::END, | |
| 210 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0)); | |
| 211 break; | |
| 212 } | |
| 213 | |
| 214 tri_view->SetContainerLayout(container, CreateLayoutManager(container)); | |
| 215 } | |
| 216 | |
| 217 } // namespace ash | 194 } // namespace ash |
| OLD | NEW |