shelf_container_view.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "ash/shelf/shelf_container_view.h"
  5. #include "ash/public/cpp/shelf_config.h"
  6. #include "ui/compositor/layer.h"
  7. namespace ash {
  8. ShelfContainerView::ShelfContainerView(ShelfView* shelf_view)
  9. : shelf_view_(shelf_view) {}
  10. ShelfContainerView::~ShelfContainerView() = default;
  11. void ShelfContainerView::Initialize() {
  12. SetPaintToLayer(ui::LAYER_NOT_DRAWN);
  13. layer()->SetFillsBoundsOpaquely(false);
  14. layer()->SetMasksToBounds(true);
  15. shelf_view_->SetPaintToLayer(ui::LAYER_NOT_DRAWN);
  16. shelf_view_->layer()->SetFillsBoundsOpaquely(false);
  17. AddChildView(shelf_view_);
  18. }
  19. gfx::Size ShelfContainerView::CalculateIdealSize(int button_size) const {
  20. const int button_strip_size = ShelfView::GetSizeOfAppButtons(
  21. shelf_view_->number_of_visible_apps(), button_size);
  22. return shelf_view_->shelf()->IsHorizontalAlignment()
  23. ? gfx::Size(button_strip_size, button_size)
  24. : gfx::Size(button_size, button_strip_size);
  25. }
  26. gfx::Size ShelfContainerView::CalculatePreferredSize() const {
  27. return CalculateIdealSize(shelf_view_->GetButtonSize());
  28. }
  29. void ShelfContainerView::ChildPreferredSizeChanged(views::View* child) {
  30. // The CL (https://crrev.com/c/1876128) modifies View::PreferredSizeChanged
  31. // by moving InvalidateLayout() after ChildPreferredSizeChanged(). Meanwhile,
  32. // the parent view of ShelfContainerView overrides ChildPreferredSizeChanged
  33. // with calling Layout(). Due to the CL above, ShelfContainerView is not
  34. // labeled as |needs_layout_| when the parent view updates the layout. As a
  35. // result, Calling Layout() in the parent view may not trigger the update in
  36. // child view. So we have to invalidate the layout here explicitly.
  37. InvalidateLayout();
  38. PreferredSizeChanged();
  39. }
  40. const char* ShelfContainerView::GetClassName() const {
  41. return "ShelfContainerView";
  42. }
  43. void ShelfContainerView::TranslateShelfView(const gfx::Vector2dF& offset) {
  44. gfx::Transform transform_matrix;
  45. transform_matrix.Translate(-offset);
  46. shelf_view_->SetTransform(transform_matrix);
  47. shelf_view_->NotifyAccessibilityEvent(ax::mojom::Event::kLocationChanged,
  48. true);
  49. }
  50. } // namespace ash