Title: [188510] trunk/Source/WebCore
Revision
188510
Author
wenson_hs...@apple.com
Date
2015-08-15 10:50:04 -0700 (Sat, 15 Aug 2015)

Log Message

Search fields should scale when rendering while zoomed
https://bugs.webkit.org/show_bug.cgi?id=147867

Reviewed by Daniel Bates.

When rendering zoomed search fields, draw to an image buffer instead of drawing directly into the context. This
allows us to scale the image buffer up before rendering. Also refactors common logic used to draw both selects
(paintMenuList) and search fields into the new private method paintCellAndSetFocusedElementNeedsRepaintIfNecessary.

* rendering/RenderThemeMac.h: Changed drawCellOrFocusRingWithViewIntoContext to take a raw pointer.
* rendering/RenderThemeMac.mm:
(WebCore::paintToggleButton): Passes a raw pointer to drawCellOrFocusRingWithViewIntoContext.
(WebCore::ThemeMac::drawCellOrFocusRingWithViewIntoContext): Changed to take a raw pointer.
* rendering/RenderThemeMac.h:
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::paintMenuList): Refactored to use paintCellAndSetFocusedElementNeedsRepaintIfNecessary.
(WebCore::RenderThemeMac::paintCellAndSetFocusedElementNeedsRepaintIfNecessary): Contains logic common to painting
    both selects and search fields.
(WebCore::RenderThemeMac::paintSearchField): Use ThemeMac::drawCellOrFocusRingWithViewIntoContext
    to render search fields, utilizing an offscreen image buffer only when necessary.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (188509 => 188510)


--- trunk/Source/WebCore/ChangeLog	2015-08-15 05:51:04 UTC (rev 188509)
+++ trunk/Source/WebCore/ChangeLog	2015-08-15 17:50:04 UTC (rev 188510)
@@ -1,3 +1,26 @@
+2015-08-15  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Search fields should scale when rendering while zoomed
+        https://bugs.webkit.org/show_bug.cgi?id=147867
+
+        Reviewed by Daniel Bates.
+
+        When rendering zoomed search fields, draw to an image buffer instead of drawing directly into the context. This
+        allows us to scale the image buffer up before rendering. Also refactors common logic used to draw both selects
+        (paintMenuList) and search fields into the new private method paintCellAndSetFocusedElementNeedsRepaintIfNecessary.
+
+        * rendering/RenderThemeMac.h: Changed drawCellOrFocusRingWithViewIntoContext to take a raw pointer.
+        * rendering/RenderThemeMac.mm:
+        (WebCore::paintToggleButton): Passes a raw pointer to drawCellOrFocusRingWithViewIntoContext.
+        (WebCore::ThemeMac::drawCellOrFocusRingWithViewIntoContext): Changed to take a raw pointer.
+        * rendering/RenderThemeMac.h:
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::paintMenuList): Refactored to use paintCellAndSetFocusedElementNeedsRepaintIfNecessary.
+        (WebCore::RenderThemeMac::paintCellAndSetFocusedElementNeedsRepaintIfNecessary): Contains logic common to painting
+            both selects and search fields.
+        (WebCore::RenderThemeMac::paintSearchField): Use ThemeMac::drawCellOrFocusRingWithViewIntoContext
+            to render search fields, utilizing an offscreen image buffer only when necessary.
+
 2015-08-14  Chris Dumez  <cdu...@apple.com>
 
         Refactor HTMLCollection to be as fast as CachedLiveNodeList

Modified: trunk/Source/WebCore/platform/mac/ThemeMac.h (188509 => 188510)


--- trunk/Source/WebCore/platform/mac/ThemeMac.h	2015-08-15 05:51:04 UTC (rev 188509)
+++ trunk/Source/WebCore/platform/mac/ThemeMac.h	2015-08-15 17:50:04 UTC (rev 188510)
@@ -58,7 +58,7 @@
     // FIXME: Once RenderThemeMac is converted over to use Theme then this can be internal to ThemeMac.
     static NSView* ensuredView(ScrollView*, const ControlStates&, bool useUnparentedView = false);
     static void setFocusRingClipRect(const FloatRect&);
-    static bool drawCellOrFocusRingWithViewIntoContext(RetainPtr<NSCell>, GraphicsContext*, const FloatRect&, NSView*, bool /* drawButtonCell */, bool /* drawFocusRing */, bool /* useImageBuffer */, float /* deviceScaleFactor */);
+    static bool drawCellOrFocusRingWithViewIntoContext(NSCell*, GraphicsContext*, const FloatRect&, NSView*, bool /* drawButtonCell */, bool /* drawFocusRing */, bool /* useImageBuffer */, float /* deviceScaleFactor */);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/mac/ThemeMac.mm (188509 => 188510)


--- trunk/Source/WebCore/platform/mac/ThemeMac.mm	2015-08-15 05:51:04 UTC (rev 188509)
+++ trunk/Source/WebCore/platform/mac/ThemeMac.mm	2015-08-15 17:50:04 UTC (rev 188510)
@@ -437,9 +437,9 @@
 
         [toggleButtonCell _renderCurrentAnimationFrameInContext:context->platformContext() atLocation:NSMakePoint(0, 0)];
         if (![toggleButtonCell _stateAnimationRunning] && isCellFocused)
-            needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, false, true, useImageBuffer, deviceScaleFactor);
+            needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell.get(), context, inflatedRect, view, false, true, useImageBuffer, deviceScaleFactor);
     } else
-        needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, true, isCellFocused, useImageBuffer, deviceScaleFactor);
+        needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell.get(), context, inflatedRect, view, true, isCellFocused, useImageBuffer, deviceScaleFactor);
 #else
     needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, true, isCellFocused, useImageBuffer, deviceScaleFactor);
 #endif
@@ -664,7 +664,7 @@
 
 const float buttonFocusRectOutlineWidth = 3.0f;
 
-bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(RetainPtr<NSCell> cell, GraphicsContext* context, const FloatRect& inflatedRect, NSView* view, bool drawButtonCell, bool drawFocusRing, bool useImageBuffer, float deviceScaleFactor)
+bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(NSCell* cell, GraphicsContext* context, const FloatRect& inflatedRect, NSView* view, bool drawButtonCell, bool drawFocusRing, bool useImageBuffer, float deviceScaleFactor)
 {
     ASSERT(drawButtonCell || drawFocusRing);
     bool needsRepaint = false;
@@ -677,7 +677,7 @@
                 [cell drawWithFrame:imageBufferDrawRect inView:view];
             
             if (drawFocusRing)
-                needsRepaint = drawCellFocusRing(cell.get(), imageBufferDrawRect, view);
+                needsRepaint = drawCellFocusRing(cell, imageBufferDrawRect, view);
         }
         context->drawImageBuffer(imageBuffer.get(), ColorSpaceSRGB, inflatedRect.location() - FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth));
         return needsRepaint;
@@ -686,7 +686,7 @@
         [cell drawWithFrame:NSRect(inflatedRect) inView:view];
     
     if (drawFocusRing)
-        needsRepaint = drawCellFocusRing(cell.get(), NSRect(inflatedRect), view);
+        needsRepaint = drawCellFocusRing(cell, NSRect(inflatedRect), view);
     
     return needsRepaint;
 }

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.h (188509 => 188510)


--- trunk/Source/WebCore/rendering/RenderThemeMac.h	2015-08-15 05:51:04 UTC (rev 188509)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.h	2015-08-15 17:50:04 UTC (rev 188510)
@@ -196,6 +196,7 @@
 
     // Helpers for adjusting appearance and for painting
 
+    void paintCellAndSetFocusedElementNeedsRepaintIfNecessary(NSCell*, const RenderObject&, const PaintInfo&, const FloatRect&);
     void setPopupButtonCellState(const RenderObject&, const IntSize&);
     const IntSize* popupButtonSizes() const;
     const int* popupButtonMargins() const;

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (188509 => 188510)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2015-08-15 05:51:04 UTC (rev 188509)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2015-08-15 17:50:04 UTC (rev 188510)
@@ -946,16 +946,7 @@
         paintInfo.context->translate(-inflatedRect.x(), -inflatedRect.y());
     }
 
-    NSView *view = documentViewFor(renderer);
-    Page* page = renderer.document().page();
-    float pageScaleFactor = page->pageScaleFactor();
-    float deviceScaleFactor = page->deviceScaleFactor();
-    bool shouldDrawFocusRing = isFocused(renderer) && renderer.style().outlineStyleIsAuto();
-    bool shouldUseImageBuffer = zoomLevel != 1.0f || pageScaleFactor != 1.0f;
-    bool shouldDrawCell = true;
-    if (ThemeMac::drawCellOrFocusRingWithViewIntoContext(popupButton, paintInfo.context, inflatedRect, view, shouldDrawCell, shouldDrawFocusRing, shouldUseImageBuffer, deviceScaleFactor))
-        page->focusController().setFocusedElementNeedsRepaint();
-
+    paintCellAndSetFocusedElementNeedsRepaintIfNecessary(popupButton, renderer, paintInfo, inflatedRect);
     [popupButton setControlView:nil];
 
     return false;
@@ -1464,6 +1455,16 @@
     updatePressedState(popupButton, o);
 }
 
+void RenderThemeMac::paintCellAndSetFocusedElementNeedsRepaintIfNecessary(NSCell* cell, const RenderObject& renderer, const PaintInfo& paintInfo, const FloatRect& rect)
+{
+    Page* page = renderer.document().page();
+    bool shouldDrawFocusRing = isFocused(renderer) && renderer.style().outlineStyleIsAuto();
+    bool shouldUseImageBuffer = renderer.style().effectiveZoom() != 1 || page->pageScaleFactor() != 1;
+    bool shouldDrawCell = true;
+    if (ThemeMac::drawCellOrFocusRingWithViewIntoContext(cell, paintInfo.context, rect, documentViewFor(renderer), shouldDrawCell, shouldDrawFocusRing, shouldUseImageBuffer, page->deviceScaleFactor()))
+        page->focusController().setFocusedElementNeedsRepaint();
+}
+
 const IntSize* RenderThemeMac::menuListSizes() const
 {
     static const IntSize sizes[3] = { IntSize(9, 0), IntSize(5, 0), IntSize(0, 0) };
@@ -1616,17 +1617,10 @@
     // Set the search button to nil before drawing.  Then reset it so we can draw it later.
     [search setSearchButtonCell:nil];
 
-    NSView *documentView = documentViewFor(o);
-    [search drawWithFrame:NSRect(unzoomedRect) inView:documentView];
-
+    paintCellAndSetFocusedElementNeedsRepaintIfNecessary(search, o, paintInfo, unzoomedRect);
     [search setControlView:nil];
     [search resetSearchButtonCell];
 
-    if (isFocused(o) && o.style().outlineStyleIsAuto()) {
-        if (wkDrawCellFocusRingWithFrameAtTime(search, NSRect(unzoomedRect), documentView, std::numeric_limits<double>::max()))
-            o.document().page()->focusController().setFocusedElementNeedsRepaint();
-    }
-    
     return false;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to