| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 goog.provide('image.collections.extension.DocumentImage'); | 5 goog.provide('image.collections.extension.domextractor.DocumentImage'); |
| 6 | 6 |
| 7 goog.require('goog.asserts'); | 7 goog.require('image.collections.extension.domextractor.DocumentFeature'); |
| 8 goog.require('image.collections.extension.DocumentFeature'); | 8 goog.require('image.collections.extension.domextractor.DomUtils'); |
| 9 | 9 |
| 10 goog.scope(function() { | 10 goog.scope(function() { |
| 11 var DocumentFeature = image.collections.extension.DocumentFeature; | 11 var DocumentFeature = image.collections.extension.domextractor.DocumentFeature; |
| 12 | 12 |
| 13 | 13 |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * A class representing a salient image in an HTML document. | 16 * A class representing a salient image in an HTML document. |
| 17 * @param {number} relevance | 17 * @param {number} relevance |
| 18 * @param {string} url | 18 * @param {string} url |
| 19 * @param {!goog.math.Size=} opt_size Natural size of image or null if image | 19 * @param {!image.collections.extension.domextractor.Size=} opt_size Natural |
| 20 * size is not available in the DOM tree. | 20 * size of image or undefined if image size is not available in the DOM |
| 21 * @param {!goog.math.Size=} opt_displaySize Size at which the image is being | 21 * tree. |
| 22 * shown. One of opt_size or opt_displaySize MUST be specified. | 22 * @param {!image.collections.extension.domextractor.Size=} opt_displaySize Size |
| 23 * at which the image is being shown. One of opt_size or opt_displaySize |
| 24 * MUST be specified. |
| 23 * @extends {DocumentFeature} | 25 * @extends {DocumentFeature} |
| 24 * @constructor | 26 * @constructor |
| 27 * @suppress {undefinedNames} |
| 25 */ | 28 */ |
| 26 image.collections.extension.DocumentImage = function( | 29 image.collections.extension.domextractor.DocumentImage = function( |
| 27 relevance, url, opt_size, opt_displaySize) { | 30 relevance, url, opt_size, opt_displaySize) { |
| 28 DocumentImage.base(this, 'constructor', relevance); | 31 DocumentImage.base(this, 'constructor', relevance); |
| 29 | 32 |
| 30 /** @private {string} Absolute image url. */ | 33 /** @private {string} Absolute image url. */ |
| 31 this.url_ = url; | 34 this.url_ = url; |
| 32 | 35 |
| 33 /** @private {!goog.math.Size|undefined} Image resolution in pixels. */ | 36 /** |
| 37 * @private {!image.collections.extension.domextractor.Size|undefined} Image |
| 38 * resolution in pixels. |
| 39 */ |
| 34 this.size_ = opt_size; | 40 this.size_ = opt_size; |
| 35 | 41 |
| 36 /** @private {!goog.math.Size|undefined} Displayed image resolution | 42 /** |
| 37 * in pixels. | 43 * @private {!image.collections.extension.domextractor.Size|undefined} |
| 44 * Displayed image resolution in pixels. |
| 38 */ | 45 */ |
| 39 this.displaySize_ = opt_displaySize; | 46 this.displaySize_ = opt_displaySize; |
| 40 | |
| 41 goog.asserts.assert(goog.isDef(opt_size) || goog.isDef(opt_displaySize)); | |
| 42 }; | 47 }; |
| 43 goog.inherits(image.collections.extension.DocumentImage, DocumentFeature); | 48 image.collections.extension.domextractor.DomUtils.inherits( |
| 44 var DocumentImage = image.collections.extension.DocumentImage; | 49 image.collections.extension.domextractor.DocumentImage, DocumentFeature); |
| 50 var DocumentImage = image.collections.extension.domextractor.DocumentImage; |
| 45 | 51 |
| 46 | 52 |
| 47 /** | 53 /** |
| 48 * These attributes needs to be set for images defined in <meta> and <link> | 54 * These attributes needs to be set for images defined in <meta> and <link> |
| 49 * elements (e.g. OpenGraph images) so that they can be used as salient image | 55 * elements (e.g. OpenGraph images) so that they can be used as salient image |
| 50 * candidates. They are computed by the DomController class. | 56 * candidates. They are computed by the DomController class. |
| 51 * @enum {string} | 57 * @enum {string} |
| 52 */ | 58 */ |
| 53 DocumentImage.CustomAttribute = { | 59 DocumentImage.CustomAttribute = { |
| 54 WIDTH: 'data-google-stars-image-width', | 60 WIDTH: 'data-google-stars-image-width', |
| 55 HEIGHT: 'data-google-stars-image-height' | 61 HEIGHT: 'data-google-stars-image-height' |
| 56 }; | 62 }; |
| 57 | 63 |
| 58 | 64 |
| 59 /** | 65 /** |
| 60 * Returns the absolute image url. | 66 * Returns the absolute image url. |
| 61 * @return {string} | 67 * @return {string} |
| 62 */ | 68 */ |
| 63 DocumentImage.prototype.getUrl = function() { | 69 DocumentImage.prototype.getUrl = function() { |
| 64 return this.url_; | 70 return this.url_; |
| 65 }; | 71 }; |
| 66 | 72 |
| 67 | 73 |
| 68 /** | 74 /** |
| 69 * Returns the image resolution in pixels. | 75 * Returns the image resolution in pixels. |
| 70 * @return {!goog.math.Size|undefined} | 76 * @return {!image.collections.extension.domextractor.Size|undefined} |
| 71 */ | 77 */ |
| 72 DocumentImage.prototype.getSize = function() { | 78 DocumentImage.prototype.getSize = function() { |
| 73 return this.size_; | 79 return this.size_; |
| 74 }; | 80 }; |
| 75 | 81 |
| 76 | 82 |
| 77 /** | 83 /** |
| 78 * Returns the shown image resolution in pixels. | 84 * Returns the shown image resolution in pixels. |
| 79 * @return {!goog.math.Size|undefined} | 85 * @return {!image.collections.extension.domextractor.Size|undefined} |
| 80 */ | 86 */ |
| 81 DocumentImage.prototype.getDisplaySize = function() { | 87 DocumentImage.prototype.getDisplaySize = function() { |
| 82 return this.displaySize_; | 88 return this.displaySize_; |
| 83 }; | 89 }; |
| 84 }); // goog.scope | 90 }); // goog.scope |
| OLD | NEW |