/** * This method is called when a widget is attached to the browser's document. * onAttach needs special handling for the CheckBox case. Must still call * {@link Widget#onAttach()} to preserve the <code>onAttach</code> contract. */ @Override protected void onLoad() { DOM.setEventListener(inputElem, this); }
/** * Sets the {@link EventListener} to receive events for the given element. * Only one such listener may exist for a single element. * * @param elem the element whose listener is to be set * @param listener the listener to receive {@link Event events} */ public static void setEventListener(Element elem, EventListener listener) { DOM.setEventListener(elem, listener); }
@Override public void onDetach() { super.onDetach(); DOM.setEventListener(expandable, null); DOM.setEventListener(collapsible, null); lastOffsetHeight = -1; lastOffsetWidth = -1; }
/** * Convenience method to convert the specified HTML into DOM elements and * return the parent of the DOM elements. * * @param html the HTML to convert * @param tmpElem a temporary element * @return the parent element */ static Element convertToElements(Widget widget, Element tmpElem, SafeHtml html) { // Attach an event listener so we can catch synchronous load events from // cached images. DOM.setEventListener(tmpElem, widget); tmpElem.setInnerSafeHtml(html); // Detach the event listener. DOM.setEventListener(tmpElem, null); return tmpElem; }
@Override protected void doAttachChildren() { try { AttachDetachException.tryCommand(this, AttachDetachException.attachCommand); } finally { DOM.setEventListener(focusable, this); } }
@Override protected void doDetachChildren() { try { AttachDetachException.tryCommand(this, AttachDetachException.detachCommand); } finally { DOM.setEventListener(focusable, null); } }
@Override public void onAttach() { super.onAttach(); DOM.setEventListener(expandable, this); DOM.setEventListener(collapsible, this); /* * Update the scrollables in a deferred command so the browser calculates * the offsetHeight/Width correctly. */ Scheduler.get().scheduleDeferred(new ScheduledCommand() { public void execute() { resetScrollables(); } }); }
/** * This method is called when a widget is detached from the browser's * document. Overridden because of IE bug that throws away checked state and * in order to clear the event listener off of the <code>inputElem</code>. */ @Override protected void onUnload() { // Clear out the inputElem's event listener (breaking the circular // reference between it and the widget). DOM.setEventListener(inputElem, null); setValue(getValue()); }
@Override void replaceElement(com.google.gwt.dom.client.Element elem) { if (isAttached()) { // Remove old event listener to avoid leaking. onDetach will not do this // for us, because it is only called when the widget itself is detached // from the document. DOM.setEventListener(getElement(), null); } super.replaceElement(elem); if (isAttached()) { // Hook the event listener back up on the new element. onAttach will not // do this for us, because it is only called when the widget itself is // attached to the document. DOM.setEventListener(getElement(), this); } }
@Override public void onBrowserEvent(final Widget widget, Event event) { // We need to remove the event listener from the cell now that the event // has fired. String type = event.getType().toLowerCase(Locale.ROOT); if (BrowserEvents.FOCUS.equals(type) || BrowserEvents.BLUR.equals(type) || BrowserEvents.CHANGE.equals(type)) { EventTarget eventTarget = event.getEventTarget(); if (Element.is(eventTarget)) { Element target = eventTarget.cast(); if (target != widget.getElement()) { DOM.setEventListener(target, null); } } } // Update the value of the focused input box. if (focusedInput != null && BrowserEvents.CHANGE.equals(type)) { focusedInputValue = getInputValue(focusedInput); } // We might need to fire a synthetic change event on the input element. if (focusedInput != null && !focusedInputChangesOnBlurOnly && changeEventTriggers.contains(type)) { // Defer the change event because the change does not occur until after // the events specified above. Scheduler.get().scheduleDeferred(new ScheduledCommand() { public void execute() { maybeFireChangeEvent(widget); } }); } }
/** * Convenience method to replace all children of a Widget. * * @param widget the widget who's contents will be replaced * @param childContainer the container that holds the contents * @param html the html to set */ static void replaceAllChildren(Widget widget, Element childContainer, SafeHtml html) { // If the widget is not attached, attach an event listener so we can catch // synchronous load events from cached images. if (!widget.isAttached()) { DOM.setEventListener(widget.getElement(), widget); } // Render the HTML. childContainer.setInnerSafeHtml(CellBasedWidgetImpl.get().processHtml(html)); // Detach the event listener. if (!widget.isAttached()) { DOM.setEventListener(widget.getElement(), null); } }
DOM.setEventListener(tmpElem, table); DOM.setEventListener(tmpElem, null);
} finally { DOM.setEventListener(getElement(), null); attached = false;
/** * Render a table section in the table. * * @param table the {@link AbstractCellTable} * @param section the {@link TableSectionElement} to replace * @param html the html of a table section element containing the rows */ public final void replaceAllRows(AbstractCellTable<?> table, TableSectionElement section, SafeHtml html) { // If the widget is not attached, attach an event listener so we can catch // synchronous load events from cached images. if (!table.isAttached()) { DOM.setEventListener(table.getElement(), table); } // Remove the section from the tbody. Element parent = section.getParentElement(); Element nextSection = section.getNextSiblingElement(); detachSectionElement(section); // Render the html. replaceAllRowsImpl(table, section, html); /* * Reattach the section. If next section is null, the section will be * appended instead. */ reattachSectionElement(parent, section, nextSection); // Detach the event listener. if (!table.isAttached()) { DOM.setEventListener(table.getElement(), null); } }
/** * Dispatch an event to the cell, ensuring that the widget will catch it. * * @param widget the widget that will handle the event * @param target the cell element * @param eventBits the event bits to sink * @param event the event to fire, or null not to fire an event */ private static void dispatchCellEvent(Widget widget, Element target, int eventBits, Event event) { // Make sure that the target is still a child of the widget. We defer the // firing of some events, so its possible that the DOM structure has // changed before we fire the event. if (!widget.getElement().isOrHasChild(target)) { return; } // Temporary listen for events from the cell. The event listener will be // removed in onBrowserEvent(). DOM.setEventListener(target, widget); DOM.sinkEvents(target, eventBits | DOM.getEventsSunk(target)); // Dispatch the event to the cell. if (event != null) { target.dispatchEvent(event); } }
DOM.setEventListener(getElement(), this); int bitsToAdd = eventsToSink; eventsToSink = -1;
@Override protected void onAttach() { checkInit(); if (!isOrWasAttached()) { widget.sinkEvents(eventsToSink); eventsToSink = -1; } widget.onAttach(); // Clobber the widget's call to setEventListener(), causing all events to // be routed to this composite, which will delegate back to the widget by // default (note: it's not necessary to clear this in onDetach(), because // the widget's onDetach will do so). DOM.setEventListener(getElement(), this); // Call doAttachChildren() and then onLoad() directly, because we're not // calling super.onAttach(). doAttachChildren(); onLoad(); AttachEvent.fire(this, true); }
DOM.setEventListener(inputElem, null); DOM.setEventListener(inputElem, this);
DOM.setEventListener(table.getElement(), table); DOM.setEventListener(table.getElement(), null);
/** * This method is called when a widget is detached from the browser's * document. Overridden because of IE bug that throws away checked state and * in order to clear the event listener off of the <code>inputElem</code>. */ @Override protected void onUnload() { // Clear out the inputElem's event listener (breaking the circular // reference between it and the widget). DOM.setEventListener(inputElem, null); setValue(getValue()); }