goog.ui.ControlRenderer
Provided By | |
---|---|
All Known Direct Subclasses |
Default renderer for goog.ui.Control
s. Can be used as-is, but
subclasses of Control will probably want to use renderers specifically
tailored for them by extending this class. Controls that use renderers
delegate one or more of the following API methods to the renderer:
- `createDom` - renders the DOM for the component
- `canDecorate` - determines whether an element can be decorated by the component
- `decorate` - decorates an existing element with the component
- `setState` - updates the appearance of the component based on its state
- `getContent` - returns the component's content
- `setContent` - sets the component's content
new ControlRenderer()
Parameters | None. |
---|
Instance Methods
this.canDecorate( element ) → boolean
boolean
Returns true if this renderer can decorate the element, false otherwise. The default implementation always returns true.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.createDom( control ) → (Element|null)
(Element|null)
Returns the control's contents wrapped in a DIV, with the renderer's own CSS class and additional state-specific classes applied to it.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.decorate( control, element ) → (Element|null)
(Element|null)
Default implementation of decorate
for goog.ui.Control
s.
Initializes the control's ID, content, and state based on the ID of the
element, its child nodes, and its CSS classes, respectively. Returns the
element.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
this.enableClassName( control, className, enable ) → void
void
Updates the control's DOM by adding or removing the specified class name to/from its root element. May add additional combined classes as needed in IE6 and lower. Because of this, subclasses should use this method when modifying class names on the control's root element.
Parameters |
|
---|
this.enableExtraClassName( control, className, enable ) → void
void
Updates the control's DOM by adding or removing the specified extra class name to/from its element.
Parameters |
|
---|
this.getAriaRole() → (goog.a11y.aria.Role|undefined)
(goog.a11y.aria.Role|undefined)
Returns the ARIA role to be applied to the control. See http://wiki/Main/ARIA for more info.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getClassForState( state ) → (string|undefined)
(string|undefined)
Takes a single goog.ui.Component.State
, and returns the
corresponding CSS class name (null if none).
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
Returns all CSS class names applicable to the given control, based on its state. The return value is an array of strings containing
- the renderer-specific CSS class returned by
#getCssClass
, followed by - the structural CSS class returned by
getStructuralCssClass
(if different from the renderer-specific CSS class), followed by - any state-specific classes returned by
#getClassNamesForState
, followed by - any extra classes returned by the control's `getExtraClassNames` method and
- for IE6 and lower, additional combined classes from
getAppliedCombinedClassNames_
.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
Takes a bit mask of goog.ui.Component.State
s, and returns an array
of the appropriate class names representing the given state, suitable to be
applied to the root element of a component rendered using this renderer, or
null if no state-specific classes need to be applied. This default
implementation uses the renderer's getClassForState
method to
generate each state-specific class.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.getContentElement( element ) → (Element|null)
(Element|null)
Takes the control's root element and returns the parent element of the control's contents. Since by default controls are rendered as a single DIV, the default implementation returns the element itself. Subclasses with more complex DOM structures must override this method as needed.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.getCssClass() → string
string
Returns the CSS class name to be applied to the root element of all components rendered or decorated using this renderer. The class name is expected to uniquely identify the renderer class, i.e. no two renderer classes are expected to share the same CSS class name.
Parameters | None. | ||
---|---|---|---|
Returns |
|
Returns an array of combinations of classes to apply combined class names for
in IE6 and below. See IE6_CLASS_COMBINATIONS
for more detail. This
method doesn't reference IE6_CLASS_COMBINATIONS
so that it can be
compiled out, but subclasses should return their IE6_CLASS_COMBINATIONS
static constant instead.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getKeyEventTarget( control ) → (Element|null)
(Element|null)
Returns the element within the component's DOM that should receive keyboard focus (null if none). The default implementation returns the control's root element.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.getStateFromClass( className ) → goog.ui.Component.State
goog.ui.Component.State
Takes a single CSS class name which may represent a component state, and returns the corresponding component state (0x00 if none).
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.getStructuralCssClass() → string
string
Returns the name of a DOM structure-specific CSS class to be applied to the
root element of all components rendered or decorated using this renderer.
Unlike the class name returned by #getCssClass
, the structural class
name may be shared among different renderers that generate similar DOM
structures. The structural class name also serves as the basis of derived
class names used to identify and style structural elements of the control's
DOM, as well as the basis for state-specific class names. The default
implementation returns the same class name as #getCssClass
, but
subclasses are expected to override this method as needed.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.initializeDom( control ) → void
void
Initializes the control's DOM by configuring properties that can only be set
after the DOM has entered the document. This implementation sets up BiDi
and keyboard focus. Called from goog.ui.Control#enterDocument
.
Parameters |
|
---|
this.isFocusable( control ) → boolean
boolean
Returns true if the control's key event target supports keyboard focus
(based on its tabIndex
attribute), false otherwise.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.setAllowTextSelection( element, allow ) → void
void
Allows or disallows text selection within the control's DOM.
Parameters |
|
---|
this.setAriaLabel( element, ariaLabel ) → void
void
Sets the element's ARIA label. This should be overriden by subclasses that don't apply the role directly on control.element_.
Parameters |
|
---|
this.setAriaRole( element, opt_preferredRole ) → void
void
Sets the element's ARIA role.
Parameters |
|
---|
this.setAriaStates( control, element ) → void
void
Sets the element's ARIA attributes, including distinguishing between universally supported ARIA properties and ARIA states that are only supported by certain ARIA roles. Only attributes which are initialized to be true will be set.
Parameters |
|
---|
this.setContent( element, content ) → void
void
Takes a control's root element, and sets its content to the given text caption or DOM structure. The default implementation replaces the children of the given element. Renderers that create more complex DOM structures must override this method accordingly.
Parameters |
|
---|
this.setFocusable( control, focusable ) → void
void
Updates the control's key event target to make it focusable or non-focusable
via its tabIndex
attribute. Does nothing if the control doesn't
support the FOCUSED
state, or if it has no key event target.
Parameters |
|
---|
this.setRightToLeft( element, rightToLeft ) → void
void
Applies special styling to/from the control's element if it is rendered right-to-left, and removes it if it is rendered left-to-right.
Parameters |
|
---|
this.setState( control, state, enable ) → void
void
Updates the appearance of the control in response to a state change.
Parameters |
|
---|
this.setVisible( element, visible ) → void
void
Shows or hides the element.
Parameters |
|
---|
this.updateAriaState( element, state, enable ) → void
void
Updates the element's ARIA (accessibility) attributes , including distinguishing between universally supported ARIA properties and ARIA states that are only supported by certain ARIA roles.
Parameters |
|
---|
Static Functions
ControlRenderer.getCustomRenderer( ctor, cssClassName ) → (goog.ui.ControlRenderer|null)
(goog.ui.ControlRenderer|null)
Constructs a new renderer and sets the CSS class that the renderer will use as the base CSS class to apply to all elements rendered by that renderer. An example to use this function using a color palette:
var myCustomRenderer = goog.ui.ControlRenderer.getCustomRenderer( goog.ui.PaletteRenderer, 'my-special-palette'); var newColorPalette = new goog.ui.ColorPalette( colors, myCustomRenderer, opt_domHelper);
Your CSS can look like this now:
.my-special-palette { } .my-special-palette-table { } .my-special-palette-cell { } etc.
instead of
.CSS_MY_SPECIAL_PALETTE .goog-palette { } .CSS_MY_SPECIAL_PALETTE .goog-palette-table { } .CSS_MY_SPECIAL_PALETTE .goog-palette-cell { } etc.
You would want to use this functionality when you want an instance of a component to have specific styles different than the other components of the same type in your application. This avoids using descendant selectors to apply the specific styles to this component.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
ControlRenderer.getInstance() → goog.ui.ControlRenderer
goog.ui.ControlRenderer
Parameters | None. | |
---|---|---|
Returns |
|
Static Properties
ControlRenderer.CSS_CLASS → string
string
Default CSS class to be applied to the root element of components rendered by this renderer.