Adds the InlineHyperlink widget, which is just like a Hyperlink, except that it
isn't wrapped with an outer div, so it lays out inline.

Issue 3056.

patch by: ajr
review by: rjrjr



git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4241 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/Hyperlink.java b/user/src/com/google/gwt/user/client/ui/Hyperlink.java
index 789f855..467a729 100644
--- a/user/src/com/google/gwt/user/client/ui/Hyperlink.java
+++ b/user/src/com/google/gwt/user/client/ui/Hyperlink.java
@@ -56,17 +56,14 @@
 
   private static HyperlinkImpl impl = GWT.create(HyperlinkImpl.class);
   
-  private Element anchorElem;
+  private final Element anchorElem = DOM.createAnchor();
   private String targetHistoryToken;
 
   /**
    * Creates an empty hyperlink.
    */
   public Hyperlink() {
-    setElement(DOM.createDiv());
-    DOM.appendChild(getElement(), anchorElem = DOM.createAnchor());
-    sinkEvents(Event.ONCLICK);
-    setStyleName("gwt-Hyperlink");
+    this(DOM.createDiv());
   }
 
   /**
@@ -98,6 +95,18 @@
     setText(text);
     setTargetHistoryToken(targetHistoryToken);
   }
+  
+  protected Hyperlink(Element elem) {
+    if (elem == null) {
+      setElement(anchorElem);
+    } else {
+      setElement(elem);
+      DOM.appendChild(getElement(), anchorElem);
+    }
+
+    sinkEvents(Event.ONCLICK);
+    setStyleName("gwt-Hyperlink");
+  }
 
   public HandlerRegistration addClickHandler(ClickHandler handler) {
     return addHandler(handler, ClickEvent.getType());
diff --git a/user/src/com/google/gwt/user/client/ui/InlineHyperlink.java b/user/src/com/google/gwt/user/client/ui/InlineHyperlink.java
new file mode 100644
index 0000000..40a42cb
--- /dev/null
+++ b/user/src/com/google/gwt/user/client/ui/InlineHyperlink.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2008 Google Inc.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.google.gwt.user.client.ui;
+
+/**
+ * A widget that serves as an "internal" hyperlink. That is, it is a link to
+ * another state of the running application. It should behave exactly like
+ * {@link com.google.gwt.user.client.ui.Hyperlink}, save that it lays out
+ * as an inline element, not block.
+ * 
+ * <h3>CSS Style Rules</h3>
+ * <ul class='css'>
+ * <li>.gwt-InlineHyperlink { }</li>
+ * </ul>
+ */
+public class InlineHyperlink extends Hyperlink {
+
+  /**
+   * Creates an empty hyperlink.
+   */
+  public InlineHyperlink() {
+    super(null);
+
+    setStyleName("gwt-InlineHyperlink");
+  }
+
+  /**
+   * Creates a hyperlink with its text and target history token specified.
+   * 
+   * @param text the hyperlink's text
+   * @param asHTML <code>true</code> to treat the specified text as html
+   * @param targetHistoryToken the history token to which it will link
+   * @see #setTargetHistoryToken
+   */
+  public InlineHyperlink(String text, boolean asHTML, String targetHistoryToken) {
+    this();
+
+    if (asHTML) {
+      setHTML(text);
+    } else {
+      setText(text);
+    }
+    setTargetHistoryToken(targetHistoryToken);
+  }
+
+  /**
+   * Creates a hyperlink with its text and target history token specified.
+   * 
+   * @param text the hyperlink's text
+   * @param targetHistoryToken the history token to which it will link
+   */
+  public InlineHyperlink(String text, String targetHistoryToken) {
+    this(text, false, targetHistoryToken);
+  }
+}