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

Commit 1448ba5

Browse files
committed
comments
1 parent e52699b commit 1448ba5

18 files changed

+195
-107
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class AccessibilityBridgeMacDelegate : public AccessibilityBridge::Accessibility
6464

6565
//---------------------------------------------------------------------------
6666
/// @brief Whether the given event is in current pending events.
67-
/// @param[in] event_type The event you would like to look up.
67+
/// @param[in] event_type The event to look up.
6868
bool HasPendingEvent(ui::AXEventGenerator::Event event) const;
6969

7070
//---------------------------------------------------------------------------

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
inline constexpr int32_t kRootNode = 0;
1616

1717
// Native mac notifications fired. These notifications are not publicly documented.
18-
// We have to define them ourselves.
1918
static NSString* const AccessibilityLoadCompleteNotification = @"AXLoadComplete";
2019
static NSString* const AccessibilityInvalidStatusChangedNotification = @"AXInvalidStatusChanged";
2120
static NSString* const AccessibilityLiveRegionCreatedNotification = @"AXLiveRegionCreated";
@@ -29,7 +28,7 @@
2928
void AccessibilityBridgeMacDelegate::OnAccessibilityEvent(
3029
ui::AXEventGenerator::TargetedEvent targeted_event) {
3130
if (!flutter_engine_.viewController.viewLoaded || !flutter_engine_.viewController.view.window) {
32-
// We don't need to send accessibility events if the there is no view or window.
31+
// Don't need to send accessibility events if the there is no view or window.
3332
return;
3433
}
3534
ui::AXNode* ax_node = targeted_event.node;
@@ -67,16 +66,16 @@
6766
.user_info = nil,
6867
});
6968
} else if (ax_node.data().role == ax::mojom::Role::kTextFieldWithComboBox) {
70-
// Even though the selected item in the combo box has changed, we don't
71-
// want to post a focus change because this will take the focus out of
69+
// Even though the selected item in the combo box has changed, don't
70+
// post a focus change because this will take the focus out of
7271
// the combo box where the user might be typing.
7372
events.push_back({
7473
.name = NSAccessibilitySelectedChildrenChangedNotification,
7574
.target = native_node,
7675
.user_info = nil,
7776
});
7877
}
79-
// In all other cases we should post
78+
// In all other cases this delegate should post
8079
// |NSAccessibilityFocusedUIElementChangedNotification|, but this is
8180
// handled elsewhere.
8281
break;
@@ -125,7 +124,7 @@
125124
id focused = mac_platform_node_delegate->GetFocus();
126125
if ([focused isKindOfClass:[FlutterTextField class]]) {
127126
// If it is a text field, the selection notifications are handled by
128-
// the FlutterTextField directly. We only need to make sure it is the
127+
// the FlutterTextField directly. Only need to make sure it is the
129128
// first responder.
130129
FlutterTextField* native_text_field = (FlutterTextField*)focused;
131130
if (native_text_field == mac_platform_node_delegate->GetFocus()) {
@@ -167,7 +166,7 @@
167166
case ui::AXEventGenerator::Event::VALUE_CHANGED: {
168167
if (ax_node.data().role == ax::mojom::Role::kTextField) {
169168
// If it is a text field, the value change notifications are handled by
170-
// the FlutterTextField directly. We only need to make sure it is the
169+
// the FlutterTextField directly. Only need to make sure it is the
171170
// first responder.
172171
FlutterTextField* native_text_field =
173172
(FlutterTextField*)mac_platform_node_delegate->GetNativeViewAccessible();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class FlutterCompositor {
2525
// Creates a BackingStore and saves updates the backing_store_out
2626
// data with the new BackingStore data.
2727
// If the backing store is being requested for the first time
28-
// for a given frame, we do not create a new backing store but
29-
// rather return the backing store associated with the
28+
// for a given frame, this compositor do not create a new backing
29+
// store but rather return 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/FlutterEmbedderKeyResponder.mm

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ static NSUInteger computeModifierFlagOfInterestMask() {
198198
// which is used for the "Apple logo" character (Option-Shift-K on a US
199199
// keyboard.)
200200
//
201-
// We hereby assume that non-printable function keys are defined from
201+
// Assume that non-printable function keys are defined from
202202
// 0xF700 upwards, and printable private keys are defined from 0xF8FF
203-
// downwards. We want to keep the printable private keys, therefore we only
204-
// filter out 0xF700-0xF7FF.
203+
// downwards. This function filter out 0xF700-0xF7FF in order to keep
204+
// the printable private keys.
205205
return nullptr;
206206
}
207207
return [characters UTF8String];
@@ -215,8 +215,8 @@ static NSUInteger computeModifierFlagOfInterestMask() {
215215
* The embedder functions only accept C-functions as callbacks, as well as an
216216
* arbitrary user_data. In order to send an instance method of
217217
* |FlutterEmbedderKeyResponder.handleResponse| to the engine's |SendKeyEvent|,
218-
* we wrap the invocation into a C-function |HandleResponse| and invocation
219-
* context |FlutterKeyPendingResponse|.
218+
* the embedder wrap the invocation into a C-function |HandleResponse| and
219+
* invocation context |FlutterKeyPendingResponse|.
220220
*
221221
* When this object is sent to the engine's |SendKeyEvent| as |user_data|, it
222222
* must be attached with |__bridge_retained|. When this object is parsed
@@ -544,7 +544,8 @@ - (void)sendCapsLockTapWithTimestamp:(NSTimeInterval)timestamp
544544
// MacOS sends a down *or* an up when CapsLock is tapped, alternatively on
545545
// even taps and odd taps. A CapsLock down or CapsLock up should always be
546546
// converted to a down *and* an up, and the up should always be a synthesized
547-
// event, since we will never know when the button is released.
547+
// event, since the FlutterEmbedderKeyResponder will never know when the
548+
// button is released.
548549
FlutterKeyEvent flutterEvent = {
549550
.struct_size = sizeof(FlutterKeyEvent),
550551
.timestamp = GetFlutterTimestampFrom(timestamp),

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,7 @@ - (void)setSemanticsEnabled:(BOOL)enabled {
454454
return;
455455
}
456456
_semanticsEnabled = enabled;
457-
// We need to remove the accessibility children from flutter view
458-
// before we reset the bridge.
457+
// Remove the accessibility children from flutter view before reseting the bridge.
459458
if (!_semanticsEnabled && self.viewController.viewLoaded) {
460459
self.viewController.flutterView.accessibilityChildren = nil;
461460
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class FlutterGLCompositor : public FlutterCompositor {
2727
// Creates a BackingStore and saves updates the backing_store_out
2828
// data with the new BackingStore data.
2929
// If the backing store is being requested for the first time
30-
// for a given frame, we do not create a new backing store but
31-
// rather return the backing store associated with the
30+
// for a given frame, this compositor do not create a new backing
31+
// store but rather return 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/FlutterKeyboardManager.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ - (void)addSecondaryResponder:(nonnull id<FlutterKeySecondaryResponder>)responde
4646
}
4747

4848
- (void)handleEvent:(nonnull NSEvent*)event {
49-
// Be sure to add a handling method in propagateKeyEvent if you allow more
49+
// Be sure to add a handling method in propagateKeyEvent when allowing more
5050
// event types here.
5151
if (event.type != NSEventTypeKeyDown && event.type != NSEventTypeKeyUp &&
5252
event.type != NSEventTypeFlagsChanged) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class FlutterMetalCompositor : public FlutterCompositor {
2121
// backing store.
2222
//
2323
// If the backing store is being requested for the first time
24-
// for a given frame, we do not create a new backing store but
25-
// rather return the backing store associated with the
24+
// for a given frame, this compositor do not create a new backing
25+
// store but rather return 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/FlutterPlatformNodeDelegateMac.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
NSMakeRect(local_bounds.x(), local_bounds.y(), local_bounds.width(), local_bounds.height());
100100
// The macOS XY coordinates start at bottom-left and increase toward top-right,
101101
// which is different from the Flutter's XY coordinates that start at top-left
102-
// increasing to bottom-right. Therefore, We need to flip the y coordinate when
103-
// we convert from flutter coordinates to macOS coordinates.
102+
// increasing to bottom-right. Therefore, this method need to flip the y coordinate when
103+
// it converts the bounds from flutter coordinates to macOS coordinates.
104104
ns_local_bounds.origin.y = -ns_local_bounds.origin.y - ns_local_bounds.size.height;
105105

106106
NSCAssert(engine_, @"Flutter engine should not be deallocated");
@@ -119,7 +119,7 @@
119119
gfx::RectF FlutterPlatformNodeDelegateMac::ConvertBoundsFromScreenToGlobal(
120120
const gfx::RectF& screen_bounds) const {
121121
// The VoiceOver seems to only accept bounds that are relative to primary screen.
122-
// Thus, we use [[NSScreen screens] firstObject] instead of [NSScreen mainScreen].
122+
// Thus, this method uses [[NSScreen screens] firstObject] instead of [NSScreen mainScreen].
123123
NSScreen* screen = [[NSScreen screens] firstObject];
124124
NSRect primary_screen_bounds = [screen frame];
125125
// The screen is flipped against y axis.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@
280280
double pixelRatio = view.bounds.size.width == 0 ? 1 : scaledSize.width / view.bounds.size.width;
281281

282282
double expectedFrameSize = rectSize * transformFactor / pixelRatio;
283-
EXPECT_EQ(NSEqualRects(native_text_field.frame, NSMakeRect(0, 600 - expectedFrameSize,
284-
expectedFrameSize, expectedFrameSize)),
285-
YES);
283+
EXPECT_EQ(
284+
NSEqualRects(native_text_field.frame, NSMakeRect(0, 0, expectedFrameSize, expectedFrameSize)),
285+
YES);
286286
// The text of TextInputPlugin only starts syncing editing state to the
287287
// native text field when it becomes the first responder.
288288
[native_text_field becomeFirstResponder];

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Flow during window resize
3131
*
3232
* 1. Platform thread calls [synchronizer beginResize:notify:]
33-
* This will hold the platform thread until we're ready to display contents.
33+
* This will hold the platform thread until the raster thread is ready to display contents.
3434
* 2. Raster thread calls [synchronizer shouldEnsureSurfaceForSize:] with target size
3535
* This will return false for any size other than target size
3636
* 3. Raster thread calls [synchronizer requestCommit]
@@ -45,8 +45,8 @@
4545
* This will invoke [delegate flush:] on raster thread and
4646
* [delegate commit:] on platform thread. The requestCommit call will be blocked
4747
* until this is done. This is necessary to ensure that rasterizer won't start
48-
* rasterizing next frame before we flipped the surface, which must be performed
49-
* on platform thread
48+
* rasterizing next frame before the FlutterSurfaceManager flipped the surface,
49+
* which must be performed on platform thread.
5050
*/
5151
@interface FlutterResizeSynchronizer : NSObject
5252

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ @interface FlutterResizeSynchronizer () {
1717
// Used to block [requestCommit].
1818
std::condition_variable _condBlockRequestCommit;
1919

20-
// Whether a frame was received; We don't block platform thread during resize
21-
// until we know that framework is running and producing frames
20+
// Whether a frame was received; the synchronizer don't block platform thread during resize
21+
// until it knows that framework is running and producing frames
2222
BOOL _receivedFirstFrame;
2323

2424
// If NO, requestCommit calls are ignored until shouldEnsureSurfaceForSize is called with

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@ - (instancetype)initWithViewController:(FlutterViewController*)viewController {
177177
binaryMessenger:viewController.engine.binaryMessenger
178178
codec:[FlutterJSONMethodCodec sharedInstance]];
179179
_shown = FALSE;
180-
// NSTextView does not support _weak reference, so we have to
181-
// use __unsafe_unretained and manage the reference ourselves.
180+
// NSTextView does not support _weak reference, so this class have to
181+
// use __unsafe_unretained and manage the reference by itself.
182182
//
183-
// Since we will nil the handler in dealloc. the weakSelf should
183+
// Since the dealloc removes the handler, the pointer should
184184
// be valid if the handler is ever called.
185-
__unsafe_unretained FlutterTextInputPlugin* weakSelf = self;
185+
__unsafe_unretained FlutterTextInputPlugin* unsafeSelf = self;
186186
[_channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
187-
[weakSelf handleMethodCall:call result:result];
187+
[unsafeSelf handleMethodCall:call result:result];
188188
}];
189189
_textInputContext = [[NSTextInputContext alloc] initWithClient:self];
190190
_previouslyPressedFlags = 0;
@@ -200,7 +200,7 @@ - (instancetype)initWithViewController:(FlutterViewController*)viewController {
200200
}
201201

202202
- (BOOL)isFirstResponder {
203-
if (!self.flutterViewController.viewLoaded || !self.flutterViewController.view.window) {
203+
if (!self.flutterViewController.viewLoaded) {
204204
return false;
205205
}
206206
return [self.flutterViewController.view.window firstResponder] == self;
@@ -356,7 +356,7 @@ - (void)updateTextAndSelection {
356356
int extend = _activeModel->selection().extent();
357357
NSRange selection = NSMakeRange(MIN(start, extend), ABS(start - extend));
358358
// There may be a native text field client if VoiceOver is on.
359-
// In this case, we have to update text and selection through
359+
// In this case, this plugin have to update text and selection through
360360
// the client in order for VoiceOver to announce the text editing
361361
// properly.
362362
if (_client) {
@@ -411,14 +411,6 @@ - (void)flagsChanged:(NSEvent*)event {
411411
[self.flutterViewController flagsChanged:event];
412412
}
413413

414-
- (void)mouseEntered:(NSEvent*)event {
415-
[self.flutterViewController mouseEntered:event];
416-
}
417-
418-
- (void)mouseExited:(NSEvent*)event {
419-
[self.flutterViewController mouseExited:event];
420-
}
421-
422414
- (void)mouseDown:(NSEvent*)event {
423415
[self.flutterViewController mouseDown:event];
424416
}
@@ -474,7 +466,7 @@ - (void)insertText:(id)string replacementRange:(NSRange)range {
474466
if (range.location != NSNotFound) {
475467
// The selected range can actually have negative numbers, since it can start
476468
// at the end of the range if the user selected the text going backwards.
477-
// NSRange uses NSUIntegers, however, so we have to cast them to know if the
469+
// NSRange uses NSUIntegers, however, so they have to be casted to know if the
478470
// selection is reversed or not.
479471
long signedLength = static_cast<long>(range.length);
480472
long location = range.location;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,8 @@ - (bool)testFirstRectForCharacterRange {
228228
FlutterTextPlatformNode textPlatformNode(&delegate, engine);
229229

230230
FlutterTextFieldMock* mockTextField =
231-
[[FlutterTextFieldMock alloc] initWithPlatformNode:&textPlatformNode
232-
withFieldEditor:viewController.textInputPlugin];
233-
231+
[[FlutterTextFieldMock alloc] initWithPlatformNode:&textPlatformNode];
232+
[mockTextField setFieldEditor:viewController.textInputPlugin];
234233
[viewController.view addSubview:mockTextField];
235234
[mockTextField becomeFirstResponder];
236235

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ class FlutterTextPlatformNode : public ui::AXPlatformNodeBase {
3131
~FlutterTextPlatformNode() override;
3232

3333
//------------------------------------------------------------------------------
34-
/// @brief Gets the bounds of this platform node relative to the NSWindow. This
35-
/// is used by the FlutterTextField to get its frame rect.
36-
NSRect GetWindowFrame();
34+
/// @brief Gets the frame of this platform node relative to the view of
35+
/// FlutterViewController. This is used by the FlutterTextField to get its
36+
/// frame rect because the FlutterTextField is a subview of the
37+
/// FlutterViewController.view.
38+
NSRect GetFrameRelativeToControllerView();
3739

3840
// |ui::AXPlatformNodeBase|
3941
gfx::NativeViewAccessible GetNativeViewAccessible() override;
@@ -73,9 +75,18 @@ class FlutterTextPlatformNode : public ui::AXPlatformNodeBase {
7375

7476
/**
7577
* Initializes a FlutterTextField.
78+
*
79+
* The plugin will be stored as an __unsafe_unretained pointer, and the FlutterTextField expects
80+
* the point is valid during its lifetime.
81+
*/
82+
- (instancetype)initWithPlatformNode:(flutter::FlutterTextPlatformNode*)node;
83+
84+
/**
85+
* Assign the field editor for this FlutterTextField. The plugin will be stored as an
86+
* __unsafe_unretained pointer, and the FlutterTextField expects the pointer is valid
87+
* during its lifetime.
7688
*/
77-
- (instancetype)initWithPlatformNode:(flutter::FlutterTextPlatformNode*)node
78-
withFieldEditor:(FlutterTextInputPlugin*)plugin;
89+
- (void)setFieldEditor:(FlutterTextInputPlugin*)plugin;
7990

8091
/**
8192
* Updates the string value and the selection of this text field.

0 commit comments

Comments
 (0)