palette_welcome_bubble.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2017 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_SYSTEM_PALETTE_PALETTE_WELCOME_BUBBLE_H_
  5. #define ASH_SYSTEM_PALETTE_PALETTE_WELCOME_BUBBLE_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/session/session_observer.h"
  8. #include "ui/events/event_handler.h"
  9. #include "ui/views/widget/widget_observer.h"
  10. class PrefRegistrySimple;
  11. class PrefService;
  12. namespace views {
  13. class View;
  14. }
  15. namespace ash {
  16. class PaletteTray;
  17. // The PaletteWelcomeBubble handles displaying a warm welcome bubble letting
  18. // users know about the PaletteTray the first time a stylus is ejected, or if an
  19. // external stylus is detected. PaletteTray controls the visibility of the
  20. // bubble.
  21. class ASH_EXPORT PaletteWelcomeBubble : public SessionObserver,
  22. public views::WidgetObserver,
  23. public ui::EventHandler {
  24. public:
  25. explicit PaletteWelcomeBubble(PaletteTray* tray);
  26. PaletteWelcomeBubble(const PaletteWelcomeBubble&) = delete;
  27. PaletteWelcomeBubble& operator=(const PaletteWelcomeBubble&) = delete;
  28. ~PaletteWelcomeBubble() override;
  29. static void RegisterProfilePrefs(PrefRegistrySimple* registry);
  30. // Show the welcome bubble iff it has not been shown before.
  31. void ShowIfNeeded();
  32. // Get the pref which stores whether the bubble has been shown before.
  33. bool HasBeenShown() const;
  34. // Set the pref which stores whether the bubble has been shown before as true.
  35. // The bubble will not be shown after this is called.
  36. void MarkAsShown();
  37. // SessionObserver:
  38. void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;
  39. // views::WidgetObserver:
  40. void OnWidgetDestroying(views::Widget* widget) override;
  41. // Returns the bubble view for tests, or null when the bubble is not showing.
  42. views::View* GetBubbleViewForTesting();
  43. private:
  44. friend class PaletteWelcomeBubbleTest;
  45. class WelcomeBubbleView;
  46. // Shows or hides the welcome bubble.
  47. void Show();
  48. void Hide();
  49. // Disconnects from the observers and pre-target handlers.
  50. void DisconnectObservers();
  51. // ui::EventHandler:
  52. void OnMouseEvent(ui::MouseEvent* event) override;
  53. void OnTouchEvent(ui::TouchEvent* event) override;
  54. // The PaletteTray this bubble is associated with. Serves as the anchor for
  55. // the bubble. Not owned.
  56. PaletteTray* tray_ = nullptr;
  57. PrefService* active_user_pref_service_ = nullptr; // Not owned.
  58. WelcomeBubbleView* bubble_view_ = nullptr;
  59. };
  60. } // namespace ash
  61. #endif // ASH_SYSTEM_PALETTE_PALETTE_WELCOME_BUBBLE_H_