2012-03-10 10 views
1

私は2つのRichTextAreasを持つGWTアプリケーションで作業しています。それぞれに同じ文章がありますが、異なる言語で書かれています。ユーザーが単語をクリックすると、それは他のRichTextAreaの対応と一緒に強調表示されます。ユーザーが単語の代わりに単語をダブルクリックすると、その単語の塊が強調表示されます。 RichTextAreaを拡張して自分自身のクラスを作成し、ダブルクリックイベントを発生させました(2回のクリック間に渡された時間に応じて)。ダブルクリック時のテキスト選択を無効にする

問題は、デフォルトのテキスト選択を無効にできないことです。私は可能な解決策を探してきましたが、実際に働いているものは見つかりませんでした。私はCSSとJavaScriptの両方で試しました。これは私のクラスがどのように見えるかです:

public class MyRichTextArea extends RichTextArea 
{ 
    private boolean clickedOnce = false; 
    private int msDelay = 250; 

    public MyRichTextArea() 
    { 
     sinkEvents(Event.ONMOUSEDOWN); 
       disableTextSelectInternal(this.getElement()); 
    } 

    public void onBrowserEvent(Event event) 
     { 
     switch (DOM.eventGetType(event)) 
     { 
      case Event.ONMOUSEDOWN: 
       if (!clickedOnce) 
       { 
        clickedOnce = true; 
        Timer t = new Timer() 
        { 
         public void run() 
         { 
          if (clickedOnce) 
          { 
           clickedOnce = false; 
           raiseEvent(1); 
          } 
         } 
        }; 
        t.schedule(msDelay); 
       } 
       else 
       { 
        clickedOnce = false; 
        raiseEvent(2); 
       } 
       //DOM.eventPreventDefault(event); 
       break; 

     } 
    } 

    public void raiseEvent(int clickCount) 
    { 
     if (clickCount == 1) 
     { 
      this.fireEvent(new GwtEvent<ClickHandler>() 
       { 
        public com.google.gwt.event.shared.GwtEvent.Type<ClickHandler> getAssociatedType() 
        { 
         return ClickEvent.getType(); 
        } 

        protected void dispatch(ClickHandler handler) 
        { 
         handler.onClick(null); 
        } 
       }); 
     } 
     else 
     { 
      this.fireEvent(new GwtEvent<DoubleClickHandler>() 
        { 
         public com.google.gwt.event.shared.GwtEvent.Type<DoubleClickHandler> getAssociatedType() 
         { 
          return DoubleClickEvent.getType(); 
         } 

         protected void dispatch(DoubleClickHandler handler) 
         { 
          handler.onDoubleClick(null); 
         } 
        }); 
     } 
    } 

    protected native static void disableTextSelectInternal(Element e) 
    /*-{ 
      e.ondrag = function() { return false; }; 
      e.onselectstart = function() { return false; }; 
      e.onmousedown = function() { return false; } 
      e.style.MozUserSelect="none" 
    }-*/; 
} 

私はここからその方法を選んだ:http://comments.gmane.org/gmane.org.google.gwt/49564が、それは私には動作しません。 JavaScriptでこれを行う必要があります。私はJavaScriptの初心者で、どこから始めたらいいのかわかりません。誰もがこの問題に直面している、または可能な解決策があれば、どんな助力も認められるでしょう。

ありがとうございます。

+0

可能な複製http://stackoverflow.com/q/826782/681807 –

答えて

2

私はあなたがCSSタグを探していると信じています。次のように彼らがされています

-webkit-touch-callout: none; 
-webkit-user-select: none; 
-khtml-user-select: none; 
-moz-user-select: none; 
-ms-user-select: none; 
user-select: none; 

をjavaのを通して、あなたのオブジェクトにそれらを実装するためには、あなたがこのような何かを探している:

MyRichTextArea myRichTextArea = new MyRichTextArea(); 
myRichTextArea.getElement().setAttribute("style", 
    myRichTextArea.getElement().getAttribute("style") + 
" -webkit-touch-callout: none;" + 
" -webkit-user-select: none;" + 
" -khtml-user-select: none;" + 
" -moz-user-select: none;" + 
" -ms-user-select: none;" + 
" user-select: none;"); 

これは既に設定されているCSSで上記のCSSを追加します要素。これがあなたが探している答えであることを願っています!

関連する問題