| | 127 | public void setHeight(String height) { |
| | 128 | if (height != null && height.indexOf("%") > 0) { |
| | 129 | // special handling for proportional height |
| | 130 | proportionalHeight = Float.parseFloat(height.substring(0, height |
| | 131 | .indexOf("%"))) / 100; |
| | 132 | iLayout(); |
| | 133 | } else { |
| | 134 | super.setHeight(height); |
| | 135 | proportionalHeight = -1; |
| | 136 | } |
| | 137 | } |
| | 138 | |
| | 139 | public void setWidth(String width) { |
| | 140 | if (width != null && width.indexOf("%") > 0) { |
| | 141 | // special handling for proportional w |
| | 142 | proportionalWidth = Float.parseFloat(width.substring(0, width |
| | 143 | .indexOf("%"))) / 100; |
| | 144 | iLayout(); |
| | 145 | } else { |
| | 146 | super.setHeight(width); |
| | 147 | proportionalWidth = -1; |
| | 148 | } |
| | 149 | } |
| | 150 | |
| | 151 | public void iLayout() { |
| | 152 | if (proportionalWidth >= 0) { |
| | 153 | int availPixels = (int) (DOM.getElementPropertyInt(DOM |
| | 154 | .getParent(getElement()), "clientWidth") * proportionalWidth); |
| | 155 | availPixels -= getExtraHorizontalPixels(); |
| | 156 | super.setWidth(availPixels + "px"); |
| | 157 | } |
| | 158 | if (proportionalHeight >= 0) { |
| | 159 | int availPixels = (int) (DOM.getElementPropertyInt(DOM |
| | 160 | .getParent(getElement()), "clientHeight") * proportionalHeight); |
| | 161 | availPixels -= getExtraVerticalPixels(); |
| | 162 | super.setHeight(availPixels + "px"); |
| | 163 | } |
| | 164 | } |
| | 165 | |
| | 166 | /** |
| | 167 | * @return space used by components paddings and borders |
| | 168 | */ |
| | 169 | private int getExtraHorizontalPixels() { |
| | 170 | if (extraHorizontalPixels < 0) { |
| | 171 | detectExtraSizes(); |
| | 172 | } |
| | 173 | return extraHorizontalPixels; |
| | 174 | } |
| | 175 | |
| | 176 | /** |
| | 177 | * @return space used by components paddings and borders |
| | 178 | */ |
| | 179 | private int getExtraVerticalPixels() { |
| | 180 | if (extraVerticalPixels < 0) { |
| | 181 | detectExtraSizes(); |
| | 182 | } |
| | 183 | return extraVerticalPixels; |
| | 184 | } |
| | 185 | |
| | 186 | /** |
| | 187 | * Detects space used by components paddings and borders. Used when |
| | 188 | * relational size are used. |
| | 189 | */ |
| | 190 | private void detectExtraSizes() { |
| | 191 | Element clone = Util.cloneNode(getElement(), false); |
| | 192 | DOM.setElementAttribute(clone, "id", ""); |
| | 193 | DOM.setStyleAttribute(clone, "visibility", "hidden"); |
| | 194 | DOM.setStyleAttribute(clone, "position", "absolute"); |
| | 195 | DOM.setStyleAttribute(clone, "width", "0"); |
| | 196 | DOM.setStyleAttribute(clone, "height", "0"); |
| | 197 | DOM.appendChild(DOM.getParent(getElement()), clone); |
| | 198 | extraHorizontalPixels = DOM.getElementPropertyInt(clone, "offsetWidth"); |
| | 199 | extraVerticalPixels = DOM.getElementPropertyInt(clone, "offsetHeight"); |
| | 200 | DOM.removeChild(DOM.getParent(getElement()), clone); |
| | 201 | } |
| | 202 | |