Home | History | Annotate | Download | only in shadow
      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/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 WebCore {
     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         mediaNode = node;
     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->paintInvalidationForWholeRenderer();
    100 }
    101 
    102 // ----------------------------
    103 
    104 MediaControlDivElement::MediaControlDivElement(MediaControls& mediaControls, MediaControlElementType displayType)
    105     : HTMLDivElement(mediaControls.document())
    106     , MediaControlElement(mediaControls, displayType, this)
    107 {
    108 }
    109 
    110 // ----------------------------
    111 
    112 MediaControlInputElement::MediaControlInputElement(MediaControls& mediaControls, MediaControlElementType displayType)
    113     : HTMLInputElement(mediaControls.document(), 0, false)
    114     , MediaControlElement(mediaControls, displayType, this)
    115 {
    116 }
    117 
    118 bool MediaControlInputElement::isMouseFocusable() const
    119 {
    120     return false;
    121 }
    122 
    123 // ----------------------------
    124 
    125 MediaControlTimeDisplayElement::MediaControlTimeDisplayElement(MediaControls& mediaControls, MediaControlElementType displayType)
    126     : MediaControlDivElement(mediaControls, displayType)
    127     , m_currentValue(0)
    128 {
    129 }
    130 
    131 void MediaControlTimeDisplayElement::setCurrentValue(double time)
    132 {
    133     m_currentValue = time;
    134 }
    135 
    136 } // namespace WebCore
    137