| 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/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/system/tray/fixed_sized_image_view.h" | 9 #include "ash/common/system/tray/fixed_sized_image_view.h" |
| 9 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
| 10 #include "ash/common/system/tray/tray_popup_label_button.h" | 11 #include "ash/common/system/tray/tray_popup_label_button.h" |
| 11 #include "ui/views/border.h" | 12 #include "ui/views/border.h" |
| 12 #include "ui/views/controls/button/label_button.h" | 13 #include "ui/views/controls/button/label_button.h" |
| 13 #include "ui/views/controls/image_view.h" | 14 #include "ui/views/controls/image_view.h" |
| 14 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 16 #include "ui/views/controls/slider.h" |
| 15 #include "ui/views/layout/box_layout.h" | 17 #include "ui/views/layout/box_layout.h" |
| 18 #include "ui/views/layout/fill_layout.h" |
| 16 | 19 |
| 17 namespace ash { | 20 namespace ash { |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 // Creates a layout manager that positions Views vertically. The Views will be | 24 // Creates a layout manager that positions Views vertically. The Views will be |
| 22 // stretched horizontally and centered vertically. | 25 // stretched horizontally and centered vertically. |
| 23 std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() { | 26 std::unique_ptr<views::LayoutManager> CreateDefaultCenterLayoutManager() { |
| 24 // TODO(bruthig): Use constants instead of magic numbers. | 27 // TODO(bruthig): Use constants instead of magic numbers. |
| 25 views::BoxLayout* box_layout = | 28 views::BoxLayout* box_layout = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 box_layout->set_main_axis_alignment( | 42 box_layout->set_main_axis_alignment( |
| 40 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | 43 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
| 41 box_layout->set_cross_axis_alignment( | 44 box_layout->set_cross_axis_alignment( |
| 42 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | 45 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); |
| 43 return std::unique_ptr<views::LayoutManager>(box_layout); | 46 return std::unique_ptr<views::LayoutManager>(box_layout); |
| 44 } | 47 } |
| 45 | 48 |
| 46 } // namespace | 49 } // namespace |
| 47 | 50 |
| 48 TriView* TrayPopupUtils::CreateDefaultRowView() { | 51 TriView* TrayPopupUtils::CreateDefaultRowView() { |
| 52 TriView* tri_view = CreateMultiTargetRowView(); |
| 53 tri_view->SetContainerBorder(TriView::Container::START, |
| 54 CreateDefaultBorder(TriView::Container::START)); |
| 55 tri_view->SetContainerBorder(TriView::Container::CENTER, |
| 56 CreateDefaultBorder(TriView::Container::CENTER)); |
| 57 tri_view->SetContainerBorder(TriView::Container::END, |
| 58 CreateDefaultBorder(TriView::Container::END)); |
| 59 |
| 60 tri_view->SetContainerLayout( |
| 61 TriView::Container::START, |
| 62 CreateDefaultLayoutManager(TriView::Container::START)); |
| 63 tri_view->SetContainerLayout( |
| 64 TriView::Container::CENTER, |
| 65 CreateDefaultLayoutManager(TriView::Container::CENTER)); |
| 66 tri_view->SetContainerLayout( |
| 67 TriView::Container::END, |
| 68 CreateDefaultLayoutManager(TriView::Container::END)); |
| 69 |
| 70 return tri_view; |
| 71 } |
| 72 |
| 73 TriView* TrayPopupUtils::CreateMultiTargetRowView() { |
| 49 TriView* tri_view = new TriView(0 /* padding_between_items */); | 74 TriView* tri_view = new TriView(0 /* padding_between_items */); |
| 50 | 75 |
| 51 tri_view->SetInsets( | 76 tri_view->SetInsets( |
| 52 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0, | 77 gfx::Insets(0, GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET), 0, |
| 53 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); | 78 GetTrayConstant(TRAY_POPUP_ITEM_RIGHT_INSET))); |
| 54 tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 79 tri_view->SetMinCrossAxisSize(GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); |
| 55 | 80 |
| 56 ConfigureDefaultLayout(tri_view, TriView::Container::START); | 81 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::START); |
| 57 ConfigureDefaultLayout(tri_view, TriView::Container::CENTER); | 82 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::CENTER); |
| 58 ConfigureDefaultLayout(tri_view, TriView::Container::END); | 83 ConfigureDefaultSizeAndFlex(tri_view, TriView::Container::END); |
| 84 |
| 85 tri_view->SetContainerLayout(TriView::Container::START, |
| 86 base::MakeUnique<views::FillLayout>()); |
| 87 tri_view->SetContainerLayout(TriView::Container::CENTER, |
| 88 base::MakeUnique<views::FillLayout>()); |
| 89 tri_view->SetContainerLayout(TriView::Container::END, |
| 90 base::MakeUnique<views::FillLayout>()); |
| 59 | 91 |
| 60 return tri_view; | 92 return tri_view; |
| 61 } | 93 } |
| 62 | 94 |
| 63 std::unique_ptr<views::LayoutManager> TrayPopupUtils::CreateLayoutManager( | |
| 64 TriView::Container container) { | |
| 65 switch (container) { | |
| 66 case TriView::Container::START: | |
| 67 case TriView::Container::END: | |
| 68 return CreateDefaultEndsLayoutManager(); | |
| 69 case TriView::Container::CENTER: | |
| 70 return CreateDefaultCenterLayoutManager(); | |
| 71 } | |
| 72 // Required by some compilers. | |
| 73 NOTREACHED(); | |
| 74 return nullptr; | |
| 75 } | |
| 76 | |
| 77 views::Label* TrayPopupUtils::CreateDefaultLabel() { | 95 views::Label* TrayPopupUtils::CreateDefaultLabel() { |
| 78 views::Label* label = new views::Label(); | 96 views::Label* label = new views::Label(); |
| 79 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 97 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 80 label->SetBorder(views::CreateEmptyBorder(0, kTrayPopupLabelHorizontalPadding, | 98 label->SetBorder(views::CreateEmptyBorder(0, kTrayPopupLabelHorizontalPadding, |
| 81 0, | 99 0, |
| 82 kTrayPopupLabelHorizontalPadding)); | 100 kTrayPopupLabelHorizontalPadding)); |
| 83 | 101 |
| 84 // TODO(bruthig): Fix this so that |label| uses the kBackgroundColor to | 102 // TODO(bruthig): Fix this so that |label| uses the kBackgroundColor to |
| 85 // perform subpixel rendering instead of disabling subpixel rendering. | 103 // perform subpixel rendering instead of disabling subpixel rendering. |
| 86 // | 104 // |
| 87 // Text rendered on a non-opaque background looks ugly and it is possible for | 105 // Text rendered on a non-opaque background looks ugly and it is possible for |
| 88 // labels to given a a clear canvas at paint time when an ink drop is visible. | 106 // labels to given a a clear canvas at paint time when an ink drop is visible. |
| 89 // See http://crbug.com/661714. | 107 // See http://crbug.com/661714. |
| 90 label->SetSubpixelRenderingEnabled(false); | 108 label->SetSubpixelRenderingEnabled(false); |
| 91 | 109 |
| 92 return label; | 110 return label; |
| 93 } | 111 } |
| 94 | 112 |
| 95 views::ImageView* TrayPopupUtils::CreateMainImageView() { | 113 views::ImageView* TrayPopupUtils::CreateMainImageView() { |
| 96 return new FixedSizedImageView( | 114 return new FixedSizedImageView( |
| 97 GetTrayConstant(TRAY_POPUP_ITEM_MAIN_IMAGE_CONTAINER_WIDTH), | 115 GetTrayConstant(TRAY_POPUP_ITEM_MAIN_IMAGE_CONTAINER_WIDTH), |
| 98 GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 116 GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); |
| 99 } | 117 } |
| 100 | 118 |
| 101 views::ImageView* TrayPopupUtils::CreateMoreImageView() { | 119 views::ImageView* TrayPopupUtils::CreateMoreImageView() { |
| 102 views::ImageView* image = new FixedSizedImageView( | 120 views::ImageView* image = |
| 103 GetTrayConstant(TRAY_POPUP_ITEM_MORE_IMAGE_CONTAINER_WIDTH), | 121 new FixedSizedImageView(GetTrayConstant(TRAY_POPUP_ITEM_MORE_IMAGE_SIZE), |
| 104 GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 122 GetTrayConstant(TRAY_POPUP_ITEM_MORE_IMAGE_SIZE)); |
| 105 image->EnableCanvasFlippingForRTLUI(true); | 123 image->EnableCanvasFlippingForRTLUI(true); |
| 106 return image; | 124 return image; |
| 107 } | 125 } |
| 108 | 126 |
| 109 void TrayPopupUtils::ConfigureDefaultLayout(TriView* tri_view, | 127 views::Slider* TrayPopupUtils::CreateSlider(views::SliderListener* listener) { |
| 110 TriView::Container container) { | 128 const bool is_material = MaterialDesignController::IsSystemTrayMenuMaterial(); |
| 129 views::Slider* slider = views::Slider::CreateSlider(is_material, listener); |
| 130 slider->set_focus_border_color(kFocusBorderColor); |
| 131 if (is_material) { |
| 132 slider->SetBorder( |
| 133 views::CreateEmptyBorder(gfx::Insets(0, kTrayPopupSliderPaddingMD))); |
| 134 } else { |
| 135 slider->SetBorder( |
| 136 views::CreateEmptyBorder(0, 0, 0, kTrayPopupPaddingBetweenItems)); |
| 137 } |
| 138 return slider; |
| 139 } |
| 140 |
| 141 void TrayPopupUtils::ConfigureContainer(TriView::Container container, |
| 142 views::View* container_view) { |
| 143 container_view->SetBorder(CreateDefaultBorder(container)); |
| 144 container_view->SetLayoutManager( |
| 145 CreateDefaultLayoutManager(container).release()); |
| 146 } |
| 147 |
| 148 void TrayPopupUtils::ConfigureDefaultSizeAndFlex(TriView* tri_view, |
| 149 TriView::Container container) { |
| 111 switch (container) { | 150 switch (container) { |
| 112 case TriView::Container::START: | 151 case TriView::Container::START: |
| 113 tri_view->SetMinSize( | 152 tri_view->SetMinSize( |
| 114 TriView::Container::START, | 153 TriView::Container::START, |
| 115 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0)); | 154 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_START_WIDTH), 0)); |
| 116 break; | 155 break; |
| 117 case TriView::Container::CENTER: | 156 case TriView::Container::CENTER: |
| 118 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f); | 157 tri_view->SetFlexForContainer(TriView::Container::CENTER, 1.f); |
| 119 break; | 158 break; |
| 120 case TriView::Container::END: | 159 case TriView::Container::END: |
| 121 tri_view->SetMinSize( | 160 tri_view->SetMinSize( |
| 122 TriView::Container::END, | 161 TriView::Container::END, |
| 123 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0)); | 162 gfx::Size(GetTrayConstant(TRAY_POPUP_ITEM_MIN_END_WIDTH), 0)); |
| 124 break; | 163 break; |
| 125 } | 164 } |
| 165 } |
| 126 | 166 |
| 127 tri_view->SetContainerLayout(container, CreateLayoutManager(container)); | 167 std::unique_ptr<views::LayoutManager> |
| 168 TrayPopupUtils::CreateDefaultLayoutManager(TriView::Container container) { |
| 169 switch (container) { |
| 170 case TriView::Container::START: |
| 171 case TriView::Container::END: |
| 172 return CreateDefaultEndsLayoutManager(); |
| 173 case TriView::Container::CENTER: |
| 174 return CreateDefaultCenterLayoutManager(); |
| 175 } |
| 176 // Required by some compilers. |
| 177 NOTREACHED(); |
| 178 return nullptr; |
| 179 } |
| 180 |
| 181 std::unique_ptr<views::Border> TrayPopupUtils::CreateDefaultBorder( |
| 182 TriView::Container container) { |
| 183 switch (container) { |
| 184 case TriView::Container::START: |
| 185 // TODO(bruthig): Update the 'Main' images to have a fixed size that is |
| 186 // just the painted size and add a border. |
| 187 return nullptr; |
| 188 break; |
| 189 case TriView::Container::CENTER: |
| 190 return nullptr; |
| 191 break; |
| 192 case TriView::Container::END: |
| 193 return views::CreateEmptyBorder( |
| 194 0, GetTrayConstant(TRAY_POPUP_ITEM_MORE_REGION_HORIZONTAL_INSET), 0, |
| 195 GetTrayConstant(TRAY_POPUP_ITEM_MORE_REGION_HORIZONTAL_INSET)); |
| 196 break; |
| 197 } |
| 198 // Required by some compilers. |
| 199 NOTREACHED(); |
| 200 return nullptr; |
| 128 } | 201 } |
| 129 | 202 |
| 130 } // namespace ash | 203 } // namespace ash |
| OLD | NEW |