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

Side by Side Diff: ash/wm/default_state.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: Fix comment 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
« no previous file with comments | « ash/accelerators/accelerator_table.cc ('k') | ash/wm/dock/dock_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/wm/default_state.h" 5 #include "ash/wm/default_state.h"
6 6
7 #include "ash/display/display_controller.h" 7 #include "ash/display/display_controller.h"
8 #include "ash/screen_util.h" 8 #include "ash/screen_util.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
11 #include "ash/wm/coordinate_conversion.h" 11 #include "ash/wm/coordinate_conversion.h"
12 #include "ash/wm/dock/docked_window_layout_manager.h"
12 #include "ash/wm/window_animations.h" 13 #include "ash/wm/window_animations.h"
13 #include "ash/wm/window_state.h" 14 #include "ash/wm/window_state.h"
14 #include "ash/wm/window_state_delegate.h" 15 #include "ash/wm/window_state_delegate.h"
15 #include "ash/wm/window_state_util.h" 16 #include "ash/wm/window_state_util.h"
16 #include "ash/wm/window_util.h" 17 #include "ash/wm/window_util.h"
17 #include "ash/wm/wm_event.h" 18 #include "ash/wm/wm_event.h"
18 #include "ash/wm/workspace/workspace_window_resizer.h" 19 #include "ash/wm/workspace/workspace_window_resizer.h"
19 #include "ui/aura/client/aura_constants.h" 20 #include "ui/aura/client/aura_constants.h"
20 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
21 #include "ui/aura/window_delegate.h" 22 #include "ui/aura/window_delegate.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 aura::Window* new_root = 58 aura::Window* new_root =
58 display_controller->GetRootWindowForDisplayId(display.id()); 59 display_controller->GetRootWindowForDisplayId(display.id());
59 if (new_root != window_state->window()->GetRootWindow()) { 60 if (new_root != window_state->window()->GetRootWindow()) {
60 aura::Window* new_container = 61 aura::Window* new_container =
61 Shell::GetContainer(new_root, window_state->window()->parent()->id()); 62 Shell::GetContainer(new_root, window_state->window()->parent()->id());
62 new_container->AddChild(window_state->window()); 63 new_container->AddChild(window_state->window());
63 } 64 }
64 } 65 }
65 } 66 }
66 67
68 DockedWindowLayoutManager* GetDockedWindowLayoutManager() {
69 aura::Window* active_window = ash::wm::GetActiveWindow();
70 if (active_window) {
71 aura::Window* dock_container = Shell::GetContainer(
72 active_window->GetRootWindow(), kShellWindowId_DockedContainer);
73 DockedWindowLayoutManager* dock_layout =
74 static_cast<DockedWindowLayoutManager*>(
75 dock_container->layout_manager());
76 return dock_layout;
77 }
78 return NULL;
79 }
80
81 class ScopedPreferredAlignmentResetter {
82 public:
83 ScopedPreferredAlignmentResetter(DockedAlignment dock_alignment,
84 DockedWindowLayoutManager* dock_layout)
85 : docked_window_layout_manager_(dock_layout) {
86 docked_window_layout_manager_->set_preferred_alignment(dock_alignment);
87 }
88 ~ScopedPreferredAlignmentResetter() {
89 docked_window_layout_manager_->set_preferred_alignment(
90 DOCKED_ALIGNMENT_NONE);
91 }
92
93 private:
94 DockedWindowLayoutManager* docked_window_layout_manager_;
95
96 DISALLOW_COPY_AND_ASSIGN(ScopedPreferredAlignmentResetter);
97 };
98
99 class ScopedDockedLayoutEventSourceResetter {
100 public:
101 ScopedDockedLayoutEventSourceResetter(DockedWindowLayoutManager* dock_layout)
102 : docked_window_layout_manager_(dock_layout) {
103 docked_window_layout_manager_->set_event_source(
104 DOCKED_ACTION_SOURCE_KEYBOARD);
105 }
106 ~ScopedDockedLayoutEventSourceResetter() {
107 docked_window_layout_manager_->set_event_source(
108 DOCKED_ACTION_SOURCE_UNKNOWN);
109 }
110
111 private:
112 DockedWindowLayoutManager* docked_window_layout_manager_;
113
114 DISALLOW_COPY_AND_ASSIGN(ScopedDockedLayoutEventSourceResetter);
115 };
116
117 void CycleSnapDock(WindowState* window_state, WMEventType event) {
118 DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager();
119 wm::WindowStateType desired_snap_state = event ==
120 WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED :
121 wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED;
122 DockedAlignment desired_dock_alignment = event ==
123 WM_EVENT_CYCLE_SNAP_DOCK_LEFT ?
124 DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT;
125 DockedAlignment current_dock_alignment = dock_layout ?
126 dock_layout->CalculateAlignment() : DOCKED_ALIGNMENT_NONE;
127
128 if (!window_state->IsDocked() ||
129 (current_dock_alignment != DOCKED_ALIGNMENT_NONE &&
130 current_dock_alignment != desired_dock_alignment)) {
131 if (window_state->CanSnap() &&
132 window_state->GetStateType() != desired_snap_state &&
133 window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) {
134 const wm::WMEvent event(desired_snap_state ==
135 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ?
136 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT);
137 window_state->OnWMEvent(&event);
138 return;
139 }
140
141 if (dock_layout &&
142 dock_layout->CanDockWindow(window_state->window(),
143 desired_dock_alignment)) {
144 if (window_state->IsDocked()) {
145 dock_layout->MaybeSetDesiredDockedAlignment(desired_dock_alignment);
146 return;
147 }
148
149 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout);
150 ScopedPreferredAlignmentResetter alignmentResetter(desired_dock_alignment,
151 dock_layout);
152 const wm::WMEvent event(wm::WM_EVENT_DOCK);
153 window_state->OnWMEvent(&event);
154 return;
155 }
156 }
157
158 if (window_state->IsDocked() || window_state->IsSnapped()) {
159 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout);
160 window_state->Restore();
161 return;
162 }
163 ::wm::AnimateWindow(window_state->window(),
164 ::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
165 }
166
67 } // namespace; 167 } // namespace;
68 168
69 DefaultState::DefaultState(WindowStateType initial_state_type) 169 DefaultState::DefaultState(WindowStateType initial_state_type)
70 : state_type_(initial_state_type) {} 170 : state_type_(initial_state_type) {}
71 DefaultState::~DefaultState() {} 171 DefaultState::~DefaultState() {}
72 172
73 void DefaultState::OnWMEvent(WindowState* window_state, 173 void DefaultState::OnWMEvent(WindowState* window_state,
74 const WMEvent* event) { 174 const WMEvent* event) {
75 if (ProcessWorkspaceEvents(window_state, event)) 175 if (ProcessWorkspaceEvents(window_state, event))
76 return; 176 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 SetBounds(window_state, static_cast<const SetBoundsEvent*>(event)); 210 SetBounds(window_state, static_cast<const SetBoundsEvent*>(event));
111 return; 211 return;
112 case WM_EVENT_SHOW_INACTIVE: 212 case WM_EVENT_SHOW_INACTIVE:
113 next_state_type = WINDOW_STATE_TYPE_INACTIVE; 213 next_state_type = WINDOW_STATE_TYPE_INACTIVE;
114 break; 214 break;
115 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: 215 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
116 case WM_EVENT_TOGGLE_MAXIMIZE: 216 case WM_EVENT_TOGGLE_MAXIMIZE:
117 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: 217 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
118 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: 218 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
119 case WM_EVENT_TOGGLE_FULLSCREEN: 219 case WM_EVENT_TOGGLE_FULLSCREEN:
220 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT:
221 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT:
120 case WM_EVENT_CENTER: 222 case WM_EVENT_CENTER:
121 NOTREACHED() << "Compound event should not reach here:" << event; 223 NOTREACHED() << "Compound event should not reach here:" << event;
122 return; 224 return;
123 case WM_EVENT_ADDED_TO_WORKSPACE: 225 case WM_EVENT_ADDED_TO_WORKSPACE:
124 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: 226 case WM_EVENT_WORKAREA_BOUNDS_CHANGED:
125 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: 227 case WM_EVENT_DISPLAY_BOUNDS_CHANGED:
126 NOTREACHED() << "Workspace event should not reach here:" << event; 228 NOTREACHED() << "Workspace event should not reach here:" << event;
127 return; 229 return;
128 } 230 }
129 231
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 363 }
262 364
263 window_state->SetRestoreBoundsInParent(restore_bounds); 365 window_state->SetRestoreBoundsInParent(restore_bounds);
264 window->SetBounds(new_bounds); 366 window->SetBounds(new_bounds);
265 } 367 }
266 return true; 368 return true;
267 } 369 }
268 case WM_EVENT_TOGGLE_FULLSCREEN: 370 case WM_EVENT_TOGGLE_FULLSCREEN:
269 ToggleFullScreen(window_state, window_state->delegate()); 371 ToggleFullScreen(window_state, window_state->delegate());
270 return true; 372 return true;
373 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT:
374 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT:
375 CycleSnapDock(window_state, event->type());
376 return true;
271 case WM_EVENT_CENTER: 377 case WM_EVENT_CENTER:
272 CenterWindow(window_state); 378 CenterWindow(window_state);
273 return true; 379 return true;
274 case WM_EVENT_NORMAL: 380 case WM_EVENT_NORMAL:
275 case WM_EVENT_MAXIMIZE: 381 case WM_EVENT_MAXIMIZE:
276 case WM_EVENT_MINIMIZE: 382 case WM_EVENT_MINIMIZE:
277 case WM_EVENT_FULLSCREEN: 383 case WM_EVENT_FULLSCREEN:
278 case WM_EVENT_SNAP_LEFT: 384 case WM_EVENT_SNAP_LEFT:
279 case WM_EVENT_SNAP_RIGHT: 385 case WM_EVENT_SNAP_RIGHT:
280 case WM_EVENT_SET_BOUNDS: 386 case WM_EVENT_SET_BOUNDS:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 window_state->AdjustSnappedBounds(&bounds); 469 window_state->AdjustSnappedBounds(&bounds);
364 if (window_state->window()->bounds() != bounds) 470 if (window_state->window()->bounds() != bounds)
365 window_state->SetBoundsDirectAnimated(bounds); 471 window_state->SetBoundsDirectAnimated(bounds);
366 return true; 472 return true;
367 } 473 }
368 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: 474 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
369 case WM_EVENT_TOGGLE_MAXIMIZE: 475 case WM_EVENT_TOGGLE_MAXIMIZE:
370 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: 476 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
371 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: 477 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
372 case WM_EVENT_TOGGLE_FULLSCREEN: 478 case WM_EVENT_TOGGLE_FULLSCREEN:
479 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT:
480 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT:
373 case WM_EVENT_CENTER: 481 case WM_EVENT_CENTER:
374 case WM_EVENT_NORMAL: 482 case WM_EVENT_NORMAL:
375 case WM_EVENT_MAXIMIZE: 483 case WM_EVENT_MAXIMIZE:
376 case WM_EVENT_MINIMIZE: 484 case WM_EVENT_MINIMIZE:
377 case WM_EVENT_FULLSCREEN: 485 case WM_EVENT_FULLSCREEN:
378 case WM_EVENT_SNAP_LEFT: 486 case WM_EVENT_SNAP_LEFT:
379 case WM_EVENT_SNAP_RIGHT: 487 case WM_EVENT_SNAP_RIGHT:
380 case WM_EVENT_SET_BOUNDS: 488 case WM_EVENT_SET_BOUNDS:
381 case WM_EVENT_SHOW_INACTIVE: 489 case WM_EVENT_SHOW_INACTIVE:
382 case WM_EVENT_DOCK: 490 case WM_EVENT_DOCK:
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); 733 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window);
626 center_in_parent.ClampToCenteredSize(window->bounds().size()); 734 center_in_parent.ClampToCenteredSize(window->bounds().size());
627 window_state->SetBoundsDirectAnimated(center_in_parent); 735 window_state->SetBoundsDirectAnimated(center_in_parent);
628 } 736 }
629 // Centering window is treated as if a user moved and resized the window. 737 // Centering window is treated as if a user moved and resized the window.
630 window_state->set_bounds_changed_by_user(true); 738 window_state->set_bounds_changed_by_user(true);
631 } 739 }
632 740
633 } // namespace wm 741 } // namespace wm
634 } // namespace ash 742 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_table.cc ('k') | ash/wm/dock/dock_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698