01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.user.client.ui.impl;
17:
18: import com.google.gwt.user.client.DOM;
19: import com.google.gwt.user.client.Element;
20: import com.google.gwt.core.client.GWT;
21:
22: /**
23: * Uses a combination of a clear image and a background image to clip all except
24: * a desired portion of an underlying image.
25: *
26: * Do not use this class - it is used for implementation only, and its methods
27: * may change in the future.
28: */
29: public class ClippedImageImpl {
30:
31: public void adjust(Element img, String url, int left, int top,
32: int width, int height) {
33: String style = "url(" + url + ") no-repeat " + (-left + "px ")
34: + (-top + "px");
35: DOM.setStyleAttribute(img, "background", style);
36: DOM.setStyleAttribute(img, "width", width + "px");
37: DOM.setStyleAttribute(img, "height", height + "px");
38: }
39:
40: public Element createStructure(String url, int left, int top,
41: int width, int height) {
42: Element tmp = DOM.createSpan();
43: DOM.setInnerHTML(tmp, getHTML(url, left, top, width, height));
44: return DOM.getFirstChild(tmp);
45: }
46:
47: public String getHTML(String url, int left, int top, int width,
48: int height) {
49: String style = "width: " + width + "px; height: " + height
50: + "px; background: url(" + url + ") no-repeat "
51: + (-left + "px ") + (-top + "px");
52:
53: String clippedImgHtml = "<img src='" + GWT.getModuleBaseURL()
54: + "clear.cache.gif' style='" + style + "' border='0'>";
55:
56: return clippedImgHtml;
57: }
58: }
|