mirror of
https://github.com/google/blockly.git
synced 2026-01-06 08:30:13 +01:00
Adding requiresResize check (#4649)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user