Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: ash/accelerators/accelerator_controller.cc

Issue 594383002: Change behaviour of the Alt-] and Alt-[ keys so that it cycles through SnapLeft/SnapRight to DockLe… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@event
Patch Set: Address varkha's comments on patch set 5 Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/accelerators/accelerator_controller.h" 5 #include "ash/accelerators/accelerator_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 10
(...skipping 26 matching lines...) Expand all
37 #include "ash/shell_window_ids.h" 37 #include "ash/shell_window_ids.h"
38 #include "ash/system/brightness_control_delegate.h" 38 #include "ash/system/brightness_control_delegate.h"
39 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" 39 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
40 #include "ash/system/status_area_widget.h" 40 #include "ash/system/status_area_widget.h"
41 #include "ash/system/tray/system_tray.h" 41 #include "ash/system/tray/system_tray.h"
42 #include "ash/system/tray/system_tray_delegate.h" 42 #include "ash/system/tray/system_tray_delegate.h"
43 #include "ash/system/tray/system_tray_notifier.h" 43 #include "ash/system/tray/system_tray_notifier.h"
44 #include "ash/system/web_notification/web_notification_tray.h" 44 #include "ash/system/web_notification/web_notification_tray.h"
45 #include "ash/touch/touch_hud_debug.h" 45 #include "ash/touch/touch_hud_debug.h"
46 #include "ash/volume_control_delegate.h" 46 #include "ash/volume_control_delegate.h"
47 #include "ash/wm/dock/docked_window_layout_manager.h"
47 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 48 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
48 #include "ash/wm/mru_window_tracker.h" 49 #include "ash/wm/mru_window_tracker.h"
49 #include "ash/wm/overview/window_selector_controller.h" 50 #include "ash/wm/overview/window_selector_controller.h"
50 #include "ash/wm/partial_screenshot_view.h" 51 #include "ash/wm/partial_screenshot_view.h"
51 #include "ash/wm/power_button_controller.h" 52 #include "ash/wm/power_button_controller.h"
53 #include "ash/wm/window_animations.h"
52 #include "ash/wm/window_cycle_controller.h" 54 #include "ash/wm/window_cycle_controller.h"
53 #include "ash/wm/window_state.h" 55 #include "ash/wm/window_state.h"
54 #include "ash/wm/window_util.h" 56 #include "ash/wm/window_util.h"
55 #include "ash/wm/wm_event.h" 57 #include "ash/wm/wm_event.h"
56 #include "base/bind.h" 58 #include "base/bind.h"
57 #include "base/command_line.h" 59 #include "base/command_line.h"
58 #include "base/metrics/user_metrics.h" 60 #include "base/metrics/user_metrics.h"
59 #include "ui/aura/env.h" 61 #include "ui/aura/env.h"
60 #include "ui/aura/window_event_dispatcher.h" 62 #include "ui/aura/window_event_dispatcher.h"
61 #include "ui/base/accelerators/accelerator.h" 63 #include "ui/base/accelerators/accelerator.h"
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 } 497 }
496 accelerators::ToggleFullscreen(); 498 accelerators::ToggleFullscreen();
497 return true; 499 return true;
498 } 500 }
499 501
500 bool HandleToggleRootWindowFullScreen() { 502 bool HandleToggleRootWindowFullScreen() {
501 Shell::GetPrimaryRootWindowController()->ash_host()->ToggleFullScreen(); 503 Shell::GetPrimaryRootWindowController()->ash_host()->ToggleFullScreen();
502 return true; 504 return true;
503 } 505 }
504 506
505 bool HandleWindowSnap(int action) { 507 DockedWindowLayoutManager* GetDockedWindowLayoutManager()
508 {
509 aura::Window* active_window = ash::wm::GetActiveWindow();
510 if (active_window) {
511 aura::Window* dock_container = Shell::GetContainer(
512 active_window->GetRootWindow(), kShellWindowId_DockedContainer);
513 DockedWindowLayoutManager* dock_layout =
514 static_cast<DockedWindowLayoutManager*>(
515 dock_container->layout_manager());
516 return dock_layout;
517 }
518 return NULL;
519 }
520
521 class ScopedPreferredAlignmentResetter {
522 public:
523 ScopedPreferredAlignmentResetter(DockedAlignment dock_alignment)
524 : docked_window_layout_manager_(GetDockedWindowLayoutManager()) {
525 docked_window_layout_manager_->set_preferred_alignment(dock_alignment);
526 }
527 ~ScopedPreferredAlignmentResetter() {
528 docked_window_layout_manager_->set_preferred_alignment(
529 DOCKED_ALIGNMENT_NONE);
530 }
531
532 private:
533 DISALLOW_COPY_AND_ASSIGN(ScopedPreferredAlignmentResetter);
534 DockedWindowLayoutManager* docked_window_layout_manager_;
535 };
536
537 void RestoreWindow() {
538 wm::WindowState* window_state = wm::GetActiveWindowState();
539 if (!window_state)
540 return;
541
542 base::RecordAction(UserMetricsAction("Accel_Window_Restore"));
543 const wm::WMEvent event(wm::WM_EVENT_NORMAL);
544 window_state->OnWMEvent(&event);
545 }
546
547 void DockWindow(DockedAlignment dock_alignment) {
548 wm::WindowState* window_state = wm::GetActiveWindowState();
549 if (!window_state)
550 return;
551
552 if (window_state->IsDocked()) {
553 GetDockedWindowLayoutManager()->RequestDesiredDockedAlignment(
554 dock_alignment);
555 return;
556 }
557
558 ScopedPreferredAlignmentResetter alignmentResetter(dock_alignment);
559 base::RecordAction(UserMetricsAction(dock_alignment == DOCKED_ALIGNMENT_LEFT ?
560 "Accel_Window_Dock_Left" : "Accel_Window_Dock_Right"));
561 const wm::WMEvent event(wm::WM_EVENT_DOCK);
562 window_state->OnWMEvent(&event);
563 }
564
565 void SnapWindow(wm::WMEventType event_type) {
566 wm::WindowState* window_state = wm::GetActiveWindowState();
567 if (!window_state)
568 return;
569 base::RecordAction(UserMetricsAction(event_type == wm::WM_EVENT_SNAP_LEFT ?
570 "Accel_Window_Snap_Left" :
571 "Accel_Window_Snap_Right"));
572 const wm::WMEvent event(event_type);
573 window_state->OnWMEvent(&event);
574 }
575
576 bool CanDock(DockedAlignment desired_alignment) {
577 aura::Window* active_window = ash::wm::GetActiveWindow();
578 DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager();
579 if (dock_layout)
580 return dock_layout->CanDockWindow(active_window, desired_alignment);
581 return false;
582 }
583
584 DockedAlignment CurrentDockAlignment() {
585 DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager();
586 if (dock_layout)
587 return dock_layout->CalculateAlignment();
588 return DOCKED_ALIGNMENT_NONE;
589 }
590
591 bool HandleWindowSnapOrDock(int action) {
506 wm::WindowState* window_state = wm::GetActiveWindowState(); 592 wm::WindowState* window_state = wm::GetActiveWindowState();
507 // Disable window snapping shortcut key for full screen window due to 593 // Disable window snapping shortcut key for full screen window due to
508 // http://crbug.com/135487. 594 // http://crbug.com/135487.
509 if (!window_state || 595 if (!window_state ||
510 window_state->window()->type() != ui::wm::WINDOW_TYPE_NORMAL || 596 (window_state->window()->type() != ui::wm::WINDOW_TYPE_NORMAL &&
511 window_state->IsFullscreen() || 597 window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) ||
512 !window_state->CanSnap()) { 598 window_state->IsFullscreen()) {
513 return false; 599 return false;
514 } 600 }
515 601
516 if (action == WINDOW_SNAP_LEFT) { 602 wm::WindowStateType desired_snap_state = action == WINDOW_SNAP_OR_DOCK_LEFT ?
517 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left")); 603 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED;
518 } else { 604 DockedAlignment desired_dock_alignment = action == WINDOW_SNAP_OR_DOCK_LEFT ?
519 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right")); 605 DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT;
606 DockedAlignment current_dock_alignment = CurrentDockAlignment();
607
608 if (!window_state->IsDocked() ||
609 (current_dock_alignment != DOCKED_ALIGNMENT_NONE &&
610 current_dock_alignment != desired_dock_alignment)) {
611 if (window_state->CanSnap() &&
612 window_state->GetStateType() != desired_snap_state &&
613 window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) {
614 SnapWindow(desired_snap_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ?
615 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT);
616 return true;
617 }
618
619 if (CanDock(desired_dock_alignment)) {
620 DockWindow(desired_dock_alignment);
621 return true;
622 }
520 } 623 }
521 const wm::WMEvent event(action == WINDOW_SNAP_LEFT ? 624
522 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); 625 if (window_state->IsDocked() || window_state->IsSnapped()) {
523 window_state->OnWMEvent(&event); 626 RestoreWindow();
524 return true; 627 return true;
628 }
629 ::wm::AnimateWindow(window_state->window(),
630 ::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
varkha 2014/09/30 20:31:03 nit: align with ( above.
dtapuska 2014/10/01 15:02:16 Done.
631 return false;
525 } 632 }
526 633
527 bool HandleWindowMinimize() { 634 bool HandleWindowMinimize() {
528 base::RecordAction( 635 base::RecordAction(
529 base::UserMetricsAction("Accel_Toggle_Minimized_Minus")); 636 base::UserMetricsAction("Accel_Toggle_Minimized_Minus"));
530 return accelerators::ToggleMinimized(); 637 return accelerators::ToggleMinimized();
531 } 638 }
532 639
533 #if defined(OS_CHROMEOS) 640 #if defined(OS_CHROMEOS)
534 bool HandleAddRemoveDisplay() { 641 bool HandleAddRemoveDisplay() {
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 case LAUNCH_APP_4: 1151 case LAUNCH_APP_4:
1045 return HandleLaunchAppN(4); 1152 return HandleLaunchAppN(4);
1046 case LAUNCH_APP_5: 1153 case LAUNCH_APP_5:
1047 return HandleLaunchAppN(5); 1154 return HandleLaunchAppN(5);
1048 case LAUNCH_APP_6: 1155 case LAUNCH_APP_6:
1049 return HandleLaunchAppN(6); 1156 return HandleLaunchAppN(6);
1050 case LAUNCH_APP_7: 1157 case LAUNCH_APP_7:
1051 return HandleLaunchAppN(7); 1158 return HandleLaunchAppN(7);
1052 case LAUNCH_LAST_APP: 1159 case LAUNCH_LAST_APP:
1053 return HandleLaunchLastApp(); 1160 return HandleLaunchLastApp();
1054 case WINDOW_SNAP_LEFT: 1161 case WINDOW_SNAP_OR_DOCK_LEFT:
1055 case WINDOW_SNAP_RIGHT: 1162 case WINDOW_SNAP_OR_DOCK_RIGHT:
1056 return HandleWindowSnap(action); 1163 return HandleWindowSnapOrDock(action);
1057 case WINDOW_MINIMIZE: 1164 case WINDOW_MINIMIZE:
1058 return HandleWindowMinimize(); 1165 return HandleWindowMinimize();
1059 case TOGGLE_FULLSCREEN: 1166 case TOGGLE_FULLSCREEN:
1060 return HandleToggleFullscreen(key_code); 1167 return HandleToggleFullscreen(key_code);
1061 case TOGGLE_MAXIMIZED: 1168 case TOGGLE_MAXIMIZED:
1062 accelerators::ToggleMaximized(); 1169 accelerators::ToggleMaximized();
1063 return true; 1170 return true;
1064 case WINDOW_POSITION_CENTER: 1171 case WINDOW_POSITION_CENTER:
1065 return HandlePositionCenter(); 1172 return HandlePositionCenter();
1066 case SCALE_UI_UP: 1173 case SCALE_UI_UP:
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 keyboard_brightness_control_delegate) { 1324 keyboard_brightness_control_delegate) {
1218 keyboard_brightness_control_delegate_ = 1325 keyboard_brightness_control_delegate_ =
1219 keyboard_brightness_control_delegate.Pass(); 1326 keyboard_brightness_control_delegate.Pass();
1220 } 1327 }
1221 1328
1222 bool AcceleratorController::CanHandleAccelerators() const { 1329 bool AcceleratorController::CanHandleAccelerators() const {
1223 return true; 1330 return true;
1224 } 1331 }
1225 1332
1226 } // namespace ash 1333 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/accelerators/accelerator_controller_unittest.cc » ('j') | ash/wm/dock/docked_window_layout_manager.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698