| OLD | NEW |
| 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/immersive_fullscreen_controller.h" | 5 #include "ash/wm/immersive_fullscreen_controller.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "ash/common/ash_constants.h" | 9 #include "ash/common/ash_constants.h" |
| 10 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 widget_(NULL), | 242 widget_(NULL), |
| 243 native_window_(NULL), | 243 native_window_(NULL), |
| 244 observers_enabled_(false), | 244 observers_enabled_(false), |
| 245 enabled_(false), | 245 enabled_(false), |
| 246 reveal_state_(CLOSED), | 246 reveal_state_(CLOSED), |
| 247 revealed_lock_count_(0), | 247 revealed_lock_count_(0), |
| 248 mouse_x_when_hit_top_in_screen_(-1), | 248 mouse_x_when_hit_top_in_screen_(-1), |
| 249 gesture_begun_(false), | 249 gesture_begun_(false), |
| 250 animation_(new gfx::SlideAnimation(this)), | 250 animation_(new gfx::SlideAnimation(this)), |
| 251 animations_disabled_for_test_(false), | 251 animations_disabled_for_test_(false), |
| 252 weak_ptr_factory_(this) { | 252 weak_ptr_factory_(this) {} |
| 253 } | |
| 254 | 253 |
| 255 ImmersiveFullscreenController::~ImmersiveFullscreenController() { | 254 ImmersiveFullscreenController::~ImmersiveFullscreenController() { |
| 256 EnableWindowObservers(false); | 255 EnableWindowObservers(false); |
| 257 } | 256 } |
| 258 | 257 |
| 259 void ImmersiveFullscreenController::Init(Delegate* delegate, | 258 void ImmersiveFullscreenController::Init(Delegate* delegate, |
| 260 views::Widget* widget, | 259 views::Widget* widget, |
| 261 views::View* top_container) { | 260 views::View* top_container) { |
| 262 delegate_ = delegate; | 261 delegate_ = delegate; |
| 263 top_container_ = top_container; | 262 top_container_ = top_container; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 307 } |
| 309 } else { | 308 } else { |
| 310 // Stop cursor-at-top tracking. | 309 // Stop cursor-at-top tracking. |
| 311 top_edge_hover_timer_.Stop(); | 310 top_edge_hover_timer_.Stop(); |
| 312 reveal_state_ = CLOSED; | 311 reveal_state_ = CLOSED; |
| 313 | 312 |
| 314 delegate_->OnImmersiveFullscreenExited(); | 313 delegate_->OnImmersiveFullscreenExited(); |
| 315 } | 314 } |
| 316 | 315 |
| 317 if (enabled_) { | 316 if (enabled_) { |
| 318 UMA_HISTOGRAM_ENUMERATION("Ash.ImmersiveFullscreen.WindowType", | 317 UMA_HISTOGRAM_ENUMERATION("Ash.ImmersiveFullscreen.WindowType", window_type, |
| 319 window_type, | |
| 320 WINDOW_TYPE_COUNT); | 318 WINDOW_TYPE_COUNT); |
| 321 } | 319 } |
| 322 } | 320 } |
| 323 | 321 |
| 324 bool ImmersiveFullscreenController::IsEnabled() const { | 322 bool ImmersiveFullscreenController::IsEnabled() const { |
| 325 return enabled_; | 323 return enabled_; |
| 326 } | 324 } |
| 327 | 325 |
| 328 bool ImmersiveFullscreenController::IsRevealed() const { | 326 bool ImmersiveFullscreenController::IsRevealed() const { |
| 329 return enabled_ && reveal_state_ != CLOSED; | 327 return enabled_ && reveal_state_ != CLOSED; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 default: | 432 default: |
| 435 break; | 433 break; |
| 436 } | 434 } |
| 437 } | 435 } |
| 438 | 436 |
| 439 //////////////////////////////////////////////////////////////////////////////// | 437 //////////////////////////////////////////////////////////////////////////////// |
| 440 // views::FocusChangeListener overrides: | 438 // views::FocusChangeListener overrides: |
| 441 | 439 |
| 442 void ImmersiveFullscreenController::OnWillChangeFocus( | 440 void ImmersiveFullscreenController::OnWillChangeFocus( |
| 443 views::View* focused_before, | 441 views::View* focused_before, |
| 444 views::View* focused_now) { | 442 views::View* focused_now) {} |
| 445 } | |
| 446 | 443 |
| 447 void ImmersiveFullscreenController::OnDidChangeFocus( | 444 void ImmersiveFullscreenController::OnDidChangeFocus( |
| 448 views::View* focused_before, | 445 views::View* focused_before, |
| 449 views::View* focused_now) { | 446 views::View* focused_now) { |
| 450 UpdateFocusRevealedLock(); | 447 UpdateFocusRevealedLock(); |
| 451 } | 448 } |
| 452 | 449 |
| 453 //////////////////////////////////////////////////////////////////////////////// | 450 //////////////////////////////////////////////////////////////////////////////// |
| 454 // views::WidgetObserver overrides: | 451 // views::WidgetObserver overrides: |
| 455 | 452 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 aura::Window* transient) { | 502 aura::Window* transient) { |
| 506 bubble_observer_->StopObserving(transient); | 503 bubble_observer_->StopObserving(transient); |
| 507 } | 504 } |
| 508 | 505 |
| 509 //////////////////////////////////////////////////////////////////////////////// | 506 //////////////////////////////////////////////////////////////////////////////// |
| 510 // ash::ImmersiveRevealedLock::Delegate overrides: | 507 // ash::ImmersiveRevealedLock::Delegate overrides: |
| 511 | 508 |
| 512 void ImmersiveFullscreenController::LockRevealedState( | 509 void ImmersiveFullscreenController::LockRevealedState( |
| 513 AnimateReveal animate_reveal) { | 510 AnimateReveal animate_reveal) { |
| 514 ++revealed_lock_count_; | 511 ++revealed_lock_count_; |
| 515 Animate animate = (animate_reveal == ANIMATE_REVEAL_YES) ? | 512 Animate animate = |
| 516 ANIMATE_FAST : ANIMATE_NO; | 513 (animate_reveal == ANIMATE_REVEAL_YES) ? ANIMATE_FAST : ANIMATE_NO; |
| 517 MaybeStartReveal(animate); | 514 MaybeStartReveal(animate); |
| 518 } | 515 } |
| 519 | 516 |
| 520 void ImmersiveFullscreenController::UnlockRevealedState() { | 517 void ImmersiveFullscreenController::UnlockRevealedState() { |
| 521 --revealed_lock_count_; | 518 --revealed_lock_count_; |
| 522 DCHECK_GE(revealed_lock_count_, 0); | 519 DCHECK_GE(revealed_lock_count_, 0); |
| 523 if (revealed_lock_count_ == 0) { | 520 if (revealed_lock_count_ == 0) { |
| 524 // Always animate ending the reveal fast. | 521 // Always animate ending the reveal fast. |
| 525 MaybeEndReveal(ANIMATE_FAST); | 522 MaybeEndReveal(ANIMATE_FAST); |
| 526 } | 523 } |
| 527 } | 524 } |
| 528 | 525 |
| 529 //////////////////////////////////////////////////////////////////////////////// | 526 //////////////////////////////////////////////////////////////////////////////// |
| 530 // private: | 527 // private: |
| 531 | 528 |
| 532 void ImmersiveFullscreenController::EnableWindowObservers(bool enable) { | 529 void ImmersiveFullscreenController::EnableWindowObservers(bool enable) { |
| 533 if (observers_enabled_ == enable) | 530 if (observers_enabled_ == enable) |
| 534 return; | 531 return; |
| 535 observers_enabled_ = enable; | 532 observers_enabled_ = enable; |
| 536 | 533 |
| 537 views::FocusManager* focus_manager = widget_->GetFocusManager(); | 534 views::FocusManager* focus_manager = widget_->GetFocusManager(); |
| 538 | 535 |
| 539 if (enable) { | 536 if (enable) { |
| 540 widget_->AddObserver(this); | 537 widget_->AddObserver(this); |
| 541 focus_manager->AddFocusChangeListener(this); | 538 focus_manager->AddFocusChangeListener(this); |
| 542 Shell::GetInstance()->AddPreTargetHandler(this); | 539 Shell::GetInstance()->AddPreTargetHandler(this); |
| 543 ::wm::TransientWindowManager::Get(native_window_)-> | 540 ::wm::TransientWindowManager::Get(native_window_)->AddObserver(this); |
| 544 AddObserver(this); | |
| 545 | 541 |
| 546 RecreateBubbleObserver(); | 542 RecreateBubbleObserver(); |
| 547 } else { | 543 } else { |
| 548 widget_->RemoveObserver(this); | 544 widget_->RemoveObserver(this); |
| 549 focus_manager->RemoveFocusChangeListener(this); | 545 focus_manager->RemoveFocusChangeListener(this); |
| 550 Shell::GetInstance()->RemovePreTargetHandler(this); | 546 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 551 ::wm::TransientWindowManager::Get(native_window_)-> | 547 ::wm::TransientWindowManager::Get(native_window_)->RemoveObserver(this); |
| 552 RemoveObserver(this); | |
| 553 | 548 |
| 554 // We have stopped observing whether transient children are added or removed | 549 // We have stopped observing whether transient children are added or removed |
| 555 // to |native_window_|. The set of bubbles that BubbleObserver is observing | 550 // to |native_window_|. The set of bubbles that BubbleObserver is observing |
| 556 // will become stale really quickly. Destroy BubbleObserver and recreate it | 551 // will become stale really quickly. Destroy BubbleObserver and recreate it |
| 557 // when we start observing |native_window_| again. | 552 // when we start observing |native_window_| again. |
| 558 bubble_observer_.reset(); | 553 bubble_observer_.reset(); |
| 559 | 554 |
| 560 animation_->Stop(); | 555 animation_->Stop(); |
| 561 } | 556 } |
| 562 } | 557 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 if (top_edge_hover_timer_.IsRunning() && | 595 if (top_edge_hover_timer_.IsRunning() && |
| 601 abs(location_in_screen.x() - mouse_x_when_hit_top_in_screen_) <= | 596 abs(location_in_screen.x() - mouse_x_when_hit_top_in_screen_) <= |
| 602 kMouseRevealXThresholdPixels) | 597 kMouseRevealXThresholdPixels) |
| 603 return; | 598 return; |
| 604 | 599 |
| 605 // Start the reveal if the cursor doesn't move for some amount of time. | 600 // Start the reveal if the cursor doesn't move for some amount of time. |
| 606 mouse_x_when_hit_top_in_screen_ = location_in_screen.x(); | 601 mouse_x_when_hit_top_in_screen_ = location_in_screen.x(); |
| 607 top_edge_hover_timer_.Stop(); | 602 top_edge_hover_timer_.Stop(); |
| 608 // Timer is stopped when |this| is destroyed, hence Unretained() is safe. | 603 // Timer is stopped when |this| is destroyed, hence Unretained() is safe. |
| 609 top_edge_hover_timer_.Start( | 604 top_edge_hover_timer_.Start( |
| 610 FROM_HERE, | 605 FROM_HERE, base::TimeDelta::FromMilliseconds(kMouseRevealDelayMs), |
| 611 base::TimeDelta::FromMilliseconds(kMouseRevealDelayMs), | |
| 612 base::Bind( | 606 base::Bind( |
| 613 &ImmersiveFullscreenController::AcquireLocatedEventRevealedLock, | 607 &ImmersiveFullscreenController::AcquireLocatedEventRevealedLock, |
| 614 base::Unretained(this))); | 608 base::Unretained(this))); |
| 615 } | 609 } |
| 616 | 610 |
| 617 void ImmersiveFullscreenController::UpdateLocatedEventRevealedLock( | 611 void ImmersiveFullscreenController::UpdateLocatedEventRevealedLock( |
| 618 ui::LocatedEvent* event) { | 612 ui::LocatedEvent* event) { |
| 619 if (!enabled_) | 613 if (!enabled_) |
| 620 return; | 614 return; |
| 621 DCHECK(!event || event->IsMouseEvent() || event->IsTouchEvent()); | 615 DCHECK(!event || event->IsMouseEvent() || event->IsTouchEvent()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 635 | 629 |
| 636 // Ignore all events while a window has capture. This keeps the top-of-window | 630 // Ignore all events while a window has capture. This keeps the top-of-window |
| 637 // views revealed during a drag. | 631 // views revealed during a drag. |
| 638 if (aura::client::GetCaptureWindow(native_window_)) | 632 if (aura::client::GetCaptureWindow(native_window_)) |
| 639 return; | 633 return; |
| 640 | 634 |
| 641 gfx::Point location_in_screen; | 635 gfx::Point location_in_screen; |
| 642 if (event && event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) { | 636 if (event && event->type() != ui::ET_MOUSE_CAPTURE_CHANGED) { |
| 643 location_in_screen = GetEventLocationInScreen(*event); | 637 location_in_screen = GetEventLocationInScreen(*event); |
| 644 } else { | 638 } else { |
| 645 aura::client::CursorClient* cursor_client = aura::client::GetCursorClient( | 639 aura::client::CursorClient* cursor_client = |
| 646 native_window_->GetRootWindow()); | 640 aura::client::GetCursorClient(native_window_->GetRootWindow()); |
| 647 if (!cursor_client->IsMouseEventsEnabled()) { | 641 if (!cursor_client->IsMouseEventsEnabled()) { |
| 648 // If mouse events are disabled, the user's last interaction was probably | 642 // If mouse events are disabled, the user's last interaction was probably |
| 649 // via touch. Do no do further processing in this case as there is no easy | 643 // via touch. Do no do further processing in this case as there is no easy |
| 650 // way of retrieving the position of the user's last touch. | 644 // way of retrieving the position of the user's last touch. |
| 651 return; | 645 return; |
| 652 } | 646 } |
| 653 location_in_screen = aura::Env::GetInstance()->last_mouse_location(); | 647 location_in_screen = aura::Env::GetInstance()->last_mouse_location(); |
| 654 } | 648 } |
| 655 | 649 |
| 656 if ((!event || event->IsMouseEvent()) && | 650 if ((!event || event->IsMouseEvent()) && |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 void ImmersiveFullscreenController::UpdateFocusRevealedLock() { | 690 void ImmersiveFullscreenController::UpdateFocusRevealedLock() { |
| 697 if (!enabled_) | 691 if (!enabled_) |
| 698 return; | 692 return; |
| 699 | 693 |
| 700 bool hold_lock = false; | 694 bool hold_lock = false; |
| 701 if (widget_->IsActive()) { | 695 if (widget_->IsActive()) { |
| 702 views::View* focused_view = widget_->GetFocusManager()->GetFocusedView(); | 696 views::View* focused_view = widget_->GetFocusManager()->GetFocusedView(); |
| 703 if (top_container_->Contains(focused_view)) | 697 if (top_container_->Contains(focused_view)) |
| 704 hold_lock = true; | 698 hold_lock = true; |
| 705 } else { | 699 } else { |
| 706 aura::Window* active_window = aura::client::GetActivationClient( | 700 aura::Window* active_window = |
| 707 native_window_->GetRootWindow())->GetActiveWindow(); | 701 aura::client::GetActivationClient(native_window_->GetRootWindow()) |
| 702 ->GetActiveWindow(); |
| 708 if (GetAnchorView(active_window)) { | 703 if (GetAnchorView(active_window)) { |
| 709 // BubbleObserver will already have locked the top-of-window views if the | 704 // BubbleObserver will already have locked the top-of-window views if the |
| 710 // bubble is anchored to a child of |top_container_|. Don't acquire | 705 // bubble is anchored to a child of |top_container_|. Don't acquire |
| 711 // |focus_revealed_lock_| here for the sake of simplicity. | 706 // |focus_revealed_lock_| here for the sake of simplicity. |
| 712 // Note: Instead of checking for the existence of the |anchor_view|, | 707 // Note: Instead of checking for the existence of the |anchor_view|, |
| 713 // the existence of the |anchor_widget| is performed to avoid the case | 708 // the existence of the |anchor_widget| is performed to avoid the case |
| 714 // where the view is already gone (and the widget is still running). | 709 // where the view is already gone (and the widget is still running). |
| 715 } else { | 710 } else { |
| 716 // The currently active window is not |native_window_| and it is not a | 711 // The currently active window is not |native_window_| and it is not a |
| 717 // bubble with an anchor view. The top-of-window views should be revealed | 712 // bubble with an anchor view. The top-of-window views should be revealed |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 ::wm::GetTransientChildren(native_window_); | 932 ::wm::GetTransientChildren(native_window_); |
| 938 for (size_t i = 0; i < transient_children.size(); ++i) { | 933 for (size_t i = 0; i < transient_children.size(); ++i) { |
| 939 aura::Window* transient_child = transient_children[i]; | 934 aura::Window* transient_child = transient_children[i]; |
| 940 views::View* anchor_view = GetAnchorView(transient_child); | 935 views::View* anchor_view = GetAnchorView(transient_child); |
| 941 if (anchor_view && top_container_->Contains(anchor_view)) | 936 if (anchor_view && top_container_->Contains(anchor_view)) |
| 942 bubble_observer_->StartObserving(transient_child); | 937 bubble_observer_->StartObserving(transient_child); |
| 943 } | 938 } |
| 944 } | 939 } |
| 945 | 940 |
| 946 } // namespace ash | 941 } // namespace ash |
| OLD | NEW |