| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/tray/tray_bubble_wrapper.h" | 5 #include "ash/system/tray/tray_bubble_wrapper.h" |
| 6 | 6 |
| 7 #include "ash/system/tray/tray_background_view.h" | 7 #include "ash/system/tray/tray_background_view.h" |
| 8 #include "ash/system/tray/tray_event_filter.h" | 8 #include "ash/system/tray/tray_event_filter.h" |
| 9 #include "ash/wm/window_properties.h" | 9 #include "ash/wm/window_properties.h" |
| 10 #include "base/bind.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "base/time.h" |
| 10 #include "ui/views/bubble/tray_bubble_view.h" | 13 #include "ui/views/bubble/tray_bubble_view.h" |
| 11 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 12 | 15 |
| 13 namespace ash { | 16 namespace ash { |
| 14 namespace internal { | 17 namespace internal { |
| 15 | 18 |
| 16 TrayBubbleWrapper::TrayBubbleWrapper(TrayBackgroundView* tray, | 19 TrayBubbleWrapper::TrayBubbleWrapper(TrayBackgroundView* tray, |
| 17 views::TrayBubbleView* bubble_view) | 20 views::TrayBubbleView* bubble_view) |
| 18 : tray_(tray), | 21 : tray_(tray), |
| 19 bubble_view_(bubble_view) { | 22 bubble_view_(bubble_view) { |
| 23 DCHECK(tray_); |
| 20 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); | 24 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); |
| 21 bubble_widget_->AddObserver(this); | 25 bubble_widget_->AddObserver(this); |
| 22 bubble_widget_->GetNativeView()-> | 26 bubble_widget_->GetNativeView()-> |
| 23 SetProperty(internal::kStayInSameRootWindowKey, true); | 27 SetProperty(internal::kStayInSameRootWindowKey, true); |
| 24 | 28 |
| 25 tray_->InitializeBubbleAnimations(bubble_widget_); | 29 tray_->InitializeBubbleAnimations(bubble_widget_); |
| 26 tray_->UpdateBubbleViewArrow(bubble_view_); | 30 tray_->UpdateBubbleViewArrow(bubble_view_); |
| 27 bubble_view_->InitializeAndShowBubble(); | 31 bubble_view_->InitializeAndShowBubble(); |
| 28 | 32 |
| 29 tray->tray_event_filter()->AddWrapper(this); | 33 tray->tray_event_filter()->AddWrapper(this); |
| 30 } | 34 } |
| 31 | 35 |
| 32 TrayBubbleWrapper::~TrayBubbleWrapper() { | 36 TrayBubbleWrapper::~TrayBubbleWrapper() { |
| 33 tray_->tray_event_filter()->RemoveWrapper(this); | 37 tray_->tray_event_filter()->RemoveWrapper(this); |
| 34 if (bubble_widget_) { | 38 if (bubble_widget_) { |
| 35 bubble_widget_->RemoveObserver(this); | 39 bubble_widget_->RemoveObserver(this); |
| 36 bubble_widget_->Close(); | 40 bubble_widget_->Close(); |
| 37 } | 41 } |
| 38 } | 42 } |
| 39 | 43 |
| 40 void TrayBubbleWrapper::OnWidgetDestroying(views::Widget* widget) { | 44 void TrayBubbleWrapper::OnWidgetDestroying(views::Widget* widget) { |
| 41 CHECK_EQ(bubble_widget_, widget); | 45 CHECK_EQ(bubble_widget_, widget); |
| 42 bubble_widget_ = NULL; | 46 bubble_widget_ = NULL; |
| 43 tray_->HideBubbleWithView(bubble_view_); // May destroy |bubble_view_| | 47 |
| 48 // Do not call HideBubbleWithView directly but post the task to ensure that |
| 49 // HideBubbleWithView is called after the click event on the tray button is |
| 50 // handled. See crbug.com/177075 and crbug.com/169940 |
| 51 MessageLoopForUI::current()->PostTask( |
| 52 FROM_HERE, |
| 53 base::Bind(&TrayBubbleWrapper::HideBubbleWithView, AsWeakPtr())); |
| 54 } |
| 55 |
| 56 void TrayBubbleWrapper::HideBubbleWithView() { |
| 57 tray_->HideBubbleWithView(bubble_view_); |
| 44 } | 58 } |
| 45 | 59 |
| 46 } // namespace internal | 60 } // namespace internal |
| 47 } // namespace ash | 61 } // namespace ash |
| OLD | NEW |