|
13 | 13 |
|
14 | 14 | package org.eclipse.swt.internal.browser; |
15 | 15 |
|
| 16 | +import org.eclipse.swt.SWT; |
16 | 17 | import org.eclipse.swt.graphics.Point; |
17 | 18 | import org.eclipse.swt.internal.xhtml.CSSStyle; |
18 | 19 | import org.eclipse.swt.internal.xhtml.Element; |
@@ -425,20 +426,86 @@ public static Point getStringStyledSize(String str, String className, String css |
425 | 426 | return new Point(getContainerWidth(c), getContainerHeight(c)); |
426 | 427 | } |
427 | 428 |
|
428 | | - static public Point getElementPositionInShell(Element elem, Element shellElem){ |
429 | | - Element currentElem = elem; |
| 429 | + public static Point calcuateRelativePosition(Element el, Element relativeEl){ |
| 430 | + Element currentEl = el; |
430 | 431 | int left = 0; |
431 | 432 | int top = 0; |
432 | | - while (currentElem != null && currentElem != shellElem) { |
433 | | - left += currentElem.offsetLeft; |
434 | | - top += currentElem.offsetTop; |
435 | | - currentElem = currentElem.offsetParent; |
| 433 | + while (currentEl != null && currentEl != relativeEl) { |
| 434 | + left += currentEl.offsetLeft; |
| 435 | + top += currentEl.offsetTop; |
| 436 | + currentEl = currentEl.offsetParent; |
436 | 437 | } |
437 | | -// System.out.println(getShell().she) |
438 | 438 | if(isFirefox){ |
| 439 | + // why? |
439 | 440 | left += 6; |
440 | 441 | top += 2; |
441 | 442 | } |
442 | | - return new Point(left, top + OS.getContainerHeight(elem)); |
| 443 | + return new Point(left, top + OS.getContainerHeight(el)); |
443 | 444 | } |
| 445 | + |
| 446 | + public static void updateArrowSize(Object el, int style, int cx, int cy) { |
| 447 | + int xx = Math.min(cx, cy) / 3; |
| 448 | + final CSSStyle s = ((Element) el).style; |
| 449 | + s.borderWidth = (xx > 0 ? xx : 0) + "px"; |
| 450 | + if ((style & SWT.LEFT) != 0) { |
| 451 | + s.borderLeftWidth = "0"; |
| 452 | + } else if ((style & SWT.RIGHT) != 0) { |
| 453 | + s.borderRightWidth = "0"; |
| 454 | + } else if ((style & SWT.UP) != 0) { |
| 455 | + s.borderTopWidth = "0"; |
| 456 | + } else if ((style & SWT.DOWN) != 0) { |
| 457 | + if (xx > 1) { |
| 458 | + s.borderWidth = (xx - 1) + "px"; |
| 459 | + } |
| 460 | + s.borderBottomWidth = "0"; |
| 461 | + } else { |
| 462 | + s.borderTopWidth = "0"; |
| 463 | + } |
| 464 | + int x = cy / 6; |
| 465 | + xx = cy / 3; |
| 466 | + s.position = "relative"; |
| 467 | + if ((style & (SWT.RIGHT | SWT.LEFT)) != 0) { |
| 468 | + s.top = (x - 3) + "px"; |
| 469 | + if ((style & SWT.RIGHT) != 0) { |
| 470 | + s.left = "1px"; |
| 471 | + } |
| 472 | + } else { |
| 473 | + if ((style & SWT.UP) != 0) { |
| 474 | + s.top = (xx - 3)+ "px"; |
| 475 | + } else if ((style & SWT.DOWN) != 0) { |
| 476 | + s.top = (xx - 2)+ "px"; |
| 477 | + } |
| 478 | + } |
| 479 | + /** |
| 480 | + * TODO: Get rid of these nasty position things! |
| 481 | + */ |
| 482 | + if (OS.isMozilla && !OS.isFirefox) { |
| 483 | + if ((style & SWT.UP) != 0) { |
| 484 | + s.left = "-2px"; |
| 485 | + } else if ((style & SWT.DOWN) != 0) { |
| 486 | + s.left = "-1px"; |
| 487 | + } |
| 488 | + } |
| 489 | + if (OS.isFirefox) { |
| 490 | + if ((style & (SWT.RIGHT | SWT.LEFT)) != 0) { |
| 491 | + s.top = "-2px"; |
| 492 | + if ((style & SWT.RIGHT) != 0) { |
| 493 | + s.left = "1px"; |
| 494 | + } |
| 495 | + } else { |
| 496 | + if ((style & SWT.UP) != 0) { |
| 497 | + if (Math.min(cx, cy) <= 12) { |
| 498 | + s.left = "-1px"; |
| 499 | + } else { |
| 500 | + s.left = "-2px"; |
| 501 | + } |
| 502 | + s.top = "-1px"; |
| 503 | + } else if ((style & SWT.DOWN) != 0) { |
| 504 | + s.left = "-1px"; |
| 505 | + s.top = "-1px"; |
| 506 | + } |
| 507 | + } |
| 508 | + } |
| 509 | + } |
| 510 | + |
444 | 511 | } |
0 commit comments