| 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..8633ed0082ab3a8e5fd708c439400ec9ff3cb1c4
|
| --- /dev/null
|
| +++ b/components/bubble/bubble_manager.cc
|
| @@ -0,0 +1,86 @@
|
| +// 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_controller.h"
|
| +
|
| +BubbleManager::~BubbleManager() {}
|
| +
|
| +BubbleReference BubbleManager::ShowBubble(scoped_ptr<BubbleDelegate> bubble) {
|
| + DCHECK(bubble);
|
| + scoped_ptr<BubbleController> controller(new BubbleController(bubble.Pass()));
|
| +
|
| + BubbleReference bubble_ref = controller->AsWeakPtr();
|
| + ShowBubbleUI(bubble_ref);
|
| +
|
| + controllers_.push_back(controller.Pass());
|
| + return bubble_ref;
|
| +}
|
| +
|
| +bool BubbleManager::CloseBubble(BubbleReference bubble,
|
| + BubbleCloseReason reason) {
|
| + for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) {
|
| + if (*iter == bubble.get()) {
|
| + if (ShouldClose((*iter)->AsWeakPtr(), reason)) {
|
| + // Remove the controller before attempting to delete because some
|
| + // delegates may chain showing more bubbles.
|
| + BubbleController* controller = *iter;
|
| + controllers_.weak_erase(iter);
|
| + delete controller;
|
| + return true;
|
| + }
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + // Attempting to close a bubble that is already closed or that this manager
|
| + // doesn't own is a bug.
|
| + NOTREACHED();
|
| + return false;
|
| +}
|
| +
|
| +void BubbleManager::UpdateAllBubbleAnchors() {
|
| + for (auto controller : controllers_) {
|
| + UpdateAnchorPosition(controller->AsWeakPtr());
|
| + }
|
| +}
|
| +
|
| +BubbleManager::BubbleManager() {}
|
| +
|
| +void BubbleManager::CloseAllBubbles(BubbleCloseReason reason) {
|
| + std::vector<BubbleController*> closing;
|
| +
|
| + for (auto iter = controllers_.begin(); iter != controllers_.end();) {
|
| + if (ShouldClose((*iter)->AsWeakPtr(), reason)) {
|
| + // Remove the controllers before attempting to delete because some
|
| + // delegates may chain showing more bubbles.
|
| + closing.push_back(*iter);
|
| + iter = controllers_.weak_erase(iter);
|
| + continue;
|
| + }
|
| + ++iter;
|
| + }
|
| +
|
| + for (auto iter : closing) {
|
| + delete iter;
|
| + // No need to remove from the vector after deleting.
|
| + }
|
| +}
|
| +
|
| +void BubbleManager::ShowBubbleUI(base::WeakPtr<BubbleController> controller) {
|
| + controller->Show();
|
| +}
|
| +
|
| +bool BubbleManager::ShouldClose(base::WeakPtr<BubbleController> controller,
|
| + BubbleCloseReason reason) {
|
| + return controller->ShouldClose(reason);
|
| +}
|
| +
|
| +void BubbleManager::UpdateAnchorPosition(
|
| + base::WeakPtr<BubbleController> controller) {
|
| + controller->UpdateAnchorPosition();
|
| +}
|
|
|