[Blackberry][FullScreen] HTML5 <video> controls are scaled differently depending...
authortonikitoo@webkit.org <tonikitoo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Jul 2012 16:21:12 +0000 (16:21 +0000)
committertonikitoo@webkit.org <tonikitoo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Jul 2012 16:21:12 +0000 (16:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90884
PR #162839

Reviewed by Rob Buis.
Patch by Antonio Gomes <agomes@rim.com>

The way the BlackBerry port implements the FULLSCREEN_API for media
elements might result in the controls being oversized, proportionally
to the current page scale. That happens because the fullscreen element
gets sized to be as big as the viewport size, and the viewport size might
get outstretched to fit to the screen dimensions.

In order to fix that, the patch strips out the Page scale factor from
the media controls multiplier.

Patch also changes many integer-based calculations to be float-based, in
order to get the needed precision.

Internally reviewed by Jacky Jiang.

* platform/blackberry/RenderThemeBlackBerry.cpp:
(WebCore):
(WebCore::determineFullScreenMultiplier):
(WebCore::RenderThemeBlackBerry::adjustSliderThumbSize):
(WebCore::RenderThemeBlackBerry::adjustMediaControlStyle):
(WebCore::RenderThemeBlackBerry::adjustSliderTrackStyle):
(WebCore::RenderThemeBlackBerry::paintMediaSliderTrack):
(WebCore::RenderThemeBlackBerry::paintMediaSliderThumb):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@124214 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/blackberry/RenderThemeBlackBerry.cpp

index a217f7934430c8c9f29e4a6dca50516e397c884d..298ea8ebf2e8d66ce21f12f4a5c70a3cbd2d0f27 100644 (file)
@@ -1,3 +1,34 @@
+2012-07-17  Antonio Gomes  <agomes@rim.com>
+
+        [Blackberry][FullScreen] HTML5 <video> controls are scaled differently depending on the current webpage scale
+        https://bugs.webkit.org/show_bug.cgi?id=90884
+        PR #162839
+
+        Reviewed by Rob Buis.
+
+        The way the BlackBerry port implements the FULLSCREEN_API for media
+        elements might result in the controls being oversized, proportionally
+        to the current page scale. That happens because the fullscreen element
+        gets sized to be as big as the viewport size, and the viewport size might
+        get outstretched to fit to the screen dimensions.
+
+        In order to fix that, the patch strips out the Page scale factor from
+        the media controls multiplier.
+
+        Patch also changes many integer-based calculations to be float-based, in
+        order to get the needed precision.
+
+        Internally reviewed by Jacky Jiang.
+
+        * platform/blackberry/RenderThemeBlackBerry.cpp:
+        (WebCore):
+        (WebCore::determineFullScreenMultiplier):
+        (WebCore::RenderThemeBlackBerry::adjustSliderThumbSize):
+        (WebCore::RenderThemeBlackBerry::adjustMediaControlStyle):
+        (WebCore::RenderThemeBlackBerry::adjustSliderTrackStyle):
+        (WebCore::RenderThemeBlackBerry::paintMediaSliderTrack):
+        (WebCore::RenderThemeBlackBerry::paintMediaSliderThumb):
+
 2012-07-31  Stephen White  <senorblanco@chromium.org>
 
         Remove the clone() method from FilterOperation (and subclasses).
index 7e258816fa67bc1c3549a1198893b74a76a10b06..351a2b8b595efc73b46b97b09becc9742d0700e6 100644 (file)
 #include "CSSValueKeywords.h"
 #include "Frame.h"
 #include "HTMLMediaElement.h"
+#include "HostWindow.h"
 #include "MediaControlElements.h"
 #include "MediaPlayerPrivateBlackBerry.h"
 #include "Page.h"
 #include "PaintInfo.h"
+#include "RenderFullScreen.h"
 #include "RenderProgress.h"
 #include "RenderSlider.h"
 #include "RenderView.h"
@@ -39,13 +41,13 @@ namespace WebCore {
 const unsigned smallRadius = 1;
 const unsigned largeRadius = 3;
 const unsigned lineWidth = 1;
-const int marginSize = 4;
-const int mediaControlsHeight = 32;
-const int mediaSliderThumbWidth = 40;
-const int mediaSliderThumbHeight = 13;
-const int mediaSliderThumbRadius = 5;
-const int sliderThumbWidth = 15;
-const int sliderThumbHeight = 25;
+const float marginSize = 4;
+const float mediaControlsHeight = 32;
+const float mediaSliderThumbWidth = 40;
+const float mediaSliderThumbHeight = 13;
+const float mediaSliderThumbRadius = 5;
+const float sliderThumbWidth = 15;
+const float sliderThumbHeight = 25;
 
 // Checkbox check scalers
 const float checkboxLeftX = 7 / 40.0;
@@ -158,13 +160,23 @@ static RenderSlider* determineRenderSlider(RenderObject* object)
     return toRenderSlider(object);
 }
 
-static int determineFullScreenMultiplier(Element* element)
+static float determineFullScreenMultiplier(Element* element)
 {
-    int fullScreenMultiplier = 1;
+    float fullScreenMultiplier = 1.0;
 #if ENABLE(FULLSCREEN_API) && ENABLE(VIDEO)
     if (element && element->document()->webkitIsFullScreen() && element->document()->webkitCurrentFullScreenElement() == toParentMediaElement(element)) {
         if (element->document()->page()->deviceScaleFactor() < scaleFactorThreshold)
             fullScreenMultiplier = fullScreenEnlargementFactor;
+
+        // The way the BlackBerry port implements the FULLSCREEN_API for media elements
+        // might result in the controls being oversized, proportionally to the current page
+        // scale. That happens because the fullscreen element gets sized to be as big as the
+        // viewport size, and the viewport size might get outstretched to fit to the screen dimensions.
+        // To fix that, lets strips out the Page scale factor from the media controls multiplier.
+        float scaleFactor = element->document()->view()->hostWindow()->platformPageClient()->currentZoomFactor();
+        static ViewportArguments defaultViewportArguments;
+        float scaleFactorFudge = element->document()->page()->viewportArguments() != defaultViewportArguments ? .5 : .85;
+        fullScreenMultiplier /= scaleFactor * scaleFactorFudge;
     }
 #endif
     return fullScreenMultiplier;
@@ -629,7 +641,7 @@ bool RenderThemeBlackBerry::paintMenuListButton(RenderObject* object, const Pain
 
 void RenderThemeBlackBerry::adjustSliderThumbSize(RenderStyle* style, Element* element) const
 {
-    int fullScreenMultiplier = 1;
+    float fullScreenMultiplier = 1;
     ControlPart part = style->appearance();
 
     if (part == MediaSliderThumbPart || part == MediaVolumeSliderThumbPart) {
@@ -750,14 +762,15 @@ bool RenderThemeBlackBerry::paintSliderThumb(RenderObject* object, const PaintIn
 
 void RenderThemeBlackBerry::adjustMediaControlStyle(StyleResolver*, RenderStyle* style, Element* element) const
 {
-    int fullScreenMultiplier = determineFullScreenMultiplier(element);
+    float fullScreenMultiplier = determineFullScreenMultiplier(element);
 
     // We use multiples of mediaControlsHeight to make all objects scale evenly
     Length controlsHeight(mediaControlsHeight * fullScreenMultiplier, Fixed);
     Length timeWidth(mediaControlsHeight * 3 / 2 * fullScreenMultiplier, Fixed);
     Length volumeHeight(mediaControlsHeight * 4 * fullScreenMultiplier, Fixed);
     Length padding(mediaControlsHeight / 8 * fullScreenMultiplier, Fixed);
-    int fontSize = mediaControlsHeight / 2 * fullScreenMultiplier;
+    float fontSize = mediaControlsHeight / 2 * fullScreenMultiplier;
+
     switch (style->appearance()) {
     case MediaPlayButtonPart:
     case MediaEnterFullscreenButtonPart:
@@ -785,7 +798,7 @@ void RenderThemeBlackBerry::adjustMediaControlStyle(StyleResolver*, RenderStyle*
 
 void RenderThemeBlackBerry::adjustSliderTrackStyle(StyleResolver*, RenderStyle* style, Element* element) const
 {
-    int fullScreenMultiplier = determineFullScreenMultiplier(element);
+    float fullScreenMultiplier = determineFullScreenMultiplier(element);
 
     // We use multiples of mediaControlsHeight to make all objects scale evenly
     Length controlsHeight(mediaControlsHeight * fullScreenMultiplier, Fixed);
@@ -881,7 +894,7 @@ bool RenderThemeBlackBerry::paintMediaSliderTrack(RenderObject* object, const Pa
     if (!mediaElement)
         return false;
 
-    int fullScreenMultiplier = determineFullScreenMultiplier(mediaElement);
+    float fullScreenMultiplier = determineFullScreenMultiplier(mediaElement);
     float loaded = 0;
     // FIXME: replace loaded with commented out one when buffer bug is fixed (see comment in
     // MediaPlayerPrivateMMrenderer::percentLoaded).
@@ -890,14 +903,14 @@ bool RenderThemeBlackBerry::paintMediaSliderTrack(RenderObject* object, const Pa
         loaded = static_cast<MediaPlayerPrivate *>(mediaElement->player()->implementation())->percentLoaded();
     float position = mediaElement->duration() > 0 ? (mediaElement->currentTime() / mediaElement->duration()) : 0;
 
-    int x = rect.x() + 2 * fullScreenMultiplier - fullScreenMultiplier / 2;
-    int y = rect.y() + 14 * fullScreenMultiplier + fullScreenMultiplier / 2;
-    int w = rect.width() - 4 * fullScreenMultiplier + fullScreenMultiplier / 2;
-    int h = 2 * fullScreenMultiplier;
+    int x = ceil(rect.x() + 2 * fullScreenMultiplier - fullScreenMultiplier / 2);
+    int y = ceil(rect.y() + 14 * fullScreenMultiplier + fullScreenMultiplier / 2);
+    int w = ceil(rect.width() - 4 * fullScreenMultiplier + fullScreenMultiplier / 2);
+    int h = ceil(2 * fullScreenMultiplier);
     IntRect rect2(x, y, w, h);
 
-    int wPlayed = (w * position);
-    int wLoaded = (w - mediaSliderThumbWidth * fullScreenMultiplier) * loaded + mediaSliderThumbWidth * fullScreenMultiplier;
+    int wPlayed = ceil(w * position);
+    int wLoaded = ceil((w - mediaSliderThumbWidth * fullScreenMultiplier) * loaded + mediaSliderThumbWidth * fullScreenMultiplier);
 
     IntRect played(x, y, wPlayed, h);
     IntRect buffered(x, y, wLoaded, h);
@@ -929,7 +942,7 @@ bool RenderThemeBlackBerry::paintMediaSliderThumb(RenderObject* object, const Pa
     if (!slider)
         return false;
 
-    int fullScreenMultiplier = determineFullScreenMultiplier(toElement(slider->node()));
+    float fullScreenMultiplier = determineFullScreenMultiplier(toElement(slider->node()));
 
     paintInfo.context->save();
     Path mediaThumbRoundedRectangle;