CustomButton class
CustomButton is a base button class with built in support for a set number of button faces.
Each face has its own style modifier. For example, the state for down and hovering is assigned the CSS modifier <i>down-hovering</i>. So, if the button's overall style name is <i>gwt-PushButton</i> then when showing the <code>down-hovering</code> face, the button's style is <i> gwt-PushButton-down-hovering</i>. The overall style name can be used to change the style of the button irrespective of the current face.
Each button face can be assigned is own image, text, or html contents. If no
content is defined for a face, then the face will use the contents of another
face. For example, if down-hovering
does not have defined
contents, it will use the contents defined by the down
face.
The supported faces are defined below:
CSS style name | Getter method | description of face | defaults to contents of face |
up | {@link #getUpFace()} | face shown when button is up | none |
down | {@link #getDownFace()} | face shown when button is down | up |
up-hovering | {@link #getUpHoveringFace()} | face shown when button is up and hovering | up |
up-disabled | {@link #getUpDisabledFace()} | face shown when button is up and disabled | up |
down-hovering | {@link #getDownHoveringFace()} | face shown when button is down and hovering | down |
down-disabled | {@link #getDownDisabledFace()} | face shown when button is down and disabled | down |
Use in UiBinder Templates
When working with CustomButton subclasses in {@link com.google.gwt.uibinder.client.UiBinder UiBinder} templates, you can set text and assign ImageResources for their various faces via child elements: <p> <dl> <dt><g:upFace> <dt><g:downFace> <dt><g:upHoveringFace> <dt><g:downHoveringFace> <dt><g:upDisabledFace> <dt><g:downDisabledFace> </dl>
Each face element can take an optional <code>image</code> attribute and an html body. For example:<pre> <ui:image field='downButton'/> <!-- define an {@link com.google.gwt.resources.client.ImageResource ImageResource} -->
<g:PushButton ui:field='pushButton' enabled='true'> <g:upFace>
<b>click me</b>
</gwt:upFace> <g:upHoveringFace>
<b>Click ME!</b>
</gwt:upHoveringFace>
<g:downFace image='{downButton}'/> <g:downHoveringFace image='{downButton}'/> </g:PushButton> </pre>
class CustomButton extends ButtonBase { static String _STYLENAME_DEFAULT = "dwt-CustomButton"; /** * Pressed Attribute bit. */ static const int _DOWN_ATTRIBUTE = 1; /** * Hovering Attribute bit. */ static const int _HOVERING_ATTRIBUTE = 2; /** * Disabled Attribute bit. */ static const int _DISABLED_ATTRIBUTE = 4; /** * ID for up face. */ static const int _UP = 0; /** * ID for down face. */ static const int _DOWN = _DOWN_ATTRIBUTE; /** * ID for _upHovering face. */ static const int _UP_HOVERING = _HOVERING_ATTRIBUTE; /** * ID for _downHovering face. */ static const int _DOWN_HOVERING = _DOWN_ATTRIBUTE | _HOVERING_ATTRIBUTE; /** * ID for _upDisabled face. */ static const int _UP_DISABLED = _DISABLED_ATTRIBUTE; /** * ID for _downDisabled face. */ static const int _DOWN_DISABLED = _DOWN | _DISABLED_ATTRIBUTE; /** * The button's current face element. */ dart_html.Element _curFaceElement; /** * The button's current face. */ Face _curFace; /** * Face for up. */ Face _up; /** * Face for down. */ Face _down; /** * Face for downHover. */ Face _downHovering; /** * Face for upHover. */ Face _upHovering; /** * Face for _upDisabled. */ Face _upDisabled; /** * Face for _downDisabled. */ Face _downDisabled; /** * If <code>true</code>, this widget is capturing with the mouse held down. */ bool _isCapturing = false; /** * If <code>true</code>, this widget has focus with the space bar down. */ bool _isFocusing = false; /** * Used to decide whether to allow clicks to propagate up to the superclass * or container elements. */ bool _allowClick = false; /** * Constructor for <code>CustomButton</code>. * * @param upImage image for the default (up) face of the button */ CustomButton.fromImage(Image upImage, {Image downImage:null, ClickHandler handler:null}) : super(FocusPanel.impl.createFocusable()) { _init(); // getUpFace().setImage(upImage); // if (downImage != null) { getDownFace().setImage(downImage); } // if (handler != null) { addClickHandler(handler); } } /** * Constructor for <code>CustomButton</code>. * * @param upText the text for the default (up) face of the button */ CustomButton.fromText(String upText, {String downText:null, ClickHandler handler:null}) : super(FocusPanel.impl.createFocusable()) { _init(); // getUpFace().text = upText; // if (downText != null) { getDownFace().text = downText; } // if (handler != null) { addClickHandler(handler); } } CustomButton.internal() : super(FocusPanel.impl.createFocusable()) { _init(); } /** * Constructor for <code>CustomButton</code>. */ void _init() { // Use FocusPanel.impl rather than FocusWidget because only FocusPanel.impl // works across browsers to create a focusable element. sinkEvents(IEvent.ONCLICK | IEvent.MOUSEEVENTS | IEvent.FOCUSEVENTS | IEvent.KEYEVENTS); // setUpFace(_createFace(null, "up", _UP)); clearAndSetStyleName(_STYLENAME_DEFAULT); // Add a11y role "button" Roles.BUTTON.set(getElement()); } //******** // Up Face //******** /** * Gets the up face of the button. * * @return the up face */ Face getUpFace() { return _up; } /** * Gets the _upDisabled face of the button. * * @return the _upDisabled face */ Face getUpDisabledFace() { if (_upDisabled == null) { _setUpDisabledFace(_createFace(getUpFace(), "up-disabled", _UP_DISABLED)); } return _upDisabled; } /** * Gets the _upHovering face of the button. * * @return the _upHovering face */ Face getUpHoveringFace() { if (_upHovering == null) { _setUpHoveringFace(_createFace(getUpFace(), "up-hovering", _UP_HOVERING)); } return _upHovering; } //********** // Down Face //********** /** * Gets the down face of the button. * * @return the down face */ Face getDownFace() { if (_down == null) { _setDownFace(_createFace(getUpFace(), "down", _DOWN)); } return _down; } /** * Gets the _downDisabled face of the button. * * @return the _downDisabled face */ Face getDownDisabledFace() { if (_downDisabled == null) { _setDownDisabledFace(_createFace(getDownFace(), "down-disabled", _DOWN_DISABLED)); } return _downDisabled; } /** * Gets the _downHovering face of the button. * * @return the _downHovering face */ Face getDownHoveringFace() { if (_downHovering == null) { _setDownHoveringFace(_createFace(getDownFace(), "down-hovering", _DOWN_HOVERING)); } return _downHovering; } //************* // Current face //************* /** * Gets the current face's html. * * @return current face's html */ String get html => getCurrentFace().html; /** * Sets the current face's html. * * @param html html to set */ void set html(String value) { getCurrentFace().html = value; } int get tabIndex => FocusPanel.impl.getTabIndex(getElement()); void set tabIndex(int index) { FocusPanel.impl.setTabIndex(getElement(), index); } /** * Gets the current face's text. * * @return current face's text */ String get text => getCurrentFace().text; /** * Sets the current face's text. * * @param text text to set */ void set text(String value) { getCurrentFace().text = value; } /** * Is this button down? * * @return <code>true</code> if the button is down */ bool isDown() { return (_DOWN_ATTRIBUTE & getCurrentFace().getFaceID()) > 0; } //******* // Events //******* void onBrowserEvent(dart_html.Event event) { // Should not act on button if disabled. if (!enabled) { // This can happen when events are bubbled up from non-disabled children return; } int type = Dom.eventGetType(event); switch (type) { case IEvent.ONCLICK: // If clicks are currently disallowed, keep it from bubbling or being // passed to the superclass. if (!_allowClick) { event.stopPropagation(); return; } break; case IEvent.ONMOUSEDOWN: if (getMouseEvent(event).button == IEvent.BUTTON_LEFT) { setFocus(true); onClickStart(); Dom.setCapture(getElement()); _isCapturing = true; // Prevent dragging (on some browsers); event.preventDefault(); } break; case IEvent.ONMOUSEUP: if (_isCapturing) { _isCapturing = false; Dom.releaseCapture(getElement()); if (isHovering() && getMouseEvent(event).button == IEvent.BUTTON_LEFT) { onClick(); } } break; case IEvent.ONMOUSEMOVE: if (_isCapturing) { // Prevent dragging (on other browsers); event.preventDefault(); } break; case IEvent.ONMOUSEOUT: dart_html.Element to = Dom.eventGetToElement(event); if (Dom.isOrHasChild(getElement(), event.target) && (to == null || !Dom.isOrHasChild(getElement(), to))) { if (_isCapturing) { onClickCancel(); } setHovering(false); } break; case IEvent.ONMOUSEOVER: if (Dom.isOrHasChild(getElement(), event.target)) { setHovering(true); if (_isCapturing) { onClickStart(); } } break; case IEvent.ONBLUR: if (_isFocusing) { _isFocusing = false; onClickCancel(); } break; case IEvent.ONLOSECAPTURE: if (_isCapturing) { _isCapturing = false; onClickCancel(); } break; } super.onBrowserEvent(event); // Synthent is size clicks based on keyboard events AFTER the normal key handling. if ((event is dart_html.KeyboardEvent) && (IEvent.getTypeInt(event.type) & IEvent.KEYEVENTS) != 0) { int keyCode = (event as dart_html.KeyboardEvent).keyCode; switch (type) { case IEvent.ONKEYDOWN: if (keyCode == ' '.codeUnitAt(0)) { _isFocusing = true; onClickStart(); } break; case IEvent.ONKEYUP: if (_isFocusing && keyCode == ' '.codeUnitAt(0)) { _isFocusing = false; onClick(); } break; case IEvent.ONKEYPRESS: if (keyCode == '\n'.codeUnitAt(0) || keyCode == '\r'.codeUnitAt(0)) { onClickStart(); onClick(); } break; } } } dart_html.MouseEvent getMouseEvent(dart_html.Event evt) { return evt as dart_html.MouseEvent; } void setAccessKey(int key) { FocusPanel.impl.setAccessKey(getElement(), key); } /** * Sets whether this button is enabled. * * @param enabled <code>true</code> to enable the button, <code>false</code> * to disable it */ void set enabled(bool value) { if (enabled != value) { toggleDisabled(); super.enabled = value; if (!value) { cleanupCaptureState(); Roles.BUTTON.removeAriaPressedState(getElement()); } else { _setAriaPressed(getCurrentFace()); } } } void setFocus(bool focused) { if (focused) { FocusPanel.impl.focus(getElement()); } else { FocusPanel.impl.blur(getElement()); } } /** * Overridden on attach to ensure that a button face has been chosen before * the button is displayed. */ void onAttach() { finishSetup(); super.onAttach(); } void onDetach() { super.onDetach(); cleanupCaptureState(); setHovering(false); } /** * Called when the user finishes clicking on this button. The default behavior * is to fire the click event to listeners. Subclasses that override * {@link #onClickStart()} should override this method to restore the normal * widget display. */ void onClick() { // Allow the click we're about to synthesize to pass through to the // superclass and containing elements. Element.dispatchEvent() is // synchronous, so we simply set and clear the flag within this method. _allowClick = true; // Mouse coordinates are not always available (e.g., when the click is // caused by a keyboard event). //NativeEvent evt = Document.get().createClickEvent(1, 0, 0, 0, 0, false, false, false, false); // Create Dom CustomEvent // dart_html.CustomEvent evt = dart_html.document.$dom_createEvent('CustomEvent'); // After Dom CustomEvent instance has been created we can initialise it here // evt.$dom_initCustomEvent('CustomEvent', false, false, false); dart_html.CustomEvent evt = new dart_html.CustomEvent('CustomEvent', canBubble: false, cancelable: false, detail: false); // Dispatch event getElement().dispatchEvent(evt); _allowClick = false; } /** * Called when the user aborts a click in progress; for example, by dragging * the mouse outside of the button before releasing the mouse button. * Subclasses that override {@link #onClickStart()} should override this * method to restore the normal widget display. */ void onClickCancel() { } /** * Called when the user begins to click on this button. Subclasses may * override this method to display the start of the click visually; such * subclasses should also override {@link #onClick()} and * {@link #onClickCancel()} to restore normal visual state. Each * <code>onClickStart</code> will eventually be followed by either * <code>onClick</code> or <code>onClickCancel</code>, depending on whether * the click is completed. */ void onClickStart() { } /** * Sets whether this button is down. * * @param down <code>true</code> to press the button, <code>false</code> * otherwise */ void setDown(bool down) { if (down != isDown()) { toggleDown(); } } /** * Common setup between constructors. */ void finishSetup() { if (_curFace == null) { setCurrentFace(getUpFace()); } } void fireClickListeners(dart_html.Event nativeEvent) { // TODO(ecc) Once event triggering is committed, should fire a native click event instead. fireEvent(new ClickEvent()); } /** * Gets the current face of the button. * * @return the current face */ Face getCurrentFace() { /* * Implementation note: Package protected so we can use it when testing the * button. */ finishSetup(); return _curFace; } void setCurrentFace(Face newFace) { /* * Implementation note: default access for testing. */ if (_curFace != newFace) { if (_curFace != null) { removeStyleDependentName(_curFace.getName()); } _curFace = newFace; _setCurrentFaceElement(newFace.getFace()); addStyleDependentName(_curFace.getName()); if (enabled) { _setAriaPressed(newFace); } } } /** * Sets the current face based on the faceID. * * @param faceID sets the new face of the button */ void _setCurrentFace(int faceID) { Face newFace = _getFaceFromID(faceID); setCurrentFace(newFace); } /** * Is the mouse hovering over this button? * * @return <code>true</code> if the mouse is hovering */ bool isHovering() { return (_HOVERING_ATTRIBUTE & getCurrentFace().getFaceID()) > 0; } /** * Sets whether this button is hovering. * * @param hovering is this button hovering? */ void setHovering(bool hovering) { if (hovering != isHovering()) { toggleHover(); } } /** * Toggle the up/down attribute. */ void toggleDown() { int newFaceID = getCurrentFace().getFaceID() ^ _DOWN_ATTRIBUTE; _setCurrentFace(newFaceID); } /** * Resets internal state if this button can no longer service events. This can * occur when the widget becomes detached or disabled. */ void cleanupCaptureState() { if (_isCapturing || _isFocusing) { Dom.releaseCapture(getElement()); _isCapturing = false; _isFocusing = false; onClickCancel(); } } Face _createFace(Face delegateTo, String name, int faceID) { return new SimpleFace(this, delegateTo, name, faceID); } Face _getFaceFromID(int id) { switch (id) { case _DOWN: return getDownFace(); case _UP: return getUpFace(); case _DOWN_HOVERING: return getDownHoveringFace(); case _UP_HOVERING: return getUpHoveringFace(); case _UP_DISABLED: return getUpDisabledFace(); case _DOWN_DISABLED: return getDownDisabledFace(); default: throw new Exception("$id is not a known face id."); } } void _setAriaPressed(Face newFace) { bool pressed = (newFace.getFaceID() & _DOWN_ATTRIBUTE) == 1; Roles.BUTTON.setAriaPressedState(getElement(), PressedValue.of(pressed)); } void _setCurrentFaceElement(dart_html.Element newFaceElement) { if (_curFaceElement != newFaceElement) { if (_curFaceElement != null) { //Dom.removeChild(getElement(), _curFaceElement); _curFaceElement.remove(); } _curFaceElement = newFaceElement; //Dom.appendChild(getElement(), _curFaceElement); getElement().append(_curFaceElement); } } /** * Sets the _downDisabled face of the button. * * @param _downDisabled _downDisabled face */ void _setDownDisabledFace(Face _downDisabled) { this._downDisabled = _downDisabled; } /** * Sets the down face of the button. * * @param down the down face */ void _setDownFace(Face down) { this._down = down; } /** * Sets the _downHovering face of the button. * * @param _downHovering hoverDown face */ void _setDownHoveringFace(Face _downHovering) { this._downHovering = _downHovering; } /** * Sets the _upDisabled face of the button. * * @param _upDisabled _upDisabled face */ void _setUpDisabledFace(Face _upDisabled) { this._upDisabled = _upDisabled; } /** * Sets the up face of the button. * * @param up up face */ void setUpFace(Face up) { this._up = up; } /** * Sets the _upHovering face of the button. * * @param _upHovering _upHovering face */ void _setUpHoveringFace(Face _upHovering) { this._upHovering = _upHovering; } /** * Toggle the disabled attribute. */ void toggleDisabled() { // Toggle disabled. int newFaceID = getCurrentFace().getFaceID() ^ _DISABLED_ATTRIBUTE; // Remove hovering. newFaceID &= ~_HOVERING_ATTRIBUTE; // Sets the current face. _setCurrentFace(newFaceID); } /** * Toggle the hovering attribute. */ void toggleHover() { // Toggle hovering. int newFaceID = getCurrentFace().getFaceID() ^ _HOVERING_ATTRIBUTE; // Remove disabled. newFaceID &= ~_DISABLED_ATTRIBUTE; _setCurrentFace(newFaceID); } }
Extends
UiObject > Widget > FocusWidget > ButtonBase > CustomButton
Subclasses
Constructors
new CustomButton.fromImage(Image upImage, {Image downImage: null, ClickHandler handler: null}) #
Constructor for <code>CustomButton</code>.
@param upImage image for the default (up) face of the button
CustomButton.fromImage(Image upImage, {Image downImage:null, ClickHandler handler:null}) : super(FocusPanel.impl.createFocusable()) { _init(); // getUpFace().setImage(upImage); // if (downImage != null) { getDownFace().setImage(downImage); } // if (handler != null) { addClickHandler(handler); } }
new CustomButton.fromText(String upText, {String downText: null, ClickHandler handler: null}) #
Constructor for <code>CustomButton</code>.
@param upText the text for the default (up) face of the button
CustomButton.fromText(String upText, {String downText:null, ClickHandler handler:null}) : super(FocusPanel.impl.createFocusable()) { _init(); // getUpFace().text = upText; // if (downText != null) { getDownFace().text = downText; } // if (handler != null) { addClickHandler(handler); } }
new CustomButton.internal() #
CustomButton.internal() : super(FocusPanel.impl.createFocusable()) { _init(); }
Properties
void set accessKey(int key) #
Sets the widget's 'access key'. This key is used (in conjunction with a browser-specific modifier key) to automatically focus the widget.
@param key the widget's access key
void set accessKey(int key) { //Dom.setElementProperty(getElement(), "accessKey", "" + key); }
bool get enabled #
Gets whether this widget is enabled.
@return <code>true</code> if the widget is enabled
bool get enabled => !Dom.getElementPropertyBoolean(getElement(), "disabled");
void set enabled(bool value) #
Sets whether this button is enabled.
@param enabled <code>true</code> to enable the button, <code>false</code> to disable it
void set enabled(bool value) { if (enabled != value) { toggleDisabled(); super.enabled = value; if (!value) { cleanupCaptureState(); Roles.BUTTON.removeAriaPressedState(getElement()); } else { _setAriaPressed(getCurrentFace()); } } }
int eventsToSink #
A set og events that should be sunk when the widget is attached to the DOM. (We delay the sinking of events to improve startup performance.) When the widget is attached, this is set is empty
Package protected to allow Composite to see it.
int eventsToSink = 0
void set focus(bool focused) #
Explicitly focus/unfocus this widget. Only one widget can have focus at a time, and the widget that does will receive all keyboard events.
@param focused whether this widget should take focus or release it
void set focus(bool focused) { if (focused) { impl.focus(getElement()); } else { impl.blur(getElement()); } }
String get html #
Gets the current face's html.
@return current face's html
String get html => getCurrentFace().html;
void set html(String value) #
Sets the current face's html.
@param html html to set
void set html(String value) { getCurrentFace().html = value; }
int get tabIndex #
Gets the widget's position in the tab index.
@return the widget's tab index
int get tabIndex => FocusPanel.impl.getTabIndex(getElement());
void set tabIndex(int index) #
Sets the widget's position in the tab index. If more than one widget has the same tab index, each such widget will receive focus in an arbitrary order. Setting the tab index to <code>-1</code> will cause this widget to be removed from the tab order.
@param index the widget's tab index
void set tabIndex(int index) { FocusPanel.impl.setTabIndex(getElement(), index); }
String get text #
Gets the current face's text.
@return current face's text
String get text => getCurrentFace().text;
void set text(String value) #
Sets the current face's text.
@param text text to set
void set text(String value) { getCurrentFace().text = value; }
String get title #
Gets the title associated with this object. The title is the 'tool-tip' displayed to users when they hover over the object.
@return the object's title
String get title => getElement().title;
void set title(String value) #
Sets the element's title.
void set title(String value) { getElement().title = value; }
bool get visible #
Determines whether or not this object is visible. Note that this does not necessarily take into account whether or not the receiver's parent is visible, or even if it is attached to the Document. The default implementation of this trait in UIObject is based on the value of a dom element's style object's display attribute.
@return <code>true</code> if the object is visible
bool get visible => isVisible(getElement());
Methods
HandlerRegistration addAttachHandler(AttachEventHandler handler) #
Adds an AttachEvent handler.
@param handler the handler @return the handler registration
HandlerRegistration addAttachHandler(AttachEventHandler handler) { return addHandler(handler, AttachEvent.TYPE); }
HandlerRegistration addBitlessDomHandler(EventHandler handler, DomEventType type) #
For <a href= "http://code.google.com/p/google-web-toolkit/wiki/UnderstandingMemoryLeaks"
browsers which do not leak</a>, adds a native event handler to the widget.
Note that, unlike the {@link #addDomHandler(EventHandler, com.google.gwt.event.dom.client.DomEvent.Type)} implementation, there is no need to attach the widget to the DOM in order to cause the event handlers to be attached.
@param <H> the type of handler to add @param type the event key @param handler the handler @return {@link HandlerRegistration} used to remove the handler
HandlerRegistration addBitlessDomHandler(EventHandler handler, DomEventType type) { assert (handler != null);; // : "handler must not be null"; assert (type != null); // : "type must not be null"; sinkBitlessEvent(type.eventName); return ensureHandlers().addHandler(type, handler); }
HandlerRegistration addBlurHandler(BlurHandler handler) #
Adds a {@link BlurEvent} handler.
@param handler the blur handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addBlurHandler(BlurHandler handler) { return addDomHandler(handler, BlurEvent.TYPE); }
HandlerRegistration addClickHandler(ClickHandler handler) #
Adds a {@link ClickEvent} handler.
@param handler the click handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addClickHandler(ClickHandler handler) { return addDomHandler(handler, ClickEvent.TYPE); }
HandlerRegistration addDomHandler(EventHandler handler, DomEventType type) #
Adds a native event handler to the widget and sinks the corresponding native event. If you do not want to sink the native event, use the generic addHandler method instead.
@param <H> the type of handler to add @param type the event key @param handler the handler @return {@link HandlerRegistration} used to remove the handler
HandlerRegistration addDomHandler(EventHandler handler, DomEventType type) { assert (handler != null); // : "handler must not be null"; assert (type != null); // : "type must not be null"; int typeInt = IEvent.getTypeInt(type.eventName); if (typeInt == -1) { sinkBitlessEvent(type.eventName); } else { sinkEvents(typeInt); } return ensureHandlers().addHandler(type, handler); }
HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler) #
Adds a {@link DoubleClickEvent} handler.
@param handler the double click handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler) { return addDomHandler(handler, DoubleClickEvent.TYPE); }
HandlerRegistration addDragEndHandler(DragEndHandler handler) #
Adds a {@link DragEndEvent} handler.
@param handler the drag end handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addDragEndHandler(DragEndHandler handler) { return addBitlessDomHandler(handler, DragEndEvent.TYPE); }
HandlerRegistration addDragEnterHandler(DragEnterHandler handler) #
Adds a {@link DragEnterEvent} handler.
@param handler the drag end handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addDragEnterHandler(DragEnterHandler handler) { return addBitlessDomHandler(handler, DragEnterEvent.TYPE); }
HandlerRegistration addDragHandler(DragHandler handler) #
Adds a {@link DragEvent} handler.
@param handler the drag handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addDragHandler(DragHandler handler) { return addBitlessDomHandler(handler, DragEvent.TYPE); }
HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler) #
Adds a {@link DragLeaveEvent} handler.
@param handler the drag leave handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler) { return addBitlessDomHandler(handler, DragLeaveEvent.TYPE); }
HandlerRegistration addDragOverHandler(DragOverHandler handler) #
Adds a {@link DragOverEvent} handler.
@param handler the drag over handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addDragOverHandler(DragOverHandler handler) { return addBitlessDomHandler(handler, DragOverEvent.TYPE); }
HandlerRegistration addDragStartHandler(DragStartHandler handler) #
Adds a {@link DragStartEvent} handler.
@param handler the drag start handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addDragStartHandler(DragStartHandler handler) { return addBitlessDomHandler(handler, DragStartEvent.TYPE); }
HandlerRegistration addDropHandler(DropHandler handler) #
Adds a {@link DropEvent} handler.
@param handler the drop handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addDropHandler(DropHandler handler) { return addBitlessDomHandler(handler, DropEvent.TYPE); }
HandlerRegistration addFocusHandler(FocusHandler handler) #
Adds a {@link FocusEvent} handler.
@param handler the focus handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addFocusHandler(FocusHandler handler) { return addDomHandler(handler, FocusEvent.TYPE); }
HandlerRegistration addGestureChangeHandler(GestureChangeHandler handler) #
HandlerRegistration addGestureChangeHandler(GestureChangeHandler handler) { return addDomHandler(handler, GestureChangeEvent.TYPE); }
HandlerRegistration addGestureEndHandler(GestureEndHandler handler) #
HandlerRegistration addGestureEndHandler(GestureEndHandler handler) { return addDomHandler(handler, GestureEndEvent.TYPE); }
HandlerRegistration addGestureStartHandler(GestureStartHandler handler) #
HandlerRegistration addGestureStartHandler(GestureStartHandler handler) { return addDomHandler(handler, GestureStartEvent.TYPE); }
HandlerRegistration addHandler(EventHandler handler, EventType<EventHandler> type) #
Adds this handler to the widget.
@param <H> the type of handler to add @param type the event type @param handler the handler @return {@link HandlerRegistration} used to remove the handler
HandlerRegistration addHandler(EventHandler handler, EventType<EventHandler> type) { return ensureHandlers().addHandler(type, handler); }
HandlerRegistration addKeyDownHandler(KeyDownHandler handler) #
Adds a {@link KeyDownEvent} handler.
@param handler the key down handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addKeyDownHandler(KeyDownHandler handler) { return addDomHandler(handler, KeyDownEvent.TYPE); }
HandlerRegistration addKeyPressHandler(KeyPressHandler handler) #
Adds a {@link KeyPressEvent} handler.
@param handler the key press handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addKeyPressHandler(KeyPressHandler handler) { return addDomHandler(handler, KeyPressEvent.TYPE); }
HandlerRegistration addKeyUpHandler(KeyUpHandler handler) #
Adds a {@link KeyUpEvent} handler.
@param handler the key up handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addKeyUpHandler(KeyUpHandler handler) { return addDomHandler(handler, KeyUpEvent.TYPE); }
HandlerRegistration addMouseDownHandler(MouseDownHandler handler) #
Adds a {@link MouseDownEvent} handler.
@param handler the mouse down handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addMouseDownHandler(MouseDownHandler handler) { return addDomHandler(handler, MouseDownEvent.TYPE); }
HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) #
Adds a {@link MouseMoveEvent} handler.
@param handler the mouse move handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) { return addDomHandler(handler, MouseMoveEvent.TYPE); }
HandlerRegistration addMouseOutHandler(MouseOutHandler handler) #
Adds a {@link MouseOutEvent} handler.
@param handler the mouse out handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addMouseOutHandler(MouseOutHandler handler) { return addDomHandler(handler, MouseOutEvent.TYPE); }
HandlerRegistration addMouseOverHandler(MouseOverHandler handler) #
Adds a {@link MouseOverEvent} handler.
@param handler the mouse over handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addMouseOverHandler(MouseOverHandler handler) { return addDomHandler(handler, MouseOverEvent.TYPE); }
HandlerRegistration addMouseUpHandler(MouseUpHandler handler) #
Adds a {@link MouseUpEvent} handler.
@param handler the mouse up handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addMouseUpHandler(MouseUpHandler handler) { return addDomHandler(handler, MouseUpEvent.TYPE); }
HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler) #
Adds a {@link MouseWheelEvent} handler.
@param handler the mouse wheel handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler) { return addDomHandler(handler, MouseWheelEvent.TYPE); }
void addStyleDependentName(String styleSuffix) #
Adds a dependent style name by specifying the style name's suffix. The actual form of the style name that is added is:
getStylePrimaryName() + '-' + styleSuffix
@param styleSuffix the suffix of the dependent style to be added. @see #setStylePrimaryName(String) @see #removeStyleDependentName(String) @see #setStyleDependentName(String, boolean) @see #addStyleName(String)
void addStyleDependentName(String styleSuffix) { setStyleDependentName(styleSuffix, true); }
void addStyleName(String style) #
Adds a secondary or dependent style name to this object. A secondary style name is an additional style name that is, in HTML/CSS terms, included as a space-separated token in the value of the CSS <code>class</code> attribute for this object's root element.
The most important use for this method is to add a special kind of
secondary style name called a dependent style name. To add a
dependent style name, use {@link #addStyleDependentName(String)}, which
will prefix the 'style' argument with the result of
{@link #k()} (followed by a '-'). For example, suppose
the primary style name is gwt-TextBox
. If the following method
is called as obj.setReadOnly(true)
:
public void setReadOnly(boolean readOnly) { isReadOnlyMode = readOnly;// Create a dependent style name. String readOnlyStyle = "readonly";
if (readOnly) {
addStyleDependentName(readOnlyStyle);
} else {
removeStyleDependentName(readOnlyStyle);
} }</pre>
then both of the CSS style rules below will be applied:
// This rule is based on the primary style name and is always active. .gwt-TextBox { font-size: 12pt; }
// This rule is based on a dependent style name that is only active // when the widget has called addStyleName(getStylePrimaryName() + // "-readonly"). .gwt-TextBox-readonly { background-color: lightgrey; border: none; }</pre>
The code can also be simplified with {@link #setStyleDependentName(String, boolean)}:
public void setReadOnly(boolean readOnly) { isReadOnlyMode = readOnly; setStyleDependentName("readonly", readOnly); }Dependent style names are powerful because they are automatically updated whenever the primary style name changes. Continuing with the example above, if the primary style name changed due to the following call:
setStylePrimaryName("my-TextThingy");then the object would be re-associated with following style rules, removing those that were shown above.
.my-TextThingy { font-size: 20pt; }.my-TextThingy-readonly { background-color: red; border: 2px solid yellow; }</pre>
Secondary style names that are not dependent style names are not automatically updated when the primary style name changes.
@param style the secondary style name to be added @see UIObject @see #removeStyleName(String)
void addStyleName(String style) { setStyleName(style, true); }
HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) #
Adds a {@link TouchCancelEvent} handler.
@param handler the touch cancel handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) { return addDomHandler(handler, TouchCancelEvent.TYPE); }
HandlerRegistration addTouchEndHandler(TouchEndHandler handler) #
Adds a {@link TouchEndEvent} handler.
@param handler the touch end handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addTouchEndHandler(TouchEndHandler handler) { return addDomHandler(handler, TouchEndEvent.TYPE); }
HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) #
Adds a {@link TouchMoveEvent} handler.
@param handler the touch move handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) { return addDomHandler(handler, TouchMoveEvent.TYPE); }
HandlerRegistration addTouchStartHandler(TouchStartHandler handler) #
Adds a {@link TouchStartEvent} handler.
@param handler the touch start handler @return {@link HandlerRegistration} used to remove this handler
HandlerRegistration addTouchStartHandler(TouchStartHandler handler) { return addDomHandler(handler, TouchStartEvent.TYPE); }
Widget asWidget() #
Returns the Widget aspect of the receiver.
Widget asWidget() { return this; }
void cleanupCaptureState() #
Resets internal state if this button can no longer service events. This can occur when the widget becomes detached or disabled.
void cleanupCaptureState() { if (_isCapturing || _isFocusing) { Dom.releaseCapture(getElement()); _isCapturing = false; _isFocusing = false; onClickCancel(); } }
void clearAndSetStyleName(String style) #
Clears all of the object's style names and sets it to the given style. You should normally use {@link #setStylePrimaryName(String)} unless you wish to explicitly remove all existing styles.
@param style the new style name @see #setStylePrimaryName(String)
void clearAndSetStyleName(String style) { setElementStyleName(getStyleElement(), style); }
EventBus createEventBus() #
Creates the SimpleEventBus used by this Widget. You can override this method to create a custom EventBus.
@return the EventBus you want to use.
EventBus createEventBus() { return new SimpleEventBus(); }
void delegateEvent(Widget target, DwtEvent event) #
Fires an event on a child widget. Used to delegate the handling of an event from one widget to another.
@param event the event @param target fire the event on the given target
void delegateEvent(Widget target, DwtEvent event) { target.fireEvent(event); }
void doAttachChildren() #
If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call {@link #onAttach()} for each of its child widgets.
@see #onAttach()
void doAttachChildren() { }
void doDetachChildren() #
If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call {@link #onDetach()} for each of its child widgets.
@see #onDetach()
void doDetachChildren() { }
EventBus ensureHandlers() #
Ensures the existence of the event bus.
@return the EventBus.
EventBus ensureHandlers() { return _eventBus == null ? _eventBus = createEventBus() : _eventBus; }
double extractLengthValue(String s) #
Intended to be used to pull the value out of a CSS length. If the value is "auto" or "inherit", 0 will be returned.
@param s The CSS length string to extract @return The leading numeric portion of <code>s</code>, or 0 if "auto" or
"inherit" are passed in.
double extractLengthValue(String s) { if (s == "auto" || s == "inherit" || s == "") { return 0.0; } else { // numberRegex divides the string into a leading numeric portion // followed by an arbitrary portion. if(numberRegex.hasMatch(s)) { // Extract the leading numeric portion of string s = numberRegex.firstMatch(s)[0]; } return double.parse(s); } }
void finishSetup() #
Common setup between constructors.
void finishSetup() { if (_curFace == null) { setCurrentFace(getUpFace()); } }
void fireClickListeners(Event nativeEvent) #
void fireClickListeners(dart_html.Event nativeEvent) { // TODO(ecc) Once event triggering is committed, should fire a native click event instead. fireEvent(new ClickEvent()); }
void fireEvent(DwtEvent event) #
Fires the given event to the handlers listening to the event's type.
Any exceptions thrown by handlers will be bundled into a UmbrellaException and then re-thrown after all handlers have completed. An exception thrown by a handler will not prevent other handlers from executing.
@param event the event
void fireEvent(DwtEvent event) { // if (_eventBus != null) { // _eventBus.fireEvent(event); // } if (_eventBus != null) { // If it not live we should revive it. if (!event.isLive()) { event.revive(); } Object oldSource = event.getSource(); event.overrideSource(getElement()); try { // May throw an UmbrellaException. _eventBus.fireEventFromSource(event, getElement()); } on UmbrellaException catch (e) { throw new UmbrellaException(e.causes); } finally { if (oldSource == null) { // This was my event, so I should kill it now that I'm done. event.kill(); } else { // Restoring the source for the next handler to use. event.overrideSource(oldSource); } } } }
int getAbsoluteLeft() #
Gets the object's absolute left position in pixels, as measured from the browser window's client area.
@return the object's absolute left position
int getAbsoluteLeft() { return Dom.getAbsoluteLeft(getElement()); }
int getAbsoluteTop() #
Gets the object's absolute top position in pixels, as measured from the browser window's client area.
@return the object's absolute top position
int getAbsoluteTop() { return Dom.getAbsoluteTop(getElement()); }
Face getCurrentFace() #
Gets the current face of the button.
@return the current face
Face getCurrentFace() { /* * Implementation note: Package protected so we can use it when testing the * button. */ finishSetup(); return _curFace; }
Face getDownDisabledFace() #
Gets the _downDisabled face of the button.
@return the _downDisabled face
Face getDownDisabledFace() { if (_downDisabled == null) { _setDownDisabledFace(_createFace(getDownFace(), "down-disabled", _DOWN_DISABLED)); } return _downDisabled; }
Face getDownFace() #
Gets the down face of the button.
@return the down face
Face getDownFace() { if (_down == null) { _setDownFace(_createFace(getUpFace(), "down", _DOWN)); } return _down; }
Face getDownHoveringFace() #
Gets the _downHovering face of the button.
@return the _downHovering face
Face getDownHoveringFace() { if (_downHovering == null) { _setDownHoveringFace(_createFace(getDownFace(), "down-hovering", _DOWN_HOVERING)); } return _downHovering; }
Element getElement() #
Gets this object's browser element.
dart_html.Element getElement() { assert (_element != null); // : MISSING_ELEMENT_ERROR; return _element; }
EventBus getEventBus() #
Return EventBus.
EventBus getEventBus() { return _eventBus; }
Object getLayoutData() #
Gets the panel-defined layout data associated with this widget.
@return the widget's layout data @see #setLayoutData
Object getLayoutData() { return _layoutData; }
MouseEvent getMouseEvent(Event evt) #
dart_html.MouseEvent getMouseEvent(dart_html.Event evt) { return evt as dart_html.MouseEvent; }
int getOffsetHeight() #
Gets the object's offset height in pixels. This is the total height of the object, including decorations such as border and padding, but not margin.
@return the object's offset height
int getOffsetHeight() { return getElement().offset.height; // Dom.getElementPropertyInt(getElement(), "offsetHeight"); }
int getOffsetWidth() #
Gets the object's offset width in pixels. This is the total width of the object, including decorations such as border and padding, but not margin.
@return the object's offset width
int getOffsetWidth() { return getElement().offset.width; // Dom.getElementPropertyInt(getElement(), "offsetWidth"); }
Widget getParent() #
Gets this widget's parent panel.
@return the widget's parent panel
Widget getParent() { return _parent; }
Element getStyleElement() #
Template method that returns the element to which style names will be applied. By default it returns the root element, but this method may be overridden to apply styles to a child element.
@return the element to which style names will be applied
dart_html.Element getStyleElement() { return getElement(); }
String getStyleName() #
Gets all of the object's style names, as a space-separated list. If you wish to retrieve only the primary style name, call {@link #getStylePrimaryName()}.
@return the objects's space-separated style names @see #getStylePrimaryName()
String getStyleName() { return getElementStyleName(getStyleElement()); }
String getStylePrimaryName() #
Gets the primary style name associated with the object.
@return the object's primary style name @see #setStyleName(String) @see #addStyleName(String) @see #removeStyleName(String)
String getStylePrimaryName() { return getElementStylePrimaryName(getStyleElement()); }
Face getUpDisabledFace() #
Gets the _upDisabled face of the button.
@return the _upDisabled face
Face getUpDisabledFace() { if (_upDisabled == null) { _setUpDisabledFace(_createFace(getUpFace(), "up-disabled", _UP_DISABLED)); } return _upDisabled; }
Face getUpFace() #
Gets the up face of the button.
@return the up face
Face getUpFace() { return _up; }
Face getUpHoveringFace() #
Gets the _upHovering face of the button.
@return the _upHovering face
Face getUpHoveringFace() { if (_upHovering == null) { _setUpHoveringFace(_createFace(getUpFace(), "up-hovering", _UP_HOVERING)); } return _upHovering; }
bool isAttached() #
Returns whether or not the receiver is attached to the {@link com.google.gwt.dom.client.Document Document}'s {@link com.google.gwt.dom.client.BodyElement BodyElement}.
@return true if attached, false otherwise
bool isAttached() { return _attached; }
bool isDown() #
Is this button down?
@return <code>true</code> if the button is down
bool isDown() { return (_DOWN_ATTRIBUTE & getCurrentFace().getFaceID()) > 0; }
bool isHovering() #
Is the mouse hovering over this button?
@return <code>true</code> if the mouse is hovering
bool isHovering() { return (_HOVERING_ATTRIBUTE & getCurrentFace().getFaceID()) > 0; }
bool isOrWasAttached() #
Has this widget ever been attached?
@return true if this widget ever been attached to the DOM, false otherwise
bool isOrWasAttached() { return eventsToSink == -1; }
void onAttach() #
Overridden on attach to ensure that a button face has been chosen before the button is displayed.
void onAttach() { finishSetup(); super.onAttach(); }
void onBrowserEvent(Event event) #
Fired whenever a browser event is received.
@param event the event received
TODO
void onBrowserEvent(dart_html.Event event) { // Should not act on button if disabled. if (!enabled) { // This can happen when events are bubbled up from non-disabled children return; } int type = Dom.eventGetType(event); switch (type) { case IEvent.ONCLICK: // If clicks are currently disallowed, keep it from bubbling or being // passed to the superclass. if (!_allowClick) { event.stopPropagation(); return; } break; case IEvent.ONMOUSEDOWN: if (getMouseEvent(event).button == IEvent.BUTTON_LEFT) { setFocus(true); onClickStart(); Dom.setCapture(getElement()); _isCapturing = true; // Prevent dragging (on some browsers); event.preventDefault(); } break; case IEvent.ONMOUSEUP: if (_isCapturing) { _isCapturing = false; Dom.releaseCapture(getElement()); if (isHovering() && getMouseEvent(event).button == IEvent.BUTTON_LEFT) { onClick(); } } break; case IEvent.ONMOUSEMOVE: if (_isCapturing) { // Prevent dragging (on other browsers); event.preventDefault(); } break; case IEvent.ONMOUSEOUT: dart_html.Element to = Dom.eventGetToElement(event); if (Dom.isOrHasChild(getElement(), event.target) && (to == null || !Dom.isOrHasChild(getElement(), to))) { if (_isCapturing) { onClickCancel(); } setHovering(false); } break; case IEvent.ONMOUSEOVER: if (Dom.isOrHasChild(getElement(), event.target)) { setHovering(true); if (_isCapturing) { onClickStart(); } } break; case IEvent.ONBLUR: if (_isFocusing) { _isFocusing = false; onClickCancel(); } break; case IEvent.ONLOSECAPTURE: if (_isCapturing) { _isCapturing = false; onClickCancel(); } break; } super.onBrowserEvent(event); // Synthent is size clicks based on keyboard events AFTER the normal key handling. if ((event is dart_html.KeyboardEvent) && (IEvent.getTypeInt(event.type) & IEvent.KEYEVENTS) != 0) { int keyCode = (event as dart_html.KeyboardEvent).keyCode; switch (type) { case IEvent.ONKEYDOWN: if (keyCode == ' '.codeUnitAt(0)) { _isFocusing = true; onClickStart(); } break; case IEvent.ONKEYUP: if (_isFocusing && keyCode == ' '.codeUnitAt(0)) { _isFocusing = false; onClick(); } break; case IEvent.ONKEYPRESS: if (keyCode == '\n'.codeUnitAt(0) || keyCode == '\r'.codeUnitAt(0)) { onClickStart(); onClick(); } break; } } }
void onClick() #
Called when the user finishes clicking on this button. The default behavior is to fire the click event to listeners. Subclasses that override {@link #onClickStart()} should override this method to restore the normal widget display.
void onClick() { // Allow the click we're about to synthesize to pass through to the // superclass and containing elements. Element.dispatchEvent() is // synchronous, so we simply set and clear the flag within this method. _allowClick = true; // Mouse coordinates are not always available (e.g., when the click is // caused by a keyboard event). //NativeEvent evt = Document.get().createClickEvent(1, 0, 0, 0, 0, false, false, false, false); // Create Dom CustomEvent // dart_html.CustomEvent evt = dart_html.document.$dom_createEvent('CustomEvent'); // After Dom CustomEvent instance has been created we can initialise it here // evt.$dom_initCustomEvent('CustomEvent', false, false, false); dart_html.CustomEvent evt = new dart_html.CustomEvent('CustomEvent', canBubble: false, cancelable: false, detail: false); // Dispatch event getElement().dispatchEvent(evt); _allowClick = false; }
void onClickCancel() #
Called when the user aborts a click in progress; for example, by dragging the mouse outside of the button before releasing the mouse button. Subclasses that override {@link #onClickStart()} should override this method to restore the normal widget display.
void onClickCancel() { }
void onClickStart() #
Called when the user begins to click on this button. Subclasses may override this method to display the start of the click visually; such subclasses should also override {@link #onClick()} and {@link #onClickCancel()} to restore normal visual state. Each <code>onClickStart</code> will eventually be followed by either <code>onClick</code> or <code>onClickCancel</code>, depending on whether the click is completed.
void onClickStart() { }
void onDetach() #
This method is called when a widget is detached from the browser's document. To receive notification before a Widget is removed from the document, override the {@link #onUnload} method or use {@link #addAttachHandler}.
It is strongly recommended that you override {@link #onUnload()} or {@link #doDetachChildren()} instead of this method to avoid inconsistencies between logical and physical attachment states.
Subclasses that override this method must call
super.onDetach()
to ensure that the Widget has been detached
from the underlying Element. Failure to do so will result in application
memory leaks due to circular references between DOM Elements and JavaScript
objects.
@throws IllegalStateException if this widget is already detached @see #onUnload() @see #doDetachChildren()
void onDetach() { super.onDetach(); cleanupCaptureState(); setHovering(false); }
void onLoad() #
This method is called immediately after a widget becomes attached to the browser's document.
void onLoad() { }
void onUnload() #
This method is called immediately before a widget will be detached from the browser's document.
void onUnload() { }
void removeFromParent() #
Removes this widget from its parent widget, if one exists.
If it has no parent, this method does nothing. If it is a "root" widget (meaning it's been added to the detach list via {@link RootPanel#detachOnWindowClose(Widget)}), it will be removed from the detached immediately. This makes it possible for Composites and Panels to adopt root widgets.
@throws IllegalStateException if this widget's parent does not support
removal (e.g. {@link Composite})
void removeFromParent() { if (_parent == null) { // If the widget had no parent, check to see if it was in the detach list // and remove it if necessary. if (RootPanel.isInDetachList(this)) { RootPanel.detachNow(this); } } else if (_parent is HasWidgets) { (_parent as HasWidgets).remove(this); } else if (_parent != null) { throw new Exception("This widget's parent does not implement HasWidgets"); } }
void removeStyleDependentName(String styleSuffix) #
Removes a dependent style name by specifying the style name's suffix.
@param styleSuffix the suffix of the dependent style to be removed @see #setStylePrimaryName(Element, String) @see #addStyleDependentName(String) @see #setStyleDependentName(String, boolean)
void removeStyleDependentName(String styleSuffix) { setStyleDependentName(styleSuffix, false); }
void removeStyleName(String style) #
Removes a style name. This method is typically used to remove secondary style names, but it can be used to remove primary stylenames as well. That use is not recommended.
@param style the secondary style name to be removed @see #addStyleName(String) @see #setStyleName(String, boolean)
void removeStyleName(String style) { setStyleName(style, false); }
void replaceElement(Element elem) #
Replaces this object's browser element.
This method exists only to support a specific use-case in Image, and should not be used by other classes.
@param elem the object's new element
void replaceElement(dart_html.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); } }
void setAccessKey(int key) #
void setAccessKey(int key) { FocusPanel.impl.setAccessKey(getElement(), key); }
void setCurrentFace(Face newFace) #
void setCurrentFace(Face newFace) { /* * Implementation note: default access for testing. */ if (_curFace != newFace) { if (_curFace != null) { removeStyleDependentName(_curFace.getName()); } _curFace = newFace; _setCurrentFaceElement(newFace.getFace()); addStyleDependentName(_curFace.getName()); if (enabled) { _setAriaPressed(newFace); } } }
void setDown(bool down) #
Sets whether this button is down.
@param down <code>true</code> to press the button, <code>false</code> otherwise
void setDown(bool down) { if (down != isDown()) { toggleDown(); } }
void setElement(Element elem) #
Sets this object's browser element. UIObject subclasses must call this method before attempting to call any other methods, and it may only be called once.
@param elem the object's element
void setElement(dart_html.Element elem) { assert (_element == null); this._element = elem; }
void setFocus(bool focused) #
void setFocus(bool focused) { if (focused) { FocusPanel.impl.focus(getElement()); } else { FocusPanel.impl.blur(getElement()); } }
void setHeight(String height) #
Sets the object's height. This height does not include decorations such as border, margin, and padding.
@param height the object's new height, in CSS units (e.g. "10px", "1em")
void setHeight(String height) { // This exists to deal with an inconsistency in IE's implementation where // it won't accept negative numbers in length measurements assert (extractLengthValue(height.trim().toLowerCase()) >= 0); // : "CSS heights should not be negative"; Dom.setStyleAttribute(getElement(), "height", height); }
void setHovering(bool hovering) #
Sets whether this button is hovering.
@param hovering is this button hovering?
void setHovering(bool hovering) { if (hovering != isHovering()) { toggleHover(); } }
void setLayoutData(Object value) #
Sets the panel-defined layout data associated with this widget. Only the panel that currently contains a widget should ever set this value. It serves as a place to store layout bookkeeping data associated with a widget.
@param layoutData the widget's layout data
void setLayoutData(Object value) { this._layoutData = value; }
void setParent(Widget parent) #
Sets this widget's parent. This method should only be called by {@link Panel} and {@link Composite}.
@param parent the widget's new parent @throws IllegalStateException if <code>parent</code> is non-null and the
widget already has a parent
void setParent(Widget parent) { Widget oldParent = this._parent; if (parent == null) { try { if (oldParent != null && oldParent.isAttached()) { onDetach(); assert (!isAttached()); // : "Failure of " + this.getClass().getName() + " to call super.onDetach()"; } } finally { // Put this in a finally in case onDetach throws an exception. this._parent = null; } } else { if (oldParent != null) { throw new Exception("Cannot set a new parent without first clearing the old parent"); } this._parent = parent; if (parent.isAttached()) { onAttach(); assert (isAttached()); // : "Failure of " + this.getClass().getName() + " to call super.onAttach()"; } } }
void setPixelSize(int width, int height) #
Sets the object's size, in pixels, not including decorations such as border, margin, and padding.
@param width the object's new width, in pixels @param height the object's new height, in pixels
void setPixelSize(int width, int height) { if (width >= 0) { setWidth(width.toString() + "px"); } if (height >= 0) { setHeight(height.toString() + "px"); } }
void setSize(String width, String height) #
Sets the object's size. This size does not include decorations such as border, margin, and padding.
@param width the object's new width, in CSS units (e.g. "10px", "1em") @param height the object's new height, in CSS units (e.g. "10px", "1em")
void setSize(String width, String height) { setWidth(width); setHeight(height); }
void setStyleDependentName(String styleSuffix, bool add) #
Adds or removes a dependent style name by specifying the style name's suffix. The actual form of the style name that is added is:
getStylePrimaryName() + '-' + styleSuffix
@param styleSuffix the suffix of the dependent style to be added or removed @param add <code>true</code> to add the given style, <code>false</code> to
remove it
@see #setStylePrimaryName(Element, String) @see #addStyleDependentName(String) @see #setStyleName(String, boolean) @see #removeStyleDependentName(String)
void setStyleDependentName(String styleSuffix, bool add) { setStyleName(getStylePrimaryName() + '-' + styleSuffix, add); }
void setStyleName(String style, bool add) #
Adds or removes a style name. This method is typically used to remove secondary style names, but it can be used to remove primary stylenames as well. That use is not recommended.
@param style the style name to be added or removed @param add <code>true</code> to add the given style, <code>false</code> to
remove it
@see #addStyleName(String) @see #removeStyleName(String)
void setStyleName(String style, bool add) { manageElementStyleName(getStyleElement(), style, add); }
void setStylePrimaryName(String style) #
Sets the object's primary style name and updates all dependent style names.
@param style the new primary style name @see #addStyleName(String) @see #removeStyleName(String)
void setStylePrimaryName(String style) { setElementStylePrimaryName(getStyleElement(), style); }
void setUpFace(Face up) #
Sets the up face of the button.
@param up up face
void setUpFace(Face up) { this._up = up; }
void setWidth(String width) #
Sets the object's width. This width does not include decorations such as border, margin, and padding.
@param width the object's new width, in CSS units (e.g. "10px", "1em")
void setWidth(String width) { // This exists to deal with an inconsistency in IE's implementation where // it won't accept negative numbers in length measurements assert (extractLengthValue(width.trim().toLowerCase()) >= 0); // : "CSS widths should not be negative"; Dom.setStyleAttribute(getElement(), "width", width); }
void sinkBitlessEvent(String eventTypeName) #
Sinks a named event. Note that only {@link Widget widgets} may actually receive events, but can receive events from all objects contained within them.
@param eventTypeName name of the event to sink on this element @see com.google.gwt.user.client.Event
void sinkBitlessEvent(String eventTypeName) { Dom.sinkBitlessEvent(getElement(), eventTypeName); }
void sinkEvents(int eventBitsToAdd) #
Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement. Subclasses wishing to customize sinkEvents can preserve this deferred sink behavior by putting their implementation behind a check of <code>isOrWasAttached()</code>:
{@literal @}Override public void sinkEvents(int eventBitsToAdd) { if (isOrWasAttached()) { /{@literal *} customized sink code goes here {@literal *}/ } else { super.sinkEvents(eventBitsToAdd); } }
void sinkEvents(int eventBitsToAdd) { if (isOrWasAttached()) { super.sinkEvents(eventsToSink); } else { eventsToSink |= eventBitsToAdd; } }
void toggleDisabled() #
Toggle the disabled attribute.
void toggleDisabled() { // Toggle disabled. int newFaceID = getCurrentFace().getFaceID() ^ _DISABLED_ATTRIBUTE; // Remove hovering. newFaceID &= ~_HOVERING_ATTRIBUTE; // Sets the current face. _setCurrentFace(newFaceID); }
void toggleDown() #
Toggle the up/down attribute.
void toggleDown() { int newFaceID = getCurrentFace().getFaceID() ^ _DOWN_ATTRIBUTE; _setCurrentFace(newFaceID); }
void toggleHover() #
Toggle the hovering attribute.
void toggleHover() { // Toggle hovering. int newFaceID = getCurrentFace().getFaceID() ^ _HOVERING_ATTRIBUTE; // Remove disabled. newFaceID &= ~_DISABLED_ATTRIBUTE; _setCurrentFace(newFaceID); }
String toString() #
This method is overridden so that any object can be viewed in the debugger as an HTML snippet.
@return a string representation of the object
String toString() { if (_element == null) { return "(null handle)"; } return getElement().toString(); }
void unsinkEvents(int eventBitsToRemove) #
Removes a set of events from this object's event list.
@param eventBitsToRemove a bitfield representing the set of events to be
removed from this element's event set
@see #sinkEvents @see com.google.gwt.user.client.Event
void unsinkEvents(int eventBitsToRemove) { Dom.sinkEvents(getElement(), Dom.getEventsSunk(getElement()) & (~eventBitsToRemove)); }