contextual_nudge.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2020 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. #ifndef ASH_CONTROLS_CONTEXTUAL_NUDGE_H_
  5. #define ASH_CONTROLS_CONTEXTUAL_NUDGE_H_
  6. #include "ash/ash_export.h"
  7. #include "base/callback.h"
  8. #include "ui/views/bubble/bubble_dialog_delegate_view.h"
  9. #include "ui/views/controls/label.h"
  10. namespace views {
  11. class View;
  12. } // namespace views
  13. namespace ash {
  14. // The implementation of contextual nudge tooltip bubbles.
  15. class ASH_EXPORT ContextualNudge : public views::BubbleDialogDelegateView {
  16. public:
  17. // Indicates whether the nudge should be shown below or above the anchor.
  18. enum class Position { kBottom, kTop };
  19. // |anchor| - The view to which the nudge bubble should be anchored. May be
  20. // nullptr, in which case anchor bounds should be provided using
  21. // UpdateAnchorRect().
  22. // |parent_window| - if set, the window that should parent the nudge native
  23. // window. If not set, the shelf container in the anchor view's root
  24. // window will be used.
  25. // |position| - The nudge position relative to the anchor rectangle.
  26. // |margins| - The margins added to the nudge bubble.
  27. // |text| - The nudge text.
  28. // |text_color| - The nudge text label foreground color.
  29. // |tap_callback| - If set, the callback called when the user taps the nuge.
  30. ContextualNudge(views::View* anchor,
  31. aura::Window* parent_window,
  32. Position position,
  33. const gfx::Insets& margins,
  34. const std::u16string& text,
  35. SkColor text_color,
  36. const base::RepeatingClosure& tap_callback);
  37. ~ContextualNudge() override;
  38. ContextualNudge(const ContextualNudge&) = delete;
  39. ContextualNudge& operator=(const ContextualNudge&) = delete;
  40. views::Label* label() { return label_; }
  41. // Sets the nudge bubble anchor rect - should be used to set the anchor rect
  42. // if no valid anchor was passed to the nudge bubble.
  43. void UpdateAnchorRect(const gfx::Rect& rect);
  44. // BubbleDialogDelegateView:
  45. ui::LayerType GetLayerType() const override;
  46. void OnGestureEvent(ui::GestureEvent* event) override;
  47. private:
  48. base::RepeatingClosure tap_callback_;
  49. views::Label* label_;
  50. };
  51. } // namespace ash
  52. #endif // ASH_CONTROLS_CONTEXTUAL_NUDGE_H_