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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
ash / wm / gestures / back_gesture / back_gesture_metrics.cc [blame]
// Copyright 2019 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/wm/gestures/back_gesture/back_gesture_metrics.h"
#include "ash/display/screen_orientation_controller.h"
#include "ash/shell.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/splitview/split_view_divider.h"
#include "ash/wm/window_util.h"
#include "base/metrics/histogram_macros.h"
#include "chromeos/ui/base/app_types.h"
#include "chromeos/ui/base/window_properties.h"
namespace ash {
constexpr char kBackGestureStartScenarioHistogram[] =
"Ash.BackGesture.StartScenarioType";
constexpr char kBackGestureEndScenarioHistogram[] =
"Ash.BackGesture.EndScenarioType";
constexpr char kBackGestureUnderneathWindowTypeHistogram[] =
"Ash.BackGesture.UnderneathWindowType";
BackGestureStartScenarioType GetStartScenarioType(
bool dragged_from_splitview_divider,
const gfx::Point& start_screen_location) {
auto* split_view_controller = SplitViewController::Get(
window_util::GetRootWindowAt(start_screen_location));
if (!split_view_controller->InTabletSplitViewMode()) {
return Shell::Get()->overview_controller()->InOverviewSession()
? BackGestureStartScenarioType::kOverview
: BackGestureStartScenarioType::kNonSnappedWindow;
}
const auto* left_window = split_view_controller->primary_window();
const auto* right_window = split_view_controller->secondary_window();
const bool is_primary = IsCurrentScreenOrientationPrimary();
const auto* physical_left_or_top_window =
is_primary ? left_window : right_window;
const auto* physical_right_or_bottom_window =
is_primary ? right_window : left_window;
if (IsCurrentScreenOrientationLandscape()) {
if (dragged_from_splitview_divider) {
return physical_right_or_bottom_window
? BackGestureStartScenarioType::kRightSnappedWindow
: BackGestureStartScenarioType::kRightOverview;
}
return physical_left_or_top_window
? BackGestureStartScenarioType::kLeftSnappedWindow
: BackGestureStartScenarioType::kLeftOverview;
}
if (start_screen_location.y() <= split_view_controller->split_view_divider()
->GetDividerBoundsInScreen(
/*is_dragging=*/false)
.bottom()) {
return physical_left_or_top_window
? BackGestureStartScenarioType::kTopSnappedWindow
: BackGestureStartScenarioType::kTopOverview;
}
return physical_right_or_bottom_window
? BackGestureStartScenarioType::kBottomSnappedWindow
: BackGestureStartScenarioType::kBottomOverview;
}
void RecordStartScenarioType(BackGestureStartScenarioType type) {
UMA_HISTOGRAM_ENUMERATION(kBackGestureStartScenarioHistogram, type);
}
BackGestureEndScenarioType GetEndScenarioType(
BackGestureStartScenarioType start_type,
BackGestureEndType end_type) {
BackGestureEndScenarioType type = BackGestureEndScenarioType::kMaxValue;
switch (start_type) {
case BackGestureStartScenarioType::kNonSnappedWindow:
if (end_type == BackGestureEndType::kAbort)
type = BackGestureEndScenarioType::kNonSnappedWindowAbort;
else if (end_type == BackGestureEndType::kBack)
type = BackGestureEndScenarioType::kNonSnappedWindowGoBack;
else
type = BackGestureEndScenarioType::kNonSnappedWindowMinimize;
break;
case BackGestureStartScenarioType::kLeftSnappedWindow:
if (end_type == BackGestureEndType::kAbort)
type = BackGestureEndScenarioType::kLeftSnappedWindowAbort;
else if (end_type == BackGestureEndType::kBack)
type = BackGestureEndScenarioType::kLeftSnappedWindowGoBack;
else
type = BackGestureEndScenarioType::kLeftSnappedWindowMinimize;
break;
case BackGestureStartScenarioType::kRightSnappedWindow:
if (end_type == BackGestureEndType::kAbort)
type = BackGestureEndScenarioType::kRightSnappedWindowAbort;
else if (end_type == BackGestureEndType::kBack)
type = BackGestureEndScenarioType::kRightSnappedWindowGoBack;
else
type = BackGestureEndScenarioType::kRightSnappedWindowMinimize;
break;
case BackGestureStartScenarioType::kTopSnappedWindow:
if (end_type == BackGestureEndType::kAbort)
type = BackGestureEndScenarioType::kTopSnappedWindowAbort;
else if (end_type == BackGestureEndType::kBack)
type = BackGestureEndScenarioType::kTopSnappedWindowGoBack;
else
type = BackGestureEndScenarioType::kTopSnappedWindowMinimize;
break;
case BackGestureStartScenarioType::kBottomSnappedWindow:
if (end_type == BackGestureEndType::kAbort)
type = BackGestureEndScenarioType::kBottomSnappedWindowAbort;
else if (end_type == BackGestureEndType::kBack)
type = BackGestureEndScenarioType::kBottomSnappedWindowGoBack;
else
type = BackGestureEndScenarioType::kBottomSnappedWindowMinimize;
break;
case BackGestureStartScenarioType::kOverview:
case BackGestureStartScenarioType::kLeftOverview:
case BackGestureStartScenarioType::kRightOverview:
case BackGestureStartScenarioType::kTopOverview:
case BackGestureStartScenarioType::kBottomOverview:
if (end_type == BackGestureEndType::kAbort)
type = BackGestureEndScenarioType::kOverviewAbort;
else if (end_type == BackGestureEndType::kBack)
type = BackGestureEndScenarioType::kOverviewGoBack;
break;
default:
break;
}
return type;
}
void RecordEndScenarioType(BackGestureEndScenarioType type) {
UMA_HISTOGRAM_ENUMERATION(kBackGestureEndScenarioHistogram, type);
}
BackGestureUnderneathWindowType GetUnderneathWindowType(
BackGestureStartScenarioType start_type) {
if (start_type == BackGestureStartScenarioType::kOverview ||
start_type == BackGestureStartScenarioType::kLeftOverview ||
start_type == BackGestureStartScenarioType::kRightOverview ||
start_type == BackGestureStartScenarioType::kTopOverview ||
start_type == BackGestureStartScenarioType::kBottomOverview) {
return BackGestureUnderneathWindowType::kOverview;
}
const auto* window = window_util::GetTopWindow();
DCHECK(window);
const chromeos::AppType app_type = window->GetProperty(chromeos::kAppTypeKey);
if (app_type == chromeos::AppType::BROWSER) {
return BackGestureUnderneathWindowType::kBrowser;
}
if (app_type == chromeos::AppType::CHROME_APP) {
return BackGestureUnderneathWindowType::kChromeApp;
}
if (app_type == chromeos::AppType::ARC_APP) {
return BackGestureUnderneathWindowType::kArcApp;
}
return BackGestureUnderneathWindowType::kOthers;
}
void RecordUnderneathWindowType(BackGestureUnderneathWindowType type) {
UMA_HISTOGRAM_ENUMERATION(kBackGestureUnderneathWindowTypeHistogram, type);
}
} // namespace ash