| Index: ui/views/bubble/bubble_delegate.cc
|
| diff --git a/ui/views/bubble/bubble_delegate.cc b/ui/views/bubble/bubble_delegate.cc
|
| index fd922e4454789415611675a7d815c0b526a4b727..85204745ba1e5682634c8ddd2916e8a88ea0d20b 100644
|
| --- a/ui/views/bubble/bubble_delegate.cc
|
| +++ b/ui/views/bubble/bubble_delegate.cc
|
| @@ -52,7 +52,13 @@ Widget* CreateBubbleWidget(BubbleDelegateView* bubble) {
|
| const char BubbleDelegateView::kViewClassName[] = "BubbleDelegateView";
|
|
|
| BubbleDelegateView::BubbleDelegateView()
|
| - : BubbleDelegateView(nullptr, BubbleBorder::TOP_LEFT) {}
|
| + : BubbleDelegateView(static_cast<View*>(nullptr), BubbleBorder::TOP_LEFT) {}
|
| +
|
| +BubbleDelegateView::BubbleDelegateView(WidgetObserverView* anchor_view,
|
| + BubbleBorder::Arrow arrow)
|
| + : BubbleDelegateView(static_cast<View*>(anchor_view), arrow) {
|
| + anchor_view_has_widget_observer_ = true;
|
| +}
|
|
|
| BubbleDelegateView::BubbleDelegateView(View* anchor_view,
|
| BubbleBorder::Arrow arrow)
|
| @@ -60,6 +66,7 @@ BubbleDelegateView::BubbleDelegateView(View* anchor_view,
|
| close_on_deactivate_(true),
|
| anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()),
|
| anchor_widget_(NULL),
|
| + anchor_view_has_widget_observer_(false),
|
| arrow_(arrow),
|
| shadow_(BubbleBorder::SMALL_SHADOW),
|
| color_explicitly_set_(false),
|
| @@ -76,8 +83,16 @@ BubbleDelegateView::BubbleDelegateView(View* anchor_view,
|
| }
|
|
|
| BubbleDelegateView::~BubbleDelegateView() {
|
| - if (GetWidget())
|
| + if (GetWidget()) {
|
| GetWidget()->RemoveObserver(this);
|
| + if (anchor_view_has_widget_observer_) {
|
| + View* anchor_view = GetAnchorView();
|
| + if (anchor_view) {
|
| + GetWidget()->RemoveObserver(
|
| + static_cast<WidgetObserverView*>(anchor_view));
|
| + }
|
| + }
|
| + }
|
| SetLayoutManager(NULL);
|
| SetAnchorView(NULL);
|
| }
|
| @@ -86,7 +101,8 @@ BubbleDelegateView::~BubbleDelegateView() {
|
| Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) {
|
| bubble_delegate->Init();
|
| // Get the latest anchor widget from the anchor view at bubble creation time.
|
| - bubble_delegate->SetAnchorView(bubble_delegate->GetAnchorView());
|
| + View* anchor_view = bubble_delegate->GetAnchorView();
|
| + bubble_delegate->SetAnchorView(anchor_view);
|
| Widget* bubble_widget = CreateBubbleWidget(bubble_delegate);
|
|
|
| #if defined(OS_WIN)
|
| @@ -102,6 +118,8 @@ Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) {
|
|
|
| bubble_delegate->SizeToContents();
|
| bubble_widget->AddObserver(bubble_delegate);
|
| + if (bubble_delegate->anchor_view_has_widget_observer_)
|
| + bubble_widget->AddObserver(static_cast<WidgetObserverView*>(anchor_view));
|
| return bubble_widget;
|
| }
|
|
|
| @@ -232,6 +250,9 @@ void BubbleDelegateView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
|
| void BubbleDelegateView::Init() {}
|
|
|
| void BubbleDelegateView::SetAnchorView(View* anchor_view) {
|
| + View* previous_anchor_view = GetAnchorView();
|
| + if (anchor_view == previous_anchor_view)
|
| + return;
|
| // When the anchor view gets set the associated anchor widget might
|
| // change as well.
|
| if (!anchor_view || anchor_widget() != anchor_view->GetWidget()) {
|
| @@ -248,8 +269,14 @@ void BubbleDelegateView::SetAnchorView(View* anchor_view) {
|
|
|
| // Remove the old storage item and set the new (if there is one).
|
| ViewStorage* view_storage = ViewStorage::GetInstance();
|
| - if (view_storage->RetrieveView(anchor_view_storage_id_))
|
| + if (previous_anchor_view) {
|
| + if (anchor_view_has_widget_observer_ && GetWidget()) {
|
| + GetWidget()->RemoveObserver(
|
| + static_cast<WidgetObserverView*>(previous_anchor_view));
|
| + }
|
| + anchor_view_has_widget_observer_ = false;
|
| view_storage->RemoveView(anchor_view_storage_id_);
|
| + }
|
| if (anchor_view)
|
| view_storage->StoreView(anchor_view_storage_id_, anchor_view);
|
|
|
|
|