OLD | NEW |
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 "chrome/browser/ui/views/exclusive_access_bubble_views.h" | 5 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 ExclusiveAccessBubbleViews::ExclusiveAccessBubbleViews( | 382 ExclusiveAccessBubbleViews::ExclusiveAccessBubbleViews( |
383 ExclusiveAccessBubbleViewsContext* context, | 383 ExclusiveAccessBubbleViewsContext* context, |
384 const GURL& url, | 384 const GURL& url, |
385 ExclusiveAccessBubbleType bubble_type) | 385 ExclusiveAccessBubbleType bubble_type) |
386 : ExclusiveAccessBubble(context->GetExclusiveAccessManager(), | 386 : ExclusiveAccessBubble(context->GetExclusiveAccessManager(), |
387 url, | 387 url, |
388 bubble_type), | 388 bubble_type), |
389 bubble_view_context_(context), | 389 bubble_view_context_(context), |
390 popup_(nullptr), | 390 popup_(nullptr), |
391 animation_(new gfx::SlideAnimation(this)), | 391 animation_(new gfx::SlideAnimation(this)), |
392 animated_attribute_(ANIMATED_ATTRIBUTE_BOUNDS) { | 392 animated_attribute_(ExpectedAnimationAttribute()) { |
393 // With the simplified fullscreen UI flag, initially hide the bubble; | 393 // With the simplified fullscreen UI flag, initially hide the bubble; |
394 // otherwise, initially show it. | 394 // otherwise, initially show it. |
395 double initial_value = | 395 double initial_value = |
396 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 0 : 1; | 396 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() ? 0 : 1; |
397 animation_->Reset(initial_value); | 397 animation_->Reset(initial_value); |
398 | 398 |
399 // Create the contents view. | 399 // Create the contents view. |
400 ui::Accelerator accelerator(ui::VKEY_UNKNOWN, ui::EF_NONE); | 400 ui::Accelerator accelerator(ui::VKEY_UNKNOWN, ui::EF_NONE); |
401 bool got_accelerator = | 401 bool got_accelerator = |
402 bubble_view_context_->GetBubbleAssociatedWidget()->GetAccelerator( | 402 bubble_view_context_->GetAcceleratorProvider() |
403 IDC_FULLSCREEN, &accelerator); | 403 ->GetAcceleratorForCommandId(IDC_FULLSCREEN, &accelerator); |
404 DCHECK(got_accelerator); | 404 DCHECK(got_accelerator); |
405 view_ = new ExclusiveAccessView(this, accelerator.GetShortcutText(), url, | 405 view_ = new ExclusiveAccessView(this, accelerator.GetShortcutText(), url, |
406 bubble_type_); | 406 bubble_type_); |
407 | 407 |
408 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView. | 408 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView. |
409 // TODO(pkotwicz): When this becomes a views bubble, make sure that this | 409 // TODO(pkotwicz): When this becomes a views bubble, make sure that this |
410 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager. | 410 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager. |
411 // Initialize the popup. | 411 // Initialize the popup. |
412 popup_ = new views::Widget; | 412 popup_ = new views::Widget; |
413 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 413 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
414 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 414 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
415 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 415 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
416 params.parent = | 416 params.parent = bubble_view_context_->GetBubbleParentView(); |
417 bubble_view_context_->GetBubbleAssociatedWidget()->GetNativeView(); | |
418 // The simplified UI just shows a notice; clicks should go through to the | 417 // The simplified UI just shows a notice; clicks should go through to the |
419 // underlying window. | 418 // underlying window. |
420 params.accept_events = | 419 params.accept_events = |
421 !ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled(); | 420 !ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled(); |
422 popup_->Init(params); | 421 popup_->Init(params); |
423 popup_->SetContentsView(view_); | 422 popup_->SetContentsView(view_); |
424 gfx::Size size = GetPopupRect(true).size(); | 423 gfx::Size size = GetPopupRect(true).size(); |
425 // Bounds are in screen coordinates. | 424 // Bounds are in screen coordinates. |
426 popup_->SetBounds(GetPopupRect(false)); | 425 popup_->SetBounds(GetPopupRect(false)); |
427 // We set layout manager to nullptr to prevent the widget from sizing its | 426 // We set layout manager to nullptr to prevent the widget from sizing its |
428 // contents to the same size as itself. This prevents the widget contents from | 427 // contents to the same size as itself. This prevents the widget contents from |
429 // shrinking while we animate the height of the popup to give the impression | 428 // shrinking while we animate the height of the popup to give the impression |
430 // that it is sliding off the top of the screen. | 429 // that it is sliding off the top of the screen. |
431 popup_->GetRootView()->SetLayoutManager(nullptr); | 430 popup_->GetRootView()->SetLayoutManager(nullptr); |
432 view_->SetBounds(0, 0, size.width(), size.height()); | 431 view_->SetBounds(0, 0, size.width(), size.height()); |
433 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) | 432 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) |
434 popup_->ShowInactive(); // This does not activate the popup. | 433 popup_->ShowInactive(); // This does not activate the popup. |
435 | 434 |
436 popup_->AddObserver(this); | 435 popup_->AddObserver(this); |
437 | 436 |
438 registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 437 registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
439 content::Source<FullscreenController>( | 438 content::Source<FullscreenController>( |
440 bubble_view_context_->GetExclusiveAccessManager() | 439 bubble_view_context_->GetExclusiveAccessManager() |
441 ->fullscreen_controller())); | 440 ->fullscreen_controller())); |
442 | 441 |
443 UpdateForImmersiveState(); | 442 UpdateMouseWatcher(); |
444 } | 443 } |
445 | 444 |
446 ExclusiveAccessBubbleViews::~ExclusiveAccessBubbleViews() { | 445 ExclusiveAccessBubbleViews::~ExclusiveAccessBubbleViews() { |
447 popup_->RemoveObserver(this); | 446 popup_->RemoveObserver(this); |
448 | 447 |
449 // This is tricky. We may be in an ATL message handler stack, in which case | 448 // This is tricky. We may be in an ATL message handler stack, in which case |
450 // the popup cannot be deleted yet. We also can't set the popup's ownership | 449 // the popup cannot be deleted yet. We also can't set the popup's ownership |
451 // model to NATIVE_WIDGET_OWNS_WIDGET because if the user closed the last tab | 450 // model to NATIVE_WIDGET_OWNS_WIDGET because if the user closed the last tab |
452 // while in fullscreen mode, Windows has already destroyed the popup HWND by | 451 // while in fullscreen mode, Windows has already destroyed the popup HWND by |
453 // the time we get here, and thus either the popup will already have been | 452 // the time we get here, and thus either the popup will already have been |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 484 |
486 void ExclusiveAccessBubbleViews::RepositionIfVisible() { | 485 void ExclusiveAccessBubbleViews::RepositionIfVisible() { |
487 if (popup_->IsVisible()) | 486 if (popup_->IsVisible()) |
488 UpdateBounds(); | 487 UpdateBounds(); |
489 } | 488 } |
490 | 489 |
491 views::View* ExclusiveAccessBubbleViews::GetView() { | 490 views::View* ExclusiveAccessBubbleViews::GetView() { |
492 return view_; | 491 return view_; |
493 } | 492 } |
494 | 493 |
| 494 ExclusiveAccessBubbleViews::AnimatedAttribute |
| 495 ExclusiveAccessBubbleViews::ExpectedAnimationAttribute() { |
| 496 return ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() || |
| 497 bubble_view_context_->IsImmersiveModeEnabled() |
| 498 ? ANIMATED_ATTRIBUTE_OPACITY |
| 499 : ANIMATED_ATTRIBUTE_BOUNDS; |
| 500 } |
| 501 |
495 void ExclusiveAccessBubbleViews::UpdateMouseWatcher() { | 502 void ExclusiveAccessBubbleViews::UpdateMouseWatcher() { |
496 bool should_watch_mouse = false; | 503 bool should_watch_mouse = false; |
497 if (popup_->IsVisible()) | 504 if (popup_->IsVisible()) |
498 should_watch_mouse = | 505 should_watch_mouse = |
499 !exclusive_access_bubble::ShowButtonsForType(bubble_type_); | 506 !exclusive_access_bubble::ShowButtonsForType(bubble_type_); |
500 else | 507 else |
501 should_watch_mouse = CanMouseTriggerSlideIn(); | 508 should_watch_mouse = CanMouseTriggerSlideIn(); |
502 | 509 |
503 if (should_watch_mouse == IsWatchingMouse()) | 510 if (should_watch_mouse == IsWatchingMouse()) |
504 return; | 511 return; |
505 | 512 |
506 if (should_watch_mouse) | 513 if (should_watch_mouse) |
507 StartWatchingMouse(); | 514 StartWatchingMouse(); |
508 else | 515 else |
509 StopWatchingMouse(); | 516 StopWatchingMouse(); |
510 } | 517 } |
511 | 518 |
512 void ExclusiveAccessBubbleViews::UpdateForImmersiveState() { | 519 void ExclusiveAccessBubbleViews::UpdateForImmersiveState() { |
513 AnimatedAttribute expected_animated_attribute = | 520 AnimatedAttribute expected_animated_attribute = ExpectedAnimationAttribute(); |
514 ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() || | |
515 bubble_view_context_->IsImmersiveModeEnabled() | |
516 ? ANIMATED_ATTRIBUTE_OPACITY | |
517 : ANIMATED_ATTRIBUTE_BOUNDS; | |
518 if (animated_attribute_ != expected_animated_attribute) { | 521 if (animated_attribute_ != expected_animated_attribute) { |
519 // If an animation is currently in progress, skip to the end because | 522 // If an animation is currently in progress, skip to the end because |
520 // switching the animated attribute midway through the animation looks | 523 // switching the animated attribute midway through the animation looks |
521 // weird. | 524 // weird. |
522 animation_->End(); | 525 animation_->End(); |
523 | 526 |
524 animated_attribute_ = expected_animated_attribute; | 527 animated_attribute_ = expected_animated_attribute; |
525 | 528 |
526 // We may have finished hiding |popup_|. However, the bounds animation | 529 // We may have finished hiding |popup_|. However, the bounds animation |
527 // assumes |popup_| has the opacity when it is fully shown and the opacity | 530 // assumes |popup_| has the opacity when it is fully shown and the opacity |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 } | 571 } |
569 | 572 |
570 void ExclusiveAccessBubbleViews::AnimationEnded( | 573 void ExclusiveAccessBubbleViews::AnimationEnded( |
571 const gfx::Animation* animation) { | 574 const gfx::Animation* animation) { |
572 AnimationProgressed(animation); | 575 AnimationProgressed(animation); |
573 } | 576 } |
574 | 577 |
575 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( | 578 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( |
576 bool ignore_animation_state) const { | 579 bool ignore_animation_state) const { |
577 gfx::Size size(view_->GetPreferredSize()); | 580 gfx::Size size(view_->GetPreferredSize()); |
578 gfx::Rect widget_bounds = bubble_view_context_->GetBubbleAssociatedWidget() | 581 gfx::Rect widget_bounds = bubble_view_context_->GetClientAreaBoundsInScreen(); |
579 ->GetClientAreaBoundsInScreen(); | |
580 int x = widget_bounds.x() + (widget_bounds.width() - size.width()) / 2; | 582 int x = widget_bounds.x() + (widget_bounds.width() - size.width()) / 2; |
581 | 583 |
582 int top_container_bottom = widget_bounds.y(); | 584 int top_container_bottom = widget_bounds.y(); |
583 if (bubble_view_context_->IsImmersiveModeEnabled()) { | 585 if (bubble_view_context_->IsImmersiveModeEnabled()) { |
584 // Skip querying the top container height in non-immersive fullscreen | 586 // Skip querying the top container height in non-immersive fullscreen |
585 // because: | 587 // because: |
586 // - The top container height is always zero in non-immersive fullscreen. | 588 // - The top container height is always zero in non-immersive fullscreen. |
587 // - Querying the top container height may return the height before entering | 589 // - Querying the top container height may return the height before entering |
588 // fullscreen because layout is disabled while entering fullscreen. | 590 // fullscreen because layout is disabled while entering fullscreen. |
589 // A visual glitch due to the delayed layout is avoided in immersive | 591 // A visual glitch due to the delayed layout is avoided in immersive |
(...skipping 15 matching lines...) Expand all Loading... |
605 int total_height = size.height() + desired_top; | 607 int total_height = size.height() + desired_top; |
606 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); | 608 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); |
607 int y_offset = std::min(popup_bottom, desired_top); | 609 int y_offset = std::min(popup_bottom, desired_top); |
608 size.set_height(size.height() - popup_bottom + y_offset); | 610 size.set_height(size.height() - popup_bottom + y_offset); |
609 y -= y_offset; | 611 y -= y_offset; |
610 } | 612 } |
611 return gfx::Rect(gfx::Point(x, y), size); | 613 return gfx::Rect(gfx::Point(x, y), size); |
612 } | 614 } |
613 | 615 |
614 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { | 616 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { |
615 gfx::Point cursor_pos = gfx::Screen::GetScreen()->GetCursorScreenPoint(); | 617 return bubble_view_context_->GetCursorPointInParent(); |
616 views::View::ConvertPointFromScreen(GetBrowserRootView(), &cursor_pos); | |
617 return cursor_pos; | |
618 } | 618 } |
619 | 619 |
620 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { | 620 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { |
621 return GetBrowserRootView()->HitTestPoint(pos); | 621 return GetBrowserRootView()->HitTestPoint(pos); |
622 } | 622 } |
623 | 623 |
624 bool ExclusiveAccessBubbleViews::IsWindowActive() { | 624 bool ExclusiveAccessBubbleViews::IsWindowActive() { |
625 return bubble_view_context_->GetBubbleAssociatedWidget()->IsActive(); | 625 return bubble_view_context_->GetBubbleAssociatedWidget()->IsActive(); |
626 } | 626 } |
627 | 627 |
(...skipping 21 matching lines...) Expand all Loading... |
649 const content::NotificationDetails& details) { | 649 const content::NotificationDetails& details) { |
650 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 650 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
651 UpdateForImmersiveState(); | 651 UpdateForImmersiveState(); |
652 } | 652 } |
653 | 653 |
654 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( | 654 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( |
655 views::Widget* widget, | 655 views::Widget* widget, |
656 bool visible) { | 656 bool visible) { |
657 UpdateMouseWatcher(); | 657 UpdateMouseWatcher(); |
658 } | 658 } |
OLD | NEW |