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 3 // found in the LICENSE file. 4 5 #include "ash/system/tray/tray_bubble_wrapper.h" 6 7 #include "ash/system/tray/tray_background_view.h" 8 #include "ash/system/tray/tray_event_filter.h" 9 #include "ash/wm/window_properties.h" 10 #include "ui/aura/client/capture_client.h" 11 #include "ui/aura/root_window.h" 12 #include "ui/aura/window.h" 13 #include "ui/views/bubble/tray_bubble_view.h" 14 #include "ui/views/widget/widget.h" 15 16 namespace ash { 17 namespace internal { 18 19 TrayBubbleWrapper::TrayBubbleWrapper(TrayBackgroundView* tray, 20 views::TrayBubbleView* bubble_view) 21 : tray_(tray), 22 bubble_view_(bubble_view) { 23 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); 24 bubble_widget_->AddObserver(this); 25 26 tray_->InitializeBubbleAnimations(bubble_widget_); 27 tray_->UpdateBubbleViewArrow(bubble_view_); 28 bubble_view_->InitializeAndShowBubble(); 29 30 tray->tray_event_filter()->AddWrapper(this); 31 } 32 33 TrayBubbleWrapper::~TrayBubbleWrapper() { 34 tray_->tray_event_filter()->RemoveWrapper(this); 35 if (bubble_widget_) { 36 bubble_widget_->RemoveObserver(this); 37 bubble_widget_->Close(); 38 } 39 } 40 41 void TrayBubbleWrapper::OnWidgetDestroying(views::Widget* widget) { 42 CHECK_EQ(bubble_widget_, widget); 43 bubble_widget_->RemoveObserver(this); 44 bubble_widget_ = NULL; 45 46 // Although the bubble is already closed, the next mouse release event 47 // will invoke PerformAction which reopens the bubble again. To prevent the 48 // reopen, the mouse capture of |tray_| has to be released. 49 // See crbug.com/177075 50 aura::client::CaptureClient* capture_client = aura::client::GetCaptureClient( 51 tray_->GetWidget()->GetNativeView()->GetRootWindow()); 52 if (capture_client) 53 capture_client->ReleaseCapture(tray_->GetWidget()->GetNativeView()); 54 tray_->HideBubbleWithView(bubble_view_); // May destroy |bubble_view_| 55 } 56 57 void TrayBubbleWrapper::OnWidgetBoundsChanged(views::Widget* widget, 58 const gfx::Rect& new_bounds) { 59 DCHECK_EQ(bubble_widget_, widget); 60 tray_->BubbleResized(bubble_view_); 61 } 62 63 } // namespace internal 64 } // namespace ash 65