@Override public void onBrowserEvent(Event event) { if (disabled || readonly) { return; } final Element targ = DOM.eventGetTarget(event); if (DOM.eventGetType(event) == Event.ONMOUSEWHEEL) { processMouseWheelEvent(event); } else if (dragging || targ == handle) { processHandleEvent(event); } else if (targ == smaller) { decreaseValue(true); } else if (targ == bigger) { increaseValue(true); } else if (DOM.eventGetType(event) == Event.MOUSEEVENTS) { processBaseEvent(event); } else if ((BrowserInfo.get().isGecko() && DOM.eventGetType(event) == Event.ONKEYPRESS) || (!BrowserInfo.get().isGecko() && DOM.eventGetType(event) == Event.ONKEYDOWN)) { if (handleNavigation(event.getKeyCode(), event.getCtrlKey(), event.getShiftKey())) { feedbackPopup.show(); delayedValueUpdater.trigger(); DOM.eventPreventDefault(event); DOM.eventCancelBubble(event, true); } } else if (targ.equals(getElement()) && DOM.eventGetType(event) == Event.ONFOCUS) { feedbackPopup.show(); } else if (targ.equals(getElement()) && DOM.eventGetType(event) == Event.ONBLUR) { feedbackPopup.hide(); } else if (DOM.eventGetType(event) == Event.ONMOUSEDOWN) { feedbackPopup.show(); processBaseEvent(event); } if (Util.isTouchEvent(event)) { event.preventDefault(); // avoid simulated events event.stopPropagation(); } if (client != null) { client.handleTooltipEvent(event, this); } }
private void setValue(Double value, boolean updateToServer) { if (value == null) { return; } if (value < min) { value = min; } else if (value > max) { value = max; } // Update handle position final String styleAttribute = vertical ? "marginTop" : "marginLeft"; final String domProperty = vertical ? "offsetHeight" : "offsetWidth"; final int handleSize = Integer.parseInt(DOM.getElementProperty(handle, domProperty)); final int baseSize = Integer.parseInt(DOM.getElementProperty(base, domProperty)) - (2 * BASE_BORDER_WIDTH); final int range = baseSize - handleSize; double v = value.doubleValue(); // Round value to resolution if (resolution > 0) { v = Math.round(v * Math.pow(10, resolution)); v = v / Math.pow(10, resolution); } else { v = Math.round(v); } final double valueRange = max - min; double p = 0; if (valueRange > 0) { p = range * ((v - min) / valueRange); } if (p < 0) { p = 0; } if (vertical) { // IE6 rounding behaves a little unstable, reduce one pixel so the // containing element (base) won't expand without limits p = range - p - (BrowserInfo.get().isIE6() ? 1 : 0); } final double pos = p; DOM.setStyleAttribute(handle, styleAttribute, (Math.round(pos)) + "px"); // Update value this.value = new Double(v); setFeedbackValue(v); if (updateToServer) { updateValueToServer(); } }