3289 }
3290 }
3291 }
3292 }
3293
3294 if (reset) {
3295 KeyboardFocusManager.setMostRecentFocusOwner(window, null);
3296 }
3297 }
3298
3299 void clearCurrentFocusCycleRootOnHide() {
3300 KeyboardFocusManager kfm =
3301 KeyboardFocusManager.getCurrentKeyboardFocusManager();
3302 Container cont = kfm.getCurrentFocusCycleRoot();
3303
3304 if (cont == this || isParentOf(cont)) {
3305 kfm.setGlobalCurrentFocusCycleRootPriv(null);
3306 }
3307 }
3308
3309 final Container getTraversalRoot() {
3310 if (isFocusCycleRoot()) {
3311 return findTraversalRoot();
3312 }
3313
3314 return super.getTraversalRoot();
3315 }
3316
3317 /**
3318 * Sets the focus traversal policy that will manage keyboard traversal of
3319 * this Container's children, if this Container is a focus cycle root. If
3320 * the argument is null, this Container inherits its policy from its focus-
3321 * cycle-root ancestor. If the argument is non-null, this policy will be
3322 * inherited by all focus-cycle-root children that have no keyboard-
3323 * traversal policy of their own (as will, recursively, their focus-cycle-
3324 * root children).
3325 * <p>
3326 * If this Container is not a focus cycle root, the policy will be
3327 * remembered, but will not be used or inherited by this or any other
3328 * Containers until this Container is made a focus cycle root.
4372 * container
4373 */
4374 private static final int LWD_MOUSE_DRAGGED_OVER = 1500;
4375
4376 private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.LightweightDispatcher");
4377
4378 LightweightDispatcher(Container nativeContainer) {
4379 this.nativeContainer = nativeContainer;
4380 mouseEventTarget = null;
4381 eventMask = 0;
4382 }
4383
4384 /*
4385 * Clean up any resources allocated when dispatcher was created;
4386 * should be called from Container.removeNotify
4387 */
4388 void dispose() {
4389 //System.out.println("Disposing lw dispatcher");
4390 stopListeningForOtherDrags();
4391 mouseEventTarget = null;
4392 }
4393
4394 /**
4395 * Enables events to subcomponents.
4396 */
4397 void enableEvents(long events) {
4398 eventMask |= events;
4399 }
4400
4401 /**
4402 * Dispatches an event to a sub-component if necessary, and
4403 * returns whether or not the event was forwarded to a
4404 * sub-component.
4405 *
4406 * @param e the event
4407 */
4408 boolean dispatchEvent(AWTEvent e) {
4409 boolean ret = false;
4410
4411 /*
4463 /**
4464 * This method attempts to distribute a mouse event to a lightweight
4465 * component. It tries to avoid doing any unnecessary probes down
4466 * into the component tree to minimize the overhead of determining
4467 * where to route the event, since mouse movement events tend to
4468 * come in large and frequent amounts.
4469 */
4470 private boolean processMouseEvent(MouseEvent e) {
4471 int id = e.getID();
4472 Component mouseOver = // sensitive to mouse events
4473 nativeContainer.getMouseEventTarget(e.getX(), e.getY(),
4474 Container.INCLUDE_SELF);
4475
4476 trackMouseEnterExit(mouseOver, e);
4477
4478 // 4508327 : MOUSE_CLICKED should only go to the recipient of
4479 // the accompanying MOUSE_PRESSED, so don't reset mouseEventTarget on a
4480 // MOUSE_CLICKED.
4481 if (!isMouseGrab(e) && id != MouseEvent.MOUSE_CLICKED) {
4482 mouseEventTarget = (mouseOver != nativeContainer) ? mouseOver: null;
4483 }
4484
4485 if (mouseEventTarget != null) {
4486 switch (id) {
4487 case MouseEvent.MOUSE_ENTERED:
4488 case MouseEvent.MOUSE_EXITED:
4489 break;
4490 case MouseEvent.MOUSE_PRESSED:
4491 retargetMouseEvent(mouseEventTarget, id, e);
4492 break;
4493 case MouseEvent.MOUSE_RELEASED:
4494 retargetMouseEvent(mouseEventTarget, id, e);
4495 break;
4496 case MouseEvent.MOUSE_CLICKED:
4497 // 4508327: MOUSE_CLICKED should never be dispatched to a Component
4498 // other than that which received the MOUSE_PRESSED event. If the
4499 // mouse is now over a different Component, don't dispatch the event.
4500 // The previous fix for a similar problem was associated with bug
4501 // 4155217.
4502 if (mouseOver == mouseEventTarget) {
4510 if (isMouseGrab(e)) {
4511 retargetMouseEvent(mouseEventTarget, id, e);
4512 }
4513 break;
4514 case MouseEvent.MOUSE_WHEEL:
4515 // This may send it somewhere that doesn't have MouseWheelEvents
4516 // enabled. In this case, Component.dispatchEventImpl() will
4517 // retarget the event to a parent that DOES have the events enabled.
4518 if (eventLog.isLoggable(PlatformLogger.FINEST) && (mouseOver != null)) {
4519 eventLog.finest("retargeting mouse wheel to " +
4520 mouseOver.getName() + ", " +
4521 mouseOver.getClass());
4522 }
4523 retargetMouseEvent(mouseOver, id, e);
4524 break;
4525 }
4526 //Consuming of wheel events is implemented in "retargetMouseEvent".
4527 if (id != MouseEvent.MOUSE_WHEEL) {
4528 e.consume();
4529 }
4530 }
4531 return e.isConsumed();
4532 }
4533
4534 private boolean processDropTargetEvent(SunDropTargetEvent e) {
4535 int id = e.getID();
4536 int x = e.getX();
4537 int y = e.getY();
4538
4539 /*
4540 * Fix for BugTraq ID 4395290.
4541 * It is possible that SunDropTargetEvent's Point is outside of the
4542 * native container bounds. In this case we truncate coordinates.
4543 */
4544 if (!nativeContainer.contains(x, y)) {
4545 final Dimension d = nativeContainer.getSize();
4546 if (d.width <= x) {
4547 x = d.width - 1;
4548 } else if (x < 0) {
4549 x = 0;
4853
4854 /**
4855 * This variable is not used, but kept for serialization compatibility
4856 */
4857 private Component focus;
4858
4859 /**
4860 * The current subcomponent being hosted by this windowed
4861 * component that has events being forwarded to it. If this
4862 * is null, there are currently no events being forwarded to
4863 * a subcomponent.
4864 */
4865 private transient Component mouseEventTarget;
4866
4867 /**
4868 * The last component entered
4869 */
4870 private transient Component targetLastEntered;
4871
4872 /**
4873 * Is the mouse over the native container
4874 */
4875 private transient boolean isMouseInNativeContainer = false;
4876
4877 /**
4878 * This variable is not used, but kept for serialization compatibility
4879 */
4880 private Cursor nativeCursor;
4881
4882 /**
4883 * The event mask for contained lightweight components. Lightweight
4884 * components need a windowed container to host window-related
4885 * events. This separate mask indicates events that have been
4886 * requested by contained lightweight components without effecting
4887 * the mask of the windowed component itself.
4888 */
4889 private long eventMask;
4890
4891 /**
4892 * The kind of events routed to lightweight components from windowed
4893 * hosts.
4894 */
4895 private static final long PROXY_EVENT_MASK =
4896 AWTEvent.FOCUS_EVENT_MASK |
4897 AWTEvent.KEY_EVENT_MASK |
4898 AWTEvent.MOUSE_EVENT_MASK |
4899 AWTEvent.MOUSE_MOTION_EVENT_MASK |
4900 AWTEvent.MOUSE_WHEEL_EVENT_MASK;
4901
4902 private static final long MOUSE_MASK =
4903 AWTEvent.MOUSE_EVENT_MASK |
4904 AWTEvent.MOUSE_MOTION_EVENT_MASK |
4905 AWTEvent.MOUSE_WHEEL_EVENT_MASK;
4906 }
|
3289 }
3290 }
3291 }
3292 }
3293
3294 if (reset) {
3295 KeyboardFocusManager.setMostRecentFocusOwner(window, null);
3296 }
3297 }
3298
3299 void clearCurrentFocusCycleRootOnHide() {
3300 KeyboardFocusManager kfm =
3301 KeyboardFocusManager.getCurrentKeyboardFocusManager();
3302 Container cont = kfm.getCurrentFocusCycleRoot();
3303
3304 if (cont == this || isParentOf(cont)) {
3305 kfm.setGlobalCurrentFocusCycleRootPriv(null);
3306 }
3307 }
3308
3309 @Override
3310 void clearLightweightDispatcherOnRemove(Component removedComponent) {
3311 if (dispatcher != null) {
3312 dispatcher.removeReferences(removedComponent);
3313 } else {
3314 //It is a Lightweight Container, should clear parent`s Dispatcher
3315 super.clearLightweightDispatcherOnRemove(removedComponent);
3316 }
3317 }
3318
3319 final Container getTraversalRoot() {
3320 if (isFocusCycleRoot()) {
3321 return findTraversalRoot();
3322 }
3323
3324 return super.getTraversalRoot();
3325 }
3326
3327 /**
3328 * Sets the focus traversal policy that will manage keyboard traversal of
3329 * this Container's children, if this Container is a focus cycle root. If
3330 * the argument is null, this Container inherits its policy from its focus-
3331 * cycle-root ancestor. If the argument is non-null, this policy will be
3332 * inherited by all focus-cycle-root children that have no keyboard-
3333 * traversal policy of their own (as will, recursively, their focus-cycle-
3334 * root children).
3335 * <p>
3336 * If this Container is not a focus cycle root, the policy will be
3337 * remembered, but will not be used or inherited by this or any other
3338 * Containers until this Container is made a focus cycle root.
4382 * container
4383 */
4384 private static final int LWD_MOUSE_DRAGGED_OVER = 1500;
4385
4386 private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.LightweightDispatcher");
4387
4388 LightweightDispatcher(Container nativeContainer) {
4389 this.nativeContainer = nativeContainer;
4390 mouseEventTarget = null;
4391 eventMask = 0;
4392 }
4393
4394 /*
4395 * Clean up any resources allocated when dispatcher was created;
4396 * should be called from Container.removeNotify
4397 */
4398 void dispose() {
4399 //System.out.println("Disposing lw dispatcher");
4400 stopListeningForOtherDrags();
4401 mouseEventTarget = null;
4402 targetLastEntered = null;
4403 }
4404
4405 /**
4406 * Enables events to subcomponents.
4407 */
4408 void enableEvents(long events) {
4409 eventMask |= events;
4410 }
4411
4412 /**
4413 * Dispatches an event to a sub-component if necessary, and
4414 * returns whether or not the event was forwarded to a
4415 * sub-component.
4416 *
4417 * @param e the event
4418 */
4419 boolean dispatchEvent(AWTEvent e) {
4420 boolean ret = false;
4421
4422 /*
4474 /**
4475 * This method attempts to distribute a mouse event to a lightweight
4476 * component. It tries to avoid doing any unnecessary probes down
4477 * into the component tree to minimize the overhead of determining
4478 * where to route the event, since mouse movement events tend to
4479 * come in large and frequent amounts.
4480 */
4481 private boolean processMouseEvent(MouseEvent e) {
4482 int id = e.getID();
4483 Component mouseOver = // sensitive to mouse events
4484 nativeContainer.getMouseEventTarget(e.getX(), e.getY(),
4485 Container.INCLUDE_SELF);
4486
4487 trackMouseEnterExit(mouseOver, e);
4488
4489 // 4508327 : MOUSE_CLICKED should only go to the recipient of
4490 // the accompanying MOUSE_PRESSED, so don't reset mouseEventTarget on a
4491 // MOUSE_CLICKED.
4492 if (!isMouseGrab(e) && id != MouseEvent.MOUSE_CLICKED) {
4493 mouseEventTarget = (mouseOver != nativeContainer) ? mouseOver: null;
4494 isCleaned = false;
4495 }
4496
4497 if (mouseEventTarget != null) {
4498 switch (id) {
4499 case MouseEvent.MOUSE_ENTERED:
4500 case MouseEvent.MOUSE_EXITED:
4501 break;
4502 case MouseEvent.MOUSE_PRESSED:
4503 retargetMouseEvent(mouseEventTarget, id, e);
4504 break;
4505 case MouseEvent.MOUSE_RELEASED:
4506 retargetMouseEvent(mouseEventTarget, id, e);
4507 break;
4508 case MouseEvent.MOUSE_CLICKED:
4509 // 4508327: MOUSE_CLICKED should never be dispatched to a Component
4510 // other than that which received the MOUSE_PRESSED event. If the
4511 // mouse is now over a different Component, don't dispatch the event.
4512 // The previous fix for a similar problem was associated with bug
4513 // 4155217.
4514 if (mouseOver == mouseEventTarget) {
4522 if (isMouseGrab(e)) {
4523 retargetMouseEvent(mouseEventTarget, id, e);
4524 }
4525 break;
4526 case MouseEvent.MOUSE_WHEEL:
4527 // This may send it somewhere that doesn't have MouseWheelEvents
4528 // enabled. In this case, Component.dispatchEventImpl() will
4529 // retarget the event to a parent that DOES have the events enabled.
4530 if (eventLog.isLoggable(PlatformLogger.FINEST) && (mouseOver != null)) {
4531 eventLog.finest("retargeting mouse wheel to " +
4532 mouseOver.getName() + ", " +
4533 mouseOver.getClass());
4534 }
4535 retargetMouseEvent(mouseOver, id, e);
4536 break;
4537 }
4538 //Consuming of wheel events is implemented in "retargetMouseEvent".
4539 if (id != MouseEvent.MOUSE_WHEEL) {
4540 e.consume();
4541 }
4542 } else if (isCleaned && id != MouseEvent.MOUSE_WHEEL) {
4543 //After mouseEventTarget was removed and cleaned should consume all events
4544 //until new mouseEventTarget is found
4545 e.consume();
4546 }
4547 return e.isConsumed();
4548 }
4549
4550 private boolean processDropTargetEvent(SunDropTargetEvent e) {
4551 int id = e.getID();
4552 int x = e.getX();
4553 int y = e.getY();
4554
4555 /*
4556 * Fix for BugTraq ID 4395290.
4557 * It is possible that SunDropTargetEvent's Point is outside of the
4558 * native container bounds. In this case we truncate coordinates.
4559 */
4560 if (!nativeContainer.contains(x, y)) {
4561 final Dimension d = nativeContainer.getSize();
4562 if (d.width <= x) {
4563 x = d.width - 1;
4564 } else if (x < 0) {
4565 x = 0;
4869
4870 /**
4871 * This variable is not used, but kept for serialization compatibility
4872 */
4873 private Component focus;
4874
4875 /**
4876 * The current subcomponent being hosted by this windowed
4877 * component that has events being forwarded to it. If this
4878 * is null, there are currently no events being forwarded to
4879 * a subcomponent.
4880 */
4881 private transient Component mouseEventTarget;
4882
4883 /**
4884 * The last component entered
4885 */
4886 private transient Component targetLastEntered;
4887
4888 /**
4889 * Indicates whether {@code mouseEventTarget} was removed and nulled
4890 */
4891 private transient boolean isCleaned;
4892
4893 /**
4894 * Is the mouse over the native container
4895 */
4896 private transient boolean isMouseInNativeContainer = false;
4897
4898 /**
4899 * This variable is not used, but kept for serialization compatibility
4900 */
4901 private Cursor nativeCursor;
4902
4903 /**
4904 * The event mask for contained lightweight components. Lightweight
4905 * components need a windowed container to host window-related
4906 * events. This separate mask indicates events that have been
4907 * requested by contained lightweight components without effecting
4908 * the mask of the windowed component itself.
4909 */
4910 private long eventMask;
4911
4912 /**
4913 * The kind of events routed to lightweight components from windowed
4914 * hosts.
4915 */
4916 private static final long PROXY_EVENT_MASK =
4917 AWTEvent.FOCUS_EVENT_MASK |
4918 AWTEvent.KEY_EVENT_MASK |
4919 AWTEvent.MOUSE_EVENT_MASK |
4920 AWTEvent.MOUSE_MOTION_EVENT_MASK |
4921 AWTEvent.MOUSE_WHEEL_EVENT_MASK;
4922
4923 private static final long MOUSE_MASK =
4924 AWTEvent.MOUSE_EVENT_MASK |
4925 AWTEvent.MOUSE_MOTION_EVENT_MASK |
4926 AWTEvent.MOUSE_WHEEL_EVENT_MASK;
4927
4928 void removeReferences(Component removedComponent) {
4929 if (mouseEventTarget == removedComponent) {
4930 isCleaned = true;
4931 mouseEventTarget = null;
4932 }
4933 if (targetLastEntered == removedComponent) {
4934 targetLastEntered = null;
4935 }
4936 }
4937 }
|