Chromium Code Reviews| Index: chrome/browser/resources/file_manager/js/image_editor/image_util.js |
| diff --git a/chrome/browser/resources/file_manager/js/image_editor/image_util.js b/chrome/browser/resources/file_manager/js/image_editor/image_util.js |
| index 04f733d9179380ce08cc497eb433c5192561979c..51ccc8ded7aa6dc394e4a7fa415c48d60bfe8400 100644 |
| --- a/chrome/browser/resources/file_manager/js/image_editor/image_util.js |
| +++ b/chrome/browser/resources/file_manager/js/image_editor/image_util.js |
| @@ -18,7 +18,7 @@ ImageUtil.trace = (function() { |
| this.container_ = container; |
| }; |
| - PerformanceTrace.prototype.report_ = function(key, value) { |
| + PerformanceTrace.prototype.report = function(key, value) { |
| if (!this.container_) return; |
| if (!(key in this.lines_)) { |
| var div = this.lines_[key] = document.createElement('div'); |
| @@ -29,17 +29,17 @@ ImageUtil.trace = (function() { |
| PerformanceTrace.prototype.resetTimer = function(key) { |
| this.timers_[key] = Date.now(); |
| - } |
| + }; |
| PerformanceTrace.prototype.reportTimer = function(key) { |
| - this.report_(key, (Date.now() - this.timers_[key]) + 'ms'); |
| + this.report(key, (Date.now() - this.timers_[key]) + 'ms'); |
| }; |
| return new PerformanceTrace(); |
| })(); |
| -ImageUtil.clip = function(min, value, max) { |
| +ImageUtil.clamp = function(min, value, max) { |
| return Math.max(min, Math.min(max, value)); |
| }; |
| @@ -169,6 +169,36 @@ Rect.prototype.inside = function(x, y) { |
| this.top <= y && y < this.top + this.height; |
| }; |
| +/** |
| + * Clamp the rectangle to the bounds by moving it. |
| + * Decrease the size only if necessary. |
| + */ |
| +Rect.prototype.clamp = function(bounds) { |
| + var rect = new Rect(this); |
| + |
| + if (rect.width > bounds.width) { |
| + rect.left = bounds.left; |
| + rect.width = bounds.width; |
| + } else if (rect.left < bounds.left){ |
| + rect.left = bounds.left; |
| + } else if (rect.left + rect.width > |
| + bounds.left + bounds.width) { |
| + rect.left = bounds.left + bounds.width - rect.width; |
| + } |
| + |
| + if (rect.height > bounds.height) { |
| + rect.top = bounds.top; |
| + rect.height = bounds.height; |
| + } else if (rect.top < bounds.top){ |
| + rect.top = bounds.top; |
| + } else if (rect.top + rect.height > |
| + bounds.top + bounds.height) { |
| + rect.top = bounds.top + bounds.height - rect.height; |
| + } |
| + |
| + return rect; |
| +}; |
| + |
| /* |
| * Useful shortcuts for drawing (static functions). |
| */ |
| @@ -177,6 +207,8 @@ Rect.prototype.inside = function(x, y) { |
| * Draws the image in context with appropriate scaling. |
| */ |
| Rect.drawImage = function(context, image, dstRect, srcRect) { |
| + dstRect = dstRect || new Rect(context.canvas); |
|
SeRya
2011/08/08 13:26:44
Shouldn't it be dstRect_opt ans srcRect_opt?
Vladislav Kaznacheev
2011/08/08 13:47:51
Done.
|
| + srcRect = srcRect || new Rect(image); |
| context.drawImage(image, |
| srcRect.left, srcRect.top, srcRect.width, srcRect.height, |
| dstRect.left, dstRect.top, dstRect.width, dstRect.height); |
| @@ -223,7 +255,7 @@ function Circle(x, y, R) { |
| this.x = x; |
| this.y = y; |
| this.squaredR = R * R; |
| -}; |
| +} |
| Circle.prototype.inside = function(x, y) { |
| x -= this.x; |