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 // Obtain accelerator to exit fullscreen (default ESC) if it is defined. There |
273 browser_view_->GetWidget()->GetAccelerator(IDC_FULLSCREEN, &accelerator); | 274 // is accelerator defined to escape out of fullscreen for packaged apps. |
scheib
2015/02/25 22:31:51
Thanks for explanation. You intended "is no accele
Sriram
2015/02/25 23:15:59
This is not hit in current patch but with patch th
| |
274 DCHECK(got_accelerator); | 275 bubble_view_context_->GetWidget()->GetAccelerator(IDC_FULLSCREEN, |
276 &accelerator); | |
275 view_ = new ExclusiveAccessView(this, accelerator.GetShortcutText(), url, | 277 view_ = new ExclusiveAccessView(this, accelerator.GetShortcutText(), url, |
276 bubble_type_); | 278 bubble_type_); |
277 | 279 |
278 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView. | 280 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView. |
279 // TODO(pkotwicz): When this becomes a views bubble, make sure that this | 281 // TODO(pkotwicz): When this becomes a views bubble, make sure that this |
280 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager. | 282 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager. |
281 // Initialize the popup. | 283 // Initialize the popup. |
282 popup_ = new views::Widget; | 284 popup_ = new views::Widget; |
283 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 285 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
284 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 286 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
285 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 287 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
286 params.parent = browser_view_->GetWidget()->GetNativeView(); | 288 params.parent = bubble_view_context_->GetWidget()->GetNativeView(); |
287 params.bounds = GetPopupRect(false); | 289 params.bounds = GetPopupRect(false); |
288 popup_->Init(params); | 290 popup_->Init(params); |
289 gfx::Size size = GetPopupRect(true).size(); | 291 gfx::Size size = GetPopupRect(true).size(); |
290 popup_->SetContentsView(view_); | 292 popup_->SetContentsView(view_); |
291 // We set layout manager to NULL to prevent the widget from sizing its | 293 // 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 | 294 // 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 | 295 // shrinking while we animate the height of the popup to give the impression |
294 // that it is sliding off the top of the screen. | 296 // that it is sliding off the top of the screen. |
295 popup_->GetRootView()->SetLayoutManager(NULL); | 297 popup_->GetRootView()->SetLayoutManager(NULL); |
296 view_->SetBounds(0, 0, size.width(), size.height()); | 298 view_->SetBounds(0, 0, size.width(), size.height()); |
297 popup_->ShowInactive(); // This does not activate the popup. | 299 popup_->ShowInactive(); // This does not activate the popup. |
298 | 300 |
299 popup_->AddObserver(this); | 301 popup_->AddObserver(this); |
300 | 302 |
301 registrar_.Add( | 303 registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
302 this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 304 content::Source<FullscreenController>( |
303 content::Source<FullscreenController>(browser_view_->browser() | 305 bubble_view_context_->GetExclusiveAccessManager() |
304 ->exclusive_access_manager() | 306 ->fullscreen_controller())); |
305 ->fullscreen_controller())); | |
306 | 307 |
307 UpdateForImmersiveState(); | 308 UpdateForImmersiveState(); |
308 } | 309 } |
309 | 310 |
310 ExclusiveAccessBubbleViews::~ExclusiveAccessBubbleViews() { | 311 ExclusiveAccessBubbleViews::~ExclusiveAccessBubbleViews() { |
311 popup_->RemoveObserver(this); | 312 popup_->RemoveObserver(this); |
312 | 313 |
313 // This is tricky. We may be in an ATL message handler stack, in which case | 314 // 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 | 315 // 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 | 316 // 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; | 365 return; |
365 | 366 |
366 if (should_watch_mouse) | 367 if (should_watch_mouse) |
367 StartWatchingMouse(); | 368 StartWatchingMouse(); |
368 else | 369 else |
369 StopWatchingMouse(); | 370 StopWatchingMouse(); |
370 } | 371 } |
371 | 372 |
372 void ExclusiveAccessBubbleViews::UpdateForImmersiveState() { | 373 void ExclusiveAccessBubbleViews::UpdateForImmersiveState() { |
373 AnimatedAttribute expected_animated_attribute = | 374 AnimatedAttribute expected_animated_attribute = |
374 browser_view_->immersive_mode_controller()->IsEnabled() | 375 bubble_view_context_->IsImmersiveModeEnabled() |
375 ? ANIMATED_ATTRIBUTE_OPACITY | 376 ? ANIMATED_ATTRIBUTE_OPACITY |
376 : ANIMATED_ATTRIBUTE_BOUNDS; | 377 : ANIMATED_ATTRIBUTE_BOUNDS; |
377 if (animated_attribute_ != expected_animated_attribute) { | 378 if (animated_attribute_ != expected_animated_attribute) { |
378 // If an animation is currently in progress, skip to the end because | 379 // If an animation is currently in progress, skip to the end because |
379 // switching the animated attribute midway through the animation looks | 380 // switching the animated attribute midway through the animation looks |
380 // weird. | 381 // weird. |
381 animation_->End(); | 382 animation_->End(); |
382 | 383 |
383 animated_attribute_ = expected_animated_attribute; | 384 animated_attribute_ = expected_animated_attribute; |
384 | 385 |
(...skipping 11 matching lines...) Expand all Loading... | |
396 | 397 |
397 void ExclusiveAccessBubbleViews::UpdateBounds() { | 398 void ExclusiveAccessBubbleViews::UpdateBounds() { |
398 gfx::Rect popup_rect(GetPopupRect(false)); | 399 gfx::Rect popup_rect(GetPopupRect(false)); |
399 if (!popup_rect.IsEmpty()) { | 400 if (!popup_rect.IsEmpty()) { |
400 popup_->SetBounds(popup_rect); | 401 popup_->SetBounds(popup_rect); |
401 view_->SetY(popup_rect.height() - view_->height()); | 402 view_->SetY(popup_rect.height() - view_->height()); |
402 } | 403 } |
403 } | 404 } |
404 | 405 |
405 views::View* ExclusiveAccessBubbleViews::GetBrowserRootView() const { | 406 views::View* ExclusiveAccessBubbleViews::GetBrowserRootView() const { |
406 return browser_view_->GetWidget()->GetRootView(); | 407 return bubble_view_context_->GetWidget()->GetRootView(); |
407 } | 408 } |
408 | 409 |
409 void ExclusiveAccessBubbleViews::AnimationProgressed( | 410 void ExclusiveAccessBubbleViews::AnimationProgressed( |
410 const gfx::Animation* animation) { | 411 const gfx::Animation* animation) { |
411 if (animated_attribute_ == ANIMATED_ATTRIBUTE_OPACITY) { | 412 if (animated_attribute_ == ANIMATED_ATTRIBUTE_OPACITY) { |
412 int opacity = animation_->CurrentValueBetween(0, 255); | 413 int opacity = animation_->CurrentValueBetween(0, 255); |
413 if (opacity == 0) { | 414 if (opacity == 0) { |
414 popup_->Hide(); | 415 popup_->Hide(); |
415 } else { | 416 } else { |
416 popup_->Show(); | 417 popup_->Show(); |
(...skipping 12 matching lines...) Expand all Loading... | |
429 void ExclusiveAccessBubbleViews::AnimationEnded( | 430 void ExclusiveAccessBubbleViews::AnimationEnded( |
430 const gfx::Animation* animation) { | 431 const gfx::Animation* animation) { |
431 AnimationProgressed(animation); | 432 AnimationProgressed(animation); |
432 } | 433 } |
433 | 434 |
434 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( | 435 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( |
435 bool ignore_animation_state) const { | 436 bool ignore_animation_state) const { |
436 gfx::Size size(view_->GetPreferredSize()); | 437 gfx::Size size(view_->GetPreferredSize()); |
437 // NOTE: don't use the bounds of the root_view_. On linux GTK changing window | 438 // 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. | 439 // size is async. Instead we use the size of the screen. |
439 gfx::Screen* screen = | 440 gfx::Screen* screen = gfx::Screen::GetScreenFor( |
440 gfx::Screen::GetScreenFor(browser_view_->GetWidget()->GetNativeView()); | 441 bubble_view_context_->GetWidget()->GetNativeView()); |
441 gfx::Rect screen_bounds = | 442 gfx::Rect screen_bounds = |
442 screen->GetDisplayNearestWindow( | 443 screen->GetDisplayNearestWindow( |
443 browser_view_->GetWidget()->GetNativeView()).bounds(); | 444 bubble_view_context_->GetWidget()->GetNativeView()).bounds(); |
444 int x = screen_bounds.x() + (screen_bounds.width() - size.width()) / 2; | 445 int x = screen_bounds.x() + (screen_bounds.width() - size.width()) / 2; |
445 | 446 |
446 int top_container_bottom = screen_bounds.y(); | 447 int top_container_bottom = screen_bounds.y(); |
447 if (browser_view_->immersive_mode_controller()->IsEnabled()) { | 448 if (bubble_view_context_->IsImmersiveModeEnabled()) { |
448 // Skip querying the top container height in non-immersive fullscreen | 449 // Skip querying the top container height in non-immersive fullscreen |
449 // because: | 450 // because: |
450 // - The top container height is always zero in non-immersive fullscreen. | 451 // - The top container height is always zero in non-immersive fullscreen. |
451 // - Querying the top container height may return the height before entering | 452 // - Querying the top container height may return the height before entering |
452 // fullscreen because layout is disabled while entering fullscreen. | 453 // fullscreen because layout is disabled while entering fullscreen. |
453 // A visual glitch due to the delayed layout is avoided in immersive | 454 // A visual glitch due to the delayed layout is avoided in immersive |
454 // fullscreen because entering fullscreen starts with the top container | 455 // fullscreen because entering fullscreen starts with the top container |
455 // revealed. When revealed, the top container has the same height as before | 456 // revealed. When revealed, the top container has the same height as before |
456 // entering fullscreen. | 457 // entering fullscreen. |
457 top_container_bottom = | 458 top_container_bottom = |
458 browser_view_->top_container()->GetBoundsInScreen().bottom(); | 459 bubble_view_context_->GetTopContainerBoundsInScreen().bottom(); |
459 } | 460 } |
460 int y = top_container_bottom + kPopupTopPx; | 461 int y = top_container_bottom + kPopupTopPx; |
461 | 462 |
462 if (!ignore_animation_state && | 463 if (!ignore_animation_state && |
463 animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) { | 464 animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) { |
464 int total_height = size.height() + kPopupTopPx; | 465 int total_height = size.height() + kPopupTopPx; |
465 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); | 466 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); |
466 int y_offset = std::min(popup_bottom, kPopupTopPx); | 467 int y_offset = std::min(popup_bottom, kPopupTopPx); |
467 size.set_height(size.height() - popup_bottom + y_offset); | 468 size.set_height(size.height() - popup_bottom + y_offset); |
468 y -= y_offset; | 469 y -= y_offset; |
469 } | 470 } |
470 return gfx::Rect(gfx::Point(x, y), size); | 471 return gfx::Rect(gfx::Point(x, y), size); |
471 } | 472 } |
472 | 473 |
473 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { | 474 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { |
474 gfx::Point cursor_pos = | 475 gfx::Point cursor_pos = |
475 gfx::Screen::GetScreenFor(browser_view_->GetWidget()->GetNativeView()) | 476 gfx::Screen::GetScreenFor( |
477 bubble_view_context_->GetWidget()->GetNativeView()) | |
476 ->GetCursorScreenPoint(); | 478 ->GetCursorScreenPoint(); |
477 views::View::ConvertPointFromScreen(GetBrowserRootView(), &cursor_pos); | 479 views::View::ConvertPointFromScreen(GetBrowserRootView(), &cursor_pos); |
478 return cursor_pos; | 480 return cursor_pos; |
479 } | 481 } |
480 | 482 |
481 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { | 483 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { |
482 return GetBrowserRootView()->HitTestPoint(pos); | 484 return GetBrowserRootView()->HitTestPoint(pos); |
483 } | 485 } |
484 | 486 |
485 bool ExclusiveAccessBubbleViews::IsWindowActive() { | 487 bool ExclusiveAccessBubbleViews::IsWindowActive() { |
486 return browser_view_->GetWidget()->IsActive(); | 488 return bubble_view_context_->GetWidget()->IsActive(); |
487 } | 489 } |
488 | 490 |
489 void ExclusiveAccessBubbleViews::Hide() { | 491 void ExclusiveAccessBubbleViews::Hide() { |
490 animation_->SetSlideDuration(kSlideOutDurationMs); | 492 animation_->SetSlideDuration(kSlideOutDurationMs); |
491 animation_->Hide(); | 493 animation_->Hide(); |
492 } | 494 } |
493 | 495 |
494 void ExclusiveAccessBubbleViews::Show() { | 496 void ExclusiveAccessBubbleViews::Show() { |
495 animation_->SetSlideDuration(kSlideInDurationMs); | 497 animation_->SetSlideDuration(kSlideInDurationMs); |
496 animation_->Show(); | 498 animation_->Show(); |
497 } | 499 } |
498 | 500 |
499 bool ExclusiveAccessBubbleViews::IsAnimating() { | 501 bool ExclusiveAccessBubbleViews::IsAnimating() { |
500 return animation_->is_animating(); | 502 return animation_->is_animating(); |
501 } | 503 } |
502 | 504 |
503 bool ExclusiveAccessBubbleViews::CanMouseTriggerSlideIn() const { | 505 bool ExclusiveAccessBubbleViews::CanMouseTriggerSlideIn() const { |
504 return !browser_view_->immersive_mode_controller()->IsEnabled(); | 506 return !bubble_view_context_->IsImmersiveModeEnabled(); |
505 } | 507 } |
506 | 508 |
507 void ExclusiveAccessBubbleViews::Observe( | 509 void ExclusiveAccessBubbleViews::Observe( |
508 int type, | 510 int type, |
509 const content::NotificationSource& source, | 511 const content::NotificationSource& source, |
510 const content::NotificationDetails& details) { | 512 const content::NotificationDetails& details) { |
511 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 513 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
512 UpdateForImmersiveState(); | 514 UpdateForImmersiveState(); |
513 } | 515 } |
514 | 516 |
515 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( | 517 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( |
516 views::Widget* widget, | 518 views::Widget* widget, |
517 bool visible) { | 519 bool visible) { |
518 UpdateMouseWatcher(); | 520 UpdateMouseWatcher(); |
519 } | 521 } |
OLD | NEW |