/*! * UI development toolkit for HTML5 (OpenUI5) * (c) Copyright 2009-2018 SAP SE or an SAP affiliate company. * Licensed under the Apache License, Version 2.0 - see LICENSE.txt. */ sap.ui.define([ 'sap/ui/Device', 'sap/ui/core/library', 'sap/ui/core/IconPool', 'sap/m/library', 'sap/ui/core/InvisibleText', "sap/base/security/encodeXML" ], function(Device, coreLibrary, IconPool, library, InvisibleText, encodeXML) { "use strict"; // shortcut for sap.m.ButtonType var ButtonType = library.ButtonType; // shortcut for sap.ui.core.TextDirection var TextDirection = coreLibrary.TextDirection; /** * Button renderer. * @namespace */ var ButtonRenderer = {}; /** * Renders the HTML for the given control, using the provided * {@link sap.ui.core.RenderManager}. * * @param {sap.ui.core.RenderManager} oRm * the RenderManager that can be used for writing to * the Render-Output-Buffer * @param {sap.ui.core.Control} oButton * the button to be rendered */ ButtonRenderer.render = function(oRm, oButton) { // get control properties var sType = oButton.getType(); var bEnabled = oButton.getEnabled(); var sWidth = oButton.getWidth(); var sTooltip = oButton._getTooltip(); var sText = oButton._getText(); var sTextDir = oButton.getTextDirection(); var bIE_Edge = Device.browser.internet_explorer || Device.browser.edge; // render bdi tag only if the browser is different from IE and Edge since it is not supported there var bRenderBDI = (sTextDir === TextDirection.Inherit) && !bIE_Edge; // get icon from icon pool var sBackURI = IconPool.getIconURI("nav-back"); // start button tag oRm.write(" 0) { mAccProps["labelledby"] = {value: oButton.getId() + "-content", append: true }; } //descendants (e.g. ToggleButton) callback if (this.renderAccessibilityAttributes) { this.renderAccessibilityAttributes(oRm, oButton, mAccProps); } oRm.writeAccessibilityState(oButton, mAccProps); // check if the button is disabled if (!bEnabled) { oRm.writeAttribute("disabled", "disabled"); if (!oButton._isUnstyled()) { oRm.addClass("sapMBtnDisabled"); } } else { switch (sType) { case ButtonType.Accept: case ButtonType.Reject: case ButtonType.Emphasized: oRm.addClass("sapMBtnInverted"); break; default: // No need to do anything for other button types break; } } // add tooltip if available if (sTooltip) { oRm.writeAttributeEscaped("title", sTooltip); } oRm.writeClasses(); // set user defined width if (sWidth != "" || sWidth.toLowerCase() === "auto") { oRm.addStyle("width", sWidth); oRm.writeStyles(); } renderTabIndex(oButton, oRm); // close button tag oRm.write(">"); // start inner button tag oRm.write(""); // set image for internal image control (back) if (sType === ButtonType.Back || sType === ButtonType.Up) { this.writeInternalIconPoolHtml(oRm, oButton, sBackURI); } // write icon if (oButton.getIcon()) { this.writeImgHtml(oRm, oButton); } // write button text if (sText) { oRm.write(""); if (bRenderBDI) { oRm.write(""); } oRm.writeEscaped(sText); if (bRenderBDI) { oRm.write(""); } oRm.write(""); } // special handling for IE focus outline if (bIE_Edge && bEnabled) { oRm.write(''); } // end inner button tag oRm.write(""); // end button tag oRm.write(""); }; /** * HTML for image * * @param {sap.ui.core.RenderManager} oRm * the RenderManager that can be used for writing to * the Render-Output-Buffer * @param {sap.ui.core.Control} oButton * the button to be rendered * @private */ ButtonRenderer.writeImgHtml = function(oRm, oButton) { oRm.renderControl(oButton._getImage((oButton.getId() + "-img"), oButton.getIcon(), oButton.getActiveIcon(), oButton.getIconDensityAware())); }; /** * @param {sap.ui.core.RenderManager} oRm * the RenderManager that can be used for writing to * the Render-Output-Buffer * @param {sap.ui.core.Control} oButton * the button to be rendered * @param {sap.ui.core.URI} sURI * URI of the icon to be written * HTML for internal image (icon pool) */ ButtonRenderer.writeInternalIconPoolHtml = function(oRm, oButton, sURI) { oRm.renderControl(oButton._getInternalIconBtn((oButton.getId() + "-iconBtn"), sURI)); }; /** * Renders tabindex with value of "-1" if required by _bExcludeFromTabChain property. * @param {sap.m.Button} oButton The sap.m.Button to be rendered * @param {sap.ui.core.RenderManager} oRm The RenderManager that can be used for writing to the Render-Output-Buffer */ function renderTabIndex(oButton, oRm){ if (oButton._bExcludeFromTabChain) { oRm.writeAttribute("tabindex", -1); } } var mARIATextKeys = { Accept: "BUTTON_ARIA_TYPE_ACCEPT", Reject: "BUTTON_ARIA_TYPE_REJECT", Emphasized: "BUTTON_ARIA_TYPE_EMPHASIZED" }; ButtonRenderer.getButtonTypeAriaLabelId = function(sType) { return InvisibleText.getStaticId("sap.m", mARIATextKeys[sType]); }; return ButtonRenderer; }, /* bExport= */ true);