| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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 #ifndef COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_ |
| 6 #define COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/threading/thread_checker.h" |
| 12 #include "components/bubble/bubble_close_reason.h" |
| 13 |
| 14 class BubbleController; |
| 15 class BubbleDelegate; |
| 16 |
| 17 typedef base::WeakPtr<BubbleController> BubbleReference; |
| 18 |
| 19 // Inherit from BubbleManager to show, update, and close bubbles. |
| 20 // Any class that inherits from BubbleManager should capture any events that |
| 21 // should dismiss a bubble or update its anchor point. |
| 22 // This class assumes that we won't be showing a lot of bubbles simultaneously. |
| 23 // TODO(hcarmona): Handle simultaneous bubbles. http://crbug.com/366937 |
| 24 class BubbleManager { |
| 25 public: |
| 26 BubbleManager(); |
| 27 virtual ~BubbleManager(); |
| 28 |
| 29 // Shows a specific bubble and returns a reference to it. |
| 30 // This reference should be used through the BubbleManager. |
| 31 BubbleReference ShowBubble(scoped_ptr<BubbleDelegate> bubble); |
| 32 |
| 33 // Notify a bubble of an event that might trigger close. |
| 34 // Returns true if the bubble was actually closed. |
| 35 bool CloseBubble(BubbleReference bubble, BubbleCloseReason reason); |
| 36 |
| 37 // Notify all bubbles of an event that might trigger close. |
| 38 void CloseAllBubbles(BubbleCloseReason reason); |
| 39 |
| 40 // Notify all bubbles that their anchor or parent may have changed. |
| 41 void UpdateAllBubbleAnchors(); |
| 42 |
| 43 private: |
| 44 enum ManagerStates { |
| 45 SHOW_BUBBLES, |
| 46 QUEUE_BUBBLES, |
| 47 NO_MORE_BUBBLES, |
| 48 }; |
| 49 |
| 50 // Show any bubbles that were added to |show_queue_|. |
| 51 void ShowPendingBubbles(); |
| 52 |
| 53 // Verify that calls that affect the UI are done on the UI thread. |
| 54 base::ThreadChecker ui_thread_checker_; |
| 55 |
| 56 // Determines what happens to a bubble when |ShowBubble| is called. |
| 57 ManagerStates manager_state_; |
| 58 |
| 59 // The bubbles that are being managed. |
| 60 ScopedVector<BubbleController> controllers_; |
| 61 |
| 62 // The bubbles queued to be shown when possible. |
| 63 ScopedVector<BubbleController> show_queue_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(BubbleManager); |
| 66 }; |
| 67 |
| 68 #endif // COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_ |
| OLD | NEW |