Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ash / wm / overlay_event_filter.cc
blob2319d2fca27b6ddc07e3d0d36ed7db70e7080da5
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 "ash/wm/partial_screenshot_view.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_delegate.h"
10 #include "ui/base/events/event.h"
11 #include "ui/views/widget/widget.h"
13 namespace ash {
14 namespace internal {
16 OverlayEventFilter::OverlayEventFilter()
17 : delegate_(NULL) {
20 OverlayEventFilter::~OverlayEventFilter() {
21 delegate_ = NULL;
24 void OverlayEventFilter::OnKeyEvent(ui::KeyEvent* event) {
25 if (!delegate_)
26 return;
28 // Do not consume a translated key event which is generated by an IME (e.g.,
29 // ui::VKEY_PROCESSKEY) since the key event is generated in response to a key
30 // press or release before showing the ovelay. This is important not to
31 // confuse key event handling JavaScript code in a page.
32 if (event->type() == ui::ET_TRANSLATED_KEY_PRESS ||
33 event->type() == ui::ET_TRANSLATED_KEY_RELEASE) {
34 return;
37 if (delegate_ && delegate_->IsCancelingKeyEvent(event))
38 Cancel();
40 // Handle key events only when they are sent to a child of the delegate's
41 // window.
42 aura::Window* target = static_cast<aura::Window*>(event->target());
43 if (delegate_ && delegate_->GetWindow() &&
44 delegate_->GetWindow()->Contains(target))
45 target->delegate()->OnKeyEvent(event);
47 // Always handled: other windows shouldn't receive input while we're
48 // displaying an overlay.
49 event->StopPropagation();
52 void OverlayEventFilter::OnLoginStateChanged(
53 user::LoginStatus status) {
54 Cancel();
57 void OverlayEventFilter::OnAppTerminating() {
58 Cancel();
61 void OverlayEventFilter::OnLockStateChanged(bool locked) {
62 Cancel();
65 void OverlayEventFilter::Activate(Delegate* delegate) {
66 delegate_ = delegate;
69 void OverlayEventFilter::Deactivate() {
70 delegate_ = NULL;
73 void OverlayEventFilter::Cancel() {
74 if (delegate_)
75 delegate_->Cancel();
77 } // namespace internal
78 } // namespace ash