01: /*
02: * Copyright 2006 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;
17:
18: import com.google.gwt.user.client.DOM;
19: import com.google.gwt.user.client.Event;
20:
21: /**
22: * A widget that can contain arbitrary HTML.
23: *
24: * <p>
25: * If you only need a simple label (text, but not HTML), then the
26: * {@link com.google.gwt.user.client.ui.Label} widget is more appropriate, as it
27: * disallows the use of HTML, which can lead to potential security issues if not
28: * used properly.
29: * </p>
30: *
31: * <h3>CSS Style Rules</h3>
32: * <ul class='css'>
33: * <li>.gwt-HTML { }</li>
34: * </ul>
35: *
36: * <p>
37: * <h3>Example</h3> {@example com.google.gwt.examples.HTMLExample}
38: * </p>
39: */
40: public class HTML extends Label implements HasHTML {
41:
42: /**
43: * Creates an empty HTML widget.
44: */
45: public HTML() {
46: setElement(DOM.createDiv());
47: sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS);
48: setStyleName("gwt-HTML");
49: }
50:
51: /**
52: * Creates an HTML widget with the specified HTML contents.
53: *
54: * @param html the new widget's HTML contents
55: */
56: public HTML(String html) {
57: this ();
58: setHTML(html);
59: }
60:
61: /**
62: * Creates an HTML widget with the specified contents, optionally treating it
63: * as HTML, and optionally disabling word wrapping.
64: *
65: * @param html the widget's contents
66: * @param wordWrap <code>false</code> to disable word wrapping
67: */
68: public HTML(String html, boolean wordWrap) {
69: this (html);
70: setWordWrap(wordWrap);
71: }
72:
73: public String getHTML() {
74: return DOM.getInnerHTML(getElement());
75: }
76:
77: public void setHTML(String html) {
78: DOM.setInnerHTML(getElement(), html);
79: }
80: }
|