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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 animated_attribute_(ANIMATED_ATTRIBUTE_BOUNDS) { | 392 animated_attribute_(ANIMATED_ATTRIBUTE_BOUNDS) { |
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_->GetAccelerator2(IDC_FULLSCREEN, &accelerator); |
403 IDC_FULLSCREEN, &accelerator); | |
404 DCHECK(got_accelerator); | 403 DCHECK(got_accelerator); |
405 view_ = new ExclusiveAccessView(this, accelerator.GetShortcutText(), url, | 404 view_ = new ExclusiveAccessView(this, accelerator.GetShortcutText(), url, |
406 bubble_type_); | 405 bubble_type_); |
407 | 406 |
408 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView. | 407 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView. |
409 // TODO(pkotwicz): When this becomes a views bubble, make sure that this | 408 // TODO(pkotwicz): When this becomes a views bubble, make sure that this |
410 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager. | 409 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager. |
411 // Initialize the popup. | 410 // Initialize the popup. |
412 popup_ = new views::Widget; | 411 popup_ = new views::Widget; |
413 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 412 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
414 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 413 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
415 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 414 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
416 params.parent = | 415 params.parent = bubble_view_context_->GetNativeView(); |
417 bubble_view_context_->GetBubbleAssociatedWidget()->GetNativeView(); | |
418 // The simplified UI just shows a notice; clicks should go through to the | 416 // The simplified UI just shows a notice; clicks should go through to the |
419 // underlying window. | 417 // underlying window. |
420 params.accept_events = | 418 params.accept_events = |
421 !ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled(); | 419 !ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled(); |
422 popup_->Init(params); | 420 popup_->Init(params); |
423 popup_->SetContentsView(view_); | 421 popup_->SetContentsView(view_); |
424 gfx::Size size = GetPopupRect(true).size(); | 422 gfx::Size size = GetPopupRect(true).size(); |
425 // Bounds are in screen coordinates. | 423 // Bounds are in screen coordinates. |
426 popup_->SetBounds(GetPopupRect(false)); | 424 popup_->SetBounds(GetPopupRect(false)); |
427 // We set layout manager to nullptr to prevent the widget from sizing its | 425 // We set layout manager to nullptr to prevent the widget from sizing its |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 } | 534 } |
537 | 535 |
538 void ExclusiveAccessBubbleViews::UpdateBounds() { | 536 void ExclusiveAccessBubbleViews::UpdateBounds() { |
539 gfx::Rect popup_rect(GetPopupRect(false)); | 537 gfx::Rect popup_rect(GetPopupRect(false)); |
540 if (!popup_rect.IsEmpty()) { | 538 if (!popup_rect.IsEmpty()) { |
541 popup_->SetBounds(popup_rect); | 539 popup_->SetBounds(popup_rect); |
542 view_->SetY(popup_rect.height() - view_->height()); | 540 view_->SetY(popup_rect.height() - view_->height()); |
543 } | 541 } |
544 } | 542 } |
545 | 543 |
546 views::View* ExclusiveAccessBubbleViews::GetBrowserRootView() const { | |
547 return bubble_view_context_->GetBubbleAssociatedWidget()->GetRootView(); | |
548 } | |
549 | |
550 void ExclusiveAccessBubbleViews::AnimationProgressed( | 544 void ExclusiveAccessBubbleViews::AnimationProgressed( |
551 const gfx::Animation* animation) { | 545 const gfx::Animation* animation) { |
552 if (animated_attribute_ == ANIMATED_ATTRIBUTE_OPACITY) { | 546 if (animated_attribute_ == ANIMATED_ATTRIBUTE_OPACITY) { |
553 int opacity = animation_->CurrentValueBetween(0, 255); | 547 int opacity = animation_->CurrentValueBetween(0, 255); |
554 if (opacity == 0) { | 548 if (opacity == 0) { |
555 popup_->Hide(); | 549 popup_->Hide(); |
556 } else { | 550 } else { |
557 popup_->Show(); | 551 popup_->Show(); |
558 popup_->SetOpacity(opacity); | 552 popup_->SetOpacity(opacity); |
559 } | 553 } |
560 } else { | 554 } else { |
561 if (GetPopupRect(false).IsEmpty()) { | 555 if (GetPopupRect(false).IsEmpty()) { |
562 popup_->Hide(); | 556 popup_->Hide(); |
563 } else { | 557 } else { |
564 UpdateBounds(); | 558 UpdateBounds(); |
565 popup_->Show(); | 559 popup_->Show(); |
566 } | 560 } |
567 } | 561 } |
568 } | 562 } |
569 | 563 |
570 void ExclusiveAccessBubbleViews::AnimationEnded( | 564 void ExclusiveAccessBubbleViews::AnimationEnded( |
571 const gfx::Animation* animation) { | 565 const gfx::Animation* animation) { |
572 AnimationProgressed(animation); | 566 AnimationProgressed(animation); |
573 } | 567 } |
574 | 568 |
575 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( | 569 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( |
576 bool ignore_animation_state) const { | 570 bool ignore_animation_state) const { |
577 gfx::Size size(view_->GetPreferredSize()); | 571 gfx::Size size(view_->GetPreferredSize()); |
578 gfx::Rect widget_bounds = bubble_view_context_->GetBubbleAssociatedWidget() | 572 gfx::Rect widget_bounds = bubble_view_context_->GetClientAreaBoundsInScreen(); |
579 ->GetClientAreaBoundsInScreen(); | |
580 int x = widget_bounds.x() + (widget_bounds.width() - size.width()) / 2; | 573 int x = widget_bounds.x() + (widget_bounds.width() - size.width()) / 2; |
581 | 574 |
582 int top_container_bottom = widget_bounds.y(); | 575 int top_container_bottom = widget_bounds.y(); |
583 if (bubble_view_context_->IsImmersiveModeEnabled()) { | 576 if (bubble_view_context_->IsImmersiveModeEnabled()) { |
584 // Skip querying the top container height in non-immersive fullscreen | 577 // Skip querying the top container height in non-immersive fullscreen |
585 // because: | 578 // because: |
586 // - The top container height is always zero in non-immersive fullscreen. | 579 // - The top container height is always zero in non-immersive fullscreen. |
587 // - Querying the top container height may return the height before entering | 580 // - Querying the top container height may return the height before entering |
588 // fullscreen because layout is disabled while entering fullscreen. | 581 // fullscreen because layout is disabled while entering fullscreen. |
589 // A visual glitch due to the delayed layout is avoided in immersive | 582 // 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; | 598 int total_height = size.height() + desired_top; |
606 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); | 599 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); |
607 int y_offset = std::min(popup_bottom, desired_top); | 600 int y_offset = std::min(popup_bottom, desired_top); |
608 size.set_height(size.height() - popup_bottom + y_offset); | 601 size.set_height(size.height() - popup_bottom + y_offset); |
609 y -= y_offset; | 602 y -= y_offset; |
610 } | 603 } |
611 return gfx::Rect(gfx::Point(x, y), size); | 604 return gfx::Rect(gfx::Point(x, y), size); |
612 } | 605 } |
613 | 606 |
614 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { | 607 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { |
615 gfx::Point cursor_pos = | 608 return bubble_view_context_->GetCursorScreenPoint(); |
616 gfx::Screen::GetScreenFor( | |
617 bubble_view_context_->GetBubbleAssociatedWidget()->GetNativeView()) | |
618 ->GetCursorScreenPoint(); | |
619 views::View::ConvertPointFromScreen(GetBrowserRootView(), &cursor_pos); | |
620 return cursor_pos; | |
621 } | 609 } |
622 | 610 |
623 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { | 611 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { |
624 return GetBrowserRootView()->HitTestPoint(pos); | 612 return bubble_view_context_->HitTestPoint(pos); |
625 } | 613 } |
626 | 614 |
627 bool ExclusiveAccessBubbleViews::IsWindowActive() { | 615 bool ExclusiveAccessBubbleViews::IsWindowActive() { |
628 return bubble_view_context_->GetBubbleAssociatedWidget()->IsActive(); | 616 return bubble_view_context_->IsParentActive(); |
629 } | 617 } |
630 | 618 |
631 void ExclusiveAccessBubbleViews::Hide() { | 619 void ExclusiveAccessBubbleViews::Hide() { |
632 animation_->SetSlideDuration(kSlideOutDurationMs); | 620 animation_->SetSlideDuration(kSlideOutDurationMs); |
633 animation_->Hide(); | 621 animation_->Hide(); |
634 } | 622 } |
635 | 623 |
636 void ExclusiveAccessBubbleViews::Show() { | 624 void ExclusiveAccessBubbleViews::Show() { |
637 animation_->SetSlideDuration(kSlideInDurationMs); | 625 animation_->SetSlideDuration(kSlideInDurationMs); |
638 animation_->Show(); | 626 animation_->Show(); |
(...skipping 13 matching lines...) Expand all Loading... |
652 const content::NotificationDetails& details) { | 640 const content::NotificationDetails& details) { |
653 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 641 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
654 UpdateForImmersiveState(); | 642 UpdateForImmersiveState(); |
655 } | 643 } |
656 | 644 |
657 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( | 645 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( |
658 views::Widget* widget, | 646 views::Widget* widget, |
659 bool visible) { | 647 bool visible) { |
660 UpdateMouseWatcher(); | 648 UpdateMouseWatcher(); |
661 } | 649 } |
OLD | NEW |