Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5345209

Browse files
committed
addressing comments
1 parent d50c486 commit 5345209

15 files changed

Lines changed: 73 additions & 81 deletions

shell/platform/common/accessibility_bridge.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,16 @@ AccessibilityBridge::GetPendingEvents() {
114114
void AccessibilityBridge::UpdateDelegate(
115115
std::unique_ptr<AccessibilityBridgeDelegate> delegate) {
116116
delegate_ = std::move(delegate);
117-
// FlutterPlatformNodeDelegate[s] are created by the
118-
// AccessibilityBridgeDelegate and may contain states from previous
119-
// AccessibilityBridgeDelegate. Need to recreate them.
120-
for (const auto& pair : id_wrapper_map_) {
117+
// Recreate FlutterPlatformNodeDelegates since they may contain stale state
118+
// from the previous AccessibilityBridgeDelegate.
119+
for (const auto& [node_id, old_platform_node_delegate] : id_wrapper_map_) {
121120
std::shared_ptr<FlutterPlatformNodeDelegate> platform_node_delegate =
122121
delegate_->CreateFlutterPlatformNodeDelegate();
123122
platform_node_delegate->Init(
124123
std::static_pointer_cast<FlutterPlatformNodeDelegate::OwnerBridge>(
125124
shared_from_this()),
126-
pair.second->GetAXNode());
127-
id_wrapper_map_[pair.first] = platform_node_delegate;
125+
old_platform_node_delegate->GetAXNode());
126+
id_wrapper_map_[node_id] = platform_node_delegate;
128127
}
129128
}
130129

shell/platform/common/accessibility_bridge_unittests.cc

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,9 @@ TEST(AccessibilityBridgeTest, canFireChildrenChangedCorrectly) {
156156
}
157157

158158
TEST(AccessibilityBridgeTest, canUpdateDelegate) {
159-
TestAccessibilityBridgeDelegate* delegate =
160-
new TestAccessibilityBridgeDelegate();
161-
std::unique_ptr<TestAccessibilityBridgeDelegate> ptr(delegate);
162159
std::shared_ptr<AccessibilityBridge> bridge =
163-
std::make_shared<AccessibilityBridge>(std::move(ptr));
160+
std::make_shared<AccessibilityBridge>(
161+
std::make_unique<TestAccessibilityBridgeDelegate>());
164162
FlutterSemanticsNode root;
165163
root.id = 0;
166164
root.flags = static_cast<FlutterSemanticsFlag>(0);
@@ -200,10 +198,7 @@ TEST(AccessibilityBridgeTest, canUpdateDelegate) {
200198
EXPECT_FALSE(root_node.expired());
201199
EXPECT_FALSE(child1_node.expired());
202200
// Update Delegate
203-
TestAccessibilityBridgeDelegate* new_delegate =
204-
new TestAccessibilityBridgeDelegate();
205-
std::unique_ptr<TestAccessibilityBridgeDelegate> new_ptr(new_delegate);
206-
bridge->UpdateDelegate(std::move(new_ptr));
201+
bridge->UpdateDelegate(std::make_unique<TestAccessibilityBridgeDelegate>());
207202

208203
// Old tree is destroyed.
209204
EXPECT_TRUE(root_node.expired());
@@ -266,11 +261,9 @@ TEST(AccessibilityBridgeTest, canHandleSelectionChangeCorrectly) {
266261
}
267262

268263
TEST(AccessibilityBridgeTest, doesNotAssignEditableRootToSelectableText) {
269-
TestAccessibilityBridgeDelegate* delegate =
270-
new TestAccessibilityBridgeDelegate();
271-
std::unique_ptr<TestAccessibilityBridgeDelegate> ptr(delegate);
272264
std::shared_ptr<AccessibilityBridge> bridge =
273-
std::make_shared<AccessibilityBridge>(std::move(ptr));
265+
std::make_shared<AccessibilityBridge>(
266+
std::make_unique<TestAccessibilityBridgeDelegate>());
274267
FlutterSemanticsNode root;
275268
root.id = 0;
276269
root.flags = static_cast<FlutterSemanticsFlag>(
@@ -292,9 +285,8 @@ TEST(AccessibilityBridgeTest, doesNotAssignEditableRootToSelectableText) {
292285

293286
auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
294287

295-
EXPECT_EQ(root_node->GetData().GetBoolAttribute(
296-
ax::mojom::BoolAttribute::kEditableRoot),
297-
false);
288+
EXPECT_FALSE(root_node->GetData().GetBoolAttribute(
289+
ax::mojom::BoolAttribute::kEditableRoot));
298290
}
299291

300292
} // namespace testing

shell/platform/common/flutter_platform_node_delegate.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ class FlutterPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase {
135135

136136
//------------------------------------------------------------------------------
137137
/// @brief Gets the owner of this platform node delegate. This is useful
138-
/// when you want to get the information surround this platform
139-
/// node delegate, e.g. the global rect of this platform node
140-
/// delegate. This pointer is only safe in the platform thread.
138+
/// when you want to get the information about surrounding nodes
139+
/// of this platform node delegate, e.g. the global rect of this
140+
/// platform node delegate. This pointer is only safe in the
141+
/// platform thread.
141142
std::weak_ptr<OwnerBridge> GetOwnerBridge() const;
142143

143144
private:

shell/platform/darwin/macos/framework/Source/AccessibilityBridgeMacDelegate.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
.user_info = nil,
7878
});
7979
}
80-
// In all other cases this delegate should post
80+
// In all other cases, this delegate should post
8181
// |NSAccessibilityFocusedUIElementChangedNotification|, but this is
8282
// handled elsewhere.
8383
break;

shell/platform/darwin/macos/framework/Source/FlutterCompositor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FlutterCompositor {
2626
// data with the new BackingStore data.
2727
// If the backing store is being requested for the first time
2828
// for a given frame, this compositor does not create a new backing
29-
// store but rather return the backing store associated with the
29+
// store but rather returns the backing store associated with the
3030
// FlutterView's FlutterSurfaceManager.
3131
//
3232
// Any additional state allocated for the backing store and

shell/platform/darwin/macos/framework/Source/FlutterGLCompositor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class FlutterGLCompositor : public FlutterCompositor {
2828
// data with the new BackingStore data.
2929
// If the backing store is being requested for the first time
3030
// for a given frame, this compositor does not create a new backing
31-
// store but rather return the backing store associated with the
31+
// store but rather returns the backing store associated with the
3232
// FlutterView's FlutterSurfaceManager.
3333
//
3434
// Any additional state allocated for the backing store and

shell/platform/darwin/macos/framework/Source/FlutterMetalCompositor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class FlutterMetalCompositor : public FlutterCompositor {
2222
//
2323
// If the backing store is being requested for the first time
2424
// for a given frame, this compositor does not create a new backing
25-
// store but rather return the backing store associated with the
25+
// store but rather returns the backing store associated with the
2626
// FlutterView's FlutterSurfaceManager.
2727
//
2828
// Any additional state allocated for the backing store and

shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
* This is not an FlutterPlugin since it needs access to FlutterViewController internals, so needs
2020
* to be managed differently.
2121
*
22-
* When accessibility is on, accessibility bridge creates a native text field, i.e.
23-
* FlutterTextField, for every text field in the Flutter. This plugin acts as a field editor for
24-
* those native text fields.
22+
* When accessibility is on, accessibility bridge creates a NSTextField, i.e. FlutterTextField,
23+
* for every text field in the Flutter. This plugin acts as a field editor for those NSTextField[s].
2524
*/
2625
@interface FlutterTextInputPlugin : NSTextView <FlutterKeySecondaryResponder>
2726

2827
/**
29-
* The native text field that currently has this plugin as its field editor.
28+
* The NSTextField that currently has this plugin as its field editor.
3029
*
3130
* Must be nil if accessibility is off.
3231
*/

shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,7 @@ - (void)insertText:(id)string replacementRange:(NSRange)range {
466466
if (range.location != NSNotFound) {
467467
// The selected range can actually have negative numbers, since it can start
468468
// at the end of the range if the user selected the text going backwards.
469-
// NSRange uses NSUIntegers, however, so they have to be casted to know if the
470-
// selection is reversed or not.
469+
// Cast to a signed type to determine whether or not the selection is reversed.
471470
long signedLength = static_cast<long>(range.length);
472471
long location = range.location;
473472
long textLength = _activeModel->text_range().end();

shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ - (bool)testFirstRectForCharacterRange {
181181
namespace flutter::testing {
182182

183183
namespace {
184-
// Returns an engine configured for the text fixture resource configuration.
184+
// Allocates and returns an engine configured for the text fixture resource configuration.
185185
FlutterEngine* CreateTestEngine() {
186186
NSString* fixtures = @(testing::GetFixturesPath());
187187
FlutterDartProject* project = [[FlutterDartProject alloc]
@@ -208,7 +208,7 @@ - (bool)testFirstRectForCharacterRange {
208208
FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:project];
209209
[viewController loadView];
210210
[engine setViewController:viewController];
211-
// Creates a NSWindow so that the native text field can become first responder.
211+
// Create a NSWindow so that the native text field can become first responder.
212212
NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
213213
styleMask:NSBorderlessWindowMask
214214
backing:NSBackingStoreBuffered
@@ -233,7 +233,6 @@ - (bool)testFirstRectForCharacterRange {
233233
[viewController.view addSubview:mockTextField];
234234
[mockTextField becomeFirstResponder];
235235

236-
// Sets Client.
237236
NSDictionary* arguments = @{
238237
@"inputAction" : @"action",
239238
@"inputType" : @{@"name" : @"inputName"},
@@ -244,7 +243,6 @@ - (bool)testFirstRectForCharacterRange {
244243
};
245244
[viewController.textInputPlugin handleMethodCall:methodCall result:result];
246245

247-
// Sets editing state.
248246
arguments = @{
249247
@"text" : @"new text",
250248
@"selectionBase" : @(1),

0 commit comments

Comments
 (0)