| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (videoElement()->shouldDisplayPosterImage()) | 133 if (videoElement()->shouldDisplayPosterImage()) |
| 134 m_cachedImageSize = intrinsicSize(); | 134 m_cachedImageSize = intrinsicSize(); |
| 135 | 135 |
| 136 // The intrinsic size is now that of the image, but in case we already had t
he | 136 // The intrinsic size is now that of the image, but in case we already had t
he |
| 137 // intrinsic size of the video we call this here to restore the video size. | 137 // intrinsic size of the video we call this here to restore the video size. |
| 138 updateIntrinsicSize(); | 138 updateIntrinsicSize(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 IntRect RenderVideo::videoBox() const | 141 IntRect RenderVideo::videoBox() const |
| 142 { | 142 { |
| 143 if (m_cachedImageSize.isEmpty() && videoElement()->shouldDisplayPosterImage(
)) | 143 const LayoutSize* overriddenIntrinsicSize = 0; |
| 144 return IntRect(); | 144 if (videoElement()->shouldDisplayPosterImage()) |
| 145 overriddenIntrinsicSize = &m_cachedImageSize; |
| 145 | 146 |
| 146 LayoutSize elementSize; | 147 return pixelSnappedIntRect(replacedContentRect(overriddenIntrinsicSize)); |
| 147 if (videoElement()->shouldDisplayPosterImage()) | |
| 148 elementSize = m_cachedImageSize; | |
| 149 else | |
| 150 elementSize = intrinsicSize(); | |
| 151 | |
| 152 IntRect contentRect = pixelSnappedIntRect(contentBoxRect()); | |
| 153 if (elementSize.isEmpty() || contentRect.isEmpty()) | |
| 154 return IntRect(); | |
| 155 | |
| 156 LayoutRect renderBox = contentRect; | |
| 157 LayoutUnit ratio = renderBox.width() * elementSize.height() - renderBox.heig
ht() * elementSize.width(); | |
| 158 if (ratio > 0) { | |
| 159 LayoutUnit newWidth = renderBox.height() * elementSize.width() / element
Size.height(); | |
| 160 // Just fill the whole area if the difference is one pixel or less (in b
oth sides) | |
| 161 if (renderBox.width() - newWidth > 2) | |
| 162 renderBox.setWidth(newWidth); | |
| 163 renderBox.move((contentRect.width() - renderBox.width()) / 2, 0); | |
| 164 } else if (ratio < 0) { | |
| 165 LayoutUnit newHeight = renderBox.width() * elementSize.height() / elemen
tSize.width(); | |
| 166 if (renderBox.height() - newHeight > 2) | |
| 167 renderBox.setHeight(newHeight); | |
| 168 renderBox.move(0, (contentRect.height() - renderBox.height()) / 2); | |
| 169 } | |
| 170 | |
| 171 return pixelSnappedIntRect(renderBox); | |
| 172 } | 148 } |
| 173 | 149 |
| 174 bool RenderVideo::shouldDisplayVideo() const | 150 bool RenderVideo::shouldDisplayVideo() const |
| 175 { | 151 { |
| 176 return !videoElement()->shouldDisplayPosterImage(); | 152 return !videoElement()->shouldDisplayPosterImage(); |
| 177 } | 153 } |
| 178 | 154 |
| 179 void RenderVideo::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
fset) | 155 void RenderVideo::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
fset) |
| 180 { | 156 { |
| 181 MediaPlayer* mediaPlayer = mediaElement()->player(); | 157 MediaPlayer* mediaPlayer = mediaElement()->player(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 195 if (rect.isEmpty()) { | 171 if (rect.isEmpty()) { |
| 196 if (page && paintInfo.phase == PaintPhaseForeground) | 172 if (page && paintInfo.phase == PaintPhaseForeground) |
| 197 page->addRelevantUnpaintedObject(this, visualOverflowRect()); | 173 page->addRelevantUnpaintedObject(this, visualOverflowRect()); |
| 198 return; | 174 return; |
| 199 } | 175 } |
| 200 rect.moveBy(paintOffset); | 176 rect.moveBy(paintOffset); |
| 201 | 177 |
| 202 if (page && paintInfo.phase == PaintPhaseForeground) | 178 if (page && paintInfo.phase == PaintPhaseForeground) |
| 203 page->addRelevantRepaintedObject(this, rect); | 179 page->addRelevantRepaintedObject(this, rect); |
| 204 | 180 |
| 181 LayoutRect contentRect = contentBoxRect(); |
| 182 contentRect.moveBy(paintOffset); |
| 183 GraphicsContext* context = paintInfo.context; |
| 184 bool clip = !contentRect.contains(rect); |
| 185 if (clip) { |
| 186 context->save(); |
| 187 context->clip(contentRect); |
| 188 } |
| 189 |
| 205 if (displayingPoster) | 190 if (displayingPoster) |
| 206 paintIntoRect(paintInfo.context, rect); | 191 paintIntoRect(context, rect); |
| 207 else if (document()->view() && document()->view()->paintBehavior() & PaintBe
haviorFlattenCompositingLayers) | 192 else if (document()->view() && document()->view()->paintBehavior() & PaintBe
haviorFlattenCompositingLayers) |
| 208 mediaPlayer->paintCurrentFrameInContext(paintInfo.context, pixelSnappedI
ntRect(rect)); | 193 mediaPlayer->paintCurrentFrameInContext(context, pixelSnappedIntRect(rec
t)); |
| 209 else | 194 else |
| 210 mediaPlayer->paint(paintInfo.context, pixelSnappedIntRect(rect)); | 195 mediaPlayer->paint(context, pixelSnappedIntRect(rect)); |
| 196 |
| 197 if (clip) |
| 198 context->restore(); |
| 211 } | 199 } |
| 212 | 200 |
| 213 void RenderVideo::layout() | 201 void RenderVideo::layout() |
| 214 { | 202 { |
| 215 StackStats::LayoutCheckPoint layoutCheckPoint; | 203 StackStats::LayoutCheckPoint layoutCheckPoint; |
| 216 RenderMedia::layout(); | 204 RenderMedia::layout(); |
| 217 updatePlayer(); | 205 updatePlayer(); |
| 218 } | 206 } |
| 219 | 207 |
| 220 HTMLVideoElement* RenderVideo::videoElement() const | 208 HTMLVideoElement* RenderVideo::videoElement() const |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 290 } |
| 303 | 291 |
| 304 LayoutUnit RenderVideo::offsetHeight() const | 292 LayoutUnit RenderVideo::offsetHeight() const |
| 305 { | 293 { |
| 306 if (const RenderBlock* block = rendererPlaceholder(this)) | 294 if (const RenderBlock* block = rendererPlaceholder(this)) |
| 307 return block->offsetHeight(); | 295 return block->offsetHeight(); |
| 308 return RenderMedia::offsetHeight(); | 296 return RenderMedia::offsetHeight(); |
| 309 } | 297 } |
| 310 | 298 |
| 311 } // namespace WebCore | 299 } // namespace WebCore |
| OLD | NEW |