Commit 43d64fe0 authored by Lambros Lambrou's avatar Lambros Lambrou Committed by Commit Bot

[remoting] Don't resize buttons in permission wizard.

The permission wizard had a multi-purpose "Next" button whose text and
behavior were adjusted, depending on the wizard state. Resizing the
button sometimes caused rendering glitches in the bezel outline.

This CL simplifies things by creating separate buttons (and event
handlers) for each purpose, and it shows/hides them instead of
replacing the title strings.

This CL also enables/disables the "Next" button (according to
permission grant state), so that the buttons don't jump around as much.
The "Open .. preferences" button and "Next" buttons remain visible, but
the user can still only advance when permission is granted.

Bug: 1015201
Change-Id: I255fcc8bc3f8c18acfef0dc830964c40dd081e98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1949673
Commit-Queue: Lambros Lambrou <lambroslambrou@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Auto-Submit: Lambros Lambrou <lambroslambrou@chromium.org>
Reviewed-by: default avatarYuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721278}
parent fe4d0571
...@@ -154,7 +154,10 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) { ...@@ -154,7 +154,10 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) {
@implementation PermissionWizardController { @implementation PermissionWizardController {
NSTextField* _instructionText; NSTextField* _instructionText;
NSButton* _cancelButton; NSButton* _cancelButton;
NSButton* _launchA11yButton;
NSButton* _launchScreenRecordingButton;
NSButton* _nextButton; NSButton* _nextButton;
NSButton* _okButton;
// The page of the wizard being shown. // The page of the wizard being shown.
WizardPage _page; WizardPage _page;
...@@ -227,13 +230,41 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) { ...@@ -227,13 +230,41 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) {
_cancelButton.action = @selector(onCancel:); _cancelButton.action = @selector(onCancel:);
_cancelButton.target = self; _cancelButton.target = self;
_launchA11yButton = [[[NSButton alloc] init] autorelease];
_launchA11yButton.translatesAutoresizingMaskIntoConstraints = NO;
_launchA11yButton.buttonType = NSButtonTypeMomentaryPushIn;
_launchA11yButton.bezelStyle = NSBezelStyleRegularSquare;
_launchA11yButton.title =
l10n_util::GetNSString(IDS_ACCESSIBILITY_PERMISSION_DIALOG_OPEN_BUTTON);
_launchA11yButton.action = @selector(onLaunchA11y:);
_launchA11yButton.target = self;
_launchScreenRecordingButton = [[[NSButton alloc] init] autorelease];
_launchScreenRecordingButton.translatesAutoresizingMaskIntoConstraints = NO;
_launchScreenRecordingButton.buttonType = NSButtonTypeMomentaryPushIn;
_launchScreenRecordingButton.bezelStyle = NSBezelStyleRegularSquare;
_launchScreenRecordingButton.title = l10n_util::GetNSString(
IDS_SCREEN_RECORDING_PERMISSION_DIALOG_OPEN_BUTTON);
_launchScreenRecordingButton.action = @selector(onLaunchScreenRecording:);
_launchScreenRecordingButton.target = self;
_nextButton = [[[NSButton alloc] init] autorelease]; _nextButton = [[[NSButton alloc] init] autorelease];
_nextButton.translatesAutoresizingMaskIntoConstraints = NO; _nextButton.translatesAutoresizingMaskIntoConstraints = NO;
_nextButton.buttonType = NSButtonTypeMomentaryPushIn; _nextButton.buttonType = NSButtonTypeMomentaryPushIn;
_nextButton.bezelStyle = NSBezelStyleRegularSquare; _nextButton.bezelStyle = NSBezelStyleRegularSquare;
_nextButton.title =
l10n_util::GetNSString(IDS_MAC_PERMISSION_WIZARD_NEXT_BUTTON);
_nextButton.action = @selector(onNext:); _nextButton.action = @selector(onNext:);
_nextButton.target = self; _nextButton.target = self;
_okButton = [[[NSButton alloc] init] autorelease];
_okButton.translatesAutoresizingMaskIntoConstraints = NO;
_okButton.buttonType = NSButtonTypeMomentaryPushIn;
_okButton.bezelStyle = NSBezelStyleRegularSquare;
_okButton.title = l10n_util::GetNSString(IDS_MAC_PERMISSION_WIZARD_OK_BUTTON);
_okButton.action = @selector(onOk:);
_okButton.target = self;
NSStackView* iconAndTextStack = [[[NSStackView alloc] init] autorelease]; NSStackView* iconAndTextStack = [[[NSStackView alloc] init] autorelease];
iconAndTextStack.translatesAutoresizingMaskIntoConstraints = NO; iconAndTextStack.translatesAutoresizingMaskIntoConstraints = NO;
iconAndTextStack.orientation = NSUserInterfaceLayoutOrientationHorizontal; iconAndTextStack.orientation = NSUserInterfaceLayoutOrientationHorizontal;
...@@ -246,7 +277,11 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) { ...@@ -246,7 +277,11 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) {
buttonsStack.translatesAutoresizingMaskIntoConstraints = NO; buttonsStack.translatesAutoresizingMaskIntoConstraints = NO;
buttonsStack.orientation = NSUserInterfaceLayoutOrientationHorizontal; buttonsStack.orientation = NSUserInterfaceLayoutOrientationHorizontal;
[buttonsStack addView:_cancelButton inGravity:NSStackViewGravityTrailing]; [buttonsStack addView:_cancelButton inGravity:NSStackViewGravityTrailing];
[buttonsStack addView:_launchA11yButton inGravity:NSStackViewGravityTrailing];
[buttonsStack addView:_launchScreenRecordingButton
inGravity:NSStackViewGravityTrailing];
[buttonsStack addView:_nextButton inGravity:NSStackViewGravityTrailing]; [buttonsStack addView:_nextButton inGravity:NSStackViewGravityTrailing];
[buttonsStack addView:_okButton inGravity:NSStackViewGravityTrailing];
NSStackView* mainStack = [[[NSStackView alloc] init] autorelease]; NSStackView* mainStack = [[[NSStackView alloc] init] autorelease];
mainStack.translatesAutoresizingMaskIntoConstraints = NO; mainStack.translatesAutoresizingMaskIntoConstraints = NO;
...@@ -255,6 +290,10 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) { ...@@ -255,6 +290,10 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) {
[mainStack addView:iconAndTextStack inGravity:NSStackViewGravityTop]; [mainStack addView:iconAndTextStack inGravity:NSStackViewGravityTop];
[mainStack addView:buttonsStack inGravity:NSStackViewGravityBottom]; [mainStack addView:buttonsStack inGravity:NSStackViewGravityBottom];
// Update button visibility, instructional text etc before window is
// presented, to ensure correct layout.
[self updateUI];
[self.window.contentView addSubview:mainStack]; [self.window.contentView addSubview:mainStack];
NSDictionary* views = @{ NSDictionary* views = @{
...@@ -298,18 +337,29 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) { ...@@ -298,18 +337,29 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) {
[self hide]; [self hide];
} }
- (void)onLaunchA11y:(id)sender {
// Launch the Security and Preferences pane with Accessibility selected.
[[NSWorkspace sharedWorkspace]
openURL:[NSURL
URLWithString:@"x-apple.systempreferences:com.apple."
@"preference.security?Privacy_Accessibility"]];
}
- (void)onLaunchScreenRecording:(id)sender {
[[NSWorkspace sharedWorkspace]
openURL:[NSURL
URLWithString:@"x-apple.systempreferences:com.apple."
@"preference.security?Privacy_ScreenCapture"]];
}
- (void)onNext:(id)sender { - (void)onNext:(id)sender {
if (_page == WizardPage::ALL_SET) { [self advanceToNextPage];
// OK button closes the window. }
_impl->NotifyCompletion(true);
[self hide]; - (void)onOk:(id)sender {
return; // OK button closes the window.
} _impl->NotifyCompletion(true);
if (_hasPermission) { [self hide];
[self advanceToNextPage];
} else {
[self launchSystemPreferences];
}
} }
// Updates the dialog controls according to the object's state. // Updates the dialog controls according to the object's state.
...@@ -340,36 +390,21 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) { ...@@ -340,36 +390,21 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) {
NOTREACHED(); NOTREACHED();
} }
_cancelButton.hidden = (_page == WizardPage::ALL_SET); _cancelButton.hidden = (_page == WizardPage::ALL_SET);
[self updateNextButton]; [self updateButtons];
} }
// Updates |_nextButton| according to the object's state. // Updates the buttons according to the object's state.
- (void)updateNextButton { - (void)updateButtons {
if (_page == WizardPage::ALL_SET) { // Launch buttons are always visible on their associated pages.
_nextButton.title = _launchA11yButton.hidden = (_page != WizardPage::ACCESSIBILITY);
l10n_util::GetNSString(IDS_MAC_PERMISSION_WIZARD_OK_BUTTON); _launchScreenRecordingButton.hidden = (_page != WizardPage::SCREEN_RECORDING);
return;
}
if (_hasPermission) { // OK/Next visibility are mutually exclusive.
_nextButton.title = _nextButton.hidden = (_page == WizardPage::ALL_SET);
l10n_util::GetNSString(IDS_MAC_PERMISSION_WIZARD_NEXT_BUTTON); _okButton.hidden = (_page != WizardPage::ALL_SET);
return;
}
// Permission is not granted, so show the appropriate launch text. // User can only advance if permission is granted.
switch (_page) { _nextButton.enabled = _hasPermission;
case WizardPage::ACCESSIBILITY:
_nextButton.title = l10n_util::GetNSString(
IDS_ACCESSIBILITY_PERMISSION_DIALOG_OPEN_BUTTON);
break;
case WizardPage::SCREEN_RECORDING:
_nextButton.title = l10n_util::GetNSString(
IDS_SCREEN_RECORDING_PERMISSION_DIALOG_OPEN_BUTTON);
break;
default:
NOTREACHED();
}
} }
- (void)advanceToNextPage { - (void)advanceToNextPage {
...@@ -392,10 +427,11 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) { ...@@ -392,10 +427,11 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) {
NOTREACHED(); NOTREACHED();
} }
// Kick off a permission check for the new page. The UI will be updated only // Kick off a permission check for the new page. Update the UI now, so the
// after the result comes back. // Next button is disabled and can't be accidentally double-pressed.
_hasPermission = NO; _hasPermission = NO;
_autoAdvance = YES; _autoAdvance = YES;
[self updateUI];
[self requestPermissionCheck:base::TimeDelta()]; [self requestPermissionCheck:base::TimeDelta()];
} }
...@@ -413,28 +449,6 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) { ...@@ -413,28 +449,6 @@ void PermissionWizard::Impl::OnPermissionCheckResult(bool result) {
} }
} }
- (void)launchSystemPreferences {
switch (_page) {
case WizardPage::ACCESSIBILITY:
// Launch the Security and Preferences pane with Accessibility selected.
[[NSWorkspace sharedWorkspace]
openURL:[NSURL URLWithString:
@"x-apple.systempreferences:com.apple."
@"preference.security?Privacy_Accessibility"]];
break;
case WizardPage::SCREEN_RECORDING:
// Launch the Security and Preferences pane with Screen Recording
// selected.
[[NSWorkspace sharedWorkspace]
openURL:[NSURL URLWithString:
@"x-apple.systempreferences:com.apple."
@"preference.security?Privacy_ScreenCapture"]];
return;
default:
NOTREACHED();
}
}
- (void)onPermissionCheckResult:(bool)result { - (void)onPermissionCheckResult:(bool)result {
if (_cancelled) if (_cancelled)
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment