Skip to content

Commit 421e57a

Browse files
dkwingsmtkjlubick
authored andcommitted
Rename default views to implicit views (flutter#43364)
This PR renames a number of internal variables from "default view ID" to "implicit view ID", as we have pretty much settled on naming this mechanism. Some docs are also fixed accordingly. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on writing and running engine tests. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I signed the [CLA]. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent 4ba96a2 commit 421e57a

10 files changed

+47
-45
lines changed

runtime/runtime_controller.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace flutter {
2222

23-
const uint64_t kFlutterDefaultViewId = 0llu;
23+
const uint64_t kFlutterImplicitViewId = 0llu;
2424

2525
RuntimeController::RuntimeController(RuntimeDelegate& p_client,
2626
const TaskRunners& task_runners)
@@ -320,7 +320,7 @@ void RuntimeController::ScheduleFrame() {
320320
// |PlatformConfigurationClient|
321321
void RuntimeController::Render(Scene* scene) {
322322
// TODO(dkwingsmt): Currently only supports a single window.
323-
int64_t view_id = kFlutterDefaultViewId;
323+
int64_t view_id = kFlutterImplicitViewId;
324324
auto window =
325325
UIDartState::Current()->platform_configuration()->get_window(view_id);
326326
if (window == nullptr) {

shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ FLUTTER_DARWIN_EXPORT
3636
@property(nonnull, readonly) id<FlutterTextureRegistry> textures;
3737

3838
/**
39-
* The default view displaying Flutter content.
39+
* The view displaying Flutter content.
4040
*
41-
* This method may return |nil|, for instance in a headless environment.
41+
* This property is provided for backwards compatibility for apps
42+
* that assume a single view. This will eventually be replaced by
43+
* a multi-view API variant.
4244
*
43-
* The default view is a special view operated by single-view APIs.
45+
* This method may return |nil|, for instance in a headless environment.
4446
*/
4547
@property(nullable, readonly) NSView* view;
4648

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// TODO(dkwingsmt): This class only supports single-view for now. As more
2323
// classes are gradually converted to multi-view, it should get the view ID
2424
// from somewhere.
25-
FlutterView* view = [view_provider_ viewForId:kFlutterDefaultViewId];
25+
FlutterView* view = [view_provider_ viewForId:kFlutterImplicitViewId];
2626
if (!view) {
2727
return false;
2828
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
#import "flutter/testing/testing.h"
1313

1414
@interface FlutterViewMockProvider : NSObject <FlutterViewProvider> {
15-
FlutterView* _defaultView;
15+
FlutterView* _implicitView;
1616
}
1717
/**
18-
* Create a FlutterViewMockProvider with the provided view as the default view.
18+
* Create a FlutterViewMockProvider with the provided view as the implicit view.
1919
*/
20-
- (nonnull instancetype)initWithDefaultView:(nonnull FlutterView*)view;
20+
- (nonnull instancetype)initWithImplicitView:(nonnull FlutterView*)view;
2121
@end
2222

2323
@implementation FlutterViewMockProvider
2424

25-
- (nonnull instancetype)initWithDefaultView:(nonnull FlutterView*)view {
25+
- (nonnull instancetype)initWithImplicitView:(nonnull FlutterView*)view {
2626
self = [super init];
2727
if (self != nil) {
28-
_defaultView = view;
28+
_implicitView = view;
2929
}
3030
return self;
3131
}
3232

3333
- (nullable FlutterView*)viewForId:(FlutterViewId)viewId {
34-
if (viewId == kFlutterDefaultViewId) {
35-
return _defaultView;
34+
if (viewId == kFlutterImplicitViewId) {
35+
return _implicitView;
3636
}
3737
return nil;
3838
}
@@ -81,7 +81,7 @@ - (nullable FlutterView*)viewForId:(FlutterViewId)viewId {
8181

8282
OCMStub([surfaceMock asFlutterMetalTexture]).andReturn(texture);
8383

84-
return [[FlutterViewMockProvider alloc] initWithDefaultView:viewMock];
84+
return [[FlutterViewMockProvider alloc] initWithImplicitView:viewMock];
8585
}
8686
} // namespace
8787

@@ -131,7 +131,7 @@ - (nullable FlutterView*)viewForId:(FlutterViewId)viewId {
131131
}};
132132
const FlutterLayer* layers_ptr = layers;
133133

134-
macos_compositor->Present(kFlutterDefaultViewId, &layers_ptr, 1);
134+
macos_compositor->Present(kFlutterImplicitViewId, &layers_ptr, 1);
135135

136136
ASSERT_EQ(presentedSurfaces.count, 1ul);
137137
}

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ - (nullable FlutterViewController*)viewControllerForId:(FlutterViewId)viewId;
9595
* An internal method that adds the view controller with the given ID.
9696
*
9797
* This method assigns the controller with the ID, puts the controller into the
98-
* map, and does assertions related to the default view ID.
98+
* map, and does assertions related to the implicit view ID.
9999
*/
100100
- (void)registerViewController:(FlutterViewController*)controller forId:(FlutterViewId)viewId;
101101

@@ -296,7 +296,7 @@ - (instancetype)initWithPlugin:(NSString*)pluginKey flutterEngine:(FlutterEngine
296296
}
297297

298298
- (NSView*)view {
299-
return [self viewForId:kFlutterDefaultViewId];
299+
return [self viewForId:kFlutterImplicitViewId];
300300
}
301301

302302
- (NSView*)viewForId:(FlutterViewId)viewId {
@@ -422,9 +422,9 @@ - (instancetype)initWithName:(NSString*)labelPrefix
422422
[_isResponseValid addObject:@YES];
423423
_terminationHandler = [[FlutterEngineTerminationHandler alloc] initWithEngine:self
424424
terminator:nil];
425-
// kFlutterDefaultViewId is reserved for the default view.
425+
// kFlutterImplicitViewId is reserved for the implicit view.
426426
// All IDs above it are for regular views.
427-
_nextViewId = kFlutterDefaultViewId + 1;
427+
_nextViewId = kFlutterImplicitViewId + 1;
428428

429429
_embedderAPI.struct_size = sizeof(FlutterEngineProcTable);
430430
FlutterEngineGetProcAddresses(&_embedderAPI);
@@ -506,10 +506,10 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
506506
flutterArguments.update_semantics_callback2 = [](const FlutterSemanticsUpdate2* update,
507507
void* user_data) {
508508
// TODO(dkwingsmt): This callback only supports single-view, therefore it
509-
// only operates on the default view. To support multi-view, we need a
509+
// only operates on the implicit view. To support multi-view, we need a
510510
// way to pass in the ID (probably through FlutterSemanticsUpdate).
511511
FlutterEngine* engine = (__bridge FlutterEngine*)user_data;
512-
[[engine viewControllerForId:kFlutterDefaultViewId] updateSemantics:update];
512+
[[engine viewControllerForId:kFlutterImplicitViewId] updateSemantics:update];
513513
};
514514
flutterArguments.custom_dart_entrypoint = entrypoint.UTF8String;
515515
flutterArguments.shutdown_dart_vm_when_done = true;
@@ -645,7 +645,7 @@ - (FlutterViewController*)viewControllerForId:(FlutterViewId)viewId {
645645

646646
- (void)setViewController:(FlutterViewController*)controller {
647647
FlutterViewController* currentController =
648-
[_viewControllers objectForKey:@(kFlutterDefaultViewId)];
648+
[_viewControllers objectForKey:@(kFlutterImplicitViewId)];
649649
if (currentController == controller) {
650650
// From nil to nil, or from non-nil to the same controller.
651651
return;
@@ -658,26 +658,26 @@ - (void)setViewController:(FlutterViewController*)controller {
658658
@"If you wanted to create an FlutterViewController and set it to an existing engine, "
659659
@"you should use FlutterViewController#init(engine:, nibName, bundle:) instead.",
660660
controller.engine);
661-
[self registerViewController:controller forId:kFlutterDefaultViewId];
661+
[self registerViewController:controller forId:kFlutterImplicitViewId];
662662
} else if (currentController != nil && controller == nil) {
663-
NSAssert(currentController.viewId == kFlutterDefaultViewId,
663+
NSAssert(currentController.viewId == kFlutterImplicitViewId,
664664
@"The default controller has an unexpected ID %llu", currentController.viewId);
665665
// From non-nil to nil.
666-
[self deregisterViewControllerForId:kFlutterDefaultViewId];
666+
[self deregisterViewControllerForId:kFlutterImplicitViewId];
667667
[self shutDownIfNeeded];
668668
} else {
669669
// From non-nil to a different non-nil view controller.
670670
NSAssert(NO,
671671
@"Failed to set view controller to the engine: "
672-
@"The engine already has a default view controller %@. "
673-
@"If you wanted to make the default view render in a different window, "
672+
@"The engine already has an implicit view controller %@. "
673+
@"If you wanted to make the implicit view render in a different window, "
674674
@"you should attach the current view controller to the window instead.",
675-
[_viewControllers objectForKey:@(kFlutterDefaultViewId)]);
675+
[_viewControllers objectForKey:@(kFlutterImplicitViewId)]);
676676
}
677677
}
678678

679679
- (FlutterViewController*)viewController {
680-
return [self viewControllerForId:kFlutterDefaultViewId];
680+
return [self viewControllerForId:kFlutterImplicitViewId];
681681
}
682682

683683
- (FlutterCompositor*)createFlutterCompositor {
@@ -705,9 +705,9 @@ - (FlutterCompositor*)createFlutterCompositor {
705705
void* user_data //
706706
) {
707707
// TODO(dkwingsmt): This callback only supports single-view, therefore it
708-
// only operates on the default view. To support multi-view, we need a new
708+
// only operates on the implicit view. To support multi-view, we need a new
709709
// callback that also receives a view ID.
710-
return reinterpret_cast<flutter::FlutterCompositor*>(user_data)->Present(kFlutterDefaultViewId,
710+
return reinterpret_cast<flutter::FlutterCompositor*>(user_data)->Present(kFlutterImplicitViewId,
711711
layers, layers_count);
712712
};
713713

@@ -725,7 +725,7 @@ - (FlutterCompositor*)createFlutterCompositor {
725725
#pragma mark - Framework-internal methods
726726

727727
- (void)addViewController:(FlutterViewController*)controller {
728-
[self registerViewController:controller forId:kFlutterDefaultViewId];
728+
[self registerViewController:controller forId:kFlutterImplicitViewId];
729729
}
730730

731731
- (void)removeViewController:(nonnull FlutterViewController*)viewController {
@@ -812,7 +812,7 @@ - (nonnull NSString*)executableName {
812812
}
813813

814814
- (void)updateWindowMetricsForViewController:(FlutterViewController*)viewController {
815-
if (viewController.viewId != kFlutterDefaultViewId) {
815+
if (viewController.viewId != kFlutterImplicitViewId) {
816816
// TODO(dkwingsmt): The embedder API only supports single-view for now. As
817817
// embedder APIs are converted to multi-view, this method should support any
818818
// views.
@@ -1078,7 +1078,7 @@ - (void)handleAccessibilityEvent:(NSDictionary<NSString*, id>*)annotatedEvent {
10781078
- (void)announceAccessibilityMessage:(NSString*)message
10791079
withPriority:(NSAccessibilityPriorityLevel)priority {
10801080
NSAccessibilityPostNotificationWithUserInfo(
1081-
[self viewControllerForId:kFlutterDefaultViewId].flutterView,
1081+
[self viewControllerForId:kFlutterImplicitViewId].flutterView,
10821082
NSAccessibilityAnnouncementRequestedNotification,
10831083
@{NSAccessibilityAnnouncementKey : message, NSAccessibilityPriorityKey : @(priority)});
10841084
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// CREATE_NATIVE_ENTRY and MOCK_ENGINE_PROC are leaky by design
2626
// NOLINTBEGIN(clang-analyzer-core.StackAddressEscape)
2727

28-
constexpr int64_t kDefaultViewId = 0ll;
28+
constexpr int64_t kImplicitViewId = 0ll;
2929

3030
@interface FlutterEngine (Test)
3131
/**
@@ -354,7 +354,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
354354
FlutterSemanticsNode2* nodes[] = {&root, &child1};
355355
update.nodes = nodes;
356356
update.custom_action_count = 0;
357-
// This call updates semantics for the default view, which does not exist,
357+
// This call updates semantics for the implicit view, which does not exist,
358358
// and therefore this call is invalid. But the engine should not crash.
359359
update_semantics_callback(&update, (__bridge void*)engine);
360360

@@ -632,7 +632,7 @@ - (nonnull NSView*)createWithViewIdentifier:(int64_t)viewId arguments:(nullable
632632
[threadSynchronizer shutdown];
633633

634634
std::thread rasterThread([&threadSynchronizer] {
635-
[threadSynchronizer performCommitForView:kDefaultViewId
635+
[threadSynchronizer performCommitForView:kImplicitViewId
636636
size:CGSizeMake(100, 100)
637637
notify:^{
638638
}];

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ typedef NS_ENUM(NSInteger, FlutterAppExitResponse) {
115115
*
116116
* Practically, since FlutterEngine can only be attached with one controller,
117117
* the given controller, if successfully attached, will always have the default
118-
* view ID kFlutterDefaultViewId.
118+
* view ID kFlutterImplicitViewId.
119119
*
120120
* The engine holds a weak reference to the attached view controller.
121121
*
@@ -127,11 +127,11 @@ typedef NS_ENUM(NSInteger, FlutterAppExitResponse) {
127127
/**
128128
* Dissociate the given view controller from this engine.
129129
*
130-
* Practically, since FlutterEngine can only be attached with one controller,
131-
* the given controller must be the default view controller.
132-
*
133130
* If the view controller is not associated with this engine, this call throws an
134131
* assertion.
132+
*
133+
* Practically, since FlutterEngine can only be attached with one controller for
134+
* now, the given controller must be the current view controller.
135135
*/
136136
- (void)removeViewController:(FlutterViewController*)viewController;
137137

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ typedef int64_t FlutterViewId;
2020
* backward compatibility, single-view APIs will always operate on the view with
2121
* this ID. Also, the first view assigned to the engine will also have this ID.
2222
*/
23-
constexpr FlutterViewId kFlutterDefaultViewId = 0ll;
23+
constexpr FlutterViewId kFlutterImplicitViewId = 0ll;
2424

2525
/**
2626
* Listener for view resizing.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
.andDo(^(NSInvocation* invocation) {
2828
FlutterViewId viewId;
2929
[invocation getArgument:&viewId atIndex:2];
30-
if (viewId == kFlutterDefaultViewId) {
30+
if (viewId == kFlutterImplicitViewId) {
3131
if (mockFlutterViewController != nil) {
3232
[invocation setReturnValue:&mockFlutterViewController];
3333
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import "flutter/testing/testing.h"
1010

11-
constexpr int64_t kDefaultViewId = 0ll;
11+
constexpr int64_t kImplicitViewId = 0ll;
1212

1313
@interface TestReshapeListener : NSObject <FlutterViewReshapeListener>
1414

@@ -30,6 +30,6 @@ - (void)viewDidReshape:(nonnull NSView*)view {
3030
commandQueue:queue
3131
reshapeListener:listener
3232
threadSynchronizer:threadSynchronizer
33-
viewId:kDefaultViewId];
33+
viewId:kImplicitViewId];
3434
EXPECT_EQ([view layer:view.layer shouldInheritContentsScale:3.0 fromWindow:view.window], YES);
3535
}

0 commit comments

Comments
 (0)