📄 rendermedia.cpp
字号:
/* * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */#include "config.h"#if ENABLE(VIDEO)#include "RenderMedia.h"#include "CSSStyleSelector.h"#include "Event.h"#include "EventNames.h"#include "FloatConversion.h"#include "FrameView.h"#include "GraphicsContext.h"#include "HTMLMediaElement.h"#include "HTMLNames.h"#include "MediaControlElements.h"#include "MouseEvent.h"#include "MediaPlayer.h"#include <wtf/CurrentTime.h>#include <wtf/MathExtras.h>using namespace std;namespace WebCore {static const double cTimeUpdateRepeatDelay = 0.2;static const double cOpacityAnimationRepeatDelay = 0.05;// FIXME get this from stylestatic const double cOpacityAnimationDuration = 0.1;RenderMedia::RenderMedia(HTMLMediaElement* video) : RenderReplaced(video) , m_timeUpdateTimer(this, &RenderMedia::timeUpdateTimerFired) , m_opacityAnimationTimer(this, &RenderMedia::opacityAnimationTimerFired) , m_mouseOver(false) , m_opacityAnimationStartTime(0) , m_opacityAnimationFrom(0) , m_opacityAnimationTo(1.0f) , m_previousVisible(VISIBLE){}RenderMedia::RenderMedia(HTMLMediaElement* video, const IntSize& intrinsicSize) : RenderReplaced(video, intrinsicSize) , m_timeUpdateTimer(this, &RenderMedia::timeUpdateTimerFired) , m_opacityAnimationTimer(this, &RenderMedia::opacityAnimationTimerFired) , m_mouseOver(false) , m_opacityAnimationStartTime(0) , m_opacityAnimationFrom(0) , m_opacityAnimationTo(1.0f){}RenderMedia::~RenderMedia(){}void RenderMedia::destroy(){ if (m_controlsShadowRoot && m_controlsShadowRoot->renderer()) { // detach the panel before removing the shadow renderer to prevent a crash in m_controlsShadowRoot->detach() // when display: style changes m_panel->detach(); removeChild(m_controlsShadowRoot->renderer()); m_controlsShadowRoot->detach(); m_controlsShadowRoot = 0; } RenderReplaced::destroy();}HTMLMediaElement* RenderMedia::mediaElement() const{ return static_cast<HTMLMediaElement*>(node()); }MediaPlayer* RenderMedia::player() const{ return mediaElement()->player();}void RenderMedia::layout(){ IntSize oldSize = contentBoxRect().size(); RenderReplaced::layout(); RenderBox* controlsRenderer = m_controlsShadowRoot ? m_controlsShadowRoot->renderBox() : 0; if (!controlsRenderer) return; IntSize newSize = contentBoxRect().size(); if (newSize != oldSize || controlsRenderer->needsLayout()) { controlsRenderer->setLocation(borderLeft() + paddingLeft(), borderTop() + paddingTop()); controlsRenderer->style()->setHeight(Length(newSize.height(), Fixed)); controlsRenderer->style()->setWidth(Length(newSize.width(), Fixed)); controlsRenderer->setNeedsLayout(true, false); controlsRenderer->layout(); setChildNeedsLayout(false); }}const RenderObjectChildList* RenderMedia::children() const{ return m_controlsShadowRoot ? m_controlsShadowRoot->renderer()->virtualChildren() : 0; }RenderObjectChildList* RenderMedia::children(){ return m_controlsShadowRoot ? m_controlsShadowRoot->renderer()->virtualChildren() : 0; } void RenderMedia::removeChild(RenderObject* child){ ASSERT(m_controlsShadowRoot); ASSERT(child == m_controlsShadowRoot->renderer()); child->removeLayers(enclosingLayer()); static_cast<RenderMediaControlShadowRoot*>(child)->setParent(0);} void RenderMedia::createControlsShadowRoot(){ ASSERT(!m_controlsShadowRoot); m_controlsShadowRoot = new MediaControlShadowRootElement(document(), mediaElement());}void RenderMedia::createPanel(){ ASSERT(!m_panel); RenderStyle* style = getCachedPseudoStyle(MEDIA_CONTROLS_PANEL); m_panel = new HTMLDivElement(HTMLNames::divTag, document()); RenderObject* renderer = m_panel->createRenderer(renderArena(), style); if (renderer) { m_panel->setRenderer(renderer); renderer->setStyle(style); m_panel->setAttached(); m_panel->setInDocument(true); m_controlsShadowRoot->addChild(m_panel); m_controlsShadowRoot->renderer()->addChild(renderer); }}void RenderMedia::createMuteButton(){ ASSERT(!m_muteButton); m_muteButton = new MediaControlMuteButtonElement(document(), mediaElement()); m_muteButton->attachToParent(m_panel.get());}void RenderMedia::createPlayButton(){ ASSERT(!m_playButton); m_playButton = new MediaControlPlayButtonElement(document(), mediaElement()); m_playButton->attachToParent(m_panel.get());}void RenderMedia::createSeekBackButton(){ ASSERT(!m_seekBackButton); m_seekBackButton = new MediaControlSeekButtonElement(document(), mediaElement(), false); m_seekBackButton->attachToParent(m_panel.get());}void RenderMedia::createSeekForwardButton(){ ASSERT(!m_seekForwardButton); m_seekForwardButton = new MediaControlSeekButtonElement(document(), mediaElement(), true); m_seekForwardButton->attachToParent(m_panel.get());}void RenderMedia::createTimelineContainer(){ ASSERT(!m_timelineContainer); RenderStyle* style = getCachedPseudoStyle(MEDIA_CONTROLS_TIMELINE_CONTAINER); m_timelineContainer = new HTMLDivElement(HTMLNames::divTag, document()); RenderObject* renderer = m_timelineContainer->createRenderer(renderArena(), style); if (renderer) { m_timelineContainer->setRenderer(renderer); renderer->setStyle(style); m_timelineContainer->setAttached(); m_timelineContainer->setInDocument(true); m_panel->addChild(m_timelineContainer); m_panel->renderer()->addChild(renderer); }}void RenderMedia::createTimeline(){ ASSERT(!m_timeline); m_timeline = new MediaControlTimelineElement(document(), mediaElement()); m_timeline->attachToParent(m_timelineContainer.get());} void RenderMedia::createCurrentTimeDisplay(){ ASSERT(!m_currentTimeDisplay); m_currentTimeDisplay = new MediaTimeDisplayElement(document(), mediaElement(), true); m_currentTimeDisplay->attachToParent(m_timelineContainer.get());}void RenderMedia::createTimeRemainingDisplay(){ ASSERT(!m_timeRemainingDisplay); m_timeRemainingDisplay = new MediaTimeDisplayElement(document(), mediaElement(), false); m_timeRemainingDisplay->attachToParent(m_timelineContainer.get());}void RenderMedia::createFullscreenButton(){ ASSERT(!m_fullscreenButton); m_fullscreenButton = new MediaControlFullscreenButtonElement(document(), mediaElement()); m_fullscreenButton->attachToParent(m_panel.get());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -