From 8cfecc3315f6c4d242c42b1bbb341ed98d07786a Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Tue, 6 Apr 2021 18:40:43 +0000 Subject: [PATCH] Bug 1700839 - Use the same NSSearchFieldCell object for both toolbar-style and non-toolbar-style searchfields. r=mac-reviewers,bradwerth. Differential Revision: https://phabricator.services.mozilla.com/D110971 --- widget/cocoa/nsNativeThemeCocoa.h | 4 ++-- widget/cocoa/nsNativeThemeCocoa.mm | 31 +++++++++++------------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/widget/cocoa/nsNativeThemeCocoa.h b/widget/cocoa/nsNativeThemeCocoa.h index 5b06dbc85d31..6a46a2d71a09 100644 --- a/widget/cocoa/nsNativeThemeCocoa.h +++ b/widget/cocoa/nsNativeThemeCocoa.h @@ -20,6 +20,7 @@ @class MOZCellDrawWindow; @class MOZCellDrawView; +@class MOZSearchFieldCell; @class NSProgressBarCell; class nsDeviceContext; struct SegmentedControlRenderSettings; @@ -434,8 +435,7 @@ class nsNativeThemeCocoa : private nsNativeTheme, public nsITheme { NSButtonCell* mRadioButtonCell; NSButtonCell* mCheckboxCell; NSTextFieldCell* mTextFieldCell; - NSSearchFieldCell* mSearchFieldCell; - NSSearchFieldCell* mToolbarSearchFieldCell; + MOZSearchFieldCell* mSearchFieldCell; NSPopUpButtonCell* mDropdownCell; NSComboBoxCell* mComboBoxCell; NSProgressBarCell* mProgressBarCell; diff --git a/widget/cocoa/nsNativeThemeCocoa.mm b/widget/cocoa/nsNativeThemeCocoa.mm index cf12c0f2bd4f..864dba333d2c 100644 --- a/widget/cocoa/nsNativeThemeCocoa.mm +++ b/widget/cocoa/nsNativeThemeCocoa.mm @@ -247,13 +247,14 @@ static void DrawCellIncludingFocusRing(NSCell* aCell, NSRect aWithFrame, NSView* @end -@interface MOZToolbarSearchFieldCell : NSSearchFieldCell +@interface MOZSearchFieldCell : NSSearchFieldCell +@property BOOL shouldUseToolbarStyle; @end -@implementation MOZToolbarSearchFieldCell +@implementation MOZSearchFieldCell - (BOOL)_isToolbarMode { - return YES; + return self.shouldUseToolbarStyle; } @end @@ -413,18 +414,12 @@ nsNativeThemeCocoa::nsNativeThemeCocoa() { [mTextFieldCell setEditable:YES]; [mTextFieldCell setFocusRingType:NSFocusRingTypeExterior]; - mSearchFieldCell = [[NSSearchFieldCell alloc] initTextCell:@""]; + mSearchFieldCell = [[MOZSearchFieldCell alloc] initTextCell:@""]; [mSearchFieldCell setBezelStyle:NSTextFieldRoundedBezel]; [mSearchFieldCell setBezeled:YES]; [mSearchFieldCell setEditable:YES]; [mSearchFieldCell setFocusRingType:NSFocusRingTypeExterior]; - mToolbarSearchFieldCell = [[MOZToolbarSearchFieldCell alloc] initTextCell:@""]; - [mToolbarSearchFieldCell setBezelStyle:NSTextFieldRoundedBezel]; - [mToolbarSearchFieldCell setBezeled:YES]; - [mToolbarSearchFieldCell setEditable:YES]; - [mToolbarSearchFieldCell setFocusRingType:NSFocusRingTypeExterior]; - mDropdownCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO]; mComboBoxCell = [[NSComboBoxCell alloc] initTextCell:@""]; @@ -471,7 +466,6 @@ nsNativeThemeCocoa::~nsNativeThemeCocoa() { [mCheckboxCell release]; [mTextFieldCell release]; [mSearchFieldCell release]; - [mToolbarSearchFieldCell release]; [mDropdownCell release]; [mComboBoxCell release]; [mCellDrawWindow release]; @@ -1007,19 +1001,16 @@ void nsNativeThemeCocoa::DrawSearchField(CGContextRef cgContext, const HIRect& i const TextFieldParams& aParams) { NS_OBJC_BEGIN_TRY_IGNORE_BLOCK; - NSSearchFieldCell* cell = aParams.insideToolbar ? mToolbarSearchFieldCell : mSearchFieldCell; - [cell setEnabled:!aParams.disabled]; - [cell setShowsFirstResponder:aParams.focused]; - - // When using the 10.11 SDK, the default string will be shown if we don't - // set the placeholder string. - [cell setPlaceholderString:@""]; + mSearchFieldCell.enabled = !aParams.disabled; + mSearchFieldCell.showsFirstResponder = aParams.focused; + mSearchFieldCell.placeholderString = @""; + mSearchFieldCell.shouldUseToolbarStyle = aParams.insideToolbar; if (mCellDrawWindow) { mCellDrawWindow.cellsShouldLookActive = YES; // TODO: propagate correct activeness state } - DrawCellWithSnapping(cell, cgContext, inBoxRect, searchFieldSettings, aParams.verticalAlignFactor, - mCellDrawView, aParams.rtl); + DrawCellWithSnapping(mSearchFieldCell, cgContext, inBoxRect, searchFieldSettings, + aParams.verticalAlignFactor, mCellDrawView, aParams.rtl); NS_OBJC_END_TRY_IGNORE_BLOCK; }