Adding requiresResize check (#4649)

This commit is contained in:
Monica Kozbial
2021-02-26 13:40:34 -08:00
committed by GitHub
parent 4fd6d1b229
commit 88625bc3ae

View File

@@ -653,6 +653,24 @@ Blockly.Scrollbar.prototype.resize = function(opt_metrics) {
this.updateMetrics_();
};
/**
* Returns whether the a resizeView is necessary by comparing the passed
* hostMetrics with cached old host metrics.
* @param {!Blockly.utils.Metrics} hostMetrics A data structure describing all
* the required dimensions, possibly fetched from the host object.
* @return {boolean} Whether a resizeView is necesssary.
* @private
*/
Blockly.Scrollbar.prototype.requiresViewResize_ = function(hostMetrics) {
if (!this.oldHostMetrics_) {
return true;
}
return this.oldHostMetrics_.viewWidth !== hostMetrics.viewWidth ||
this.oldHostMetrics_.viewHeight !== hostMetrics.viewHeight ||
this.oldHostMetrics_.absoluteLeft !== hostMetrics.absoluteLeft ||
this.oldHostMetrics_.absoluteTop !== hostMetrics.absoluteTop;
};
/**
* Recalculate a horizontal scrollbar's location and length.
* @param {!Blockly.utils.Metrics} hostMetrics A data structure describing all
@@ -660,9 +678,11 @@ Blockly.Scrollbar.prototype.resize = function(opt_metrics) {
* @private
*/
Blockly.Scrollbar.prototype.resizeHorizontal_ = function(hostMetrics) {
// TODO: Inspect metrics to determine if we can get away with just a content
// resize.
this.resizeViewHorizontal(hostMetrics);
if (this.requiresViewResize_(hostMetrics)) {
this.resizeViewHorizontal(hostMetrics);
} else {
this.resizeContentHorizontal(hostMetrics);
}
};
/**
@@ -755,9 +775,11 @@ Blockly.Scrollbar.prototype.resizeContentHorizontal = function(hostMetrics) {
* @private
*/
Blockly.Scrollbar.prototype.resizeVertical_ = function(hostMetrics) {
// TODO: Inspect metrics to determine if we can get away with just a content
// resize.
this.resizeViewVertical(hostMetrics);
if (this.requiresViewResize_(hostMetrics)) {
this.resizeViewVertical(hostMetrics);
} else {
this.resizeContentVertical(hostMetrics);
}
};
/**