Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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" |
| 52 #include "ash/wm/window_cycle_controller.h" | 53 #include "ash/wm/window_cycle_controller.h" |
| 53 #include "ash/wm/window_state.h" | 54 #include "ash/wm/window_state.h" |
| 54 #include "ash/wm/window_util.h" | 55 #include "ash/wm/window_util.h" |
| 55 #include "ash/wm/wm_event.h" | 56 #include "ash/wm/wm_event.h" |
| 56 #include "base/bind.h" | 57 #include "base/bind.h" |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 } | 496 } |
| 496 accelerators::ToggleFullscreen(); | 497 accelerators::ToggleFullscreen(); |
| 497 return true; | 498 return true; |
| 498 } | 499 } |
| 499 | 500 |
| 500 bool HandleToggleRootWindowFullScreen() { | 501 bool HandleToggleRootWindowFullScreen() { |
| 501 Shell::GetPrimaryRootWindowController()->ash_host()->ToggleFullScreen(); | 502 Shell::GetPrimaryRootWindowController()->ash_host()->ToggleFullScreen(); |
| 502 return true; | 503 return true; |
| 503 } | 504 } |
| 504 | 505 |
| 505 bool HandleWindowSnap(int action) { | 506 DockedWindowLayoutManager* GetDockedWindowLayoutManager() |
| 507 { | |
| 508 aura::Window* active_window = ash::wm::GetActiveWindow(); | |
| 509 if (active_window) { | |
| 510 aura::Window* dock_container = Shell::GetContainer( | |
| 511 active_window->GetRootWindow(), kShellWindowId_DockedContainer); | |
| 512 DockedWindowLayoutManager* dock_layout = | |
| 513 static_cast<DockedWindowLayoutManager*>( | |
| 514 dock_container->layout_manager()); | |
| 515 return dock_layout; | |
| 516 } | |
| 517 return 0; | |
|
varkha
2014/09/24 03:16:22
s/0/NULL
dtapuska
2014/09/25 23:27:08
Done.
| |
| 518 } | |
| 519 | |
| 520 class ScopedPreferredAlignmentResetter { | |
| 521 public: | |
| 522 ScopedPreferredAlignmentResetter(DockedAlignment dockAlignment) | |
| 523 : docked_window_layout_manager_(GetDockedWindowLayoutManager()) { | |
| 524 docked_window_layout_manager_->SetPreferredAlignment(dockAlignment); | |
| 525 } | |
| 526 ~ScopedPreferredAlignmentResetter() { | |
| 527 docked_window_layout_manager_->SetPreferredAlignment(DOCKED_ALIGNMENT_NONE); | |
| 528 } | |
| 529 | |
| 530 private: | |
| 531 DISALLOW_COPY_AND_ASSIGN(ScopedPreferredAlignmentResetter); | |
| 532 DockedWindowLayoutManager* docked_window_layout_manager_; | |
| 533 }; | |
| 534 | |
| 535 void RestoreWindow(bool left) { | |
|
varkha
2014/09/24 03:16:23
Do we need to know the side here? If it is only fo
dtapuska
2014/09/25 23:27:08
Done.
| |
| 536 wm::WindowState* window_state = wm::GetActiveWindowState(); | |
| 537 if (!window_state) | |
| 538 return; | |
| 539 | |
| 540 base::RecordAction(UserMetricsAction(left ? "Accel_Window_Restore_Left" : | |
| 541 "Accel_Window_Restore_Right")); | |
| 542 const wm::WMEvent event(wm::WM_EVENT_NORMAL); | |
| 543 window_state->OnWMEvent(&event); | |
| 544 } | |
| 545 | |
| 546 void DockWindow(DockedAlignment dockAlignment) { | |
| 547 wm::WindowState* window_state = wm::GetActiveWindowState(); | |
| 548 if (!window_state) | |
| 549 return; | |
| 550 | |
| 551 ScopedPreferredAlignmentResetter alignmentResetter(dockAlignment); | |
| 552 base::RecordAction(UserMetricsAction(dockAlignment == DOCKED_ALIGNMENT_LEFT ? | |
| 553 "Accel_Window_Dock_Left" : "Accel_Window_Dock_Right")); | |
| 554 const wm::WMEvent event(wm::WM_EVENT_DOCK); | |
| 555 window_state->OnWMEvent(&event); | |
| 556 } | |
| 557 | |
| 558 void SnapWindow(bool left) { | |
|
varkha
2014/09/24 03:16:23
I think using WM_EVENT_SNAP_xxx instead of bool wo
dtapuska
2014/09/25 23:27:09
Done.
| |
| 559 wm::WindowState* window_state = wm::GetActiveWindowState(); | |
| 560 if (!window_state) | |
| 561 return; | |
| 562 base::RecordAction(UserMetricsAction(left ? "Accel_Window_Snap_Left" : | |
| 563 "Accel_Window_Snap_Right")); | |
| 564 const wm::WMEvent event(left ? wm::WM_EVENT_SNAP_LEFT : | |
| 565 wm::WM_EVENT_SNAP_RIGHT); | |
| 566 window_state->OnWMEvent(&event); | |
| 567 } | |
| 568 | |
| 569 bool CanDock(DockedAlignment desired_alignment) { | |
| 570 aura::Window* active_window = ash::wm::GetActiveWindow(); | |
| 571 DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager(); | |
| 572 if (dock_layout) { | |
|
varkha
2014/09/24 03:16:23
nit: no need for parentheses.
dtapuska
2014/09/25 23:27:08
Done.
| |
| 573 return dock_layout->CanDockWindow(active_window, desired_alignment); | |
| 574 } | |
| 575 return false; | |
| 576 } | |
| 577 | |
| 578 DockedAlignment CurrentDockAlignment() { | |
| 579 DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager(); | |
| 580 if (dock_layout) { | |
|
varkha
2014/09/24 03:16:22
nit: no need for parentheses.
dtapuska
2014/09/25 23:27:08
Done.
| |
| 581 return dock_layout->CalculateAlignment(); | |
| 582 } | |
| 583 return DOCKED_ALIGNMENT_NONE; | |
| 584 } | |
| 585 | |
| 586 bool HandleWindowSnapOrDock(int action) { | |
| 506 wm::WindowState* window_state = wm::GetActiveWindowState(); | 587 wm::WindowState* window_state = wm::GetActiveWindowState(); |
| 507 // Disable window snapping shortcut key for full screen window due to | 588 // Disable window snapping shortcut key for full screen window due to |
| 508 // http://crbug.com/135487. | 589 // http://crbug.com/135487. |
| 509 if (!window_state || | 590 if (!window_state || |
| 510 window_state->window()->type() != ui::wm::WINDOW_TYPE_NORMAL || | 591 (window_state->window()->type() != ui::wm::WINDOW_TYPE_NORMAL && |
| 511 window_state->IsFullscreen() || | 592 window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) || |
| 512 !window_state->CanSnap()) { | 593 window_state->IsFullscreen()) { |
| 513 return false; | 594 return false; |
| 514 } | 595 } |
| 515 | 596 |
| 516 if (action == WINDOW_SNAP_LEFT) { | 597 wm::WindowStateType desiredSnapState = action == WINDOW_SNAP_OR_DOCK_LEFT ? |
| 517 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Left")); | 598 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED; |
| 518 } else { | 599 DockedAlignment desiredDockAlignment = action == WINDOW_SNAP_OR_DOCK_LEFT ? |
| 519 base::RecordAction(UserMetricsAction("Accel_Window_Snap_Right")); | 600 DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT; |
| 601 DockedAlignment currentDockAlignment = CurrentDockAlignment(); | |
| 602 | |
| 603 if (!window_state->IsDocked() || | |
|
varkha
2014/09/24 03:16:23
Do we still need to check CanSnap() somewhere?
dtapuska
2014/09/25 23:27:08
Done.
| |
| 604 (currentDockAlignment != DOCKED_ALIGNMENT_NONE && | |
| 605 currentDockAlignment != desiredDockAlignment)) { | |
|
varkha
2014/09/24 03:16:23
The logic could be just a bit simpler if the condi
dtapuska
2014/09/25 23:27:08
I don't agree. The 3rd patch now has some addition
| |
| 606 if (window_state->GetStateType() != desiredSnapState && | |
| 607 window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) { | |
| 608 SnapWindow(desiredSnapState == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED); | |
| 609 return true; | |
| 610 } | |
| 611 | |
| 612 if (CanDock(desiredDockAlignment)) { | |
| 613 DockWindow(desiredDockAlignment); | |
| 614 return true; | |
| 615 } | |
| 520 } | 616 } |
| 521 const wm::WMEvent event(action == WINDOW_SNAP_LEFT ? | 617 |
| 522 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); | 618 RestoreWindow(action == WINDOW_SNAP_OR_DOCK_LEFT); |
| 523 window_state->OnWMEvent(&event); | |
| 524 return true; | 619 return true; |
| 525 } | 620 } |
| 526 | 621 |
| 527 bool HandleWindowMinimize() { | 622 bool HandleWindowMinimize() { |
| 528 base::RecordAction( | 623 base::RecordAction( |
| 529 base::UserMetricsAction("Accel_Toggle_Minimized_Minus")); | 624 base::UserMetricsAction("Accel_Toggle_Minimized_Minus")); |
| 530 return accelerators::ToggleMinimized(); | 625 return accelerators::ToggleMinimized(); |
| 531 } | 626 } |
| 532 | 627 |
| 533 #if defined(OS_CHROMEOS) | 628 #if defined(OS_CHROMEOS) |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1029 case LAUNCH_APP_4: | 1124 case LAUNCH_APP_4: |
| 1030 return HandleLaunchAppN(4); | 1125 return HandleLaunchAppN(4); |
| 1031 case LAUNCH_APP_5: | 1126 case LAUNCH_APP_5: |
| 1032 return HandleLaunchAppN(5); | 1127 return HandleLaunchAppN(5); |
| 1033 case LAUNCH_APP_6: | 1128 case LAUNCH_APP_6: |
| 1034 return HandleLaunchAppN(6); | 1129 return HandleLaunchAppN(6); |
| 1035 case LAUNCH_APP_7: | 1130 case LAUNCH_APP_7: |
| 1036 return HandleLaunchAppN(7); | 1131 return HandleLaunchAppN(7); |
| 1037 case LAUNCH_LAST_APP: | 1132 case LAUNCH_LAST_APP: |
| 1038 return HandleLaunchLastApp(); | 1133 return HandleLaunchLastApp(); |
| 1039 case WINDOW_SNAP_LEFT: | 1134 case WINDOW_SNAP_OR_DOCK_LEFT: |
| 1040 case WINDOW_SNAP_RIGHT: | 1135 case WINDOW_SNAP_OR_DOCK_RIGHT: |
| 1041 return HandleWindowSnap(action); | 1136 return HandleWindowSnapOrDock(action); |
| 1042 case WINDOW_MINIMIZE: | 1137 case WINDOW_MINIMIZE: |
| 1043 return HandleWindowMinimize(); | 1138 return HandleWindowMinimize(); |
| 1044 case TOGGLE_FULLSCREEN: | 1139 case TOGGLE_FULLSCREEN: |
| 1045 return HandleToggleFullscreen(key_code); | 1140 return HandleToggleFullscreen(key_code); |
| 1046 case TOGGLE_MAXIMIZED: | 1141 case TOGGLE_MAXIMIZED: |
| 1047 accelerators::ToggleMaximized(); | 1142 accelerators::ToggleMaximized(); |
| 1048 return true; | 1143 return true; |
| 1049 case WINDOW_POSITION_CENTER: | 1144 case WINDOW_POSITION_CENTER: |
| 1050 return HandlePositionCenter(); | 1145 return HandlePositionCenter(); |
| 1051 case SCALE_UI_UP: | 1146 case SCALE_UI_UP: |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1202 keyboard_brightness_control_delegate) { | 1297 keyboard_brightness_control_delegate) { |
| 1203 keyboard_brightness_control_delegate_ = | 1298 keyboard_brightness_control_delegate_ = |
| 1204 keyboard_brightness_control_delegate.Pass(); | 1299 keyboard_brightness_control_delegate.Pass(); |
| 1205 } | 1300 } |
| 1206 | 1301 |
| 1207 bool AcceleratorController::CanHandleAccelerators() const { | 1302 bool AcceleratorController::CanHandleAccelerators() const { |
| 1208 return true; | 1303 return true; |
| 1209 } | 1304 } |
| 1210 | 1305 |
| 1211 } // namespace ash | 1306 } // namespace ash |
| OLD | NEW |