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

Side by Side Diff: ash/wm/workspace/frame_maximize_button.cc

Issue 13896026: Stick windows to sides of workspaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Correcting logic to avoid getting stuck on resize Created 7 years, 7 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/wm/workspace/frame_maximize_button.h" 5 #include "ash/wm/workspace/frame_maximize_button.h"
6 6
7 #include "ash/ash_switches.h"
7 #include "ash/launcher/launcher.h" 8 #include "ash/launcher/launcher.h"
8 #include "ash/screen_ash.h" 9 #include "ash/screen_ash.h"
9 #include "ash/shelf/shelf_widget.h" 10 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shell.h" 11 #include "ash/shell.h"
11 #include "ash/shell_delegate.h" 12 #include "ash/shell_delegate.h"
12 #include "ash/wm/maximize_bubble_controller.h" 13 #include "ash/wm/maximize_bubble_controller.h"
13 #include "ash/wm/property_util.h" 14 #include "ash/wm/property_util.h"
14 #include "ash/wm/window_properties.h" 15 #include "ash/wm/window_properties.h"
15 #include "ash/wm/window_util.h" 16 #include "ash/wm/window_util.h"
16 #include "ash/wm/workspace/phantom_window_controller.h" 17 #include "ash/wm/workspace/phantom_window_controller.h"
17 #include "ash/wm/workspace/snap_sizer.h" 18 #include "ash/wm/workspace/snap_sizer.h"
19 #include "ash/wm/workspace/workspace_window_resizer.h"
20 #include "base/command_line.h"
18 #include "grit/ash_strings.h" 21 #include "grit/ash_strings.h"
19 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
20 #include "ui/base/events/event.h" 23 #include "ui/base/events/event.h"
21 #include "ui/base/events/event_handler.h" 24 #include "ui/base/events/event_handler.h"
22 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
25 #include "ui/gfx/screen.h" 28 #include "ui/gfx/screen.h"
26 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
27 #include "ui/views/window/non_client_view.h" 30 #include "ui/views/window/non_client_view.h"
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 views::Widget* widget = frame_->GetWidget(); 526 views::Widget* widget = frame_->GetWidget();
524 switch (snap_type_) { 527 switch (snap_type_) {
525 case SNAP_LEFT: 528 case SNAP_LEFT:
526 case SNAP_RIGHT: { 529 case SNAP_RIGHT: {
527 shell->delegate()->RecordUserMetricsAction( 530 shell->delegate()->RecordUserMetricsAction(
528 snap_type_ == SNAP_LEFT ? 531 snap_type_ == SNAP_LEFT ?
529 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT : 532 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT :
530 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); 533 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT);
531 // Get the bounds in screen coordinates for restore purposes. 534 // Get the bounds in screen coordinates for restore purposes.
532 gfx::Rect restore = widget->GetWindowBoundsInScreen(); 535 gfx::Rect restore = widget->GetWindowBoundsInScreen();
536 bool restore_set = false;
537 gfx::Rect bounds;
538 aura::Window* window = widget->GetNativeWindow();
533 if (widget->IsMaximized() || widget->IsFullscreen()) { 539 if (widget->IsMaximized() || widget->IsFullscreen()) {
534 aura::Window* window = widget->GetNativeWindow();
535 // In case of maximized we have a restore boundary. 540 // In case of maximized we have a restore boundary.
536 DCHECK(ash::GetRestoreBoundsInScreen(window)); 541 DCHECK(ash::GetRestoreBoundsInScreen(window));
537 // If it was maximized we need to recover the old restore set. 542 // If it was maximized we need to recover the old restore set.
538 restore = *ash::GetRestoreBoundsInScreen(window); 543 restore = *ash::GetRestoreBoundsInScreen(window);
539 544
540 // The auto position manager will kick in when this is the only window. 545 // The auto position manager will kick in when this is the only window.
541 // To avoid interference with it we tell it temporarily to not change 546 // To avoid interference with it we tell it temporarily to not change
542 // the coordinates of this window. 547 // the coordinates of this window.
543 bool is_managed = ash::wm::IsWindowPositionManaged(window); 548 bool is_managed = ash::wm::IsWindowPositionManaged(window);
544 if (is_managed) 549 if (is_managed)
545 ash::wm::SetWindowPositionManaged(window, false); 550 ash::wm::SetWindowPositionManaged(window, false);
546 551
547 // Set the restore size we want to restore to. 552 // Set the restore size we want to restore to.
548 ash::SetRestoreBoundsInScreen(window, 553 bounds = ScreenBoundsForType(snap_type_, snap_sizer);
549 ScreenBoundsForType(snap_type_, 554 ash::SetRestoreBoundsInScreen(window, bounds);
550 snap_sizer));
551 widget->Restore(); 555 widget->Restore();
552 556
553 // After the window is where we want it to be we allow the window to be 557 // After the window is where we want it to be we allow the window to be
554 // auto managed again. 558 // auto managed again.
555 if (is_managed) 559 if (is_managed)
556 ash::wm::SetWindowPositionManaged(window, true); 560 ash::wm::SetWindowPositionManaged(window, true);
557 } else { 561 } else {
558 // Others might also have set up a restore rectangle already. If so, 562 // Others might also have set up a restore rectangle already. If so,
559 // we should not overwrite the restore rectangle. 563 // we should not overwrite the restore rectangle.
560 bool restore_set = 564 restore_set =
561 GetRestoreBoundsInScreen(widget->GetNativeWindow()) != NULL; 565 GetRestoreBoundsInScreen(widget->GetNativeWindow()) != NULL;
562 widget->SetBounds(ScreenBoundsForType(snap_type_, snap_sizer)); 566 bounds = ScreenBoundsForType(snap_type_, snap_sizer);
563 if (restore_set) 567 widget->SetBounds(bounds);
564 break;
565 } 568 }
569 gfx::Rect bounds_in_parent = ScreenAsh::ConvertRectToScreen(
570 window->parent(),
571 ScreenAsh::GetMaximizedWindowBoundsInParent(window));
572 int stuck_edges_mask =
573 internal::WorkspaceWindowResizer::CalculateStuckEdges(
574 bounds, bounds_in_parent);
575 if (GetStuckToEdge(window) != stuck_edges_mask &&
576 CommandLine::ForCurrentProcess()->HasSwitch(
577 switches::kAshEnableDockedWindows))
flackr 2013/05/22 02:00:56 nit: multiline if condition should use braces.
578 SetStuckToEdge(window, stuck_edges_mask);
flackr 2013/05/22 02:00:56 Why check if the condition is not stuck_edges_mask
579
580 if (restore_set)
581 break;
582
566 // Remember the widow's bounds for restoration. 583 // Remember the widow's bounds for restoration.
flackr 2013/05/22 02:00:56 s/widow/window
567 ash::SetRestoreBoundsInScreen(widget->GetNativeWindow(), restore); 584 ash::SetRestoreBoundsInScreen(widget->GetNativeWindow(), restore);
568 break; 585 break;
569 } 586 }
570 case SNAP_MAXIMIZE: 587 case SNAP_MAXIMIZE:
571 widget->Maximize(); 588 widget->Maximize();
572 shell->delegate()->RecordUserMetricsAction( 589 shell->delegate()->RecordUserMetricsAction(
573 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE); 590 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE);
574 break; 591 break;
575 case SNAP_MINIMIZE: 592 case SNAP_MINIMIZE:
576 widget->Minimize(); 593 widget->Minimize();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 return FRAME_STATE_SNAP_LEFT; 628 return FRAME_STATE_SNAP_LEFT;
612 if (bounds.right() == screen.right()) 629 if (bounds.right() == screen.right())
613 return FRAME_STATE_SNAP_RIGHT; 630 return FRAME_STATE_SNAP_RIGHT;
614 // If we come here, it is likely caused by the fact that the 631 // If we come here, it is likely caused by the fact that the
615 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case 632 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case
616 // we allow all maximize operations (and keep the restore rectangle). 633 // we allow all maximize operations (and keep the restore rectangle).
617 return FRAME_STATE_NONE; 634 return FRAME_STATE_NONE;
618 } 635 }
619 636
620 } // namespace ash 637 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698