0

Switch in non-deprecated drop-in replacements

Lots of APIs changed names but are otherwise drop-in replacements.
Make these easy changes.

Bug: 1393401
Change-Id: I034fdbfd802e981cc74dd85738f5969a4384121a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4054485
Reviewed-by: Tom Burgin <bur@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Gary Kacmarcik <garykac@chromium.org>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Cr-Commit-Position: refs/heads/main@{#1078055}
This commit is contained in:
Avi Drissman
2022-12-01 14:57:36 +00:00
committed by Chromium LUCI CQ
parent 448d68bef5
commit b54a4f10da
19 changed files with 58 additions and 45 deletions

@ -550,7 +550,8 @@ void AppShimController::UpdateProfileMenu(
action:@selector(profileMenuItemSelected:)
keyEquivalent:@""] autorelease];
[item setTag:mojo_item->menu_index];
[item setState:mojo_item->active ? NSOnState : NSOffState];
[item setState:mojo_item->active ? NSControlStateValueOn
: NSControlStateValueOff];
[item setTarget:profile_menu_target_.get()];
gfx::Image icon(mojo_item->icon);
[item setImage:icon.AsNSImage()];

@ -1494,7 +1494,7 @@ class AppControllerNativeThemeObserver : public ui::NativeThemeObserver {
const PrefService* prefService = g_browser_process->local_state();
bool enabled = prefService->GetBoolean(prefs::kConfirmToQuitEnabled);
[item setState:enabled ? NSOnState : NSOffState];
[item setState:enabled ? NSControlStateValueOn : NSControlStateValueOff];
}
- (BOOL)shouldEnableConfirmToQuitPrefMenuItem {

@ -161,9 +161,10 @@ using content::RenderViewHost;
// is still necessary.
if (action == @selector(toggleContinuousSpellChecking:)) {
if ([(id)item respondsToSelector:@selector(setState:)]) {
NSCellStateValue checkedState =
pref->GetBoolean(spellcheck::prefs::kSpellCheckEnable) ? NSOnState
: NSOffState;
NSControlStateValue checkedState =
pref->GetBoolean(spellcheck::prefs::kSpellCheckEnable)
? NSControlStateValueOn
: NSControlStateValueOff;
[(id)item setState:checkedState];
}
*valid = spellCheckUserModifiable;

@ -25,13 +25,15 @@ void SetToggleState(bool toggled, id item) {
NSMenuItem* menuItem = base::mac::ObjCCast<NSMenuItem>(item);
NSButton* buttonItem = base::mac::ObjCCast<NSButton>(item);
if (menuItem) {
NSInteger old_state = [menuItem state];
NSInteger new_state = toggled ? NSOnState : NSOffState;
NSControlStateValue old_state = [menuItem state];
NSControlStateValue new_state =
toggled ? NSControlStateValueOn : NSControlStateValueOff;
if (old_state != new_state)
[menuItem setState:new_state];
} else if (buttonItem) {
NSInteger old_state = [buttonItem state];
NSInteger new_state = toggled ? NSOnState : NSOffState;
NSControlStateValue old_state = [buttonItem state];
NSControlStateValue new_state =
toggled ? NSControlStateValueOn : NSControlStateValueOff;
if (old_state != new_state)
[buttonItem setState:new_state];
}

@ -135,7 +135,7 @@ void CenterVertically(NSView* view) {
action:nil];
[_defaultBrowserCheckbox
setFrame:NSMakeRect(45, 107, kDialogWidth - 2 * 45, 18)];
[_defaultBrowserCheckbox setState:NSOnState];
[_defaultBrowserCheckbox setState:NSControlStateValueOn];
_statsCheckbox = [NSButton
checkboxWithTitle:NSStringWithProductName(
@ -144,7 +144,7 @@ void CenterVertically(NSView* view) {
action:nil];
[_statsCheckbox setFrame:NSMakeRect(45, 82, kDialogWidth - 2 * 45, 19)];
if (_statsCheckboxInitiallyChecked)
[_statsCheckbox setState:NSOnState];
[_statsCheckbox setState:NSControlStateValueOn];
NSButton* startChromeButton =
[NSButton buttonWithTitle:NSStringWithProductName(
@ -217,11 +217,11 @@ void CenterVertically(NSView* view) {
}
- (BOOL)isStatsReportingEnabled {
return [_statsCheckbox state] == NSOnState;
return [_statsCheckbox state] == NSControlStateValueOn;
}
- (BOOL)isMakeDefaultBrowserEnabled {
return [_defaultBrowserCheckbox state] == NSOnState;
return [_defaultBrowserCheckbox state] == NSControlStateValueOn;
}
- (void)ok:(id)sender {

@ -148,7 +148,8 @@ class Observer : public BrowserListObserver, public AvatarMenuObserver {
gfx::Image itemIcon =
profiles::GetAvatarIconForNSMenu(itemData.profile_path);
[item setImage:itemIcon.ToNSImage()];
[item setState:itemData.active ? NSOnState : NSOffState];
[item setState:itemData.active ? NSControlStateValueOn
: NSControlStateValueOff];
}
[menu insertItem:item atIndex:i + offset];
}
@ -229,7 +230,8 @@ class Observer : public BrowserListObserver, public AvatarMenuObserver {
for (size_t i = 0; i < _avatarMenu->GetNumberOfItems(); ++i) {
const AvatarMenu::Item& itemData = _avatarMenu->GetItemAt(i);
[[[self menu] itemWithTag:itemData.menu_index]
setState:itemData.active ? NSOnState : NSOffState];
setState:itemData.active ? NSControlStateValueOn
: NSControlStateValueOff];
}
}

@ -65,11 +65,13 @@ class ProfileMenuControllerTest : public BrowserWithTestWindowTest {
void VerifyProfileNamedIsActive(NSString* title, int line) {
for (NSMenuItem* item in [[controller() menu] itemArray]) {
if ([[item title] isEqualToString:title]) {
EXPECT_EQ(NSOnState, [item state]) << [[item title] UTF8String]
<< " (from line " << line << ")";
EXPECT_EQ(NSControlStateValueOn, [item state])
<< base::SysNSStringToUTF8(item.title) << " (from line " << line
<< ")";
} else {
EXPECT_EQ(NSOffState, [item state]) << [[item title] UTF8String]
<< " (from line " << line << ")";
EXPECT_EQ(NSControlStateValueOff, [item state])
<< base::SysNSStringToUTF8(item.title) << " (from line " << line
<< ")";
}
}
}

@ -193,13 +193,14 @@ bool CanShare() {
[service setDelegate:self];
[service setSubject:title];
NSArray* itemsToShare;
if ([[service name] isEqual:NSSharingServiceNamePostOnTwitter]) {
// The Twitter share service expects the title as an additional share item.
// This is the same approach system apps use.
itemsToShare = @[ url, title ];
NSArray* itemsToShare = @[ url ];
if (@available(macOS 10.14, *)) {
} else {
itemsToShare = @[ url ];
if ([[service name] isEqual:NSSharingServiceNamePostOnTwitter]) {
// The Twitter share service expects the title as an additional share
// item. This is the same approach system apps use.
itemsToShare = @[ url, title ];
}
}
if ([[service name] isEqual:kRemindersSharingServiceName]) {
_activity.reset([[NSUserActivity alloc]

@ -41,7 +41,7 @@ MessageBoxResult ShowMessageBoxCocoa(const std::u16string& message,
base::scoped_nsobject<NSButton> checkbox;
if (!checkbox_text.empty()) {
checkbox.reset([[NSButton alloc] initWithFrame:NSZeroRect]);
[checkbox setButtonType:NSSwitchButton];
[checkbox setButtonType:NSButtonTypeSwitch];
[checkbox setTitle:base::SysUTF16ToNSString(checkbox_text)];
[checkbox sizeToFit];
[alert setAccessoryView:checkbox];
@ -51,7 +51,7 @@ MessageBoxResult ShowMessageBoxCocoa(const std::u16string& message,
if (result == NSAlertSecondButtonReturn)
return MESSAGE_BOX_RESULT_NO;
if (!checkbox || ([checkbox state] == NSOnState))
if (!checkbox || ([checkbox state] == NSControlStateValueOn))
return MESSAGE_BOX_RESULT_YES;
return MESSAGE_BOX_RESULT_NO;

@ -127,7 +127,7 @@ void TabMenuBridge::AddDynamicItemsFromModel() {
if (recyclable_items.count) {
item.reset([[recyclable_items firstObject] retain]);
[recyclable_items removeObjectAtIndex:0];
[item setState:NSOffState];
[item setState:NSControlStateValueOff];
} else {
item.reset([[NSMenuItem alloc] initWithTitle:@""
action:@selector(activateTab:)
@ -136,7 +136,7 @@ void TabMenuBridge::AddDynamicItemsFromModel() {
}
if (model_->active_index() == i) {
[item setState:NSOnState];
[item setState:NSControlStateValueOn];
}
UpdateItemForWebContents(item, model_->GetWebContentsAt(i));

@ -149,7 +149,7 @@ class TabMenuBridgeTest : public ::testing::Test {
// Check the static items too, to make sure none of them are checked.
for (int i = 0; i < menu().numberOfItems; ++i) {
NSMenuItem* item = [menu() itemAtIndex:i];
if (item.state == NSOnState)
if (item.state == NSControlStateValueOn)
active_items.push_back(base::SysNSStringToUTF8(item.title));
}

@ -211,7 +211,7 @@ NSString* ColumnIdentifier(int id) {
[column setHidden:!visibility];
[_tableView sizeToFit];
[_tableView setNeedsDisplay];
[_tableView setNeedsDisplay:YES];
}
- (IBAction)killSelectedProcesses:(id)sender {
@ -393,7 +393,7 @@ NSString* ColumnIdentifier(int id) {
base::scoped_nsobject<NSButtonCell> nameCell(
[[NSButtonCell alloc] initTextCell:@""]);
[nameCell.get() setImagePosition:NSImageLeft];
[nameCell.get() setButtonType:NSSwitchButton];
[nameCell.get() setButtonType:NSButtonTypeSwitch];
[nameCell.get() setAlignment:[[column dataCell] alignment]];
[nameCell.get() setFont:[[column dataCell] font]];
[column setDataCell:nameCell.get()];
@ -420,7 +420,8 @@ NSString* ColumnIdentifier(int id) {
keyEquivalent:@""];
[item setTarget:self];
[item setRepresentedObject:column];
[item setState:[column isHidden] ? NSOffState : NSOnState];
[item setState:[column isHidden] ? NSControlStateValueOff
: NSControlStateValueOn];
}
}
@ -435,10 +436,12 @@ NSString* ColumnIdentifier(int id) {
int columnId = [[column identifier] intValue];
DCHECK(column);
NSInteger oldState = [item state];
NSInteger newState = oldState == NSOnState ? NSOffState : NSOnState;
NSInteger newState = oldState == NSControlStateValueOn
? NSControlStateValueOff
: NSControlStateValueOn;
// If hiding the column, make sure at least one column will remain visible.
if (newState == NSOffState) {
if (newState == NSControlStateValueOff) {
// Find the first column that will be visible after hiding |column|.
NSTableColumn* firstRemainingVisibleColumn = nil;
@ -566,7 +569,7 @@ NSString* ColumnIdentifier(int id) {
// NSButtonCells expect an on/off state as objectValue. Their title is set
// in |tableView:dataCellForTableColumn:row:| below.
if ([[tableColumn identifier] intValue] == IDS_TASK_MANAGER_TASK_COLUMN) {
return [NSNumber numberWithInt:NSOffState];
return [NSNumber numberWithInt:NSControlStateValueOff];
}
return [self modelTextForRow:rowIndex

@ -248,7 +248,7 @@ const int kMessageTextMaxSlots = 2000;
- (bool)shouldSuppress {
if ([[self alert] showsSuppressionButton])
return [[[self alert] suppressionButton] state] == NSOnState;
return [[[self alert] suppressionButton] state] == NSControlStateValueOn;
return false;
}

@ -113,7 +113,7 @@ void MakeShellButton(NSRect* rect,
base::scoped_nsobject<NSButton> button(
[[NSButton alloc] initWithFrame:*rect]);
[button setTitle:title];
[button setBezelStyle:NSSmallSquareBezelStyle];
[button setBezelStyle:NSBezelStyleSmallSquare];
[button setAutoresizingMask:(NSViewMaxXMargin | NSViewMinYMargin)];
[button setTarget:target];
[button setAction:@selector(performAction:)];

@ -78,7 +78,7 @@ base::scoped_nsobject<NSMenu> BuildMainMenu() {
NSButton* cancelButton = [[[NSButton alloc]
initWithFrame:NSMakeRect(308, 13, 82, 32)] autorelease];
cancelButton.buttonType = NSButtonTypeMomentaryPushIn;
cancelButton.bezelStyle = NSRoundedBezelStyle;
cancelButton.bezelStyle = NSBezelStyleRounded;
cancelButton.title = @"Cancel";
cancelButton.action = @selector(cancel:);
cancelButton.target = self;
@ -87,7 +87,7 @@ base::scoped_nsobject<NSMenu> BuildMainMenu() {
NSButton* uninstallButton = [[[NSButton alloc]
initWithFrame:NSMakeRect(390, 13, 95, 32)] autorelease];
uninstallButton.buttonType = NSButtonTypeMomentaryPushIn;
uninstallButton.bezelStyle = NSRoundedBezelStyle;
uninstallButton.bezelStyle = NSBezelStyleRounded;
uninstallButton.title = @"Uninstall";
uninstallButton.action = @selector(uninstall:);
uninstallButton.target = self;

@ -56,7 +56,7 @@ SkBitmap NSImageOrNSImageRepToSkBitmapWithColorSpace(
[NSGraphicsContext saveGraphicsState];
NSGraphicsContext* context_cocoa =
[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
[NSGraphicsContext graphicsContextWithCGContext:context flipped:NO];
[NSGraphicsContext setCurrentContext:context_cocoa];
NSRect drawRect = NSMakeRect(0, 0, size.width, size.height);

@ -292,7 +292,8 @@ bool MenuHasVisibleItems(const ui::MenuModel* model) {
const size_t modelIndex = base::checked_cast<size_t>([item tag]);
BOOL checked = model->IsItemCheckedAt(modelIndex);
DCHECK([(id)item isKindOfClass:[NSMenuItem class]]);
[(id)item setState:(checked ? NSOnState : NSOffState)];
[(id)item
setState:(checked ? NSControlStateValueOn : NSControlStateValueOff)];
[(id)item setHidden:(!model->IsVisibleAt(modelIndex))];
if (model->IsItemDynamicAt(modelIndex)) {
// Update the label and the icon.

@ -86,7 +86,7 @@ scoped_refptr<base::RefCountedMemory> Get1xPNGBytesFromNSImage(
}
base::scoped_nsobject<NSBitmapImageRep> ns_bitmap(
[[NSBitmapImageRep alloc] initWithCGImage:cg_image]);
NSData* ns_data = [ns_bitmap representationUsingType:NSPNGFileType
NSData* ns_data = [ns_bitmap representationUsingType:NSBitmapImageFileTypePNG
properties:@{}];
const unsigned char* bytes =
static_cast<const unsigned char*>([ns_data bytes]);

@ -26,8 +26,8 @@ bool JPEG1xEncodedDataFromImage(const Image& image,
float compressionFactor = quality / 100.0;
NSDictionary* options = @{ NSImageCompressionFactor : @(compressionFactor)};
NSData* data =
[rep representationUsingType:NSJPEGFileType properties:options];
NSData* data = [rep representationUsingType:NSBitmapImageFileTypeJPEG
properties:options];
if ([data length] == 0)
return false;