Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/ui/views/exclusive_access_bubble_views.cc

Issue 877413004: Refactor away the Browser* dependency in exclusive_access (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename toggle fullscreen function Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 const ui::Event& event) { 200 const ui::Event& event) {
202 if (sender == button_view_->accept_button()) 201 if (sender == button_view_->accept_button())
203 bubble_->Accept(); 202 bubble_->Accept();
204 else 203 else
205 bubble_->Cancel(); 204 bubble_->Cancel();
206 } 205 }
207 206
208 void ExclusiveAccessBubbleViews::ExclusiveAccessView::LinkClicked( 207 void ExclusiveAccessBubbleViews::ExclusiveAccessView::LinkClicked(
209 views::Link* link, 208 views::Link* link,
210 int event_flags) { 209 int event_flags) {
211 bubble_->ToggleFullscreen(); 210 bubble_->ExitExclusiveAccess();
212 } 211 }
213 212
214 void ExclusiveAccessBubbleViews::ExclusiveAccessView::UpdateContent( 213 void ExclusiveAccessBubbleViews::ExclusiveAccessView::UpdateContent(
215 const GURL& url, 214 const GURL& url,
216 ExclusiveAccessBubbleType bubble_type) { 215 ExclusiveAccessBubbleType bubble_type) {
217 DCHECK_NE(EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE, bubble_type); 216 DCHECK_NE(EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE, bubble_type);
218 217
219 message_label_->SetText(bubble_->GetCurrentMessageText()); 218 message_label_->SetText(bubble_->GetCurrentMessageText());
220 if (exclusive_access_bubble::ShowButtonsForType(bubble_type)) { 219 if (exclusive_access_bubble::ShowButtonsForType(bubble_type)) {
221 link_->SetVisible(false); 220 link_->SetVisible(false);
(...skipping 28 matching lines...) Expand all
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 bool got_accelerator = bubble_view_context_->GetWidget()->GetAccelerator(
273 browser_view_->GetWidget()->GetAccelerator(IDC_FULLSCREEN, &accelerator); 274 IDC_FULLSCREEN, &accelerator);
274 DCHECK(got_accelerator); 275 DCHECK(got_accelerator);
275 view_ = new ExclusiveAccessView(this, accelerator.GetShortcutText(), url, 276 view_ = new ExclusiveAccessView(this, accelerator.GetShortcutText(), url,
276 bubble_type_); 277 bubble_type_);
277 278
278 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView. 279 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView.
279 // TODO(pkotwicz): When this becomes a views bubble, make sure that this 280 // TODO(pkotwicz): When this becomes a views bubble, make sure that this
280 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager. 281 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager.
281 // Initialize the popup. 282 // Initialize the popup.
282 popup_ = new views::Widget; 283 popup_ = new views::Widget;
283 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 284 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
284 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 285 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
285 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 286 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
286 params.parent = browser_view_->GetWidget()->GetNativeView(); 287 params.parent = bubble_view_context_->GetWidget()->GetNativeView();
287 params.bounds = GetPopupRect(false); 288 params.bounds = GetPopupRect(false);
288 popup_->Init(params); 289 popup_->Init(params);
289 gfx::Size size = GetPopupRect(true).size(); 290 gfx::Size size = GetPopupRect(true).size();
290 popup_->SetContentsView(view_); 291 popup_->SetContentsView(view_);
291 // We set layout manager to NULL to prevent the widget from sizing its 292 // 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 293 // 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 294 // shrinking while we animate the height of the popup to give the impression
294 // that it is sliding off the top of the screen. 295 // that it is sliding off the top of the screen.
295 popup_->GetRootView()->SetLayoutManager(NULL); 296 popup_->GetRootView()->SetLayoutManager(NULL);
296 view_->SetBounds(0, 0, size.width(), size.height()); 297 view_->SetBounds(0, 0, size.width(), size.height());
297 popup_->ShowInactive(); // This does not activate the popup. 298 popup_->ShowInactive(); // This does not activate the popup.
298 299
299 popup_->AddObserver(this); 300 popup_->AddObserver(this);
300 301
301 registrar_.Add( 302 registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED,
302 this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, 303 content::Source<FullscreenController>(
303 content::Source<FullscreenController>(browser_view_->browser() 304 bubble_view_context_->GetExclusiveAccessManager()
304 ->exclusive_access_manager() 305 ->fullscreen_controller()));
305 ->fullscreen_controller()));
306 306
307 UpdateForImmersiveState(); 307 UpdateForImmersiveState();
308 } 308 }
309 309
310 ExclusiveAccessBubbleViews::~ExclusiveAccessBubbleViews() { 310 ExclusiveAccessBubbleViews::~ExclusiveAccessBubbleViews() {
311 popup_->RemoveObserver(this); 311 popup_->RemoveObserver(this);
312 312
313 // This is tricky. We may be in an ATL message handler stack, in which case 313 // 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 314 // 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 315 // 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
364 return; 364 return;
365 365
366 if (should_watch_mouse) 366 if (should_watch_mouse)
367 StartWatchingMouse(); 367 StartWatchingMouse();
368 else 368 else
369 StopWatchingMouse(); 369 StopWatchingMouse();
370 } 370 }
371 371
372 void ExclusiveAccessBubbleViews::UpdateForImmersiveState() { 372 void ExclusiveAccessBubbleViews::UpdateForImmersiveState() {
373 AnimatedAttribute expected_animated_attribute = 373 AnimatedAttribute expected_animated_attribute =
374 browser_view_->immersive_mode_controller()->IsEnabled() 374 bubble_view_context_->IsImmersiveModeEnabled()
375 ? ANIMATED_ATTRIBUTE_OPACITY 375 ? ANIMATED_ATTRIBUTE_OPACITY
376 : ANIMATED_ATTRIBUTE_BOUNDS; 376 : ANIMATED_ATTRIBUTE_BOUNDS;
377 if (animated_attribute_ != expected_animated_attribute) { 377 if (animated_attribute_ != expected_animated_attribute) {
378 // If an animation is currently in progress, skip to the end because 378 // If an animation is currently in progress, skip to the end because
379 // switching the animated attribute midway through the animation looks 379 // switching the animated attribute midway through the animation looks
380 // weird. 380 // weird.
381 animation_->End(); 381 animation_->End();
382 382
383 animated_attribute_ = expected_animated_attribute; 383 animated_attribute_ = expected_animated_attribute;
384 384
(...skipping 11 matching lines...) Expand all
396 396
397 void ExclusiveAccessBubbleViews::UpdateBounds() { 397 void ExclusiveAccessBubbleViews::UpdateBounds() {
398 gfx::Rect popup_rect(GetPopupRect(false)); 398 gfx::Rect popup_rect(GetPopupRect(false));
399 if (!popup_rect.IsEmpty()) { 399 if (!popup_rect.IsEmpty()) {
400 popup_->SetBounds(popup_rect); 400 popup_->SetBounds(popup_rect);
401 view_->SetY(popup_rect.height() - view_->height()); 401 view_->SetY(popup_rect.height() - view_->height());
402 } 402 }
403 } 403 }
404 404
405 views::View* ExclusiveAccessBubbleViews::GetBrowserRootView() const { 405 views::View* ExclusiveAccessBubbleViews::GetBrowserRootView() const {
406 return browser_view_->GetWidget()->GetRootView(); 406 return bubble_view_context_->GetWidget()->GetRootView();
407 } 407 }
408 408
409 void ExclusiveAccessBubbleViews::AnimationProgressed( 409 void ExclusiveAccessBubbleViews::AnimationProgressed(
410 const gfx::Animation* animation) { 410 const gfx::Animation* animation) {
411 if (animated_attribute_ == ANIMATED_ATTRIBUTE_OPACITY) { 411 if (animated_attribute_ == ANIMATED_ATTRIBUTE_OPACITY) {
412 int opacity = animation_->CurrentValueBetween(0, 255); 412 int opacity = animation_->CurrentValueBetween(0, 255);
413 if (opacity == 0) { 413 if (opacity == 0) {
414 popup_->Hide(); 414 popup_->Hide();
415 } else { 415 } else {
416 popup_->Show(); 416 popup_->Show();
(...skipping 12 matching lines...) Expand all
429 void ExclusiveAccessBubbleViews::AnimationEnded( 429 void ExclusiveAccessBubbleViews::AnimationEnded(
430 const gfx::Animation* animation) { 430 const gfx::Animation* animation) {
431 AnimationProgressed(animation); 431 AnimationProgressed(animation);
432 } 432 }
433 433
434 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect( 434 gfx::Rect ExclusiveAccessBubbleViews::GetPopupRect(
435 bool ignore_animation_state) const { 435 bool ignore_animation_state) const {
436 gfx::Size size(view_->GetPreferredSize()); 436 gfx::Size size(view_->GetPreferredSize());
437 // NOTE: don't use the bounds of the root_view_. On linux GTK changing window 437 // 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. 438 // size is async. Instead we use the size of the screen.
439 gfx::Screen* screen = 439 gfx::Screen* screen = gfx::Screen::GetScreenFor(
440 gfx::Screen::GetScreenFor(browser_view_->GetWidget()->GetNativeView()); 440 bubble_view_context_->GetWidget()->GetNativeView());
441 gfx::Rect screen_bounds = 441 gfx::Rect screen_bounds =
442 screen->GetDisplayNearestWindow( 442 screen->GetDisplayNearestWindow(
443 browser_view_->GetWidget()->GetNativeView()).bounds(); 443 bubble_view_context_->GetWidget()->GetNativeView()).bounds();
444 int x = screen_bounds.x() + (screen_bounds.width() - size.width()) / 2; 444 int x = screen_bounds.x() + (screen_bounds.width() - size.width()) / 2;
445 445
446 int top_container_bottom = screen_bounds.y(); 446 int top_container_bottom = screen_bounds.y();
447 if (browser_view_->immersive_mode_controller()->IsEnabled()) { 447 if (bubble_view_context_->IsImmersiveModeEnabled()) {
448 // Skip querying the top container height in non-immersive fullscreen 448 // Skip querying the top container height in non-immersive fullscreen
449 // because: 449 // because:
450 // - The top container height is always zero in non-immersive fullscreen. 450 // - The top container height is always zero in non-immersive fullscreen.
451 // - Querying the top container height may return the height before entering 451 // - Querying the top container height may return the height before entering
452 // fullscreen because layout is disabled while entering fullscreen. 452 // fullscreen because layout is disabled while entering fullscreen.
453 // A visual glitch due to the delayed layout is avoided in immersive 453 // A visual glitch due to the delayed layout is avoided in immersive
454 // fullscreen because entering fullscreen starts with the top container 454 // fullscreen because entering fullscreen starts with the top container
455 // revealed. When revealed, the top container has the same height as before 455 // revealed. When revealed, the top container has the same height as before
456 // entering fullscreen. 456 // entering fullscreen.
457 top_container_bottom = 457 top_container_bottom =
458 browser_view_->top_container()->GetBoundsInScreen().bottom(); 458 bubble_view_context_->GetTopContainerBoundsInScreen().bottom();
459 } 459 }
460 int y = top_container_bottom + kPopupTopPx; 460 int y = top_container_bottom + kPopupTopPx;
461 461
462 if (!ignore_animation_state && 462 if (!ignore_animation_state &&
463 animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) { 463 animated_attribute_ == ANIMATED_ATTRIBUTE_BOUNDS) {
464 int total_height = size.height() + kPopupTopPx; 464 int total_height = size.height() + kPopupTopPx;
465 int popup_bottom = animation_->CurrentValueBetween(total_height, 0); 465 int popup_bottom = animation_->CurrentValueBetween(total_height, 0);
466 int y_offset = std::min(popup_bottom, kPopupTopPx); 466 int y_offset = std::min(popup_bottom, kPopupTopPx);
467 size.set_height(size.height() - popup_bottom + y_offset); 467 size.set_height(size.height() - popup_bottom + y_offset);
468 y -= y_offset; 468 y -= y_offset;
469 } 469 }
470 return gfx::Rect(gfx::Point(x, y), size); 470 return gfx::Rect(gfx::Point(x, y), size);
471 } 471 }
472 472
473 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() { 473 gfx::Point ExclusiveAccessBubbleViews::GetCursorScreenPoint() {
474 gfx::Point cursor_pos = 474 gfx::Point cursor_pos =
475 gfx::Screen::GetScreenFor(browser_view_->GetWidget()->GetNativeView()) 475 gfx::Screen::GetScreenFor(
476 bubble_view_context_->GetWidget()->GetNativeView())
476 ->GetCursorScreenPoint(); 477 ->GetCursorScreenPoint();
477 views::View::ConvertPointFromScreen(GetBrowserRootView(), &cursor_pos); 478 views::View::ConvertPointFromScreen(GetBrowserRootView(), &cursor_pos);
478 return cursor_pos; 479 return cursor_pos;
479 } 480 }
480 481
481 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) { 482 bool ExclusiveAccessBubbleViews::WindowContainsPoint(gfx::Point pos) {
482 return GetBrowserRootView()->HitTestPoint(pos); 483 return GetBrowserRootView()->HitTestPoint(pos);
483 } 484 }
484 485
485 bool ExclusiveAccessBubbleViews::IsWindowActive() { 486 bool ExclusiveAccessBubbleViews::IsWindowActive() {
486 return browser_view_->GetWidget()->IsActive(); 487 return bubble_view_context_->GetWidget()->IsActive();
487 } 488 }
488 489
489 void ExclusiveAccessBubbleViews::Hide() { 490 void ExclusiveAccessBubbleViews::Hide() {
490 animation_->SetSlideDuration(kSlideOutDurationMs); 491 animation_->SetSlideDuration(kSlideOutDurationMs);
491 animation_->Hide(); 492 animation_->Hide();
492 } 493 }
493 494
494 void ExclusiveAccessBubbleViews::Show() { 495 void ExclusiveAccessBubbleViews::Show() {
495 animation_->SetSlideDuration(kSlideInDurationMs); 496 animation_->SetSlideDuration(kSlideInDurationMs);
496 animation_->Show(); 497 animation_->Show();
497 } 498 }
498 499
499 bool ExclusiveAccessBubbleViews::IsAnimating() { 500 bool ExclusiveAccessBubbleViews::IsAnimating() {
500 return animation_->is_animating(); 501 return animation_->is_animating();
501 } 502 }
502 503
503 bool ExclusiveAccessBubbleViews::CanMouseTriggerSlideIn() const { 504 bool ExclusiveAccessBubbleViews::CanMouseTriggerSlideIn() const {
504 return !browser_view_->immersive_mode_controller()->IsEnabled(); 505 return !bubble_view_context_->IsImmersiveModeEnabled();
505 } 506 }
506 507
507 void ExclusiveAccessBubbleViews::Observe( 508 void ExclusiveAccessBubbleViews::Observe(
508 int type, 509 int type,
509 const content::NotificationSource& source, 510 const content::NotificationSource& source,
510 const content::NotificationDetails& details) { 511 const content::NotificationDetails& details) {
511 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); 512 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type);
512 UpdateForImmersiveState(); 513 UpdateForImmersiveState();
513 } 514 }
514 515
515 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged( 516 void ExclusiveAccessBubbleViews::OnWidgetVisibilityChanged(
516 views::Widget* widget, 517 views::Widget* widget,
517 bool visible) { 518 bool visible) {
518 UpdateMouseWatcher(); 519 UpdateMouseWatcher();
519 } 520 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698