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

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: Partial Feedback 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..8dff3bb3ec2188f4b5748d750884c0008a765dfe
--- /dev/null
+++ b/components/bubble/bubble_manager.cc
@@ -0,0 +1,104 @@
+// 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 <vector>
+
+#include "components/bubble/bubble_delegate.h"
+
+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->weak_ptr_factory.GetWeakPtr();
+ scoped_ptr<BubbleController> controller(
+ new BubbleController(this, bubble.Pass()));
+
+ // TODO(hcarmona): log that bubble was shown.
+ ScheduleShowBubble(controller->AsWeakPtr());
+
+ controllers_.push_back(controller.Pass());
+ return bubble_ref;
+}
+
+void BubbleManager::CloseBubble(BubbleReference bubble) {
+ for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
+ if ((*iter)->IsOwnerOf(bubble.get())) {
+ BubbleController* controller = *iter;
+ controllers_.weak_erase(iter);
+
+ // TODO(hcarmona): log that bubble was hidden.
+ controller->Hide(BUBBLE_CLOSE_IGNORE);
+ controller->Close();
+
+ // Dancing around this because some bubbles will chain another on close.
+ delete controller;
+ return;
+ }
+ }
+
+ // Hidden/unmanaged bubbles should not be hidden: this could indicate a bug.
+ NOTREACHED();
+}
+
+BubbleManager::BubbleManager() {}
+
+void BubbleManager::ShowMatchingBubbles(void* context) {
+ if (!context)
+ return;
+
+ for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
please use gerrit instead 2015/08/07 23:02:27 c++11
hcarmona 2015/08/11 02:35:46 Done.
+ if ((*iter)->MatchesContext(context)) {
+ // TODO(hcarmona): log that bubble was shown.
+ ScheduleShowBubble((*iter)->AsWeakPtr());
+ }
+ }
+}
+
+void BubbleManager::CloseMatchingBubbles(void* context,
+ bool force,
+ BubbleCloseReason reason) {
+ if (!context)
please use gerrit instead 2015/08/07 23:02:27 DCHECK instead
hcarmona 2015/08/11 02:35:46 Done.
+ return;
+
+ std::vector<BubbleController*> closing;
+
+ for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
+ if ((*iter)->MatchesContext(context)) {
+ // TODO(hcarmona): log that bubble was hidden.
+ (*iter)->Hide(reason);
+ if (force || (*iter)->ShouldClose()) {
+ // Don't call close here to avoid bubbles trying to show the next in a
+ // series and messing up iterating the controllers.
+ // I'm looking at you, permission bubbles!
+ closing.push_back(*iter);
+ iter = controllers_.weak_erase(iter);
+ }
+ }
+ }
+
+ for (auto iter = closing.begin(); iter != closing.end(); ++iter) {
please use gerrit instead 2015/08/07 23:02:27 c++11
hcarmona 2015/08/11 02:35:46 Done.
+ (*iter)->Close();
+ // No need to remove from the vector.
+ delete (*iter);
+ }
+}
+
+void BubbleManager::UpdateMatchingBubbles(void* context) {
+ if (!context)
please use gerrit instead 2015/08/07 23:02:27 DCHECK instead
hcarmona 2015/08/11 02:35:46 Done.
+ return;
+
+ for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
please use gerrit instead 2015/08/07 23:02:27 c++11
hcarmona 2015/08/11 02:35:46 Done.
+ if ((*iter)->MatchesContext(context))
+ (*iter)->UpdateAnchorPosition();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698