<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[186817] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/186817">186817</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-07-14 14:39:34 -0700 (Tue, 14 Jul 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Input buttons rendered at the wrong size when pinching-to-zoom
https://bugs.webkit.org/show_bug.cgi?id=146916
Patch by Wenson Hsieh <wenson_hsieh@apple.com> on 2015-07-14
Reviewed by Dean Jackson.
Scales buttons and their focus rects up when pinching to zoom by painting to an offscreen ImageBuffer which is
then scaled and painted onto the display.
* platform/Theme.h: Modified signature of Theme::paint.
(WebCore::Theme::paint): Added plumbing necessary to send the device and page scale factors to paintButton.
* platform/mac/ThemeMac.h: Modified signature of paintButton.
* platform/mac/ThemeMac.mm: Added ImageBuffer.h header.
(WebCore::buttonFocusRectOutlineWidth): Represents the width of the focus rect of a button. Used by paintButton
to determine the size of the ImageBuffer required to draw a focus rect.
(WebCore::paintButton): Changed to paint button cells and the focus rect, if applicable, to a temporary ImageBuffer
before painting the ImageBuffer onto the view. Refactored to receive a deviceScaleFactor and page scale factor,
used when painting to the ImageBuffer.
(WebCore::ThemeMac::paint): Added plumbing necessary to send the device and page scale factors to paintButton.
* rendering/RenderTheme.cpp: Modified signature of RenderTheme::paint.
(WebCore::RenderTheme::paint): Added plumbing necessary to send the device and page scale factors to paintButton.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformThemeh">trunk/Source/WebCore/platform/Theme.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmacThemeMach">trunk/Source/WebCore/platform/mac/ThemeMac.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmacThemeMacmm">trunk/Source/WebCore/platform/mac/ThemeMac.mm</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderThemecpp">trunk/Source/WebCore/rendering/RenderTheme.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (186816 => 186817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-07-14 21:19:50 UTC (rev 186816)
+++ trunk/Source/WebCore/ChangeLog        2015-07-14 21:39:34 UTC (rev 186817)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2015-07-14 Wenson Hsieh <wenson_hsieh@apple.com>
+
+ Input buttons rendered at the wrong size when pinching-to-zoom
+ https://bugs.webkit.org/show_bug.cgi?id=146916
+
+ Reviewed by Dean Jackson.
+
+ Scales buttons and their focus rects up when pinching to zoom by painting to an offscreen ImageBuffer which is
+ then scaled and painted onto the display.
+
+ * platform/Theme.h: Modified signature of Theme::paint.
+ (WebCore::Theme::paint): Added plumbing necessary to send the device and page scale factors to paintButton.
+ * platform/mac/ThemeMac.h: Modified signature of paintButton.
+ * platform/mac/ThemeMac.mm: Added ImageBuffer.h header.
+ (WebCore::buttonFocusRectOutlineWidth): Represents the width of the focus rect of a button. Used by paintButton
+ to determine the size of the ImageBuffer required to draw a focus rect.
+ (WebCore::paintButton): Changed to paint button cells and the focus rect, if applicable, to a temporary ImageBuffer
+ before painting the ImageBuffer onto the view. Refactored to receive a deviceScaleFactor and page scale factor,
+ used when painting to the ImageBuffer.
+ (WebCore::ThemeMac::paint): Added plumbing necessary to send the device and page scale factors to paintButton.
+ * rendering/RenderTheme.cpp: Modified signature of RenderTheme::paint.
+ (WebCore::RenderTheme::paint): Added plumbing necessary to send the device and page scale factors to paintButton.
+
</ins><span class="cx"> 2015-07-14 Commit Queue <commit-queue@webkit.org>
</span><span class="cx">
</span><span class="cx"> Unreviewed, rolling out r186809.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformThemeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/Theme.h (186816 => 186817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/Theme.h        2015-07-14 21:19:50 UTC (rev 186816)
+++ trunk/Source/WebCore/platform/Theme.h        2015-07-14 21:39:34 UTC (rev 186817)
</span><span class="lines">@@ -100,7 +100,7 @@
</span><span class="cx"> virtual bool controlRequiresPreWhiteSpace(ControlPart) const { return false; }
</span><span class="cx">
</span><span class="cx"> // Method for painting a control. The rect is in zoomed coordinates.
</span><del>- virtual void paint(ControlPart, ControlStates*, GraphicsContext*, const FloatRect& /*zoomedRect*/, float /*zoomFactor*/, ScrollView*) { }
</del><ins>+ virtual void paint(ControlPart, ControlStates*, GraphicsContext*, const FloatRect& /*zoomedRect*/, float /*zoomFactor*/, ScrollView*, float /*deviceScaleFactor*/, float /*pageScaleFactor*/) { }
</ins><span class="cx">
</span><span class="cx"> // Some controls may spill out of their containers (e.g., the check on an OS X checkbox). When these controls repaint,
</span><span class="cx"> // the theme needs to communicate this inflated rect to the engine so that it can invalidate the whole control.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacThemeMach"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/ThemeMac.h (186816 => 186817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/ThemeMac.h        2015-07-14 21:19:50 UTC (rev 186816)
+++ trunk/Source/WebCore/platform/mac/ThemeMac.h        2015-07-14 21:39:34 UTC (rev 186817)
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx">
</span><span class="cx"> virtual bool controlRequiresPreWhiteSpace(ControlPart part) const override { return part == PushButtonPart; }
</span><span class="cx">
</span><del>- virtual void paint(ControlPart, ControlStates*, GraphicsContext*, const FloatRect&, float zoomFactor, ScrollView*) override;
</del><ins>+ virtual void paint(ControlPart, ControlStates*, GraphicsContext*, const FloatRect&, float zoomFactor, ScrollView*, float deviceScaleFactor, float pageScaleFactor) override;
</ins><span class="cx"> virtual void inflateControlPaintRect(ControlPart, const ControlStates*, FloatRect&, float zoomFactor) const override;
</span><span class="cx">
</span><span class="cx"> // FIXME: Once RenderThemeMac is converted over to use Theme then this can be internal to ThemeMac.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmacThemeMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mac/ThemeMac.mm (186816 => 186817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mac/ThemeMac.mm        2015-07-14 21:19:50 UTC (rev 186816)
+++ trunk/Source/WebCore/platform/mac/ThemeMac.mm        2015-07-14 21:39:34 UTC (rev 186817)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #import "AXObjectCache.h"
</span><span class="cx"> #import "BlockExceptions.h"
</span><span class="cx"> #import "GraphicsContext.h"
</span><ins>+#import "ImageBuffer.h"
</ins><span class="cx"> #import "LocalCurrentGraphicsContext.h"
</span><span class="cx"> #import "ScrollView.h"
</span><span class="cx"> #import "WebCoreSystemInterface.h"
</span><span class="lines">@@ -530,8 +531,13 @@
</span><span class="cx"> return cell;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void paintButton(ControlPart part, ControlStates* controlStates, GraphicsContext* context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
</del><ins>+static float buttonFocusRectOutlineWidth()
</ins><span class="cx"> {
</span><ins>+ return 3.0f;
+}
+
+static void paintButton(ControlPart part, ControlStates* controlStates, GraphicsContext* context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView, float deviceScaleFactor, float pageScaleFactor)
+{
</ins><span class="cx"> BEGIN_BLOCK_OBJC_EXCEPTIONS
</span><span class="cx">
</span><span class="cx"> // Determine the width and height needed for the control and prepare the cell for painting.
</span><span class="lines">@@ -561,9 +567,19 @@
</span><span class="cx"> context->scale(FloatSize(zoomFactor, zoomFactor));
</span><span class="cx"> context->translate(-inflatedRect.x(), -inflatedRect.y());
</span><span class="cx"> }
</span><del>- }
-
- LocalCurrentGraphicsContext localContext(context);
</del><ins>+ }
+
+ bool shouldUseImageBuffer = pageScaleFactor != 1.0f || zoomFactor != 1.0f;
+ float focusThickness = buttonFocusRectOutlineWidth();
+
+ std::unique_ptr<ImageBuffer> imageBuffer;
+ GraphicsContext* drawButtonContext = context;
+ if (shouldUseImageBuffer) {
+ imageBuffer = ImageBuffer::createCompatibleBuffer(inflatedRect.size() + 2 * FloatSize(focusThickness, focusThickness), deviceScaleFactor, ColorSpaceDeviceRGB, context, false);
+ drawButtonContext = imageBuffer->context();
+ }
+ LocalCurrentGraphicsContext localContext(drawButtonContext);
+
</ins><span class="cx"> NSView *view = ThemeMac::ensuredView(scrollView, controlStates);
</span><span class="cx"> NSWindow *window = [view window];
</span><span class="cx"> NSButtonCell *previousDefaultButtonCell = [window defaultButtonCell];
</span><span class="lines">@@ -576,13 +592,23 @@
</span><span class="cx"> } else if ([previousDefaultButtonCell isEqual:buttonCell])
</span><span class="cx"> [window setDefaultButtonCell:nil];
</span><span class="cx">
</span><del>- [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view];
- bool needsRepaint = false;
- if (states & ControlStates::FocusState)
- needsRepaint = drawCellFocusRing(buttonCell, inflatedRect, view);
</del><ins>+ if (shouldUseImageBuffer) {
+ [buttonCell drawWithFrame:CGRectMake(focusThickness, focusThickness, inflatedRect.width(), inflatedRect.height()) inView:view];
+ if (!(states & ControlStates::FocusState))
+ context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, inflatedRect.location() - FloatSize(focusThickness, focusThickness));
+ } else
+ [buttonCell drawWithFrame:CGRect(inflatedRect) inView:view];
+
+ if (states & ControlStates::FocusState) {
+ if (shouldUseImageBuffer) {
+ drawCellFocusRing(buttonCell, CGRectMake(focusThickness, focusThickness, inflatedRect.width(), inflatedRect.height()), view);
+ context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, inflatedRect.location() - FloatSize(focusThickness, focusThickness));
+ } else
+ drawCellFocusRing(buttonCell, inflatedRect, view);
+ }
+
+ controlStates->setNeedsRepaint(false);
</ins><span class="cx">
</span><del>- controlStates->setNeedsRepaint(needsRepaint);
-
</del><span class="cx"> [buttonCell setControlView:nil];
</span><span class="cx">
</span><span class="cx"> if (![previousDefaultButtonCell isEqual:buttonCell])
</span><span class="lines">@@ -823,7 +849,7 @@
</span><span class="cx"> END_BLOCK_OBJC_EXCEPTIONS
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void ThemeMac::paint(ControlPart part, ControlStates* states, GraphicsContext* context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
</del><ins>+void ThemeMac::paint(ControlPart part, ControlStates* states, GraphicsContext* context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView, float deviceScaleFactor, float pageScaleFactor)
</ins><span class="cx"> {
</span><span class="cx"> switch (part) {
</span><span class="cx"> case CheckboxPart:
</span><span class="lines">@@ -836,7 +862,7 @@
</span><span class="cx"> case DefaultButtonPart:
</span><span class="cx"> case ButtonPart:
</span><span class="cx"> case SquareButtonPart:
</span><del>- paintButton(part, states, context, zoomedRect, zoomFactor, scrollView);
</del><ins>+ paintButton(part, states, context, zoomedRect, zoomFactor, scrollView, deviceScaleFactor, pageScaleFactor);
</ins><span class="cx"> break;
</span><span class="cx"> case InnerSpinButtonPart:
</span><span class="cx"> paintStepper(states, context, zoomedRect, zoomFactor, scrollView);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderThemecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderTheme.cpp (186816 => 186817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderTheme.cpp        2015-07-14 21:19:50 UTC (rev 186816)
+++ trunk/Source/WebCore/rendering/RenderTheme.cpp        2015-07-14 21:39:34 UTC (rev 186817)
</span><span class="lines">@@ -277,9 +277,12 @@
</span><span class="cx">
</span><span class="cx"> ControlPart part = o.style().appearance();
</span><span class="cx"> IntRect integralSnappedRect = snappedIntRect(r);
</span><del>- FloatRect devicePixelSnappedRect = snapRectToDevicePixels(r, o.document().deviceScaleFactor());
</del><ins>+ float deviceScaleFactor = o.document().deviceScaleFactor();
+ FloatRect devicePixelSnappedRect = snapRectToDevicePixels(r, deviceScaleFactor);
</ins><span class="cx">
</span><span class="cx"> #if USE(NEW_THEME)
</span><ins>+ float pageScaleFactor = o.document().page() ? o.document().page()->pageScaleFactor() : 1.0f;
+
</ins><span class="cx"> switch (part) {
</span><span class="cx"> case CheckboxPart:
</span><span class="cx"> case RadioPart:
</span><span class="lines">@@ -289,7 +292,7 @@
</span><span class="cx"> case ButtonPart:
</span><span class="cx"> case InnerSpinButtonPart:
</span><span class="cx"> updateControlStatesForRenderer(o, controlStates);
</span><del>- m_theme->paint(part, controlStates, const_cast<GraphicsContext*>(paintInfo.context), devicePixelSnappedRect, o.style().effectiveZoom(), &o.view().frameView());
</del><ins>+ m_theme->paint(part, controlStates, const_cast<GraphicsContext*>(paintInfo.context), devicePixelSnappedRect, o.style().effectiveZoom(), &o.view().frameView(), deviceScaleFactor, pageScaleFactor);
</ins><span class="cx"> return false;
</span><span class="cx"> default:
</span><span class="cx"> break;
</span></span></pre>
</div>
</div>
</body>
</html>