blob: 0e7ecf3da04f5990133ba05dc351958d1045e1b6 [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
26gfx::Size ShelfContainerView::CalculatePreferredSize() const {
Andrew Xuaa3d7112019-10-02 01:25:3627 return CalculateIdealSize();
Andrew Xu8a2a7bb2019-08-15 00:08:2428}
29
30void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) {
Andrew Xub1faf0c2019-11-19 00:27:1431 // The CL (https://crrev.com/c/1876128) modifies View::PreferredSizeChanged
32 // by moving InvalidateLayout() after ChildPreferredSizeChanged(). Meanwhile,
33 // the parent view of ShelfContainerView overrides ChildPreferredSizeChanged
34 // with calling Layout(). Due to the CL above, ShelfContainerView is not
35 // labeled as |needs_layout_| when the parent view updates the layout. As a
36 // result, Calling Layout() in the parent view may not trigger the update in
37 // child view. So we have to invalidate the layout here explicitly.
38 InvalidateLayout();
39
Andrew Xu8a2a7bb2019-08-15 00:08:2440 PreferredSizeChanged();
41}
42
Andrew Xu8a2a7bb2019-08-15 00:08:2443const char* ShelfContainerView::GetClassName() const {
44 return "ShelfContainerView";
45}
46
47void ShelfContainerView::TranslateShelfView(const gfx::Vector2dF& offset) {
48 gfx::Transform transform_matrix;
49 transform_matrix.Translate(-offset);
50 shelf_view_->SetTransform(transform_matrix);
Andrew Xu5ca25012019-11-01 20:48:3951 shelf_view_->NotifyAccessibilityEvent(ax::mojom::Event::kLocationChanged,
52 true);
Andrew Xu8a2a7bb2019-08-15 00:08:2453}
54
Andrew Xuaa3d7112019-10-02 01:25:3655gfx::Size ShelfContainerView::CalculateIdealSize() const {
56 const int width =
57 ShelfView::GetSizeOfAppIcons(shelf_view_->last_visible_index() -
Manu Cornet80ad0702020-03-05 22:46:0358 shelf_view_->first_visible_index() + 1);
Andrew Xuaa3d7112019-10-02 01:25:3659 const int height = ShelfConfig::Get()->button_size();
60 return shelf_view_->shelf()->IsHorizontalAlignment()
61 ? gfx::Size(width, height)
62 : gfx::Size(height, width);
63}
64
Andrew Xu8a2a7bb2019-08-15 00:08:2465} // namespace ash