1/* 2 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26WebInspector.ActivateButtonNavigationItem = function(identifier, defaultToolTip, activatedToolTip, image, imageWidth, imageHeight, suppressEmboss, role) 27{ 28 WebInspector.ButtonNavigationItem.call(this, identifier, defaultToolTip, image, imageWidth, imageHeight, suppressEmboss, role); 29 30 this._defaultToolTip = defaultToolTip; 31 this._activatedToolTip = activatedToolTip || defaultToolTip; 32 this._role = role; 33}; 34 35WebInspector.ActivateButtonNavigationItem.StyleClassName = "activate"; 36WebInspector.ActivateButtonNavigationItem.ActivatedStyleClassName = "activated"; 37 38WebInspector.ActivateButtonNavigationItem.prototype = { 39 constructor: WebInspector.ActivateButtonNavigationItem, 40 41 // Public 42 43 get defaultToolTip() 44 { 45 return this._defaultToolTip; 46 }, 47 48 get activatedToolTip() 49 { 50 return this._activatedToolTip; 51 }, 52 53 get activated() 54 { 55 return this.element.classList.contains(WebInspector.ActivateButtonNavigationItem.ActivatedStyleClassName); 56 }, 57 58 set activated(flag) 59 { 60 if (flag) { 61 this.toolTip = this._activatedToolTip; 62 this.element.classList.add(WebInspector.ActivateButtonNavigationItem.ActivatedStyleClassName); 63 if (this._role === "tab") 64 this.element.setAttribute("aria-selected", "true"); 65 } else { 66 this.toolTip = this._defaultToolTip; 67 this.element.classList.remove(WebInspector.ActivateButtonNavigationItem.ActivatedStyleClassName); 68 if (this._role === "tab") 69 this.element.removeAttribute("aria-selected"); 70 } 71 }, 72 73 generateStyleText: function(parentSelector) 74 { 75 var classNames = this._classNames.join("."); 76 77 if (this._suppressEmboss) 78 var styleText = parentSelector + " ." + classNames + " > .glyph { width: " + this._imageWidth + "px; height: " + this._imageHeight + "px; }\n"; 79 else { 80 var activatedClassName = "." + WebInspector.ActivateButtonNavigationItem.ActivatedStyleClassName; 81 82 // Default state. 83 var styleText = parentSelector + " ." + classNames + " > .glyph { background-image: -webkit-canvas(" + this._canvasIdentifier(WebInspector.ButtonNavigationItem.States.Normal) + "); background-size: " + this._imageWidth + "px " + this._imageHeight + "px; }\n"; 84 85 // Pressed state. 86 styleText += parentSelector + " ." + classNames + ":not(.disabled):active > .glyph { background-image: -webkit-canvas(" + this._canvasIdentifier(WebInspector.ButtonNavigationItem.States.Active) + "); }\n"; 87 88 // Activated state. 89 styleText += parentSelector + " ." + classNames + activatedClassName + ":not(.disabled) > .glyph { background-image: -webkit-canvas(" + this._canvasIdentifier(WebInspector.ButtonNavigationItem.States.Focus) + "); }\n"; 90 91 // Activated and pressed state. 92 styleText += parentSelector + " ." + classNames + activatedClassName + ":not(.disabled):active > .glyph { background-image: -webkit-canvas(" + this._canvasIdentifier(WebInspector.ButtonNavigationItem.States.ActiveFocus) + "); }\n"; 93 } 94 95 return styleText; 96 }, 97 98 // Private 99 100 _additionalClassNames: [WebInspector.ActivateButtonNavigationItem.StyleClassName, WebInspector.ButtonNavigationItem.StyleClassName] 101}; 102 103WebInspector.ActivateButtonNavigationItem.prototype.__proto__ = WebInspector.ButtonNavigationItem.prototype; 104