- add sources.
[platform/framework/web/crosswalk.git] / src / ash / wm / overlay_event_filter.cc
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
13 namespace ash {
14 namespace internal {
15
16 OverlayEventFilter::OverlayEventFilter()
17     : delegate_(NULL) {
18 }
19
20 OverlayEventFilter::~OverlayEventFilter() {
21   delegate_ = NULL;
22 }
23
24 void OverlayEventFilter::OnKeyEvent(ui::KeyEvent* event) {
25   if (!delegate_)
26     return;
27
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;
35   }
36
37   if (delegate_ && delegate_->IsCancelingKeyEvent(event))
38     Cancel();
39
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);
46
47   // Always handled: other windows shouldn't receive input while we're
48   // displaying an overlay.
49   event->StopPropagation();
50 }
51
52 void OverlayEventFilter::OnLoginStateChanged(
53     user::LoginStatus status) {
54   Cancel();
55 }
56
57 void OverlayEventFilter::OnAppTerminating() {
58   Cancel();
59 }
60
61 void OverlayEventFilter::OnLockStateChanged(bool locked) {
62   Cancel();
63 }
64
65 void OverlayEventFilter::Activate(Delegate* delegate) {
66   delegate_ = delegate;
67 }
68
69 void OverlayEventFilter::Deactivate() {
70   delegate_ = NULL;
71 }
72
73 void OverlayEventFilter::Cancel() {
74   if (delegate_)
75     delegate_->Cancel();
76 }
77 }  // namespace internal
78 }  // namespace ash