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
This commit is contained in:
Markus Stange 2021-04-06 18:40:43 +00:00
Родитель 2bcf26f3c0
Коммит 8cfecc3315
2 изменённых файлов: 13 добавлений и 22 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
}