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 20 matching lines...) Expand all Loading... |
31 profile_(profile), | 31 profile_(profile), |
32 browser_(browser), | 32 browser_(browser), |
33 fullscreened_tab_(NULL), | 33 fullscreened_tab_(NULL), |
34 tab_caused_fullscreen_(false), | 34 tab_caused_fullscreen_(false), |
35 tab_fullscreen_accepted_(false), | 35 tab_fullscreen_accepted_(false), |
36 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED) { | 36 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED) { |
37 } | 37 } |
38 | 38 |
39 FullscreenController::~FullscreenController() {} | 39 FullscreenController::~FullscreenController() {} |
40 | 40 |
41 bool FullscreenController::IsFullscreenForTab() const { | 41 bool FullscreenController::IsFullscreenForBrowser() const { |
| 42 return window_->IsFullscreen() && !tab_caused_fullscreen_; |
| 43 } |
| 44 |
| 45 bool FullscreenController::IsFullscreenForTabOrPending() const { |
42 return fullscreened_tab_ != NULL; | 46 return fullscreened_tab_ != NULL; |
43 } | 47 } |
44 | 48 |
45 bool FullscreenController::IsFullscreenForTab(const WebContents* tab) const { | |
46 if (IsFullscreenForTabOrPending(tab)) { | |
47 DCHECK(window_->IsFullscreen()); | |
48 return true; | |
49 } | |
50 return false; | |
51 } | |
52 | |
53 bool FullscreenController::IsFullscreenForTabOrPending( | 49 bool FullscreenController::IsFullscreenForTabOrPending( |
54 const WebContents* tab) const { | 50 const WebContents* tab) const { |
55 const TabContentsWrapper* wrapper = | 51 const TabContentsWrapper* wrapper = |
56 TabContentsWrapper::GetCurrentWrapperForContents(tab); | 52 TabContentsWrapper::GetCurrentWrapperForContents(tab); |
57 if (!wrapper || (wrapper != fullscreened_tab_)) | 53 if (!wrapper || (wrapper != fullscreened_tab_)) |
58 return false; | 54 return false; |
59 DCHECK(tab == browser_->GetSelectedWebContents()); | 55 DCHECK(tab == browser_->GetSelectedWebContents()); |
60 return true; | 56 return true; |
61 } | 57 } |
62 | 58 |
| 59 bool FullscreenController::IsMouseLockedOrPending() const { |
| 60 return mouse_lock_state_ != MOUSELOCK_NOT_REQUESTED; |
| 61 } |
| 62 |
63 void FullscreenController::RequestToLockMouse(WebContents* tab) { | 63 void FullscreenController::RequestToLockMouse(WebContents* tab) { |
64 // Mouse Lock is only permitted when browser is in tab fullscreen. | 64 // Mouse Lock is only permitted when browser is in tab fullscreen. |
65 if (!IsFullscreenForTabOrPending(tab)) { | 65 if (!IsFullscreenForTabOrPending(tab)) { |
66 tab->GotResponseToLockMouseRequest(false); | 66 tab->GotResponseToLockMouseRequest(false); |
67 return; | 67 return; |
68 } | 68 } |
69 | 69 |
70 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED) { | 70 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED) { |
71 tab->GotResponseToLockMouseRequest(true); | 71 tab->GotResponseToLockMouseRequest(true); |
72 return; | 72 return; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 extension_caused_fullscreen_ = extension_url; | 163 extension_caused_fullscreen_ = extension_url; |
164 ToggleFullscreenModeInternal(false); | 164 ToggleFullscreenModeInternal(false); |
165 } | 165 } |
166 | 166 |
167 void FullscreenController::LostMouseLock() { | 167 void FullscreenController::LostMouseLock() { |
168 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 168 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; |
169 UpdateFullscreenExitBubbleContent(); | 169 UpdateFullscreenExitBubbleContent(); |
170 } | 170 } |
171 | 171 |
172 void FullscreenController::OnTabClosing(WebContents* web_contents) { | 172 void FullscreenController::OnTabClosing(WebContents* web_contents) { |
173 if (IsFullscreenForTab(web_contents)) { | 173 if (IsFullscreenForTabOrPending(web_contents)) { |
174 ExitTabbedFullscreenModeIfNecessary(); | 174 ExitTabbedFullscreenModeIfNecessary(); |
175 // The call to exit fullscreen may result in asynchronous notification of | 175 // The call to exit fullscreen may result in asynchronous notification of |
176 // fullscreen state change (e.g., on Linux). We don't want to rely on it | 176 // fullscreen state change (e.g., on Linux). We don't want to rely on it |
177 // to call NotifyTabOfFullscreenExitIfNecessary(), because at that point | 177 // to call NotifyTabOfFullscreenExitIfNecessary(), because at that point |
178 // |fullscreen_tab_| may not be valid. Instead, we call it here to clean up | 178 // |fullscreen_tab_| may not be valid. Instead, we call it here to clean up |
179 // tab fullscreen related state. | 179 // tab fullscreen related state. |
180 NotifyTabOfFullscreenExitIfNecessary(); | 180 NotifyTabOfFullscreenExitIfNecessary(); |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 NotifyTabOfFullscreenExitIfNecessary(); | 257 NotifyTabOfFullscreenExitIfNecessary(); |
258 #if !defined(OS_CHROMEOS) | 258 #if !defined(OS_CHROMEOS) |
259 if (exiting_fullscreen) | 259 if (exiting_fullscreen) |
260 window_->GetDownloadShelf()->Unhide(); | 260 window_->GetDownloadShelf()->Unhide(); |
261 else | 261 else |
262 window_->GetDownloadShelf()->Hide(); | 262 window_->GetDownloadShelf()->Hide(); |
263 #endif | 263 #endif |
264 } | 264 } |
265 | 265 |
266 bool FullscreenController::HandleUserPressedEscape() { | 266 bool FullscreenController::HandleUserPressedEscape() { |
267 if (!IsFullscreenForTab()) | 267 if (!IsFullscreenForTabOrPending()) |
268 return false; | 268 return false; |
269 ExitTabbedFullscreenModeIfNecessary(); | 269 ExitTabbedFullscreenModeIfNecessary(); |
270 return true; | 270 return true; |
271 } | 271 } |
272 | 272 |
273 void FullscreenController::NotifyTabOfFullscreenExitIfNecessary() { | 273 void FullscreenController::NotifyTabOfFullscreenExitIfNecessary() { |
274 if (fullscreened_tab_ && | 274 if (fullscreened_tab_ && |
275 fullscreened_tab_->web_contents()->GetRenderViewHost()) { | 275 fullscreened_tab_->web_contents()->GetRenderViewHost()) { |
276 fullscreened_tab_->web_contents()->GetRenderViewHost()->ExitFullscreen(); | 276 fullscreened_tab_->web_contents()->GetRenderViewHost()->ExitFullscreen(); |
277 } else { | 277 } else { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 // WindowFullscreenStateChanged(). We don't do this immediately as | 401 // WindowFullscreenStateChanged(). We don't do this immediately as |
402 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | 402 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
403 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 403 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
404 | 404 |
405 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates | 405 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates |
406 // the necessary state of the frame. | 406 // the necessary state of the frame. |
407 #if defined(OS_MACOSX) | 407 #if defined(OS_MACOSX) |
408 WindowFullscreenStateChanged(); | 408 WindowFullscreenStateChanged(); |
409 #endif | 409 #endif |
410 } | 410 } |
OLD | NEW |