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

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

Issue 24108003: [Cleanup] Rename WindowSettings to WindowState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase fix Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/caption_buttons/frame_maximize_button.h" 5 #include "ash/wm/caption_buttons/frame_maximize_button.h"
6 6
7 #include "ash/launcher/launcher.h" 7 #include "ash/launcher/launcher.h"
8 #include "ash/screen_ash.h" 8 #include "ash/screen_ash.h"
9 #include "ash/shelf/shelf_widget.h" 9 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_delegate.h" 11 #include "ash/shell_delegate.h"
12 #include "ash/touch/touch_uma.h" 12 #include "ash/touch/touch_uma.h"
13 #include "ash/wm/caption_buttons/maximize_bubble_controller.h" 13 #include "ash/wm/caption_buttons/maximize_bubble_controller.h"
14 #include "ash/wm/property_util.h"
15 #include "ash/wm/window_animations.h" 14 #include "ash/wm/window_animations.h"
16 #include "ash/wm/window_settings.h" 15 #include "ash/wm/window_state.h"
17 #include "ash/wm/workspace/phantom_window_controller.h" 16 #include "ash/wm/workspace/phantom_window_controller.h"
18 #include "ash/wm/workspace/snap_sizer.h" 17 #include "ash/wm/workspace/snap_sizer.h"
19 #include "grit/ash_strings.h" 18 #include "grit/ash_strings.h"
20 #include "ui/aura/client/aura_constants.h" 19 #include "ui/aura/client/aura_constants.h"
21 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
22 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/events/event.h" 23 #include "ui/events/event.h"
25 #include "ui/events/event_handler.h" 24 #include "ui/events/event_handler.h"
26 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 frame_(frame), 86 frame_(frame),
88 observing_frame_(false), 87 observing_frame_(false),
89 is_snap_enabled_(false), 88 is_snap_enabled_(false),
90 exceeded_drag_threshold_(false), 89 exceeded_drag_threshold_(false),
91 press_is_gesture_(false), 90 press_is_gesture_(false),
92 snap_type_(SNAP_NONE), 91 snap_type_(SNAP_NONE),
93 bubble_appearance_delay_ms_(kBubbleAppearanceDelayMS) { 92 bubble_appearance_delay_ms_(kBubbleAppearanceDelayMS) {
94 // TODO(sky): nuke this. It's temporary while we don't have good images. 93 // TODO(sky): nuke this. It's temporary while we don't have good images.
95 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); 94 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
96 95
97 if (ash::Shell::IsForcedMaximizeMode()) 96 if (Shell::IsForcedMaximizeMode())
98 views::View::SetVisible(false); 97 views::View::SetVisible(false);
99 } 98 }
100 99
101 FrameMaximizeButton::~FrameMaximizeButton() { 100 FrameMaximizeButton::~FrameMaximizeButton() {
102 // Before the window gets destroyed, the maximizer dialog needs to be shut 101 // Before the window gets destroyed, the maximizer dialog needs to be shut
103 // down since it would otherwise call into a deleted object. 102 // down since it would otherwise call into a deleted object.
104 maximizer_.reset(); 103 maximizer_.reset();
105 if (observing_frame_) 104 if (observing_frame_)
106 OnWindowDestroying(frame_->GetNativeWindow()); 105 OnWindowDestroying(frame_->GetNativeWindow());
107 } 106 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 event->SetHandled(); 308 event->SetHandled();
310 return; 309 return;
311 } 310 }
312 } 311 }
313 312
314 ImageButton::OnGestureEvent(event); 313 ImageButton::OnGestureEvent(event);
315 } 314 }
316 315
317 void FrameMaximizeButton::SetVisible(bool visible) { 316 void FrameMaximizeButton::SetVisible(bool visible) {
318 // In the enforced maximized mode we do not allow to be made visible. 317 // In the enforced maximized mode we do not allow to be made visible.
319 if (ash::Shell::IsForcedMaximizeMode()) 318 if (Shell::IsForcedMaximizeMode())
320 return; 319 return;
321 320
322 views::View::SetVisible(visible); 321 views::View::SetVisible(visible);
323 } 322 }
324 323
325 void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) { 324 void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) {
326 DCHECK(is_snap_enabled_); 325 DCHECK(is_snap_enabled_);
327 // Prepare the help menu. 326 // Prepare the help menu.
328 if (!maximizer_) { 327 if (!maximizer_) {
329 maximizer_.reset(new MaximizeBubbleController( 328 maximizer_.reset(new MaximizeBubbleController(
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 case SNAP_MINIMIZE: { 491 case SNAP_MINIMIZE: {
493 gfx::Rect rect = GetMinimizeAnimationTargetBoundsInScreen(window); 492 gfx::Rect rect = GetMinimizeAnimationTargetBoundsInScreen(window);
494 if (!rect.IsEmpty()) { 493 if (!rect.IsEmpty()) {
495 // PhantomWindowController insets slightly, outset it so the phantom 494 // PhantomWindowController insets slightly, outset it so the phantom
496 // doesn't appear inset. 495 // doesn't appear inset.
497 rect.Inset(-8, -8); 496 rect.Inset(-8, -8);
498 } 497 }
499 return rect; 498 return rect;
500 } 499 }
501 case SNAP_RESTORE: { 500 case SNAP_RESTORE: {
502 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); 501 wm::WindowState* window_state = wm::GetWindowState(window);
503 return restore ? *restore : frame_->GetWindowBoundsInScreen(); 502 return window_state->HasRestoreBounds() ?
503 window_state->GetRestoreBoundsInScreen() :
504 frame_->GetWindowBoundsInScreen();
504 } 505 }
505 case SNAP_NONE: 506 case SNAP_NONE:
506 NOTREACHED(); 507 NOTREACHED();
507 } 508 }
508 return gfx::Rect(); 509 return gfx::Rect();
509 } 510 }
510 511
511 gfx::Point FrameMaximizeButton::LocationForSnapSizer( 512 gfx::Point FrameMaximizeButton::LocationForSnapSizer(
512 const gfx::Point& location) const { 513 const gfx::Point& location) const {
513 gfx::Point result(location); 514 gfx::Point result(location);
514 views::View::ConvertPointToScreen(this, &result); 515 views::View::ConvertPointToScreen(this, &result);
515 return result; 516 return result;
516 } 517 }
517 518
518 void FrameMaximizeButton::Snap(SnapSizer* snap_sizer) { 519 void FrameMaximizeButton::Snap(SnapSizer* snap_sizer) {
519 ash::Shell* shell = ash::Shell::GetInstance(); 520 Shell* shell = Shell::GetInstance();
521 wm::WindowState* window_state = wm::GetWindowState(frame_->GetNativeWindow());
520 switch (snap_type_) { 522 switch (snap_type_) {
521 case SNAP_LEFT: 523 case SNAP_LEFT:
522 case SNAP_RIGHT: { 524 case SNAP_RIGHT: {
523 // Others might also have set up a restore rectangle already. If so, we 525 // Others might also have set up a restore rectangle already. If so, we
524 // should not overwrite the restore rectangle. 526 // should not overwrite the restore rectangle.
525 gfx::Rect current_bounds_in_screen = frame_->GetWindowBoundsInScreen(); 527 gfx::Rect current_bounds_in_screen = frame_->GetWindowBoundsInScreen();
526 snap_sizer->SnapWindowToTargetBounds(); 528 snap_sizer->SnapWindowToTargetBounds();
527 if (GetRestoreBoundsInScreen(frame_->GetNativeWindow()) == NULL) { 529 if (!window_state->HasRestoreBounds())
528 ash::SetRestoreBoundsInScreen(frame_->GetNativeWindow(), 530 window_state->SetRestoreBoundsInScreen(current_bounds_in_screen);
529 current_bounds_in_screen);
530 }
531 shell->delegate()->RecordUserMetricsAction( 531 shell->delegate()->RecordUserMetricsAction(
532 snap_type_ == SNAP_LEFT ? 532 snap_type_ == SNAP_LEFT ?
533 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT : 533 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT :
534 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); 534 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT);
535 break; 535 break;
536 } 536 }
537 case SNAP_MAXIMIZE: 537 case SNAP_MAXIMIZE:
538 frame_->Maximize(); 538 frame_->Maximize();
539 shell->delegate()->RecordUserMetricsAction( 539 shell->delegate()->RecordUserMetricsAction(
540 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE); 540 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE);
541 break; 541 break;
542 case SNAP_MINIMIZE: 542 case SNAP_MINIMIZE:
543 frame_->Minimize(); 543 frame_->Minimize();
544 shell->delegate()->RecordUserMetricsAction( 544 shell->delegate()->RecordUserMetricsAction(
545 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MINIMIZE); 545 UMA_WINDOW_MAXIMIZE_BUTTON_MINIMIZE);
546 break; 546 break;
547 case SNAP_RESTORE: 547 case SNAP_RESTORE:
548 frame_->Restore(); 548 frame_->Restore();
549 shell->delegate()->RecordUserMetricsAction( 549 shell->delegate()->RecordUserMetricsAction(
550 ash::UMA_WINDOW_MAXIMIZE_BUTTON_RESTORE); 550 UMA_WINDOW_MAXIMIZE_BUTTON_RESTORE);
551 break; 551 break;
552 case SNAP_NONE: 552 case SNAP_NONE:
553 NOTREACHED(); 553 NOTREACHED();
554 } 554 }
555 } 555 }
556 556
557 MaximizeBubbleFrameState 557 MaximizeBubbleFrameState
558 FrameMaximizeButton::GetMaximizeBubbleFrameState() const { 558 FrameMaximizeButton::GetMaximizeBubbleFrameState() const {
559 wm::WindowState* window_state =
560 wm::GetWindowState(frame_->GetNativeWindow());
559 // When there are no restore bounds, we are in normal mode. 561 // When there are no restore bounds, we are in normal mode.
560 if (!ash::GetRestoreBoundsInScreen(frame_->GetNativeWindow())) 562 if (!window_state->HasRestoreBounds())
561 return FRAME_STATE_NONE; 563 return FRAME_STATE_NONE;
562 // The normal maximized test can be used. 564 // The normal maximized test can be used.
563 if (frame_->IsMaximized()) 565 if (frame_->IsMaximized())
564 return FRAME_STATE_FULL; 566 return FRAME_STATE_FULL;
565 // For Left/right maximize we need to check the dimensions. 567 // For Left/right maximize we need to check the dimensions.
566 gfx::Rect bounds = frame_->GetWindowBoundsInScreen(); 568 gfx::Rect bounds = frame_->GetWindowBoundsInScreen();
567 gfx::Rect screen = Shell::GetScreen()->GetDisplayNearestWindow( 569 gfx::Rect screen = Shell::GetScreen()->GetDisplayNearestWindow(
568 frame_->GetNativeView()).work_area(); 570 frame_->GetNativeView()).work_area();
569 if (bounds.width() < (screen.width() * kMinSnapSizePercent) / 100) 571 if (bounds.width() < (screen.width() * kMinSnapSizePercent) / 100)
570 return FRAME_STATE_NONE; 572 return FRAME_STATE_NONE;
571 // We might still have a horizontally filled window at this point which we 573 // We might still have a horizontally filled window at this point which we
572 // treat as no special state. 574 // treat as no special state.
573 if (bounds.y() != screen.y() || bounds.height() != screen.height()) 575 if (bounds.y() != screen.y() || bounds.height() != screen.height())
574 return FRAME_STATE_NONE; 576 return FRAME_STATE_NONE;
575 577
576 // We have to be in a maximize mode at this point. 578 // We have to be in a maximize mode at this point.
577 if (bounds.x() == screen.x()) 579 if (bounds.x() == screen.x())
578 return FRAME_STATE_SNAP_LEFT; 580 return FRAME_STATE_SNAP_LEFT;
579 if (bounds.right() == screen.right()) 581 if (bounds.right() == screen.right())
580 return FRAME_STATE_SNAP_RIGHT; 582 return FRAME_STATE_SNAP_RIGHT;
581 // If we come here, it is likely caused by the fact that the 583 // If we come here, it is likely caused by the fact that the
582 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case 584 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case
583 // we allow all maximize operations (and keep the restore rectangle). 585 // we allow all maximize operations (and keep the restore rectangle).
584 return FRAME_STATE_NONE; 586 return FRAME_STATE_NONE;
585 } 587 }
586 588
587 } // namespace ash 589 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698