Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 1 | // 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 Mourgos | 7532756 | 2019-09-09 21:23:57 | [diff] [blame^] | 7 | #include "ash/public/cpp/shelf_config.h" |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 8 | |
| 9 | namespace ash { |
| 10 | |
| 11 | ShelfContainerView::ShelfContainerView(ShelfView* shelf_view) |
| 12 | : shelf_view_(shelf_view) {} |
| 13 | |
| 14 | ShelfContainerView::~ShelfContainerView() = default; |
| 15 | |
| 16 | void 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 | |
| 26 | gfx::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 Mourgos | 7532756 | 2019-09-09 21:23:57 | [diff] [blame^] | 31 | const int height = ShelfConfig::Get()->button_size(); |
Andrew Xu | 8a2a7bb | 2019-08-15 00:08:24 | [diff] [blame] | 32 | return shelf_view_->shelf()->IsHorizontalAlignment() |
| 33 | ? gfx::Size(width, height) |
| 34 | : gfx::Size(height, width); |
| 35 | } |
| 36 | |
| 37 | void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) { |
| 38 | PreferredSizeChanged(); |
| 39 | } |
| 40 | |
| 41 | void ShelfContainerView::Layout() { |
| 42 | shelf_view_->SetBoundsRect(gfx::Rect(shelf_view_->GetPreferredSize())); |
| 43 | } |
| 44 | |
| 45 | const char* ShelfContainerView::GetClassName() const { |
| 46 | return "ShelfContainerView"; |
| 47 | } |
| 48 | |
| 49 | void 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 |