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

Side by Side Diff: chrome/browser/resources/file_manager/js/image_editor/image_buffer.js

Issue 7552035: Adding simple filters to ChromeOS Image Editor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * The ImageBuffer object holds an offscreen canvas object and 6 * The ImageBuffer object holds an offscreen canvas object and
7 * draws its content on the screen canvas applying scale and offset. 7 * draws its content on the screen canvas applying scale and offset.
8 * Supports pluggable overlays that modify the image appearance and behavior. 8 * Supports pluggable overlays that modify the image appearance and behavior.
9 * @constructor 9 * @constructor
10 */ 10 */
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // Draw below everything including the content. 184 // Draw below everything including the content.
185 ImageBuffer.Margin.prototype.getZIndex = function() { return -2 }; 185 ImageBuffer.Margin.prototype.getZIndex = function() { return -2 };
186 186
187 ImageBuffer.Margin.prototype.draw = function(context) { 187 ImageBuffer.Margin.prototype.draw = function(context) {
188 context.save(); 188 context.save();
189 context.fillStyle = '#F0F0F0'; 189 context.fillStyle = '#F0F0F0';
190 context.strokeStyle = '#000000'; 190 context.strokeStyle = '#000000';
191 Rect.fillBetween(context, 191 Rect.fillBetween(context,
192 this.viewport_.getImageBoundsOnScreen(), 192 this.viewport_.getImageBoundsOnScreen(),
193 this.viewport_.getScreenBounds()); 193 this.viewport_.getScreenBounds());
194 Rect.stroke(context, this.viewport_.getImageBoundsOnScreen()); 194
195 Rect.outline(context, this.viewport_.getImageBoundsOnScreen());
195 context.restore(); 196 context.restore();
196 }; 197 };
197 198
198 /** 199 /**
199 * The overlay containing the image. 200 * The overlay containing the image.
200 */ 201 */
201 ImageBuffer.Content = function(viewport, document) { 202 ImageBuffer.Content = function(viewport, document) {
202 this.viewport_ = viewport; 203 this.viewport_ = viewport;
203 this.document_ = document; 204 this.document_ = document;
204 205
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 ImageBuffer.Overview.RIGHT = 7; 336 ImageBuffer.Overview.RIGHT = 7;
336 ImageBuffer.Overview.BOTTOM = 50; 337 ImageBuffer.Overview.BOTTOM = 50;
337 338
338 ImageBuffer.Overview.prototype.update = function() { 339 ImageBuffer.Overview.prototype.update = function() {
339 var imageBounds = this.viewport_.getImageBounds(); 340 var imageBounds = this.viewport_.getImageBounds();
340 341
341 if (this.contentGeneration_ != this.content_.getCacheGeneration()) { 342 if (this.contentGeneration_ != this.content_.getCacheGeneration()) {
342 this.contentGeneration_ = this.content_.getCacheGeneration(); 343 this.contentGeneration_ = this.content_.getCacheGeneration();
343 344
344 var aspect = imageBounds.width / imageBounds.height; 345 var aspect = imageBounds.width / imageBounds.height;
345 if (aspect > 1) {
346 this.bounds_ = new Rect(ImageBuffer.Overview.MAX_SIZE,
347 ImageBuffer.Overview.MAX_SIZE / aspect);
348 } else {
349 this.bounds_ = new Rect(ImageBuffer.Overview.MAX_SIZE * aspect,
350 ImageBuffer.Overview.MAX_SIZE);
351 }
352 346
353 this.canvas_ = 347 this.canvas_ = this.content_.copyCanvas(
354 this.content_.copyCanvas(this.bounds_.width, this.bounds_.height); 348 ImageBuffer.Overview.MAX_SIZE * Math.min(aspect, 1),
349 ImageBuffer.Overview.MAX_SIZE / Math.max(aspect, 1));
355 } 350 }
356 351
352 this.bounds_ = null;
357 this.clipped_ = null; 353 this.clipped_ = null;
358 354
359 if (this.viewport_.isClipped()) { 355 if (this.viewport_.isClipped()) {
360 var screenBounds = this.viewport_.getScreenBounds(); 356 var screenBounds = this.viewport_.getScreenBounds();
361 357
362 this.bounds_ = this.bounds_.moveTo( 358 this.bounds_ = new Rect(
363 screenBounds.width - ImageBuffer.Overview.RIGHT - this.bounds_.width, 359 screenBounds.width - ImageBuffer.Overview.RIGHT - this.canvas_.width,
364 screenBounds.height - ImageBuffer.Overview.BOTTOM - 360 screenBounds.height - ImageBuffer.Overview.BOTTOM - this.canvas_.height,
365 this.bounds_.height); 361 this.canvas_.width,
362 this.canvas_.height);
366 363
367 this.scale_ = this.bounds_.width / imageBounds.width; 364 this.scale_ = this.bounds_.width / imageBounds.width;
368 365
369 this.clipped_ = this.viewport_.getImageClipped(). 366 this.clipped_ = this.viewport_.getImageClipped().
370 scale(this.scale_). 367 scale(this.scale_).
371 shift(this.bounds_.left, this.bounds_.top); 368 shift(this.bounds_.left, this.bounds_.top);
372 } 369 }
373 }; 370 };
374 371
375 ImageBuffer.Overview.prototype.draw = function(context) { 372 ImageBuffer.Overview.prototype.draw = function(context) {
376 this.update(); 373 this.update();
377 374
378 if (!this.clipped_) return; 375 if (!this.clipped_) return;
379 376
380 // Draw the thumbnail. 377 // Draw the thumbnail.
381 Rect.drawImage(context, this.canvas_, this.bounds_); 378 Rect.drawImage(context, this.canvas_, this.bounds_);
382 379
383 // Draw the thumbnail border.
384 context.strokeStyle = '#000000';
385 Rect.stroke(context, this.bounds_);
386
387 // Draw the shadow over the off-screen part of the thumbnail. 380 // Draw the shadow over the off-screen part of the thumbnail.
388 context.globalAlpha = 0.3; 381 context.globalAlpha = 0.3;
389 context.fillStyle = '#000000'; 382 context.fillStyle = '#000000';
390 Rect.fillBetween(context, this.clipped_, this.bounds_); 383 Rect.fillBetween(context, this.clipped_, this.bounds_);
391 384
392 // Outline the on-screen part of the thumbnail. 385 // Outline the on-screen part of the thumbnail.
393 context.strokeStyle = '#FFFFFF'; 386 context.strokeStyle = '#FFFFFF';
394 Rect.stroke(context, this.clipped_); 387 Rect.outline(context, this.clipped_);
388
389 context.globalAlpha = 1;
390 // Draw the thumbnail border.
391 context.strokeStyle = '#000000';
392 Rect.outline(context, this.bounds_);
395 }; 393 };
396 394
397 ImageBuffer.Overview.prototype.getCursorStyle = function(x, y) { 395 ImageBuffer.Overview.prototype.getCursorStyle = function(x, y) {
398 if (!this.bounds_ || !this.bounds_.inside(x, y)) return null; 396 if (!this.bounds_ || !this.bounds_.inside(x, y)) return null;
399 397
400 // Indicate that the on-screen part is draggable. 398 // Indicate that the on-screen part is draggable.
401 if (this.clipped_.inside(x, y)) return 'move'; 399 if (this.clipped_ && this.clipped_.inside(x, y)) return 'move';
402 400
403 // Indicate that the rest of the thumbnail is clickable. 401 // Indicate that the rest of the thumbnail is clickable.
404 return 'crosshair'; 402 return 'crosshair';
405 }; 403 };
406 404
407 ImageBuffer.Overview.prototype.onClick = function(x, y) { 405 ImageBuffer.Overview.prototype.onClick = function(x, y) {
408 if (this.getCursorStyle(x, y) != 'crosshair') return false; 406 if (this.getCursorStyle(x, y) != 'crosshair') return false;
409 this.viewport_.setCenter( 407 this.viewport_.setCenter(
410 (x - this.bounds_.left) / this.scale_, 408 (x - this.bounds_.left) / this.scale_,
411 (y - this.bounds_.top) / this.scale_); 409 (y - this.bounds_.top) / this.scale_);
412 this.viewport_.repaint(); 410 this.viewport_.repaint();
413 return true; 411 return true;
414 }; 412 };
415 413
416 ImageBuffer.Overview.prototype.getDragHandler = function(x, y) { 414 ImageBuffer.Overview.prototype.getDragHandler = function(x, y) {
417 var cursor = this.getCursorStyle(x, y); 415 var cursor = this.getCursorStyle(x, y);
418 416
419 if (cursor == 'move') { 417 if (cursor == 'move') {
420 var self = this; 418 var self = this;
421 function scale() { return -self.scale_;} 419 function scale() { return -self.scale_;}
422 function hit(x, y) { return self.bounds_ && self.bounds_.inside(x, y); } 420 function hit(x, y) { return self.bounds_ && self.bounds_.inside(x, y); }
423 return this.viewport_.createOffsetSetter(x, y, scale, hit); 421 return this.viewport_.createOffsetSetter(x, y, scale, hit);
424 } else if (cursor == 'crosshair') { 422 } else if (cursor == 'crosshair') {
425 // Force non-draggable behavior. 423 // Force non-draggable behavior.
426 return function() {}; 424 return function() {};
427 } else { 425 } else {
428 return null; 426 return null;
429 } 427 }
430 }; 428 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698