blob: 5f982b5ded354fce6028c7668d172587e4ab7281 [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/event_rewriter_event_filter.h"
#include "ash/event_rewriter_delegate.h"
#include "base/logging.h"
#include "ui/aura/event.h"
namespace ash {
namespace internal {
EventRewriterEventFilter::EventRewriterEventFilter() {}
EventRewriterEventFilter::~EventRewriterEventFilter() {}
void EventRewriterEventFilter::SetEventRewriterDelegate(
scoped_ptr<EventRewriterDelegate> delegate) {
delegate_.swap(delegate);
}
bool EventRewriterEventFilter::PreHandleKeyEvent(
aura::Window* target, aura::KeyEvent* event) {
if (!delegate_.get())
return false;
// Do not consume a translated key event which is generated by an IME.
if (event->type() == ui::ET_TRANSLATED_KEY_PRESS ||
event->type() == ui::ET_TRANSLATED_KEY_RELEASE) {
return false;
}
switch (delegate_->RewriteOrFilterKeyEvent(event)) {
case EventRewriterDelegate::ACTION_REWRITE_EVENT:
return false;
case EventRewriterDelegate::ACTION_DROP_EVENT:
return true;
}
NOTREACHED();
return false;
}
bool EventRewriterEventFilter::PreHandleMouseEvent(
aura::Window* target, aura::MouseEvent* event) {
if (!delegate_.get())
return false;
switch (delegate_->RewriteOrFilterLocatedEvent(event)) {
case EventRewriterDelegate::ACTION_REWRITE_EVENT:
return false;
case EventRewriterDelegate::ACTION_DROP_EVENT:
return true;
}
NOTREACHED();
return false;
}
ui::TouchStatus EventRewriterEventFilter::PreHandleTouchEvent(
aura::Window* target, aura::TouchEvent* event) {
return ui::TOUCH_STATUS_UNKNOWN; // Not handled.
}
ui::GestureStatus EventRewriterEventFilter::PreHandleGestureEvent(
aura::Window* target, aura::GestureEvent* event) {
return ui::GESTURE_STATUS_UNKNOWN; // Not handled.
}
} // namespace internal
} // namespace ash