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

Unified Diff: chrome/browser/resources/ntp4/md_incognito_tab.js

Issue 2888103002: Speed up the Incognito NTP reload (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/ntp4/md_incognito_tab.js
diff --git a/chrome/browser/resources/ntp4/md_incognito_tab.js b/chrome/browser/resources/ntp4/md_incognito_tab.js
index 3918f70126322fd2dc661c8f65c12be8a393ae16..4b6cd8580ab01aa3f22dfe1a3a20459bba15f923 100644
--- a/chrome/browser/resources/ntp4/md_incognito_tab.js
+++ b/chrome/browser/resources/ntp4/md_incognito_tab.js
@@ -24,8 +24,19 @@ window.addEventListener('load', function() {
var bulletpoints = document.querySelectorAll('.bulletpoints');
var content = document.querySelector('.content');
- var maxWidth = (bulletpoints[0].offsetWidth + bulletpoints[1].offsetWidth +
- 40 /* margin */ + 2 /* offsetWidths may be rounded down */);
+ // Unless this is the first load of the Incognito NTP in this session and
+ // with this font size, we already have the maximum content width determined.
+ var fontSize =
+ document.defaultView.getComputedStyle(document.body, null)
Dan Beam 2017/05/17 18:09:04 i don't really see a difference between document.d
msramek 2017/05/18 15:16:29 Done. Simplified, thanks.
+ .getPropertyValue("font-size");
Dan Beam 2017/05/17 18:09:04 does zoom affect this value?
msramek 2017/05/18 15:16:28 Good point :) I tested that neither the computed s
+ var savedMaxWidth = window.localStorage.getItem(fontSize);
Dan Beam 2017/05/17 18:09:04 can this all just be: var fontSize = window.getCo
msramek 2017/05/18 15:16:29 Done. Yes, but I'd like to keep the comments to ex
+
+ if (savedMaxWidth) {
+ maxWidth = savedMaxWidth
+ } else {
+ var maxWidth = (bulletpoints[0].offsetWidth + bulletpoints[1].offsetWidth +
+ 40 /* margin */ + 2 /* offsetWidths may be rounded down */);
+ }
// Limit the maximum width to 600px. That might force the two lists
// of bulletpoints under each other, in which case we must swap the left
@@ -37,4 +48,9 @@ window.addEventListener('load', function() {
}
content.style.maxWidth = maxWidth + "px";
+
+ // Save the data for quicker access when the NTP is reloaded. Note that since
+ // we're in the Incognito mode, the local storage is ephemeral and the data
+ // will be discarded when the session ends.
+ window.localStorage.setItem(fontSize, maxWidth);
Dan Beam 2017/05/17 18:09:04 localStorage[fontSize] = maxWidth;
msramek 2017/05/18 15:16:28 Done.
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698