Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
314 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
val getTabIndex : DOMTypes.element -> int | ||
val focus : DOMTypes.element -> unit | ||
val blur : DOMTypes.element -> unit | ||
val setTabIndex : DOMTypes.element -> int -> unit | ||
(* | ||
* This file is part of ojox, a library for web browser programming | ||
* Copyright (C) 2009 Jacob Donham | ||
* Original file (user/src/com/google/gwt/event/user/client/ui/impl/FocusImpl.java | ||
* in the GWT source distribution) is Copyright 2009 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*) | ||
|
||
open DOMTypes | ||
|
||
(** | ||
Implementation interface for creating and manipulating focusable elements | ||
that aren't naturally focusable in all browsers, such as DIVs. | ||
*) | ||
val blur : element -> unit | ||
val createFocusable : unit -> element | ||
val focus : element -> unit | ||
val getTabIndex : element -> int | ||
val setAccessKey : element -> char -> unit | ||
val setTabIndex : element -> int -> unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(* | ||
* This file is part of ojox, a library for web browser programming | ||
* Copyright (C) 2009 Jacob Donham | ||
* Original file (user/src/com/google/gwt/event/user/client/ui/impl/FocusImpl.java | ||
* in the GWT source distribution) is Copyright 2009 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*) | ||
|
||
open Ocamljs.Inline | ||
|
||
let blur = Element.blur | ||
|
||
let createFocusable () = | ||
let e = Document.createDivElement (Document.get ()) in | ||
Element.setTabIndex e 0; | ||
e | ||
|
||
let focus = Element.focus | ||
|
||
let getTabIndex = Element.getTabIndex | ||
|
||
let setAccessKey elem key = <:stmt< $elem$.accessKey = String.fromCharCode($key$); >> | ||
|
||
let setTabIndex = Element.setTabIndex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(* | ||
* This file is part of ojox, a library for web browser programming | ||
* Copyright (C) 2009 Jacob Donham | ||
* Original file (user/src/com/google/gwt/event/user/client/ui/impl/FocusImpl.java | ||
* in the GWT source distribution) is Copyright 2009 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*) | ||
|
||
include FocusImplSafari |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(* | ||
* This file is part of ojox, a library for web browser programming | ||
* Copyright (C) 2009 Jacob Donham | ||
* Original file (user/src/com/google/gwt/event/user/client/ui/impl/FocusImpl.java | ||
* in the GWT source distribution) is Copyright 2009 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*) | ||
|
||
open DOMTypes | ||
|
||
(** | ||
Implementation interface for creating and manipulating focusable elements | ||
that aren't naturally focusable in all browsers, such as DIVs. | ||
*) | ||
(** | ||
Returns the focus implementation class for creating and manipulating | ||
focusable elements that aren't naturally focusable in all browsers, such as | ||
DIVs. | ||
*) | ||
val blur : element -> unit | ||
val createFocusable : unit -> element | ||
val focus : element -> unit | ||
val getTabIndex : element -> int | ||
val setAccessKey : element -> char -> unit | ||
val setTabIndex : element -> int -> unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(* | ||
* This file is part of ojox, a library for web browser programming | ||
* Copyright (C) 2009 Jacob Donham | ||
* Original file (user/src/com/google/gwt/event/user/client/ui/impl/FocusImpl.java | ||
* in the GWT source distribution) is Copyright 2009 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*) | ||
|
||
include FocusImplAbstract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(* | ||
* This file is part of ojox, a library for web browser programming | ||
* Copyright (C) 2009 Jacob Donham | ||
* Original file (user/src/com/google/gwt/event/user/client/ui/impl/FocusImpl.java | ||
* in the GWT source distribution) is Copyright 2009 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*) | ||
|
||
open DOMTypes | ||
|
||
(** | ||
Implementation interface for creating and manipulating focusable elements | ||
that aren't naturally focusable in all browsers, such as DIVs. | ||
*) | ||
(** | ||
Returns the focus implementation class for manipulating focusable elements | ||
that are naturally focusable in all browsers, such as text boxes. | ||
*) | ||
val blur : element -> unit | ||
val createFocusable : unit -> element | ||
val focus : element -> unit | ||
val getTabIndex : element -> int | ||
val setAccessKey : element -> char -> unit | ||
val setTabIndex : element -> int -> unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(* | ||
* This file is part of ojox, a library for web browser programming | ||
* Copyright (C) 2009 Jacob Donham | ||
* Original file (user/src/com/google/gwt/event/user/client/ui/impl/FocusImplSafari.java | ||
* in the GWT source distribution) is Copyright 2009 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*) | ||
|
||
(** | ||
Safari-specific implementation of {@link FocusImpl} that creates a completely | ||
transparent hidden element, since Safari will not keyboard focus on an input | ||
element that has zero width and height. | ||
*) | ||
|
||
open Ocamljs.Inline | ||
|
||
include FocusImplStandard | ||
|
||
let blur elem = <:stmt< | ||
// Attempts to blur elements from within an event callback will generally | ||
// be unsuccessful, so we invoke blur() from outside of the callback. | ||
$$wnd.setTimeout(function() { | ||
$elem$.blur(); | ||
}, 0); | ||
>> | ||
|
||
let focus elem = <:stmt< | ||
// Attempts to focus elements from within an event callback will generally | ||
// be unsuccessful, so we invoke focus() from outside of the callback. | ||
$$wnd.setTimeout(function() { | ||
$elem$.focus(); | ||
}, 0); | ||
>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
(* | ||
* This file is part of ojox, a library for web browser programming | ||
* Copyright (C) 2009 Jacob Donham | ||
* Original file (user/src/com/google/gwt/event/user/client/ui/impl/FocusImplStandard.java | ||
* in the GWT source distribution) is Copyright 2009 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*) | ||
|
||
open Ocamljs.Inline | ||
|
||
include FocusImplAbstract | ||
|
||
(** | ||
Implementation of {@link com.google.gwt.user.client.ui.impl.FocusImpl} that | ||
uses a hidden input element to serve as a 'proxy' for accesskeys, which are | ||
only supported on form elements in most browsers. | ||
*) | ||
|
||
let focusHandler = << | ||
function(evt) { | ||
// This function is called directly as an event handler, so 'this' is | ||
// set up by the browser to be the input on which the event is fired. We | ||
// call focus() in a timeout or the element may be blurred when this event | ||
// ends. | ||
var div = this.parentNode; | ||
if (div.onfocus) { | ||
$$wnd.setTimeout(function() { | ||
div.focus(); | ||
}, 0); | ||
} | ||
} | ||
>> | ||
|
||
let createFocusable () = <:rstmt< | ||
// Divs are focusable in all browsers, but only IE supports the accessKey | ||
// property on divs. We use the infamous 'hidden input' trick to add an | ||
// accessKey to the focusable div. Note that the input is only used to | ||
// capture focus when the accessKey is pressed. Focus is forwarded to the | ||
// div immediately. | ||
var div = $$doc.createElement('div'); | ||
div.tabIndex = 0; | ||
|
||
var input = $$doc.createElement('input'); | ||
input.type = 'text'; | ||
input.tabIndex = -1; | ||
input.style.opacity = 0; | ||
input.style.height = '1px'; | ||
input.style.width = '1px'; | ||
input.style.zIndex = -1; | ||
input.style.overflow = 'hidden'; | ||
input.style.position = 'absolute'; | ||
|
||
// Note that we're using isolated lambda methods as the event listeners | ||
// to avoid creating a memory leaks. (Lambdas here would create cycles | ||
// involving the div and input). This also allows us to share a single | ||
// set of handlers among every focusable item. | ||
input.addEventListener( | ||
'focus', | ||
$focusHandler$, | ||
false); | ||
|
||
div.appendChild(input); | ||
return div; | ||
>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters