Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 | #ifndef ASH_WM_OVERLAY_EVENT_FILTER_H_ |
| 6 | #define ASH_WM_OVERLAY_EVENT_FILTER_H_ |
| 7 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 8 | #include "ash/ash_export.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 9 | #include "ash/shell_observer.h" |
| 10 | #include "base/compiler_specific.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 11 | #include "ui/aura/window.h" |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 12 | #include "ui/events/event_handler.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | |
| 14 | namespace ash { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 15 | |
| 16 | // EventFilter for the "overlay window", which intercepts events before they are |
| 17 | // processed by the usual path (e.g. the partial screenshot UI, the keyboard |
| 18 | // overlay). It does nothing the first time, but works when |Activate()| is |
| 19 | // called. The main task of this event filter is just to stop propagation |
| 20 | // of any key events during activation, and also signal cancellation when keys |
| 21 | // for canceling are pressed. |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 22 | class ASH_EXPORT OverlayEventFilter : public ui::EventHandler, |
| 23 | public ShellObserver { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 24 | public: |
| 25 | // Windows that need to receive events from OverlayEventFilter implement this. |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 26 | class ASH_EXPORT Delegate { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 27 | public: |
| 28 | // Invoked when OverlayEventFilter needs to stop handling events. |
| 29 | virtual void Cancel() = 0; |
| 30 | |
| 31 | // Returns true if the overlay should be canceled in response to |event|. |
| 32 | virtual bool IsCancelingKeyEvent(ui::KeyEvent* event) = 0; |
| 33 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 34 | // Returns the window that needs to receive events. NULL if no window needs |
| 35 | // to receive key events from OverlayEventFilter. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 36 | virtual aura::Window* GetWindow() = 0; |
| 37 | }; |
| 38 | |
| 39 | OverlayEventFilter(); |
| 40 | virtual ~OverlayEventFilter(); |
| 41 | |
| 42 | // Starts the filtering of events. It also notifies the specified |
| 43 | // |delegate| when a key event means cancel (like Esc). It holds the |
| 44 | // pointer to the specified |delegate| until Deactivate() is called, but |
| 45 | // does not take ownership. |
| 46 | void Activate(Delegate* delegate); |
| 47 | |
| 48 | // Ends the filtering of events. |
| 49 | void Deactivate(); |
| 50 | |
| 51 | // Cancels the partial screenshot UI. Do nothing if it's not activated. |
| 52 | void Cancel(); |
| 53 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 54 | // ui::EventHandler overrides: |
| 55 | virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 56 | |
| 57 | // ShellObserver overrides: |
| 58 | virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; |
| 59 | virtual void OnAppTerminating() OVERRIDE; |
| 60 | virtual void OnLockStateChanged(bool locked) OVERRIDE; |
| 61 | |
| 62 | private: |
| 63 | Delegate* delegate_; |
| 64 | |
| 65 | DISALLOW_COPY_AND_ASSIGN(OverlayEventFilter); |
| 66 | }; |
| 67 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 68 | } // namespace ash |
| 69 | |
| 70 | #endif // ASH_WM_OVERLAY_EVENT_FILTER_H_ |