01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.ui.impl;
17:
18: import com.google.gwt.core.client.JavaScriptObject;
19: import com.google.gwt.user.client.Element;
20:
21: /**
22: * Safari-specific implementation of {@link FocusImpl} that creates a completely
23: * transparent hidden element, since Safari will not keyboard focus on an input
24: * element that has zero width and height.
25: */
26: public class FocusImplSafari extends FocusImplOld {
27:
28: @Override
29: public native void blur(Element elem) /*-{
30: // Attempts to blur elements from within an event callback will generally
31: // be unsuccessful, so we invoke blur() from outside of the callback.
32: $wnd.setTimeout(function() {
33: elem.firstChild.blur();
34: }, 0);
35: }-*/;
36:
37: @Override
38: public native void focus(Element elem) /*-{
39: // Attempts to focus elements from within an event callback will generally
40: // be unsuccessful, so we invoke focus() from outside of the callback.
41: $wnd.setTimeout(function() {
42: elem.firstChild.focus();
43: }, 0);
44: }-*/;
45:
46: @Override
47: protected native Element createHiddenInput() /*-{
48: var input = $doc.createElement('input');
49: input.type = 'text';
50: input.style.opacity = 0;
51: input.style.zIndex = -1;
52: input.style.height = '1px';
53: input.style.width = '1px';
54: input.style.overflow = 'hidden';
55: input.style.position = 'absolute';
56: return input;
57: }-*/;
58:
59: @Override
60: protected native JavaScriptObject createMouseHandler() /*-{
61: return function() {
62: // This function is called directly as an event handler, so 'this' is
63: // set up by the browser to be the div on which the event is fired.
64: var firstChild = this.firstChild;
65:
66: // Attempts to focus elements from within an event callback will generally
67: // be unsuccessful, so we invoke focus() from outside of the callback.
68: $wnd.setTimeout(function() {
69: firstChild.focus();
70: }, 0);
71: }
72: }-*/;
73:
74: }
|