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

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

Powered by Google App Engine
This is Rietveld 408576698