@@ -257,11 +257,13 @@ internal class ComposeSceneMediator(
257257 platformContext.parentFocusManager.moveFocus(FocusDirection .Previous )
258258 }
259259 }
260+
260261 TRAVERSAL , TRAVERSAL_FORWARD -> {
261262 if (! focusManager.takeFocus(FocusDirection .Next )) {
262263 platformContext.parentFocusManager.moveFocus(FocusDirection .Next )
263264 }
264265 }
266+
265267 else -> Unit
266268 }
267269 }
@@ -318,11 +320,19 @@ internal class ComposeSceneMediator(
318320 }
319321 }
320322
321- private val scene by lazy { composeSceneFactory(this ) }
323+ internal val scene by lazy { composeSceneFactory(this ) }
322324 val focusManager get() = scene.focusManager
323325 var compositionLocalContext: CompositionLocalContext ?
324326 get() = scene.compositionLocalContext
325- set(value) { scene.compositionLocalContext = value }
327+ set(value) {
328+ scene.compositionLocalContext = value
329+ }
330+ var showLayoutBounds: Boolean
331+ get() = scene.showLayoutBounds
332+ set(value) {
333+ scene.showLayoutBounds = value
334+ }
335+
326336
327337 /* *
328338 * Provides the size of ComposeScene content inside infinity constraints
@@ -493,7 +503,7 @@ internal class ComposeSceneMediator(
493503 /* *
494504 * Returns the first heavyweight ancestor of the given component.
495505 */
496- private fun Component.heavyWeightAncestorOrNull () : Component ? {
506+ private fun Component.heavyWeightAncestorOrNull (): Component ? {
497507 var parent = parent
498508 while (parent != null ) {
499509 if (! parent.isLightweight) return parent
@@ -671,13 +681,14 @@ internal class ComposeSceneMediator(
671681 scene.layoutDirection = layoutDirection
672682 }
673683
674- override fun onRender (canvas : Canvas , width : Int , height : Int , nanoTime : Long ) = catchExceptions {
675- interopContainer.postponingExecutingScheduledUpdates {
676- canvas.withSceneOffset {
677- scene.render(asComposeCanvas(), nanoTime)
684+ override fun onRender (canvas : Canvas , width : Int , height : Int , nanoTime : Long ) =
685+ catchExceptions {
686+ interopContainer.postponingExecutingScheduledUpdates {
687+ canvas.withSceneOffset {
688+ scene.render(asComposeCanvas(), nanoTime)
689+ }
678690 }
679691 }
680- }
681692
682693 private inline fun Canvas.withSceneOffset (block : Canvas .() -> Unit ) {
683694 // Offset of scene relative to [container]
@@ -706,7 +717,8 @@ internal class ComposeSceneMediator(
706717 keyboardModifiersRequireUpdate = true
707718 }
708719
709- private inner class DesktopViewConfiguration : ViewConfiguration by PlatformContext .DefaultViewConfiguration {
720+ private inner class DesktopViewConfiguration :
721+ ViewConfiguration by PlatformContext .DefaultViewConfiguration {
710722 override val touchSlop: Float get() = with (platformComponent.density) { 18 .dp.toPx() }
711723 }
712724
@@ -747,7 +759,8 @@ internal class ComposeSceneMediator(
747759 * A new [SemanticsOwner] is always created above existing ones. So, usage of [LinkedHashMap]
748760 * is required here to keep insertion-order (that equal to [SemanticsOwner]s order).
749761 */
750- private val _accessibilityControllers = linkedMapOf<SemanticsOwner , AccessibilityController >()
762+ private val _accessibilityControllers =
763+ linkedMapOf<SemanticsOwner , AccessibilityController >()
751764 val accessibilityControllers get() = _accessibilityControllers .values.reversed()
752765
753766 val semanticsOwners = mutableStateSetOf<SemanticsOwner >()
@@ -797,7 +810,8 @@ internal class ComposeSceneMediator(
797810 override fun convertScreenToLocalPosition (positionOnScreen : Offset ): Offset =
798811 windowContext.convertScreenToLocalPosition(container, positionOnScreen)
799812
800- override val measureDrawLayerBounds: Boolean = this @ComposeSceneMediator.measureDrawLayerBounds
813+ override val measureDrawLayerBounds: Boolean =
814+ this @ComposeSceneMediator.measureDrawLayerBounds
801815 override val viewConfiguration: ViewConfiguration = DesktopViewConfiguration ()
802816 override val inputModeManager: InputModeManager = DefaultInputModeManager ()
803817 override val textInputService = this @ComposeSceneMediator.textInputService
@@ -810,6 +824,7 @@ internal class ComposeSceneMediator(
810824 contentComponent.cursor =
811825 (pointerIcon as ? AwtCursor )?.cursor ? : Cursor (Cursor .DEFAULT_CURSOR )
812826 }
827+
813828 override val parentFocusManager: FocusManager = DesktopFocusManager ()
814829 override fun requestFocus (): Boolean {
815830 // Don't check hasFocus(), and don't check the returning result
@@ -893,19 +908,20 @@ private fun ComposeScene.onMouseEvent(
893908 )
894909}
895910
896- internal val MouseEvent .composePointerButton: PointerButton ? get() {
897- if (button == MouseEvent .NOBUTTON ) return null
898- return when (button) {
899- MouseEvent .BUTTON2 -> PointerButton .Tertiary
900- MouseEvent .BUTTON3 -> PointerButton .Secondary
901- else -> PointerButton (button - 1 )
911+ internal val MouseEvent .composePointerButton: PointerButton ?
912+ get() {
913+ if (button == MouseEvent .NOBUTTON ) return null
914+ return when (button) {
915+ MouseEvent .BUTTON2 -> PointerButton .Tertiary
916+ MouseEvent .BUTTON3 -> PointerButton .Secondary
917+ else -> PointerButton (button - 1 )
918+ }
902919 }
903- }
904920
905921private fun ComposeScene.onMouseWheelEvent (
906922 position : Offset ,
907923 event : MouseWheelEvent
908- ) : PointerEventResult {
924+ ): PointerEventResult {
909925 return sendPointerEvent(
910926 eventType = PointerEventType .Scroll ,
911927 position = position,
@@ -923,37 +939,39 @@ private fun ComposeScene.onMouseWheelEvent(
923939}
924940
925941
926- private val MouseEvent .buttons get() = PointerButtons (
927- // We should check [event.button] because of case where [event.modifiersEx] does not provide
928- // info about the pressed mouse button when using touchpad on MacOS 12 (AWT only).
929- // When the [Tap to click] feature is activated on Mac OS 12, half of all clicks are not
930- // handled because [event.modifiersEx] may not provide info about the pressed mouse button.
931- isPrimaryPressed = ((modifiersEx and MouseEvent .BUTTON1_DOWN_MASK ) != 0
932- || (id == MouseEvent .MOUSE_PRESSED && button == MouseEvent .BUTTON1 ))
933- && ! isMacOsCtrlClick,
934- isSecondaryPressed = (modifiersEx and MouseEvent .BUTTON3_DOWN_MASK ) != 0
935- || (id == MouseEvent .MOUSE_PRESSED && button == MouseEvent .BUTTON3 )
936- || isMacOsCtrlClick,
937- isTertiaryPressed = (modifiersEx and MouseEvent .BUTTON2_DOWN_MASK ) != 0
938- || (id == MouseEvent .MOUSE_PRESSED && button == MouseEvent .BUTTON2 ),
939- isBackPressed = (modifiersEx and MouseEvent .getMaskForButton(4 )) != 0
940- || (id == MouseEvent .MOUSE_PRESSED && button == 4 ),
941- isForwardPressed = (modifiersEx and MouseEvent .getMaskForButton(5 )) != 0
942- || (id == MouseEvent .MOUSE_PRESSED && button == 5 ),
943- )
944-
945- private val MouseEvent .keyboardModifiers get() = PointerKeyboardModifiers (
946- isCtrlPressed = (modifiersEx and InputEvent .CTRL_DOWN_MASK ) != 0 ,
947- isMetaPressed = (modifiersEx and InputEvent .META_DOWN_MASK ) != 0 ,
948- isAltPressed = (modifiersEx and InputEvent .ALT_DOWN_MASK ) != 0 ,
949- isShiftPressed = (modifiersEx and InputEvent .SHIFT_DOWN_MASK ) != 0 ,
950- isAltGraphPressed = (modifiersEx and InputEvent .ALT_GRAPH_DOWN_MASK ) != 0 ,
951- isSymPressed = false ,
952- isFunctionPressed = false ,
953- isCapsLockOn = getLockingKeyStateSafe(KeyEvent .VK_CAPS_LOCK ),
954- isScrollLockOn = getLockingKeyStateSafe(KeyEvent .VK_SCROLL_LOCK ),
955- isNumLockOn = getLockingKeyStateSafe(KeyEvent .VK_NUM_LOCK ),
956- )
942+ private val MouseEvent .buttons
943+ get() = PointerButtons (
944+ // We should check [event.button] because of case where [event.modifiersEx] does not provide
945+ // info about the pressed mouse button when using touchpad on MacOS 12 (AWT only).
946+ // When the [Tap to click] feature is activated on Mac OS 12, half of all clicks are not
947+ // handled because [event.modifiersEx] may not provide info about the pressed mouse button.
948+ isPrimaryPressed = ((modifiersEx and MouseEvent .BUTTON1_DOWN_MASK ) != 0
949+ || (id == MouseEvent .MOUSE_PRESSED && button == MouseEvent .BUTTON1 ))
950+ && ! isMacOsCtrlClick,
951+ isSecondaryPressed = (modifiersEx and MouseEvent .BUTTON3_DOWN_MASK ) != 0
952+ || (id == MouseEvent .MOUSE_PRESSED && button == MouseEvent .BUTTON3 )
953+ || isMacOsCtrlClick,
954+ isTertiaryPressed = (modifiersEx and MouseEvent .BUTTON2_DOWN_MASK ) != 0
955+ || (id == MouseEvent .MOUSE_PRESSED && button == MouseEvent .BUTTON2 ),
956+ isBackPressed = (modifiersEx and MouseEvent .getMaskForButton(4 )) != 0
957+ || (id == MouseEvent .MOUSE_PRESSED && button == 4 ),
958+ isForwardPressed = (modifiersEx and MouseEvent .getMaskForButton(5 )) != 0
959+ || (id == MouseEvent .MOUSE_PRESSED && button == 5 ),
960+ )
961+
962+ private val MouseEvent .keyboardModifiers
963+ get() = PointerKeyboardModifiers (
964+ isCtrlPressed = (modifiersEx and InputEvent .CTRL_DOWN_MASK ) != 0 ,
965+ isMetaPressed = (modifiersEx and InputEvent .META_DOWN_MASK ) != 0 ,
966+ isAltPressed = (modifiersEx and InputEvent .ALT_DOWN_MASK ) != 0 ,
967+ isShiftPressed = (modifiersEx and InputEvent .SHIFT_DOWN_MASK ) != 0 ,
968+ isAltGraphPressed = (modifiersEx and InputEvent .ALT_GRAPH_DOWN_MASK ) != 0 ,
969+ isSymPressed = false ,
970+ isFunctionPressed = false ,
971+ isCapsLockOn = getLockingKeyStateSafe(KeyEvent .VK_CAPS_LOCK ),
972+ isScrollLockOn = getLockingKeyStateSafe(KeyEvent .VK_SCROLL_LOCK ),
973+ isNumLockOn = getLockingKeyStateSafe(KeyEvent .VK_NUM_LOCK ),
974+ )
957975
958976private fun Component.subscribeToMouseEvents (mouseAdapter : MouseAdapter ) {
959977 addMouseListener(mouseAdapter)
0 commit comments