Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / system / tray / tray_bubble_wrapper.cc
blob3576f6c033e04e1bae915d89a268c4f7dae15074
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.
5 #include "ash/system/tray/tray_bubble_wrapper.h"
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/aura/window_event_dispatcher.h"
13 #include "ui/views/bubble/tray_bubble_view.h"
14 #include "ui/views/widget/widget.h"
16 namespace ash {
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);
25 tray_->InitializeBubbleAnimations(bubble_widget_);
26 tray_->UpdateBubbleViewArrow(bubble_view_);
27 bubble_view_->InitializeAndShowBubble();
29 tray->tray_event_filter()->AddWrapper(this);
32 TrayBubbleWrapper::~TrayBubbleWrapper() {
33 tray_->tray_event_filter()->RemoveWrapper(this);
34 if (bubble_widget_) {
35 bubble_widget_->RemoveObserver(this);
36 bubble_widget_->Close();
40 void TrayBubbleWrapper::OnWidgetDestroying(views::Widget* widget) {
41 CHECK_EQ(bubble_widget_, widget);
42 bubble_widget_->RemoveObserver(this);
43 bubble_widget_ = NULL;
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_|
56 void TrayBubbleWrapper::OnWidgetBoundsChanged(views::Widget* widget,
57 const gfx::Rect& new_bounds) {
58 DCHECK_EQ(bubble_widget_, widget);
59 tray_->BubbleResized(bubble_view_);
62 } // namespace ash