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
ash / assistant / model / assistant_ui_model.cc [blame]
// Copyright 2018 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/assistant/model/assistant_ui_model.h"
#include "ash/assistant/model/assistant_ui_model_observer.h"
namespace ash {
std::ostream& operator<<(std::ostream& os, AssistantVisibility visibility) {
switch (visibility) {
case AssistantVisibility::kClosed:
return os << "Closed";
case AssistantVisibility::kClosing:
return os << "Closing";
case AssistantVisibility::kVisible:
return os << "Visible";
}
}
AssistantUiModel::AssistantUiModel() = default;
AssistantUiModel::~AssistantUiModel() = default;
void AssistantUiModel::AddObserver(AssistantUiModelObserver* observer) const {
observers_.AddObserver(observer);
}
void AssistantUiModel::RemoveObserver(
AssistantUiModelObserver* observer) const {
observers_.RemoveObserver(observer);
}
void AssistantUiModel::SetVisible(AssistantEntryPoint entry_point) {
SetVisibility(AssistantVisibility::kVisible, entry_point,
/*exit_point=*/std::nullopt);
}
void AssistantUiModel::SetClosing(AssistantExitPoint exit_point) {
SetVisibility(AssistantVisibility::kClosing,
/*entry_point=*/std::nullopt, exit_point);
}
void AssistantUiModel::SetClosed(AssistantExitPoint exit_point) {
SetVisibility(AssistantVisibility::kClosed,
/*entry_point=*/std::nullopt, exit_point);
}
void AssistantUiModel::SetUsableWorkArea(const gfx::Rect& usable_work_area) {
if (usable_work_area == usable_work_area_)
return;
usable_work_area_ = usable_work_area;
NotifyUsableWorkAreaChanged();
}
void AssistantUiModel::SetKeyboardTraversalMode(bool keyboard_traversal_mode) {
if (keyboard_traversal_mode == keyboard_traversal_mode_)
return;
keyboard_traversal_mode_ = keyboard_traversal_mode;
NotifyKeyboardTraversalModeChanged();
}
void AssistantUiModel::SetAppListBubbleWidth(int width) {
app_list_bubble_width_ = width;
}
void AssistantUiModel::SetVisibility(
AssistantVisibility visibility,
std::optional<AssistantEntryPoint> entry_point,
std::optional<AssistantExitPoint> exit_point) {
if (visibility == visibility_)
return;
const AssistantVisibility old_visibility = visibility_;
visibility_ = visibility;
if (visibility == AssistantVisibility::kVisible) {
// Cache the Assistant entry point used for query count UMA metric.
DCHECK(entry_point.has_value());
DCHECK(!exit_point.has_value());
entry_point_ = entry_point.value();
} else {
DCHECK(!entry_point.has_value());
DCHECK(exit_point.has_value());
}
NotifyUiVisibilityChanged(old_visibility, entry_point, exit_point);
}
void AssistantUiModel::NotifyKeyboardTraversalModeChanged() {
for (AssistantUiModelObserver& observer : observers_)
observer.OnKeyboardTraversalModeChanged(keyboard_traversal_mode_);
}
void AssistantUiModel::NotifyUiVisibilityChanged(
AssistantVisibility old_visibility,
std::optional<AssistantEntryPoint> entry_point,
std::optional<AssistantExitPoint> exit_point) {
for (AssistantUiModelObserver& observer : observers_)
observer.OnUiVisibilityChanged(visibility_, old_visibility, entry_point,
exit_point);
}
void AssistantUiModel::NotifyUsableWorkAreaChanged() {
for (AssistantUiModelObserver& observer : observers_)
observer.OnUsableWorkAreaChanged(usable_work_area_);
}
} // namespace ash