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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/bubble/bubble_manager.cc
diff --git a/components/bubble/bubble_manager.cc b/components/bubble/bubble_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3d3ffe93b37b2f012c956c25234f79ba4b8719a7
--- /dev/null
+++ b/components/bubble/bubble_manager.cc
@@ -0,0 +1,88 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/bubble/bubble_manager.h"
+
+#include "components/bubble/bubble_delegate.h"
+
+BubbleManager::BubbleManager() {}
+
+BubbleManager::~BubbleManager() {
+ // The delegate should NOT outlive the manager. When a delegate is destroyed
+ // it should hide itself. This means that when the bubble manager is being
+ // destroyed there should be no visible bubbles.
+ DCHECK_EQ(controllers_.size(), 0);
+}
+
+BubbleReference BubbleManager::ShowBubble(scoped_ptr<BubbleDelegate> bubble) {
+ DCHECK(bubble);
+ DCHECK(bubble->GetContext());
+
+ BubbleReference bubble_ref = bubble->AsWeakPtr();
+ scoped_ptr<BubbleController> controller(
+ new BubbleController(this, bubble.Pass()));
+
+ controller->Show();
+ controllers_.push_back(controller.Pass());
+
+ // TODO(hcarmona): log that bubble was shown.
+ return bubble_ref;
+}
+
+void BubbleManager::HideBubble(BubbleReference delegate) {
+ for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
+ if ((*iter)->IsOwnerOf(delegate.get())) {
+ // TODO(hcarmona): log that bubble was hidden.
+ (*iter)->Hide(BUBBLE_CLOSE_IGNORE);
+ controllers_.erase(iter);
+ return;
+ }
+ }
+
+ // Hidden/unmanaged bubbles should not be hidden: this could indicate a bug.
+ NOTREACHED();
+}
+
+bool BubbleManager::IsBubbleVisible(BubbleReference bubble) {
+ // TODO(hcarmona): Fix this or remove it, if clients don't need to know.
+ return false;
+}
+
+void BubbleManager::ShowMatchingBubbles(void* context) {
+ if (!context)
+ return;
+
+ for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
+ if ((*iter)->MatchesContext(context)) {
+ // TODO(hcarmona): log that bubble was hidden.
+ (*iter)->Show();
+ }
+ }
+}
+
+void BubbleManager::HideMatchingBubbles(void* context,
+ BubbleCloseReason reason) {
+ if (!context)
+ return;
+
+ for (auto iter = controllers_.begin(); iter != controllers_.end();) {
+ if ((*iter)->MatchesContext(context)) {
+ // TODO(hcarmona): log that bubble was hidden.
+ (*iter)->Hide(reason);
+ iter = controllers_.erase(iter);
+ } else {
+ ++iter;
+ }
+ }
+}
+
+void BubbleManager::UpdateMatchingBubbles(void* context) {
+ if (!context)
+ return;
+
+ for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
+ if ((*iter)->MatchesContext(context))
+ (*iter)->UpdateAnchorPosition();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698