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/aura/window_property.h" |
| 19 #include "ui/events/event_constants.h" |
| 20 #include "ui/views/widget/widget.h" |
| 21 |
| 22 DECLARE_WINDOW_PROPERTY_TYPE(chromeos::StylusWindowType); |
| 23 |
| 24 namespace chromeos { |
| 25 |
| 26 DEFINE_WINDOW_PROPERTY_KEY(StylusWindowType, |
| 27 kStylusWindowTypeBucket, |
| 28 StylusWindowType::WINDOW_TYPE_OTHERS); |
| 29 |
| 30 namespace { |
| 31 |
| 32 // Form factor of the down event. This enum is used to back an UMA histogram |
| 33 // and should be treated as append-only. |
| 34 enum DownEventFormFactor { |
| 35 DOWN_EVENT_FORMFACTOR_CLAMSHELL = 0, |
| 36 DOWN_EVENT_FORMFACTOR_TOUCHVIEW, |
| 37 DOWN_EVENT_FORMFACTOR_COUNT |
| 38 }; |
| 39 |
| 40 // Input type of the down event. This enum is used to back an UMA |
| 41 // histogram and should be treated as append-only. |
| 42 enum DownEventSource { |
| 43 DOWN_EVENT_SOURCE_UNKNOWN = 0, |
| 44 DOWN_EVENT_SOURCE_MOUSE, |
| 45 DOWN_EVENT_SOURCE_STYLUS, |
| 46 DOWN_EVENT_SOURCE_TOUCH, |
| 47 DOWN_EVENT_SOURCE_COUNT |
| 48 }; |
| 49 |
| 50 // Destination of the down event. This enum is used to back |
| 51 // an UMA histogram and should be treated as append-only. |
| 52 enum DownEventDestination { |
| 53 DOWN_EVENT_DESTINATION_OTHERS = 0, |
| 54 DOWN_EVENT_DESTINATION_BROWSER, |
| 55 DOWN_EVENT_DESTINATION_CHROME_APP, |
| 56 DOWN_EVENT_DESTINATION_ARC_APP, |
| 57 DOWN_EVENT_DESTINATION_NOTE_TAKING_APP, |
| 58 DOWN_EVENT_DESTINATION_COUNT |
| 59 }; |
| 60 |
| 61 DownEventDestination GetDownEventDestination(views::Widget* target) { |
| 62 DownEventDestination dest = DOWN_EVENT_DESTINATION_OTHERS; |
| 63 if (!target) |
| 64 return dest; |
| 65 |
| 66 aura::Window* window = target->GetNativeWindow(); |
| 67 |
| 68 if (!window) |
| 69 return dest; |
| 70 |
| 71 if (exo::ShellSurface::GetMainSurface(window)) |
| 72 return DOWN_EVENT_DESTINATION_ARC_APP; |
| 73 |
| 74 StylusWindowType window_type = window->GetProperty(kStylusWindowTypeBucket); |
| 75 |
| 76 if (window_type == StylusWindowType::WINDOW_TYPE_BROWSER_WINDOW) |
| 77 return DownEventDestination::DOWN_EVENT_DESTINATION_BROWSER; |
| 78 |
| 79 if (window_type == StylusWindowType::WINDOW_TYPE_APP) { |
| 80 extensions::AppWindow* app_window = |
| 81 AppWindowRegistryUtil::GetAppWindowForNativeWindowAnyProfile(window); |
| 82 if (app_window && chromeos::IsNoteTakingApp(app_window)) |
| 83 return DOWN_EVENT_DESTINATION_NOTE_TAKING_APP; |
| 84 else |
| 85 return DOWN_EVENT_DESTINATION_CHROME_APP; |
| 86 } |
| 87 |
| 88 return dest; |
| 89 } |
| 90 |
| 91 void RecordUMA(ui::EventPointerType type, views::Widget* target) { |
| 92 DownEventFormFactor form_factor = DOWN_EVENT_FORMFACTOR_CLAMSHELL; |
| 93 if (ash::WmShell::Get() |
| 94 ->maximize_mode_controller() |
| 95 ->IsMaximizeModeWindowManagerEnabled()) { |
| 96 form_factor = DOWN_EVENT_FORMFACTOR_TOUCHVIEW; |
| 97 } |
| 98 UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerFormFactor", form_factor, |
| 99 DownEventFormFactor::DOWN_EVENT_FORMFACTOR_COUNT); |
| 100 |
| 101 DownEventSource input_type = DownEventSource::DOWN_EVENT_SOURCE_UNKNOWN; |
| 102 switch (type) { |
| 103 case ui::EventPointerType::POINTER_TYPE_UNKNOWN: |
| 104 input_type = DOWN_EVENT_SOURCE_UNKNOWN; |
| 105 break; |
| 106 case ui::EventPointerType::POINTER_TYPE_MOUSE: |
| 107 input_type = DOWN_EVENT_SOURCE_MOUSE; |
| 108 break; |
| 109 case ui::EventPointerType::POINTER_TYPE_PEN: |
| 110 input_type = DOWN_EVENT_SOURCE_STYLUS; |
| 111 break; |
| 112 case ui::EventPointerType::POINTER_TYPE_TOUCH: |
| 113 input_type = DOWN_EVENT_SOURCE_TOUCH; |
| 114 break; |
| 115 case ui::EventPointerType::POINTER_TYPE_ERASER: |
| 116 input_type = DOWN_EVENT_SOURCE_STYLUS; |
| 117 break; |
| 118 } |
| 119 |
| 120 UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerInput", input_type, |
| 121 DOWN_EVENT_SOURCE_COUNT); |
| 122 |
| 123 DownEventDestination dest = GetDownEventDestination(target); |
| 124 UMA_HISTOGRAM_ENUMERATION("Event.DownEventCount.PerDestination", dest, |
| 125 DOWN_EVENT_DESTINATION_COUNT); |
| 126 } |
| 127 |
| 128 } // namespace |
| 129 |
| 130 StylusMetricsRecorder::StylusMetricsRecorder() { |
| 131 ash::WmShell::Get()->AddPointerWatcher( |
| 132 this, views::PointerWatcherEventTypes::BASIC); |
| 133 } |
| 134 |
| 135 StylusMetricsRecorder::~StylusMetricsRecorder() { |
| 136 ash::WmShell::Get()->RemovePointerWatcher(this); |
| 137 } |
| 138 |
| 139 void StylusMetricsRecorder::OnPointerEventObserved( |
| 140 const ui::PointerEvent& event, |
| 141 const gfx::Point& location_in_screen, |
| 142 views::Widget* target) { |
| 143 if (event.type() != ui::ET_POINTER_DOWN) |
| 144 return; |
| 145 RecordUMA(event.pointer_details().pointer_type, target); |
| 146 } |
| 147 |
| 148 } // namespace chromeos |
OLD | NEW |