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/wm/overlay_event_filter.h" 6 7#include "ash/wm/partial_screenshot_view.h" 8#include "ui/aura/window.h" 9#include "ui/aura/window_delegate.h" 10#include "ui/events/event.h" 11#include "ui/views/widget/widget.h" 12 13namespace ash { 14 15OverlayEventFilter::OverlayEventFilter() 16 : delegate_(NULL) { 17} 18 19OverlayEventFilter::~OverlayEventFilter() { 20 delegate_ = NULL; 21} 22 23void OverlayEventFilter::OnKeyEvent(ui::KeyEvent* event) { 24 if (!delegate_) 25 return; 26 27 // Do not consume a translated key event which is generated by an IME (e.g., 28 // ui::VKEY_PROCESSKEY) since the key event is generated in response to a key 29 // press or release before showing the ovelay. This is important not to 30 // confuse key event handling JavaScript code in a page. 31 if (event->IsTranslated()) 32 return; 33 34 if (delegate_ && delegate_->IsCancelingKeyEvent(event)) 35 Cancel(); 36 37 // Pass key events only when they are sent to a child of the delegate's 38 // window. 39 aura::Window* target = static_cast<aura::Window*>(event->target()); 40 if (!delegate_ || !delegate_->GetWindow() || 41 !delegate_->GetWindow()->Contains(target)) 42 event->StopPropagation(); 43} 44 45void OverlayEventFilter::OnLoginStateChanged( 46 user::LoginStatus status) { 47 Cancel(); 48} 49 50void OverlayEventFilter::OnAppTerminating() { 51 Cancel(); 52} 53 54void OverlayEventFilter::OnLockStateChanged(bool locked) { 55 Cancel(); 56} 57 58void OverlayEventFilter::Activate(Delegate* delegate) { 59 if (delegate_) 60 delegate_->Cancel(); 61 delegate_ = delegate; 62} 63 64void OverlayEventFilter::Deactivate(Delegate* delegate) { 65 if (delegate_ == delegate) 66 delegate_ = NULL; 67} 68 69void OverlayEventFilter::Cancel() { 70 if (delegate_) 71 delegate_->Cancel(); 72} 73 74bool OverlayEventFilter::IsActive() { 75 return delegate_ != NULL; 76} 77 78} // namespace ash 79