15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/tray_bubble_wrapper.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/tray_background_view.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/tray_event_filter.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/window_properties.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/client/capture_client.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/window.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/bubble/tray_bubble_view.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash { 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TrayBubbleWrapper::TrayBubbleWrapper(TrayBackgroundView* tray, 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::TrayBubbleView* bubble_view) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : tray_(tray), 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_view_(bubble_view) { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_widget_->AddObserver(this); 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tray_->InitializeBubbleAnimations(bubble_widget_); 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tray_->UpdateBubbleViewArrow(bubble_view_); 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_view_->InitializeAndShowBubble(); 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) tray->tray_event_filter()->AddWrapper(this); 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TrayBubbleWrapper::~TrayBubbleWrapper() { 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) tray_->tray_event_filter()->RemoveWrapper(this); 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (bubble_widget_) { 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_widget_->RemoveObserver(this); 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_widget_->Close(); 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TrayBubbleWrapper::OnWidgetDestroying(views::Widget* widget) { 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK_EQ(bubble_widget_, widget); 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bubble_widget_->RemoveObserver(this); 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bubble_widget_ = NULL; 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Although the bubble is already closed, the next mouse release event 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // will invoke PerformAction which reopens the bubble again. To prevent the 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // reopen, the mouse capture of |tray_| has to be released. 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // See crbug.com/177075 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::CaptureClient* capture_client = aura::client::GetCaptureClient( 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) tray_->GetWidget()->GetNativeView()->GetRootWindow()); 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (capture_client) 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) capture_client->ReleaseCapture(tray_->GetWidget()->GetNativeView()); 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tray_->HideBubbleWithView(bubble_view_); // May destroy |bubble_view_| 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 56d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void TrayBubbleWrapper::OnWidgetBoundsChanged(views::Widget* widget, 57d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const gfx::Rect& new_bounds) { 58d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) DCHECK_EQ(bubble_widget_, widget); 59d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) tray_->BubbleResized(bubble_view_); 60d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 61d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ash 63