001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.user.client.impl;
017:
018: import com.google.gwt.user.client.Element;
019: import com.google.gwt.user.client.Event;
020:
021: /**
022: * Safari implementation of {@link com.google.gwt.user.client.impl.DOMImpl}.
023: */
024: class DOMImplSafari extends DOMImplStandard {
025: @Override
026: public native int eventGetClientX(Event evt) /*-{
027: // In Safari2: clientX is wrong and pageX is returned instead.
028: return evt.pageX - $doc.body.scrollLeft || -1;
029: }-*/;
030:
031: @Override
032: public native int eventGetClientY(Event evt) /*-{
033: // In Safari2: clientY is wrong and pageY is returned instead.
034: return evt.pageY - $doc.body.scrollTop || -1;
035: }-*/;
036:
037: @Override
038: public native int eventGetMouseWheelVelocityY(Event evt) /*-{
039: return Math.round(-evt.wheelDelta / 40) || -1;
040: }-*/;
041:
042: @Override
043: public native int getAbsoluteLeft(Element elem) /*-{
044: // Unattached elements and elements (or their ancestors) with style
045: // 'display: none' have no offsetLeft.
046: if (elem.offsetLeft == null) {
047: return 0;
048: }
049:
050: var left = 0;
051: var curr = elem.parentNode;
052: if (curr) {
053: // This intentionally excludes body which has a null offsetParent.
054: while (curr.offsetParent) {
055: left -= curr.scrollLeft;
056: curr = curr.parentNode;
057: }
058: }
059:
060: while (elem) {
061: left += elem.offsetLeft;
062:
063: // Safari bug: a top-level absolutely positioned element includes the
064: // body's offset position already.
065: var parent = elem.offsetParent;
066: if (parent && (parent.tagName == 'BODY') &&
067: (elem.style.position == 'absolute')) {
068: break;
069: }
070:
071: elem = parent;
072: }
073: return left;
074: }-*/;
075:
076: @Override
077: public native int getAbsoluteTop(Element elem) /*-{
078: // Unattached elements and elements (or their ancestors) with style
079: // 'display: none' have no offsetTop.
080: if (elem.offsetTop == null) {
081: return 0;
082: }
083:
084: var top = 0;
085: var curr = elem.parentNode;
086: if (curr) {
087: // This intentionally excludes body which has a null offsetParent.
088: while (curr.offsetParent) {
089: top -= curr.scrollTop;
090: curr = curr.parentNode;
091: }
092: }
093:
094: while (elem) {
095: top += elem.offsetTop;
096:
097: // Safari bug: a top-level absolutely positioned element includes the
098: // body's offset position already.
099: var parent = elem.offsetParent;
100: if (parent && (parent.tagName == 'BODY') &&
101: (elem.style.position == 'absolute')) {
102: break;
103: }
104:
105: elem = parent;
106: }
107: return top;
108: }-*/;
109:
110: @Override
111: public native void insertListItem(Element select, String text,
112: String value, int index) /*-{
113: // We can't use the 'options' array due to a bug in Safari.
114: // Read the comment above com.google.gwt.user.client.ui.ListBox.ImplSafari
115: // for more information.
116: var newOption = new Option(text, value);
117: if (index == -1 || index > select.children.length - 1) {
118: select.appendChild(newOption);
119: } else{
120: select.insertBefore(newOption, select.children[index]);
121: }
122: }-*/;
123:
124: /**
125: * Gets the height of the browser window's client area excluding the
126: * scroll bar.
127: *
128: * @return the window's client height
129: */
130: @Override
131: public native int windowGetClientHeight() /*-{
132: return $wnd.innerHeight;
133: }-*/;
134:
135: /**
136: * Gets the width of the browser window's client area excluding the
137: * vertical scroll bar.
138: *
139: * @return the window's client width
140: */
141: @Override
142: public native int windowGetClientWidth() /*-{
143: return $wnd.innerWidth;
144: }-*/;
145: }
|