Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Unified Diff: Source/platform/mac/ThemeMac.mm

Issue 488353003: Specify clip rects when drawing Mac native widgets (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/platform/mac/ThemeMac.mm
diff --git a/Source/platform/mac/ThemeMac.mm b/Source/platform/mac/ThemeMac.mm
index e011e8e1b7e51840f3ab2e4616c67bef9e2269c6..8b74c3723d25dfc81e7719e8a554f7aeac4e4c95 100644
--- a/Source/platform/mac/ThemeMac.mm
+++ b/Source/platform/mac/ThemeMac.mm
@@ -91,13 +91,6 @@ NSRect focusRingClipRect;
namespace blink {
-enum {
- topMargin,
- rightMargin,
- bottomMargin,
- leftMargin
-};
-
Theme* platformTheme()
{
DEFINE_STATIC_LOCAL(ThemeMac, themeMac, ());
@@ -204,24 +197,43 @@ static ThemeDrawState convertControlStatesToThemeDrawState(ThemeButtonKind kind,
return kThemeStateActive;
}
-static IntRect inflateRect(const IntRect& zoomedRect, const IntSize& zoomedSize, const int* margins, float zoomFactor)
+// static
+IntRect ThemeMac::inflateRect(const IntRect& zoomedRect, const IntSize& zoomedSize, const int* margins, float zoomFactor)
{
// Only do the inflation if the available width/height are too small. Otherwise try to
// fit the glow/check space into the available box's width/height.
- int widthDelta = zoomedRect.width() - (zoomedSize.width() + margins[leftMargin] * zoomFactor + margins[rightMargin] * zoomFactor);
- int heightDelta = zoomedRect.height() - (zoomedSize.height() + margins[topMargin] * zoomFactor + margins[bottomMargin] * zoomFactor);
+ int widthDelta = zoomedRect.width() - (zoomedSize.width() + margins[LeftMargin] * zoomFactor + margins[RightMargin] * zoomFactor);
+ int heightDelta = zoomedRect.height() - (zoomedSize.height() + margins[TopMargin] * zoomFactor + margins[BottomMargin] * zoomFactor);
IntRect result(zoomedRect);
if (widthDelta < 0) {
- result.setX(result.x() - margins[leftMargin] * zoomFactor);
+ result.setX(result.x() - margins[LeftMargin] * zoomFactor);
result.setWidth(result.width() - widthDelta);
}
if (heightDelta < 0) {
- result.setY(result.y() - margins[topMargin] * zoomFactor);
+ result.setY(result.y() - margins[TopMargin] * zoomFactor);
result.setHeight(result.height() - heightDelta);
}
return result;
}
+// static
+IntRect ThemeMac::inflateRectForFocusRing(const IntRect& rect) {
+#if BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
+ // Just put a margin of 16 units around the rect. The UI elements that use this don't appropriately
+ // scale their focus rings appropriately (e.g, paint pickers), or switch to non-native widgets when
+ // scaled (e.g, check boxes and radio buttons).
+ const int margin = 16;
+ IntRect result;
+ result.setX(rect.x() - margin);
+ result.setY(rect.y() - margin);
+ result.setWidth(rect.width() + 2 * margin);
+ result.setHeight(rect.height() + 2 * margin);
+ return result;
+#else
+ return rect;
+#endif
+}
+
// Checkboxes
static const IntSize* checkboxSizes()
@@ -284,7 +296,7 @@ static void paintCheckbox(ControlStates states, GraphicsContext* context, const
IntSize zoomedSize = checkboxSizes()[controlSize];
zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
- IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, checkboxMargins(controlSize), zoomFactor);
+ IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, checkboxMargins(controlSize), zoomFactor);
if (zoomFactor != 1.0f) {
inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
@@ -294,7 +306,7 @@ static void paintCheckbox(ControlStates states, GraphicsContext* context, const
context->translate(-inflatedRect.x(), -inflatedRect.y());
}
- LocalCurrentGraphicsContext localContext(context);
+ LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFocusRing(inflatedRect));
NSView *view = ThemeMac::ensuredView(scrollView);
[checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view];
#if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
@@ -364,7 +376,7 @@ static void paintRadio(ControlStates states, GraphicsContext* context, const Int
IntSize zoomedSize = radioSizes()[controlSize];
zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
- IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, radioMargins(controlSize), zoomFactor);
+ IntRect inflatedRect = ThemeMac::inflateRect(zoomedRect, zoomedSize, radioMargins(controlSize), zoomFactor);
if (zoomFactor != 1.0f) {
inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
@@ -374,7 +386,7 @@ static void paintRadio(ControlStates states, GraphicsContext* context, const Int
context->translate(-inflatedRect.x(), -inflatedRect.y());
}
- LocalCurrentGraphicsContext localContext(context);
+ LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFocusRing(inflatedRect));
BEGIN_BLOCK_OBJC_EXCEPTIONS
NSView *view = ThemeMac::ensuredView(scrollView);
[radioCell drawWithFrame:NSRect(inflatedRect) inView:view];
@@ -456,7 +468,7 @@ static void paintButton(ControlPart part, ControlStates states, GraphicsContext*
}
// Now inflate it to account for the shadow.
- inflatedRect = inflateRect(inflatedRect, zoomedSize, buttonMargins(controlSize), zoomFactor);
+ inflatedRect = ThemeMac::inflateRect(inflatedRect, zoomedSize, buttonMargins(controlSize), zoomFactor);
if (zoomFactor != 1.0f) {
inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
@@ -467,7 +479,7 @@ static void paintButton(ControlPart part, ControlStates states, GraphicsContext*
}
}
- LocalCurrentGraphicsContext localContext(context);
+ LocalCurrentGraphicsContext localContext(context, ThemeMac::inflateRectForFocusRing(inflatedRect));
NSView *view = ThemeMac::ensuredView(scrollView);
[buttonCell drawWithFrame:NSRect(inflatedRect) inView:view];
@@ -536,7 +548,7 @@ static void paintStepper(ControlStates states, GraphicsContext* context, const I
backgroundBounds.origin.y = bounds.origin.y + (heightDiff / 2) + 1;
}
- LocalCurrentGraphicsContext localContext(context);
+ LocalCurrentGraphicsContext localContext(context, rect);
HIThemeDrawButton(&backgroundBounds, &drawInfo, localContext.cgContext(), kHIThemeOrientationNormal, 0);
}

Powered by Google App Engine
This is Rietveld 408576698