Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Unified Diff: ui/views/cocoa/bridged_content_view.mm

Issue 1894383002: MacViews: Implement Full Keyboard Access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SetFocusBehavior
Patch Set: Rebased Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 c6bfe7021e2a38fa3384d2111949faf47495c1b0..c269729cc2e73633e333f5df86dbb614518c3f0a 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;
}
@@ -228,6 +245,7 @@ gfx::Rect GetFirstRectForRangeHelper(const ui::TextInputClient* client,
- (void)clearView {
textInputClient_ = nullptr;
hostedView_ = nullptr;
+ [[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
[cursorTrackingArea_.get() clearOwner];
[self removeTrackingArea:cursorTrackingArea_.get()];
}
@@ -293,6 +311,16 @@ gfx::Rect GetFirstRectForRangeHelper(const ui::TextInputClient* client,
[windowMask_ transformUsingAffineTransform:flipTransform];
}
+- (void)updateFullKeyboardAccess {
+ if (!hostedView_)
+ return;
+
+ views::FocusManager* focusManager =
+ hostedView_->GetWidget()->GetFocusManager();
+ if (focusManager)
+ focusManager->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

Powered by Google App Engine
This is Rietveld 408576698