/// <summary> /// Sets the container's state based on the given CSS class name, encountered /// during decoration. CSS class names that don't represent container states /// are ignored. Considered protected; subclasses should override this method /// to support more states and CSS class names. /// </summary> /// <param name="container">Container to update.</param> /// <param name="className">CSS class name.</param> /// <param name="baseClass">Base class name used as the root of state-specific /// class names (typically the renderer's own class name).</param> protected void setStateFromClassName( goog.ui.Container container, string className, string baseClass) { if (className == le.getCssName(baseClass, "disabled")) { container.setEnabled(false); } else if (className == le.getCssName(baseClass, "horizontal")) { container.setOrientation(goog.ui.Container.Orientation.HORIZONTAL); } else if (className == le.getCssName(baseClass, "vertical")) { container.setOrientation(goog.ui.Container.Orientation.VERTICAL); } }
/// <summary> /// Default implementation of {@code decorate} for {@link goog.ui.Container}s. /// Decorates the element with the container, and attempts to decorate its child /// elements. Returns the decorated element. /// </summary> /// <param name="container">Container to decorate the element.</param> /// <param name="element">Element to decorate.</param> /// <returns>Decorated element.</returns> public virtual HTMLElement decorate(goog.ui.Container container, HTMLElement element) { // Set the container's ID to the decorated element's DOM ID, if any. if (element.Id != null) { container.setId(element.Id); } // Configure the container's state based on the CSS class names it has. var baseClass = this.getCssClass(); var hasBaseClass = false; var classNames = goog.dom.classlist.get(element); if (classNames != null) { classNames.ForEach((className) => { if (className == baseClass) { hasBaseClass = true; } else if (className != null) { this.setStateFromClassName(container, className, baseClass); } }); } if (!hasBaseClass) { // Make sure the container's root element has the renderer's own CSS class. goog.dom.classlist.add(element, baseClass); } // Decorate the element's children, if applicable. This should happen after // the container's own state has been initialized, since how children are // decorated may depend on the state of the container. this.decorateChildren(container, this.getContentElement(element)); return(element); }
/// <summary> /// Creates and returns the container's root element. The default /// simply creates a DIV and applies the renderer's own CSS class name to it. /// To be overridden in subclasses. /// </summary> /// <param name="container">Container to render.</param> /// <returns>Root element for the container.</returns> public HTMLElement createDom(goog.ui.Container container) { return(container.getDomHelper().createDom( goog.dom.TagName.DIV, this.getClassNames(container).Join(" "))); }