Chromium Code Reviews| 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()) { |
|
tapted
2016/02/03 06:20:53
this used to happen in a call to UpdateForImmersiv
msw
2016/02/03 18:52:24
Acknowledged.
| |
| 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 = bubble_view_context_->GetAcceleratorForCommandId( |
| 402 bubble_view_context_->GetBubbleAssociatedWidget()->GetAccelerator( | 402 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_->GetParentView(); |
| 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)); |
|
tapted
2016/02/03 06:20:53
prior to the change to the animated_attribute_ ini
msw
2016/02/03 18:52:24
Acknowledged.
| |
| 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 |
| 428 // contents to the same size as itself. This prevents the widget contents from | 426 // 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 | 427 // shrinking while we animate the height of the popup to give the impression |
| 430 // that it is sliding off the top of the screen. | 428 // that it is sliding off the top of the screen. |
| 431 popup_->GetRootView()->SetLayoutManager(nullptr); | 429 popup_->GetRootView()->SetLayoutManager(nullptr); |
| 432 view_->SetBounds(0, 0, size.width(), size.height()); | 430 view_->SetBounds(0, 0, size.width(), size.height()); |
| 433 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) | 431 if (!ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) |
| 434 popup_->ShowInactive(); // This does not activate the popup. | 432 popup_->ShowInactive(); // This does not activate the popup. |
| 435 | 433 |
| 436 popup_->AddObserver(this); | 434 popup_->AddObserver(this); |
| 437 | 435 |
| 438 registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 436 registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 439 content::Source<FullscreenController>( | 437 content::Source<FullscreenController>( |
| 440 bubble_view_context_->GetExclusiveAccessManager() | 438 bubble_view_context_->GetExclusiveAccessManager() |
| 441 ->fullscreen_controller())); | 439 ->fullscreen_controller())); |
| 442 | 440 |
| 443 UpdateForImmersiveState(); | 441 UpdateMouseWatcher(); |
| 444 } | 442 } |
| 445 | 443 |
| 446 ExclusiveAccessBubbleViews::~ExclusiveAccessBubbleViews() { | 444 ExclusiveAccessBubbleViews::~ExclusiveAccessBubbleViews() { |
| 447 popup_->RemoveObserver(this); | 445 popup_->RemoveObserver(this); |
| 448 | 446 |
| 449 // This is tricky. We may be in an ATL message handler stack, in which case | 447 // 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 | 448 // 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 | 449 // 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 | 450 // 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 | 451 // 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 | 483 |
| 486 void ExclusiveAccessBubbleViews::RepositionIfVisible() { | 484 void ExclusiveAccessBubbleViews::RepositionIfVisible() { |
| 487 if (popup_->IsVisible()) | 485 if (popup_->IsVisible()) |
| 488 UpdateBounds(); | 486 UpdateBounds(); |
| 489 } | 487 } |
| 490 | 488 |
| 491 views::View* ExclusiveAccessBubbleViews::GetView() { | 489 views::View* ExclusiveAccessBubbleViews::GetView() { |
| 492 return view_; | 490 return view_; |
| 493 } | 491 } |
| 494 | 492 |
| 493 ExclusiveAccessBubbleViews::AnimatedAttribute | |
| 494 ExclusiveAccessBubbleViews::ExpectedAnimationAttribute() { | |
| 495 return ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() || | |
| 496 bubble_view_context_->IsImmersiveModeEnabled() | |
| 497 ? ANIMATED_ATTRIBUTE_OPACITY | |
| 498 : ANIMATED_ATTRIBUTE_BOUNDS; | |
| 499 } | |
| 500 | |
| 495 void ExclusiveAccessBubbleViews::UpdateMouseWatcher() { | 501 void ExclusiveAccessBubbleViews::UpdateMouseWatcher() { |
| 496 bool should_watch_mouse = false; | 502 bool should_watch_mouse = false; |
| 497 if (popup_->IsVisible()) | 503 if (popup_->IsVisible()) |
| 498 should_watch_mouse = | 504 should_watch_mouse = |
| 499 !exclusive_access_bubble::ShowButtonsForType(bubble_type_); | 505 !exclusive_access_bubble::ShowButtonsForType(bubble_type_); |
| 500 else | 506 else |
| 501 should_watch_mouse = CanMouseTriggerSlideIn(); | 507 should_watch_mouse = CanMouseTriggerSlideIn(); |
| 502 | 508 |
| 503 if (should_watch_mouse == IsWatchingMouse()) | 509 if (should_watch_mouse == IsWatchingMouse()) |
| 504 return; | 510 return; |
| 505 | 511 |
| 506 if (should_watch_mouse) | 512 if (should_watch_mouse) |
| 507 StartWatchingMouse(); | 513 StartWatchingMouse(); |
| 508 else | 514 else |
| 509 StopWatchingMouse(); | 515 StopWatchingMouse(); |
| 510 } | 516 } |
| 511 | 517 |
| 512 void ExclusiveAccessBubbleViews::UpdateForImmersiveState() { | 518 void ExclusiveAccessBubbleViews::UpdateForImmersiveState() { |
| 513 AnimatedAttribute expected_animated_attribute = | 519 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) { | 520 if (animated_attribute_ != expected_animated_attribute) { |
| 519 // If an animation is currently in progress, skip to the end because | 521 // If an animation is currently in progress, skip to the end because |
| 520 // switching the animated attribute midway through the animation looks | 522 // switching the animated attribute midway through the animation looks |
| 521 // weird. | 523 // weird. |
| 522 animation_->End(); | 524 animation_->End(); |
| 523 | 525 |
| 524 animated_attribute_ = expected_animated_attribute; | 526 animated_attribute_ = expected_animated_attribute; |
| 525 | 527 |
| 526 // We may have finished hiding |popup_|. However, the bounds animation | 528 // We may have finished hiding |popup_|. However, the bounds animation |
| 527 // assumes |popup_| has the opacity when it is fully shown and the opacity | 529 // 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 } | 570 } |
| 569 | 571 |
| 570 void ExclusiveAccessBubbleViews::AnimationEnded( | 572 void ExclusiveAccessBubbleViews::AnimationEnded( |
| 571 const gfx::Animation* animation) { | 573 const gfx::Animation* animation) { |
| 572 AnimationProgressed(animation); | 574 AnimationProgressed(animation); |
| 573 } | 575 } |
| 574 | 576 |
| 575 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( | 577 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( |
| 576 bool ignore_animation_state) const { | 578 bool ignore_animation_state) const { |
| 577 gfx::Size size(view_->GetPreferredSize()); | 579 gfx::Size size(view_->GetPreferredSize()); |
| 578 gfx::Rect widget_bounds = bubble_view_context_->GetBubbleAssociatedWidget() | 580 gfx::Rect widget_bounds = bubble_view_context_->GetClientAreaBoundsInScreen(); |
| 579 ->GetClientAreaBoundsInScreen(); | |
| 580 int x = widget_bounds.x() + (widget_bounds.width() - size.width()) / 2; | 581 int x = widget_bounds.x() + (widget_bounds.width() - size.width()) / 2; |
| 581 | 582 |
| 582 int top_container_bottom = widget_bounds.y(); | 583 int top_container_bottom = widget_bounds.y(); |
| 583 if (bubble_view_context_->IsImmersiveModeEnabled()) { | 584 if (bubble_view_context_->IsImmersiveModeEnabled()) { |
| 584 // Skip querying the top container height in non-immersive fullscreen | 585 // Skip querying the top container height in non-immersive fullscreen |
| 585 // because: | 586 // because: |
| 586 // - The top container height is always zero in non-immersive fullscreen. | 587 // - The top container height is always zero in non-immersive fullscreen. |
| 587 // - Querying the top container height may return the height before entering | 588 // - Querying the top container height may return the height before entering |
| 588 // fullscreen because layout is disabled while entering fullscreen. | 589 // fullscreen because layout is disabled while entering fullscreen. |
| 589 // A visual glitch due to the delayed layout is avoided in immersive | 590 // 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; | 606 int total_height = size.height() + desired_top; |
| 606 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); | 607 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); |
| 607 int y_offset = std::min(popup_bottom, desired_top); | 608 int y_offset = std::min(popup_bottom, desired_top); |
| 608 size.set_height(size.height() - popup_bottom + y_offset); | 609 size.set_height(size.height() - popup_bottom + y_offset); |
| 609 y -= y_offset; | 610 y -= y_offset; |
| 610 } | 611 } |
| 611 return gfx::Rect(gfx::Point(x, y), size); | 612 return gfx::Rect(gfx::Point(x, y), size); |
| 612 } | 613 } |
| 613 | 614 |
| 614 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { | 615 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { |
| 615 gfx::Point cursor_pos = gfx::Screen::GetScreen()->GetCursorScreenPoint(); | 616 return bubble_view_context_->GetCursorPointInParent(); |
| 616 views::View::ConvertPointFromScreen(GetBrowserRootView(), &cursor_pos); | |
| 617 return cursor_pos; | |
| 618 } | 617 } |
| 619 | 618 |
| 620 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { | 619 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { |
| 621 return GetBrowserRootView()->HitTestPoint(pos); | 620 return GetBrowserRootView()->HitTestPoint(pos); |
| 622 } | 621 } |
| 623 | 622 |
| 624 bool ExclusiveAccessBubbleViews::IsWindowActive() { | 623 bool ExclusiveAccessBubbleViews::IsWindowActive() { |
| 625 return bubble_view_context_->GetBubbleAssociatedWidget()->IsActive(); | 624 return bubble_view_context_->GetBubbleAssociatedWidget()->IsActive(); |
| 626 } | 625 } |
| 627 | 626 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 649 const content::NotificationDetails& details) { | 648 const content::NotificationDetails& details) { |
| 650 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 649 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
| 651 UpdateForImmersiveState(); | 650 UpdateForImmersiveState(); |
| 652 } | 651 } |
| 653 | 652 |
| 654 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( | 653 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( |
| 655 views::Widget* widget, | 654 views::Widget* widget, |
| 656 bool visible) { | 655 bool visible) { |
| 657 UpdateMouseWatcher(); | 656 UpdateMouseWatcher(); |
| 658 } | 657 } |
| OLD | NEW |