blob: cd5a487650aa9f5ab6a2d0b95162626f0a99cb00 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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"
Torne (Richard Coles)d0247b12013-09-19 22:36:51 +010010#include "ui/events/event.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000011#include "ui/views/widget/widget.h"
12
13namespace ash {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000014
15OverlayEventFilter::OverlayEventFilter()
16 : delegate_(NULL) {
17}
18
19OverlayEventFilter::~OverlayEventFilter() {
20 delegate_ = NULL;
21}
22
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000023void OverlayEventFilter::OnKeyEvent(ui::KeyEvent* event) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000024 if (!delegate_)
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000025 return;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000026
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.
Torne (Richard Coles)cedac222014-06-03 10:58:34 +010031 if (event->IsTranslated())
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000032 return;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000033
34 if (delegate_ && delegate_->IsCancelingKeyEvent(event))
35 Cancel();
36
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000037 // Pass key events only when they are sent to a child of the delegate's
Torne (Richard Coles)58218062012-11-14 11:43:16 +000038 // window.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000039 aura::Window* target = static_cast<aura::Window*>(event->target());
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000040 if (!delegate_ || !delegate_->GetWindow() ||
41 !delegate_->GetWindow()->Contains(target))
42 event->StopPropagation();
Torne (Richard Coles)58218062012-11-14 11:43:16 +000043}
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 delegate_ = delegate;
60}
61
62void OverlayEventFilter::Deactivate() {
63 delegate_ = NULL;
64}
65
66void OverlayEventFilter::Cancel() {
67 if (delegate_)
68 delegate_->Cancel();
69}
Ben Murdochc5cede92014-04-10 11:22:14 +010070
Torne (Richard Coles)58218062012-11-14 11:43:16 +000071} // namespace ash