Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/system/tray/tray_container.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "ash/shelf/wm_shelf.h" | |
| 10 #include "ash/system/tray/tray_constants.h" | |
| 11 #include "ui/gfx/geometry/insets.h" | |
| 12 #include "ui/views/border.h" | |
| 13 #include "ui/views/layout/box_layout.h" | |
| 14 | |
| 15 namespace ash { | |
| 16 | |
| 17 TrayContainer::TrayContainer(WmShelf* wm_shelf) : wm_shelf_(wm_shelf) { | |
| 18 UpdateLayout(); | |
|
James Cook
2017/04/17 16:54:35
nit: DCHECK(wm_shelf_)
I like formal precondition
mohsen
2017/04/19 22:59:07
Done.
| |
| 19 } | |
| 20 | |
| 21 void TrayContainer::UpdateAfterShelfAlignmentChange() { | |
| 22 UpdateLayout(); | |
| 23 } | |
| 24 | |
| 25 void TrayContainer::SetMargin(int main_axis_margin, int cross_axis_margin) { | |
| 26 main_axis_margin_ = main_axis_margin; | |
| 27 cross_axis_margin_ = cross_axis_margin; | |
| 28 UpdateLayout(); | |
| 29 } | |
| 30 | |
| 31 void TrayContainer::ChildPreferredSizeChanged(views::View* child) { | |
| 32 PreferredSizeChanged(); | |
| 33 } | |
| 34 | |
| 35 void TrayContainer::ChildVisibilityChanged(View* child) { | |
| 36 PreferredSizeChanged(); | |
| 37 } | |
| 38 | |
| 39 void TrayContainer::ViewHierarchyChanged( | |
| 40 const ViewHierarchyChangedDetails& details) { | |
| 41 if (details.parent == this) | |
| 42 PreferredSizeChanged(); | |
| 43 } | |
| 44 | |
| 45 void TrayContainer::UpdateLayout() { | |
| 46 bool is_horizontal = wm_shelf_->IsHorizontalAlignment(); | |
|
James Cook
2017/04/17 16:54:35
nit: const
mohsen
2017/04/19 22:59:07
Done.
| |
| 47 | |
| 48 // Adjust the size of status tray dark background by adding additional | |
| 49 // empty border. | |
| 50 views::BoxLayout::Orientation orientation = | |
| 51 is_horizontal ? views::BoxLayout::kHorizontal | |
| 52 : views::BoxLayout::kVertical; | |
| 53 | |
| 54 const int hit_region_with_separator = kHitRegionPadding + kSeparatorWidth; | |
| 55 gfx::Insets insets( | |
| 56 is_horizontal | |
| 57 ? gfx::Insets(0, kHitRegionPadding, 0, hit_region_with_separator) | |
| 58 : gfx::Insets(kHitRegionPadding, 0, hit_region_with_separator, 0)); | |
| 59 if (base::i18n::IsRTL()) | |
| 60 insets.Set(insets.top(), insets.right(), insets.bottom(), insets.left()); | |
| 61 SetBorder(views::CreateEmptyBorder(insets)); | |
| 62 | |
| 63 int horizontal_margin = main_axis_margin_; | |
| 64 int vertical_margin = cross_axis_margin_; | |
| 65 if (!is_horizontal) | |
| 66 std::swap(horizontal_margin, vertical_margin); | |
| 67 views::BoxLayout* layout = | |
| 68 new views::BoxLayout(orientation, horizontal_margin, vertical_margin, 0); | |
| 69 | |
| 70 layout->set_minimum_cross_axis_size(kTrayItemSize); | |
| 71 views::View::SetLayoutManager(layout); | |
| 72 | |
| 73 PreferredSizeChanged(); | |
| 74 } | |
| 75 | |
| 76 } // namespace ash | |
| OLD | NEW |