Search fields should scale when rendering while zoomed
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Aug 2015 17:50:04 +0000 (17:50 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Aug 2015 17:50:04 +0000 (17:50 +0000)
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.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/ThemeMac.h
Source/WebCore/platform/mac/ThemeMac.mm
Source/WebCore/rendering/RenderThemeMac.h
Source/WebCore/rendering/RenderThemeMac.mm

index 01c18aeeaaaef0fec59ee0295fa0d7ffd21c91f6..57c8450a874aec88e1215e2f8b12a22702aff11a 100644 (file)
@@ -1,3 +1,26 @@
+2015-08-15  Wenson Hsieh  <wenson_hsieh@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  <cdumez@apple.com>
 
         Refactor HTMLCollection to be as fast as CachedLiveNodeList
index d30487207ec7faa4b0429adbae1447bfcbba9122..f8ee16eb9ea12143b2125f08afd63606cc841712 100644 (file)
@@ -58,7 +58,7 @@ public:
     // 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
index 9e74595583e77dda2c713ad5840fa0d6aa6861c9..891b7f2aa73f663376f028bd81d33880a0610ab2 100644 (file)
@@ -437,9 +437,9 @@ static void paintToggleButton(ControlPart buttonType, ControlStates& controlStat
 
         [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 @@ void ThemeMac::setFocusRingClipRect(const FloatRect& rect)
 
 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 @@ bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(RetainPtr<NSCell> cell, Gr
                 [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 @@ bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(RetainPtr<NSCell> cell, Gr
         [cell drawWithFrame:NSRect(inflatedRect) inView:view];
     
     if (drawFocusRing)
-        needsRepaint = drawCellFocusRing(cell.get(), NSRect(inflatedRect), view);
+        needsRepaint = drawCellFocusRing(cell, NSRect(inflatedRect), view);
     
     return needsRepaint;
 }
index e2e06084ed0dd142bee1c50b83a9d02b68e62edf..14a0e4c616a35b1f5520ba49df24f070f4a67252 100644 (file)
@@ -196,6 +196,7 @@ private:
 
     // 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;
index a87199182cb26ebbf81f98a411efebd151e62041..7b85342780866ec1d71c149446e8f5e9933385eb 100644 (file)
@@ -946,16 +946,7 @@ bool RenderThemeMac::paintMenuList(const RenderObject& renderer, const PaintInfo
         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 @@ void RenderThemeMac::setPopupButtonCellState(const RenderObject& o, const IntSiz
     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 @@ bool RenderThemeMac::paintSearchField(const RenderObject& o, const PaintInfo& pa
     // 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;
 }