File: pointer_metrics_recorder.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (108 lines) | stat: -rw-r--r-- 3,746 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/metrics/pointer_metrics_recorder.h"

#include "ash/display/screen_orientation_controller.h"
#include "ash/shell.h"
#include "base/metrics/histogram_macros.h"
#include "chromeos/ui/base/app_types.h"
#include "chromeos/ui/base/window_properties.h"
#include "ui/aura/window.h"
#include "ui/display/screen.h"
#include "ui/events/event_constants.h"
#include "ui/events/types/event_type.h"
#include "ui/views/widget/widget.h"

namespace ash {

namespace {

chromeos::AppType GetDestination(views::Widget* target) {
  if (!target) {
    return chromeos::AppType::NON_APP;
  }

  aura::Window* window = target->GetNativeWindow();
  DCHECK(window);
  return window->GetProperty(chromeos::kAppTypeKey);
}

DownEventMetric2 FindCombination(chromeos::AppType destination,
                                 DownEventSource input_type,
                                 DownEventFormFactor form_factor) {
  constexpr int kNumCombinationPerDestination =
      static_cast<int>(DownEventSource::kSourceCount) *
      static_cast<int>(DownEventFormFactor::kFormFactorCount);
  int result = static_cast<int>(destination) * kNumCombinationPerDestination +
               static_cast<int>(DownEventFormFactor::kFormFactorCount) *
                   static_cast<int>(input_type) +
               static_cast<int>(form_factor);
  DCHECK(result >= 0 &&
         result <= static_cast<int>(DownEventMetric2::kMaxValue));
  return static_cast<DownEventMetric2>(result);
}

void RecordUMA(ui::EventPointerType type, ui::EventTarget* event_target) {
  DCHECK_NE(type, ui::EventPointerType::kUnknown);
  views::Widget* target = views::Widget::GetTopLevelWidgetForNativeView(
      static_cast<aura::Window*>(event_target));
  DownEventFormFactor form_factor = DownEventFormFactor::kClamshell;
  if (display::Screen::GetScreen()->InTabletMode()) {
    chromeos::OrientationType screen_orientation =
        Shell::Get()->screen_orientation_controller()->GetCurrentOrientation();
    if (screen_orientation == chromeos::OrientationType::kLandscapePrimary ||
        screen_orientation == chromeos::OrientationType::kLandscapeSecondary) {
      form_factor = DownEventFormFactor::kTabletModeLandscape;
    } else {
      form_factor = DownEventFormFactor::kTabletModePortrait;
    }
  }

  DownEventSource input_type = DownEventSource::kUnknown;
  switch (type) {
    case ui::EventPointerType::kUnknown:
      return;
    case ui::EventPointerType::kMouse:
      input_type = DownEventSource::kMouse;
      break;
    case ui::EventPointerType::kPen:
      input_type = DownEventSource::kStylus;
      break;
    case ui::EventPointerType::kTouch:
      input_type = DownEventSource::kTouch;
      break;
    case ui::EventPointerType::kEraser:
      input_type = DownEventSource::kStylus;
      break;
  }

  UMA_HISTOGRAM_ENUMERATION(
      "Event.DownEventCount.PerInputFormFactorDestinationCombination2",
      FindCombination(GetDestination(target), input_type, form_factor));
}

}  // namespace

PointerMetricsRecorder::PointerMetricsRecorder() {
  Shell::Get()->AddPreTargetHandler(this);
}

PointerMetricsRecorder::~PointerMetricsRecorder() {
  Shell::Get()->RemovePreTargetHandler(this);
}

void PointerMetricsRecorder::OnMouseEvent(ui::MouseEvent* event) {
  if (event->type() == ui::EventType::kMousePressed) {
    RecordUMA(event->pointer_details().pointer_type, event->target());
  }
}

void PointerMetricsRecorder::OnTouchEvent(ui::TouchEvent* event) {
  if (event->type() == ui::EventType::kTouchPressed) {
    RecordUMA(event->pointer_details().pointer_type, event->target());
  }
}

}  // namespace ash