Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4335828
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:43:24+00:00 2026-05-21T10:43:24+00:00

PopupPanel is a class within GWT written (akhem) a long time ago (which is

  • 0

PopupPanel is a class within GWT written (akhem) a long time ago (which is why it sucks so much) that allows for showing popups with content. One of the options is autoHide where if there’s a certain event outside of the popup it closes the popup. It works well on anything EXCEPT Safari Mobil (SM). Reason is SM doesn’t fire click events on touch. It fires touch events. PopupPanel is hard coded to look for ClickEvents.

Specifically, the code says:

case Event.ONMOUSEDOWN:
   ...
   if (!eventTargetsPopupOrPartner && autoHide) {
      hide(true);
   ...

Obviously this isn’t complete and it should also include Event.ONTOUCHSTART

Problem is, all the methods and fields are private so I cannot add this functionality. That’s a big boo-boo on the part of GWT team but not really a concern since I could just make my own class and copy contents of PopupPanel. The big problem is that nativeEventPreview doesn’t capture Touch Events!

I tried adding the following to Event Preview the following:

private static NativePreviewHandler nativePreviewHandler = new NativePreviewHandler() {
    public void onPreviewNativeEvent(NativePreviewEvent event) {
        Event nativeEvent = Event.as(event.getNativeEvent());
        switch (nativeEvent.getTypeInt()) {         
        case Event.ONTOUCHSTART:        
        case Event.ONMOUSEDOWN:
            EventTarget target = nativeEvent.getEventTarget();
            if (!Element.is(target) || !popup.getElement().isOrHasChild(Element.as(target))) {                  
                popup.hide();
            } break;
        }       
            }
};

Where ‘popup’ is the PopupPanel I’m trying to get to close on outside touch events.
Sad thing is it works for mouse down when testing in any other browser on Earth, but not on iPad.

Another thing I tried was adding a TouchStartHandler to the glass of the PopupPanel (the gray looking thing behind it). I war hoping that I could catch the touch events that way, but I was unable to get events to fire on glass since it’s attached to DOM in some funny way. My code:

private static class ProperPopupPanel extends PopupPanel {

    public ProperPopupPanel() {
        super();            
}          

    void setHideOnGlassTouch() {
        setGlassEnabled(true);

        TouchableLabeThatDoesntCrashOnWrap glass = new TouchableLabeThatDoesntCrashOnWrap(getGlassElement());
        glass.addTouchStartHandler(new TouchStartHandler() {

            @Override
            public void onTouchStart(TouchStartEvent event) {                   
                hide();                 
            }

        });
        glass.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                hide();                     
            }               
        });
    }       

    private class TouchableLabeThatDoesntCrashOnWrap extends Label {
        public TouchableLabeThatDoesntCrashOnWrap(Element element) {
            super(element);
            super.onAttach();
        }
    }
}

In my mind this should work, but it doesn’t. I don’t know why. Any ideas or suggestions are welcome. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:43:25+00:00Added an answer on May 21, 2026 at 10:43 am

    Not enough GWT users here… well I made my own class that adds touch handlers through JSNI …

    /**
     * Overwrite of the usual PopupPanel with a modification that this one
     * works well on touch-enabled browsers.
     * @author McTrafik
     */
    public class ProperPopupPanel extends PopupPanel {
    
        ////////////////////////////////////////////////////////////
        /////////// OVERRIDES //////////////////////////////////////
        ////////////////////////////////////////////////////////////
    
        public ProperPopupPanel() {
            super();
            setTouchListener();
        }
    
        @Override
        public void hide() {
            super.hide();
            removeTouchListener();
    
        }
    
        @Override
        public void show() {
            super.show();
            addTouchListener();
        }
    
        ////////////////////////////////////////////////////////////
        /////////// NANDLERS ///////////////////////////////////////
        ////////////////////////////////////////////////////////////
    
        protected JavaScriptObject touchHandler;
    
        /**
         * Handle a touch event that happened while the popup is open.
         * @param event - The event to handle
         */
        protected void handleTouchEvent(Event event) {
            // Check to see if the events should be firing in the first place.
            if (!isShowing()) {
                removeTouchListener();
                return;
            }
            // Check if the event happened within the popup
            EventTarget target = event.getEventTarget();
            if (!Element.is(target) || !getElement().isOrHasChild(Element.as(target))) {
                // Stop event if the popup is modal
                if (isModal()) event.preventDefault();
                // Close the popup if the event happened outside
                if (isAutoHideEnabled()) {
                    hide(true);
                    removeTouchListener();
                }
            }
        };
    
    
        /**
         * Create a touchHandler that knows how to point to this instance.
         * Without it there's a cast exception that happens.
         */
        protected native void setTouchListener() /*-{
            var caller = this;
            this.@[package].ProperPopupPanel::touchHandler = function(event) {
                caller.@[package].ProperPopupPanel::handleTouchEvent(Lcom/google/gwt/user/client/Event;)(event);
            }
        }-*/;
    
    
        /**
         * Add a touch listener that will listen to touch events.
         */
        protected native void addTouchListener() /*-{
            $doc.addEventListener(
                "touchstart", 
                this.@[package].ProperPopupPanel::touchHandler, 
                true
            );
            $doc.addEventListener(
                "MozTouchDown", 
                this.@[package].ProperPopupPanel::touchHandler, 
                true
            ); 
        }-*/;
    
    
        /**
         * Remove the touch listeners
         */
        protected native void removeTouchListener() /*-{
             $doc.removeEventListener(
                 "touchstart", 
                 this.@[package].ProperPopupPanel::touchHandler, 
                 true
             );
             $doc.removeEventListener(
                 "MozTouchDown",
                 this.@[package].ProperPopupPanel::touchHandler, 
                 true
             );
        }-*/;
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a GWT PopupPanel that has an image. I add imgAreaSelect using
I have written a scientific GWT application that basically just asks for parameters, performs
I have a ModalPopupExtender that allows a customer to apply payment info. It has
Here is GWT PopupPanel ShowCase: http://gwt.google.com/samples/Showcase/Showcase.html#!CwBasicPopup The Panel got hide when the user click
In a <rich:popupPanel /> I have a <rich:fileUpload /> which has a fileUploadListener defined
I have rich:popupPanel which contains t:dataList under one column of t:dataTable. This dataList has
I'm showing myFormPanel includes a form.I'm opening this panel like : popUpPanel = new
I need some panels in GWT that have moveable functionality. This is so that
Here's the code: public class MyEntryPoint implements EntryPoint { PopupPanel popupPanel = new PopupPanel(false,true);
Using GWT I am displaying an image thumbnail with a ClickHandler that then shows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.