OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 "chrome/browser/ui/ash/metrics/stylus_metrics_recorder.h" | |
6 | |
7 #include "ash/common/shell_window_ids.h" | |
8 #include "ash/common/wm/container_finder.h" | |
9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | |
10 #include "ash/common/wm_lookup.h" | |
11 #include "ash/common/wm_shell.h" | |
12 #include "ash/common/wm_window.h" | |
13 #include "base/metrics/histogram_macros.h" | |
14 #include "chrome/browser/apps/app_window_registry_util.h" | |
15 #include "chrome/browser/chromeos/note_taking_app_utils.h" | |
16 #include "components/exo/shell_surface.h" | |
17 #include "extensions/browser/app_window/app_window.h" | |
18 #include "ui/events/event_constants.h" | |
19 #include "ui/views/widget/widget.h" | |
20 | |
21 namespace chromeos { | |
22 | |
23 StylusMetricsRecorder::StylusMetricsRecorder() { | |
24 ash::WmShell::Get()->AddPointerWatcher( | |
25 this, views::PointerWatcherEventTypes::BASIC); | |
26 } | |
27 | |
28 StylusMetricsRecorder::~StylusMetricsRecorder() { | |
29 ash::WmShell::Get()->RemovePointerWatcher(this); | |
30 } | |
31 | |
32 void StylusMetricsRecorder::OnPointerEventObserved( | |
33 const ui::PointerEvent& event, | |
34 const gfx::Point& location_in_screen, | |
35 views::Widget* target) { | |
36 if (event.type() != ui::ET_POINTER_DOWN) | |
37 return; | |
38 RecordUMA(event.pointer_details().pointer_type, target); | |
39 } | |
40 | |
41 void StylusMetricsRecorder::RecordUMA(ui::EventPointerType type, | |
42 views::Widget* target) { | |
43 DownEventFormFactor form_factor = DOWN_EVENT_FORMFACTOR_CLAMSHELL; | |
44 if (ash::WmShell::Get() | |
45 ->maximize_mode_controller() | |
46 ->IsMaximizeModeWindowManagerEnabled()) { | |
47 form_factor = DOWN_EVENT_FORMFACTOR_TOUCHVIEW; | |
48 } | |
49 UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerFormFactor", form_factor, | |
50 DOWN_EVENT_FORMFACTOR_COUNT); | |
51 | |
52 DownEventSource input_type = DOWN_EVENT_SOURCE_UNKNOWN; | |
53 switch (type) { | |
54 case ui::EventPointerType::POINTER_TYPE_UNKNOWN: | |
55 input_type = DOWN_EVENT_SOURCE_UNKNOWN; | |
56 break; | |
57 case ui::EventPointerType::POINTER_TYPE_MOUSE: | |
58 input_type = DOWN_EVENT_SOURCE_MOUSE; | |
59 break; | |
60 case ui::EventPointerType::POINTER_TYPE_PEN: | |
61 input_type = DOWN_EVENT_SOURCE_STYLUS; | |
62 break; | |
63 case ui::EventPointerType::POINTER_TYPE_TOUCH: | |
64 input_type = DOWN_EVENT_SOURCE_TOUCH; | |
65 break; | |
66 case ui::EventPointerType::POINTER_TYPE_ERASER: | |
67 input_type = DOWN_EVENT_SOURCE_STYLUS; | |
68 break; | |
69 } | |
70 | |
71 UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerInput", input_type, | |
72 DOWN_EVENT_SOURCE_COUNT); | |
73 | |
74 DownEventDestination dest = GetDownEventDestination(target); | |
75 UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerDestination", dest, | |
76 DOWN_EVENT_DESTINATION_COUNT); | |
77 } | |
78 | |
79 bool StylusMetricsRecorder::IsEventOnShelf(views::Widget* target) { | |
80 if (!target) { | |
sky
2016/09/13 00:03:26
In general we don't use {} around single line cond
xiaoyinh(OOO Sep 11-29)
2016/09/16 18:41:16
Done.
| |
81 return false; | |
82 } | |
83 | |
84 ash::WmWindow* window = ash::WmLookup::Get()->GetWindowForWidget(target); | |
85 int container_id = ash::wm::GetContainerForWindow(window)->GetShellWindowId(); | |
sky
2016/09/13 00:03:26
Make sure you null check GetContainerForWindow and
xiaoyinh(OOO Sep 11-29)
2016/09/16 18:41:16
Done.
| |
86 | |
87 // Events on the shelf. | |
88 if (container_id == ash::kShellWindowId_ShelfContainer) | |
89 return true; | |
90 // Events on the status area. | |
91 if (container_id == ash::kShellWindowId_StatusContainer) | |
92 return true; | |
93 // Events on the right click menus. | |
94 if (container_id == ash::kShellWindowId_MenuContainer) | |
sky
2016/09/13 00:03:26
This hits *all* menus. I don't think you want that
xiaoyinh(OOO Sep 11-29)
2016/09/16 18:41:16
Deleted. Thanks.
| |
95 return true; | |
96 // Events on the settings trays. | |
97 if (container_id == ash::kShellWindowId_SettingBubbleContainer) | |
98 return true; | |
99 // Events on the overflow bubbles over the shelf. | |
100 if (container_id == ash::kShellWindowId_ShelfBubbleContainer) | |
101 return true; | |
102 | |
103 return false; | |
104 } | |
105 | |
106 DownEventDestination StylusMetricsRecorder::GetDownEventDestination( | |
107 views::Widget* target) { | |
108 DownEventDestination dest = DOWN_EVENT_DESTINATION_OTHERS; | |
109 if (!target) | |
110 return dest; | |
111 | |
112 if (IsEventOnShelf(target)) | |
113 return DOWN_EVENT_DESTINATION_SYSTEM_UI; | |
114 | |
115 aura::Window* window = target->GetNativeWindow(); | |
116 | |
117 if (exo::ShellSurface::GetMainSurface(window)) | |
118 return DOWN_EVENT_DESTINATION_ARC_APP; | |
119 | |
120 if (window->GetProperty(aura::client::kStylusWindowTypeBucket) == | |
xiyuan
2016/09/12 20:15:47
nit: save the result of window->GetProperty(aura::
xiaoyinh(OOO Sep 11-29)
2016/09/16 18:41:16
Done.
| |
121 StylusWindowType::WINDOW_TYPE_BROWSER_WINDOW) | |
122 return DOWN_EVENT_DESTINATION_WEBSITE; | |
123 | |
124 if (window->GetProperty(aura::client::kStylusWindowTypeBucket) == | |
125 StylusWindowType::WINDOW_TYPE_APP) { | |
126 extensions::AppWindow* app_window = | |
127 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(window); | |
128 if (app_window && chromeos::IsCurrentAppNoteTakingApp(app_window)) | |
129 return DOWN_EVENT_DESTINATION_NOTE_TAKING_APP; | |
130 } | |
131 | |
132 return dest; | |
133 } | |
134 | |
135 } // namespace chromeos | |
OLD | NEW |