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

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

Issue 2466413009: Propagate view background color when changing visible web contents. (Closed)
Patch Set: none Created 4 years, 1 month 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
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 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 SearchTabHelper::FromWebContents(contents)->OnTabDeactivated(); 988 SearchTabHelper::FromWebContents(contents)->OnTabDeactivated();
989 989
990 // Save what the user's currently typing, so it can be restored when we 990 // Save what the user's currently typing, so it can be restored when we
991 // switch back to this tab. 991 // switch back to this tab.
992 window_->GetLocationBar()->SaveStateToContents(contents); 992 window_->GetLocationBar()->SaveStateToContents(contents);
993 993
994 if (instant_controller_) 994 if (instant_controller_)
995 instant_controller_->TabDeactivated(contents); 995 instant_controller_->TabDeactivated(contents);
996 } 996 }
997 997
998 // Copies the background color from an old WebContents to a new one that
999 // replaces it on the screen. This allows the new WebContents to use the
1000 // old one's background color as the starting background color, before having
1001 // loaded any contents. As a result, we avoid flashing white when navigating
1002 // from a site whith a dark background to another site with a dark background.
1003 void CopyBackgroundColor(WebContents* old_contents, WebContents* new_contents) {
Peter Kasting 2016/11/07 19:27:41 Nit: I would inline this into the single caller as
chrishtr 2016/11/09 21:39:36 Done.
1004 if (old_contents && new_contents) {
1005 RenderWidgetHostView* old_view = old_contents->GetMainFrame()->GetView();
1006 RenderWidgetHostView* new_view = new_contents->GetMainFrame()->GetView();
1007 if (old_view && new_view)
1008 new_view->SetBackgroundColor(old_view->background_color());
1009 }
1010 }
1011
998 void Browser::ActiveTabChanged(WebContents* old_contents, 1012 void Browser::ActiveTabChanged(WebContents* old_contents,
999 WebContents* new_contents, 1013 WebContents* new_contents,
1000 int index, 1014 int index,
1001 int reason) { 1015 int reason) {
1002 content::RecordAction(UserMetricsAction("ActiveTabChanged")); 1016 content::RecordAction(UserMetricsAction("ActiveTabChanged"));
1003 1017
1004 // Update the bookmark state, since the BrowserWindow may query it during 1018 // Update the bookmark state, since the BrowserWindow may query it during
1005 // OnActiveTabChanged() below. 1019 // OnActiveTabChanged() below.
1006 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); 1020 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH);
1007 1021
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 return size; 1858 return size;
1845 } 1859 }
1846 1860
1847 /////////////////////////////////////////////////////////////////////////////// 1861 ///////////////////////////////////////////////////////////////////////////////
1848 // Browser, CoreTabHelperDelegate implementation: 1862 // Browser, CoreTabHelperDelegate implementation:
1849 1863
1850 void Browser::SwapTabContents(content::WebContents* old_contents, 1864 void Browser::SwapTabContents(content::WebContents* old_contents,
1851 content::WebContents* new_contents, 1865 content::WebContents* new_contents,
1852 bool did_start_load, 1866 bool did_start_load,
1853 bool did_finish_load) { 1867 bool did_finish_load) {
1868 CopyBackgroundColor(old_contents, new_contents);
1854 int index = tab_strip_model_->GetIndexOfWebContents(old_contents); 1869 int index = tab_strip_model_->GetIndexOfWebContents(old_contents);
1855 DCHECK_NE(TabStripModel::kNoTab, index); 1870 DCHECK_NE(TabStripModel::kNoTab, index);
1856 tab_strip_model_->ReplaceWebContentsAt(index, new_contents); 1871 tab_strip_model_->ReplaceWebContentsAt(index, new_contents);
1857 } 1872 }
1858 1873
1859 bool Browser::CanReloadContents(content::WebContents* web_contents) const { 1874 bool Browser::CanReloadContents(content::WebContents* web_contents) const {
1860 return chrome::CanReload(this); 1875 return chrome::CanReload(this);
1861 } 1876 }
1862 1877
1863 bool Browser::CanSaveContents(content::WebContents* web_contents) const { 1878 bool Browser::CanSaveContents(content::WebContents* web_contents) const {
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
2583 if (contents && !allow_js_access) { 2598 if (contents && !allow_js_access) {
2584 contents->web_contents()->GetController().LoadURL( 2599 contents->web_contents()->GetController().LoadURL(
2585 target_url, 2600 target_url,
2586 content::Referrer(), 2601 content::Referrer(),
2587 ui::PAGE_TRANSITION_LINK, 2602 ui::PAGE_TRANSITION_LINK,
2588 std::string()); // No extra headers. 2603 std::string()); // No extra headers.
2589 } 2604 }
2590 2605
2591 return contents != NULL; 2606 return contents != NULL;
2592 } 2607 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698