Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: ash/wm/overlay_event_filter.cc

Issue 10825026: Make accelerators not to work when the keyboard overlay is shown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/partial_screenshot_event_filter.h" 5 #include "ash/wm/overlay_event_filter.h"
6 6
7 #include "ash/wm/partial_screenshot_view.h" 7 #include "ash/wm/partial_screenshot_view.h"
8 #include "ui/aura/window.h" 8 #include "ui/aura/window.h"
9 #include "ui/aura/window_delegate.h" 9 #include "ui/aura/window_delegate.h"
10 #include "ui/views/widget/widget.h" 10 #include "ui/views/widget/widget.h"
11 11
12 namespace ash { 12 namespace ash {
13 namespace internal { 13 namespace internal {
14 14
15 PartialScreenshotEventFilter::PartialScreenshotEventFilter() 15 OverlayEventFilter::OverlayEventFilter()
16 : view_(NULL) { 16 : delegate_(NULL) {
17 } 17 }
18 18
19 PartialScreenshotEventFilter::~PartialScreenshotEventFilter() { 19 OverlayEventFilter::~OverlayEventFilter() {
20 view_ = NULL; 20 delegate_ = NULL;
21 } 21 }
22 22
23 bool PartialScreenshotEventFilter::PreHandleKeyEvent( 23 bool OverlayEventFilter::PreHandleKeyEvent(
24 aura::Window* target, aura::KeyEvent* event) { 24 aura::Window* target, aura::KeyEvent* event) {
25 if (!view_) 25 if (!delegate_)
26 return false; 26 return false;
27 27
28 // Do not consume a translated key event which is generated by an IME (e.g., 28 // Do not consume a translated key event which is generated by an IME (e.g.,
29 // ui::VKEY_PROCESSKEY) since the key event is generated in response to a key 29 // ui::VKEY_PROCESSKEY) since the key event is generated in response to a key
30 // press or release before showing the screenshot view. This is important not 30 // press or release before showing the screenshot view. This is important not
Daniel Erat 2012/07/26 01:52:51 nit: s/screenshot view/overlay/
mazda 2012/07/26 02:09:08 Done.
31 // to confuse key event handling JavaScript code in a page. 31 // to confuse key event handling JavaScript code in a page.
32 if (event->type() == ui::ET_TRANSLATED_KEY_PRESS || 32 if (event->type() == ui::ET_TRANSLATED_KEY_PRESS ||
33 event->type() == ui::ET_TRANSLATED_KEY_RELEASE) { 33 event->type() == ui::ET_TRANSLATED_KEY_RELEASE) {
34 return false; 34 return false;
35 } 35 }
36 36
37 if (event->key_code() == ui::VKEY_ESCAPE) 37 if (delegate_ && delegate_->IsCancelingKeyEvent(event))
38 Cancel(); 38 Cancel();
39 39
40 // Handle key events only when they are sent to a child of the delegate's
41 // window.
42 if (delegate_ && delegate_->GetWindow()->Contains(target))
43 target->delegate()->OnKeyEvent(event);
44
40 // Always handled: other windows shouldn't receive input while we're 45 // Always handled: other windows shouldn't receive input while we're
41 // taking a screenshot. 46 // taking a screenshot.
Daniel Erat 2012/07/26 01:52:51 nit: s/taking a screenshot/displaying an overlay/
mazda 2012/07/26 02:09:08 Done.
42 return true; 47 return true;
43 } 48 }
44 49
45 bool PartialScreenshotEventFilter::PreHandleMouseEvent( 50 bool OverlayEventFilter::PreHandleMouseEvent(
46 aura::Window* target, aura::MouseEvent* event) { 51 aura::Window* target, aura::MouseEvent* event) {
47 if (view_) { 52 if (delegate_) {
48 DCHECK_EQ(target, view_->GetWidget()->GetNativeWindow()); 53 DCHECK_EQ(target, delegate_->GetWindow());
49 target->delegate()->OnMouseEvent(event); 54 target->delegate()->OnMouseEvent(event);
50 return true; 55 return true;
51 } 56 }
52 return false; // Not handled. 57 return false; // Not handled.
53 } 58 }
54 59
55 ui::TouchStatus PartialScreenshotEventFilter::PreHandleTouchEvent( 60 ui::TouchStatus OverlayEventFilter::PreHandleTouchEvent(
56 aura::Window* target, aura::TouchEvent* event) { 61 aura::Window* target, aura::TouchEvent* event) {
57 return ui::TOUCH_STATUS_UNKNOWN; // Not handled. 62 return ui::TOUCH_STATUS_UNKNOWN; // Not handled.
58 } 63 }
59 64
60 ui::GestureStatus PartialScreenshotEventFilter::PreHandleGestureEvent( 65 ui::GestureStatus OverlayEventFilter::PreHandleGestureEvent(
61 aura::Window* target, aura::GestureEvent* event) { 66 aura::Window* target, aura::GestureEvent* event) {
62 return ui::GESTURE_STATUS_UNKNOWN; // Not handled. 67 return ui::GESTURE_STATUS_UNKNOWN; // Not handled.
63 } 68 }
64 69
65 void PartialScreenshotEventFilter::OnLoginStateChanged( 70 void OverlayEventFilter::OnLoginStateChanged(
66 user::LoginStatus status) { 71 user::LoginStatus status) {
67 Cancel(); 72 Cancel();
68 } 73 }
69 74
70 void PartialScreenshotEventFilter::OnAppTerminating() { 75 void OverlayEventFilter::OnAppTerminating() {
71 Cancel(); 76 Cancel();
72 } 77 }
73 78
74 void PartialScreenshotEventFilter::OnLockStateChanged(bool locked) { 79 void OverlayEventFilter::OnLockStateChanged(bool locked) {
75 Cancel(); 80 Cancel();
76 } 81 }
77 82
78 void PartialScreenshotEventFilter::Activate(PartialScreenshotView* view) { 83 void OverlayEventFilter::Activate(Delegate* delegate) {
79 view_ = view; 84 delegate_ = delegate;
80 } 85 }
81 86
82 void PartialScreenshotEventFilter::Deactivate() { 87 void OverlayEventFilter::Deactivate() {
83 view_ = NULL; 88 delegate_ = NULL;
84 } 89 }
85 90
86 void PartialScreenshotEventFilter::Cancel() { 91 void OverlayEventFilter::Cancel() {
87 if (view_) 92 if (delegate_)
88 view_->Cancel(); 93 delegate_->Cancel();
89 } 94 }
90 } // namespace internal 95 } // namespace internal
91 } // namespace ash 96 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698