0

以下代码可以根据 KeyUp 事件使 RichTextArea 垂直自动增长或收缩,问题是当用户粘贴或剪切内容时如何做同样的事情(Google plus 已经实现了这一点)。MouseUp 和 CONTEXTMENU 事件已经试过了,没有运气。有人可以给出解决方案吗?谢谢。

public AutoResizeTextArea()
{
    new Timer()
    {
        @Override
        public void run()
        {
            (doc = ((FrameElement) getElement().cast()).getContentDocument()).getBody()
                    .setAttribute("style", "word-wrap:break-word;overflow:hidden;");
        }
    }.schedule(100);
}


@Override
public void onBrowserEvent(Event event)
{
    switch (DOM.eventGetType(event))
    {
        case Event.ONKEYUP:
            adjustHeight();
            break;
    }
}

private void adjustHeight()
{
    if (doc.getDocumentElement()
            .getOffsetHeight() != doc.getClientHeight())
    {
        setHeight((doc.getDocumentElement()
                .getOffsetHeight() + 19) + "px");
    }
}
4

1 回答 1

0

这对我有用。我假设您的 RichTextArea 小部件 = richTextArea 变量。

IFrameElement iFrame = IFrameElement.as(richTextArea.getElement());

//listen for paste event
addTextPasteHandler(iFrame);

/**
 * Add a listener for the paste event
 * @param iframe
 */
private native void addTextPasteHandler(IFrameElement iframe)
/*-{
    if(iframe == null)
        return;

    var _this = this;

    var pasteFunction = function(e)
    {
        _this.@com.yourpackagepath.YourClass::handlePaste()();
    }

    iframe.contentWindow.addEventListener('paste', pasteFunction, true);

}-*/;

public void handlePaste() {
    Window.alert("Paste!");
}
于 2012-09-13T03:47:36.793 回答