KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > impl > FocusImplSafari


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.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   public native void blur(Element elem) /*-{
29     // Attempts to blur elements from within an event callback will generally
30     // be unsuccessful, so we invoke blur() from outside of the callback.
31     $wnd.setTimeout(function() {
32       elem.firstChild.blur();
33     }, 0);
34   }-*/
;
35
36   public native void focus(Element elem) /*-{
37     // Attempts to focus elements from within an event callback will generally
38     // be unsuccessful, so we invoke focus() from outside of the callback.
39     $wnd.setTimeout(function() {
40       elem.firstChild.focus();
41     }, 0);
42   }-*/
;
43
44   protected native Element createHiddenInput() /*-{
45     var input = $doc.createElement('input');
46     input.type = 'text';
47     input.style.opacity = 0;
48     input.style.zIndex = -1;
49     input.style.position = 'absolute';
50     return input;
51   }-*/
;
52
53   protected native JavaScriptObject createMouseHandler() /*-{
54     return function() {
55       // This function is called directly as an event handler, so 'this' is
56       // set up by the browser to be the div on which the event is fired.
57       var firstChild = this.firstChild;
58
59       // Attempts to focus elements from within an event callback will generally
60       // be unsuccessful, so we invoke focus() from outside of the callback.
61       $wnd.setTimeout(function() {
62         firstChild.focus();
63       }, 0);
64     }
65   }-*/
;
66
67 }
68
Popular Tags