// Path: src/main/java/com/tractionsoftware/gwt/user/client/util/Geometry.java
// public class Geometry {
// 
//     public static final void setInvisibleToMeasure(Element e) {
//         Style s = e.getStyle();
//         s.setProperty("visibility", "hidden");
//         s.setProperty("display", "block");
//     }
// 
//     public static final void unsetInvisibleToMeasure(Element e) {
//         Style s = e.getStyle();
//         s.setProperty("display", "none");
//         s.setProperty("visibility", "");
//     }
// 
//     public static final Rect getBoundsOfHidden(Element e) {
//         setInvisibleToMeasure(e);
//         Rect ret = getBounds(e);
//         unsetInvisibleToMeasure(e);
//         return ret;
//     }
// 
//     public static final Rect getBounds(Element e) {
//         return new Rect(getX(e), getY(e), getW(e), getH(e));
//     }
// 
//     public static final int getX(Element e) {
//         return e.getAbsoluteLeft();
//     }
// 
//     public static final int getY(Element e) {
//         return e.getAbsoluteTop();
//     }
// 
//     /**
//      * Updated to factor in border and padding
//      */
//     public static final int getW(Element e) {
//         int ret = e.getOffsetWidth();
//         ret -= MiscUtils.getComputedStyleInt(e, "paddingLeft");
//         ret -= MiscUtils.getComputedStyleInt(e, "paddingRight");
//         ret -= MiscUtils.getComputedStyleInt(e, "borderLeftWidth");
//         ret -= MiscUtils.getComputedStyleInt(e, "borderRightWidth");
//         return Math.max(ret, 0);
//     }
// 
//     /**
//      * Updated to factor in border and padding
//      */
//     public static final int getH(Element e) {
//         int ret = e.getOffsetHeight();
//         ret -= MiscUtils.getComputedStyleInt(e, "paddingTop");
//         ret -= MiscUtils.getComputedStyleInt(e, "paddingBottom");
//         ret -= MiscUtils.getComputedStyleInt(e, "borderTopWidth");
//         ret -= MiscUtils.getComputedStyleInt(e, "borderBottomWidth");
//         return Math.max(ret, 0);
//     }
// 
//     /**
//      * Sets the bounds of a UIObject, moving and sizing to match the
//      * bounds specified. Currently used for the itemhover and useful
//      * for other absolutely positioned elements.
//      */
//     public static final void setBounds(UIObject o, Rect bounds) {
//         setPosition(o, bounds);
//         setSize(o, bounds);
//     }
// 
//     /**
//      * Sets the position of a UIObject
//      */
//     public static final void setPosition(UIObject o, Rect pos) {
//         Style style = o.getElement().getStyle();
//         style.setPropertyPx("left", pos.x);
//         style.setPropertyPx("top", pos.y);
//     }
// 
//     /**
//      * Sets the size of a UIObject
//      */
//     public static final void setSize(UIObject o, Rect size) {
//         o.setPixelSize(size.w, size.h);
// 
//     }
// 
//     /**
//      * Determines if a point is inside a box.
//      */
//     public static final boolean isInside(int x, int y, Rect box) {
//         return (box.x < x && x < box.x + box.w && box.y < y && y < box.y + box.h);
//     }
// 
//     /**
//      * Determines if a mouse event is inside a box.
//      */
//     public static final boolean isMouseInside(NativeEvent event, Element element) {
//         return isInside(event.getClientX() + Window.getScrollLeft(), event.getClientY() + Window.getScrollTop(), getBounds(element));
//     }
// 
//     /**
//      * This takes into account scrolling and will be in absolute
//      * coordinates where the top left corner of the page is 0,0 but
//      * the viewport may be scrolled to something else.
//      */
//     public static final Rect getViewportBounds() {
//         return new Rect(Window.getScrollLeft(), Window.getScrollTop(), Window.getClientWidth(), Window.getClientHeight());
//     }
// 
// }


import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.HasKeyDownHandlers;
import com.google.gwt.event.dom.client.HasKeyUpHandlers;
import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.tractionsoftware.gwt.user.client.util.Geometry;
/*
 * Copyright 2010 Traction Software, 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.tractionsoftware.gwt.user.client.ui;



/**
 * This attaches to an input, listening for KeyDown/KeyUp, and
 * automatically resizing the text area. It does this using an
 * invisible span that matches the text of the input.
 */
public class AutoSizingTextBox<T extends Widget & HasTextSelection & HasValue<String> & HasValueChangeHandlers<String> & HasKeyUpHandlers & HasKeyDownHandlers & Focusable & HasText> extends AutoSizingBase<T, InlineLabel> {
    
    private static final class TextBoxForAutoSize extends TextBox implements HasTextSelection {}

    public AutoSizingTextBox() {
	this((T)new TextBoxForAutoSize());
    }
    public AutoSizingTextBox(T box) {
	this(box, 30);
    }
    public AutoSizingTextBox(T box, int extraSize) {
	super(box, new InlineLabel());
	setExtraSize(extraSize);
    }

    @Override
    protected void onLoad() {
	setMinFromCss("minWidth");
	setMaxFromCss("maxWidth");
	super.onLoad();
    }

    /**
     * Returns the size of the shadow element.
     */
    @Override
    public int getShadowSize() {
// Path: src/main/java/com/tractionsoftware/gwt/user/client/util/Geometry.java
// public class Geometry {
// 
//     public static final void setInvisibleToMeasure(Element e) {
//         Style s = e.getStyle();
//         s.setProperty("visibility", "hidden");
//         s.setProperty("display", "block");
//     }
// 
//     public static final void unsetInvisibleToMeasure(Element e) {
//         Style s = e.getStyle();
//         s.setProperty("display", "none");
//         s.setProperty("visibility", "");
//     }
// 
//     public static final Rect getBoundsOfHidden(Element e) {
//         setInvisibleToMeasure(e);
//         Rect ret = getBounds(e);
//         unsetInvisibleToMeasure(e);
//         return ret;
//     }
// 
//     public static final Rect getBounds(Element e) {
//         return new Rect(getX(e), getY(e), getW(e), getH(e));
//     }
// 
//     public static final int getX(Element e) {
//         return e.getAbsoluteLeft();
//     }
// 
//     public static final int getY(Element e) {
//         return e.getAbsoluteTop();
//     }
// 
//     /**
//      * Updated to factor in border and padding
//      */
//     public static final int getW(Element e) {
//         int ret = e.getOffsetWidth();
//         ret -= MiscUtils.getComputedStyleInt(e, "paddingLeft");
//         ret -= MiscUtils.getComputedStyleInt(e, "paddingRight");
//         ret -= MiscUtils.getComputedStyleInt(e, "borderLeftWidth");
//         ret -= MiscUtils.getComputedStyleInt(e, "borderRightWidth");
//         return Math.max(ret, 0);
//     }
// 
//     /**
//      * Updated to factor in border and padding
//      */
//     public static final int getH(Element e) {
//         int ret = e.getOffsetHeight();
//         ret -= MiscUtils.getComputedStyleInt(e, "paddingTop");
//         ret -= MiscUtils.getComputedStyleInt(e, "paddingBottom");
//         ret -= MiscUtils.getComputedStyleInt(e, "borderTopWidth");
//         ret -= MiscUtils.getComputedStyleInt(e, "borderBottomWidth");
//         return Math.max(ret, 0);
//     }
// 
//     /**
//      * Sets the bounds of a UIObject, moving and sizing to match the
//      * bounds specified. Currently used for the itemhover and useful
//      * for other absolutely positioned elements.
//      */
//     public static final void setBounds(UIObject o, Rect bounds) {
//         setPosition(o, bounds);
//         setSize(o, bounds);
//     }
// 
//     /**
//      * Sets the position of a UIObject
//      */
//     public static final void setPosition(UIObject o, Rect pos) {
//         Style style = o.getElement().getStyle();
//         style.setPropertyPx("left", pos.x);
//         style.setPropertyPx("top", pos.y);
//     }
// 
//     /**
//      * Sets the size of a UIObject
//      */
//     public static final void setSize(UIObject o, Rect size) {
//         o.setPixelSize(size.w, size.h);
// 
//     }
// 
//     /**
//      * Determines if a point is inside a box.
//      */
//     public static final boolean isInside(int x, int y, Rect box) {
//         return (box.x < x && x < box.x + box.w && box.y < y && y < box.y + box.h);
//     }
// 
//     /**
//      * Determines if a mouse event is inside a box.
//      */
//     public static final boolean isMouseInside(NativeEvent event, Element element) {
//         return isInside(event.getClientX() + Window.getScrollLeft(), event.getClientY() + Window.getScrollTop(), getBounds(element));
//     }
// 
//     /**
//      * This takes into account scrolling and will be in absolute
//      * coordinates where the top left corner of the page is 0,0 but
//      * the viewport may be scrolled to something else.
//      */
//     public static final Rect getViewportBounds() {
//         return new Rect(Window.getScrollLeft(), Window.getScrollTop(), Window.getClientWidth(), Window.getClientHeight());
//     }
// 
// }


// Path: src/main/java/com/tractionsoftware/gwt/user/client/ui/AutoSizingTextBox.java
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.HasKeyDownHandlers;
import com.google.gwt.event.dom.client.HasKeyUpHandlers;
import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.tractionsoftware.gwt.user.client.util.Geometry;

/*
 * Copyright 2010 Traction Software, 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.tractionsoftware.gwt.user.client.ui;



/**
 * This attaches to an input, listening for KeyDown/KeyUp, and
 * automatically resizing the text area. It does this using an
 * invisible span that matches the text of the input.
 */
public class AutoSizingTextBox<T extends Widget & HasTextSelection & HasValue<String> & HasValueChangeHandlers<String> & HasKeyUpHandlers & HasKeyDownHandlers & Focusable & HasText> extends AutoSizingBase<T, InlineLabel> {
    
    private static final class TextBoxForAutoSize extends TextBox implements HasTextSelection {}

    public AutoSizingTextBox() {
	this((T)new TextBoxForAutoSize());
    }
    public AutoSizingTextBox(T box) {
	this(box, 30);
    }
    public AutoSizingTextBox(T box, int extraSize) {
	super(box, new InlineLabel());
	setExtraSize(extraSize);
    }

    @Override
    protected void onLoad() {
	setMinFromCss("minWidth");
	setMaxFromCss("maxWidth");
	super.onLoad();
    }

    /**
     * Returns the size of the shadow element.
     */
    @Override
    public int getShadowSize() {
	return Geometry.getW(shadow.getElement());