Home | History | Annotate | Download | only in wm
      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 
     15 OverlayEventFilter::OverlayEventFilter()
     16     : delegate_(NULL) {
     17 }
     18 
     19 OverlayEventFilter::~OverlayEventFilter() {
     20   delegate_ = NULL;
     21 }
     22 
     23 void OverlayEventFilter::OnKeyEvent(ui::KeyEvent* event) {
     24   if (!delegate_)
     25     return;
     26 
     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;
     33 
     34   if (delegate_ && delegate_->IsCancelingKeyEvent(event))
     35     Cancel();
     36 
     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();
     43 }
     44 
     45 void OverlayEventFilter::OnLoginStateChanged(
     46     user::LoginStatus status) {
     47   Cancel();
     48 }
     49 
     50 void OverlayEventFilter::OnAppTerminating() {
     51   Cancel();
     52 }
     53 
     54 void OverlayEventFilter::OnLockStateChanged(bool locked) {
     55   Cancel();
     56 }
     57 
     58 void OverlayEventFilter::Activate(Delegate* delegate) {
     59   if (delegate_)
     60     delegate_->Cancel();
     61   delegate_ = delegate;
     62 }
     63 
     64 void OverlayEventFilter::Deactivate(Delegate* delegate) {
     65   if (delegate_ == delegate)
     66     delegate_ = NULL;
     67 }
     68 
     69 void OverlayEventFilter::Cancel() {
     70   if (delegate_)
     71     delegate_->Cancel();
     72 }
     73 
     74 bool OverlayEventFilter::IsActive() {
     75   return delegate_ != NULL;
     76 }
     77 
     78 }  // namespace ash
     79