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

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

Issue 24048003: [Refactor] Cache the views::Widget* that the FrameMaximizeButton acts on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits per jamescook@ 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
« no previous file with comments | « ash/wm/caption_buttons/frame_maximize_button.h ('k') | ash/wm/custom_frame_view_ash.cc » ('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 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"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 ui::KeyEvent* event) { 75 ui::KeyEvent* event) {
76 if (event->type() == ui::ET_KEY_PRESSED && 76 if (event->type() == ui::ET_KEY_PRESSED &&
77 event->key_code() == ui::VKEY_ESCAPE) { 77 event->key_code() == ui::VKEY_ESCAPE) {
78 button_->Cancel(false); 78 button_->Cancel(false);
79 } 79 }
80 } 80 }
81 81
82 // FrameMaximizeButton --------------------------------------------------------- 82 // FrameMaximizeButton ---------------------------------------------------------
83 83
84 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener, 84 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener,
85 views::NonClientFrameView* frame) 85 views::Widget* frame)
86 : ImageButton(listener), 86 : ImageButton(listener),
87 frame_(frame), 87 frame_(frame),
88 observing_frame_(false),
88 is_snap_enabled_(false), 89 is_snap_enabled_(false),
89 exceeded_drag_threshold_(false), 90 exceeded_drag_threshold_(false),
90 widget_(NULL),
91 press_is_gesture_(false), 91 press_is_gesture_(false),
92 snap_type_(SNAP_NONE), 92 snap_type_(SNAP_NONE),
93 bubble_appearance_delay_ms_(kBubbleAppearanceDelayMS) { 93 bubble_appearance_delay_ms_(kBubbleAppearanceDelayMS) {
94 // TODO(sky): nuke this. It's temporary while we don't have good images. 94 // TODO(sky): nuke this. It's temporary while we don't have good images.
95 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); 95 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM);
96 96
97 if (ash::Shell::IsForcedMaximizeMode()) 97 if (ash::Shell::IsForcedMaximizeMode())
98 views::View::SetVisible(false); 98 views::View::SetVisible(false);
99 } 99 }
100 100
101 FrameMaximizeButton::~FrameMaximizeButton() { 101 FrameMaximizeButton::~FrameMaximizeButton() {
102 // Before the window gets destroyed, the maximizer dialog needs to be shut 102 // Before the window gets destroyed, the maximizer dialog needs to be shut
103 // down since it would otherwise call into a deleted object. 103 // down since it would otherwise call into a deleted object.
104 maximizer_.reset(); 104 maximizer_.reset();
105 if (widget_) 105 if (observing_frame_)
106 OnWindowDestroying(widget_->GetNativeWindow()); 106 OnWindowDestroying(frame_->GetNativeWindow());
107 } 107 }
108 108
109 void FrameMaximizeButton::SnapButtonHovered(SnapType type) { 109 void FrameMaximizeButton::SnapButtonHovered(SnapType type) {
110 // Make sure to only show hover operations when no button is pressed and 110 // Make sure to only show hover operations when no button is pressed and
111 // a similar snap operation in progress does not get re-applied. 111 // a similar snap operation in progress does not get re-applied.
112 if (is_snap_enabled_ || (type == snap_type_ && snap_sizer_)) 112 if (is_snap_enabled_ || (type == snap_type_ && snap_sizer_))
113 return; 113 return;
114 // Prime the mouse location with the center of the (local) button. 114 // Prime the mouse location with the center of the (local) button.
115 press_location_ = gfx::Point(width() / 2, height() / 2); 115 press_location_ = gfx::Point(width() / 2, height() / 2);
116 // Then get an adjusted mouse position to initiate the effect. 116 // Then get an adjusted mouse position to initiate the effect.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 174 }
175 175
176 void FrameMaximizeButton::OnWindowPropertyChanged(aura::Window* window, 176 void FrameMaximizeButton::OnWindowPropertyChanged(aura::Window* window,
177 const void* key, 177 const void* key,
178 intptr_t old) { 178 intptr_t old) {
179 Cancel(false); 179 Cancel(false);
180 } 180 }
181 181
182 void FrameMaximizeButton::OnWindowDestroying(aura::Window* window) { 182 void FrameMaximizeButton::OnWindowDestroying(aura::Window* window) {
183 maximizer_.reset(); 183 maximizer_.reset();
184 if (widget_) { 184 if (observing_frame_) {
185 CHECK_EQ(widget_->GetNativeWindow(), window); 185 CHECK_EQ(frame_->GetNativeWindow(), window);
186 widget_->GetNativeWindow()->RemoveObserver(this); 186 frame_->GetNativeWindow()->RemoveObserver(this);
187 widget_->RemoveObserver(this); 187 frame_->RemoveObserver(this);
188 widget_ = NULL; 188 observing_frame_ = false;
189 } 189 }
190 } 190 }
191 191
192 void FrameMaximizeButton::OnWidgetActivationChanged(views::Widget* widget, 192 void FrameMaximizeButton::OnWidgetActivationChanged(views::Widget* widget,
193 bool active) { 193 bool active) {
194 // Upon losing focus, the control bubble should hide. 194 // Upon losing focus, the control bubble should hide.
195 if (!active && maximizer_) 195 if (!active && maximizer_)
196 maximizer_.reset(); 196 maximizer_.reset();
197 } 197 }
198 198
199 bool FrameMaximizeButton::OnMousePressed(const ui::MouseEvent& event) { 199 bool FrameMaximizeButton::OnMousePressed(const ui::MouseEvent& event) {
200 // If we are already in a mouse click / drag operation, a second button down 200 // If we are already in a mouse click / drag operation, a second button down
201 // call will cancel (this addresses crbug.com/143755). 201 // call will cancel (this addresses crbug.com/143755).
202 if (is_snap_enabled_) { 202 if (is_snap_enabled_) {
203 Cancel(false); 203 Cancel(false);
204 } else { 204 } else {
205 is_snap_enabled_ = event.IsOnlyLeftMouseButton(); 205 is_snap_enabled_ = event.IsOnlyLeftMouseButton();
206 if (is_snap_enabled_) 206 if (is_snap_enabled_)
207 ProcessStartEvent(event); 207 ProcessStartEvent(event);
208 } 208 }
209 ImageButton::OnMousePressed(event); 209 ImageButton::OnMousePressed(event);
210 return true; 210 return true;
211 } 211 }
212 212
213 void FrameMaximizeButton::OnMouseEntered(const ui::MouseEvent& event) { 213 void FrameMaximizeButton::OnMouseEntered(const ui::MouseEvent& event) {
214 ImageButton::OnMouseEntered(event); 214 ImageButton::OnMouseEntered(event);
215 if (!maximizer_) { 215 if (!maximizer_) {
216 DCHECK(GetWidget()); 216 DCHECK(GetWidget());
217 if (!widget_) { 217 if (!observing_frame_) {
218 widget_ = frame_->GetWidget(); 218 observing_frame_ = true;
219 widget_->GetNativeWindow()->AddObserver(this); 219 frame_->GetNativeWindow()->AddObserver(this);
220 widget_->AddObserver(this); 220 frame_->AddObserver(this);
221 } 221 }
222 maximizer_.reset(new MaximizeBubbleController( 222 maximizer_.reset(new MaximizeBubbleController(
223 this, 223 this,
224 GetMaximizeBubbleFrameState(), 224 GetMaximizeBubbleFrameState(),
225 bubble_appearance_delay_ms_)); 225 bubble_appearance_delay_ms_));
226 } 226 }
227 } 227 }
228 228
229 void FrameMaximizeButton::OnMouseExited(const ui::MouseEvent& event) { 229 void FrameMaximizeButton::OnMouseExited(const ui::MouseEvent& event) {
230 ImageButton::OnMouseExited(event); 230 ImageButton::OnMouseExited(event);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 414 }
415 415
416 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location, 416 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location,
417 bool select_default, 417 bool select_default,
418 bool is_touch) { 418 bool is_touch) {
419 SnapType type = SnapTypeForLocation(location); 419 SnapType type = SnapTypeForLocation(location);
420 if (type == snap_type_) { 420 if (type == snap_type_) {
421 if (snap_sizer_) { 421 if (snap_sizer_) {
422 snap_sizer_->Update(LocationForSnapSizer(location)); 422 snap_sizer_->Update(LocationForSnapSizer(location));
423 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( 423 phantom_window_->Show(ScreenAsh::ConvertRectToScreen(
424 frame_->GetWidget()->GetNativeView()->parent(), 424 frame_->GetNativeView()->parent(),
425 snap_sizer_->target_bounds())); 425 snap_sizer_->target_bounds()));
426 } 426 }
427 return; 427 return;
428 } 428 }
429 429
430 snap_type_ = type; 430 snap_type_ = type;
431 snap_sizer_.reset(); 431 snap_sizer_.reset();
432 SchedulePaint(); 432 SchedulePaint();
433 433
434 if (snap_type_ == SNAP_NONE) { 434 if (snap_type_ == SNAP_NONE) {
435 phantom_window_.reset(); 435 phantom_window_.reset();
436 return; 436 return;
437 } 437 }
438 438
439 if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) { 439 if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) {
440 SnapSizer::Edge snap_edge = snap_type_ == SNAP_LEFT ? 440 SnapSizer::Edge snap_edge = snap_type_ == SNAP_LEFT ?
441 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; 441 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE;
442 SnapSizer::InputType input_type = 442 SnapSizer::InputType input_type =
443 is_touch ? SnapSizer::TOUCH_MAXIMIZE_BUTTON_INPUT : 443 is_touch ? SnapSizer::TOUCH_MAXIMIZE_BUTTON_INPUT :
444 SnapSizer::OTHER_INPUT; 444 SnapSizer::OTHER_INPUT;
445 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), 445 snap_sizer_.reset(new SnapSizer(frame_->GetNativeWindow(),
446 LocationForSnapSizer(location), 446 LocationForSnapSizer(location),
447 snap_edge, 447 snap_edge,
448 input_type)); 448 input_type));
449 if (select_default) 449 if (select_default)
450 snap_sizer_->SelectDefaultSizeAndDisableResize(); 450 snap_sizer_->SelectDefaultSizeAndDisableResize();
451 } 451 }
452 if (!phantom_window_) { 452 if (!phantom_window_) {
453 phantom_window_.reset(new internal::PhantomWindowController( 453 phantom_window_.reset(new internal::PhantomWindowController(
454 frame_->GetWidget()->GetNativeWindow())); 454 frame_->GetNativeWindow()));
455 } 455 }
456 if (maximizer_) { 456 if (maximizer_) {
457 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); 457 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow());
458 maximizer_->SetSnapType(snap_type_); 458 maximizer_->SetSnapType(snap_type_);
459 } 459 }
460 phantom_window_->Show( 460 phantom_window_->Show(
461 ScreenBoundsForType(snap_type_, *snap_sizer_.get())); 461 ScreenBoundsForType(snap_type_, *snap_sizer_.get()));
462 } 462 }
463 463
464 SnapType FrameMaximizeButton::SnapTypeForLocation( 464 SnapType FrameMaximizeButton::SnapTypeForLocation(
465 const gfx::Point& location) const { 465 const gfx::Point& location) const {
466 MaximizeBubbleFrameState maximize_type = GetMaximizeBubbleFrameState(); 466 MaximizeBubbleFrameState maximize_type = GetMaximizeBubbleFrameState();
467 gfx::Vector2d delta(location - press_location_); 467 gfx::Vector2d delta(location - press_location_);
468 if (!views::View::ExceededDragThreshold(delta)) 468 if (!views::View::ExceededDragThreshold(delta))
469 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; 469 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE;
470 if (delta.x() < 0 && delta.y() > delta.x() && delta.y() < -delta.x()) 470 if (delta.x() < 0 && delta.y() > delta.x() && delta.y() < -delta.x())
471 return maximize_type == FRAME_STATE_SNAP_LEFT ? SNAP_RESTORE : SNAP_LEFT; 471 return maximize_type == FRAME_STATE_SNAP_LEFT ? SNAP_RESTORE : SNAP_LEFT;
472 if (delta.x() > 0 && delta.y() > -delta.x() && delta.y() < delta.x()) 472 if (delta.x() > 0 && delta.y() > -delta.x() && delta.y() < delta.x())
473 return maximize_type == FRAME_STATE_SNAP_RIGHT ? SNAP_RESTORE : SNAP_RIGHT; 473 return maximize_type == FRAME_STATE_SNAP_RIGHT ? SNAP_RESTORE : SNAP_RIGHT;
474 if (delta.y() > 0) 474 if (delta.y() > 0)
475 return SNAP_MINIMIZE; 475 return SNAP_MINIMIZE;
476 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE; 476 return maximize_type != FRAME_STATE_FULL ? SNAP_MAXIMIZE : SNAP_RESTORE;
477 } 477 }
478 478
479 gfx::Rect FrameMaximizeButton::ScreenBoundsForType( 479 gfx::Rect FrameMaximizeButton::ScreenBoundsForType(
480 SnapType type, 480 SnapType type,
481 const SnapSizer& snap_sizer) const { 481 const SnapSizer& snap_sizer) const {
482 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); 482 aura::Window* window = frame_->GetNativeWindow();
483 switch (type) { 483 switch (type) {
484 case SNAP_LEFT: 484 case SNAP_LEFT:
485 case SNAP_RIGHT: 485 case SNAP_RIGHT:
486 return ScreenAsh::ConvertRectToScreen( 486 return ScreenAsh::ConvertRectToScreen(window->parent(),
487 frame_->GetWidget()->GetNativeView()->parent(), 487 snap_sizer.target_bounds());
488 snap_sizer.target_bounds());
489 case SNAP_MAXIMIZE: 488 case SNAP_MAXIMIZE:
490 return ScreenAsh::ConvertRectToScreen( 489 return ScreenAsh::ConvertRectToScreen(
491 window->parent(), 490 window->parent(),
492 ScreenAsh::GetMaximizedWindowBoundsInParent(window)); 491 ScreenAsh::GetMaximizedWindowBoundsInParent(window));
493 case SNAP_MINIMIZE: { 492 case SNAP_MINIMIZE: {
494 gfx::Rect rect = GetMinimizeAnimationTargetBoundsInScreen(window); 493 gfx::Rect rect = GetMinimizeAnimationTargetBoundsInScreen(window);
495 if (!rect.IsEmpty()) { 494 if (!rect.IsEmpty()) {
496 // PhantomWindowController insets slightly, outset it so the phantom 495 // PhantomWindowController insets slightly, outset it so the phantom
497 // doesn't appear inset. 496 // doesn't appear inset.
498 rect.Inset(-8, -8); 497 rect.Inset(-8, -8);
499 } 498 }
500 return rect; 499 return rect;
501 } 500 }
502 case SNAP_RESTORE: { 501 case SNAP_RESTORE: {
503 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); 502 const gfx::Rect* restore = GetRestoreBoundsInScreen(window);
504 return restore ? 503 return restore ? *restore : frame_->GetWindowBoundsInScreen();
505 *restore : frame_->GetWidget()->GetWindowBoundsInScreen();
506 } 504 }
507 case SNAP_NONE: 505 case SNAP_NONE:
508 NOTREACHED(); 506 NOTREACHED();
509 } 507 }
510 return gfx::Rect(); 508 return gfx::Rect();
511 } 509 }
512 510
513 gfx::Point FrameMaximizeButton::LocationForSnapSizer( 511 gfx::Point FrameMaximizeButton::LocationForSnapSizer(
514 const gfx::Point& location) const { 512 const gfx::Point& location) const {
515 gfx::Point result(location); 513 gfx::Point result(location);
516 views::View::ConvertPointToScreen(this, &result); 514 views::View::ConvertPointToScreen(this, &result);
517 return result; 515 return result;
518 } 516 }
519 517
520 void FrameMaximizeButton::Snap(const SnapSizer& snap_sizer) { 518 void FrameMaximizeButton::Snap(const SnapSizer& snap_sizer) {
521 ash::Shell* shell = ash::Shell::GetInstance(); 519 ash::Shell* shell = ash::Shell::GetInstance();
522 views::Widget* widget = frame_->GetWidget();
523 switch (snap_type_) { 520 switch (snap_type_) {
524 case SNAP_LEFT: 521 case SNAP_LEFT:
525 case SNAP_RIGHT: { 522 case SNAP_RIGHT: {
526 shell->delegate()->RecordUserMetricsAction( 523 shell->delegate()->RecordUserMetricsAction(
527 snap_type_ == SNAP_LEFT ? 524 snap_type_ == SNAP_LEFT ?
528 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT : 525 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT :
529 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); 526 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT);
530 // Get the bounds in screen coordinates for restore purposes. 527 // Get the bounds in screen coordinates for restore purposes.
531 gfx::Rect restore = widget->GetWindowBoundsInScreen(); 528 gfx::Rect restore = frame_->GetWindowBoundsInScreen();
532 if (widget->IsMaximized() || widget->IsFullscreen()) { 529 if (frame_->IsMaximized() || frame_->IsFullscreen()) {
533 aura::Window* window = widget->GetNativeWindow(); 530 aura::Window* window = frame_->GetNativeWindow();
534 // In case of maximized we have a restore boundary. 531 // In case of maximized we have a restore boundary.
535 DCHECK(ash::GetRestoreBoundsInScreen(window)); 532 DCHECK(ash::GetRestoreBoundsInScreen(window));
536 // If it was maximized we need to recover the old restore set. 533 // If it was maximized we need to recover the old restore set.
537 restore = *ash::GetRestoreBoundsInScreen(window); 534 restore = *ash::GetRestoreBoundsInScreen(window);
538 535
539 // The auto position manager will kick in when this is the only window. 536 // The auto position manager will kick in when this is the only window.
540 // To avoid interference with it we tell it temporarily to not change 537 // To avoid interference with it we tell it temporarily to not change
541 // the coordinates of this window. 538 // the coordinates of this window.
542 wm::WindowSettings* settings = wm::GetWindowSettings(window); 539 wm::WindowSettings* settings = wm::GetWindowSettings(window);
543 bool was_managed = settings->window_position_managed(); 540 bool was_managed = settings->window_position_managed();
544 settings->set_window_position_managed(false); 541 settings->set_window_position_managed(false);
545 542
546 // Set the restore size we want to restore to. 543 // Set the restore size we want to restore to.
547 ash::SetRestoreBoundsInScreen(window, 544 ash::SetRestoreBoundsInScreen(window,
548 ScreenBoundsForType(snap_type_, 545 ScreenBoundsForType(snap_type_,
549 snap_sizer)); 546 snap_sizer));
550 widget->Restore(); 547 frame_->Restore();
551 548
552 // After the window is where we want it to be we allow the window to be 549 // After the window is where we want it to be we allow the window to be
553 // auto managed again. 550 // auto managed again.
554 settings->set_window_position_managed(was_managed); 551 settings->set_window_position_managed(was_managed);
555 } else { 552 } else {
556 // Others might also have set up a restore rectangle already. If so, 553 // Others might also have set up a restore rectangle already. If so,
557 // we should not overwrite the restore rectangle. 554 // we should not overwrite the restore rectangle.
558 bool restore_set = 555 bool restore_set =
559 GetRestoreBoundsInScreen(widget->GetNativeWindow()) != NULL; 556 GetRestoreBoundsInScreen(frame_->GetNativeWindow()) != NULL;
560 widget->SetBounds(ScreenBoundsForType(snap_type_, snap_sizer)); 557 frame_->SetBounds(ScreenBoundsForType(snap_type_, snap_sizer));
561 if (restore_set) 558 if (restore_set)
562 break; 559 break;
563 } 560 }
564 // Remember the widow's bounds for restoration. 561 // Remember the widow's bounds for restoration.
565 ash::SetRestoreBoundsInScreen(widget->GetNativeWindow(), restore); 562 ash::SetRestoreBoundsInScreen(frame_->GetNativeWindow(), restore);
566 break; 563 break;
567 } 564 }
568 case SNAP_MAXIMIZE: 565 case SNAP_MAXIMIZE:
569 widget->Maximize(); 566 frame_->Maximize();
570 shell->delegate()->RecordUserMetricsAction( 567 shell->delegate()->RecordUserMetricsAction(
571 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE); 568 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE);
572 break; 569 break;
573 case SNAP_MINIMIZE: 570 case SNAP_MINIMIZE:
574 widget->Minimize(); 571 frame_->Minimize();
575 shell->delegate()->RecordUserMetricsAction( 572 shell->delegate()->RecordUserMetricsAction(
576 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MINIMIZE); 573 ash::UMA_WINDOW_MAXIMIZE_BUTTON_MINIMIZE);
577 break; 574 break;
578 case SNAP_RESTORE: 575 case SNAP_RESTORE:
579 widget->Restore(); 576 frame_->Restore();
580 shell->delegate()->RecordUserMetricsAction( 577 shell->delegate()->RecordUserMetricsAction(
581 ash::UMA_WINDOW_MAXIMIZE_BUTTON_RESTORE); 578 ash::UMA_WINDOW_MAXIMIZE_BUTTON_RESTORE);
582 break; 579 break;
583 case SNAP_NONE: 580 case SNAP_NONE:
584 NOTREACHED(); 581 NOTREACHED();
585 } 582 }
586 } 583 }
587 584
588 MaximizeBubbleFrameState 585 MaximizeBubbleFrameState
589 FrameMaximizeButton::GetMaximizeBubbleFrameState() const { 586 FrameMaximizeButton::GetMaximizeBubbleFrameState() const {
590 // When there are no restore bounds, we are in normal mode. 587 // When there are no restore bounds, we are in normal mode.
591 if (!ash::GetRestoreBoundsInScreen( 588 if (!ash::GetRestoreBoundsInScreen(frame_->GetNativeWindow()))
592 frame_->GetWidget()->GetNativeWindow()))
593 return FRAME_STATE_NONE; 589 return FRAME_STATE_NONE;
594 // The normal maximized test can be used. 590 // The normal maximized test can be used.
595 if (frame_->GetWidget()->IsMaximized()) 591 if (frame_->IsMaximized())
596 return FRAME_STATE_FULL; 592 return FRAME_STATE_FULL;
597 // For Left/right maximize we need to check the dimensions. 593 // For Left/right maximize we need to check the dimensions.
598 gfx::Rect bounds = frame_->GetWidget()->GetWindowBoundsInScreen(); 594 gfx::Rect bounds = frame_->GetWindowBoundsInScreen();
599 gfx::Rect screen = Shell::GetScreen()->GetDisplayNearestWindow( 595 gfx::Rect screen = Shell::GetScreen()->GetDisplayNearestWindow(
600 frame_->GetWidget()->GetNativeView()).work_area(); 596 frame_->GetNativeView()).work_area();
601 if (bounds.width() < (screen.width() * kMinSnapSizePercent) / 100) 597 if (bounds.width() < (screen.width() * kMinSnapSizePercent) / 100)
602 return FRAME_STATE_NONE; 598 return FRAME_STATE_NONE;
603 // We might still have a horizontally filled window at this point which we 599 // We might still have a horizontally filled window at this point which we
604 // treat as no special state. 600 // treat as no special state.
605 if (bounds.y() != screen.y() || bounds.height() != screen.height()) 601 if (bounds.y() != screen.y() || bounds.height() != screen.height())
606 return FRAME_STATE_NONE; 602 return FRAME_STATE_NONE;
607 603
608 // We have to be in a maximize mode at this point. 604 // We have to be in a maximize mode at this point.
609 if (bounds.x() == screen.x()) 605 if (bounds.x() == screen.x())
610 return FRAME_STATE_SNAP_LEFT; 606 return FRAME_STATE_SNAP_LEFT;
611 if (bounds.right() == screen.right()) 607 if (bounds.right() == screen.right())
612 return FRAME_STATE_SNAP_RIGHT; 608 return FRAME_STATE_SNAP_RIGHT;
613 // If we come here, it is likely caused by the fact that the 609 // If we come here, it is likely caused by the fact that the
614 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case 610 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case
615 // we allow all maximize operations (and keep the restore rectangle). 611 // we allow all maximize operations (and keep the restore rectangle).
616 return FRAME_STATE_NONE; 612 return FRAME_STATE_NONE;
617 } 613 }
618 614
619 } // namespace ash 615 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/caption_buttons/frame_maximize_button.h ('k') | ash/wm/custom_frame_view_ash.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698