blob: bf07f6bb1c07f9da7020d03c524005d689a0996e [file] [log] [blame]
Andrew Xu8a2a7bb2019-08-15 00:08:241// Copyright 2019 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/shelf/shelf_container_view.h"
6
Matthew Mourgos75327562019-09-09 21:23:577#include "ash/public/cpp/shelf_config.h"
Andrew Xu8a2a7bb2019-08-15 00:08:248
9namespace ash {
10
11ShelfContainerView::ShelfContainerView(ShelfView* shelf_view)
12 : shelf_view_(shelf_view) {}
13
14ShelfContainerView::~ShelfContainerView() = default;
15
16void ShelfContainerView::Initialize() {
Mitsuru Oshimad1a016a2020-03-10 04:49:3817 SetPaintToLayer(ui::LAYER_NOT_DRAWN);
Andrew Xu8a2a7bb2019-08-15 00:08:2418 layer()->SetFillsBoundsOpaquely(false);
19 layer()->SetMasksToBounds(true);
20
Mitsuru Oshimad1a016a2020-03-10 04:49:3821 shelf_view_->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
Andrew Xu8a2a7bb2019-08-15 00:08:2422 shelf_view_->layer()->SetFillsBoundsOpaquely(false);
23 AddChildView(shelf_view_);
24}
25
Andrew Xudfea91b92020-05-12 19:03:4626gfx::Size ShelfContainerView::CalculateIdealSize(int button_size) const {
Andrew Xua9865d72020-06-04 20:30:5327 const int button_strip_size = ShelfView::GetSizeOfAppButtons(
28 shelf_view_->number_of_visible_apps(), button_size);
Andrew Xudfea91b92020-05-12 19:03:4629 return shelf_view_->shelf()->IsHorizontalAlignment()
30 ? gfx::Size(button_strip_size, button_size)
31 : gfx::Size(button_size, button_strip_size);
32}
33
Andrew Xu8a2a7bb2019-08-15 00:08:2434gfx::Size ShelfContainerView::CalculatePreferredSize() const {
Andrew Xudfea91b92020-05-12 19:03:4635 return CalculateIdealSize(shelf_view_->GetButtonSize());
Andrew Xu8a2a7bb2019-08-15 00:08:2436}
37
38void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) {
Andrew Xub1faf0c2019-11-19 00:27:1439 // The CL (https://crrev.com/c/1876128) modifies View::PreferredSizeChanged
40 // by moving InvalidateLayout() after ChildPreferredSizeChanged(). Meanwhile,
41 // the parent view of ShelfContainerView overrides ChildPreferredSizeChanged
42 // with calling Layout(). Due to the CL above, ShelfContainerView is not
43 // labeled as |needs_layout_| when the parent view updates the layout. As a
44 // result, Calling Layout() in the parent view may not trigger the update in
45 // child view. So we have to invalidate the layout here explicitly.
46 InvalidateLayout();
47
Andrew Xu8a2a7bb2019-08-15 00:08:2448 PreferredSizeChanged();
49}
50
Andrew Xu8a2a7bb2019-08-15 00:08:2451const char* ShelfContainerView::GetClassName() const {
52 return "ShelfContainerView";
53}
54
55void ShelfContainerView::TranslateShelfView(const gfx::Vector2dF& offset) {
56 gfx::Transform transform_matrix;
57 transform_matrix.Translate(-offset);
58 shelf_view_->SetTransform(transform_matrix);
Andrew Xu5ca25012019-11-01 20:48:3959 shelf_view_->NotifyAccessibilityEvent(ax::mojom::Event::kLocationChanged,
60 true);
Andrew Xu8a2a7bb2019-08-15 00:08:2461}
62
Andrew Xu8a2a7bb2019-08-15 00:08:2463} // namespace ash