Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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" |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 10 | #include "ui/events/event.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 11 | #include "ui/views/widget/widget.h" |
| 12 | |
| 13 | namespace ash { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 14 | |
| 15 | OverlayEventFilter::OverlayEventFilter() |
| 16 | : delegate_(NULL) { |
| 17 | } |
| 18 | |
| 19 | OverlayEventFilter::~OverlayEventFilter() { |
| 20 | delegate_ = NULL; |
| 21 | } |
| 22 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 23 | void OverlayEventFilter::OnKeyEvent(ui::KeyEvent* event) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 24 | if (!delegate_) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 25 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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. |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 31 | if (event->IsTranslated()) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 32 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 33 | |
| 34 | if (delegate_ && delegate_->IsCancelingKeyEvent(event)) |
| 35 | Cancel(); |
| 36 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 37 | // Pass key events only when they are sent to a child of the delegate's |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 38 | // window. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 39 | aura::Window* target = static_cast<aura::Window*>(event->target()); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 40 | if (!delegate_ || !delegate_->GetWindow() || |
| 41 | !delegate_->GetWindow()->Contains(target)) |
| 42 | event->StopPropagation(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void OverlayEventFilter::OnLoginStateChanged( |
| 46 | user::LoginStatus status) { |
| 47 | Cancel(); |
| 48 | } |
| 49 | |
| 50 | void OverlayEventFilter::OnAppTerminating() { |
| 51 | Cancel(); |
| 52 | } |
| 53 | |
| 54 | void OverlayEventFilter::OnLockStateChanged(bool locked) { |
| 55 | Cancel(); |
| 56 | } |
| 57 | |
| 58 | void OverlayEventFilter::Activate(Delegate* delegate) { |
| 59 | delegate_ = delegate; |
| 60 | } |
| 61 | |
| 62 | void OverlayEventFilter::Deactivate() { |
| 63 | delegate_ = NULL; |
| 64 | } |
| 65 | |
| 66 | void OverlayEventFilter::Cancel() { |
| 67 | if (delegate_) |
| 68 | delegate_->Cancel(); |
| 69 | } |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 70 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 71 | } // namespace ash |