Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / wm / overlay_event_filter.cc
blob2e1c998370e3aa0e818bd3f7f2ebedbcdc7e1e27
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/events/event.h"
11 #include "ui/views/widget/widget.h"
13 namespace ash {
15 OverlayEventFilter::OverlayEventFilter()
16 : delegate_(NULL) {
19 OverlayEventFilter::~OverlayEventFilter() {
20 delegate_ = NULL;
23 void OverlayEventFilter::OnKeyEvent(ui::KeyEvent* event) {
24 if (!delegate_)
25 return;
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.
31 if (event->IsTranslated())
32 return;
34 if (delegate_ && delegate_->IsCancelingKeyEvent(event))
35 Cancel();
37 // Pass key events only when they are sent to a child of the delegate's
38 // window.
39 aura::Window* target = static_cast<aura::Window*>(event->target());
40 if (!delegate_ || !delegate_->GetWindow() ||
41 !delegate_->GetWindow()->Contains(target))
42 event->StopPropagation();
45 void OverlayEventFilter::OnLoginStateChanged(
46 user::LoginStatus status) {
47 Cancel();
50 void OverlayEventFilter::OnAppTerminating() {
51 Cancel();
54 void OverlayEventFilter::OnLockStateChanged(bool locked) {
55 Cancel();
58 void OverlayEventFilter::Activate(Delegate* delegate) {
59 if (delegate_)
60 delegate_->Cancel();
61 delegate_ = delegate;
64 void OverlayEventFilter::Deactivate(Delegate* delegate) {
65 if (delegate_ == delegate)
66 delegate_ = NULL;
69 void OverlayEventFilter::Cancel() {
70 if (delegate_)
71 delegate_->Cancel();
74 bool OverlayEventFilter::IsActive() {
75 return delegate_ != NULL;
78 } // namespace ash