Avi Drissman | 3a215d1e | 2022-09-07 19:43:09 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 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/shelf/shelf_container_view.h" |
| 6 | |
Matthew Mourgos | 7532756 | 2019-09-09 21:23:57 | [diff] [blame] | 7 | #include "ash/public/cpp/shelf_config.h" |
Lei Zhang | 0c04332 | 2021-04-27 16:43:05 | [diff] [blame] | 8 | #include "ui/compositor/layer.h" |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 9 | |
| 10 | namespace ash { |
| 11 | |
| 12 | ShelfContainerView::ShelfContainerView(ShelfView* shelf_view) |
| 13 | : shelf_view_(shelf_view) {} |
| 14 | |
| 15 | ShelfContainerView::~ShelfContainerView() = default; |
| 16 | |
| 17 | void ShelfContainerView::Initialize() { |
Mitsuru Oshima | d1a016a | 2020-03-10 04:49:38 | [diff] [blame] | 18 | SetPaintToLayer(ui::LAYER_NOT_DRAWN); |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 19 | layer()->SetFillsBoundsOpaquely(false); |
| 20 | layer()->SetMasksToBounds(true); |
| 21 | |
Mitsuru Oshima | d1a016a | 2020-03-10 04:49:38 | [diff] [blame] | 22 | shelf_view_->SetPaintToLayer(ui::LAYER_NOT_DRAWN); |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 23 | shelf_view_->layer()->SetFillsBoundsOpaquely(false); |
Arthur Sonzogni | 834e018f | 2023-04-22 10:20:02 | [diff] [blame^] | 24 | AddChildView(shelf_view_.get()); |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 25 | } |
| 26 | |
Andrew Xu | dfea91b9 | 2020-05-12 19:03:46 | [diff] [blame] | 27 | gfx::Size ShelfContainerView::CalculateIdealSize(int button_size) const { |
Avery Musbach | c459c54 | 2022-10-07 04:07:45 | [diff] [blame] | 28 | const int button_strip_size = shelf_view_->GetSizeOfAppButtons( |
Andrew Xu | a9865d7 | 2020-06-04 20:30:53 | [diff] [blame] | 29 | shelf_view_->number_of_visible_apps(), button_size); |
Andrew Xu | dfea91b9 | 2020-05-12 19:03:46 | [diff] [blame] | 30 | return shelf_view_->shelf()->IsHorizontalAlignment() |
| 31 | ? gfx::Size(button_strip_size, button_size) |
| 32 | : gfx::Size(button_size, button_strip_size); |
| 33 | } |
| 34 | |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 35 | gfx::Size ShelfContainerView::CalculatePreferredSize() const { |
Andrew Xu | dfea91b9 | 2020-05-12 19:03:46 | [diff] [blame] | 36 | return CalculateIdealSize(shelf_view_->GetButtonSize()); |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) { |
Andrew Xu | b1faf0c | 2019-11-19 00:27:14 | [diff] [blame] | 40 | // The CL (https://crrev.com/c/1876128) modifies View::PreferredSizeChanged |
| 41 | // by moving InvalidateLayout() after ChildPreferredSizeChanged(). Meanwhile, |
| 42 | // the parent view of ShelfContainerView overrides ChildPreferredSizeChanged |
| 43 | // with calling Layout(). Due to the CL above, ShelfContainerView is not |
| 44 | // labeled as |needs_layout_| when the parent view updates the layout. As a |
| 45 | // result, Calling Layout() in the parent view may not trigger the update in |
| 46 | // child view. So we have to invalidate the layout here explicitly. |
| 47 | InvalidateLayout(); |
| 48 | |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 49 | PreferredSizeChanged(); |
| 50 | } |
| 51 | |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 52 | const char* ShelfContainerView::GetClassName() const { |
| 53 | return "ShelfContainerView"; |
| 54 | } |
| 55 | |
| 56 | void ShelfContainerView::TranslateShelfView(const gfx::Vector2dF& offset) { |
| 57 | gfx::Transform transform_matrix; |
| 58 | transform_matrix.Translate(-offset); |
| 59 | shelf_view_->SetTransform(transform_matrix); |
Andrew Xu | 5ca2501 | 2019-11-01 20:48:39 | [diff] [blame] | 60 | shelf_view_->NotifyAccessibilityEvent(ax::mojom::Event::kLocationChanged, |
| 61 | true); |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 62 | } |
| 63 | |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 64 | } // namespace ash |