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_controller.h" | |
| 6 | |
| 7 #include "components/bubble/bubble_delegate.h" | |
| 8 #include "components/bubble/bubble_ui.h" | |
| 9 | |
| 10 BubbleController::BubbleController(scoped_ptr<BubbleDelegate> delegate) | |
| 11 : delegate_(delegate.Pass()), bubble_ui_(nullptr), weak_ptr_factory_(this) { | |
|
msw
2015/08/18 17:26:19
nit: remove the bubble_ui_(nullptr) init, scoped_p
hcarmona
2015/08/18 23:08:48
Done.
| |
| 12 DCHECK(delegate_); | |
| 13 } | |
| 14 | |
| 15 BubbleController::~BubbleController() { | |
| 16 // Necessary so that any BubbleReferences are cleaned up in case a | |
| 17 // BubbleDelegate needs to chain showing bubbles when it's deleted. | |
| 18 weak_ptr_factory_.InvalidateWeakPtrs(); | |
| 19 | |
| 20 if (bubble_ui_) | |
| 21 ShouldClose(BUBBLE_CLOSE_FORCED); | |
| 22 } | |
| 23 | |
| 24 void BubbleController::Show() { | |
| 25 DCHECK(!bubble_ui_); | |
| 26 bubble_ui_ = delegate_->BuildBubbleUI(); | |
| 27 DCHECK(bubble_ui_); | |
| 28 bubble_ui_->Show(); | |
| 29 // TODO(hcarmona): log that bubble was shown. | |
| 30 } | |
| 31 | |
| 32 void BubbleController::UpdateAnchorPosition() { | |
| 33 DCHECK(bubble_ui_); | |
| 34 bubble_ui_->UpdateAnchorPosition(); | |
| 35 } | |
| 36 | |
| 37 bool BubbleController::ShouldClose(BubbleCloseReason reason) { | |
| 38 DCHECK(bubble_ui_); | |
| 39 if (delegate_->ShouldClose(reason) || reason == BUBBLE_CLOSE_FORCED) { | |
| 40 bubble_ui_->Close(); | |
| 41 bubble_ui_.reset(); | |
| 42 // TODO(hcarmona): log that bubble was hidden. | |
| 43 return true; | |
| 44 } | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 base::WeakPtr<BubbleController> BubbleController::AsWeakPtr() { | |
| 49 return weak_ptr_factory_.GetWeakPtr(); | |
| 50 } | |
| OLD | NEW |