Index: ui/views/cocoa/bridged_content_view.mm |
diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm |
index 88a5b84de02afe7f709d6c19cc343db02f248143..d3b0f4e69cbe041ffb693936675a3ec00997ade3 100644 |
--- a/ui/views/cocoa/bridged_content_view.mm |
+++ b/ui/views/cocoa/bridged_content_view.mm |
@@ -32,6 +32,9 @@ using views::MenuController; |
namespace { |
+NSString* const kFullKeyboardAccessChangedNotification = |
+ @"com.apple.KeyboardUIModeDidChange"; |
+ |
// Returns true if all four corners of |rect| are contained inside |path|. |
bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { |
return [path containsPoint:rect.origin] && |
@@ -185,6 +188,9 @@ gfx::Rect GetFirstRectForRangeHelper(const ui::TextInputClient* client, |
domCode:(ui::DomCode)domCode |
eventFlags:(int)eventFlags; |
+// Notification handler invoked when the Full Keyboard Access mode is changed. |
+- (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification; |
+ |
// Menu action handlers. |
- (void)undo:(id)sender; |
- (void)redo:(id)sender; |
@@ -221,6 +227,17 @@ gfx::Rect GetFirstRectForRangeHelper(const ui::TextInputClient* client, |
owner:self |
userInfo:nil]); |
[self addTrackingArea:cursorTrackingArea_.get()]; |
+ |
+ // Get notified whenever Full Keyboard Access mode is changed. |
+ [[NSDistributedNotificationCenter defaultCenter] |
+ addObserver:self |
+ selector:@selector(onFullKeyboardAccessModeChanged:) |
+ name:kFullKeyboardAccessChangedNotification |
+ object:nil]; |
+ |
+ // Initialize the focus manager with the correct keyboard accessibility |
+ // setting. |
+ [self updateFullKeyboardAccess]; |
} |
return self; |
} |
@@ -230,6 +247,7 @@ gfx::Rect GetFirstRectForRangeHelper(const ui::TextInputClient* client, |
hostedView_ = nullptr; |
[cursorTrackingArea_.get() clearOwner]; |
[self removeTrackingArea:cursorTrackingArea_.get()]; |
+ [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; |
} |
- (void)processCapturedMouseEvent:(NSEvent*)theEvent { |
@@ -293,6 +311,16 @@ gfx::Rect GetFirstRectForRangeHelper(const ui::TextInputClient* client, |
[windowMask_ transformUsingAffineTransform:flipTransform]; |
} |
+- (void)updateFullKeyboardAccess { |
+ if (!hostedView_) { |
tapted
2016/03/15 05:05:31
nit: no curlies
karandeepb
2016/03/17 07:24:46
Done.
|
+ return; |
+ } |
+ |
+ DCHECK(hostedView_->GetWidget()->GetFocusManager()); |
+ hostedView_->GetWidget()->GetFocusManager()->SetKeyboardAccessible( |
+ [NSApp isFullKeyboardAccessEnabled]); |
+} |
+ |
// BridgedContentView private implementation. |
- (void)handleKeyEvent:(NSEvent*)theEvent { |
@@ -328,6 +356,12 @@ gfx::Rect GetFirstRectForRangeHelper(const ui::TextInputClient* client, |
hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event); |
} |
+- (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification { |
+ DCHECK([[notification name] |
+ isEqualToString:kFullKeyboardAccessChangedNotification]); |
+ [self updateFullKeyboardAccess]; |
+} |
+ |
- (void)undo:(id)sender { |
// This DCHECK is more strict than a similar check in handleAction:. It can be |
// done here because the actors sending these actions should be calling |