diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-03 19:56:04 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-03 19:56:04 +0000 |
commit | d1d21c42e7d2d353feb13e9d02f03e92fcd5a8b6 (patch) | |
tree | 6a3000f5f2cefb3a18a272a805a4c109438b1190 | |
parent | 4fee20d1672a52e59657120dc398e6aa89256670 (diff) | |
download | chromium_src-d1d21c42e7d2d353feb13e9d02f03e92fcd5a8b6.zip chromium_src-d1d21c42e7d2d353feb13e9d02f03e92fcd5a8b6.tar.gz chromium_src-d1d21c42e7d2d353feb13e9d02f03e92fcd5a8b6.tar.bz2 |
Refactor view.js to define it's classes inside an anonymous namespace.
BUG=90857
Review URL: http://codereview.chromium.org/7508028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95292 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/resources/net_internals/view.js | 375 |
1 files changed, 211 insertions, 164 deletions
diff --git a/chrome/browser/resources/net_internals/view.js b/chrome/browser/resources/net_internals/view.js index efc5431..4fd2fbb 100644 --- a/chrome/browser/resources/net_internals/view.js +++ b/chrome/browser/resources/net_internals/view.js @@ -5,127 +5,148 @@ /** * Base class to represent a "view". A view is an absolutely positioned box on * the page. - * - * @constructor - */ -function View() { - this.isVisible_ = true; -} - -/** - * Called to reposition the view on the page. Measurements are in pixels. - */ -View.prototype.setGeometry = function(left, top, width, height) { - this.left_ = left; - this.top_ = top; - this.width_ = width; - this.height_ = height; -}; - -/** - * Called to show/hide the view. - */ -View.prototype.show = function(isVisible) { - this.isVisible_ = isVisible; -}; - -View.prototype.isVisible = function() { - return this.isVisible_; -}; - -/** - * Method of the observer class. - * - * Called to check if an observer needs the data it is - * observing to be actively updated. */ -View.prototype.isActive = function() { - return this.isVisible(); -}; - -View.prototype.getLeft = function() { - return this.left_; -}; - -View.prototype.getTop = function() { - return this.top_; -}; - -View.prototype.getWidth = function() { - return this.width_; -}; - -View.prototype.getHeight = function() { - return this.height_; -}; - -View.prototype.getRight = function() { - return this.getLeft() + this.getWidth(); -}; - -View.prototype.getBottom = function() { - return this.getTop() + this.getHeight(); -}; - -View.prototype.setParameters = function(params) {}; - -/** - * Called when loading a log file, after clearing all events, but before - * loading the new ones. |polledData| contains the data from all - * PollableData helpers, and |tabData| contains the data for the particular tab. - */ -View.prototype.onLoadLogStart = function(polledData, tabData) { -}; - -/** - * Called as the final step of loading a log file. Arguments are the same as - * onLoadLogStart. Returns true to indicate the tab should be shown, false - * otherwise. - */ -View.prototype.onLoadLogFinish = function(polledData, tabData) { - return false; -}; +var View = (function() { + /** + * @constructor + */ + function View() { + this.isVisible_ = true; + } + + View.prototype = { + /** + * Called to reposition the view on the page. Measurements are in pixels. + */ + setGeometry: function(left, top, width, height) { + this.left_ = left; + this.top_ = top; + this.width_ = width; + this.height_ = height; + }, + + /** + * Called to show/hide the view. + */ + show: function(isVisible) { + this.isVisible_ = isVisible; + }, + + isVisible: function() { + return this.isVisible_; + }, + + /** + * Method of the observer class. + * + * Called to check if an observer needs the data it is + * observing to be actively updated. + */ + isActive: function() { + return this.isVisible(); + }, + + getLeft: function() { + return this.left_; + }, + + getTop: function() { + return this.top_; + }, + + getWidth: function() { + return this.width_; + }, + + getHeight: function() { + return this.height_; + }, + + getRight: function() { + return this.getLeft() + this.getWidth(); + }, + + getBottom: function() { + return this.getTop() + this.getHeight(); + }, + + setParameters: function(params) {}, + + /** + * Called when loading a log file, after clearing all events, but before + * loading the new ones. |polledData| contains the data from all + * PollableData helpers, and |tabData| contains the data for the particular + * tab. + */ + onLoadLogStart: function(polledData, tabData) { + }, + + /** + * Called as the final step of loading a log file. Arguments are the same + * as onLoadLogStart. Returns true to indicate the tab should be shown, + * false otherwise. + */ + onLoadLogFinish: function(polledData, tabData) { + return false; + } + }; + + return View; +})(); //----------------------------------------------------------------------------- /** * DivView is an implementation of View that wraps a DIV. - * - * @constructor */ -function DivView(divId) { - View.call(this); - - this.node_ = $(divId); - if (!this.node_) - throw new Error('Element ' + divId + ' not found'); - - // Initialize the default values to those of the DIV. - this.width_ = this.node_.offsetWidth; - this.height_ = this.node_.offsetHeight; - this.isVisible_ = this.node_.style.display != 'none'; -} - -inherits(DivView, View); - -DivView.prototype.setGeometry = function(left, top, width, height) { - DivView.superClass_.setGeometry.call(this, left, top, width, height); +var DivView = (function() { + // We inherit from View. + var superClass = View; + + /** + * @constructor + */ + function DivView(divId) { + // Call superclass's constructor. + superClass.call(this); + + this.node_ = $(divId); + if (!this.node_) + throw new Error('Element ' + divId + ' not found'); + + // Initialize the default values to those of the DIV. + this.width_ = this.node_.offsetWidth; + this.height_ = this.node_.offsetHeight; + this.isVisible_ = this.node_.style.display != 'none'; + } + + DivView.prototype = { + // Inherit the superclass's methods. + __proto__: superClass.prototype, + + setGeometry: function(left, top, width, height) { + superClass.prototype.setGeometry.call(this, left, top, width, height); + + this.node_.style.position = 'absolute'; + setNodePosition(this.node_, left, top, width, height); + }, + + show: function(isVisible) { + superClass.prototype.show.call(this, isVisible); + setNodeDisplay(this.node_, isVisible); + }, + + /** + * Returns the wrapped DIV + */ + getNode: function() { + return this.node_; + } + }; + + return DivView; +})(); - this.node_.style.position = 'absolute'; - setNodePosition(this.node_, left, top, width, height); -}; - -DivView.prototype.show = function(isVisible) { - DivView.superClass_.show.call(this, isVisible); - setNodeDisplay(this.node_, isVisible); -}; - -/** - * Returns the wrapped DIV - */ -DivView.prototype.getNode = function() { - return this.node_; -}; //----------------------------------------------------------------------------- @@ -133,30 +154,43 @@ DivView.prototype.getNode = function() { * Implementation of View that sizes its child to fit the entire window. * * @param {!View} childView - * - * @constructor */ -function WindowView(childView) { - View.call(this); - this.childView_ = childView; - window.addEventListener('resize', this.resetGeometry.bind(this), true); -} - -inherits(WindowView, View); - -WindowView.prototype.setGeometry = function(left, top, width, height) { - WindowView.superClass_.setGeometry.call(this, left, top, width, height); - this.childView_.setGeometry(left, top, width, height); -}; - -WindowView.prototype.show = function() { - WindowView.superClass_.show.call(this, isVisible); - this.childView_.show(isVisible); -}; - -WindowView.prototype.resetGeometry = function() { - this.setGeometry(0, 0, window.innerWidth, window.innerHeight); -}; +var WindowView = (function() { + // We inherit from View. + var superClass = View; + + /** + * @constructor + */ + function WindowView(childView) { + // Call superclass's constructor. + superClass.call(this); + + this.childView_ = childView; + window.addEventListener('resize', this.resetGeometry.bind(this), true); + } + + WindowView.prototype = { + // Inherit the superclass's methods. + __proto__: superClass.prototype, + + setGeometry: function(left, top, width, height) { + superClass.prototype.setGeometry.call(this, left, top, width, height); + this.childView_.setGeometry(left, top, width, height); + }, + + show: function() { + superClass.prototype.show.call(this, isVisible); + this.childView_.show(isVisible); + }, + + resetGeometry: function() { + this.setGeometry(0, 0, window.innerWidth, window.innerHeight); + } + }; + + return WindowView; +})(); /** * View that positions two views vertically. The top view should be @@ -174,32 +208,45 @@ WindowView.prototype.resetGeometry = function() { * | | * | | * +-----------------------------------+ - * - * @constructor */ -function VerticalSplitView(topView, bottomView) { - View.call(this); - - this.topView_ = topView; - this.bottomView_ = bottomView; -} - -inherits(VerticalSplitView, View); - -VerticalSplitView.prototype.setGeometry = function(left, top, width, height) { - VerticalSplitView.superClass_.setGeometry.call( - this, left, top, width, height); - - var fixedHeight = this.topView_.getHeight(); - this.topView_.setGeometry(left, top, width, fixedHeight); - - this.bottomView_.setGeometry( - left, top + fixedHeight, width, height - fixedHeight); -}; - -VerticalSplitView.prototype.show = function(isVisible) { - VerticalSplitView.superClass_.show.call(this, isVisible); - - this.topView_.show(isVisible); - this.bottomView_.show(isVisible); -}; +var VerticalSplitView = (function() { + // We inherit from View. + var superClass = View; + + /** + * @param {!View} topView + * @param {!View} bottomView + * @constructor + */ + function VerticalSplitView(topView, bottomView) { + // Call superclass's constructor. + superClass.call(this); + + this.topView_ = topView; + this.bottomView_ = bottomView; + } + + VerticalSplitView.prototype = { + // Inherit the superclass's methods. + __proto__: superClass.prototype, + + setGeometry: function(left, top, width, height) { + superClass.prototype.setGeometry.call(this, left, top, width, height); + + var fixedHeight = this.topView_.getHeight(); + this.topView_.setGeometry(left, top, width, fixedHeight); + + this.bottomView_.setGeometry( + left, top + fixedHeight, width, height - fixedHeight); + }, + + show: function(isVisible) { + superClass.prototype.show.call(this, isVisible); + + this.topView_.show(isVisible); + this.bottomView_.show(isVisible); + } + }; + + return VerticalSplitView; +})(); |