@@ -43,6 +43,7 @@ import androidx.compose.ui.input.pointer.PointerIcon
4343import androidx.compose.ui.input.pointer.PointerKeyboardModifiers
4444import androidx.compose.ui.input.pointer.PointerType
4545import androidx.compose.ui.navigationevent.BackNavigationEventInput
46+ import androidx.compose.ui.node.InternalCoreApi
4647import androidx.compose.ui.platform.AwtDragAndDropManager
4748import androidx.compose.ui.platform.DefaultInputModeManager
4849import androidx.compose.ui.platform.DelegateRootForTestListener
@@ -322,7 +323,15 @@ internal class ComposeSceneMediator(
322323 val focusManager get() = scene.focusManager
323324 var compositionLocalContext: CompositionLocalContext ?
324325 get() = scene.compositionLocalContext
325- set(value) { scene.compositionLocalContext = value }
326+ set(value) {
327+ scene.compositionLocalContext = value
328+ }
329+ var showLayoutBounds: Boolean
330+ get() = scene.showLayoutBounds
331+ @InternalCoreApi set(value) {
332+ scene.showLayoutBounds = value
333+ }
334+
326335
327336 /* *
328337 * Provides the size of ComposeScene content inside infinity constraints
@@ -493,7 +502,7 @@ internal class ComposeSceneMediator(
493502 /* *
494503 * Returns the first heavyweight ancestor of the given component.
495504 */
496- private fun Component.heavyWeightAncestorOrNull () : Component ? {
505+ private fun Component.heavyWeightAncestorOrNull (): Component ? {
497506 var parent = parent
498507 while (parent != null ) {
499508 if (! parent.isLightweight) return parent
@@ -671,13 +680,14 @@ internal class ComposeSceneMediator(
671680 scene.layoutDirection = layoutDirection
672681 }
673682
674- override fun onRender (canvas : Canvas , width : Int , height : Int , nanoTime : Long ) = catchExceptions {
675- interopContainer.postponingExecutingScheduledUpdates {
676- canvas.withSceneOffset {
677- scene.render(asComposeCanvas(), nanoTime)
683+ override fun onRender (canvas : Canvas , width : Int , height : Int , nanoTime : Long ) =
684+ catchExceptions {
685+ interopContainer.postponingExecutingScheduledUpdates {
686+ canvas.withSceneOffset {
687+ scene.render(asComposeCanvas(), nanoTime)
688+ }
678689 }
679690 }
680- }
681691
682692 private inline fun Canvas.withSceneOffset (block : Canvas .() -> Unit ) {
683693 // Offset of scene relative to [container]
@@ -706,7 +716,8 @@ internal class ComposeSceneMediator(
706716 keyboardModifiersRequireUpdate = true
707717 }
708718
709- private inner class DesktopViewConfiguration : ViewConfiguration by PlatformContext .DefaultViewConfiguration {
719+ private inner class DesktopViewConfiguration :
720+ ViewConfiguration by PlatformContext .DefaultViewConfiguration {
710721 override val touchSlop: Float get() = with (platformComponent.density) { 18 .dp.toPx() }
711722 }
712723
@@ -747,7 +758,8 @@ internal class ComposeSceneMediator(
747758 * A new [SemanticsOwner] is always created above existing ones. So, usage of [LinkedHashMap]
748759 * is required here to keep insertion-order (that equal to [SemanticsOwner]s order).
749760 */
750- private val _accessibilityControllers = linkedMapOf<SemanticsOwner , AccessibilityController >()
761+ private val _accessibilityControllers =
762+ linkedMapOf<SemanticsOwner , AccessibilityController >()
751763 val accessibilityControllers get() = _accessibilityControllers .values.reversed()
752764
753765 val semanticsOwners = mutableStateSetOf<SemanticsOwner >()
@@ -797,7 +809,8 @@ internal class ComposeSceneMediator(
797809 override fun convertScreenToLocalPosition (positionOnScreen : Offset ): Offset =
798810 windowContext.convertScreenToLocalPosition(container, positionOnScreen)
799811
800- override val measureDrawLayerBounds: Boolean = this @ComposeSceneMediator.measureDrawLayerBounds
812+ override val measureDrawLayerBounds: Boolean =
813+ this @ComposeSceneMediator.measureDrawLayerBounds
801814 override val viewConfiguration: ViewConfiguration = DesktopViewConfiguration ()
802815 override val inputModeManager: InputModeManager = DefaultInputModeManager ()
803816 override val textInputService = this @ComposeSceneMediator.textInputService
@@ -893,19 +906,20 @@ private fun ComposeScene.onMouseEvent(
893906 )
894907}
895908
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 )
909+ internal val MouseEvent .composePointerButton: PointerButton ?
910+ get() {
911+ if (button == MouseEvent .NOBUTTON ) return null
912+ return when (button) {
913+ MouseEvent .BUTTON2 -> PointerButton .Tertiary
914+ MouseEvent .BUTTON3 -> PointerButton .Secondary
915+ else -> PointerButton (button - 1 )
916+ }
902917 }
903- }
904918
905919private fun ComposeScene.onMouseWheelEvent (
906920 position : Offset ,
907921 event : MouseWheelEvent
908- ) : PointerEventResult {
922+ ): PointerEventResult {
909923 return sendPointerEvent(
910924 eventType = PointerEventType .Scroll ,
911925 position = position,
@@ -923,37 +937,39 @@ private fun ComposeScene.onMouseWheelEvent(
923937}
924938
925939
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- )
940+ private val MouseEvent .buttons
941+ get() = PointerButtons (
942+ // We should check [event.button] because of case where [event.modifiersEx] does not provide
943+ // info about the pressed mouse button when using touchpad on MacOS 12 (AWT only).
944+ // When the [Tap to click] feature is activated on Mac OS 12, half of all clicks are not
945+ // handled because [event.modifiersEx] may not provide info about the pressed mouse button.
946+ isPrimaryPressed = ((modifiersEx and MouseEvent .BUTTON1_DOWN_MASK ) != 0
947+ || (id == MouseEvent .MOUSE_PRESSED && button == MouseEvent .BUTTON1 ))
948+ && ! isMacOsCtrlClick,
949+ isSecondaryPressed = (modifiersEx and MouseEvent .BUTTON3_DOWN_MASK ) != 0
950+ || (id == MouseEvent .MOUSE_PRESSED && button == MouseEvent .BUTTON3 )
951+ || isMacOsCtrlClick,
952+ isTertiaryPressed = (modifiersEx and MouseEvent .BUTTON2_DOWN_MASK ) != 0
953+ || (id == MouseEvent .MOUSE_PRESSED && button == MouseEvent .BUTTON2 ),
954+ isBackPressed = (modifiersEx and MouseEvent .getMaskForButton(4 )) != 0
955+ || (id == MouseEvent .MOUSE_PRESSED && button == 4 ),
956+ isForwardPressed = (modifiersEx and MouseEvent .getMaskForButton(5 )) != 0
957+ || (id == MouseEvent .MOUSE_PRESSED && button == 5 ),
958+ )
959+
960+ private val MouseEvent .keyboardModifiers
961+ get() = PointerKeyboardModifiers (
962+ isCtrlPressed = (modifiersEx and InputEvent .CTRL_DOWN_MASK ) != 0 ,
963+ isMetaPressed = (modifiersEx and InputEvent .META_DOWN_MASK ) != 0 ,
964+ isAltPressed = (modifiersEx and InputEvent .ALT_DOWN_MASK ) != 0 ,
965+ isShiftPressed = (modifiersEx and InputEvent .SHIFT_DOWN_MASK ) != 0 ,
966+ isAltGraphPressed = (modifiersEx and InputEvent .ALT_GRAPH_DOWN_MASK ) != 0 ,
967+ isSymPressed = false ,
968+ isFunctionPressed = false ,
969+ isCapsLockOn = getLockingKeyStateSafe(KeyEvent .VK_CAPS_LOCK ),
970+ isScrollLockOn = getLockingKeyStateSafe(KeyEvent .VK_SCROLL_LOCK ),
971+ isNumLockOn = getLockingKeyStateSafe(KeyEvent .VK_NUM_LOCK ),
972+ )
957973
958974private fun Component.subscribeToMouseEvents (mouseAdapter : MouseAdapter ) {
959975 addMouseListener(mouseAdapter)
0 commit comments