OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/frame/browser_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
922 | 922 |
923 void BrowserView::Restore() { | 923 void BrowserView::Restore() { |
924 frame_->Restore(); | 924 frame_->Restore(); |
925 } | 925 } |
926 | 926 |
927 void BrowserView::EnterFullscreen( | 927 void BrowserView::EnterFullscreen( |
928 const GURL& url, FullscreenExitBubbleType bubble_type) { | 928 const GURL& url, FullscreenExitBubbleType bubble_type) { |
929 if (IsFullscreen()) | 929 if (IsFullscreen()) |
930 return; // Nothing to do. | 930 return; // Nothing to do. |
931 | 931 |
932 ProcessFullscreen(true, FOR_DESKTOP, url, bubble_type); | 932 ProcessFullscreen(true, NORMAL_FULLSCREEN, url, bubble_type); |
933 } | 933 } |
934 | 934 |
935 void BrowserView::ExitFullscreen() { | 935 void BrowserView::ExitFullscreen() { |
936 if (!IsFullscreen()) | 936 if (!IsFullscreen()) |
937 return; // Nothing to do. | 937 return; // Nothing to do. |
938 | 938 |
939 ProcessFullscreen(false, FOR_DESKTOP, GURL(), FEB_TYPE_NONE); | 939 ProcessFullscreen(false, NORMAL_FULLSCREEN, GURL(), FEB_TYPE_NONE); |
940 } | 940 } |
941 | 941 |
942 void BrowserView::UpdateFullscreenExitBubbleContent( | 942 void BrowserView::UpdateFullscreenExitBubbleContent( |
943 const GURL& url, | 943 const GURL& url, |
944 FullscreenExitBubbleType bubble_type) { | 944 FullscreenExitBubbleType bubble_type) { |
945 // Immersive mode has no exit bubble because it has a visible strip at the | 945 // Immersive mode has no exit bubble because it has a visible strip at the |
946 // top that gives the user a hover target. | 946 // top that gives the user a hover target. |
947 // TODO(jamescook): Figure out what to do with mouse-lock. | 947 // TODO(jamescook): Figure out what to do with mouse-lock. |
948 if (bubble_type == FEB_TYPE_NONE || ShouldUseImmersiveFullscreenForUrl(url)) { | 948 if (bubble_type == FEB_TYPE_NONE || ShouldUseImmersiveFullscreenForUrl(url)) { |
949 fullscreen_bubble_.reset(); | 949 fullscreen_bubble_.reset(); |
(...skipping 17 matching lines...) Expand all Loading... | |
967 return frame_->IsFullscreen(); | 967 return frame_->IsFullscreen(); |
968 } | 968 } |
969 | 969 |
970 bool BrowserView::IsFullscreenBubbleVisible() const { | 970 bool BrowserView::IsFullscreenBubbleVisible() const { |
971 return fullscreen_bubble_ != NULL; | 971 return fullscreen_bubble_ != NULL; |
972 } | 972 } |
973 | 973 |
974 #if defined(OS_WIN) | 974 #if defined(OS_WIN) |
975 void BrowserView::SetMetroSnapMode(bool enable) { | 975 void BrowserView::SetMetroSnapMode(bool enable) { |
976 HISTOGRAM_COUNTS("Metro.SnapModeToggle", enable); | 976 HISTOGRAM_COUNTS("Metro.SnapModeToggle", enable); |
977 ProcessFullscreen(enable, FOR_METRO, GURL(), FEB_TYPE_NONE); | 977 ProcessFullscreen(enable, METRO_SNAP_FULLSCREEN, GURL(), FEB_TYPE_NONE); |
978 } | 978 } |
979 | 979 |
980 bool BrowserView::IsInMetroSnapMode() const { | 980 bool BrowserView::IsInMetroSnapMode() const { |
981 return false; | 981 return false; |
982 } | 982 } |
983 #endif // defined(OS_WIN) | 983 #endif // defined(OS_WIN) |
984 | 984 |
985 void BrowserView::RestoreFocus() { | 985 void BrowserView::RestoreFocus() { |
986 WebContents* selected_web_contents = GetActiveWebContents(); | 986 WebContents* selected_web_contents = GetActiveWebContents(); |
987 if (selected_web_contents) | 987 if (selected_web_contents) |
988 selected_web_contents->GetView()->RestoreFocus(); | 988 selected_web_contents->GetView()->RestoreFocus(); |
989 } | 989 } |
990 | 990 |
991 void BrowserView::SetWindowSwitcherButton(views::Button* button) { | 991 void BrowserView::SetWindowSwitcherButton(views::Button* button) { |
992 if (window_switcher_button_) | 992 if (window_switcher_button_) |
993 RemoveChildView(window_switcher_button_); | 993 RemoveChildView(window_switcher_button_); |
994 window_switcher_button_ = button; | 994 window_switcher_button_ = button; |
995 } | 995 } |
996 | 996 |
997 void BrowserView::FullscreenStateChanged() { | 997 void BrowserView::FullscreenStateChanged() { |
998 CHECK(!IsFullscreen()); | 998 CHECK(!IsFullscreen()); |
999 ProcessFullscreen(false, FOR_DESKTOP, GURL(), FEB_TYPE_NONE); | 999 ProcessFullscreen(false, NORMAL_FULLSCREEN, GURL(), FEB_TYPE_NONE); |
1000 } | 1000 } |
1001 | 1001 |
1002 void BrowserView::ToolbarSizeChanged(bool is_animating) { | 1002 void BrowserView::ToolbarSizeChanged(bool is_animating) { |
1003 // The call to InfoBarContainer::SetMaxTopArrowHeight() below can result in | 1003 // The call to InfoBarContainer::SetMaxTopArrowHeight() below can result in |
1004 // reentrancy; |call_state| tracks whether we're reentrant. We can't just | 1004 // reentrancy; |call_state| tracks whether we're reentrant. We can't just |
1005 // early-return in this case because we need to layout again so the infobar | 1005 // early-return in this case because we need to layout again so the infobar |
1006 // container's bounds are set correctly. | 1006 // container's bounds are set correctly. |
1007 static CallState call_state = NORMAL; | 1007 static CallState call_state = NORMAL; |
1008 | 1008 |
1009 // A reentrant call can (and should) use the fast resize path unless both it | 1009 // A reentrant call can (and should) use the fast resize path unless both it |
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2182 void BrowserView::UpdateUIForContents(WebContents* contents) { | 2182 void BrowserView::UpdateUIForContents(WebContents* contents) { |
2183 bool needs_layout = MaybeShowBookmarkBar(contents); | 2183 bool needs_layout = MaybeShowBookmarkBar(contents); |
2184 // TODO(jamescook): This function always returns true. Remove it and figure | 2184 // TODO(jamescook): This function always returns true. Remove it and figure |
2185 // out when layout is actually required. | 2185 // out when layout is actually required. |
2186 needs_layout |= MaybeShowInfoBar(contents); | 2186 needs_layout |= MaybeShowInfoBar(contents); |
2187 if (needs_layout) | 2187 if (needs_layout) |
2188 Layout(); | 2188 Layout(); |
2189 } | 2189 } |
2190 | 2190 |
2191 void BrowserView::ProcessFullscreen(bool fullscreen, | 2191 void BrowserView::ProcessFullscreen(bool fullscreen, |
2192 FullscreenType type, | 2192 FullscreenMode mode, |
2193 const GURL& url, | 2193 const GURL& url, |
2194 FullscreenExitBubbleType bubble_type) { | 2194 FullscreenExitBubbleType bubble_type) { |
2195 if (in_process_fullscreen_) | 2195 if (in_process_fullscreen_) |
2196 return; | 2196 return; |
2197 in_process_fullscreen_ = true; | 2197 in_process_fullscreen_ = true; |
2198 | 2198 |
2199 // Reduce jankiness during the following position changes by: | 2199 // Reduce jankiness during the following position changes by: |
2200 // * Hiding the window until it's in the final position | 2200 // * Hiding the window until it's in the final position |
2201 // * Ignoring all intervening Layout() calls, which resize the webpage and | 2201 // * Ignoring all intervening Layout() calls, which resize the webpage and |
2202 // thus are slow and look ugly (enforced via |in_process_fullscreen_|). | 2202 // thus are slow and look ugly (enforced via |in_process_fullscreen_|). |
2203 LocationBarView* location_bar = GetLocationBarView(); | 2203 LocationBarView* location_bar = GetLocationBarView(); |
2204 | 2204 |
2205 if (type == FOR_METRO || !fullscreen) { | 2205 if (mode == METRO_SNAP_FULLSCREEN || !fullscreen) { |
2206 // Hide the fullscreen bubble as soon as possible, since the mode toggle can | 2206 // Hide the fullscreen bubble as soon as possible, since the mode toggle can |
2207 // take enough time for the user to notice. | 2207 // take enough time for the user to notice. |
2208 fullscreen_bubble_.reset(); | 2208 fullscreen_bubble_.reset(); |
2209 } | 2209 } |
2210 | 2210 |
2211 if (fullscreen) { | 2211 if (fullscreen) { |
2212 // Move focus out of the location bar if necessary. | 2212 // Move focus out of the location bar if necessary. |
2213 views::FocusManager* focus_manager = GetFocusManager(); | 2213 views::FocusManager* focus_manager = GetFocusManager(); |
2214 DCHECK(focus_manager); | 2214 DCHECK(focus_manager); |
2215 // Look for focus in the location bar itself or any child view. | 2215 // Look for focus in the location bar itself or any child view. |
2216 if (location_bar->Contains(focus_manager->GetFocusedView())) | 2216 if (location_bar->Contains(focus_manager->GetFocusedView())) |
2217 focus_manager->ClearFocus(); | 2217 focus_manager->ClearFocus(); |
2218 } | 2218 } |
2219 | 2219 |
2220 // Toggle fullscreen mode. | 2220 // Toggle fullscreen mode. |
2221 frame_->SetFullscreen(fullscreen); | 2221 frame_->SetFullscreen(fullscreen); |
2222 | 2222 |
2223 // Enable immersive before the browser refreshes its list of enabled commands. | 2223 // Enable immersive before the browser refreshes its list of enabled commands. |
2224 if (ShouldUseImmersiveFullscreenForUrl(url)) | 2224 if (mode != METRO_SNAP_FULLSCREEN && ShouldUseImmersiveFullscreenForUrl(url)) |
2225 immersive_mode_controller_->SetEnabled(fullscreen); | 2225 immersive_mode_controller_->SetEnabled(fullscreen); |
2226 | 2226 |
2227 browser_->WindowFullscreenStateChanged(); | 2227 browser_->WindowFullscreenStateChanged(); |
2228 | 2228 |
2229 if (fullscreen && !chrome::IsRunningInAppMode() && type != FOR_METRO) | 2229 if (fullscreen && !chrome::IsRunningInAppMode() && |
2230 mode != METRO_SNAP_FULLSCREEN) { | |
2230 UpdateFullscreenExitBubbleContent(url, bubble_type); | 2231 UpdateFullscreenExitBubbleContent(url, bubble_type); |
2232 } | |
2231 | 2233 |
2232 // Undo our anti-jankiness hacks and force a re-layout. We also need to | 2234 // Undo our anti-jankiness hacks and force a re-layout. We also need to |
2233 // recompute the height of the infobar top arrow because toggling in and out | 2235 // recompute the height of the infobar top arrow because toggling in and out |
2234 // of fullscreen changes it. Calling ToolbarSizeChanged() will do both these | 2236 // of fullscreen changes it. Calling ToolbarSizeChanged() will do both these |
2235 // things since it computes the arrow height directly and forces a layout | 2237 // things since it computes the arrow height directly and forces a layout |
2236 // indirectly via UpdateUIForContents(). Reset |in_process_fullscreen_| in | 2238 // indirectly via UpdateUIForContents(). Reset |in_process_fullscreen_| in |
2237 // order to let the layout occur. | 2239 // order to let the layout occur. |
2238 in_process_fullscreen_ = false; | 2240 in_process_fullscreen_ = false; |
2239 ToolbarSizeChanged(false); | 2241 ToolbarSizeChanged(false); |
2240 } | 2242 } |
2241 | 2243 |
2242 bool BrowserView::ShouldUseImmersiveFullscreenForUrl(const GURL& url) const { | 2244 bool BrowserView::ShouldUseImmersiveFullscreenForUrl(const GURL& url) const { |
2243 #if defined(OS_CHROMEOS) | 2245 #if defined(OS_CHROMEOS) |
2244 // Kiosk mode needs the whole screen. | 2246 // Kiosk mode needs the whole screen. |
2245 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 2247 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
2246 return false; | 2248 return false; |
2247 bool is_browser_fullscreen = url.is_empty(); | 2249 #endif |
2248 if (ash::switches::UseImmersiveFullscreenForAllWindows()) | 2250 |
2249 return is_browser_fullscreen; | 2251 #if defined(USE_ASH) |
2250 else | 2252 if (browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH) { |
2251 return is_browser_fullscreen && IsBrowserTypeNormal(); | 2253 bool is_browser_fullscreen = url.is_empty(); |
2252 #else | 2254 if (ash::switches::UseImmersiveFullscreenForAllWindows()) |
2255 return is_browser_fullscreen; | |
2256 else | |
sky
2014/03/13 22:08:25
nit: style says no else after a return.
| |
2257 return is_browser_fullscreen && IsBrowserTypeNormal(); | |
2258 } | |
2259 #endif | |
2260 | |
2253 return false; | 2261 return false; |
2254 #endif | |
2255 } | 2262 } |
2256 | 2263 |
2257 void BrowserView::LoadAccelerators() { | 2264 void BrowserView::LoadAccelerators() { |
2258 views::FocusManager* focus_manager = GetFocusManager(); | 2265 views::FocusManager* focus_manager = GetFocusManager(); |
2259 DCHECK(focus_manager); | 2266 DCHECK(focus_manager); |
2260 | 2267 |
2261 // Let's fill our own accelerator table. | 2268 // Let's fill our own accelerator table. |
2262 const bool is_app_mode = chrome::IsRunningInForcedAppMode(); | 2269 const bool is_app_mode = chrome::IsRunningInForcedAppMode(); |
2263 const std::vector<chrome::AcceleratorMapping> accelerator_list( | 2270 const std::vector<chrome::AcceleratorMapping> accelerator_list( |
2264 chrome::GetAcceleratorList()); | 2271 chrome::GetAcceleratorList()); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2577 !GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) { | 2584 !GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) { |
2578 gfx::Point icon_bottom( | 2585 gfx::Point icon_bottom( |
2579 toolbar_->location_bar()->GetLocationBarAnchorPoint()); | 2586 toolbar_->location_bar()->GetLocationBarAnchorPoint()); |
2580 ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom); | 2587 ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom); |
2581 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); | 2588 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); |
2582 ConvertPointToTarget(infobar_container_, this, &infobar_top); | 2589 ConvertPointToTarget(infobar_container_, this, &infobar_top); |
2583 top_arrow_height = infobar_top.y() - icon_bottom.y(); | 2590 top_arrow_height = infobar_top.y() - icon_bottom.y(); |
2584 } | 2591 } |
2585 return top_arrow_height; | 2592 return top_arrow_height; |
2586 } | 2593 } |
OLD | NEW |