1 /* 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Google Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15 * its contributors may be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #include "config.h" 31 32 #include "core/html/shadow/MediaControlElementTypes.h" 33 34 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 35 #include "core/CSSValueKeywords.h" 36 #include "core/HTMLNames.h" 37 #include "core/css/StylePropertySet.h" 38 #include "core/events/MouseEvent.h" 39 #include "core/html/HTMLMediaElement.h" 40 #include "core/html/shadow/MediaControls.h" 41 42 namespace blink { 43 44 using namespace HTMLNames; 45 46 class Event; 47 48 HTMLMediaElement* toParentMediaElement(Node* node) 49 { 50 if (!node) 51 return 0; 52 Node* mediaNode = node->shadowHost(); 53 if (!mediaNode) 54 return 0; 55 if (!isHTMLMediaElement(mediaNode)) 56 return 0; 57 58 return toHTMLMediaElement(mediaNode); 59 } 60 61 MediaControlElementType mediaControlElementType(Node* node) 62 { 63 ASSERT_WITH_SECURITY_IMPLICATION(node->isMediaControlElement()); 64 HTMLElement* element = toHTMLElement(node); 65 if (isHTMLInputElement(*element)) 66 return static_cast<MediaControlInputElement*>(element)->displayType(); 67 return static_cast<MediaControlDivElement*>(element)->displayType(); 68 } 69 70 MediaControlElement::MediaControlElement(MediaControls& mediaControls, MediaControlElementType displayType, HTMLElement* element) 71 : m_mediaControls(mediaControls) 72 , m_displayType(displayType) 73 , m_element(element) 74 { 75 } 76 77 HTMLMediaElement& MediaControlElement::mediaElement() const 78 { 79 return mediaControls().mediaElement(); 80 } 81 82 void MediaControlElement::hide() 83 { 84 m_element->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); 85 } 86 87 void MediaControlElement::show() 88 { 89 m_element->removeInlineStyleProperty(CSSPropertyDisplay); 90 } 91 92 void MediaControlElement::setDisplayType(MediaControlElementType displayType) 93 { 94 if (displayType == m_displayType) 95 return; 96 97 m_displayType = displayType; 98 if (RenderObject* object = m_element->renderer()) 99 object->setShouldDoFullPaintInvalidation(true); 100 } 101 102 void MediaControlElement::trace(Visitor* visitor) 103 { 104 visitor->trace(m_element); 105 } 106 107 // ---------------------------- 108 109 MediaControlDivElement::MediaControlDivElement(MediaControls& mediaControls, MediaControlElementType displayType) 110 : HTMLDivElement(mediaControls.document()) 111 , MediaControlElement(mediaControls, displayType, this) 112 { 113 } 114 115 void MediaControlDivElement::trace(Visitor* visitor) 116 { 117 MediaControlElement::trace(visitor); 118 HTMLDivElement::trace(visitor); 119 } 120 121 // ---------------------------- 122 123 MediaControlInputElement::MediaControlInputElement(MediaControls& mediaControls, MediaControlElementType displayType) 124 : HTMLInputElement(mediaControls.document(), 0, false) 125 , MediaControlElement(mediaControls, displayType, this) 126 { 127 } 128 129 bool MediaControlInputElement::isMouseFocusable() const 130 { 131 return false; 132 } 133 134 void MediaControlInputElement::trace(Visitor* visitor) 135 { 136 MediaControlElement::trace(visitor); 137 HTMLInputElement::trace(visitor); 138 } 139 140 // ---------------------------- 141 142 MediaControlTimeDisplayElement::MediaControlTimeDisplayElement(MediaControls& mediaControls, MediaControlElementType displayType) 143 : MediaControlDivElement(mediaControls, displayType) 144 , m_currentValue(0) 145 { 146 } 147 148 void MediaControlTimeDisplayElement::setCurrentValue(double time) 149 { 150 m_currentValue = time; 151 } 152 153 } // namespace blink 154