forked from catapult-project/catapult
-
Notifications
You must be signed in to change notification settings - Fork 0
/
top_mid_bottom_view.js
84 lines (73 loc) · 2.48 KB
/
top_mid_bottom_view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var TopMidBottomView = (function() {
'use strict';
// We inherit from View.
var superClass = View;
/**
* This view stacks three boxes -- one at the top, one at the bottom, and
* one that fills the remaining space between those two. Either the top
* or the bottom bar may be null.
*
* +----------------------+
* | topbar |
* +----------------------+
* | |
* | |
* | |
* | |
* | middlebox |
* | |
* | |
* | |
* | |
* | |
* +----------------------+
* | bottombar |
* +----------------------+
*
* @constructor
*/
function TopMidBottomView(topView, midView, bottomView) {
superClass.call(this);
this.topView_ = topView;
this.midView_ = midView;
this.bottomView_ = bottomView;
}
TopMidBottomView.prototype = {
// Inherit the superclass's methods.
__proto__: superClass.prototype,
setGeometry: function(left, top, width, height) {
superClass.prototype.setGeometry.call(this, left, top, width, height);
// Calculate the vertical split points.
var topbarHeight = 0;
if (this.topView_)
topbarHeight = this.topView_.getHeight();
var bottombarHeight = 0;
if (this.bottomView_)
bottombarHeight = this.bottomView_.getHeight();
var middleboxHeight = height - (topbarHeight + bottombarHeight);
if (middleboxHeight < 0)
middleboxHeight = 0;
// Position the boxes using calculated split points.
if (this.topView_)
this.topView_.setGeometry(left, top, width, topbarHeight);
this.midView_.setGeometry(
left, top + topbarHeight, width, middleboxHeight);
if (this.bottomView_) {
this.bottomView_.setGeometry(
left, top + topbarHeight + middleboxHeight, width, bottombarHeight);
}
},
show: function(isVisible) {
superClass.prototype.show.call(this, isVisible);
if (this.topView_)
this.topView_.show(isVisible);
this.midView_.show(isVisible);
if (this.bottomView_)
this.bottomView_.show(isVisible);
}
};
return TopMidBottomView;
})();