Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <vector> | |
| 8 | |
| 9 #include "components/bubble/bubble_delegate.h" | |
| 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->weak_ptr_factory.GetWeakPtr(); | |
| 23 scoped_ptr<BubbleController> controller( | |
| 24 new BubbleController(this, bubble.Pass())); | |
| 25 | |
| 26 // TODO(hcarmona): log that bubble was shown. | |
| 27 ScheduleShowBubble(controller->AsWeakPtr()); | |
| 28 | |
| 29 controllers_.push_back(controller.Pass()); | |
| 30 return bubble_ref; | |
| 31 } | |
| 32 | |
| 33 void BubbleManager::CloseBubble(BubbleReference bubble) { | |
| 34 for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) { | |
| 35 if ((*iter)->IsOwnerOf(bubble.get())) { | |
| 36 BubbleController* controller = *iter; | |
| 37 controllers_.weak_erase(iter); | |
| 38 | |
| 39 // TODO(hcarmona): log that bubble was hidden. | |
| 40 controller->Hide(BUBBLE_CLOSE_IGNORE); | |
| 41 controller->Close(); | |
| 42 | |
| 43 // Dancing around this because some bubbles will chain another on close. | |
| 44 delete controller; | |
| 45 return; | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 // Hidden/unmanaged bubbles should not be hidden: this could indicate a bug. | |
| 50 NOTREACHED(); | |
| 51 } | |
| 52 | |
| 53 BubbleManager::BubbleManager() {} | |
| 54 | |
| 55 void BubbleManager::ShowMatchingBubbles(void* context) { | |
| 56 if (!context) | |
| 57 return; | |
| 58 | |
| 59 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.
| |
| 60 if ((*iter)->MatchesContext(context)) { | |
| 61 // TODO(hcarmona): log that bubble was shown. | |
| 62 ScheduleShowBubble((*iter)->AsWeakPtr()); | |
| 63 } | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 void BubbleManager::CloseMatchingBubbles(void* context, | |
| 68 bool force, | |
| 69 BubbleCloseReason reason) { | |
| 70 if (!context) | |
|
please use gerrit instead
2015/08/07 23:02:27
DCHECK instead
hcarmona
2015/08/11 02:35:46
Done.
| |
| 71 return; | |
| 72 | |
| 73 std::vector<BubbleController*> closing; | |
| 74 | |
| 75 for (auto iter = controllers_.begin(); iter != controllers_.end(); ++iter) { | |
| 76 if ((*iter)->MatchesContext(context)) { | |
| 77 // TODO(hcarmona): log that bubble was hidden. | |
| 78 (*iter)->Hide(reason); | |
| 79 if (force || (*iter)->ShouldClose()) { | |
| 80 // Don't call close here to avoid bubbles trying to show the next in a | |
| 81 // series and messing up iterating the controllers. | |
| 82 // I'm looking at you, permission bubbles! | |
| 83 closing.push_back(*iter); | |
| 84 iter = controllers_.weak_erase(iter); | |
| 85 } | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 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.
| |
| 90 (*iter)->Close(); | |
| 91 // No need to remove from the vector. | |
| 92 delete (*iter); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 void BubbleManager::UpdateMatchingBubbles(void* context) { | |
| 97 if (!context) | |
|
please use gerrit instead
2015/08/07 23:02:27
DCHECK instead
hcarmona
2015/08/11 02:35:46
Done.
| |
| 98 return; | |
| 99 | |
| 100 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.
| |
| 101 if ((*iter)->MatchesContext(context)) | |
| 102 (*iter)->UpdateAnchorPosition(); | |
| 103 } | |
| 104 } | |
| OLD | NEW |