Port Android relocation packer to chromium build
[chromium-blink-merge.git] / ash / wm / overlay_event_filter.cc
blobb349bf99b621bf314e2e198a86c2a0b6281458b5
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/wm/overlay_event_filter.h"
7 #include "ui/aura/window.h"
8 #include "ui/aura/window_delegate.h"
9 #include "ui/events/event.h"
10 #include "ui/views/widget/widget.h"
12 namespace ash {
14 OverlayEventFilter::OverlayEventFilter()
15 : delegate_(NULL) {
18 OverlayEventFilter::~OverlayEventFilter() {
19 delegate_ = NULL;
22 void OverlayEventFilter::OnKeyEvent(ui::KeyEvent* event) {
23 if (!delegate_)
24 return;
26 // Do not consume a translated key event which is generated by an IME (e.g.,
27 // ui::VKEY_PROCESSKEY) since the key event is generated in response to a key
28 // press or release before showing the ovelay. This is important not to
29 // confuse key event handling JavaScript code in a page.
30 if (event->IsTranslated())
31 return;
33 if (delegate_ && delegate_->IsCancelingKeyEvent(event))
34 Cancel();
36 // Pass key events only when they are sent to a child of the delegate's
37 // window.
38 aura::Window* target = static_cast<aura::Window*>(event->target());
39 if (!delegate_ || !delegate_->GetWindow() ||
40 !delegate_->GetWindow()->Contains(target))
41 event->StopPropagation();
44 void OverlayEventFilter::OnLoginStateChanged(
45 user::LoginStatus status) {
46 Cancel();
49 void OverlayEventFilter::OnAppTerminating() {
50 Cancel();
53 void OverlayEventFilter::OnLockStateChanged(bool locked) {
54 Cancel();
57 void OverlayEventFilter::Activate(Delegate* delegate) {
58 if (delegate_)
59 delegate_->Cancel();
60 delegate_ = delegate;
63 void OverlayEventFilter::Deactivate(Delegate* delegate) {
64 if (delegate_ == delegate)
65 delegate_ = nullptr;
68 void OverlayEventFilter::Cancel() {
69 if (delegate_) {
70 delegate_->Cancel();
71 delegate_ = nullptr;
75 bool OverlayEventFilter::IsActive() {
76 return delegate_ != nullptr;
79 } // namespace ash