OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. | 2 * Copyright (C) 2009 Apple Inc. |
3 * Copyright (C) 2009 Google Inc. | 3 * Copyright (C) 2009 Google Inc. |
4 * All rights reserved. | 4 * All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 // Return currentName or newName based on current or new playback. | 82 // Return currentName or newName based on current or new playback. |
83 return platformResource(RuntimeEnabledFeatures::newMediaPlaybackUiEnabled() ? newName : currentName); | 83 return platformResource(RuntimeEnabledFeatures::newMediaPlaybackUiEnabled() ? newName : currentName); |
84 } | 84 } |
85 | 85 |
86 static bool hasSource(const HTMLMediaElement* mediaElement) | 86 static bool hasSource(const HTMLMediaElement* mediaElement) |
87 { | 87 { |
88 return mediaElement->networkState() != HTMLMediaElement::NETWORK_EMPTY | 88 return mediaElement->networkState() != HTMLMediaElement::NETWORK_EMPTY |
89 && mediaElement->networkState() != HTMLMediaElement::NETWORK_NO_SOURCE; | 89 && mediaElement->networkState() != HTMLMediaElement::NETWORK_NO_SOURCE; |
90 } | 90 } |
91 | 91 |
92 static bool paintMediaButton(GraphicsContext* context, const IntRect& rect, Imag e* image, bool isEnabled = true) | 92 static FloatRect adjustRectForPadding(IntRect rect, const LayoutObject* object) |
philipj_slow
2015/10/28 12:38:07
It's surprising that it would be necessary to writ
| |
93 { | 93 { |
94 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | 94 FloatRect adjustedRect(rect); |
95 isEnabled = true; // New UI only. | 95 |
96 if (!object) | |
97 return adjustedRect; | |
98 | |
99 if (const ComputedStyle* style = object->style()) { | |
100 const float paddingLeft = style->paddingLeft().getFloatValue(); | |
101 const float paddingTop = style->paddingTop().getFloatValue(); | |
102 const float paddingRight = style->paddingRight().getFloatValue(); | |
103 const float paddingBottom = style->paddingBottom().getFloatValue(); | |
104 adjustedRect = FloatRect(rect.x() + paddingLeft, | |
105 rect.y() + paddingTop, | |
106 rect.width() - paddingLeft - paddingRight, | |
107 rect.height() - paddingTop - paddingBottom); | |
108 } | |
109 | |
110 return adjustedRect; | |
111 } | |
112 | |
113 static bool paintMediaButton(GraphicsContext* context, const IntRect& rect, Imag e* image, const LayoutObject* object, bool isEnabled) | |
114 { | |
115 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { | |
116 context->drawImage(image, rect); | |
117 return true; | |
118 } | |
119 | |
120 FloatRect drawRect = adjustRectForPadding(rect, object); | |
96 | 121 |
97 if (!isEnabled) | 122 if (!isEnabled) |
98 context->beginLayer(kDisabledAlpha); | 123 context->beginLayer(kDisabledAlpha); |
99 | 124 |
100 context->drawImage(image, rect); | 125 context->drawImage(image, drawRect, FloatRect(FloatPoint(), FloatSize(image- >size()))); |
101 | 126 |
102 if (!isEnabled) | 127 if (!isEnabled) |
103 context->endLayer(); | 128 context->endLayer(); |
104 | 129 |
105 return true; | 130 return true; |
106 } | 131 } |
107 | 132 |
133 static bool paintMediaButton(GraphicsContext* context, const IntRect& rect, Imag e* image, bool isEnabled = true) | |
134 { | |
135 return paintMediaButton(context, rect, image, 0, isEnabled); | |
136 } | |
137 | |
108 bool MediaControlsPainter::paintMediaMuteButton(const LayoutObject& object, cons t PaintInfo& paintInfo, const IntRect& rect) | 138 bool MediaControlsPainter::paintMediaMuteButton(const LayoutObject& object, cons t PaintInfo& paintInfo, const IntRect& rect) |
109 { | 139 { |
110 const HTMLMediaElement* mediaElement = toParentMediaElement(object); | 140 const HTMLMediaElement* mediaElement = toParentMediaElement(object); |
111 if (!mediaElement) | 141 if (!mediaElement) |
112 return false; | 142 return false; |
113 | 143 |
114 // The new UI uses "muted" and "not muted" only. | 144 // The new UI uses "muted" and "not muted" only. |
115 static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3", | 145 static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3", |
116 "mediaplayerSoundLevel3New"); | 146 "mediaplayerSoundLevel3New"); |
117 static Image* soundLevel2 = platformResource("mediaplayerSoundLevel2", | 147 static Image* soundLevel2 = platformResource("mediaplayerSoundLevel2", |
(...skipping 26 matching lines...) Expand all Loading... | |
144 if (!mediaElement) | 174 if (!mediaElement) |
145 return false; | 175 return false; |
146 | 176 |
147 static Image* mediaPlay = platformResource("mediaplayerPlay", "mediaplayerPl ayNew"); | 177 static Image* mediaPlay = platformResource("mediaplayerPlay", "mediaplayerPl ayNew"); |
148 static Image* mediaPause = platformResource("mediaplayerPause", "mediaplayer PauseNew"); | 178 static Image* mediaPause = platformResource("mediaplayerPause", "mediaplayer PauseNew"); |
149 // For this case, the new UI draws the normal icon, but the entire panel | 179 // For this case, the new UI draws the normal icon, but the entire panel |
150 // grays out. | 180 // grays out. |
151 static Image* mediaPlayDisabled = platformResource("mediaplayerPlayDisabled" , "mediaplayerPlayNew"); | 181 static Image* mediaPlayDisabled = platformResource("mediaplayerPlayDisabled" , "mediaplayerPlayNew"); |
152 | 182 |
153 if (!hasSource(mediaElement)) | 183 if (!hasSource(mediaElement)) |
154 return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled, fals e); | 184 return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled, &obj ect, false); |
155 | 185 |
156 Image * image = !object.node()->isMediaControlElement() || mediaControlEleme ntType(object.node()) == MediaPlayButton ? mediaPlay : mediaPause; | 186 Image * image = !object.node()->isMediaControlElement() || mediaControlEleme ntType(object.node()) == MediaPlayButton ? mediaPlay : mediaPause; |
157 return paintMediaButton(paintInfo.context, rect, image); | 187 return paintMediaButton(paintInfo.context, rect, image, &object, true); |
158 } | 188 } |
159 | 189 |
160 bool MediaControlsPainter::paintMediaOverlayPlayButton(const LayoutObject& objec t, const PaintInfo& paintInfo, const IntRect& rect) | 190 bool MediaControlsPainter::paintMediaOverlayPlayButton(const LayoutObject& objec t, const PaintInfo& paintInfo, const IntRect& rect) |
161 { | 191 { |
162 const HTMLMediaElement* mediaElement = toParentMediaElement(object); | 192 const HTMLMediaElement* mediaElement = toParentMediaElement(object); |
163 if (!mediaElement) | 193 if (!mediaElement) |
164 return false; | 194 return false; |
165 | 195 |
166 if (!hasSource(mediaElement) || !mediaElement->paused()) | 196 if (!hasSource(mediaElement) || !mediaElement->paused()) |
167 return false; | 197 return false; |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 } | 600 } |
571 | 601 |
572 float zoomLevel = style.effectiveZoom(); | 602 float zoomLevel = style.effectiveZoom(); |
573 if (thumbImage) { | 603 if (thumbImage) { |
574 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); | 604 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); |
575 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); | 605 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); |
576 } | 606 } |
577 } | 607 } |
578 | 608 |
579 } // namespace blink | 609 } // namespace blink |
OLD | NEW |