Chromium Code Reviews| Index: components/bubble/bubble_controller.cc |
| diff --git a/components/bubble/bubble_controller.cc b/components/bubble/bubble_controller.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..22c4d053503ba8b389ec96f7b46c9c6cadacf592 |
| --- /dev/null |
| +++ b/components/bubble/bubble_controller.cc |
| @@ -0,0 +1,50 @@ |
| +// 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_controller.h" |
| + |
| +#include "components/bubble/bubble_delegate.h" |
| +#include "components/bubble/bubble_ui.h" |
| + |
| +BubbleController::BubbleController(scoped_ptr<BubbleDelegate> delegate) |
| + : 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.
|
| + DCHECK(delegate_); |
| +} |
| + |
| +BubbleController::~BubbleController() { |
| + // Necessary so that any BubbleReferences are cleaned up in case a |
| + // BubbleDelegate needs to chain showing bubbles when it's deleted. |
| + weak_ptr_factory_.InvalidateWeakPtrs(); |
| + |
| + if (bubble_ui_) |
| + ShouldClose(BUBBLE_CLOSE_FORCED); |
| +} |
| + |
| +void BubbleController::Show() { |
| + DCHECK(!bubble_ui_); |
| + bubble_ui_ = delegate_->BuildBubbleUI(); |
| + DCHECK(bubble_ui_); |
| + bubble_ui_->Show(); |
| + // TODO(hcarmona): log that bubble was shown. |
| +} |
| + |
| +void BubbleController::UpdateAnchorPosition() { |
| + DCHECK(bubble_ui_); |
| + bubble_ui_->UpdateAnchorPosition(); |
| +} |
| + |
| +bool BubbleController::ShouldClose(BubbleCloseReason reason) { |
| + DCHECK(bubble_ui_); |
| + if (delegate_->ShouldClose(reason) || reason == BUBBLE_CLOSE_FORCED) { |
| + bubble_ui_->Close(); |
| + bubble_ui_.reset(); |
| + // TODO(hcarmona): log that bubble was hidden. |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +base::WeakPtr<BubbleController> BubbleController::AsWeakPtr() { |
| + return weak_ptr_factory_.GetWeakPtr(); |
| +} |