shelf_bubble.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2018 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_bubble.h"
  5. #include "ash/public/cpp/shell_window_ids.h"
  6. #include "ui/accessibility/ax_enums.mojom.h"
  7. #include "ui/aura/window.h"
  8. #include "ui/views/bubble/bubble_frame_view.h"
  9. namespace {
  10. views::BubbleBorder::Arrow GetArrow(ash::ShelfAlignment alignment) {
  11. switch (alignment) {
  12. case ash::ShelfAlignment::kBottom:
  13. case ash::ShelfAlignment::kBottomLocked:
  14. return views::BubbleBorder::BOTTOM_CENTER;
  15. case ash::ShelfAlignment::kLeft:
  16. return views::BubbleBorder::LEFT_CENTER;
  17. case ash::ShelfAlignment::kRight:
  18. return views::BubbleBorder::RIGHT_CENTER;
  19. }
  20. return views::BubbleBorder::Arrow::NONE;
  21. }
  22. } // namespace
  23. namespace ash {
  24. ShelfBubble::ShelfBubble(views::View* anchor, ShelfAlignment alignment)
  25. : views::BubbleDialogDelegateView(anchor, GetArrow(alignment)),
  26. background_animator_(
  27. /* Don't pass the Shelf so the translucent color is always used. */
  28. nullptr,
  29. Shell::Get()->wallpaper_controller()) {
  30. // Bubbles that use transparent colors should not paint their ClientViews to a
  31. // layer as doing so could result in visual artifacts.
  32. SetPaintClientToLayer(false);
  33. SetButtons(ui::DIALOG_BUTTON_NONE);
  34. background_animator_.Init(ShelfBackgroundType::kDefaultBg);
  35. background_animator_.AddObserver(this);
  36. // Place the bubble in the same display as the anchor.
  37. set_parent_window(
  38. anchor_widget()->GetNativeWindow()->GetRootWindow()->GetChildById(
  39. kShellWindowId_SettingBubbleContainer));
  40. // We override the role because the base class sets it to alert dialog,
  41. // which results in each tooltip title being announced twice on screen
  42. // readers each time it is shown.
  43. SetAccessibleRole(ax::mojom::Role::kDialog);
  44. }
  45. ShelfBubble::~ShelfBubble() {
  46. background_animator_.RemoveObserver(this);
  47. }
  48. void ShelfBubble::CreateBubble() {
  49. // Actually create the bubble.
  50. views::BubbleDialogDelegateView::CreateBubble(this);
  51. // Settings that should only be changed just after bubble creation.
  52. GetBubbleFrameView()->SetCornerRadius(border_radius_);
  53. GetBubbleFrameView()->SetBackgroundColor(color());
  54. }
  55. void ShelfBubble::UpdateShelfBackground(SkColor color) {
  56. set_color(color);
  57. }
  58. } // namespace ash