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 "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" | 11 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
12 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 12 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
13 #include "chrome/browser/ui/views/frame/browser_view.h" | 13 #include "chrome/browser/ui/views/exclusive_access_bubble_views_context.h" |
14 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 14 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
15 #include "chrome/browser/ui/views/frame/top_container_view.h" | 15 #include "chrome/browser/ui/views/frame/top_container_view.h" |
16 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/events/keycodes/keyboard_codes.h" | 20 #include "ui/events/keycodes/keyboard_codes.h" |
21 #include "ui/gfx/animation/slide_animation.h" | 21 #include "ui/gfx/animation/slide_animation.h" |
22 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
23 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
(...skipping 26 matching lines...) Expand all Loading... |
50 | 50 |
51 // Returns an empty size when the view is not visible. | 51 // Returns an empty size when the view is not visible. |
52 gfx::Size GetPreferredSize() const override; | 52 gfx::Size GetPreferredSize() const override; |
53 | 53 |
54 views::LabelButton* accept_button() const { return accept_button_; } | 54 views::LabelButton* accept_button() const { return accept_button_; } |
55 views::LabelButton* deny_button() const { return deny_button_; } | 55 views::LabelButton* deny_button() const { return deny_button_; } |
56 | 56 |
57 private: | 57 private: |
58 views::LabelButton* accept_button_; | 58 views::LabelButton* accept_button_; |
59 views::LabelButton* deny_button_; | 59 views::LabelButton* deny_button_; |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(ButtonView); | 60 DISALLOW_COPY_AND_ASSIGN(ButtonView); |
62 }; | 61 }; |
63 | 62 |
64 ButtonView::ButtonView(views::ButtonListener* listener, | 63 ButtonView::ButtonView(views::ButtonListener* listener, |
65 int between_button_spacing) | 64 int between_button_spacing) |
66 : accept_button_(NULL), deny_button_(NULL) { | 65 : accept_button_(NULL), deny_button_(NULL) { |
67 accept_button_ = new views::LabelButton(listener, base::string16()); | 66 accept_button_ = new views::LabelButton(listener, base::string16()); |
68 accept_button_->SetStyle(views::Button::STYLE_BUTTON); | 67 accept_button_->SetStyle(views::Button::STYLE_BUTTON); |
69 accept_button_->SetFocusable(false); | 68 accept_button_->SetFocusable(false); |
70 AddChildView(accept_button_); | 69 AddChildView(accept_button_); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 #endif | 249 #endif |
251 link_->SetVisible(link_visible); | 250 link_->SetVisible(link_visible); |
252 mouse_lock_exit_instruction_->SetVisible(!link_visible); | 251 mouse_lock_exit_instruction_->SetVisible(!link_visible); |
253 button_view_->SetVisible(false); | 252 button_view_->SetVisible(false); |
254 } | 253 } |
255 } | 254 } |
256 | 255 |
257 // ExclusiveAccessBubbleViews -------------------------------------------------- | 256 // ExclusiveAccessBubbleViews -------------------------------------------------- |
258 | 257 |
259 ExclusiveAccessBubbleViews::ExclusiveAccessBubbleViews( | 258 ExclusiveAccessBubbleViews::ExclusiveAccessBubbleViews( |
260 BrowserView* browser_view, | 259 ExclusiveAccessBubbleViewsContext* context, |
261 const GURL& url, | 260 const GURL& url, |
262 ExclusiveAccessBubbleType bubble_type) | 261 ExclusiveAccessBubbleType bubble_type) |
263 : ExclusiveAccessBubble(browser_view->browser(), url, bubble_type), | 262 : ExclusiveAccessBubble(context->GetExclusiveAccessManager(), |
264 browser_view_(browser_view), | 263 url, |
| 264 bubble_type), |
| 265 bubble_view_context_(context), |
265 popup_(NULL), | 266 popup_(NULL), |
266 animation_(new gfx::SlideAnimation(this)), | 267 animation_(new gfx::SlideAnimation(this)), |
267 animated_attribute_(ANIMATED_ATTRIBUTE_BOUNDS) { | 268 animated_attribute_(ANIMATED_ATTRIBUTE_BOUNDS) { |
268 animation_->Reset(1); | 269 animation_->Reset(1); |
269 | 270 |
270 // Create the contents view. | 271 // Create the contents view. |
271 ui::Accelerator accelerator(ui::VKEY_UNKNOWN, ui::EF_NONE); | 272 ui::Accelerator accelerator(ui::VKEY_UNKNOWN, ui::EF_NONE); |
272 bool got_accelerator = | 273 bubble_view_context_->GetWidget()->GetAccelerator(IDC_FULLSCREEN, |
273 browser_view_->GetWidget()->GetAccelerator(IDC_FULLSCREEN, &accelerator); | 274 &accelerator); |
274 DCHECK(got_accelerator); | |
275 view_ = new ExclusiveAccessView(this, accelerator.GetShortcutText(), url, | 275 view_ = new ExclusiveAccessView(this, accelerator.GetShortcutText(), url, |
276 bubble_type_); | 276 bubble_type_); |
277 | 277 |
278 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView. | 278 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView. |
279 // TODO(pkotwicz): When this becomes a views bubble, make sure that this | 279 // TODO(pkotwicz): When this becomes a views bubble, make sure that this |
280 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager. | 280 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager. |
281 // Initialize the popup. | 281 // Initialize the popup. |
282 popup_ = new views::Widget; | 282 popup_ = new views::Widget; |
283 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 283 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
284 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 284 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
285 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 285 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
286 params.parent = browser_view_->GetWidget()->GetNativeView(); | 286 params.parent = bubble_view_context_->GetWidget()->GetNativeView(); |
287 params.bounds = GetPopupRect(false); | 287 params.bounds = GetPopupRect(false); |
288 popup_->Init(params); | 288 popup_->Init(params); |
289 gfx::Size size = GetPopupRect(true).size(); | 289 gfx::Size size = GetPopupRect(true).size(); |
290 popup_->SetContentsView(view_); | 290 popup_->SetContentsView(view_); |
291 // We set layout manager to NULL to prevent the widget from sizing its | 291 // We set layout manager to NULL to prevent the widget from sizing its |
292 // contents to the same size as itself. This prevents the widget contents from | 292 // contents to the same size as itself. This prevents the widget contents from |
293 // shrinking while we animate the height of the popup to give the impression | 293 // shrinking while we animate the height of the popup to give the impression |
294 // that it is sliding off the top of the screen. | 294 // that it is sliding off the top of the screen. |
295 popup_->GetRootView()->SetLayoutManager(NULL); | 295 popup_->GetRootView()->SetLayoutManager(NULL); |
296 view_->SetBounds(0, 0, size.width(), size.height()); | 296 view_->SetBounds(0, 0, size.width(), size.height()); |
297 popup_->ShowInactive(); // This does not activate the popup. | 297 popup_->ShowInactive(); // This does not activate the popup. |
298 | 298 |
299 popup_->AddObserver(this); | 299 popup_->AddObserver(this); |
300 | 300 |
301 registrar_.Add( | 301 registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
302 this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 302 content::Source<FullscreenController>( |
303 content::Source<FullscreenController>(browser_view_->browser() | 303 bubble_view_context_->GetExclusiveAccessManager() |
304 ->exclusive_access_manager() | 304 ->fullscreen_controller())); |
305 ->fullscreen_controller())); | |
306 | 305 |
307 UpdateForImmersiveState(); | 306 UpdateForImmersiveState(); |
308 } | 307 } |
309 | 308 |
310 ExclusiveAccessBubbleViews::~ExclusiveAccessBubbleViews() { | 309 ExclusiveAccessBubbleViews::~ExclusiveAccessBubbleViews() { |
311 popup_->RemoveObserver(this); | 310 popup_->RemoveObserver(this); |
312 | 311 |
313 // This is tricky. We may be in an ATL message handler stack, in which case | 312 // This is tricky. We may be in an ATL message handler stack, in which case |
314 // the popup cannot be deleted yet. We also can't set the popup's ownership | 313 // the popup cannot be deleted yet. We also can't set the popup's ownership |
315 // model to NATIVE_WIDGET_OWNS_WIDGET because if the user closed the last tab | 314 // model to NATIVE_WIDGET_OWNS_WIDGET because if the user closed the last tab |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 return; | 363 return; |
365 | 364 |
366 if (should_watch_mouse) | 365 if (should_watch_mouse) |
367 StartWatchingMouse(); | 366 StartWatchingMouse(); |
368 else | 367 else |
369 StopWatchingMouse(); | 368 StopWatchingMouse(); |
370 } | 369 } |
371 | 370 |
372 void ExclusiveAccessBubbleViews::UpdateForImmersiveState() { | 371 void ExclusiveAccessBubbleViews::UpdateForImmersiveState() { |
373 AnimatedAttribute expected_animated_attribute = | 372 AnimatedAttribute expected_animated_attribute = |
374 browser_view_->immersive_mode_controller()->IsEnabled() | 373 bubble_view_context_->IsImmersiveModeEnabled() |
375 ? ANIMATED_ATTRIBUTE_OPACITY | 374 ? ANIMATED_ATTRIBUTE_OPACITY |
376 : ANIMATED_ATTRIBUTE_BOUNDS; | 375 : ANIMATED_ATTRIBUTE_BOUNDS; |
377 if (animated_attribute_ != expected_animated_attribute) { | 376 if (animated_attribute_ != expected_animated_attribute) { |
378 // If an animation is currently in progress, skip to the end because | 377 // If an animation is currently in progress, skip to the end because |
379 // switching the animated attribute midway through the animation looks | 378 // switching the animated attribute midway through the animation looks |
380 // weird. | 379 // weird. |
381 animation_->End(); | 380 animation_->End(); |
382 | 381 |
383 animated_attribute_ = expected_animated_attribute; | 382 animated_attribute_ = expected_animated_attribute; |
384 | 383 |
(...skipping 11 matching lines...) Expand all Loading... |
396 | 395 |
397 void ExclusiveAccessBubbleViews::UpdateBounds() { | 396 void ExclusiveAccessBubbleViews::UpdateBounds() { |
398 gfx::Rect popup_rect(GetPopupRect(false)); | 397 gfx::Rect popup_rect(GetPopupRect(false)); |
399 if (!popup_rect.IsEmpty()) { | 398 if (!popup_rect.IsEmpty()) { |
400 popup_->SetBounds(popup_rect); | 399 popup_->SetBounds(popup_rect); |
401 view_->SetY(popup_rect.height() - view_->height()); | 400 view_->SetY(popup_rect.height() - view_->height()); |
402 } | 401 } |
403 } | 402 } |
404 | 403 |
405 views::View* ExclusiveAccessBubbleViews::GetBrowserRootView() const { | 404 views::View* ExclusiveAccessBubbleViews::GetBrowserRootView() const { |
406 return browser_view_->GetWidget()->GetRootView(); | 405 return bubble_view_context_->GetWidget()->GetRootView(); |
407 } | 406 } |
408 | 407 |
409 void ExclusiveAccessBubbleViews::AnimationProgressed( | 408 void ExclusiveAccessBubbleViews::AnimationProgressed( |
410 const gfx::Animation* animation) { | 409 const gfx::Animation* animation) { |
411 if (animated_attribute_ == ANIMATED_ATTRIBUTE_OPACITY) { | 410 if (animated_attribute_ == ANIMATED_ATTRIBUTE_OPACITY) { |
412 int opacity = animation_->CurrentValueBetween(0, 255); | 411 int opacity = animation_->CurrentValueBetween(0, 255); |
413 if (opacity == 0) { | 412 if (opacity == 0) { |
414 popup_->Hide(); | 413 popup_->Hide(); |
415 } else { | 414 } else { |
416 popup_->Show(); | 415 popup_->Show(); |
(...skipping 12 matching lines...) Expand all Loading... |
429 void ExclusiveAccessBubbleViews::AnimationEnded( | 428 void ExclusiveAccessBubbleViews::AnimationEnded( |
430 const gfx::Animation* animation) { | 429 const gfx::Animation* animation) { |
431 AnimationProgressed(animation); | 430 AnimationProgressed(animation); |
432 } | 431 } |
433 | 432 |
434 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( | 433 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( |
435 bool ignore_animation_state) const { | 434 bool ignore_animation_state) const { |
436 gfx::Size size(view_->GetPreferredSize()); | 435 gfx::Size size(view_->GetPreferredSize()); |
437 // NOTE: don't use the bounds of the root_view_. On linux GTK changing window | 436 // NOTE: don't use the bounds of the root_view_. On linux GTK changing window |
438 // size is async. Instead we use the size of the screen. | 437 // size is async. Instead we use the size of the screen. |
439 gfx::Screen* screen = | 438 gfx::Screen* screen = gfx::Screen::GetScreenFor( |
440 gfx::Screen::GetScreenFor(browser_view_->GetWidget()->GetNativeView()); | 439 bubble_view_context_->GetWidget()->GetNativeView()); |
441 gfx::Rect screen_bounds = | 440 gfx::Rect screen_bounds = |
442 screen->GetDisplayNearestWindow( | 441 screen->GetDisplayNearestWindow( |
443 browser_view_->GetWidget()->GetNativeView()).bounds(); | 442 bubble_view_context_->GetWidget()->GetNativeView()).bounds(); |
444 int x = screen_bounds.x() + (screen_bounds.width() - size.width()) / 2; | 443 int x = screen_bounds.x() + (screen_bounds.width() - size.width()) / 2; |
445 | 444 |
446 int top_container_bottom = screen_bounds.y(); | 445 int top_container_bottom = screen_bounds.y(); |
447 if (browser_view_->immersive_mode_controller()->IsEnabled()) { | 446 if (bubble_view_context_->IsImmersiveModeEnabled()) { |
448 // Skip querying the top container height in non-immersive fullscreen | 447 // Skip querying the top container height in non-immersive fullscreen |
449 // because: | 448 // because: |
450 // - The top container height is always zero in non-immersive fullscreen. | 449 // - The top container height is always zero in non-immersive fullscreen. |
451 // - Querying the top container height may return the height before entering | 450 // - Querying the top container height may return the height before entering |
452 // fullscreen because layout is disabled while entering fullscreen. | 451 // fullscreen because layout is disabled while entering fullscreen. |
453 // A visual glitch due to the delayed layout is avoided in immersive | 452 // A visual glitch due to the delayed layout is avoided in immersive |
454 // fullscreen because entering fullscreen starts with the top container | 453 // fullscreen because entering fullscreen starts with the top container |
455 // revealed. When revealed, the top container has the same height as before | 454 // revealed. When revealed, the top container has the same height as before |
456 // entering fullscreen. | 455 // entering fullscreen. |
457 top_container_bottom = | 456 top_container_bottom = |
458 browser_view_->top_container()->GetBoundsInScreen().bottom(); | 457 bubble_view_context_->GetTopContainerBoundsInScreen().bottom(); |
459 } | 458 } |
460 int y = top_container_bottom + kPopupTopPx; | 459 int y = top_container_bottom + kPopupTopPx; |
461 | 460 |
462 if (!ignore_animation_state && | 461 if (!ignore_animation_state && |
463 animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) { | 462 animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) { |
464 int total_height = size.height() + kPopupTopPx; | 463 int total_height = size.height() + kPopupTopPx; |
465 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); | 464 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); |
466 int y_offset = std::min(popup_bottom, kPopupTopPx); | 465 int y_offset = std::min(popup_bottom, kPopupTopPx); |
467 size.set_height(size.height() - popup_bottom + y_offset); | 466 size.set_height(size.height() - popup_bottom + y_offset); |
468 y -= y_offset; | 467 y -= y_offset; |
469 } | 468 } |
470 return gfx::Rect(gfx::Point(x, y), size); | 469 return gfx::Rect(gfx::Point(x, y), size); |
471 } | 470 } |
472 | 471 |
473 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { | 472 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { |
474 gfx::Point cursor_pos = | 473 gfx::Point cursor_pos = |
475 gfx::Screen::GetScreenFor(browser_view_->GetWidget()->GetNativeView()) | 474 gfx::Screen::GetScreenFor( |
| 475 bubble_view_context_->GetWidget()->GetNativeView()) |
476 ->GetCursorScreenPoint(); | 476 ->GetCursorScreenPoint(); |
477 views::View::ConvertPointFromScreen(GetBrowserRootView(), &cursor_pos); | 477 views::View::ConvertPointFromScreen(GetBrowserRootView(), &cursor_pos); |
478 return cursor_pos; | 478 return cursor_pos; |
479 } | 479 } |
480 | 480 |
481 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { | 481 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { |
482 return GetBrowserRootView()->HitTestPoint(pos); | 482 return GetBrowserRootView()->HitTestPoint(pos); |
483 } | 483 } |
484 | 484 |
485 bool ExclusiveAccessBubbleViews::IsWindowActive() { | 485 bool ExclusiveAccessBubbleViews::IsWindowActive() { |
486 return browser_view_->GetWidget()->IsActive(); | 486 return bubble_view_context_->GetWidget()->IsActive(); |
487 } | 487 } |
488 | 488 |
489 void ExclusiveAccessBubbleViews::Hide() { | 489 void ExclusiveAccessBubbleViews::Hide() { |
490 animation_->SetSlideDuration(kSlideOutDurationMs); | 490 animation_->SetSlideDuration(kSlideOutDurationMs); |
491 animation_->Hide(); | 491 animation_->Hide(); |
492 } | 492 } |
493 | 493 |
494 void ExclusiveAccessBubbleViews::Show() { | 494 void ExclusiveAccessBubbleViews::Show() { |
495 animation_->SetSlideDuration(kSlideInDurationMs); | 495 animation_->SetSlideDuration(kSlideInDurationMs); |
496 animation_->Show(); | 496 animation_->Show(); |
497 } | 497 } |
498 | 498 |
499 bool ExclusiveAccessBubbleViews::IsAnimating() { | 499 bool ExclusiveAccessBubbleViews::IsAnimating() { |
500 return animation_->is_animating(); | 500 return animation_->is_animating(); |
501 } | 501 } |
502 | 502 |
503 bool ExclusiveAccessBubbleViews::CanMouseTriggerSlideIn() const { | 503 bool ExclusiveAccessBubbleViews::CanMouseTriggerSlideIn() const { |
504 return !browser_view_->immersive_mode_controller()->IsEnabled(); | 504 return !bubble_view_context_->IsImmersiveModeEnabled(); |
505 } | 505 } |
506 | 506 |
507 void ExclusiveAccessBubbleViews::Observe( | 507 void ExclusiveAccessBubbleViews::Observe( |
508 int type, | 508 int type, |
509 const content::NotificationSource& source, | 509 const content::NotificationSource& source, |
510 const content::NotificationDetails& details) { | 510 const content::NotificationDetails& details) { |
511 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 511 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
512 UpdateForImmersiveState(); | 512 UpdateForImmersiveState(); |
513 } | 513 } |
514 | 514 |
515 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( | 515 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( |
516 views::Widget* widget, | 516 views::Widget* widget, |
517 bool visible) { | 517 bool visible) { |
518 UpdateMouseWatcher(); | 518 UpdateMouseWatcher(); |
519 } | 519 } |
OLD | NEW |