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/fullscreen_controller.h" | 5 #include "chrome/browser/ui/fullscreen_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 bool FullscreenController::IsMouseLocked() const { | 71 bool FullscreenController::IsMouseLocked() const { |
72 return mouse_lock_state_ == MOUSELOCK_ACCEPTED || | 72 return mouse_lock_state_ == MOUSELOCK_ACCEPTED || |
73 mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY; | 73 mouse_lock_state_ == MOUSELOCK_ACCEPTED_SILENTLY; |
74 } | 74 } |
75 | 75 |
76 void FullscreenController::RequestToLockMouse(WebContents* web_contents, | 76 void FullscreenController::RequestToLockMouse(WebContents* web_contents, |
77 bool user_gesture, | 77 bool user_gesture, |
78 bool last_unlocked_by_target) { | 78 bool last_unlocked_by_target) { |
79 DCHECK(!IsMouseLocked()); | 79 DCHECK(!IsMouseLocked()); |
| 80 NotifyMouseLockChange(); |
80 | 81 |
81 // Check for command line switch disabling mouse lock when not tab fullscreen. | 82 // Check for command line switch disabling mouse lock when not tab fullscreen. |
82 if (CommandLine::ForCurrentProcess()->HasSwitch( | 83 if (CommandLine::ForCurrentProcess()->HasSwitch( |
83 switches::kDisableNonFullscreenMouseLock) && | 84 switches::kDisableNonFullscreenMouseLock) && |
84 !IsFullscreenForTabOrPending(web_contents)) { | 85 !IsFullscreenForTabOrPending(web_contents)) { |
85 web_contents->GotResponseToLockMouseRequest(false); | 86 web_contents->GotResponseToLockMouseRequest(false); |
86 return; | 87 return; |
87 } | 88 } |
88 | 89 |
89 NotifyMouseLockChange(); | |
90 | |
91 // Must have a user gesture to prevent misbehaving sites from constantly | 90 // Must have a user gesture to prevent misbehaving sites from constantly |
92 // re-locking the mouse. Exceptions are when the page has unlocked | 91 // re-locking the mouse. Exceptions are when the page has unlocked |
93 // (i.e. not the user), or if we're in tab fullscreen (user gesture required | 92 // (i.e. not the user), or if we're in tab fullscreen (user gesture required |
94 // for that) | 93 // for that) |
95 if (!last_unlocked_by_target && !user_gesture && | 94 if (!last_unlocked_by_target && !user_gesture && |
96 !IsFullscreenForTabOrPending(web_contents)) { | 95 !IsFullscreenForTabOrPending(web_contents)) { |
97 web_contents->GotResponseToLockMouseRequest(false); | 96 web_contents->GotResponseToLockMouseRequest(false); |
98 return; | 97 return; |
99 } | 98 } |
100 mouse_lock_tab_ = TabContents::FromWebContents(web_contents); | 99 mouse_lock_tab_ = TabContents::FromWebContents(web_contents); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 bool FullscreenController::HandleUserPressedEscape() { | 330 bool FullscreenController::HandleUserPressedEscape() { |
332 if (IsFullscreenForTabOrPending() || | 331 if (IsFullscreenForTabOrPending() || |
333 IsMouseLocked() || IsMouseLockRequested()) { | 332 IsMouseLocked() || IsMouseLockRequested()) { |
334 ExitTabFullscreenOrMouseLockIfNecessary(); | 333 ExitTabFullscreenOrMouseLockIfNecessary(); |
335 return true; | 334 return true; |
336 } | 335 } |
337 | 336 |
338 return false; | 337 return false; |
339 } | 338 } |
340 | 339 |
| 340 bool FullscreenController::HandleUserPressedReload() { |
| 341 if (IsFullscreenForTabOrPending() || |
| 342 IsMouseLocked() || IsMouseLockRequested()) { |
| 343 ExitTabFullscreenOrMouseLockIfNecessary(); |
| 344 } |
| 345 |
| 346 return false; |
| 347 } |
| 348 |
341 FullscreenController::~FullscreenController() {} | 349 FullscreenController::~FullscreenController() {} |
342 | 350 |
343 void FullscreenController::NotifyTabOfExitIfNecessary() { | 351 void FullscreenController::NotifyTabOfExitIfNecessary() { |
344 if (fullscreened_tab_) { | 352 if (fullscreened_tab_) { |
345 RenderViewHost* rvh = | 353 RenderViewHost* rvh = |
346 fullscreened_tab_->web_contents()->GetRenderViewHost(); | 354 fullscreened_tab_->web_contents()->GetRenderViewHost(); |
347 fullscreened_tab_ = NULL; | 355 fullscreened_tab_ = NULL; |
348 tab_caused_fullscreen_ = false; | 356 tab_caused_fullscreen_ = false; |
349 tab_fullscreen_accepted_ = false; | 357 tab_fullscreen_accepted_ = false; |
350 if (rvh) | 358 if (rvh) |
351 rvh->ExitFullscreen(); | 359 rvh->ExitFullscreen(); |
352 } | 360 } |
353 | 361 |
354 if (mouse_lock_tab_) { | 362 if (mouse_lock_tab_) { |
355 WebContents* web_contents = mouse_lock_tab_->web_contents(); | 363 WebContents* web_contents = mouse_lock_tab_->web_contents(); |
356 if (IsMouseLockRequested()) { | 364 if (IsMouseLockRequested()) { |
357 web_contents->GotResponseToLockMouseRequest(false); | 365 web_contents->GotResponseToLockMouseRequest(false); |
| 366 NotifyMouseLockChange(); |
358 } else if (web_contents->GetRenderViewHost() && | 367 } else if (web_contents->GetRenderViewHost() && |
359 web_contents->GetRenderViewHost()->GetView()) { | 368 web_contents->GetRenderViewHost()->GetView()) { |
360 web_contents->GetRenderViewHost()->GetView()->UnlockMouse(); | 369 web_contents->GetRenderViewHost()->GetView()->UnlockMouse(); |
361 } | 370 } |
362 mouse_lock_tab_ = NULL; | 371 mouse_lock_tab_ = NULL; |
363 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 372 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
364 } | 373 } |
365 | 374 |
366 UpdateFullscreenExitBubbleContent(); | 375 UpdateFullscreenExitBubbleContent(); |
367 } | 376 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 window_->ExitFullscreen(); | 535 window_->ExitFullscreen(); |
527 extension_caused_fullscreen_ = GURL(); | 536 extension_caused_fullscreen_ = GURL(); |
528 } | 537 } |
529 UpdateFullscreenExitBubbleContent(); | 538 UpdateFullscreenExitBubbleContent(); |
530 | 539 |
531 // Once the window has become fullscreen it'll call back to | 540 // Once the window has become fullscreen it'll call back to |
532 // WindowFullscreenStateChanged(). We don't do this immediately as | 541 // WindowFullscreenStateChanged(). We don't do this immediately as |
533 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 542 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
534 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 543 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
535 } | 544 } |
OLD | NEW |