zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
    实现外观边框和内间距.
        border
        padding
*/
 
/**
    @name Edo.containers.Box
    @class 
    @typeName box
    @description 盒容器,实现边框border和内间距padding
    @extend Edo.containers.Container
    @example 
*/
Edo.containers.Box = function(){    
    Edo.containers.Box.superclass.constructor.call(this);
};
Edo.containers.Box.extend(Edo.containers.Container, {
    /**
        @name Edo.containers.Application#defaultWidth
        @property
        @default 60
    */ 
    defaultWidth: 60,
    /**
        @name Edo.containers.Application#defaultHeight
        @property
        @default 22
    */ 
    defaultHeight: 22, 
    /**
        @name Edo.containers.Box#border
        @property
        @type [top, right, bottom, left]
        @default [1,1,1,1]
        @description 边框线宽度
    */
    border: [1,1,1,1],    
    /**
        @name Edo.containers.Box#padding
        @property
        @type [top, right, bottom, left]
        @default [1,1,1,1]
        @description 内边距宽度
    */
    padding: [5,5,5,5],        
    
    elCls: 'e-box',    
    /**
        @name Edo.containers.Box#bodyStyle
        @property
        @type String
        @description body的style
    */
    bodyStyle: '',          //bodyStyle
    /**
        @name Edo.containers.Box#bodyCls
        @property
        @type String
        @description body的cls
    */
    bodyCls: '',
    
    getInnerHtml: function(sb){
        var box = this._getBox();
        var lb = this.getLayoutBox(box);
        
        sb[sb.length] = '<div class="e-box-scrollct ';
        sb[sb.length] = this.bodyCls;
        sb[sb.length] = '" style="';        
        sb[sb.length] = this.bodyStyle;
        sb[sb.length] = ';width:';
        sb[sb.length] = lb.width;
        sb[sb.length] = 'px;height:';
        sb[sb.length] = lb.height;
        sb[sb.length] = 'px;margin:0px;padding:0px;border:0px;position:absolute;left:';
        
        sb[sb.length] = lb.x - box.x - this.border[3];
        sb[sb.length] = 'px;top:';
        sb[sb.length] = lb.y - box.y - this.border[0];
        sb[sb.length] = 'px;';        
        sb[sb.length] = ';'+this.doScrollPolicy();
        
        
        sb[sb.length] = '"></div>';
    },
    
    createHtml: function(w, h, appendArray){    
        this._getBPStyle();
    
        return Edo.containers.Box.superclass.createHtml.call(this, w, h, appendArray);
    },
    
    createChildren: function(el){
        Edo.containers.Box.superclass.createChildren.call(this, el);
        this.scrollEl = this.el.firstChild; //这个操作很耗时 1000个box生成,要耗掉150左右毫秒
    },
    measure: function(){
        Edo.containers.Box.superclass.measure.call(this);
        
        var b = this.border;
        var p = this.padding;        
        //1)给得到的布局参考值加上所有的偏移
        this.realWidth += b[3] + p[3] + b[1] + p[1];        //如果不是绝对设置的,则需要加上偏移
        this.realHeight += b[0] + p[0] + b[2] + p[2];
        
        //2)确保操作...
        this.measureSize();
    },
    getLayoutBox: function(box){           //获取容器的布局尺寸!!!要减掉偏移!!!
        var b = this.border;
        var p = this.padding;
        
        box = box || Edo.containers.Box.superclass.getLayoutBox.call(this);
        box.width = box.width - b[3] - p[3] - b[1] - p[1];
        box.height = box.height - b[0] - p[0] - b[2] - p[2];
        box.x += b[3] + p[3];
        box.y += b[0] + p[0];
        box.right = box.x + box.width;
        box.bottom = box.y + box.height;
        return box;             //这里的逻辑没问题!!!
    },
    syncSize: function(){
        var w = this.realWidth, h = this.realHeight;
        
        this.domWidth = w;
        this.domHeight = h;
        Edo.containers.Box.superclass.syncSize.call(this);
        
    },
    _setBodyCls: function(value){
        if(this.bodyCls != value){
            this.bodyCls = value;
            if(this.el){
                Edo.util.Dom.addClass(this.scrollEl, value);
            }
            this.changeProperty('bodyCls', value); 
        }
    },
    _setBodyStyle: function(value){
        if(this.bodyStyle != value){
            this.bodyStyle = value;
            if(this.el){
                Edo.util.Dom.applyStyles(this.scrollEl, value);    
            }
            this.changeProperty('bodyStyle', value); 
        }
    },
    _getBPStyle: function(){
        var b = this.border;//, p = this.padding;
        var style = 'border-left-width:'+ b[3]+'px;border-top-width:'+ b[0]+'px;border-right-width:'+ b[1]+'px;border-bottom-width:'+ b[2] + 'px;';
        //style += 'padding-left:'+ p[0]+'px;padding-top:'+ p[1]+'px;padding-right:'+ p[2]+'px;padding-bottom:'+ p[3]+'px;';        
        this.addStyle(style);
    },    
    _setBorder: function(value){
        value = this._toArray(value);
        if(!this._checkTheSame(this.border, value)){
            this.border = value;            
            this.addStyle(this._getBPStyle());
            this.relayout('border', value);
            this.changeProperty('border', value);
        }
    },
    _setPadding: function(value){
        value = this._toArray(value);
        if(!this._checkTheSame(this.padding, value)){
                    
            this.padding = value;
            this.addStyle(this._getBPStyle());
            
            this.relayout('padding', value);
            this.changeProperty('padding', value);
        }
    }
});
Edo.containers.Box.regType('box');