Create DrawMultilineTextField. draft
authorMarkus Stange <mstange@themasta.com>
Fri, 17 Nov 2017 19:52:14 -0500
changeset 700303 579725b1f81a24181fa7aa8dcb30c8a660c5cddb
parent 700302 2a4e973f13a3ee33f152b2add4535ee4e0768a04
child 700304 1d1c88970ed2786cc619e40c1d11b0a49c5a7777
push id89787
push userbmo:mstange@themasta.com
push dateSun, 19 Nov 2017 21:49:28 +0000
milestone59.0a1
Create DrawMultilineTextField. MozReview-Commit-ID: 2ZzNRb5J3ca
widget/cocoa/nsNativeThemeCocoa.h
widget/cocoa/nsNativeThemeCocoa.mm
--- a/widget/cocoa/nsNativeThemeCocoa.h
+++ b/widget/cocoa/nsNativeThemeCocoa.h
@@ -285,16 +285,18 @@ protected:
                           float aUnifiedHeight, bool aIsMain);
   void DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRect,
                      bool aIsMain);
   void DrawResizer(CGContextRef cgContext, const HIRect& aRect, nsIFrame *aFrame);
   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
   void GetScrollbarPressStates(nsIFrame *aFrame,
                                mozilla::EventStates aButtonStates[]);
   nsIFrame* GetParentScrollbarFrame(nsIFrame *aFrame);
   bool IsParentScrollbarRolledOver(nsIFrame* aFrame);
 
 private:
--- a/widget/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/cocoa/nsNativeThemeCocoa.mm
@@ -2534,16 +2534,45 @@ SetCGContextFillColor(CGContextRef cgCon
 }
 
 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];
+  }
+}
+
 NS_IMETHODIMP
 nsNativeThemeCocoa::DrawWidgetBackground(gfxContext* aContext,
                                          nsIFrame* aFrame,
                                          uint8_t aWidgetType,
                                          const nsRect& aRect,
                                          const nsRect& aDirtyRect)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
@@ -3080,42 +3109,19 @@ nsNativeThemeCocoa::DrawWidgetBackground
 #endif
     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);