KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > impl > DOMImplSafari


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.user.client.impl;
17
18 import com.google.gwt.user.client.Element;
19 import com.google.gwt.user.client.Event;
20
21 /**
22  * Safari implementation of {@link com.google.gwt.user.client.impl.DOMImpl}.
23  */

24 class DOMImplSafari extends DOMImplStandard {
25   public native int eventGetClientX(Event evt) /*-{
26     // In Safari2: clientX is wrong and pageX is returned instead.
27     return evt.pageX - $doc.body.scrollLeft;
28   }-*/
;
29
30   public native int eventGetClientY(Event evt) /*-{
31     // In Safari2: clientY is wrong and pageY is returned instead.
32     return evt.pageY - $doc.body.scrollTop;
33   }-*/
;
34
35   public native int eventGetMouseWheelVelocityY(Event evt) /*-{
36     return Math.round(-evt.wheelDelta / 40);
37   }-*/
;
38
39   public native int getAbsoluteLeft(Element elem) /*-{
40     // Unattached elements and elements (or their ancestors) with style
41     // 'display: none' have no offsetLeft.
42     if (elem.offsetLeft == null) {
43       return 0;
44     }
45
46     var left = 0;
47     var curr = elem;
48     // This intentionally excludes body which has a null offsetParent.
49     while (curr.offsetParent) {
50       left -= curr.scrollLeft;
51       curr = curr.parentNode;
52     }
53     while (elem) {
54       left += elem.offsetLeft;
55
56       // Safari bug: a top-level absolutely positioned element includes the
57       // body's offset position already.
58       var parent = elem.offsetParent;
59       if (parent && (parent.tagName == 'BODY') &&
60           (elem.style.position == 'absolute')) {
61         break;
62       }
63
64       elem = parent;
65     }
66     return left;
67   }-*/
;
68
69   public native int getAbsoluteTop(Element elem) /*-{
70     // Unattached elements and elements (or their ancestors) with style
71     // 'display: none' have no offsetTop.
72     if (elem.offsetTop == null) {
73       return 0;
74     }
75
76     var top = 0;
77     var curr = elem;
78     // This intentionally excludes body which has a null offsetParent.
79     while (curr.offsetParent) {
80       top -= curr.scrollTop;
81       curr = curr.parentNode;
82     }
83     while (elem) {
84       top += elem.offsetTop;
85
86       // Safari bug: a top-level absolutely positioned element includes the
87       // body's offset position already.
88       var parent = elem.offsetParent;
89       if (parent && (parent.tagName == 'BODY') &&
90           (elem.style.position == 'absolute')) {
91         break;
92       }
93
94       elem = parent;
95     }
96     return top;
97   }-*/
;
98 }
99
Popular Tags