forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_list_controller_impl.cc
1388 lines (1181 loc) · 49.1 KB
/
app_list_controller_impl.cc
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/app_list/app_list_controller_impl.h"
#include <utility>
#include <vector>
#include "ash/app_list/app_list_controller_observer.h"
#include "ash/app_list/app_list_metrics.h"
#include "ash/app_list/app_list_presenter_delegate_impl.h"
#include "ash/app_list/model/app_list_folder_item.h"
#include "ash/app_list/model/app_list_item.h"
#include "ash/app_list/views/app_list_main_view.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/app_list/views/contents_view.h"
#include "ash/app_list/views/search_box_view.h"
#include "ash/assistant/assistant_controller.h"
#include "ash/assistant/assistant_ui_controller.h"
#include "ash/assistant/model/assistant_ui_model.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/assistant/util/assistant_util.h"
#include "ash/assistant/util/deep_link_util.h"
#include "ash/home_screen/home_launcher_gesture_handler.h"
#include "ash/home_screen/home_screen_controller.h"
#include "ash/public/cpp/app_list/app_list_client.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/app_list/app_list_metrics.h"
#include "ash/public/cpp/app_list/app_list_types.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shell.h"
#include "ash/voice_interaction/voice_interaction_controller.h"
#include "ash/wallpaper/wallpaper_controller.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_state.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/constants/chromeos_switches.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "extensions/common/constants.h"
#include "ui/base/ui_base_features.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/wm/public/activation_client.h"
namespace ash {
namespace {
bool IsHomeScreenAvailable() {
return Shell::Get()->home_screen_controller()->IsHomeScreenAvailable();
}
bool IsTabletMode() {
return Shell::Get()
->tablet_mode_controller()
->IsTabletModeWindowManagerEnabled();
}
// Close current Assistant UI.
void CloseAssistantUi(AssistantExitPoint exit_point) {
if (app_list_features::IsEmbeddedAssistantUIEnabled())
Shell::Get()->assistant_controller()->ui_controller()->CloseUi(exit_point);
}
app_list::TabletModeAnimationTransition CalculateAnimationTransitionForMetrics(
HomeScreenDelegate::AnimationTrigger trigger,
bool launcher_should_show) {
switch (trigger) {
case HomeScreenDelegate::AnimationTrigger::kHideForWindow:
return app_list::TabletModeAnimationTransition::
kHideHomeLauncherForWindow;
case HomeScreenDelegate::AnimationTrigger::kLauncherButton:
return app_list::TabletModeAnimationTransition::kAppListButtonShow;
case HomeScreenDelegate::AnimationTrigger::kDragRelease:
return launcher_should_show
? app_list::TabletModeAnimationTransition::kDragReleaseShow
: app_list::TabletModeAnimationTransition::kDragReleaseHide;
case HomeScreenDelegate::AnimationTrigger::kOverviewMode:
return launcher_should_show
? app_list::TabletModeAnimationTransition::kExitOverviewMode
: app_list::TabletModeAnimationTransition::kEnterOverviewMode;
}
}
int GetAssistantPrivacyInfoShownCount() {
PrefService* prefs =
Shell::Get()->session_controller()->GetLastActiveUserPrefService();
return prefs->GetInteger(prefs::kAssistantPrivacyInfoShownInLauncher);
}
void SetAssistantPrivacyInfoShownCount(int count) {
PrefService* prefs =
Shell::Get()->session_controller()->GetLastActiveUserPrefService();
prefs->SetInteger(prefs::kAssistantPrivacyInfoShownInLauncher, count);
}
bool IsAssistantPrivacyInfoDismissed() {
PrefService* prefs =
Shell::Get()->session_controller()->GetLastActiveUserPrefService();
return prefs->GetBoolean(prefs::kAssistantPrivacyInfoDismissedInLauncher);
}
void SetAssistantPrivacyInfoDismissed() {
PrefService* prefs =
Shell::Get()->session_controller()->GetLastActiveUserPrefService();
prefs->SetBoolean(prefs::kAssistantPrivacyInfoDismissedInLauncher, true);
}
} // namespace
AppListControllerImpl::AppListControllerImpl()
: model_(std::make_unique<app_list::AppListModel>()),
presenter_(std::make_unique<AppListPresenterDelegateImpl>(this)) {
model_->AddObserver(this);
SessionControllerImpl* session_controller =
Shell::Get()->session_controller();
session_controller->AddObserver(this);
// In case of crash-and-restart case where session state starts with ACTIVE
// and does not change to trigger OnSessionStateChanged(), notify the current
// session state here to ensure that the app list is shown.
OnSessionStateChanged(session_controller->GetSessionState());
Shell* shell = Shell::Get();
shell->tablet_mode_controller()->AddObserver(this);
shell->wallpaper_controller()->AddObserver(this);
shell->AddShellObserver(this);
shell->overview_controller()->AddObserver(this);
keyboard::KeyboardController::Get()->AddObserver(this);
shell->voice_interaction_controller()->AddLocalObserver(this);
shell->window_tree_host_manager()->AddObserver(this);
shell->mru_window_tracker()->AddObserver(this);
if (app_list_features::IsEmbeddedAssistantUIEnabled()) {
shell->assistant_controller()->AddObserver(this);
shell->assistant_controller()->ui_controller()->AddModelObserver(this);
}
shell->home_screen_controller()->home_launcher_gesture_handler()->AddObserver(
this);
}
AppListControllerImpl::~AppListControllerImpl() {
// If this is being destroyed before the Shell starts shutting down, first
// remove this from objects it's observing.
if (!is_shutdown_)
Shutdown();
if (client_)
client_->OnAppListControllerDestroyed();
}
// static
void AppListControllerImpl::RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(prefs::kAssistantPrivacyInfoShownInLauncher, 0);
registry->RegisterBooleanPref(
prefs::kAssistantPrivacyInfoDismissedInLauncher, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
}
void AppListControllerImpl::SetClient(app_list::AppListClient* client) {
client_ = client;
}
app_list::AppListModel* AppListControllerImpl::GetModel() {
return model_.get();
}
app_list::SearchModel* AppListControllerImpl::GetSearchModel() {
return &search_model_;
}
void AppListControllerImpl::AddItem(
std::unique_ptr<ash::AppListItemMetadata> item_data) {
const std::string folder_id = item_data->folder_id;
if (folder_id.empty())
model_->AddItem(CreateAppListItem(std::move(item_data)));
else
AddItemToFolder(std::move(item_data), folder_id);
}
void AppListControllerImpl::AddItemToFolder(
std::unique_ptr<ash::AppListItemMetadata> item_data,
const std::string& folder_id) {
// When we're setting a whole model of a profile, each item may have its
// folder id set properly. However, |AppListModel::AddItemToFolder| requires
// the item to add is not in the target folder yet, and sets its folder id
// later. So we should clear the folder id here to avoid breaking checks.
item_data->folder_id.clear();
model_->AddItemToFolder(CreateAppListItem(std::move(item_data)), folder_id);
}
void AppListControllerImpl::RemoveItem(const std::string& id) {
model_->DeleteItem(id);
}
void AppListControllerImpl::RemoveUninstalledItem(const std::string& id) {
model_->DeleteUninstalledItem(id);
}
void AppListControllerImpl::MoveItemToFolder(const std::string& id,
const std::string& folder_id) {
app_list::AppListItem* item = model_->FindItem(id);
model_->MoveItemToFolder(item, folder_id);
}
void AppListControllerImpl::SetStatus(ash::AppListModelStatus status) {
model_->SetStatus(status);
}
void AppListControllerImpl::SetState(ash::AppListState state) {
model_->SetState(state);
}
void AppListControllerImpl::HighlightItemInstalledFromUI(
const std::string& id) {
model_->top_level_item_list()->HighlightItemInstalledFromUI(id);
}
void AppListControllerImpl::SetSearchEngineIsGoogle(bool is_google) {
search_model_.SetSearchEngineIsGoogle(is_google);
}
void AppListControllerImpl::SetSearchTabletAndClamshellAccessibleName(
const base::string16& tablet_accessible_name,
const base::string16& clamshell_accessible_name) {
search_model_.search_box()->SetTabletAndClamshellAccessibleName(
tablet_accessible_name, clamshell_accessible_name);
}
void AppListControllerImpl::SetSearchHintText(const base::string16& hint_text) {
search_model_.search_box()->SetHintText(hint_text);
}
void AppListControllerImpl::UpdateSearchBox(const base::string16& text,
bool initiated_by_user) {
search_model_.search_box()->Update(text, initiated_by_user);
}
void AppListControllerImpl::PublishSearchResults(
std::vector<std::unique_ptr<ash::SearchResultMetadata>> results) {
std::vector<std::unique_ptr<app_list::SearchResult>> new_results;
for (auto& result_metadata : results) {
std::unique_ptr<app_list::SearchResult> result =
std::make_unique<app_list::SearchResult>();
result->SetMetadata(std::move(result_metadata));
new_results.push_back(std::move(result));
}
search_model_.PublishResults(std::move(new_results));
}
void AppListControllerImpl::SetItemMetadata(
const std::string& id,
std::unique_ptr<ash::AppListItemMetadata> data) {
app_list::AppListItem* item = model_->FindItem(id);
if (!item)
return;
// data may not contain valid position or icon. Preserve it in this case.
if (!data->position.IsValid())
data->position = item->position();
// Update the item's position and name based on the metadata.
if (!data->position.Equals(item->position()))
model_->SetItemPosition(item, data->position);
if (data->short_name.empty()) {
if (data->name != item->name()) {
model_->SetItemName(item, data->name);
}
} else {
if (data->name != item->name() || data->short_name != item->short_name()) {
model_->SetItemNameAndShortName(item, data->name, data->short_name);
}
}
// Folder icon is generated on ash side and chrome side passes a null
// icon here. Skip it.
if (data->icon.isNull())
data->icon = item->icon();
item->SetMetadata(std::move(data));
}
void AppListControllerImpl::SetItemIcon(const std::string& id,
const gfx::ImageSkia& icon) {
app_list::AppListItem* item = model_->FindItem(id);
if (item)
item->SetIcon(icon);
}
void AppListControllerImpl::SetItemIsInstalling(const std::string& id,
bool is_installing) {
app_list::AppListItem* item = model_->FindItem(id);
if (item)
item->SetIsInstalling(is_installing);
}
void AppListControllerImpl::SetItemPercentDownloaded(
const std::string& id,
int32_t percent_downloaded) {
app_list::AppListItem* item = model_->FindItem(id);
if (item)
item->SetPercentDownloaded(percent_downloaded);
}
void AppListControllerImpl::SetModelData(
int profile_id,
std::vector<std::unique_ptr<ash::AppListItemMetadata>> apps,
bool is_search_engine_google) {
// Clear old model data.
model_->DeleteAllItems();
search_model_.DeleteAllResults();
profile_id_ = profile_id;
// Populate new models. First populate folders and then other items to avoid
// automatically creating folder items in |AddItemToFolder|.
for (auto& app : apps) {
if (!app->is_folder)
continue;
DCHECK(app->folder_id.empty());
AddItem(std::move(app));
}
for (auto& app : apps) {
if (!app)
continue;
AddItem(std::move(app));
}
search_model_.SetSearchEngineIsGoogle(is_search_engine_google);
}
void AppListControllerImpl::SetSearchResultMetadata(
std::unique_ptr<ash::SearchResultMetadata> metadata) {
app_list::SearchResult* result = search_model_.FindSearchResult(metadata->id);
if (result)
result->SetMetadata(std::move(metadata));
}
void AppListControllerImpl::SetSearchResultIsInstalling(const std::string& id,
bool is_installing) {
app_list::SearchResult* result = search_model_.FindSearchResult(id);
if (result)
result->SetIsInstalling(is_installing);
}
void AppListControllerImpl::SetSearchResultPercentDownloaded(
const std::string& id,
int32_t percent_downloaded) {
app_list::SearchResult* result = search_model_.FindSearchResult(id);
if (result)
result->SetPercentDownloaded(percent_downloaded);
}
void AppListControllerImpl::NotifySearchResultItemInstalled(
const std::string& id) {
app_list::SearchResult* result = search_model_.FindSearchResult(id);
if (result)
result->NotifyItemInstalled();
}
void AppListControllerImpl::GetIdToAppListIndexMap(
GetIdToAppListIndexMapCallback callback) {
base::flat_map<std::string, uint16_t> id_to_app_list_index;
for (size_t i = 0; i < model_->top_level_item_list()->item_count(); ++i)
id_to_app_list_index[model_->top_level_item_list()->item_at(i)->id()] = i;
std::move(callback).Run(id_to_app_list_index);
}
void AppListControllerImpl::FindOrCreateOemFolder(
const std::string& oem_folder_name,
const syncer::StringOrdinal& preferred_oem_position,
FindOrCreateOemFolderCallback callback) {
app_list::AppListFolderItem* oem_folder =
model_->FindFolderItem(kOemFolderId);
if (!oem_folder) {
std::unique_ptr<app_list::AppListFolderItem> new_folder =
std::make_unique<app_list::AppListFolderItem>(kOemFolderId);
syncer::StringOrdinal oem_position = preferred_oem_position.IsValid()
? preferred_oem_position
: GetOemFolderPos();
// Do not create a sync item for the OEM folder here, do it in
// ResolveFolderPositions() when the item position is finalized.
oem_folder = static_cast<app_list::AppListFolderItem*>(
model_->AddItem(std::move(new_folder)));
model_->SetItemPosition(oem_folder, oem_position);
}
model_->SetItemName(oem_folder, oem_folder_name);
std::move(callback).Run();
}
void AppListControllerImpl::ResolveOemFolderPosition(
const syncer::StringOrdinal& preferred_oem_position,
ResolveOemFolderPositionCallback callback) {
// In ash:
app_list::AppListFolderItem* ash_oem_folder = FindFolderItem(kOemFolderId);
std::unique_ptr<ash::AppListItemMetadata> metadata;
if (ash_oem_folder) {
const syncer::StringOrdinal& oem_folder_pos =
preferred_oem_position.IsValid() ? preferred_oem_position
: GetOemFolderPos();
model_->SetItemPosition(ash_oem_folder, oem_folder_pos);
metadata = ash_oem_folder->CloneMetadata();
}
std::move(callback).Run(std::move(metadata));
}
void AppListControllerImpl::DismissAppList() {
presenter_.Dismiss(base::TimeTicks());
}
void AppListControllerImpl::GetAppInfoDialogBounds(
GetAppInfoDialogBoundsCallback callback) {
app_list::AppListView* app_list_view = presenter_.GetView();
gfx::Rect bounds = gfx::Rect();
if (app_list_view)
bounds = app_list_view->GetAppInfoDialogBounds();
std::move(callback).Run(bounds);
}
void AppListControllerImpl::ShowAppListAndSwitchToState(
ash::AppListState state) {
bool app_list_was_open = true;
app_list::AppListView* app_list_view = presenter_.GetView();
if (!app_list_view) {
// TODO(calamity): This may cause the app list to show briefly before the
// state change. If this becomes an issue, add the ability to ash::Shell to
// load the app list without showing it.
presenter_.Show(GetDisplayIdToShowAppListOn(), base::TimeTicks());
app_list_was_open = false;
app_list_view = presenter_.GetView();
DCHECK(app_list_view);
}
if (state == ash::AppListState::kInvalidState)
return;
app_list::ContentsView* contents_view =
app_list_view->app_list_main_view()->contents_view();
contents_view->SetActiveState(state, app_list_was_open /* animate */);
}
void AppListControllerImpl::ShowAppList() {
presenter_.Show(GetDisplayIdToShowAppListOn(), base::TimeTicks());
}
////////////////////////////////////////////////////////////////////////////////
// app_list::AppListModelObserver:
void AppListControllerImpl::OnAppListItemAdded(app_list::AppListItem* item) {
if (item->is_folder())
client_->OnFolderCreated(profile_id_, item->CloneMetadata());
else if (item->is_page_break())
client_->OnPageBreakItemAdded(profile_id_, item->id(), item->position());
}
void AppListControllerImpl::OnActiveUserPrefServiceChanged(
PrefService* /* pref_service */) {
if (!IsHomeScreenAvailable()) {
DismissAppList();
return;
}
// Show the app list after signing in in tablet mode.
Show(GetDisplayIdToShowAppListOn(), app_list::AppListShowSource::kTabletMode,
base::TimeTicks());
// The app list is not dismissed before switching user, suggestion chips will
// not be shown. So reset app list state and trigger an initial search here to
// update the suggestion results.
presenter_.GetView()->CloseOpenedPage();
presenter_.GetView()->search_box_view()->ClearSearch();
}
void AppListControllerImpl::OnAppListItemWillBeDeleted(
app_list::AppListItem* item) {
if (!client_)
return;
if (item->is_folder())
client_->OnFolderDeleted(profile_id_, item->CloneMetadata());
if (item->is_page_break())
client_->OnPageBreakItemDeleted(profile_id_, item->id());
}
void AppListControllerImpl::OnAppListItemUpdated(app_list::AppListItem* item) {
if (client_)
client_->OnItemUpdated(profile_id_, item->CloneMetadata());
}
void AppListControllerImpl::OnAppListStateChanged(ash::AppListState new_state,
ash::AppListState old_state) {
if (!app_list_features::IsEmbeddedAssistantUIEnabled())
return;
UpdateLauncherContainer();
if (new_state == ash::AppListState::kStateEmbeddedAssistant) {
// ShowUi will be no-op if the AssistantUiModel is already visible.
Shell::Get()->assistant_controller()->ui_controller()->ShowUi(
ash::AssistantEntryPoint::kUnspecified);
return;
}
if (old_state == ash::AppListState::kStateEmbeddedAssistant) {
// CloseUi will be no-op if the AssistantUiModel is already closed.
Shell::Get()->assistant_controller()->ui_controller()->CloseUi(
ash::AssistantExitPoint::kBackInLauncher);
}
}
////////////////////////////////////////////////////////////////////////////////
// Methods used in Ash
bool AppListControllerImpl::GetTargetVisibility() const {
return presenter_.GetTargetVisibility();
}
bool AppListControllerImpl::IsVisible() const {
return presenter_.IsVisible();
}
void AppListControllerImpl::Show(int64_t display_id,
app_list::AppListShowSource show_source,
base::TimeTicks event_time_stamp) {
UMA_HISTOGRAM_ENUMERATION(app_list::kAppListToggleMethodHistogram,
show_source);
if (!presenter_.GetTargetVisibility() && IsVisible()) {
// The launcher is running close animation, so close it immediately before
// reshow the launcher in tablet mode.
presenter_.GetView()->GetWidget()->CloseNow();
}
presenter_.Show(display_id, event_time_stamp);
// AppListControllerImpl::Show is called in ash at the first time of showing
// app list view. So check whether the expand arrow view should be visible.
UpdateExpandArrowVisibility();
}
void AppListControllerImpl::UpdateYPositionAndOpacity(
int y_position_in_screen,
float background_opacity) {
// Avoid changing app list opacity and position when homecher is enabled.
if (IsHomeScreenAvailable())
return;
presenter_.UpdateYPositionAndOpacity(y_position_in_screen,
background_opacity);
}
void AppListControllerImpl::EndDragFromShelf(
ash::AppListViewState app_list_state) {
// Avoid dragging app list when homecher is enabled.
if (IsHomeScreenAvailable())
return;
presenter_.EndDragFromShelf(app_list_state);
}
void AppListControllerImpl::ProcessMouseWheelEvent(
const ui::MouseWheelEvent& event) {
presenter_.ProcessMouseWheelOffset(event.offset());
}
ash::ShelfAction AppListControllerImpl::ToggleAppList(
int64_t display_id,
app_list::AppListShowSource show_source,
base::TimeTicks event_time_stamp) {
ash::ShelfAction action =
presenter_.ToggleAppList(display_id, show_source, event_time_stamp);
if (action == SHELF_ACTION_APP_LIST_SHOWN) {
UMA_HISTOGRAM_ENUMERATION(app_list::kAppListToggleMethodHistogram,
show_source);
}
return action;
}
ash::AppListViewState AppListControllerImpl::GetAppListViewState() {
return model_->state_fullscreen();
}
void AppListControllerImpl::OnShellDestroying() {
// Stop observing at the beginning of ~Shell to avoid unnecessary work during
// Shell shutdown.
Shutdown();
}
void AppListControllerImpl::OnOverviewModeStarting() {
if (!IsHomeScreenAvailable())
DismissAppList();
}
void AppListControllerImpl::OnTabletModeStarted() {
presenter_.OnTabletModeChanged(true);
// Show the app list if the tablet mode starts.
Shell::Get()->home_screen_controller()->Show();
UpdateLauncherContainer();
}
void AppListControllerImpl::OnTabletModeEnded() {
base::Optional<app_list::AppListPresenterImpl::ScopedDismissAnimationDisabler>
dismiss_animation_disabler;
aura::Window* window = presenter_.GetWindow();
if (window && RootWindowController::ForWindow(window)
->GetShelfLayoutManager()
->HasVisibleWindow()) {
dismiss_animation_disabler.emplace(presenter());
}
presenter_.OnTabletModeChanged(false);
// Dismiss the app list if the tablet mode ends.
DismissAppList();
UpdateLauncherContainer();
}
void AppListControllerImpl::OnWallpaperColorsChanged() {
if (IsVisible())
presenter_.GetView()->OnWallpaperColorsChanged();
}
void AppListControllerImpl::OnKeyboardVisibilityStateChanged(
const bool is_visible) {
onscreen_keyboard_shown_ = is_visible;
app_list::AppListView* app_list_view = presenter_.GetView();
if (app_list_view)
app_list_view->OnScreenKeyboardShown(is_visible);
}
void AppListControllerImpl::OnVoiceInteractionStatusChanged(
mojom::VoiceInteractionState state) {
UpdateAssistantVisibility();
}
void AppListControllerImpl::OnVoiceInteractionSettingsEnabled(bool enabled) {
UpdateAssistantVisibility();
}
void AppListControllerImpl::OnAssistantFeatureAllowedChanged(
mojom::AssistantAllowedState state) {
UpdateAssistantVisibility();
}
void AppListControllerImpl::OnDisplayConfigurationChanged() {
// Entering tablet mode triggers a display configuration change when we
// automatically switch to mirror mode. Switching to mirror mode happens
// asynchronously (see DisplayConfigurationObserver::OnTabletModeStarted()).
// This may result in the removal of a window tree host, as in the example of
// switching to tablet mode while Unified Desktop mode is on; the Unified host
// will be destroyed and the Home Launcher (which was created earlier when we
// entered tablet mode) will be dismissed.
// To avoid crashes, we must ensure that the Home Launcher shown status is as
// expected if it's enabled and we're still in tablet mode.
// https://crbug.com/900956.
const bool should_be_shown = IsTabletMode();
DCHECK_EQ(should_be_shown, IsHomeScreenAvailable());
if (should_be_shown == GetTargetVisibility())
return;
if (should_be_shown)
Shell::Get()->home_screen_controller()->Show();
}
void AppListControllerImpl::OnWindowUntracked(aura::Window* untracked_window) {
UpdateExpandArrowVisibility();
}
void AppListControllerImpl::OnAssistantReady() {
UpdateAssistantVisibility();
}
void AppListControllerImpl::OnUiVisibilityChanged(
AssistantVisibility new_visibility,
AssistantVisibility old_visibility,
base::Optional<AssistantEntryPoint> entry_point,
base::Optional<AssistantExitPoint> exit_point) {
switch (new_visibility) {
case AssistantVisibility::kVisible:
if (!IsVisible()) {
Show(GetDisplayIdToShowAppListOn(), app_list::kAssistantEntryPoint,
base::TimeTicks());
}
if (!IsShowingEmbeddedAssistantUI()) {
if (presenter_.GetView()->app_list_state() ==
ash::AppListViewState::kPeeking) {
presenter_.GetView()->SetState(ash::AppListViewState::kHalf);
}
presenter_.ShowEmbeddedAssistantUI(true);
}
break;
case AssistantVisibility::kHidden:
NOTREACHED();
break;
case AssistantVisibility::kClosed:
if (!IsShowingEmbeddedAssistantUI())
break;
// Reset model state.
// When Launcher is closing, we do not want to call
// |ShowEmbeddedAssistantUI(false)|, which will show previous state page
// in Launcher and make the Ui flashing.
if (IsHomeScreenAvailable()) {
presenter_.ShowEmbeddedAssistantUI(false);
presenter_.GetView()->app_list_main_view()->ResetForShow();
presenter_.GetView()->SetState(
ash::AppListViewState::kFullscreenAllApps);
} else if (exit_point != AssistantExitPoint::kBackInLauncher) {
DismissAppList();
}
break;
}
}
void AppListControllerImpl::OnHomeLauncherAnimationComplete(
bool shown,
int64_t display_id) {
CloseAssistantUi(shown ? AssistantExitPoint::kLauncherOpen
: AssistantExitPoint::kLauncherClose);
}
void AppListControllerImpl::ShowHomeScreenView() {
DCHECK(IsTabletMode());
Show(GetDisplayIdToShowAppListOn(), app_list::kTabletMode, base::TimeTicks());
}
aura::Window* AppListControllerImpl::GetHomeScreenWindow() {
return presenter_.GetWindow();
}
void AppListControllerImpl::UpdateYPositionAndOpacityForHomeLauncher(
int y_position_in_screen,
float opacity,
UpdateAnimationSettingsCallback callback) {
presenter_.UpdateYPositionAndOpacityForHomeLauncher(
y_position_in_screen, opacity, std::move(callback));
}
void AppListControllerImpl::UpdateAfterHomeLauncherShown() {
// Show or hide the expand arrow view.
UpdateExpandArrowVisibility();
}
base::Optional<base::TimeDelta>
AppListControllerImpl::GetOptionalAnimationDuration() {
if (model_->state() == ash::AppListState::kStateEmbeddedAssistant) {
// If Assistant is shown, we don't want any delay in animation transitions
// since the launcher is already shown.
return base::TimeDelta::Min();
}
return base::nullopt;
}
bool AppListControllerImpl::ShouldShowShelfOnHomeScreen() const {
return true;
}
bool AppListControllerImpl::ShouldShowStatusAreaOnHomeScreen() const {
return true;
}
void AppListControllerImpl::Back() {
presenter_.GetView()->Back();
}
void AppListControllerImpl::SetKeyboardTraversalMode(bool engaged) {
if (keyboard_traversal_engaged_ == engaged)
return;
keyboard_traversal_engaged_ = engaged;
views::View* focused_view =
presenter_.GetView()->GetFocusManager()->GetFocusedView();
if (!focused_view)
return;
// When the search box has focus, it is actually the textfield that has focus.
// As such, the |SearchBoxView| must be told to repaint directly.
if (focused_view == presenter_.GetView()->search_box_view()->search_box())
presenter_.GetView()->search_box_view()->SchedulePaint();
else
focused_view->SchedulePaint();
}
ash::ShelfAction AppListControllerImpl::OnAppListButtonPressed(
int64_t display_id,
app_list::AppListShowSource show_source,
base::TimeTicks event_time_stamp) {
if (!IsHomeScreenAvailable())
return ToggleAppList(display_id, show_source, event_time_stamp);
bool handled = Shell::Get()->home_screen_controller()->GoHome(display_id);
// Perform the "back" action for the app list.
if (!handled)
Back();
return ash::SHELF_ACTION_APP_LIST_SHOWN;
}
bool AppListControllerImpl::IsShowingEmbeddedAssistantUI() const {
return presenter_.IsShowingEmbeddedAssistantUI();
}
void AppListControllerImpl::UpdateExpandArrowVisibility() {
bool should_show = false;
// Hide the expand arrow view when the home screen is available and there is
// no activatable window.
if (IsHomeScreenAvailable()) {
should_show = !ash::Shell::Get()
->mru_window_tracker()
->BuildWindowForCycleList()
.empty();
} else {
should_show = true;
}
presenter_.SetExpandArrowViewVisibility(should_show);
}
ash::AppListViewState AppListControllerImpl::CalculateStateAfterShelfDrag(
const ui::GestureEvent& gesture_in_screen,
float launcher_above_shelf_bottom_amount) const {
if (presenter_.GetView())
return presenter_.GetView()->CalculateStateAfterShelfDrag(
gesture_in_screen, launcher_above_shelf_bottom_amount);
return ash::AppListViewState::kClosed;
}
void AppListControllerImpl::SetAppListModelForTest(
std::unique_ptr<app_list::AppListModel> model) {
model_->RemoveObserver(this);
model_ = std::move(model);
model_->AddObserver(this);
}
void AppListControllerImpl::SetStateTransitionAnimationCallback(
StateTransitionAnimationCallback callback) {
state_transition_animation_callback_ = std::move(callback);
}
void AppListControllerImpl::RecordShelfAppLaunched(
base::Optional<AppListViewState> recorded_app_list_view_state,
base::Optional<bool> recorded_home_launcher_shown) {
app_list::RecordAppListAppLaunched(
AppListLaunchedFrom::kLaunchedFromShelf,
recorded_app_list_view_state.value_or(GetAppListViewState()),
IsTabletMode(),
recorded_home_launcher_shown.value_or(presenter_.home_launcher_shown()));
}
////////////////////////////////////////////////////////////////////////////////
// Methods of |client_|:
void AppListControllerImpl::StartAssistant() {
if (app_list_features::IsEmbeddedAssistantUIEnabled()) {
ash::Shell::Get()->assistant_controller()->ui_controller()->ShowUi(
ash::AssistantEntryPoint::kLauncherSearchBoxMic);
return;
}
if (!IsHomeScreenAvailable())
DismissAppList();
ash::Shell::Get()->assistant_controller()->ui_controller()->ShowUi(
ash::AssistantEntryPoint::kLauncherSearchBox);
}
void AppListControllerImpl::StartSearch(const base::string16& raw_query) {
if (client_) {
base::string16 query;
base::TrimWhitespace(raw_query, base::TRIM_ALL, &query);
client_->StartSearch(query);
}
}
void AppListControllerImpl::OpenSearchResult(const std::string& result_id,
int event_flags,
AppListLaunchedFrom launched_from,
AppListLaunchType launch_type,
int suggestion_index) {
app_list::SearchResult* result = search_model_.FindSearchResult(result_id);
if (!result)
return;
if (launch_type == AppListLaunchType::kAppSearchResult) {
switch (launched_from) {
case AppListLaunchedFrom::kLaunchedFromSearchBox:
case AppListLaunchedFrom::kLaunchedFromSuggestionChip:
RecordAppLaunched(launched_from);
break;
case AppListLaunchedFrom::kLaunchedFromGrid:
case AppListLaunchedFrom::kLaunchedFromShelf:
break;
}
}
UMA_HISTOGRAM_ENUMERATION(app_list::kSearchResultOpenDisplayTypeHistogram,
result->display_type(),
ash::SearchResultDisplayType::kLast);
// Suggestion chips are not represented to the user as search results, so do
// not record search result metrics for them.
if (launched_from != AppListLaunchedFrom::kLaunchedFromSuggestionChip) {
base::RecordAction(base::UserMetricsAction("AppList_OpenSearchResult"));
UMA_HISTOGRAM_COUNTS_100(app_list::kSearchQueryLength,
GetLastQueryLength());
if (IsTabletMode()) {
UMA_HISTOGRAM_COUNTS_100(app_list::kSearchQueryLengthInTablet,
GetLastQueryLength());
} else {
UMA_HISTOGRAM_COUNTS_100(app_list::kSearchQueryLengthInClamshell,
GetLastQueryLength());
}
if (result->distance_from_origin() >= 0) {
UMA_HISTOGRAM_COUNTS_100(app_list::kSearchResultDistanceFromOrigin,
result->distance_from_origin());
}
}
if (presenter_.IsVisible() && result->is_omnibox_search() &&
IsAssistantAllowedAndEnabled() &&
app_list_features::IsEmbeddedAssistantUIEnabled()) {
// Record the assistant result. Other types of results are recorded in
// |client_| where there is richer data on SearchResultType.
DCHECK_EQ(AppListLaunchedFrom::kLaunchedFromSearchBox, launched_from)
<< "Only log search results which are represented to the user as "
"search results (ie. search results in the search result page) not "
"chips.";
app_list::RecordSearchResultOpenTypeHistogram(
launched_from, app_list::ASSISTANT_OMNIBOX_RESULT, IsTabletMode());
Shell::Get()->assistant_controller()->ui_controller()->ShowUi(
AssistantEntryPoint::kLauncherSearchResult);
Shell::Get()->assistant_controller()->OpenUrl(
ash::assistant::util::CreateAssistantQueryDeepLink(
base::UTF16ToUTF8(result->title())));
} else {
if (client_)
client_->OpenSearchResult(result_id, event_flags, launched_from,
launch_type, suggestion_index);
}
ResetHomeLauncherIfShown();
}
void AppListControllerImpl::LogResultLaunchHistogram(
app_list::SearchResultLaunchLocation launch_location,
int suggestion_index) {
app_list::RecordSearchLaunchIndexAndQueryLength(
launch_location, GetLastQueryLength(), suggestion_index);
}
void AppListControllerImpl::LogSearchAbandonHistogram() {
app_list::RecordSearchAbandonWithQueryLengthHistogram(GetLastQueryLength());
}
void AppListControllerImpl::InvokeSearchResultAction(
const std::string& result_id,
int action_index,
int event_flags) {
if (client_)
client_->InvokeSearchResultAction(result_id, action_index, event_flags);
}
void AppListControllerImpl::GetSearchResultContextMenuModel(
const std::string& result_id,
GetContextMenuModelCallback callback) {
if (client_)
client_->GetSearchResultContextMenuModel(result_id, std::move(callback));
}
void AppListControllerImpl::ViewShown(int64_t display_id) {
if (app_list_features::IsEmbeddedAssistantUIEnabled() &&
GetAssistantViewDelegate()->GetUiModel()->ui_mode() !=
ash::AssistantUiMode::kLauncherEmbeddedUi) {
CloseAssistantUi(AssistantExitPoint::kLauncherOpen);
}
UpdateAssistantVisibility();
if (client_)
client_->ViewShown(display_id);
// Ensure search box starts fresh with no ring each time it opens.
keyboard_traversal_engaged_ = false;
}