Commit efa531fe authored by hirono@chromium.org's avatar hirono@chromium.org

Remove repaint callbacks from Viewport.

To focus geometory calculation, remove the role other than caculation from the
Viewport class.

BUG=245926
TEST=manually

Review URL: https://codereview.chromium.org/382143004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282602 0039d316-1c4b-4281-b951-d872f2087c98
parent f31bc463
...@@ -133,7 +133,7 @@ ImageBuffer.Overlay = function() {}; ...@@ -133,7 +133,7 @@ ImageBuffer.Overlay = function() {};
* TODO(JSDOC). * TODO(JSDOC).
* @return {number} // TODO(JSDOC). * @return {number} // TODO(JSDOC).
*/ */
ImageBuffer.Overlay.prototype.getZIndex = function() { return 0 }; ImageBuffer.Overlay.prototype.getZIndex = function() { return 0; };
/** /**
* TODO(JSDOC). * TODO(JSDOC).
......
...@@ -29,21 +29,17 @@ function ImageEditor( ...@@ -29,21 +29,17 @@ function ImageEditor(
ImageUtil.removeChildren(this.container_); ImageUtil.removeChildren(this.container_);
var document = this.container_.ownerDocument;
this.viewport_ = viewport; this.viewport_ = viewport;
this.viewport_.sizeByFrame(this.container_); this.viewport_.sizeByFrame(this.container_);
this.buffer_ = new ImageBuffer();
this.viewport_.addRepaintCallback(this.buffer_.draw.bind(this.buffer_));
this.imageView_ = imageView; this.imageView_ = imageView;
this.imageView_.addContentCallback(this.onContentUpdate_.bind(this)); this.imageView_.addContentCallback(this.onContentUpdate_.bind(this));
this.buffer_ = new ImageBuffer();
this.buffer_.addOverlay(this.imageView_); this.buffer_.addOverlay(this.imageView_);
this.panControl_ = new ImageEditor.MouseControl( this.panControl_ = new ImageEditor.MouseControl(
this.rootContainer_, this.container_, this.getBuffer()); this.rootContainer_, this.container_, this.getBuffer());
this.panControl_.setDoubleTapCallback(this.onDoubleTap_.bind(this)); this.panControl_.setDoubleTapCallback(this.onDoubleTap_.bind(this));
this.mainToolbar_ = new ImageEditor.Toolbar( this.mainToolbar_ = new ImageEditor.Toolbar(
......
...@@ -10,8 +10,11 @@ ...@@ -10,8 +10,11 @@
* @param {HTMLElement} container The container element. * @param {HTMLElement} container The container element.
* @param {Viewport} viewport The viewport. * @param {Viewport} viewport The viewport.
* @constructor * @constructor
* @extends {ImageBuffer.Overlay}
*/ */
function ImageView(container, viewport) { function ImageView(container, viewport) {
ImageBuffer.Overlay.call(this);
this.container_ = container; this.container_ = container;
this.viewport_ = viewport; this.viewport_ = viewport;
this.document_ = container.ownerDocument; this.document_ = container.ownerDocument;
...@@ -89,13 +92,12 @@ ImageView.LOAD_TYPE_TOTAL = 5; ...@@ -89,13 +92,12 @@ ImageView.LOAD_TYPE_TOTAL = 5;
ImageView.prototype = {__proto__: ImageBuffer.Overlay.prototype}; ImageView.prototype = {__proto__: ImageBuffer.Overlay.prototype};
/** /**
* Draws below overlays with the default zIndex. * @override
* @return {number} Z-index.
*/ */
ImageView.prototype.getZIndex = function() { return -1; }; ImageView.prototype.getZIndex = function() { return -1; };
/** /**
* Draws the image on screen. * @override
*/ */
ImageView.prototype.draw = function() { ImageView.prototype.draw = function() {
if (!this.contentCanvas_) // Do nothing if the image content is not set. if (!this.contentCanvas_) // Do nothing if the image content is not set.
...@@ -123,36 +125,6 @@ ImageView.prototype.draw = function() { ...@@ -123,36 +125,6 @@ ImageView.prototype.draw = function() {
} }
}; };
/**
* @param {number} x X pointer position.
* @param {number} y Y pointer position.
* @param {boolean} mouseDown True if mouse is down.
* @return {string} CSS cursor style.
*/
ImageView.prototype.getCursorStyle = function(x, y, mouseDown) {
// Indicate that the image is draggable.
if (this.viewport_.isClipped() &&
this.viewport_.getScreenClipped().inside(x, y))
return 'move';
return null;
};
/**
* @param {number} x X pointer position.
* @param {number} y Y pointer position.
* @return {function} The closure to call on drag.
*/
ImageView.prototype.getDragHandler = function(x, y) {
var cursor = this.getCursorStyle(x, y);
if (cursor === 'move') {
// Return the handler that drags the entire image.
return this.viewport_.createOffsetSetter(x, y);
}
return null;
};
/** /**
* @return {number} The cache generation. * @return {number} The cache generation.
*/ */
......
...@@ -35,7 +35,6 @@ function Viewport() { ...@@ -35,7 +35,6 @@ function Viewport() {
this.generation_ = 0; this.generation_ = 0;
this.repaintCallbacks_ = [];
this.update(); this.update();
} }
...@@ -154,41 +153,6 @@ Viewport.prototype.setOffset = function(x, y, ignoreClipping) { ...@@ -154,41 +153,6 @@ Viewport.prototype.setOffset = function(x, y, ignoreClipping) {
this.invalidateCaches(); this.invalidateCaches();
}; };
/**
* Return a closure that can be called to pan the image.
* Useful for implementing non-trivial variants of panning (overview etc).
* @param {number} originalX The x coordinate on the screen canvas that
* corresponds to zero change to offsetX.
* @param {number} originalY The y coordinate on the screen canvas that
* corresponds to zero change to offsetY.
* @param {function():number} scaleFunc returns the image to screen scale.
* @param {function(number,number):boolean} hitFunc returns true if (x,y) is
* in the valid region.
* @return {function} The closure to pan the image.
*/
Viewport.prototype.createOffsetSetter = function(
originalX, originalY, scaleFunc, hitFunc) {
var originalOffsetX = this.offsetX_;
var originalOffsetY = this.offsetY_;
if (!hitFunc) hitFunc = function() { return true; };
if (!scaleFunc) scaleFunc = this.getScale.bind(this);
var self = this;
return function(x, y) {
if (hitFunc(x, y)) {
var scale = scaleFunc();
self.setOffset(
originalOffsetX + (x - originalX) / scale,
originalOffsetY + (y - originalY) / scale);
self.repaint();
}
};
};
/*
* Access to the current viewport state.
*/
/** /**
* @return {Rect} The image bounds in image coordinates. * @return {Rect} The image bounds in image coordinates.
*/ */
...@@ -220,7 +184,7 @@ Viewport.prototype.getScreenClipped = function() { ...@@ -220,7 +184,7 @@ Viewport.prototype.getScreenClipped = function() {
Viewport.prototype.getCacheGeneration = function() { return this.generation_; }; Viewport.prototype.getCacheGeneration = function() { return this.generation_; };
/** /**
* Called on event view port state change (even if repaint has not been called). * Called on event view port state change.
*/ */
Viewport.prototype.invalidateCaches = function() { this.generation_++; }; Viewport.prototype.invalidateCaches = function() { this.generation_++; };
...@@ -231,10 +195,6 @@ Viewport.prototype.getImageBoundsOnScreen = function() { ...@@ -231,10 +195,6 @@ Viewport.prototype.getImageBoundsOnScreen = function() {
return this.imageOnScreen_; return this.imageOnScreen_;
}; };
/*
* Conversion between the screen and image coordinate spaces.
*/
/** /**
* @param {number} size Size in screen coordinates. * @param {number} size Size in screen coordinates.
* @return {number} Size in image coordinates. * @return {number} Size in image coordinates.
...@@ -423,22 +383,6 @@ Viewport.prototype.update = function() { ...@@ -423,22 +383,6 @@ Viewport.prototype.update = function() {
} }
}; };
/**
* @param {function} callback Repaint callback.
*/
Viewport.prototype.addRepaintCallback = function(callback) {
this.repaintCallbacks_.push(callback);
};
/**
* Repaint all clients.
*/
Viewport.prototype.repaint = function() {
this.update();
for (var i = 0; i != this.repaintCallbacks_.length; i++)
this.repaintCallbacks_[i]();
};
/** /**
* Obtains CSS transformation for the screen image. * Obtains CSS transformation for the screen image.
* @return {string} Transformation description. * @return {string} Transformation description.
......
...@@ -82,7 +82,7 @@ SlideMode.prototype.getTitle = function() { return 'GALLERY_SLIDE'; }; ...@@ -82,7 +82,7 @@ SlideMode.prototype.getTitle = function() { return 'GALLERY_SLIDE'; };
* @private * @private
*/ */
SlideMode.prototype.initListeners_ = function() { SlideMode.prototype.initListeners_ = function() {
window.addEventListener('resize', this.onResize_.bind(this), false); window.addEventListener('resize', this.onResize_.bind(this));
}; };
/** /**
...@@ -868,7 +868,8 @@ SlideMode.prototype.onKeyDown = function(event) { ...@@ -868,7 +868,8 @@ SlideMode.prototype.onKeyDown = function(event) {
*/ */
SlideMode.prototype.onResize_ = function() { SlideMode.prototype.onResize_ = function() {
this.viewport_.sizeByFrameAndFit(this.container_); this.viewport_.sizeByFrameAndFit(this.container_);
this.viewport_.repaint(); this.viewport_.update();
this.editor_.getBuffer().draw();
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment