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

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 12631008: alternate ntp: implement Show/HideBars API to reduce jank when showing/hiding bars (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
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/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // defined(OS_WIN) 10 #endif // defined(OS_WIN)
(...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 } 1220 }
1221 1221
1222 void Browser::ShowFirstRunBubble() { 1222 void Browser::ShowFirstRunBubble() {
1223 window()->GetLocationBar()->ShowFirstRunBubble(); 1223 window()->GetLocationBar()->ShowFirstRunBubble();
1224 } 1224 }
1225 1225
1226 void Browser::MaybeUpdateBookmarkBarStateForInstantOverlay( 1226 void Browser::MaybeUpdateBookmarkBarStateForInstantOverlay(
1227 const chrome::search::Mode& mode) { 1227 const chrome::search::Mode& mode) {
1228 // This is invoked by a platform-specific implementation of 1228 // This is invoked by a platform-specific implementation of
1229 // |InstantOverlayController| to update bookmark bar state according to 1229 // |InstantOverlayController| to update bookmark bar state according to
1230 // Instant overlay state. 1230 // Instant overlay state. Only handle |DEFAULT| pages for this callback.
1231 // ModeChanged() updates bookmark bar state for all mode transitions except 1231 if (mode.is_origin_default())
1232 // when new mode is |SEARCH_SUGGESTIONS|, because that needs to be done when
1233 // the suggestions are ready.
1234 if (mode.is_search_suggestions() &&
1235 bookmark_bar_state_ == BookmarkBar::SHOW) {
1236 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); 1232 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
1237 }
1238 } 1233 }
1239 1234
1240 void Browser::ShowDownload(content::DownloadItem* download) { 1235 void Browser::ShowDownload(content::DownloadItem* download) {
1241 if (!window()) 1236 if (!window())
1242 return; 1237 return;
1243 1238
1244 // If the download occurs in a new tab, and it's not a save page 1239 // If the download occurs in a new tab, and it's not a save page
1245 // download (started before initial navigation completed) close it. 1240 // download (started before initial navigation completed) close it.
1246 WebContents* source = download->GetWebContents(); 1241 WebContents* source = download->GetWebContents();
1247 if (source && source->GetController().IsInitialNavigation() && 1242 if (source && source->GetController().IsInitialNavigation() &&
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1805 break; 1800 break;
1806 } 1801 }
1807 1802
1808 default: 1803 default:
1809 NOTREACHED() << "Got a notification we didn't register for."; 1804 NOTREACHED() << "Got a notification we didn't register for.";
1810 } 1805 }
1811 } 1806 }
1812 1807
1813 void Browser::ModeChanged(const chrome::search::Mode& old_mode, 1808 void Browser::ModeChanged(const chrome::search::Mode& old_mode,
1814 const chrome::search::Mode& new_mode) { 1809 const chrome::search::Mode& new_mode) {
1815 // If new mode is |SEARCH_SUGGESTIONS|, don't update bookmark bar state now; 1810 // If new mode is |SEARCH_SUGGESTIONS| or |SEARCH_RESULTS|, don't update
dhollowa 2013/03/08 00:03:32 A note here mentioning the similar code in infobar
Peter Kasting 2013/03/08 00:51:36 Better yet, move all this code out to a common loc
dhollowa 2013/03/08 01:14:19 +1 Maybe a utility of the form: c::s::Visibility
kuan 2013/03/12 18:00:38 i've provided a chrome::search::ShouldHandleTopBar
1816 // wait till the Instant overlay is ready to show suggestions before hiding 1811 // bookmark bar state now:
1817 // the bookmark bar (in MaybeUpdateBookmarkBarStateForInstantOverlay()). 1812 // - for |DEFAULT| page, wait for Instant overlay to show or hide, via
1818 // TODO(kuan): but for now, only delay updating bookmark bar state if origin 1813 // MaybeUpdateBookmarkBarStateForInstantOverlay().
1819 // is |DEFAULT|; other origins require more complex logic to be implemented 1814 // - for |NTP| and |SERP| pages, wait for SearchBox API callback via
1820 // to prevent jankiness caused by hiding bookmark bar, so just hide the 1815 // TopBarsVisibilityChanged().
1821 // bookmark bar immediately and tolerate the jankiness for a while.
1822 // For other mode transitions, update bookmark bar state accordingly. 1816 // For other mode transitions, update bookmark bar state accordingly.
1823 if (new_mode.is_search_suggestions() && 1817 if (new_mode.is_search())
1824 new_mode.is_origin_default() &&
1825 bookmark_bar_state_ == BookmarkBar::SHOW) {
1826 return; 1818 return;
1819 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
1820 }
1821
1822 void Browser::TopBarsVisibilityChanged(const chrome::search::Mode& mode,
1823 bool visible) {
1824 // Only handle non-|DEFAULT| pages in |SEARCH_SUGGESTIONS| or
1825 // |SEARCH_RESULTS| modes for this callback.
1826 if (!mode.is_search() || mode.is_origin_default())
1827 return;
1828 if ((visible && bookmark_bar_state() == BookmarkBar::HIDDEN) ||
1829 (!visible && bookmark_bar_state() != BookmarkBar::HIDDEN)) {
1830 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
1827 } 1831 }
1828 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
1829 } 1832 }
1830 1833
1831 /////////////////////////////////////////////////////////////////////////////// 1834 ///////////////////////////////////////////////////////////////////////////////
1832 // Browser, Command and state updating (private): 1835 // Browser, Command and state updating (private):
1833 1836
1834 void Browser::OnDevToolsDisabledChanged() { 1837 void Browser::OnDevToolsDisabledChanged() {
1835 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) 1838 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
1836 content::DevToolsManager::GetInstance()->CloseAllClientHosts(); 1839 content::DevToolsManager::GetInstance()->CloseAllClientHosts();
1837 } 1840 }
1838 1841
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 } else { 2131 } else {
2129 WebContents* web_contents = tab_strip_model_->GetActiveWebContents(); 2132 WebContents* web_contents = tab_strip_model_->GetActiveWebContents();
2130 BookmarkTabHelper* bookmark_tab_helper = 2133 BookmarkTabHelper* bookmark_tab_helper =
2131 web_contents ? BookmarkTabHelper::FromWebContents(web_contents) : NULL; 2134 web_contents ? BookmarkTabHelper::FromWebContents(web_contents) : NULL;
2132 if (bookmark_tab_helper && bookmark_tab_helper->ShouldShowBookmarkBar()) 2135 if (bookmark_tab_helper && bookmark_tab_helper->ShouldShowBookmarkBar())
2133 state = BookmarkBar::DETACHED; 2136 state = BookmarkBar::DETACHED;
2134 else 2137 else
2135 state = BookmarkBar::HIDDEN; 2138 state = BookmarkBar::HIDDEN;
2136 } 2139 }
2137 2140
2138 // Don't allow the bookmark bar to be shown in suggestions mode. 2141 // Bookmark bar may need to be hidden for |SEARCH_SUGGESTIONS| and
2142 // |SEARCH_RESULTS| modes as per SearchBox API or Instant overlay.
2139 #if !defined(OS_MACOSX) 2143 #if !defined(OS_MACOSX)
dhollowa 2013/03/08 00:03:32 Please add a note as to why this doesn't apply to
kuan 2013/03/12 18:00:38 Done.
2140 if (search_model_->mode().is_search_suggestions()) 2144 const chrome::search::Mode& mode = search_model_->mode();
2141 state = BookmarkBar::HIDDEN; 2145 if (state != BookmarkBar::HIDDEN && mode.is_search()) {
2142 #endif 2146 // Hide bookmark bar if:
2147 // - for |DEFAULT| pages: Instant overlay is showing.
2148 // - for non-|DEFAULT| pages: if bookmark bar is detached or SearchBox API
2149 // says so.
2150 if (mode.is_origin_default()) {
2151 // TODO(kuan): change GetOverlayContents() to overlay() after sreeram's
2152 // refactoring, which should correctly indicate show/hide state of Instant
2153 // overlay. For now, GetOverlayContents() returns non-NULL even when
2154 // Instant overlay is hidden, resulting in an empty bookmark bar; this is
2155 // tracked at http://crbug.com/175776.
2156 if (instant_controller_ &&
2157 instant_controller_->instant()->model()->GetOverlayContents()) {
2158 state = BookmarkBar::HIDDEN;
2159 }
2160 } else if (state == BookmarkBar::DETACHED ||
2161 !search_model_->show_top_bars()) {
2162 state = BookmarkBar::HIDDEN;
2163 }
2164 }
2165 #endif // !defined(OS_MACOSX)
2143 2166
2144 if (state == bookmark_bar_state_) 2167 if (state == bookmark_bar_state_)
2145 return; 2168 return;
2146 2169
2147 bookmark_bar_state_ = state; 2170 bookmark_bar_state_ = state;
2148 2171
2149 if (!window_) 2172 if (!window_)
2150 return; // This is called from the constructor when window_ is NULL. 2173 return; // This is called from the constructor when window_ is NULL.
2151 2174
2152 if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) { 2175 if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2242 if (contents && !allow_js_access) { 2265 if (contents && !allow_js_access) {
2243 contents->web_contents()->GetController().LoadURL( 2266 contents->web_contents()->GetController().LoadURL(
2244 target_url, 2267 target_url,
2245 content::Referrer(), 2268 content::Referrer(),
2246 content::PAGE_TRANSITION_LINK, 2269 content::PAGE_TRANSITION_LINK,
2247 std::string()); // No extra headers. 2270 std::string()); // No extra headers.
2248 } 2271 }
2249 2272
2250 return contents != NULL; 2273 return contents != NULL;
2251 } 2274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698