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

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

Issue 1870573003: Full Keyboard Access: Second Approach (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « ui/views/cocoa/bridged_content_view.h ('k') | ui/views/cocoa/bridged_native_widget.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6d72fef5cf7ece1d35262f4b7b1a572622710f05..fffc05c1d9e4adf0242cecfc626c056fa587aba1 100644
--- a/ui/views/cocoa/bridged_content_view.mm
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -27,11 +27,15 @@
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
+#include "base/strings/utf_string_conversions.h"
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 +189,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 +228,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 +248,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 +312,15 @@ gfx::Rect GetFirstRectForRangeHelper(const ui::TextInputClient* client,
[windowMask_ transformUsingAffineTransform:flipTransform];
}
+- (void)updateFullKeyboardAccess {
+ if (!hostedView_)
+ 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
« no previous file with comments | « ui/views/cocoa/bridged_content_view.h ('k') | ui/views/cocoa/bridged_native_widget.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698