Home | History | Annotate | Download | only in tray
      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/window.h"
     12 #include "ui/views/bubble/tray_bubble_view.h"
     13 #include "ui/views/widget/widget.h"
     14 
     15 namespace ash {
     16 namespace internal {
     17 
     18 TrayBubbleWrapper::TrayBubbleWrapper(TrayBackgroundView* tray,
     19                                      views::TrayBubbleView* bubble_view)
     20     : tray_(tray),
     21       bubble_view_(bubble_view) {
     22   bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_);
     23   bubble_widget_->AddObserver(this);
     24 
     25   tray_->InitializeBubbleAnimations(bubble_widget_);
     26   tray_->UpdateBubbleViewArrow(bubble_view_);
     27   bubble_view_->InitializeAndShowBubble();
     28 
     29   tray->tray_event_filter()->AddWrapper(this);
     30 }
     31 
     32 TrayBubbleWrapper::~TrayBubbleWrapper() {
     33   tray_->tray_event_filter()->RemoveWrapper(this);
     34   if (bubble_widget_) {
     35     bubble_widget_->RemoveObserver(this);
     36     bubble_widget_->Close();
     37   }
     38 }
     39 
     40 void TrayBubbleWrapper::OnWidgetDestroying(views::Widget* widget) {
     41   CHECK_EQ(bubble_widget_, widget);
     42   bubble_widget_->RemoveObserver(this);
     43   bubble_widget_ = NULL;
     44 
     45   // Although the bubble is already closed, the next mouse release event
     46   // will invoke PerformAction which reopens the bubble again. To prevent the
     47   // reopen, the mouse capture of |tray_| has to be released.
     48   // See crbug.com/177075
     49   aura::client::CaptureClient* capture_client = aura::client::GetCaptureClient(
     50       tray_->GetWidget()->GetNativeView()->GetRootWindow());
     51   if (capture_client)
     52     capture_client->ReleaseCapture(tray_->GetWidget()->GetNativeView());
     53   tray_->HideBubbleWithView(bubble_view_);  // May destroy |bubble_view_|
     54 }
     55 
     56 }  // namespace internal
     57 }  // namespace ash
     58