blob: f575fe455dab19c4a9b1a74847a5fcda352778d1 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/overlay_event_filter.h"
#include "ash/wm/partial_screenshot_view.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace internal {
OverlayEventFilter::OverlayEventFilter()
: delegate_(NULL) {
}
OverlayEventFilter::~OverlayEventFilter() {
delegate_ = NULL;
}
bool OverlayEventFilter::PreHandleKeyEvent(
aura::Window* target, aura::KeyEvent* event) {
if (!delegate_)
return false;
// Do not consume a translated key event which is generated by an IME (e.g.,
// ui::VKEY_PROCESSKEY) since the key event is generated in response to a key
// press or release before showing the ovelay. This is important not to
// confuse key event handling JavaScript code in a page.
if (event->type() == ui::ET_TRANSLATED_KEY_PRESS ||
event->type() == ui::ET_TRANSLATED_KEY_RELEASE) {
return false;
}
if (delegate_ && delegate_->IsCancelingKeyEvent(event))
Cancel();
// Handle key events only when they are sent to a child of the delegate's
// window.
if (delegate_ && delegate_->GetWindow()->Contains(target))
target->delegate()->OnKeyEvent(event);
// Always handled: other windows shouldn't receive input while we're
// displaying an overlay.
return true;
}
bool OverlayEventFilter::PreHandleMouseEvent(
aura::Window* target, aura::MouseEvent* event) {
if (delegate_) {
DCHECK_EQ(target, delegate_->GetWindow());
target->delegate()->OnMouseEvent(event);
return true;
}
return false; // Not handled.
}
ui::TouchStatus OverlayEventFilter::PreHandleTouchEvent(
aura::Window* target, aura::TouchEvent* event) {
return ui::TOUCH_STATUS_UNKNOWN; // Not handled.
}
ui::GestureStatus OverlayEventFilter::PreHandleGestureEvent(
aura::Window* target, aura::GestureEvent* event) {
return ui::GESTURE_STATUS_UNKNOWN; // Not handled.
}
void OverlayEventFilter::OnLoginStateChanged(
user::LoginStatus status) {
Cancel();
}
void OverlayEventFilter::OnAppTerminating() {
Cancel();
}
void OverlayEventFilter::OnLockStateChanged(bool locked) {
Cancel();
}
void OverlayEventFilter::Activate(Delegate* delegate) {
delegate_ = delegate;
}
void OverlayEventFilter::Deactivate() {
delegate_ = NULL;
}
void OverlayEventFilter::Cancel() {
if (delegate_)
delegate_->Cancel();
}
} // namespace internal
} // namespace ash