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