1 // Copyright (c) 2012 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.
6 * Base class to represent a "view". A view is an absolutely positioned box on
9 var View = (function() {
16 this.isVisible_ = true;
21 * Called to reposition the view on the page. Measurements are in pixels.
23 setGeometry: function(left, top, width, height) {
27 this.height_ = height;
31 * Called to show/hide the view.
33 show: function(isVisible) {
34 this.isVisible_ = isVisible;
37 isVisible: function() {
38 return this.isVisible_;
42 * Method of the observer class.
44 * Called to check if an observer needs the data it is
45 * observing to be actively updated.
47 isActive: function() {
48 return this.isVisible();
59 getWidth: function() {
63 getHeight: function() {
67 getRight: function() {
68 return this.getLeft() + this.getWidth();
71 getBottom: function() {
72 return this.getTop() + this.getHeight();
75 setParameters: function(params) {},
78 * Called when loading a log file, after clearing all events, but before
79 * loading the new ones. |polledData| contains the data from all
80 * PollableData helpers. |tabData| contains the data for the particular
81 * tab. |logDump| is the entire log dump, which includes the other two
82 * values. It's included separately so most views don't have to depend on
85 onLoadLogStart: function(polledData, tabData, logDump) {
89 * Called as the final step of loading a log file. Arguments are the same
90 * as onLoadLogStart. Returns true to indicate the tab should be shown,
93 onLoadLogFinish: function(polledData, tabData, logDump) {
101 //-----------------------------------------------------------------------------
104 * DivView is an implementation of View that wraps a DIV.
106 var DivView = (function() {
109 // We inherit from View.
110 var superClass = View;
115 function DivView(divId) {
116 // Call superclass's constructor.
117 superClass.call(this);
119 this.node_ = $(divId);
121 throw new Error('Element ' + divId + ' not found');
123 // Initialize the default values to those of the DIV.
124 this.width_ = this.node_.offsetWidth;
125 this.height_ = this.node_.offsetHeight;
126 this.isVisible_ = this.node_.style.display != 'none';
129 DivView.prototype = {
130 // Inherit the superclass's methods.
131 __proto__: superClass.prototype,
133 setGeometry: function(left, top, width, height) {
134 superClass.prototype.setGeometry.call(this, left, top, width, height);
136 this.node_.style.position = 'absolute';
137 setNodePosition(this.node_, left, top, width, height);
140 show: function(isVisible) {
141 superClass.prototype.show.call(this, isVisible);
142 setNodeDisplay(this.node_, isVisible);
146 * Returns the wrapped DIV
148 getNode: function() {
157 //-----------------------------------------------------------------------------
160 * Implementation of View that sizes its child to fit the entire window.
162 * @param {!View} childView The child view.
164 var WindowView = (function() {
167 // We inherit from View.
168 var superClass = View;
173 function WindowView(childView) {
174 // Call superclass's constructor.
175 superClass.call(this);
177 this.childView_ = childView;
178 window.addEventListener('resize', this.resetGeometry.bind(this), true);
181 WindowView.prototype = {
182 // Inherit the superclass's methods.
183 __proto__: superClass.prototype,
185 setGeometry: function(left, top, width, height) {
186 superClass.prototype.setGeometry.call(this, left, top, width, height);
187 this.childView_.setGeometry(left, top, width, height);
191 superClass.prototype.show.call(this, isVisible);
192 this.childView_.show(isVisible);
195 resetGeometry: function() {
196 this.setGeometry(0, 0, window.innerWidth, window.innerHeight);
204 * View that positions two views vertically. The top view should be
205 * fixed-height, and the bottom view will fill the remainder of the space.
207 * +-----------------------------------+
209 * +-----------------------------------+
218 * +-----------------------------------+
220 var VerticalSplitView = (function() {
223 // We inherit from View.
224 var superClass = View;
227 * @param {!View} topView The top view.
228 * @param {!View} bottomView The bottom view.
231 function VerticalSplitView(topView, bottomView) {
232 // Call superclass's constructor.
233 superClass.call(this);
235 this.topView_ = topView;
236 this.bottomView_ = bottomView;
239 VerticalSplitView.prototype = {
240 // Inherit the superclass's methods.
241 __proto__: superClass.prototype,
243 setGeometry: function(left, top, width, height) {
244 superClass.prototype.setGeometry.call(this, left, top, width, height);
246 var fixedHeight = this.topView_.getHeight();
247 this.topView_.setGeometry(left, top, width, fixedHeight);
249 this.bottomView_.setGeometry(
250 left, top + fixedHeight, width, height - fixedHeight);
253 show: function(isVisible) {
254 superClass.prototype.show.call(this, isVisible);
256 this.topView_.show(isVisible);
257 this.bottomView_.show(isVisible);
261 return VerticalSplitView;
265 * View that positions two views horizontally. The left view should be
266 * fixed-width, and the right view will fill the remainder of the space.
268 * +----------+--------------------------+
272 * | leftView | rightView |
280 * +----------+--------------------------+
282 var HorizontalSplitView = (function() {
285 // We inherit from View.
286 var superClass = View;
289 * @param {!View} leftView The left view.
290 * @param {!View} rightView The right view.
293 function HorizontalSplitView(leftView, rightView) {
294 // Call superclass's constructor.
295 superClass.call(this);
297 this.leftView_ = leftView;
298 this.rightView_ = rightView;
301 HorizontalSplitView.prototype = {
302 // Inherit the superclass's methods.
303 __proto__: superClass.prototype,
305 setGeometry: function(left, top, width, height) {
306 superClass.prototype.setGeometry.call(this, left, top, width, height);
308 var fixedWidth = this.leftView_.getWidth();
309 this.leftView_.setGeometry(left, top, fixedWidth, height);
311 this.rightView_.setGeometry(
312 left + fixedWidth, top, width - fixedWidth, height);
315 show: function(isVisible) {
316 superClass.prototype.show.call(this, isVisible);
318 this.leftView_.show(isVisible);
319 this.rightView_.show(isVisible);
323 return HorizontalSplitView;