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..9862fc7d87977854e8b241e4a9becdf28e2a77c2 |
| --- /dev/null |
| +++ b/components/bubble/bubble_controller.cc |
| @@ -0,0 +1,62 @@ |
| +// 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" |
| + |
| +BubbleController::BubbleController(scoped_ptr<BubbleDelegate> delegate) |
| + : delegate_(delegate.Pass()), bubble_ui_(nullptr), weak_ptr_factory_(this) { |
| + DCHECK(delegate_); |
| +} |
| + |
| +BubbleController::~BubbleController() {} |
| + |
| +void BubbleController::Show() { |
| + if (bubble_ui_) |
| + return; |
| + |
| + // TODO(hcarmona): log that bubble was shown. |
| + bubble_ui_ = delegate_->BuildBubbleUI(); |
| + |
| + DCHECK(bubble_ui_); |
| + bubble_ui_->Show(); |
| +} |
| + |
| +void BubbleController::Hide(BubbleCloseReason reason) { |
|
msw
2015/08/13 03:37:22
nit: reason isn't used.
hcarmona
2015/08/15 02:03:19
Acknowledged.
|
| + if (!bubble_ui_) |
|
msw
2015/08/13 03:37:22
nit: should we DCHECK against this?
hcarmona
2015/08/15 02:03:19
Done.
|
| + return; |
| + |
| + // TODO(hcarmona): log that bubble was hidden. |
| + bubble_ui_->Hide(); |
| + bubble_ui_.reset(); |
| +} |
| + |
| +void BubbleController::UpdateAnchorPosition() { |
| + DCHECK(bubble_ui_); |
| + bubble_ui_->UpdateAnchorPosition(); |
| +} |
| + |
| +bool BubbleController::ShouldUpdateBubble() { |
|
msw
2015/08/13 03:37:22
nit: const?
hcarmona
2015/08/15 02:03:19
Acknowledged.
|
| + if (!bubble_ui_) |
| + return true; // If UI isn't shown, then it can be udpated. |
|
msw
2015/08/13 03:37:22
nit: updated spelling
msw
2015/08/13 03:37:22
Can you elaborate a bit more, how can UI that isn'
hcarmona
2015/08/15 02:03:19
This is specific to the permission bubbles. May no
|
| + return bubble_ui_->CanAcceptUpdate(); |
| +} |
| + |
| +bool BubbleController::ShouldClose() const { |
| + return delegate_->ShouldCloseOnHide(); |
| +} |
| + |
| +void BubbleController::Close() { |
| + weak_ptr_factory_.InvalidateWeakPtrs(); |
|
msw
2015/08/13 03:37:22
Huh? Is this instance going to be torn down now or
hcarmona
2015/08/13 20:50:35
Permission bubbles want to show another bubble whe
msw
2015/08/13 21:41:37
The permission code should attempt to show another
hcarmona
2015/08/15 02:03:19
Moved this to the destructor. Still explicitly cal
|
| + delegate_->DidClose(); |
| +} |
| + |
| +bool BubbleController::MatchesContext(void* context) const { |
| + return delegate_->GetContext() == context; |
| +} |
| + |
| +base::WeakPtr<BubbleController> BubbleController::AsWeakPtr() { |
| + return weak_ptr_factory_.GetWeakPtr(); |
| +} |