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

Side by Side Diff: ui/events/event_utils.cc

Issue 284903002: Only dispatch menu events if they have a valid target. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 7 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
« no previous file with comments | « ui/events/event_utils.h ('k') | ui/views/controls/menu/menu_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/events/event_utils.h" 5 #include "ui/events/event_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ui/events/event.h" 9 #include "ui/events/event.h"
10 #include "ui/gfx/display.h" 10 #include "ui/gfx/display.h"
11 #include "ui/gfx/screen.h" 11 #include "ui/gfx/screen.h"
12 12
13 namespace ui { 13 namespace ui {
14 14
15 namespace { 15 namespace {
16 int g_custom_event_types = ET_LAST; 16 int g_custom_event_types = ET_LAST;
17 } // namespace 17 } // namespace
18 18
19 scoped_ptr<Event> EventFromNative(const base::NativeEvent& native_event) {
20 scoped_ptr<Event> event;
21 EventType type = EventTypeFromNative(native_event);
22 switch(type) {
23 case ET_KEY_PRESSED:
24 case ET_KEY_RELEASED:
25 event.reset(new KeyEvent(native_event, false));
26 break;
27
28 case ET_TRANSLATED_KEY_PRESS:
29 case ET_TRANSLATED_KEY_RELEASE:
30 // These should not be generated by native events.
31 NOTREACHED();
32 break;
33
34 case ET_MOUSE_PRESSED:
35 case ET_MOUSE_DRAGGED:
36 case ET_MOUSE_RELEASED:
37 case ET_MOUSE_MOVED:
38 case ET_MOUSE_ENTERED:
39 case ET_MOUSE_EXITED:
40 event.reset(new MouseEvent(native_event));
41 break;
42
43 case ET_MOUSEWHEEL:
44 event.reset(new MouseWheelEvent(native_event));
45 break;
46
47 case ET_SCROLL_FLING_START:
48 case ET_SCROLL_FLING_CANCEL:
49 case ET_SCROLL:
50 event.reset(new ScrollEvent(native_event));
51 break;
52
53 case ET_TOUCH_RELEASED:
54 case ET_TOUCH_PRESSED:
55 case ET_TOUCH_MOVED:
56 case ET_TOUCH_CANCELLED:
57 event.reset(new TouchEvent(native_event));
58 break;
59
60 default:
61 break;
62 }
63 return event.Pass();
64 }
65
19 int RegisterCustomEventType() { 66 int RegisterCustomEventType() {
20 return ++g_custom_event_types; 67 return ++g_custom_event_types;
21 } 68 }
22 69
23 base::TimeDelta EventTimeForNow() { 70 base::TimeDelta EventTimeForNow() {
24 return base::TimeDelta::FromInternalValue( 71 return base::TimeDelta::FromInternalValue(
25 base::TimeTicks::Now().ToInternalValue()); 72 base::TimeTicks::Now().ToInternalValue());
26 } 73 }
27 74
28 bool ShouldDefaultToNaturalScroll() { 75 bool ShouldDefaultToNaturalScroll() {
29 return GetInternalDisplayTouchSupport() == 76 return GetInternalDisplayTouchSupport() ==
30 gfx::Display::TOUCH_SUPPORT_AVAILABLE; 77 gfx::Display::TOUCH_SUPPORT_AVAILABLE;
31 } 78 }
32 79
33 gfx::Display::TouchSupport GetInternalDisplayTouchSupport() { 80 gfx::Display::TouchSupport GetInternalDisplayTouchSupport() {
34 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); 81 gfx::Screen* screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE);
35 // No screen in some unit tests. 82 // No screen in some unit tests.
36 if (!screen) 83 if (!screen)
37 return gfx::Display::TOUCH_SUPPORT_UNKNOWN; 84 return gfx::Display::TOUCH_SUPPORT_UNKNOWN;
38 const std::vector<gfx::Display>& displays = screen->GetAllDisplays(); 85 const std::vector<gfx::Display>& displays = screen->GetAllDisplays();
39 for (std::vector<gfx::Display>::const_iterator it = displays.begin(); 86 for (std::vector<gfx::Display>::const_iterator it = displays.begin();
40 it != displays.end(); ++it) { 87 it != displays.end(); ++it) {
41 if (it->IsInternal()) 88 if (it->IsInternal())
42 return it->touch_support(); 89 return it->touch_support();
43 } 90 }
44 return gfx::Display::TOUCH_SUPPORT_UNAVAILABLE; 91 return gfx::Display::TOUCH_SUPPORT_UNAVAILABLE;
45 } 92 }
46 93
47 } // namespace ui 94 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/event_utils.h ('k') | ui/views/controls/menu/menu_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698