| 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/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 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 763 |
| 764 void BrowserView::Restore() { | 764 void BrowserView::Restore() { |
| 765 frame_->Restore(); | 765 frame_->Restore(); |
| 766 } | 766 } |
| 767 | 767 |
| 768 void BrowserView::EnterFullscreen( | 768 void BrowserView::EnterFullscreen( |
| 769 const GURL& url, FullscreenExitBubbleType bubble_type) { | 769 const GURL& url, FullscreenExitBubbleType bubble_type) { |
| 770 if (IsFullscreen()) | 770 if (IsFullscreen()) |
| 771 return; // Nothing to do. | 771 return; // Nothing to do. |
| 772 | 772 |
| 773 ProcessFullscreen(true, FOR_DESKTOP, url, bubble_type); | 773 ProcessFullscreen(true, url, bubble_type); |
| 774 } | 774 } |
| 775 | 775 |
| 776 void BrowserView::ExitFullscreen() { | 776 void BrowserView::ExitFullscreen() { |
| 777 if (!IsFullscreen()) | 777 if (!IsFullscreen()) |
| 778 return; // Nothing to do. | 778 return; // Nothing to do. |
| 779 | 779 |
| 780 ProcessFullscreen(false, FOR_DESKTOP, GURL(), FEB_TYPE_NONE); | 780 ProcessFullscreen(false, GURL(), FEB_TYPE_NONE); |
| 781 } | 781 } |
| 782 | 782 |
| 783 void BrowserView::UpdateFullscreenExitBubbleContent( | 783 void BrowserView::UpdateFullscreenExitBubbleContent( |
| 784 const GURL& url, | 784 const GURL& url, |
| 785 FullscreenExitBubbleType bubble_type) { | 785 FullscreenExitBubbleType bubble_type) { |
| 786 if (bubble_type == FEB_TYPE_NONE) { | 786 if (bubble_type == FEB_TYPE_NONE) { |
| 787 fullscreen_bubble_.reset(); | 787 fullscreen_bubble_.reset(); |
| 788 } else if (fullscreen_bubble_.get()) { | 788 } else if (fullscreen_bubble_.get()) { |
| 789 fullscreen_bubble_->UpdateContent(url, bubble_type); | 789 fullscreen_bubble_->UpdateContent(url, bubble_type); |
| 790 } else { | 790 } else { |
| 791 fullscreen_bubble_.reset(new FullscreenExitBubbleViews( | 791 fullscreen_bubble_.reset(new FullscreenExitBubbleViews( |
| 792 GetWidget(), browser_.get(), url, bubble_type)); | 792 GetWidget(), browser_.get(), url, bubble_type)); |
| 793 } | 793 } |
| 794 } | 794 } |
| 795 | 795 |
| 796 bool BrowserView::IsFullscreen() const { | 796 bool BrowserView::IsFullscreen() const { |
| 797 return frame_->IsFullscreen(); | 797 return frame_->IsFullscreen(); |
| 798 } | 798 } |
| 799 | 799 |
| 800 bool BrowserView::IsFullscreenBubbleVisible() const { | 800 bool BrowserView::IsFullscreenBubbleVisible() const { |
| 801 return fullscreen_bubble_ != NULL; | 801 return fullscreen_bubble_ != NULL; |
| 802 } | 802 } |
| 803 | 803 |
| 804 void BrowserView::FullScreenStateChanged() { | 804 void BrowserView::FullScreenStateChanged() { |
| 805 if (IsFullscreen()) { | 805 if (IsFullscreen()) { |
| 806 if (fullscreen_request_.pending) { | 806 if (fullscreen_request_.pending) { |
| 807 fullscreen_request_.pending = false; | 807 fullscreen_request_.pending = false; |
| 808 ProcessFullscreen(true, FOR_DESKTOP, | 808 ProcessFullscreen(true, fullscreen_request_.url, |
| 809 fullscreen_request_.url, | |
| 810 fullscreen_request_.bubble_type); | 809 fullscreen_request_.bubble_type); |
| 811 } else { | 810 } else { |
| 812 ProcessFullscreen(true, FOR_DESKTOP, GURL(), | 811 ProcessFullscreen(true, GURL(), |
| 813 FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION); | 812 FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION); |
| 814 } | 813 } |
| 815 } else { | 814 } else { |
| 816 ProcessFullscreen(false, FOR_DESKTOP, GURL(), FEB_TYPE_NONE); | 815 ProcessFullscreen(false, GURL(), FEB_TYPE_NONE); |
| 817 } | 816 } |
| 818 } | 817 } |
| 819 | 818 |
| 820 #if defined(OS_WIN) | |
| 821 void BrowserView::SetMetroSnapMode(bool enable) { | |
| 822 ProcessFullscreen(enable, FOR_METRO, GURL(), FEB_TYPE_NONE); | |
| 823 } | |
| 824 | |
| 825 bool BrowserView::IsInMetroSnapMode() const { | |
| 826 return static_cast<views::NativeWidgetWin*>( | |
| 827 frame_->native_widget())->IsInMetroSnapMode(); | |
| 828 } | |
| 829 #endif // defined(OS_WIN) | |
| 830 | |
| 831 void BrowserView::RestoreFocus() { | 819 void BrowserView::RestoreFocus() { |
| 832 WebContents* selected_web_contents = GetActiveWebContents(); | 820 WebContents* selected_web_contents = GetActiveWebContents(); |
| 833 if (selected_web_contents) | 821 if (selected_web_contents) |
| 834 selected_web_contents->GetView()->RestoreFocus(); | 822 selected_web_contents->GetView()->RestoreFocus(); |
| 835 } | 823 } |
| 836 | 824 |
| 837 void BrowserView::SetWindowSwitcherButton(views::Button* button) { | 825 void BrowserView::SetWindowSwitcherButton(views::Button* button) { |
| 838 if (window_switcher_button_) | 826 if (window_switcher_button_) |
| 839 RemoveChildView(window_switcher_button_); | 827 RemoveChildView(window_switcher_button_); |
| 840 window_switcher_button_ = button; | 828 window_switcher_button_ = button; |
| (...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2091 DCHECK_EQ(0, new_height); | 2079 DCHECK_EQ(0, new_height); |
| 2092 // The heights are the same, but the old view is null. This only happens | 2080 // The heights are the same, but the old view is null. This only happens |
| 2093 // when the height is zero. Zero out the bounds. | 2081 // when the height is zero. Zero out the bounds. |
| 2094 new_view->SetBounds(0, 0, 0, 0); | 2082 new_view->SetBounds(0, 0, 0, 0); |
| 2095 } | 2083 } |
| 2096 *old_view = new_view; | 2084 *old_view = new_view; |
| 2097 return changed; | 2085 return changed; |
| 2098 } | 2086 } |
| 2099 | 2087 |
| 2100 void BrowserView::ProcessFullscreen(bool fullscreen, | 2088 void BrowserView::ProcessFullscreen(bool fullscreen, |
| 2101 FullscreenType type, | |
| 2102 const GURL& url, | 2089 const GURL& url, |
| 2103 FullscreenExitBubbleType bubble_type) { | 2090 FullscreenExitBubbleType bubble_type) { |
| 2104 // Reduce jankiness during the following position changes by: | 2091 // Reduce jankiness during the following position changes by: |
| 2105 // * Hiding the window until it's in the final position | 2092 // * Hiding the window until it's in the final position |
| 2106 // * Ignoring all intervening Layout() calls, which resize the webpage and | 2093 // * Ignoring all intervening Layout() calls, which resize the webpage and |
| 2107 // thus are slow and look ugly | 2094 // thus are slow and look ugly |
| 2108 ignore_layout_ = true; | 2095 ignore_layout_ = true; |
| 2109 LocationBarView* location_bar = GetLocationBarView(); | 2096 LocationBarView* location_bar = GetLocationBarView(); |
| 2110 #if defined(OS_WIN) && !defined(USE_AURA) | 2097 #if defined(OS_WIN) && !defined(USE_AURA) |
| 2111 OmniboxViewWin* omnibox_view = | 2098 OmniboxViewWin* omnibox_view = |
| 2112 static_cast<OmniboxViewWin*>(location_bar->GetLocationEntry()); | 2099 static_cast<OmniboxViewWin*>(location_bar->GetLocationEntry()); |
| 2113 #endif | 2100 #endif |
| 2114 | 2101 if (!fullscreen) { |
| 2115 if (!fullscreen && type != FOR_METRO) { | |
| 2116 // Hide the fullscreen bubble as soon as possible, since the mode toggle can | 2102 // Hide the fullscreen bubble as soon as possible, since the mode toggle can |
| 2117 // take enough time for the user to notice. | 2103 // take enough time for the user to notice. |
| 2118 fullscreen_bubble_.reset(); | 2104 fullscreen_bubble_.reset(); |
| 2119 } else { | 2105 } else { |
| 2120 // Move focus out of the location bar if necessary. | 2106 // Move focus out of the location bar if necessary. |
| 2121 views::FocusManager* focus_manager = GetFocusManager(); | 2107 views::FocusManager* focus_manager = GetFocusManager(); |
| 2122 DCHECK(focus_manager); | 2108 DCHECK(focus_manager); |
| 2123 // Look for focus in the location bar itself or any child view. | 2109 // Look for focus in the location bar itself or any child view. |
| 2124 if (location_bar->Contains(focus_manager->GetFocusedView())) | 2110 if (location_bar->Contains(focus_manager->GetFocusedView())) |
| 2125 focus_manager->ClearFocus(); | 2111 focus_manager->ClearFocus(); |
| 2126 | 2112 |
| 2127 #if defined(OS_WIN) && !defined(USE_AURA) | 2113 #if defined(OS_WIN) && !defined(USE_AURA) |
| 2128 // If we don't hide the edit and force it to not show until we come out of | 2114 // If we don't hide the edit and force it to not show until we come out of |
| 2129 // fullscreen, then if the user was on the New Tab Page, the edit contents | 2115 // fullscreen, then if the user was on the New Tab Page, the edit contents |
| 2130 // will appear atop the web contents once we go into fullscreen mode. This | 2116 // will appear atop the web contents once we go into fullscreen mode. This |
| 2131 // has something to do with how we move the main window while it's hidden; | 2117 // has something to do with how we move the main window while it's hidden; |
| 2132 // if we don't hide the main window below, we don't get this problem. | 2118 // if we don't hide the main window below, we don't get this problem. |
| 2133 omnibox_view->set_force_hidden(true); | 2119 omnibox_view->set_force_hidden(true); |
| 2134 ShowWindow(omnibox_view->m_hWnd, SW_HIDE); | 2120 ShowWindow(omnibox_view->m_hWnd, SW_HIDE); |
| 2135 #endif | 2121 #endif |
| 2136 } | 2122 } |
| 2137 #if defined(OS_WIN) && !defined(USE_AURA) | 2123 #if defined(OS_WIN) && !defined(USE_AURA) |
| 2138 static_cast<views::NativeWidgetWin*>(frame_->native_widget())-> | 2124 static_cast<views::NativeWidgetWin*>(frame_->native_widget())-> |
| 2139 PushForceHidden(); | 2125 PushForceHidden(); |
| 2140 #endif | 2126 #endif |
| 2141 | 2127 |
| 2142 if (type == FOR_METRO) { | 2128 // Toggle fullscreen mode. |
| 2143 #if defined(OS_WIN) | 2129 frame_->SetFullscreen(fullscreen); |
| 2144 // Enter metro snap mode. | |
| 2145 static_cast<views::NativeWidgetWin*>( | |
| 2146 frame_->native_widget())->SetMetroSnapFullscreen(fullscreen); | |
| 2147 #endif | |
| 2148 } else { | |
| 2149 // Toggle fullscreen mode. | |
| 2150 frame_->SetFullscreen(fullscreen); | |
| 2151 } | |
| 2152 | 2130 |
| 2153 browser_->WindowFullscreenStateChanged(); | 2131 browser_->WindowFullscreenStateChanged(); |
| 2154 | 2132 |
| 2155 if (fullscreen) { | 2133 if (fullscreen) { |
| 2156 bool is_kiosk = | 2134 bool is_kiosk = |
| 2157 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); | 2135 CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); |
| 2158 if (!is_kiosk && type != FOR_METRO) { | 2136 if (!is_kiosk) { |
| 2159 fullscreen_bubble_.reset(new FullscreenExitBubbleViews( | 2137 fullscreen_bubble_.reset(new FullscreenExitBubbleViews( |
| 2160 GetWidget(), browser_.get(), url, bubble_type)); | 2138 GetWidget(), browser_.get(), url, bubble_type)); |
| 2161 } | 2139 } |
| 2162 } else { | 2140 } else { |
| 2163 #if defined(OS_WIN) && !defined(USE_AURA) | 2141 #if defined(OS_WIN) && !defined(USE_AURA) |
| 2164 // Show the edit again since we're no longer in fullscreen mode. | 2142 // Show the edit again since we're no longer in fullscreen mode. |
| 2165 omnibox_view->set_force_hidden(false); | 2143 omnibox_view->set_force_hidden(false); |
| 2166 ShowWindow(omnibox_view->m_hWnd, SW_SHOW); | 2144 ShowWindow(omnibox_view->m_hWnd, SW_SHOW); |
| 2167 #endif | 2145 #endif |
| 2168 } | 2146 } |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2469 this, | 2447 this, |
| 2470 tab_contents->web_contents()->GetRenderViewHost(), | 2448 tab_contents->web_contents()->GetRenderViewHost(), |
| 2471 password_generator, | 2449 password_generator, |
| 2472 browser_.get(), | 2450 browser_.get(), |
| 2473 tab_contents->password_manager()); | 2451 tab_contents->password_manager()); |
| 2474 | 2452 |
| 2475 views::BubbleDelegateView::CreateBubble(bubble); | 2453 views::BubbleDelegateView::CreateBubble(bubble); |
| 2476 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 2454 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 2477 bubble->Show(); | 2455 bubble->Show(); |
| 2478 } | 2456 } |
| OLD | NEW |