Chromium Code Reviews
  | 
| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * Base class to represent a "view". A view is an absolutely positioned box on | |
| 7 * the page. | |
| 8 * | |
| 9 * @constructor | |
| 10 */ | |
| 11 function View() { | |
| 
 
arv (Not doing code reviews)
2010/11/24 19:07:38
Is this a copy from net internals? We should never
 
 | |
| 12 this.isVisible_ = true; | |
| 13 } | |
| 14 | |
| 15 /** | |
| 16 * Called to reposition the view on the page. Measurements are in pixels. | |
| 17 */ | |
| 18 View.prototype.setGeometry = function(left, top, width, height) { | |
| 19 this.left_ = left; | |
| 20 this.top_ = top; | |
| 21 this.width_ = width; | |
| 22 this.height_ = height; | |
| 23 }; | |
| 24 | |
| 25 /** | |
| 26 * Called to show/hide the view. | |
| 27 */ | |
| 28 View.prototype.show = function(isVisible) { | |
| 
 
arv (Not doing code reviews)
2010/11/24 19:07:38
visible setter
 
 | |
| 29 this.isVisible_ = isVisible; | |
| 30 }; | |
| 31 | |
| 32 View.prototype.isVisible = function() { | |
| 33 return this.isVisible_; | |
| 34 }; | |
| 35 | |
| 36 View.prototype.getLeft = function() { | |
| 
 
arv (Not doing code reviews)
2010/11/24 19:07:38
use getters or read only value properties
 
 | |
| 37 return this.left_; | |
| 38 }; | |
| 39 | |
| 40 View.prototype.getTop = function() { | |
| 41 return this.top_; | |
| 42 }; | |
| 43 | |
| 44 View.prototype.getWidth = function() { | |
| 45 return this.width_; | |
| 46 }; | |
| 47 | |
| 48 View.prototype.getHeight = function() { | |
| 49 return this.height_; | |
| 50 }; | |
| 51 | |
| 52 View.prototype.getRight = function() { | |
| 53 return this.getLeft() + this.getWidth(); | |
| 54 }; | |
| 55 | |
| 56 View.prototype.getBottom = function() { | |
| 57 return this.getTop() + this.getHeight(); | |
| 58 }; | |
| 59 | |
| 60 | |
| 61 //----------------------------------------------------------------------------- | |
| 62 | |
| 63 /** | |
| 64 * DivView is an implementation of View that wraps a DIV. | |
| 65 * | |
| 66 * @constructor | |
| 67 */ | |
| 68 function DivView(divId) { | |
| 69 View.call(this); | |
| 70 | |
| 71 this.node_ = document.getElementById(divId); | |
| 
 
arv (Not doing code reviews)
2010/11/24 19:07:38
Make this extend HTMLElement instead so that you d
 
 | |
| 72 | |
| 73 // Initialize the default values to those of the DIV. | |
| 74 this.width_ = this.node_.offsetWidth; | |
| 75 this.height_ = this.node_.offsetHeight; | |
| 76 this.isVisible_ = this.node_.style.display != 'none'; | |
| 77 } | |
| 78 | |
| 79 inherits(DivView, View); | |
| 80 | |
| 81 DivView.prototype.setGeometry = function(left, top, width, height) { | |
| 82 DivView.superClass_.setGeometry.call(this, left, top, width, height); | |
| 83 | |
| 84 this.node_.style.position = "absolute"; | |
| 
 
arv (Not doing code reviews)
2010/11/24 19:07:38
move to css
 
arv (Not doing code reviews)
2010/11/24 19:07:38
It seems like you are using abs pos to do the layo
 
 | |
| 85 setNodePosition(this.node_, left, top, width, height); | |
| 86 }; | |
| 87 | |
| 88 DivView.prototype.show = function(isVisible) { | |
| 89 DivView.superClass_.show.call(this, isVisible); | |
| 90 setNodeDisplay(this.node_, isVisible); | |
| 91 }; | |
| 92 | |
| 93 /** | |
| 94 * Returns the wrapped DIV | |
| 95 */ | |
| 96 DivView.prototype.getNode = function() { | |
| 97 return this.node_; | |
| 98 }; | |
| 99 | |
| 100 //----------------------------------------------------------------------------- | |
| 101 | |
| 102 /** | |
| 103 * Implementation of View that sizes its child to fit the entire window. | |
| 104 * | |
| 105 * @param {!View} childView | |
| 106 * | |
| 107 * @constructor | |
| 108 */ | |
| 109 function WindowView(childView) { | |
| 110 View.call(this); | |
| 111 this.childView_ = childView; | |
| 112 window.addEventListener("resize", this.resetGeometry.bind(this), true); | |
| 113 } | |
| 114 | |
| 115 inherits(WindowView, View); | |
| 116 | |
| 117 WindowView.prototype.setGeometry = function(left, top, width, height) { | |
| 118 WindowView.superClass_.setGeometry.call(this, left, top, width, height); | |
| 119 this.childView_.setGeometry(left, top, width, height); | |
| 120 }; | |
| 121 | |
| 122 WindowView.prototype.show = function() { | |
| 123 WindowView.superClass_.show.call(this, isVisible); | |
| 124 this.childView_.show(isVisible); | |
| 125 }; | |
| 126 | |
| 127 WindowView.prototype.resetGeometry = function() { | |
| 128 this.setGeometry(0, 0, window.innerWidth, window.innerHeight); | |
| 129 }; | |
| 130 | |
| OLD | NEW |