Bug 1421088 - Create DrawMultilineTextField. r?spohl draft
authorMarkus Stange <mstange@themasta.com>
Fri, 01 Dec 2017 18:35:45 -0500
changeset 782257 a66d59f0bde3ad87e797628568eab65353e66174
parent 782256 18b926b566e8a1d68ccb6191e8b03af7d098bfc9
child 782258 042e5629f7cac6c1658e8c43357aa139f7b2aca8
push id106506
push userbmo:mstange@themasta.com
push dateSun, 15 Apr 2018 03:32:46 +0000
reviewersspohl
bugs1421088
milestone61.0a1
Bug 1421088 - Create DrawMultilineTextField. r?spohl MozReview-Commit-ID: CyAhfGVmfzs
widget/cocoa/nsNativeThemeCocoa.h
widget/cocoa/nsNativeThemeCocoa.mm
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -381,16 +381,18 @@ protected:
                           const UnifiedToolbarParams& aParams);
   void DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRect,
                      bool aIsMain);
   void DrawResizer(CGContextRef cgContext, const HIRect& aRect, bool aIsRTL);
   void DrawScrollbarThumb(CGContextRef cgContext, const CGRect& inBoxRect,
                           ScrollbarParams aParams);
   void DrawScrollbarTrack(CGContextRef cgContext, const CGRect& inBoxRect,
                           ScrollbarParams aParams);
+  void DrawMultilineTextField(CGContextRef cgContext, const CGRect& inBoxRect,
+                              bool aIsFocused);
 
   // Scrollbars
   nsIFrame* GetParentScrollbarFrame(nsIFrame *aFrame);
   bool IsParentScrollbarRolledOver(nsIFrame* aFrame);
 
 private:
   NSButtonCell* mDisclosureButtonCell;
   NSButtonCell* mHelpButtonCell;
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -2718,16 +2718,51 @@ nsNativeThemeCocoa::DrawScrollbarTrack(C
             (aParams.onDarkBackground ? @"kCUIVariantWhite" : @""), @"kCUIVariantKey",
             [NSNumber numberWithBool:YES], @"noindicator",
             [NSNumber numberWithBool:YES], @"kCUIThumbProportionKey",
             [NSNumber numberWithBool:YES], @"is.flipped",
             nil],
           true);
 }
 
+static const Color kTooltipBackgroundColor(0.996, 1.000, 0.792, 0.950);
+static const Color kMultilineTextFieldTopBorderColor(0.4510, 0.4510, 0.4510, 1.0);
+static const Color kMultilineTextFieldSidesAndBottomBorderColor(0.6, 0.6, 0.6, 1.0);
+static const Color kListboxTopBorderColor(0.557, 0.557, 0.557, 1.0);
+static const Color kListBoxSidesAndBottomBorderColor(0.745, 0.745, 0.745, 1.0);
+
+void
+nsNativeThemeCocoa::DrawMultilineTextField(CGContextRef cgContext,
+                                           const CGRect& inBoxRect,
+                                           bool aIsFocused)
+{
+  CGContextSetRGBFillColor(cgContext, 1.0, 1.0, 1.0, 1.0);
+
+  CGContextFillRect(cgContext, inBoxRect);
+
+  float x = inBoxRect.origin.x, y = inBoxRect.origin.y;
+  float w = inBoxRect.size.width, h = inBoxRect.size.height;
+  SetCGContextFillColor(cgContext, kMultilineTextFieldTopBorderColor);
+  CGContextFillRect(cgContext, CGRectMake(x, y, w, 1));
+  SetCGContextFillColor(cgContext, kMultilineTextFieldSidesAndBottomBorderColor);
+  CGContextFillRect(cgContext, CGRectMake(x, y + 1, 1, h - 1));
+  CGContextFillRect(cgContext, CGRectMake(x + w - 1, y + 1, 1, h - 1));
+  CGContextFillRect(cgContext, CGRectMake(x + 1, y + h - 1, w - 2, 1));
+
+  if (aIsFocused) {
+    NSGraphicsContext* savedContext = [NSGraphicsContext currentContext];
+    [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:YES]];
+    CGContextSaveGState(cgContext);
+    NSSetFocusRingStyle(NSFocusRingOnly);
+    NSRectFill(NSRectFromCGRect(inBoxRect));
+    CGContextRestoreGState(cgContext);
+    [NSGraphicsContext setCurrentContext:savedContext];
+  }
+}
+
 static void
 DrawVibrancyBackground(CGContextRef cgContext, CGRect inBoxRect,
                        nsIFrame* aFrame, nsITheme::ThemeGeometryType aThemeGeometryType)
 {
   DrawVibrancyBackground(cgContext, inBoxRect,
                          VibrancyFillColor(aFrame, aThemeGeometryType), 0);
 }
 
@@ -2742,22 +2777,16 @@ nsNativeThemeCocoa::IsParentScrollbarRol
 
 static bool
 IsHiDPIContext(nsDeviceContext* aContext)
 {
   return nsPresContext::AppUnitsPerCSSPixel() >=
     2 * aContext->AppUnitsPerDevPixelAtUnitFullZoom();
 }
 
-static const Color kTooltipBackgroundColor(0.996, 1.000, 0.792, 0.950);
-static const Color kMultilineTextFieldTopBorderColor(0.4510, 0.4510, 0.4510, 1.0);
-static const Color kMultilineTextFieldSidesAndBottomBorderColor(0.6, 0.6, 0.6, 1.0);
-static const Color kListboxTopBorderColor(0.557, 0.557, 0.557, 1.0);
-static const Color kListBoxSidesAndBottomBorderColor(0.745, 0.745, 0.745, 1.0);
-
 NS_IMETHODIMP
 nsNativeThemeCocoa::DrawWidgetBackground(gfxContext* aContext,
                                          nsIFrame* aFrame,
                                          uint8_t aWidgetType,
                                          const nsRect& aRect,
                                          const nsRect& aDirtyRect)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
@@ -3261,42 +3290,19 @@ nsNativeThemeCocoa::DrawWidgetBackground
     break;
     case NS_THEME_SCROLLBARTRACK_HORIZONTAL:
     case NS_THEME_SCROLLBARTRACK_VERTICAL:
       DrawScrollbarTrack(cgContext, macRect,
         ComputeScrollbarParams(
           aFrame, aWidgetType == NS_THEME_SCROLLBARTRACK_HORIZONTAL));
       break;
 
-    case NS_THEME_TEXTFIELD_MULTILINE: {
-      // we have to draw this by hand because there is no HITheme value for it
-      CGContextSetRGBFillColor(cgContext, 1.0, 1.0, 1.0, 1.0);
-
-      CGContextFillRect(cgContext, macRect);
-
-      float x = macRect.origin.x, y = macRect.origin.y;
-      float w = macRect.size.width, h = macRect.size.height;
-      SetCGContextFillColor(cgContext, kMultilineTextFieldTopBorderColor);
-      CGContextFillRect(cgContext, CGRectMake(x, y, w, 1));
-      SetCGContextFillColor(cgContext, kMultilineTextFieldSidesAndBottomBorderColor);
-      CGContextFillRect(cgContext, CGRectMake(x, y + 1, 1, h - 1));
-      CGContextFillRect(cgContext, CGRectMake(x + w - 1, y + 1, 1, h - 1));
-      CGContextFillRect(cgContext, CGRectMake(x + 1, y + h - 1, w - 2, 1));
-
-      // draw a focus ring
-      if (eventState.HasState(NS_EVENT_STATE_FOCUS)) {
-        NSGraphicsContext* savedContext = [NSGraphicsContext currentContext];
-        [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:YES]];
-        CGContextSaveGState(cgContext);
-        NSSetFocusRingStyle(NSFocusRingOnly);
-        NSRectFill(NSRectFromCGRect(macRect));
-        CGContextRestoreGState(cgContext);
-        [NSGraphicsContext setCurrentContext:savedContext];
-      }
-    }
+    case NS_THEME_TEXTFIELD_MULTILINE:
+      DrawMultilineTextField(cgContext, macRect,
+                             eventState.HasState(NS_EVENT_STATE_FOCUS));
       break;
 
     case NS_THEME_LISTBOX: {
       // We have to draw this by hand because kHIThemeFrameListBox drawing
       // is buggy on 10.5, see bug 579259.
       CGContextSetRGBFillColor(cgContext, 1.0, 1.0, 1.0, 1.0);
       CGContextFillRect(cgContext, macRect);