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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/browser.cc
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index fe651faec5dc9c3ae045fc0ec60ce8e54dfcb9f8..67aab7d5d2669c82f814e264d091d292c9c73a22 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -995,6 +995,20 @@ void Browser::TabDeactivated(WebContents* contents) {
instant_controller_->TabDeactivated(contents);
}
+// Copies the background color from an old WebContents to a new one that
+// replaces it on the screen. This allows the new WebContents to use the
+// old one's background color as the starting background color, before having
+// loaded any contents. As a result, we avoid flashing white when navigating
+// from a site whith a dark background to another site with a dark background.
+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.
+ if (old_contents && new_contents) {
+ RenderWidgetHostView* old_view = old_contents->GetMainFrame()->GetView();
+ RenderWidgetHostView* new_view = new_contents->GetMainFrame()->GetView();
+ if (old_view && new_view)
+ new_view->SetBackgroundColor(old_view->background_color());
+ }
+}
+
void Browser::ActiveTabChanged(WebContents* old_contents,
WebContents* new_contents,
int index,
@@ -1851,6 +1865,7 @@ void Browser::SwapTabContents(content::WebContents* old_contents,
content::WebContents* new_contents,
bool did_start_load,
bool did_finish_load) {
+ CopyBackgroundColor(old_contents, new_contents);
int index = tab_strip_model_->GetIndexOfWebContents(old_contents);
DCHECK_NE(TabStripModel::kNoTab, index);
tab_strip_model_->ReplaceWebContentsAt(index, new_contents);

Powered by Google App Engine
This is Rietveld 408576698