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.
5 #ifndef COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_
6 #define COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_
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"
14 class BubbleController
;
17 typedef base::WeakPtr
<BubbleController
> BubbleReference
;
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
26 // Should be instantiated on the UI thread.
28 virtual ~BubbleManager();
30 // Shows a specific bubble and returns a reference to it.
31 // This reference should be used through the BubbleManager.
32 BubbleReference
ShowBubble(scoped_ptr
<BubbleDelegate
> bubble
);
34 // Notify a bubble of an event that might trigger close.
35 // Returns true if the bubble was actually closed.
36 bool CloseBubble(BubbleReference bubble
, BubbleCloseReason reason
);
38 // Notify all bubbles of an event that might trigger close.
39 void CloseAllBubbles(BubbleCloseReason reason
);
41 // Notify all bubbles that their anchor or parent may have changed.
42 void UpdateAllBubbleAnchors();
51 // Show any bubbles that were added to |show_queue_|.
52 void ShowPendingBubbles();
54 // Verify that functions that affect the UI are done on the same thread.
55 base::ThreadChecker thread_checker_
;
57 // Determines what happens to a bubble when |ShowBubble| is called.
58 ManagerStates manager_state_
;
60 // The bubbles that are being managed.
61 ScopedVector
<BubbleController
> controllers_
;
63 // The bubbles queued to be shown when possible.
64 ScopedVector
<BubbleController
> show_queue_
;
66 DISALLOW_COPY_AND_ASSIGN(BubbleManager
);
69 #endif // COMPONENTS_BUBBLE_BUBBLE_MANAGER_H_