shell_tab_handler.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "shell_tab_handler.h"
  5. #include "ash/capture_mode/capture_mode_util.h"
  6. #include "ash/focus_cycler.h"
  7. #include "ash/shelf/shelf.h"
  8. #include "ash/shelf/shelf_navigation_widget.h"
  9. #include "ash/shell.h"
  10. #include "ash/system/status_area_widget.h"
  11. #include "ash/wm/tablet_mode/tablet_mode_controller.h"
  12. #include "ash/wm/window_util.h"
  13. #include "ui/events/event.h"
  14. #include "ui/wm/public/activation_client.h"
  15. namespace ash {
  16. void ShellTabHandler::OnKeyEvent(ui::KeyEvent* key_event) {
  17. // Only focus the shelf if the device is in clamshell mode, and the user
  18. // pressed tab.
  19. if (key_event->key_code() != ui::KeyboardCode::VKEY_TAB ||
  20. key_event->type() != ui::EventType::ET_KEY_PRESSED ||
  21. key_event->IsAltDown() || key_event->IsControlDown() ||
  22. key_event->IsCommandDown() ||
  23. shell_->tablet_mode_controller()->InTabletMode()) {
  24. return;
  25. }
  26. // Capture session will process their own tab events.
  27. if (capture_mode_util::IsCaptureModeActive())
  28. return;
  29. aura::Window* root_window_for_new_windows =
  30. Shell::GetRootWindowForNewWindows();
  31. if (!root_window_for_new_windows || window_util::GetActiveWindow())
  32. return;
  33. // If there is no active window, focus the HomeButton or StatusWidget,
  34. // depending on whether this is Tab or Shift + Tab. This will allow the
  35. // users focus to traverse the shelf.
  36. auto* shelf = Shelf::ForWindow(root_window_for_new_windows);
  37. views::Widget* status_area_widget = shelf->status_area_widget();
  38. views::Widget* navigation_widget = shelf->navigation_widget();
  39. shell_->focus_cycler()->FocusWidget(
  40. key_event->IsShiftDown() ? status_area_widget : navigation_widget);
  41. key_event->SetHandled();
  42. key_event->StopPropagation();
  43. }
  44. } // namespace ash