| 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" |
| 11 #include "ash/common/system/tray/tray_constants.h" | 11 #include "ash/common/system/tray/tray_constants.h" |
| 12 #include "ash/common/system/tray/tray_popup_label_button.h" | 12 #include "ash/common/system/tray/tray_popup_label_button.h" |
| 13 #include "ash/common/system/tray/tray_popup_label_button_border.h" | 13 #include "ash/common/system/tray/tray_popup_label_button_border.h" |
| 14 #include "ash/common/wm_shell.h" | 14 #include "ash/common/wm_shell.h" |
| 15 #include "ui/views/animation/ink_drop_impl.h" | 15 #include "ui/views/animation/ink_drop_impl.h" |
| 16 #include "ui/views/border.h" | 16 #include "ui/views/border.h" |
| 17 #include "ui/views/controls/button/button.h" | 17 #include "ui/views/controls/button/button.h" |
| 18 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
| 19 #include "ui/views/controls/button/md_text_button.h" | 19 #include "ui/views/controls/button/md_text_button.h" |
| 20 #include "ui/views/controls/image_view.h" | 20 #include "ui/views/controls/image_view.h" |
| 21 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
| 22 #include "ui/views/controls/separator.h" | 22 #include "ui/views/controls/separator.h" |
| 23 #include "ui/views/controls/slider.h" |
| 23 #include "ui/views/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" |
| 25 #include "ui/views/layout/fill_layout.h" |
| 24 | 26 |
| 25 namespace ash { | 27 namespace ash { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 // Creates a layout manager that positions Views vertically. The Views will be | 31 // Creates a layout manager that positions Views vertically. The Views will be |
| 30 // stretched horizontally and centered vertically. | 32 // stretched horizontally and centered vertically. |
| 31 std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() { | 33 std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() { |
| 32 // TODO(bruthig): Use constants instead of magic numbers. | 34 // TODO(bruthig): Use constants instead of magic numbers. |
| 33 views::BoxLayout* box_layout = | 35 views::BoxLayout* box_layout = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 ink_drop->SetShowHighlightOnHover(false); | 94 ink_drop->SetShowHighlightOnHover(false); |
| 93 return std::move(ink_drop); | 95 return std::move(ink_drop); |
| 94 } | 96 } |
| 95 | 97 |
| 96 DISALLOW_COPY_AND_ASSIGN(BorderlessLabelButton); | 98 DISALLOW_COPY_AND_ASSIGN(BorderlessLabelButton); |
| 97 }; | 99 }; |
| 98 | 100 |
| 99 } // namespace | 101 } // namespace |
| 100 | 102 |
| 101 TriView* TrayPopupUtils::CreateDefaultRowView() { | 103 TriView* TrayPopupUtils::CreateDefaultRowView() { |
| 104 TriView* tri_view = CreateMultiTargetRowView(); |
| 105 tri_view->SetContainerBorder(TriView::Container::START, |
| 106 CreateDefaultBorder(TriView::Container::START)); |
| 107 tri_view->SetContainerBorder(TriView::Container::CENTER, |
| 108 CreateDefaultBorder(TriView::Container::CENTER)); |
| 109 tri_view->SetContainerBorder(TriView::Container::END, |
| 110 CreateDefaultBorder(TriView::Container::END)); |
| 111 |
| 112 tri_view->SetContainerLayout( |
| 113 TriView::Container::START, |
| 114 CreateDefaultLayoutManager(TriView::Container::START)); |
| 115 tri_view->SetContainerLayout( |
| 116 TriView::Container::CENTER, |
| 117 CreateDefaultLayoutManager(TriView::Container::CENTER)); |
| 118 tri_view->SetContainerLayout( |
| 119 TriView::Container::END, |
| 120 CreateDefaultLayoutManager(TriView::Container::END)); |
| 121 |
| 122 return tri_view; |
| 123 } |
| 124 |
| 125 TriView* TrayPopupUtils::CreateMultiTargetRowView() { |
| 102 TriView* tri_view = new TriView(0 /* padding_between_items */); | 126 TriView* tri_view = new TriView(0 /* padding_between_items */); |
| 103 | 127 |
| 104 tri_view->SetInsets( | 128 tri_view->SetInsets( |
| 105 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0, | 129 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0, |
| 106 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); | 130 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); |
| 107 tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 131 tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); |
| 108 | 132 |
| 109 ConfigureDefaultLayout(tri_view, TriView::Container::START); | 133 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::START); |
| 110 ConfigureDefaultLayout(tri_view, TriView::Container::CENTER); | 134 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::CENTER); |
| 111 ConfigureDefaultLayout(tri_view, TriView::Container::END); | 135 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::END); |
| 136 |
| 137 tri_view->SetContainerLayout(TriView::Container::START, |
| 138 base::MakeUnique<views::FillLayout>()); |
| 139 tri_view->SetContainerLayout(TriView::Container::CENTER, |
| 140 base::MakeUnique<views::FillLayout>()); |
| 141 tri_view->SetContainerLayout(TriView::Container::END, |
| 142 base::MakeUnique<views::FillLayout>()); |
| 112 | 143 |
| 113 return tri_view; | 144 return tri_view; |
| 114 } | 145 } |
| 115 | 146 |
| 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() { | 147 views::Label* TrayPopupUtils::CreateDefaultLabel() { |
| 131 views::Label* label = new views::Label(); | 148 views::Label* label = new views::Label(); |
| 132 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 149 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 133 label->SetBorder(views::CreateEmptyBorder(0, kTrayPopupLabelHorizontalPadding, | 150 label->SetBorder(views::CreateEmptyBorder(0, kTrayPopupLabelHorizontalPadding, |
| 134 0, | 151 0, |
| 135 kTrayPopupLabelHorizontalPadding)); | 152 kTrayPopupLabelHorizontalPadding)); |
| 136 | 153 |
| 137 // TODO(bruthig): Fix this so that |label| uses the kBackgroundColor to | 154 // TODO(bruthig): Fix this so that |label| uses the kBackgroundColor to |
| 138 // perform subpixel rendering instead of disabling subpixel rendering. | 155 // perform subpixel rendering instead of disabling subpixel rendering. |
| 139 // | 156 // |
| 140 // Text rendered on a non-opaque background looks ugly and it is possible for | 157 // Text rendered on a non-opaque background looks ugly and it is possible for |
| 141 // labels to given a a clear canvas at paint time when an ink drop is visible. | 158 // labels to given a a clear canvas at paint time when an ink drop is visible. |
| 142 // See http://crbug.com/661714. | 159 // See http://crbug.com/661714. |
| 143 label->SetSubpixelRenderingEnabled(false); | 160 label->SetSubpixelRenderingEnabled(false); |
| 144 | 161 |
| 145 return label; | 162 return label; |
| 146 } | 163 } |
| 147 | 164 |
| 148 views::ImageView* TrayPopupUtils::CreateMainImageView() { | 165 views::ImageView* TrayPopupUtils::CreateMainImageView() { |
| 149 return new FixedSizedImageView( | 166 return new FixedSizedImageView( |
| 150 GetTrayConstant(TRAY_POPUP_ITEM_MAIN_IMAGE_CONTAINER_WIDTH), | 167 GetTrayConstant(TRAY_POPUP_ITEM_MAIN_IMAGE_CONTAINER_WIDTH), |
| 151 GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 168 GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); |
| 152 } | 169 } |
| 153 | 170 |
| 154 views::ImageView* TrayPopupUtils::CreateMoreImageView() { | 171 views::ImageView* TrayPopupUtils::CreateMoreImageView() { |
| 155 views::ImageView* image = new FixedSizedImageView( | 172 views::ImageView* image = |
| 156 GetTrayConstant(TRAY_POPUP_ITEM_MORE_IMAGE_CONTAINER_WIDTH), | 173 new FixedSizedImageView(GetTrayConstant(TRAY_POPUP_ITEM_MORE_IMAGE_SIZE), |
| 157 GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 174 GetTrayConstant(TRAY_POPUP_ITEM_MORE_IMAGE_SIZE)); |
| 158 image->EnableCanvasFlippingForRTLUI(true); | 175 image->EnableCanvasFlippingForRTLUI(true); |
| 159 return image; | 176 return image; |
| 160 } | 177 } |
| 161 | 178 |
| 179 views::Slider* TrayPopupUtils::CreateSlider(views::SliderListener* listener) { |
| 180 const bool is_material = MaterialDesignController::IsSystemTrayMenuMaterial(); |
| 181 views::Slider* slider = views::Slider::CreateSlider(is_material, listener); |
| 182 slider->set_focus_border_color(kFocusBorderColor); |
| 183 if (is_material) { |
| 184 slider->SetBorder( |
| 185 views::CreateEmptyBorder(gfx::Insets(0, kTrayPopupSliderPaddingMD))); |
| 186 } else { |
| 187 slider->SetBorder( |
| 188 views::CreateEmptyBorder(0, 0, 0, kTrayPopupPaddingBetweenItems)); |
| 189 } |
| 190 return slider; |
| 191 } |
| 192 |
| 193 void TrayPopupUtils::ConfigureContainer(TriView::Container container, |
| 194 views::View* container_view) { |
| 195 container_view->SetBorder(CreateDefaultBorder(container)); |
| 196 container_view->SetLayoutManager( |
| 197 CreateDefaultLayoutManager(container).release()); |
| 198 } |
| 199 |
| 200 void TrayPopupUtils::ConfigureDefaultSizeAndFlex(TriView* tri_view, |
| 201 TriView::Container container) { |
| 202 switch (container) { |
| 203 case TriView::Container::START: |
| 204 tri_view->SetMinSize( |
| 205 TriView::Container::START, |
| 206 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0)); |
| 207 break; |
| 208 case TriView::Container::CENTER: |
| 209 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f); |
| 210 break; |
| 211 case TriView::Container::END: |
| 212 tri_view->SetMinSize( |
| 213 TriView::Container::END, |
| 214 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0)); |
| 215 break; |
| 216 } |
| 217 } |
| 218 |
| 162 views::LabelButton* TrayPopupUtils::CreateTrayPopupBorderlessButton( | 219 views::LabelButton* TrayPopupUtils::CreateTrayPopupBorderlessButton( |
| 163 views::ButtonListener* listener, | 220 views::ButtonListener* listener, |
| 164 const base::string16& text) { | 221 const base::string16& text) { |
| 165 return new BorderlessLabelButton(listener, text); | 222 return new BorderlessLabelButton(listener, text); |
| 166 } | 223 } |
| 167 | 224 |
| 168 views::LabelButton* TrayPopupUtils::CreateTrayPopupButton( | 225 views::LabelButton* TrayPopupUtils::CreateTrayPopupButton( |
| 169 views::ButtonListener* listener, | 226 views::ButtonListener* listener, |
| 170 const base::string16& text) { | 227 const base::string16& text) { |
| 171 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) | 228 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 186 | 243 |
| 187 bool TrayPopupUtils::CanOpenWebUISettings(LoginStatus status) { | 244 bool TrayPopupUtils::CanOpenWebUISettings(LoginStatus status) { |
| 188 // TODO(tdanderson): Consider moving this into WmShell, or introduce a | 245 // TODO(tdanderson): Consider moving this into WmShell, or introduce a |
| 189 // CanShowSettings() method in each delegate type that has a | 246 // CanShowSettings() method in each delegate type that has a |
| 190 // ShowSettings() method. | 247 // ShowSettings() method. |
| 191 return status != LoginStatus::NOT_LOGGED_IN && | 248 return status != LoginStatus::NOT_LOGGED_IN && |
| 192 status != LoginStatus::LOCKED && | 249 status != LoginStatus::LOCKED && |
| 193 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); | 250 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); |
| 194 } | 251 } |
| 195 | 252 |
| 196 void TrayPopupUtils::ConfigureDefaultLayout(TriView* tri_view, | 253 std::unique_ptr<views::LayoutManager> |
| 197 TriView::Container container) { | 254 TrayPopupUtils::CreateDefaultLayoutManager(TriView::Container container) { |
| 198 switch (container) { | 255 switch (container) { |
| 199 case TriView::Container::START: | 256 case TriView::Container::START: |
| 200 tri_view->SetMinSize( | 257 case TriView::Container::END: |
| 201 TriView::Container::START, | 258 return CreateDefaultEndsLayoutManager(); |
| 202 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0)); | 259 case TriView::Container::CENTER: |
| 260 return CreateDefaultCenterLayoutManager(); |
| 261 } |
| 262 // Required by some compilers. |
| 263 NOTREACHED(); |
| 264 return nullptr; |
| 265 } |
| 266 |
| 267 std::unique_ptr<views::Border> TrayPopupUtils::CreateDefaultBorder( |
| 268 TriView::Container container) { |
| 269 switch (container) { |
| 270 case TriView::Container::START: |
| 271 // TODO(bruthig): Update the 'Main' images to have a fixed size that is |
| 272 // just the painted size and add a border. |
| 273 return nullptr; |
| 203 break; | 274 break; |
| 204 case TriView::Container::CENTER: | 275 case TriView::Container::CENTER: |
| 205 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f); | 276 return nullptr; |
| 206 break; | 277 break; |
| 207 case TriView::Container::END: | 278 case TriView::Container::END: |
| 208 tri_view->SetMinSize( | 279 return views::CreateEmptyBorder( |
| 209 TriView::Container::END, | 280 0, GetTrayConstant(TRAY_POPUP_ITEM_MORE_REGION_HORIZONTAL_INSET), 0, |
| 210 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0)); | 281 GetTrayConstant(TRAY_POPUP_ITEM_MORE_REGION_HORIZONTAL_INSET)); |
| 211 break; | 282 break; |
| 212 } | 283 } |
| 213 | 284 // Required by some compilers. |
| 214 tri_view->SetContainerLayout(container, CreateLayoutManager(container)); | 285 NOTREACHED(); |
| 286 return nullptr; |
| 215 } | 287 } |
| 216 | 288 |
| 217 } // namespace ash | 289 } // namespace ash |
| OLD | NEW |