Commit 9a7f768c authored by Weidong Guo's avatar Weidong Guo Committed by Commit Bot

Apply the same behavior of app list shelf button to search key

Changes:
Extract logic triggered by app list shelf button into common function
which is also used by search key.

Bug: 896895
Change-Id: Ie81ef2aee94cc56270842887c7554297b1a94575
Reviewed-on: https://chromium-review.googlesource.com/c/1313057Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Weidong Guo <weidongg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604971}
parent ea17936a
......@@ -497,15 +497,10 @@ bool CanHandleToggleAppList(const ui::Accelerator& accelerator,
}
void HandleToggleAppList(const ui::Accelerator& accelerator) {
if (Shell::Get()
->app_list_controller()
->IsHomeLauncherEnabledInTabletMode()) {
return;
}
if (accelerator.key_code() == ui::VKEY_LWIN)
base::RecordAction(UserMetricsAction("Accel_Search_LWin"));
Shell::Get()->app_list_controller()->ToggleAppList(
Shell::Get()->app_list_controller()->OnAppListButtonPressed(
display::Screen::GetScreen()
->GetDisplayNearestWindow(Shell::GetRootWindowForNewWindows())
.id(),
......
......@@ -19,18 +19,23 @@
#include "ash/assistant/assistant_ui_controller.h"
#include "ash/public/cpp/app_list/answer_card_contents_registry.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/session/session_controller.h"
#include "ash/shelf/shelf.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/window_selector_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 "extensions/common/constants.h"
#include "ui/base/ui_base_features.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
namespace ash {
......@@ -602,6 +607,61 @@ void AppListControllerImpl::Back() {
presenter_.GetView()->Back();
}
void AppListControllerImpl::OnAppListButtonPressed(
int64_t display_id,
app_list::AppListShowSource show_source,
base::TimeTicks event_time_stamp) {
if (!IsHomeLauncherEnabledInTabletMode()) {
ToggleAppList(display_id, show_source, event_time_stamp);
return;
}
// Whether the this action is handled.
bool handled = false;
if (home_launcher_gesture_handler_) {
handled = home_launcher_gesture_handler_->ShowHomeLauncher(
Shell::Get()->display_manager()->GetDisplayForId(display_id));
}
if (!handled) {
if (Shell::Get()->window_selector_controller()->IsSelecting()) {
// End overview mode.
Shell::Get()->window_selector_controller()->ToggleOverview(
WindowSelector::EnterExitOverviewType::kWindowsMinimized);
handled = true;
}
if (Shell::Get()->split_view_controller()->IsSplitViewModeActive()) {
// End split view mode.
Shell::Get()->split_view_controller()->EndSplitView(
SplitViewController::EndReason::kHomeLauncherPressed);
handled = true;
}
}
if (!handled) {
// Minimize all windows that aren't the app list in reverse order to
// preserve the mru ordering.
aura::Window* app_list_container =
Shell::Get()->GetPrimaryRootWindow()->GetChildById(
kShellWindowId_AppListTabletModeContainer);
aura::Window::Windows windows =
Shell::Get()->mru_window_tracker()->BuildWindowForCycleList();
std::reverse(windows.begin(), windows.end());
for (auto* window : windows) {
if (!app_list_container->Contains(window) &&
!wm::GetWindowState(window)->IsMinimized()) {
wm::GetWindowState(window)->Minimize();
handled = true;
}
}
}
// Perform the "back" action for the app list.
if (!handled)
Back();
}
////////////////////////////////////////////////////////////////////////////////
// Methods of |client_|:
......
......@@ -224,6 +224,15 @@ class ASH_EXPORT AppListControllerImpl
// Performs the 'back' action for the active page.
void Back();
// Handles app list button press event. (Search key should trigger the same
// behavior.) All three parameters are only used in clamshell mode.
// |display_id| is the id of display where app list should toggle.
// |show_source| is the source of the event. |event_time_stamp| records the
// event timestamp.
void OnAppListButtonPressed(int64_t display_id,
app_list::AppListShowSource show_source,
base::TimeTicks event_time_stamp);
private:
syncer::StringOrdinal GetOemFolderPos();
std::unique_ptr<app_list::AppListItem> CreateAppListItem(
......
......@@ -8,18 +8,8 @@
#include <utility>
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/app_list/home_launcher_gesture_handler.h"
#include "ash/public/cpp/app_list/app_list_constants.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/overview/window_selector_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 "ui/display/manager/display_manager.h"
namespace ash {
......@@ -32,62 +22,8 @@ void AppListShelfItemDelegate::ItemSelected(std::unique_ptr<ui::Event> event,
int64_t display_id,
ShelfLaunchSource source,
ItemSelectedCallback callback) {
if (!Shell::Get()
->app_list_controller()
->IsHomeLauncherEnabledInTabletMode()) {
Shell::Get()->app_list_controller()->ToggleAppList(
display_id, app_list::kShelfButton, event->time_stamp());
std::move(callback).Run(SHELF_ACTION_APP_LIST_SHOWN, base::nullopt);
return;
}
// Whether the this action is handled.
bool handled = false;
HomeLauncherGestureHandler* home_launcher_gesture_handler =
Shell::Get()->app_list_controller()->home_launcher_gesture_handler();
if (home_launcher_gesture_handler) {
handled = home_launcher_gesture_handler->ShowHomeLauncher(
Shell::Get()->display_manager()->GetDisplayForId(display_id));
}
if (!handled) {
if (Shell::Get()->window_selector_controller()->IsSelecting()) {
// End overview mode.
Shell::Get()->window_selector_controller()->ToggleOverview(
WindowSelector::EnterExitOverviewType::kWindowsMinimized);
handled = true;
}
if (Shell::Get()->split_view_controller()->IsSplitViewModeActive()) {
// End split view mode.
Shell::Get()->split_view_controller()->EndSplitView(
SplitViewController::EndReason::kHomeLauncherPressed);
handled = true;
}
}
if (!handled) {
// Minimize all windows that aren't the app list in reverse order to
// preserve the mru ordering.
aura::Window* app_list_container =
Shell::Get()->GetPrimaryRootWindow()->GetChildById(
kShellWindowId_AppListTabletModeContainer);
aura::Window::Windows windows =
Shell::Get()->mru_window_tracker()->BuildWindowForCycleList();
std::reverse(windows.begin(), windows.end());
for (auto* window : windows) {
if (!app_list_container->Contains(window) &&
!wm::GetWindowState(window)->IsMinimized()) {
wm::GetWindowState(window)->Minimize();
handled = true;
}
}
}
// Perform the "back" action for the app list.
if (!handled)
Shell::Get()->app_list_controller()->Back();
Shell::Get()->app_list_controller()->OnAppListButtonPressed(
display_id, app_list::kShelfButton, event->time_stamp());
std::move(callback).Run(SHELF_ACTION_APP_LIST_SHOWN, base::nullopt);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment