OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/overlay_event_filter.h" | 5 #include "ash/wm/overlay_event_filter.h" |
6 | 6 |
7 #include "ui/aura/window.h" | 7 #include "ui/aura/window.h" |
8 #include "ui/aura/window_delegate.h" | 8 #include "ui/aura/window_delegate.h" |
9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
10 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
11 | 11 |
12 namespace ash { | 12 namespace ash { |
13 | 13 |
14 OverlayEventFilter::OverlayEventFilter() | 14 OverlayEventFilter::OverlayEventFilter() |
15 : delegate_(NULL) { | 15 : delegate_(NULL) { |
16 } | 16 } |
17 | 17 |
18 OverlayEventFilter::~OverlayEventFilter() { | 18 OverlayEventFilter::~OverlayEventFilter() { |
19 delegate_ = NULL; | 19 delegate_ = NULL; |
20 } | 20 } |
21 | 21 |
22 void OverlayEventFilter::OnKeyEvent(ui::KeyEvent* event) { | 22 void OverlayEventFilter::OnKeyEvent(ui::KeyEvent* event) { |
23 if (!delegate_) | 23 if (!delegate_) |
24 return; | 24 return; |
25 | 25 |
26 // Do not consume a translated key event which is generated by an IME (e.g., | |
27 // ui::VKEY_PROCESSKEY) since the key event is generated in response to a key | |
28 // press or release before showing the ovelay. This is important not to | |
29 // confuse key event handling JavaScript code in a page. | |
30 if (event->IsTranslated()) | |
31 return; | |
32 | |
33 if (delegate_ && delegate_->IsCancelingKeyEvent(event)) | 26 if (delegate_ && delegate_->IsCancelingKeyEvent(event)) |
34 Cancel(); | 27 Cancel(); |
35 | 28 |
36 // Pass key events only when they are sent to a child of the delegate's | 29 // Pass key events only when they are sent to a child of the delegate's |
37 // window. | 30 // window. |
38 aura::Window* target = static_cast<aura::Window*>(event->target()); | 31 aura::Window* target = static_cast<aura::Window*>(event->target()); |
39 if (!delegate_ || !delegate_->GetWindow() || | 32 if (!delegate_ || !delegate_->GetWindow() || |
40 !delegate_->GetWindow()->Contains(target)) | 33 !delegate_->GetWindow()->Contains(target)) |
41 event->StopPropagation(); | 34 event->StopPropagation(); |
42 } | 35 } |
(...skipping 27 matching lines...) Expand all Loading... |
70 delegate_->Cancel(); | 63 delegate_->Cancel(); |
71 delegate_ = nullptr; | 64 delegate_ = nullptr; |
72 } | 65 } |
73 } | 66 } |
74 | 67 |
75 bool OverlayEventFilter::IsActive() { | 68 bool OverlayEventFilter::IsActive() { |
76 return delegate_ != nullptr; | 69 return delegate_ != nullptr; |
77 } | 70 } |
78 | 71 |
79 } // namespace ash | 72 } // namespace ash |
OLD | NEW |