2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-05-02 12:09:19 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-04-15 01:35:26 +00:00
|
|
|
#import "atom/browser/mac/atom_application.h"
|
2013-05-02 12:09:19 +00:00
|
|
|
|
2015-04-13 12:10:51 +00:00
|
|
|
#include "atom/browser/browser.h"
|
2013-05-02 12:09:19 +00:00
|
|
|
#include "base/auto_reset.h"
|
2013-07-10 08:10:38 +00:00
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2015-04-12 17:44:27 +00:00
|
|
|
#include "content/public/browser/browser_accessibility_state.h"
|
|
|
|
|
2013-05-02 12:09:19 +00:00
|
|
|
@implementation AtomApplication
|
|
|
|
|
2013-05-30 08:03:10 +00:00
|
|
|
+ (AtomApplication*)sharedApplication {
|
|
|
|
return (AtomApplication*)[super sharedApplication];
|
|
|
|
}
|
|
|
|
|
2013-05-02 12:09:19 +00:00
|
|
|
- (BOOL)isHandlingSendEvent {
|
|
|
|
return handlingSendEvent_;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sendEvent:(NSEvent*)event {
|
|
|
|
base::AutoReset<BOOL> scoper(&handlingSendEvent_, YES);
|
|
|
|
[super sendEvent:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
|
|
|
|
handlingSendEvent_ = handlingSendEvent;
|
|
|
|
}
|
|
|
|
|
2013-07-10 08:10:38 +00:00
|
|
|
- (void)awakeFromNib {
|
|
|
|
[[NSAppleEventManager sharedAppleEventManager]
|
|
|
|
setEventHandler:self
|
|
|
|
andSelector:@selector(handleURLEvent:withReplyEvent:)
|
|
|
|
forEventClass:kInternetEventClass
|
|
|
|
andEventID:kAEGetURL];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)handleURLEvent:(NSAppleEventDescriptor*)event
|
|
|
|
withReplyEvent:(NSAppleEventDescriptor*)replyEvent {
|
|
|
|
NSString* url = [
|
|
|
|
[event paramDescriptorForKeyword:keyDirectObject] stringValue];
|
|
|
|
atom::Browser::Get()->OpenURL(base::SysNSStringToUTF8(url));
|
|
|
|
}
|
|
|
|
|
2015-10-08 22:56:26 +00:00
|
|
|
- (bool)voiceOverEnabled {
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
[defaults addSuiteNamed:@"com.apple.universalaccess"];
|
|
|
|
[defaults synchronize];
|
|
|
|
|
|
|
|
return [defaults boolForKey:@"voiceOverOnOffKey"];
|
|
|
|
}
|
|
|
|
|
2015-04-12 17:44:27 +00:00
|
|
|
- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute {
|
2015-04-13 12:10:51 +00:00
|
|
|
// Undocumented attribute that VoiceOver happens to set while running.
|
2015-04-12 17:44:27 +00:00
|
|
|
// Chromium uses this too, even though it's not exactly right.
|
|
|
|
if ([attribute isEqualToString:@"AXEnhancedUserInterface"]) {
|
2015-10-08 22:56:26 +00:00
|
|
|
bool enableAccessibility = ([self voiceOverEnabled] && [value boolValue]);
|
|
|
|
[self updateAccessibilityEnabled:enableAccessibility];
|
2015-04-12 17:44:27 +00:00
|
|
|
}
|
|
|
|
return [super accessibilitySetValue:value forAttribute:attribute];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateAccessibilityEnabled:(BOOL)enabled {
|
2015-04-13 12:10:51 +00:00
|
|
|
auto ax_state = content::BrowserAccessibilityState::GetInstance();
|
2015-04-12 17:44:27 +00:00
|
|
|
|
|
|
|
if (enabled) {
|
|
|
|
ax_state->OnScreenReaderDetected();
|
|
|
|
} else {
|
|
|
|
ax_state->DisableAccessibility();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 12:09:19 +00:00
|
|
|
@end
|