[Base Shell] Refactor Presentation in CommonBaseShellModel
To soft transition presentation.fidl, CommonBaseShellModel
needs to extends instead of implements the Presentation
interface.
This CL refactors it by moving the implementation into a
separate class. It also fixes the comments that were
incorrectly marking some methods as Presentation overrides.
Bug: SU-158
Tests: manual
Change-Id: Icb0ceefeaacaa94343ce1d06e096bd29bc7f1231
diff --git a/bin/userpicker_base_shell/lib/user_picker_base_shell_model.dart b/bin/userpicker_base_shell/lib/user_picker_base_shell_model.dart
index cc247fd..ceef118 100644
--- a/bin/userpicker_base_shell/lib/user_picker_base_shell_model.dart
+++ b/bin/userpicker_base_shell/lib/user_picker_base_shell_model.dart
@@ -27,11 +27,9 @@
class UserPickerBaseShellModel extends CommonBaseShellModel
with TickerProviderModelMixin
implements
- Presentation,
ServiceProvider,
KeyboardCaptureListenerHack,
- PointerCaptureListenerHack,
- PresentationModeListener {
+ PointerCaptureListenerHack {
/// Called when the base shell stops.
final VoidCallback onBaseShellStopped;
diff --git a/lib/base_shell/lib/base_model.dart b/lib/base_shell/lib/base_model.dart
index 2ed75a7..0f6ce90 100644
--- a/lib/base_shell/lib/base_model.dart
+++ b/lib/base_shell/lib/base_model.dart
@@ -35,17 +35,108 @@
const Duration _kCobaltTimerTimeout = const Duration(seconds: 20);
const int _kSessionShellLoginTimeMetricId = 14;
+// This class is extends the Presentation protocol and implements and PresentationModeListener.
+// It delegates the methods to the Presentation received by the CommonBaseShellModel that owns it.
+class CommonBaseShellPresentationImpl extends Presentation
+ implements PresentationModeListener {
+ final CommonBaseShellModel _model;
+
+ CommonBaseShellPresentationImpl(this._model);
+
+ /// |Presentation|.
+ @override
+ // ignore: avoid_positional_boolean_parameters
+ Future<void> enableClipping(bool enabled) async {
+ await _model.presentation.enableClipping(enabled);
+ }
+
+ @override
+ Future<void> useOrthographicView() async {
+ await _model.presentation.useOrthographicView();
+ }
+
+ @override
+ Future<void> usePerspectiveView() async {
+ await _model.presentation.usePerspectiveView();
+ }
+
+ @override
+ Future<void> setRendererParams(List<RendererParam> params) async {
+ await _model.presentation.setRendererParams(params);
+ }
+
+ @override
+ Future<void> setDisplayUsage(DisplayUsage usage) async {
+ await _model.presentation.setDisplayUsage(usage);
+ }
+
+ @override
+ // ignore: avoid_positional_boolean_parameters
+ Future<void> setDisplayRotation(
+ double displayRotationDegrees, bool animate) async {
+ await _model.presentation
+ .setDisplayRotation(displayRotationDegrees, animate);
+ }
+
+ @override
+ Future<void> setDisplaySizeInMm(num widthInMm, num heightInMm) async {
+ await _model.presentation.setDisplaySizeInMm(widthInMm, heightInMm);
+ }
+
+ @override
+ Future<void> captureKeyboardEventHack(input.KeyboardEvent eventToCapture,
+ InterfaceHandle<KeyboardCaptureListenerHack> listener) async {
+ await _model.presentation
+ .captureKeyboardEventHack(eventToCapture, listener);
+ }
+
+ @override
+ Future<void> capturePointerEventsHack(
+ InterfaceHandle<PointerCaptureListenerHack> listener) async {
+ await _model.presentation.capturePointerEventsHack(listener);
+ }
+
+ @override
+ Future<PresentationMode> getPresentationMode() async {
+ return await _model.presentation.getPresentationMode();
+ }
+
+ @override
+ Future<void> setPresentationModeListener(
+ InterfaceHandle<PresentationModeListener> listener) async {
+ await _model.presentation.setPresentationModeListener(listener);
+ }
+
+ /// |PresentationModeListener|.
+ @override
+ Future<void> onModeChanged() async {
+ PresentationMode mode = await getPresentationMode();
+ log.info('Presentation mode changed to: $mode');
+ switch (mode) {
+ case PresentationMode.tent:
+ await setDisplayRotation(180.0, true);
+ break;
+ case PresentationMode.tablet:
+ // TODO(sanjayc): Figure out up/down orientation.
+ await setDisplayRotation(90.0, true);
+ break;
+ case PresentationMode.laptop:
+ default:
+ await setDisplayRotation(0.0, true);
+ break;
+ }
+ }
+}
+
/// Provides common features needed by all base shells.
///
/// This includes user management, presentation handling,
/// and keyboard shortcuts.
class CommonBaseShellModel extends BaseShellModel
implements
- Presentation,
ServiceProvider,
KeyboardCaptureListenerHack,
- PointerCaptureListenerHack,
- PresentationModeListener {
+ PointerCaptureListenerHack {
/// Handles login, logout, and adding/removing users.
///
/// Shouldn't be used before onReady.
@@ -78,8 +169,12 @@
final List<PresentationBinding> _presentationBindings =
<PresentationBinding>[];
+ CommonBaseShellPresentationImpl _presentationImpl;
+
/// Constructor
- CommonBaseShellModel(this.logger) : super();
+ CommonBaseShellModel(this.logger) : super() {
+ _presentationImpl = CommonBaseShellPresentationImpl(this);
+ }
List<Account> get accounts => _accounts;
@@ -89,25 +184,13 @@
set shouldCreateNewChildView(bool should) {}
- @override
- Future<void> captureKeyboardEventHack(input.KeyboardEvent eventToCapture,
- InterfaceHandle<KeyboardCaptureListenerHack> listener) async {
- await presentation.captureKeyboardEventHack(eventToCapture, listener);
- }
-
- @override
- Future<void> capturePointerEventsHack(
- InterfaceHandle<PointerCaptureListenerHack> listener) async {
- await presentation.capturePointerEventsHack(listener);
- }
-
// |ServiceProvider|.
@override
Future<void> connectToService(String serviceName, Channel channel) {
// TODO(SCN-595) mozart.Presentation is being renamed to ui.Presentation.
if (serviceName == 'ui.Presentation') {
_presentationBindings.add(PresentationBinding()
- ..bind(this, InterfaceRequest<Presentation>(channel)));
+ ..bind(_presentationImpl, InterfaceRequest<Presentation>(channel)));
} else {
log.warning(
'UserPickerBaseShell: received request for unknown service: $serviceName !');
@@ -129,18 +212,6 @@
}
}
- @override
- // ignore: avoid_positional_boolean_parameters
- Future<void> enableClipping(bool enabled) async {
- await presentation.enableClipping(enabled);
- }
-
- /// |Presentation|.
- @override
- Future<PresentationMode> getPresentationMode() async {
- return await presentation.getPresentationMode();
- }
-
/// Whether or not the device has an internet connection.
///
/// Currently, having an IP is equivalent to having internet, although
@@ -234,26 +305,6 @@
notifyListeners();
}
- /// |PresentationModeListener|.
- @override
- Future<void> onModeChanged() async {
- PresentationMode mode = await getPresentationMode();
- log.info('Presentation mode changed to: $mode');
- switch (mode) {
- case PresentationMode.tent:
- await setDisplayRotation(180.0, true);
- break;
- case PresentationMode.tablet:
- // TODO(sanjayc): Figure out up/down orientation.
- await setDisplayRotation(90.0, true);
- break;
- case PresentationMode.laptop:
- default:
- await setDisplayRotation(0.0, true);
- break;
- }
- }
-
/// |KeyboardCaptureListener|.
@override
Future<void> onEvent(input.KeyboardEvent ev) async {}
@@ -262,8 +313,7 @@
@override
Future<void> onPointerEvent(input.PointerEvent event) async {}
- // |Presentation|.
- // Delegate to the Presentation received by BaseShell.Initialize().
+ // |BaseShellModel|.
// TODO: revert to default state when client logs out.
@mustCallSuper
@override
@@ -281,7 +331,7 @@
await presentation
.capturePointerEventsHack(_pointerCaptureListenerBinding.wrap(this));
await presentation.setPresentationModeListener(
- _presentationModeListenerBinding.wrap(this));
+ _presentationModeListenerBinding.wrap(_presentationImpl));
_userManager = BaseShellUserManager(userProvider);
@@ -307,8 +357,7 @@
await refreshUsers();
}
- // |Presentation|.
- // Delegate to the Presentation received by BaseShell.Initialize().
+ // |BaseShellModel|
// TODO: revert to default state when client logs out.
@override
void onStop() {
@@ -320,8 +369,6 @@
super.onStop();
}
- // |Presentation|.
- // Delegate to the Presentation received by BaseShell.Initialize().
// TODO: revert to default state when client logs out.
/// Refreshes the list of users.
Future<void> refreshUsers() async {
@@ -329,8 +376,6 @@
notifyListeners();
}
- // |Presentation|.
- // Delegate to the Presentation received by BaseShell.Initialize().
// TODO: revert to default state when client logs out.
/// Permanently removes the user.
Future removeUser(Account account) async {
@@ -343,50 +388,6 @@
}
}
- // |Presentation|.
- @override
- // ignore: avoid_positional_boolean_parameters
- Future<void> setDisplayRotation(
- double displayRotationDegrees, bool animate) async {
- await presentation.setDisplayRotation(displayRotationDegrees, animate);
- }
-
- // |Presentation|.
- @override
- Future<void> setDisplaySizeInMm(num widthInMm, num heightInMm) async {
- await presentation.setDisplaySizeInMm(widthInMm, heightInMm);
- }
-
- // |Presentation|.
- @override
- Future<void> setDisplayUsage(DisplayUsage usage) async {
- await presentation.setDisplayUsage(usage);
- }
-
- // |Presentation|.
- /// |Presentation|.
- @override
- Future<void> setPresentationModeListener(
- InterfaceHandle<PresentationModeListener> listener) async {
- await presentation.setPresentationModeListener(listener);
- }
-
- // |Presentation|.
- @override
- Future<void> setRendererParams(List<RendererParam> params) async {
- await presentation.setRendererParams(params);
- }
-
- @override
- Future<void> useOrthographicView() async {
- await presentation.useOrthographicView();
- }
-
- @override
- Future<void> usePerspectiveView() async {
- await presentation.usePerspectiveView();
- }
-
@override
// TODO: implement $serviceData
ServiceData get $serviceData => null;