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

Unified Diff: ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js

Issue 2843333002: WebUI: restrict cr-dialogs max-height to the viewport. (Closed)
Patch Set: Created 3 years, 8 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: ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js
diff --git a/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js b/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js
index 3e9fc20ba55944730342044421ecc1ec773b8336..0fe9b0e38990b83247109d0ce74427bb33f56667 100644
--- a/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js
+++ b/ui/webui/resources/cr_elements/cr_dialog/cr_dialog.js
@@ -64,6 +64,9 @@ Polymer({
this.addEventListener('keypress', this.onKeypress_.bind(this));
},
+ /** @private {Function} */
+ onResize_: null,
+
/** @override */
attached: function() {
if (!this.showScrollBorders)
@@ -72,6 +75,10 @@ Polymer({
this.mutationObserver_ = new MutationObserver(function() {
if (this.open) {
this.addIntersectionObserver_();
+ this.adjustHeight_();
+
+ this.onResize_ = this.adjustHeight_.bind(this);
+ window.addEventListener('resize', this.onResize_);
} else {
this.removeIntersectionObserver_();
}
@@ -90,6 +97,20 @@ Polymer({
this.mutationObserver_.disconnect();
this.mutationObserver_ = null;
}
+ window.removeEventListener('resize', this.onResize_);
+ },
+
+ adjustHeight_: function() {
dpapad 2017/04/27 22:33:24 Can we add a test for the auto-shrink logic? Also,
scottchen 2017/04/28 23:12:55 It did not jump around. However, based on our off
+ // Try to first render with just CSS styling.
+ this.$$('.body-container').style.maxHeight = null;
+
+ var delta = this.offsetHeight - window.innerHeight;
+
+ // If dialog is taller than visible viewport height, shrink by difference.
+ if (delta > 0) {
+ this.$$('.body-container').style.maxHeight =
+ (this.$$('.body-container').offsetHeight - delta) + 'px';
+ }
},
/** @private */
« 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