use of org.gwtproject.dom.client.EventTarget in project gwtproject by treblereel.
the class CompositeCell method onBrowserEvent.
@Override
public void onBrowserEvent(org.gwtproject.cell.client.Cell.Context context, Element parent, C value, NativeEvent event, org.gwtproject.cell.client.ValueUpdater<C> valueUpdater) {
int index = 0;
EventTarget eventTarget = event.getEventTarget();
if (Element.is(eventTarget)) {
Element target = eventTarget.cast();
Element container = getContainerElement(parent);
Element wrapper = container.getFirstChildElement();
while (wrapper != null) {
if (wrapper.isOrHasChild(target)) {
onBrowserEventImpl(context, wrapper, value, event, valueUpdater, hasCells.get(index));
}
index++;
wrapper = wrapper.getNextSiblingElement();
}
}
}
use of org.gwtproject.dom.client.EventTarget in project gwtproject by treblereel.
the class AbstractUiRenderer method computeDispatchEvent.
/**
* Obtains the index of the method that will receive an event.
*
* @param table event types and field names indexed by the method that can handle an event.
* @param root of a previously rendered DOM structure
* @param event event to handle
* @return index of the method that will process the event or NO_HANDLER_FOUND.
*/
private static int computeDispatchEvent(HashMap<String, Integer> table, Element root, NativeEvent event) {
String uiId = root.getAttribute(RENDERED_ATTRIBUTE);
EventTarget eventTarget = event.getEventTarget();
if (!Element.is(eventTarget)) {
return NO_HANDLER_FOUND;
}
Element cursor = Element.as(eventTarget);
while (cursor != null && cursor != root && cursor.getNodeType() != Element.DOCUMENT_NODE) {
String fieldName = getFieldName(uiId, cursor);
if (fieldName == null) {
cursor = cursor.getParentElement();
continue;
}
String key = event.getType() + UI_ID_SEPARATOR + fieldName;
if (table.containsKey(key)) {
return table.get(key);
}
cursor = cursor.getParentElement();
}
if (cursor == root) {
String key = event.getType() + UI_ID_SEPARATOR + ROOT_FAKE_NAME;
if (table.containsKey(key)) {
return table.get(key);
}
}
return NO_HANDLER_FOUND;
}
use of org.gwtproject.dom.client.EventTarget in project gwtproject by treblereel.
the class AbstractHasData method onBrowserEvent.
/**
* Handle browser events. Subclasses should override {@link #onBrowserEvent2(Event)} if they want
* to extend browser event handling.
*
* @see #onBrowserEvent2(Event)
*/
@Override
public final void onBrowserEvent(Event event) {
CellBasedWidgetImpl.get().onBrowserEvent(this, event);
// Ignore spurious events (such as onblur) while we refresh the table.
if (isRefreshing) {
return;
}
// Verify that the target is still a child of this widget. IE fires focus
// events even after the element has been removed from the DOM.
EventTarget eventTarget = event.getEventTarget();
if (!Element.is(eventTarget)) {
return;
}
Element target = Element.as(eventTarget);
if (!getElement().isOrHasChild(Element.as(eventTarget))) {
return;
}
super.onBrowserEvent(event);
String eventType = event.getType();
if (BrowserEvents.FOCUS.equals(eventType)) {
// Remember the focus state.
isFocused = true;
onFocus();
} else if (BrowserEvents.BLUR.equals(eventType)) {
// Remember the blur state.
isFocused = false;
onBlur();
} else if (BrowserEvents.KEYDOWN.equals(eventType)) {
// A key event indicates that we already have focus.
isFocused = true;
} else if (BrowserEvents.MOUSEDOWN.equals(eventType) && CellBasedWidgetImpl.get().isFocusable(Element.as(target))) {
// If a natively focusable element was just clicked, then we must have
// focus.
isFocused = true;
}
// Let subclasses handle the event now.
onBrowserEvent2(event);
}
use of org.gwtproject.dom.client.EventTarget in project gwtproject by treblereel.
the class CellList method onBrowserEvent2.
@Override
protected void onBrowserEvent2(Event event) {
// Get the event target.
EventTarget eventTarget = event.getEventTarget();
if (!Element.is(eventTarget)) {
return;
}
final Element target = event.getEventTarget().cast();
// Forward the event to the cell.
String idxString = "";
Element cellTarget = target;
while ((cellTarget != null) && ((idxString = cellTarget.getAttribute("__idx")).length() == 0)) {
cellTarget = cellTarget.getParentElement();
}
if (idxString.length() > 0) {
// Select the item if the cell does not consume events. Selection occurs
// before firing the event to the cell in case the cell operates on the
// currently selected item.
String eventType = event.getType();
boolean isClick = BrowserEvents.CLICK.equals(eventType);
int idx = Integer.parseInt(idxString);
int indexOnPage = idx - getPageStart();
if (!isRowWithinBounds(indexOnPage)) {
// If the event causes us to page, then the index will be out of bounds.
return;
}
// Get the cell parent before doing selection in case the list is redrawn.
boolean isSelectionHandled = cell.handlesSelection() || HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.BOUND_TO_SELECTION == getKeyboardSelectionPolicy();
Element cellParent = getCellParent(cellTarget);
T value = getVisibleItem(indexOnPage);
Context context = new Context(idx, 0, getValueKey(value));
CellPreviewEvent<T> previewEvent = CellPreviewEvent.fire(this, event, this, context, value, cellIsEditing, isSelectionHandled);
// Fire the event to the cell if the list has not been refreshed.
if (!previewEvent.isCanceled()) {
fireEventToCell(context, event, cellParent, value);
}
}
}
use of org.gwtproject.dom.client.EventTarget in project gwtproject by treblereel.
the class ImageLoadingCell method eventOccurredOnImage.
/**
* Check whether or not an event occurred within the wrapper around the image element.
*
* @param event the event
* @param parent the parent element
* @return true if the event targets the image
*/
private boolean eventOccurredOnImage(NativeEvent event, Element parent) {
EventTarget eventTarget = event.getEventTarget();
if (!Element.is(eventTarget)) {
return false;
}
Element target = eventTarget.cast();
// Make sure the target occurred within the div around the image.
Element imgWrapper = parent.getFirstChildElement().getNextSiblingElement();
return imgWrapper.isOrHasChild(target);
}
Aggregations