Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: components/bubble/bubble_manager.cc

Issue 1251633002: Add BubbleManager to manage bubbles and ChromeBubbleManager for events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "components/bubble/bubble_manager.h"
6
7 #include "components/bubble/bubble_delegate.h"
8
9 BubbleManager::BubbleManager() {}
10
11 BubbleManager::~BubbleManager() {
12 // The delegate should NOT outlive the manager. When a delegate is destroyed
13 // it should hide itself. This means that when the bubble manager is being
14 // destroyed there should be no visible bubbles.
15 DCHECK_EQ(controllers_.size(), 0);
16 }
17
18 BubbleReference BubbleManager::ShowBubble(scoped_ptr<BubbleDelegate> bubble) {
19 DCHECK(bubble);
20 DCHECK(bubble->GetContext());
21
22 BubbleReference bubble_ref = bubble->AsWeakPtr();
23 scoped_ptr<BubbleController> controller(
24 new BubbleController(this, bubble.Pass()));
25
26 controller->Show();
27 controllers_.push_back(controller.Pass());
28
29 // TODO(hcarmona): log that bubble was shown.
30 return bubble_ref;
31 }
32
33 void BubbleManager::HideBubble(BubbleReference delegate) {
34 for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
35 if ((*iter)->IsOwnerOf(delegate.get())) {
36 // TODO(hcarmona): log that bubble was hidden.
37 (*iter)->Hide(BUBBLE_CLOSE_IGNORE);
38 controllers_.erase(iter);
39 return;
40 }
41 }
42
43 // Hidden/unmanaged bubbles should not be hidden: this could indicate a bug.
44 NOTREACHED();
45 }
46
47 bool BubbleManager::IsBubbleVisible(BubbleReference bubble) {
48 // TODO(hcarmona): Fix this or remove it, if clients don't need to know.
49 return false;
50 }
51
52 void BubbleManager::ShowMatchingBubbles(void* context) {
53 if (!context)
54 return;
55
56 for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
57 if ((*iter)->MatchesContext(context)) {
58 // TODO(hcarmona): log that bubble was hidden.
59 (*iter)->Show();
60 }
61 }
62 }
63
64 void BubbleManager::HideMatchingBubbles(void* context,
65 BubbleCloseReason reason) {
66 if (!context)
67 return;
68
69 for (auto iter = controllers_.begin(); iter != controllers_.end();) {
70 if ((*iter)->MatchesContext(context)) {
71 // TODO(hcarmona): log that bubble was hidden.
72 (*iter)->Hide(reason);
73 iter = controllers_.erase(iter);
74 } else {
75 ++iter;
76 }
77 }
78 }
79
80 void BubbleManager::UpdateMatchingBubbles(void* context) {
81 if (!context)
82 return;
83
84 for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
85 if ((*iter)->MatchesContext(context))
86 (*iter)->UpdateAnchorPosition();
87 }
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698