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

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 DockLeft/DockRight issues 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_->SetPreferredAlignment(dock_alignment);
526 }
527 ~ScopedPreferredAlignmentResetter() {
528 docked_window_layout_manager_->SetPreferredAlignment(DOCKED_ALIGNMENT_NONE);
529 }
530
531 private:
532 DISALLOW_COPY_AND_ASSIGN(ScopedPreferredAlignmentResetter);
533 DockedWindowLayoutManager* docked_window_layout_manager_;
534 };
535
536 void RestoreWindow() {
537 wm::WindowState* window_state = wm::GetActiveWindowState();
538 if (!window_state)
539 return;
540
541 base::RecordAction(UserMetricsAction("Accel_Window_Restore"));
542 const wm::WMEvent event(wm::WM_EVENT_NORMAL);
543 window_state->OnWMEvent(&event);
544 }
545
546 void DockWindow(DockedAlignment dock_alignment) {
547 wm::WindowState* window_state = wm::GetActiveWindowState();
548 if (!window_state)
549 return;
550
551 if (window_state->IsDocked()) {
552 GetDockedWindowLayoutManager()->SetDockedAlignment(dock_alignment);
553 return;
554 }
555
556 ScopedPreferredAlignmentResetter alignmentResetter(dock_alignment);
557 base::RecordAction(UserMetricsAction(dock_alignment == DOCKED_ALIGNMENT_LEFT ?
558 "Accel_Window_Dock_Left" : "Accel_Window_Dock_Right"));
559 const wm::WMEvent event(wm::WM_EVENT_DOCK);
560 window_state->OnWMEvent(&event);
561 }
562
563 void SnapWindow(wm::WMEventType event_type) {
564 wm::WindowState* window_state = wm::GetActiveWindowState();
565 if (!window_state)
566 return;
567 base::RecordAction(UserMetricsAction(event_type == wm::WM_EVENT_SNAP_LEFT ?
568 "Accel_Window_Snap_Left" :
569 "Accel_Window_Snap_Right"));
570 const wm::WMEvent event(event_type);
571 window_state->OnWMEvent(&event);
572 }
573
574 bool CanDock(DockedAlignment desired_alignment) {
575 aura::Window* active_window = ash::wm::GetActiveWindow();
576 DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager();
577 if (dock_layout)
578 return dock_layout->CanDockWindow(active_window, desired_alignment);
579 return false;
580 }
581
582 DockedAlignment CurrentDockAlignment() {
583 DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager();
584 if (dock_layout)
585 return dock_layout->CalculateAlignment();
586 return DOCKED_ALIGNMENT_NONE;
587 }
588
589 bool HandleWindowSnapOrDock(int action) {
varkha 2014/09/29 21:04:34 I am not sure it this should be AcceleratorAction
dtapuska 2014/09/30 14:40:49 It appears they wanted to speed up compilation by
varkha 2014/09/30 20:31:03 Acknowledged.
506 wm::WindowState* window_state = wm::GetActiveWindowState(); 590 wm::WindowState* window_state = wm::GetActiveWindowState();
507 // Disable window snapping shortcut key for full screen window due to 591 // Disable window snapping shortcut key for full screen window due to
508 // http://crbug.com/135487. 592 // http://crbug.com/135487.
509 if (!window_state || 593 if (!window_state ||
510 window_state->window()->type() != ui::wm::WINDOW_TYPE_NORMAL || 594 (window_state->window()->type() != ui::wm::WINDOW_TYPE_NORMAL &&
511 window_state->IsFullscreen() || 595 window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) ||
512 !window_state->CanSnap()) { 596 window_state->IsFullscreen()) {
513 return false; 597 return false;
514 } 598 }
515 599
516 if (action == WINDOW_SNAP_LEFT) { 600 wm::WindowStateType desired_snap_state = action == WINDOW_SNAP_OR_DOCK_LEFT ?
517 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left")); 601 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED;
602 DockedAlignment desired_dock_alignment = action == WINDOW_SNAP_OR_DOCK_LEFT ?
603 DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT;
varkha 2014/09/29 21:04:34 nit: alignment +4
dtapuska 2014/09/30 14:40:49 Done.
604 DockedAlignment current_dock_alignment = CurrentDockAlignment();
605
606 if (!window_state->IsDocked() ||
607 (current_dock_alignment != DOCKED_ALIGNMENT_NONE &&
608 current_dock_alignment != desired_dock_alignment)) {
609 if (window_state->CanSnap() &&
610 window_state->GetStateType() != desired_snap_state &&
611 window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) {
612 SnapWindow(desired_snap_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ?
613 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT);
614 return true;
615 }
616
617 if (CanDock(desired_dock_alignment)) {
618 DockWindow(desired_dock_alignment);
619 return true;
620 }
621 }
622
623 if (window_state->IsDocked() || window_state->IsSnapped()) {
624 RestoreWindow();
625 return true;
518 } else { 626 } else {
varkha 2014/09/29 21:04:34 nit: No need for else after return (mentioned in h
dtapuska 2014/09/30 14:40:48 Done.
519 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right")); 627 ::wm::AnimateWindow(window_state->window(),
628 ::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
629 return false;
520 } 630 }
521 const wm::WMEvent event(action == WINDOW_SNAP_LEFT ?
522 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT);
523 window_state->OnWMEvent(&event);
524 return true;
525 } 631 }
526 632
527 bool HandleWindowMinimize() { 633 bool HandleWindowMinimize() {
528 base::RecordAction( 634 base::RecordAction(
529 base::UserMetricsAction("Accel_Toggle_Minimized_Minus")); 635 base::UserMetricsAction("Accel_Toggle_Minimized_Minus"));
530 return accelerators::ToggleMinimized(); 636 return accelerators::ToggleMinimized();
531 } 637 }
532 638
533 #if defined(OS_CHROMEOS) 639 #if defined(OS_CHROMEOS)
534 bool HandleAddRemoveDisplay() { 640 bool HandleAddRemoveDisplay() {
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 case LAUNCH_APP_4: 1150 case LAUNCH_APP_4:
1045 return HandleLaunchAppN(4); 1151 return HandleLaunchAppN(4);
1046 case LAUNCH_APP_5: 1152 case LAUNCH_APP_5:
1047 return HandleLaunchAppN(5); 1153 return HandleLaunchAppN(5);
1048 case LAUNCH_APP_6: 1154 case LAUNCH_APP_6:
1049 return HandleLaunchAppN(6); 1155 return HandleLaunchAppN(6);
1050 case LAUNCH_APP_7: 1156 case LAUNCH_APP_7:
1051 return HandleLaunchAppN(7); 1157 return HandleLaunchAppN(7);
1052 case LAUNCH_LAST_APP: 1158 case LAUNCH_LAST_APP:
1053 return HandleLaunchLastApp(); 1159 return HandleLaunchLastApp();
1054 case WINDOW_SNAP_LEFT: 1160 case WINDOW_SNAP_OR_DOCK_LEFT:
1055 case WINDOW_SNAP_RIGHT: 1161 case WINDOW_SNAP_OR_DOCK_RIGHT:
1056 return HandleWindowSnap(action); 1162 return HandleWindowSnapOrDock(action);
1057 case WINDOW_MINIMIZE: 1163 case WINDOW_MINIMIZE:
1058 return HandleWindowMinimize(); 1164 return HandleWindowMinimize();
1059 case TOGGLE_FULLSCREEN: 1165 case TOGGLE_FULLSCREEN:
1060 return HandleToggleFullscreen(key_code); 1166 return HandleToggleFullscreen(key_code);
1061 case TOGGLE_MAXIMIZED: 1167 case TOGGLE_MAXIMIZED:
1062 accelerators::ToggleMaximized(); 1168 accelerators::ToggleMaximized();
1063 return true; 1169 return true;
1064 case WINDOW_POSITION_CENTER: 1170 case WINDOW_POSITION_CENTER:
1065 return HandlePositionCenter(); 1171 return HandlePositionCenter();
1066 case SCALE_UI_UP: 1172 case SCALE_UI_UP:
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 keyboard_brightness_control_delegate) { 1323 keyboard_brightness_control_delegate) {
1218 keyboard_brightness_control_delegate_ = 1324 keyboard_brightness_control_delegate_ =
1219 keyboard_brightness_control_delegate.Pass(); 1325 keyboard_brightness_control_delegate.Pass();
1220 } 1326 }
1221 1327
1222 bool AcceleratorController::CanHandleAccelerators() const { 1328 bool AcceleratorController::CanHandleAccelerators() const {
1223 return true; 1329 return true;
1224 } 1330 }
1225 1331
1226 } // namespace ash 1332 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698