• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "RenderMediaControls.h"
28 
29 #include "GraphicsContext.h"
30 #include "HTMLMediaElement.h"
31 #include "HTMLNames.h"
32 #include "RenderThemeSafari.h"
33 #include "SoftLinking.h"
34 #include <CoreGraphics/CoreGraphics.h>
35 
36 using namespace std;
37 
38 namespace WebCore {
39 
40 #ifdef DEBUG_ALL
41 SOFT_LINK_DEBUG_LIBRARY(SafariTheme)
42 #else
43 SOFT_LINK_LIBRARY(SafariTheme)
44 #endif
45 
46 SOFT_LINK(SafariTheme, paintThemePart, void, __stdcall, (ThemePart part, CGContextRef context, const CGRect& rect, NSControlSize size, ThemeControlState state), (part, context, rect, size, state))
47 SOFT_LINK(SafariTheme, STPaintProgressIndicator, void, APIENTRY, (ProgressIndicatorType type, CGContextRef context, const CGRect& rect, NSControlSize size, ThemeControlState state, float value), (type, context, rect, size, state, value))
48 
49 #if ENABLE(VIDEO)
50 
determineState(RenderObject * o)51 static ThemeControlState determineState(RenderObject* o)
52 {
53     ThemeControlState result = 0;
54     RenderTheme* theme = o->theme();
55     if (theme->isActive(o))
56         result |= SafariTheme::ActiveState;
57     if (theme->isEnabled(o) && !theme->isReadOnlyControl(o))
58         result |= SafariTheme::EnabledState;
59     if (theme->isPressed(o))
60         result |= SafariTheme::PressedState;
61     if (theme->isChecked(o))
62         result |= SafariTheme::CheckedState;
63     if (theme->isIndeterminate(o))
64         result |= SafariTheme::IndeterminateCheckedState;
65     if (theme->isFocused(o))
66         result |= SafariTheme::FocusedState;
67     if (theme->isDefault(o))
68         result |= SafariTheme::DefaultState;
69     return result;
70 }
71 
72 static const int mediaSliderThumbWidth = 13;
73 static const int mediaSliderThumbHeight = 14;
74 
adjustMediaSliderThumbSize(RenderObject * o)75 void RenderMediaControls::adjustMediaSliderThumbSize(RenderObject* o)
76 {
77     if (o->style()->appearance() != MediaSliderThumbPart)
78         return;
79 
80     float zoomLevel = o->style()->effectiveZoom();
81     o->style()->setWidth(Length(static_cast<int>(mediaSliderThumbWidth * zoomLevel), Fixed));
82     o->style()->setHeight(Length(static_cast<int>(mediaSliderThumbHeight * zoomLevel), Fixed));
83 }
84 
paintMediaControlsPart(MediaControlElementType part,RenderObject * o,const RenderObject::PaintInfo & paintInfo,const IntRect & r)85 bool RenderMediaControls::paintMediaControlsPart(MediaControlElementType part, RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
86 {
87     ASSERT(SafariThemeLibrary());
88 
89     switch (part) {
90         case MediaFullscreenButton:
91             paintThemePart(SafariTheme::MediaFullscreenButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
92             break;
93         case MediaShowClosedCaptionsButton:
94         case MediaHideClosedCaptionsButton:
95 #if SAFARI_THEME_VERSION >= 4
96             if (MediaControlToggleClosedCaptionsButtonElement* btn = static_cast<MediaControlToggleClosedCaptionsButtonElement*>(o->node())) {
97                 bool captionsVisible = btn->displayType() == MediaHideClosedCaptionsButton;
98                 paintThemePart(captionsVisible ? SafariTheme::MediaHideClosedCaptionsButtonPart : SafariTheme::MediaShowClosedCaptionsButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
99             }
100 #endif
101             break;
102         case MediaMuteButton:
103         case MediaUnMuteButton:
104             if (MediaControlMuteButtonElement* btn = static_cast<MediaControlMuteButtonElement*>(o->node())) {
105                 bool audioEnabled = btn->displayType() == MediaMuteButton;
106                 paintThemePart(audioEnabled ? SafariTheme::MediaMuteButtonPart : SafariTheme::MediaUnMuteButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
107             }
108             break;
109         case MediaPauseButton:
110         case MediaPlayButton:
111             if (MediaControlPlayButtonElement* btn = static_cast<MediaControlPlayButtonElement*>(o->node())) {
112                 bool canPlay = btn->displayType() == MediaPlayButton;
113                 paintThemePart(canPlay ? SafariTheme::MediaPlayButtonPart : SafariTheme::MediaPauseButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
114             }
115             break;
116         case MediaSeekBackButton:
117             paintThemePart(SafariTheme::MediaSeekBackButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
118             break;
119         case MediaSeekForwardButton:
120             paintThemePart(SafariTheme::MediaSeekForwardButtonPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
121             break;
122         case MediaSlider: {
123             if (HTMLMediaElement* mediaElement = toParentMediaElement(o))
124                 STPaintProgressIndicator(SafariTheme::MediaType, paintInfo.context->platformContext(), r, NSRegularControlSize, 0, mediaElement->percentLoaded());
125             break;
126         }
127         case MediaSliderThumb:
128             paintThemePart(SafariTheme::MediaSliderThumbPart, paintInfo.context->platformContext(), r, NSRegularControlSize, determineState(o));
129             break;
130         case MediaVolumeSliderContainer:
131             // FIXME: Implement volume slider.
132             ASSERT_NOT_REACHED();
133             break;
134         case MediaVolumeSlider:
135             // FIXME: Implement volume slider.
136             ASSERT_NOT_REACHED();
137             break;
138         case MediaVolumeSliderThumb:
139             // FIXME: Implement volume slider.
140             ASSERT_NOT_REACHED();
141             break;
142         case MediaTimelineContainer:
143             ASSERT_NOT_REACHED();
144             break;
145         case MediaCurrentTimeDisplay:
146             ASSERT_NOT_REACHED();
147             break;
148         case MediaTimeRemainingDisplay:
149             ASSERT_NOT_REACHED();
150             break;
151         case MediaControlsPanel:
152             ASSERT_NOT_REACHED();
153             break;
154     }
155     return false;
156 }
157 
158 #endif  // #if ENABLE(VIDEO)
159 
160 } // namespace WebCore
161