blob: 5e03d01183f2491de235b74a9bfc8d1d5f96f3dd [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() {
17 SetPaintToLayer();
18 layer()->SetFillsBoundsOpaquely(false);
19 layer()->SetMasksToBounds(true);
20
21 shelf_view_->SetPaintToLayer();
22 shelf_view_->layer()->SetFillsBoundsOpaquely(false);
23 AddChildView(shelf_view_);
24}
25
26gfx::Size ShelfContainerView::CalculatePreferredSize() const {
27 const int width =
28 ShelfView::GetSizeOfAppIcons(shelf_view_->last_visible_index() -
29 shelf_view_->first_visible_index() + 1,
30 false);
Matthew Mourgos75327562019-09-09 21:23:5731 const int height = ShelfConfig::Get()->button_size();
Andrew Xu8a2a7bb2019-08-15 00:08:2432 return shelf_view_->shelf()->IsHorizontalAlignment()
33 ? gfx::Size(width, height)
34 : gfx::Size(height, width);
35}
36
37void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) {
38 PreferredSizeChanged();
39}
40
41void ShelfContainerView::Layout() {
42 shelf_view_->SetBoundsRect(gfx::Rect(shelf_view_->GetPreferredSize()));
43}
44
45const char* ShelfContainerView::GetClassName() const {
46 return "ShelfContainerView";
47}
48
49void ShelfContainerView::TranslateShelfView(const gfx::Vector2dF& offset) {
50 gfx::Transform transform_matrix;
51 transform_matrix.Translate(-offset);
52 shelf_view_->SetTransform(transform_matrix);
53}
54
55} // namespace ash