Skip to content
This repository
Browse code

Merge pull request #95 from blackberry-webworks/next

The "next" branch for 2.3.1
  • Loading branch information...
commit dcdc5d04d81c3e5bb4fb30b9b5924f0bf0643277 2 parents 1885747 + 93368b7
authored February 21, 2012
2  api/dialog/src/main/java/blackberry/ui/dialog/ColorPickerAsyncFunction.java
@@ -41,7 +41,7 @@ public Object execute( Object thiz, Object[] args ) throws Exception {
41 41
         ScriptableFunction callback = (ScriptableFunction) args[ 1 ];
42 42
 
43 43
         // create dialog
44  
-        Runnable dr = DialogRunnableFactory.getColorPickerRunnable( initialColor, callback, thiz );
  44
+        Runnable dr = DialogRunnableFactory.getColorPickerRunnable( initialColor, callback );
45 45
 
46 46
         // queue
47 47
         UiApplication.getUiApplication().invokeLater( dr );
79  api/dialog/src/main/java/blackberry/ui/dialog/CustomAskAsyncFunction.java
... ...
@@ -0,0 +1,79 @@
  1
+/*
  2
+* Copyright 2010-2011 Research In Motion Limited.
  3
+*
  4
+* Licensed under the Apache License, Version 2.0 (the "License");
  5
+* you may not use this file except in compliance with the License.
  6
+* You may obtain a copy of 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,
  12
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13
+* See the License for the specific language governing permissions and
  14
+* limitations under the License.
  15
+*/
  16
+package blackberry.ui.dialog;
  17
+
  18
+import net.rim.device.api.script.Scriptable;
  19
+import net.rim.device.api.script.ScriptableFunction;
  20
+import net.rim.device.api.ui.UiApplication;
  21
+import blackberry.core.FunctionSignature;
  22
+import blackberry.core.ScriptableFunctionBase;
  23
+
  24
+/**
  25
+ * Implementation of asynchronous custom ask function (blackberry.ui.dialog.customAskAsync)
  26
+ * 
  27
+ * @author dmateescu
  28
+ * 
  29
+ */
  30
+public class CustomAskAsyncFunction extends ScriptableFunctionBase {
  31
+
  32
+    public static final String NAME = "customAskAsync";
  33
+
  34
+    /**
  35
+     * @see blackberry.core.ScriptableFunctionBase#execute(Object, Object[])
  36
+     */
  37
+    public Object execute( Object thiz, Object[] args ) throws Exception {
  38
+        String message;
  39
+        String[] buttons;
  40
+        // the default value of the default choice. The developer cannot change it.
  41
+        final int defaultChoice = 0;
  42
+        // callback function
  43
+        ScriptableFunction callback = (ScriptableFunction) args[ 2 ];
  44
+        // the default value of the global status. The developer cannot change it.
  45
+        final boolean global = false;
  46
+        // message
  47
+        message = (String) args[ 0 ];
  48
+        // choices & values
  49
+        Scriptable stringArray = (Scriptable) args[ 1 ];
  50
+        int count = stringArray.getElementCount();
  51
+        buttons = new String[ count ];
  52
+        for( int i = 0; i < count; i++ ) {
  53
+            buttons[ i ] = stringArray.getElement( i ).toString();
  54
+        }
  55
+
  56
+        Runnable dr = DialogRunnableFactory.getCustomAskRunnable( message, buttons, defaultChoice, global, callback );
  57
+        // queue
  58
+        UiApplication.getUiApplication().invokeLater( dr );
  59
+        // return value
  60
+        return Scriptable.UNDEFINED;
  61
+    }
  62
+
  63
+
  64
+    /**
  65
+     * @see blackberry.core.ScriptableFunctionBase#getFunctionSignatures()
  66
+     */
  67
+    protected FunctionSignature[] getFunctionSignatures() {
  68
+        FunctionSignature fs = new FunctionSignature( 3 );
  69
+        // message
  70
+        fs.addParam( String.class, true );
  71
+        // choices
  72
+        fs.addParam( Scriptable.class, true );
  73
+        // callback
  74
+        fs.addParam( ScriptableFunction.class, true );
  75
+        // filler
  76
+        fs.addParam( Object.class, false );
  77
+        return new FunctionSignature[] { fs };
  78
+    }
  79
+}
2  api/dialog/src/main/java/blackberry/ui/dialog/DateTimeAsyncFunction.java
@@ -47,7 +47,7 @@ public Object execute(Object thiz, Object[] args) throws Exception {
47 47
         String min = (String)options.getField("min");
48 48
         String max = (String)options.getField("max");
49 49
         
50  
-        Runnable dr = DialogRunnableFactory.getDateTimeRunnable(type, value, min, max, callback, thiz);
  50
+        Runnable dr = DialogRunnableFactory.getDateTimeRunnable(type, value, min, max, callback);
51 51
         
52 52
         // queue
53 53
         UiApplication.getUiApplication().invokeLater(dr);
3  api/dialog/src/main/java/blackberry/ui/dialog/DialogNamespace.java
@@ -17,7 +17,6 @@
17 17
 
18 18
 import java.util.Hashtable;
19 19
 
20  
-import net.rim.device.api.script.ScriptEngine;
21 20
 import net.rim.device.api.script.Scriptable;
22 21
 import net.rim.device.api.ui.component.Dialog;
23 22
 
@@ -52,7 +51,9 @@ public DialogNamespace() {
52 51
         _fields = new Hashtable();
53 52
 
54 53
         _fields.put( StandardAskFunction.NAME, new StandardAskFunction() );
  54
+        _fields.put( StandardAskAsyncFunction.NAME, new StandardAskAsyncFunction());
55 55
         _fields.put( CustomAskFunction.NAME, new CustomAskFunction() );
  56
+        _fields.put(CustomAskAsyncFunction.NAME, new CustomAskAsyncFunction());
56 57
         _fields.put( SelectAsyncFunction.NAME, new SelectAsyncFunction() );
57 58
         _fields.put( DateTimeAsyncFunction.NAME, new DateTimeAsyncFunction() );
58 59
         _fields.put( ColorPickerAsyncFunction.NAME, new ColorPickerAsyncFunction() );
119  api/dialog/src/main/java/blackberry/ui/dialog/DialogRunnableFactory.java
@@ -18,37 +18,92 @@
18 18
 
19 19
 import java.util.Vector;
20 20
 
21  
-import net.rim.device.api.system.DeviceInfo;
22 21
 import net.rim.device.api.script.ScriptableFunction;
23 22
 import net.rim.device.api.script.ScriptableImpl;
24  
-
  23
+import net.rim.device.api.system.DeviceInfo;
  24
+import net.rim.device.api.ui.component.Dialog;
  25
+import blackberry.ui.dialog.color.ColorPickerDialog;
25 26
 import blackberry.ui.dialog.datetime.DateTimeDialog;
26  
-import blackberry.ui.dialog.IWebWorksDialog;
27 27
 import blackberry.ui.dialog.select.SelectDialog;
28  
-import blackberry.ui.dialog.color.ColorPickerDialog;
29 28
 
  29
+/**
  30
+ * Factory class for running dialogs asynchronously
  31
+ *
  32
+ */
30 33
 public class DialogRunnableFactory {
31 34
     
32  
-    public static Runnable getDateTimeRunnable( String type, String value, String min, String max, ScriptableFunction callback,
33  
-            Object thiz ) {
  35
+    /**
  36
+     * Factory method for running an asynchronous DateTime dialog
  37
+     * @param type the dialog's type
  38
+     * @param value the value
  39
+     * @param min the minimum value
  40
+     * @param max the maximum value
  41
+     * @param callback the callback function
  42
+     * @return the Runnable responsible for opening the dialog
  43
+     */
  44
+    public static Runnable getDateTimeRunnable( String type, String value, String min, String max, ScriptableFunction callback) {
34 45
         IWebWorksDialog d = new DateTimeDialog( type, value, min, max );
35  
-        return new DialogRunnable( d, callback, thiz );
  46
+        return new DialogRunnable( d, callback );
36 47
     }
37 48
 
38  
-    public static Runnable getColorPickerRunnable( int initialColor, ScriptableFunction callback, Object thiz ) {
  49
+    /**
  50
+     * Factory method for running an asynchronous ColorPicker dialog
  51
+     * @param initialColor the initial color
  52
+     * @param callback the callback function
  53
+     * @return the Runnable responsible for opening the dialog
  54
+     */
  55
+    public static Runnable getColorPickerRunnable( int initialColor, ScriptableFunction callback ) {
39 56
         ColorPickerDialog d = new ColorPickerDialog( initialColor );
40  
-        return new DialogRunnable( d, callback, thiz );
  57
+        return new DialogRunnable( d, callback );
41 58
     }
42 59
     
43  
-    public static Runnable getSelectRunnable(boolean allowMultiple, String[] labels, boolean[] enabled, boolean[] selected, int[] types, ScriptableFunction callback, Object thiz) {
  60
+    /**
  61
+     * Factory method for running an asynchronous Select dialog
  62
+     * @param allowMultiple flag indicating whether multiple values are allowed
  63
+     * @param labels the labels 
  64
+     * @param enabled the enabled values
  65
+     * @param selected the selected values
  66
+     * @param types the types of the values 
  67
+     * @param callback the callback function
  68
+     * @return the Runnable responsible for opening the dialog
  69
+     */
  70
+    public static Runnable getSelectRunnable(boolean allowMultiple, String[] labels, boolean[] enabled, boolean[] selected, int[] types, ScriptableFunction callback) {
44 71
         IWebWorksDialog d = new SelectDialog(allowMultiple, labels, enabled, selected, types);
45  
-        return new DialogRunnable(d, callback, thiz);
  72
+        return new DialogRunnable(d, callback);
  73
+    }
  74
+    
  75
+    /**
  76
+     * Factory method for running an asynchronous CustomAsk dialog
  77
+     * @param message the message to be displayed in the dialog
  78
+     * @param buttons the choices presented as buttons
  79
+     * @param values the values of the choices
  80
+     * @param defaultChoice the default choice
  81
+     * @param global the global status
  82
+     * @param callback the callback function
  83
+     * @return the Runnable responsible for opening the dialog
  84
+     */
  85
+    public static Runnable getCustomAskRunnable(String message, String[] buttons, int defaultChoice, boolean global /* style, false */, ScriptableFunction callback) {
  86
+        Dialog d = new Dialog( message, buttons, null, defaultChoice, null /* bitmap */, global ? Dialog.GLOBAL_STATUS : 0 /* style */);
  87
+        return new DialogAsyncRunnable( d, callback );
  88
+    }
  89
+    
  90
+    /**
  91
+     * Factory method for running an asynchronous StandardAsk dialog
  92
+     * @param message the message to be displayed in the dialog
  93
+     * @param type the dialog's type
  94
+     * @param defaultChoice
  95
+     * @param global the global status
  96
+     * @param callback the callback function
  97
+     * @return the Runnable responsible for running the dialog
  98
+     */
  99
+    public static Runnable getStandardAskRunnable(String message, int type, int defaultChoice, boolean global /* style, false */, ScriptableFunction callback) {
  100
+    	Dialog d = new Dialog( type, message, defaultChoice, null /* bitmap */, global ? Dialog.GLOBAL_STATUS : 0 /* style */);
  101
+        return new DialogAsyncRunnable(d, callback);
46 102
     }
47 103
     
48 104
     private static class DialogRunnable implements Runnable {
49 105
         private IWebWorksDialog _dialog;
50 106
         private ScriptableFunction _callback;
51  
-        private Object _context;
52 107
             
53 108
         /**
54 109
          * Constructs a <code>DialogRunnable</code> object.
@@ -57,13 +112,10 @@ public static Runnable getSelectRunnable(boolean allowMultiple, String[] labels,
57 112
          *            The dialog
58 113
          * @param callback
59 114
          *            The callback
60  
-         * @param context
61  
-         *            The context in which the callback executes (its "this" object)
62 115
          */
63  
-        DialogRunnable( IWebWorksDialog dialog, ScriptableFunction callback, Object context ) {
  116
+        DialogRunnable( IWebWorksDialog dialog, ScriptableFunction callback ) {
64 117
             _dialog = dialog;
65 118
             _callback = callback;
66  
-            _context = context;
67 119
         }
68 120
         
69 121
 
@@ -106,4 +158,39 @@ public void run() {
106 158
             }
107 159
         }
108 160
     }
  161
+    
  162
+    private static class DialogAsyncRunnable implements Runnable {
  163
+        private Dialog _dialog;
  164
+        private ScriptableFunction _callback;
  165
+        private Integer _dialogValue;
  166
+            
  167
+        /**
  168
+         * Constructs a <code>DialogRunnable</code> object.
  169
+         * 
  170
+         * @param dialog
  171
+         *            The dialog
  172
+         * @param callback
  173
+         *            The callback
  174
+         */
  175
+        DialogAsyncRunnable( Dialog dialog, ScriptableFunction callback ) {
  176
+            _dialog = dialog;
  177
+            _callback = callback;
  178
+        }
  179
+        
  180
+        /**
  181
+         * Run the dialog.
  182
+         * 
  183
+         * @see java.lang.Runnable#run()
  184
+         */
  185
+        public void run() {
  186
+            _dialogValue = new Integer( _dialog.doModal() );
  187
+            // get object's string as all ecma primitives will return a valid string representation of themselves
  188
+            Object retVal = _dialogValue.toString();
  189
+            try {
  190
+                _callback.invoke( null, new Object[] { retVal } );
  191
+            } catch( Exception e ) {
  192
+                throw new RuntimeException( "Invoke callback failed: " + e.getMessage() );
  193
+            }
  194
+        }
  195
+    }
109 196
 }
7  api/dialog/src/main/java/blackberry/ui/dialog/SelectAsyncFunction.java
@@ -15,17 +15,12 @@
15 15
  */
16 16
 package blackberry.ui.dialog;
17 17
 
18  
-import net.rim.device.api.script.ScriptEngine;
19 18
 import net.rim.device.api.script.Scriptable;
20 19
 import net.rim.device.api.script.ScriptableFunction;
21 20
 import net.rim.device.api.ui.UiApplication;
22  
-import blackberry.common.util.json4j.JSONArray;
23 21
 import blackberry.core.FunctionSignature;
24 22
 import blackberry.core.ScriptableFunctionBase;
25 23
 
26  
-import blackberry.ui.dialog.DialogRunnableFactory;
27  
-import blackberry.ui.dialog.select.SelectDialog;
28  
-
29 24
 /**
30 25
  * Implementation of asynchronous selection dialog
31 26
  * 
@@ -56,7 +51,7 @@ public Object execute( Object thiz, Object[] args ) throws Exception {
56 51
 
57 52
         populateChoiceStateArrays( choices, labels, enabled, selected, types, allowMultiple );
58 53
         
59  
-        Runnable dr = DialogRunnableFactory.getSelectRunnable(allowMultiple, labels, enabled, selected, types, callback, thiz);
  54
+        Runnable dr = DialogRunnableFactory.getSelectRunnable(allowMultiple, labels, enabled, selected, types, callback);
60 55
         
61 56
         // queue
62 57
         UiApplication.getUiApplication().invokeLater(dr);
77  api/dialog/src/main/java/blackberry/ui/dialog/StandardAskAsyncFunction.java
... ...
@@ -0,0 +1,77 @@
  1
+/*
  2
+* Copyright 2010-2011 Research In Motion Limited.
  3
+*
  4
+* Licensed under the Apache License, Version 2.0 (the "License");
  5
+* you may not use this file except in compliance with the License.
  6
+* You may obtain a copy of 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,
  12
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13
+* See the License for the specific language governing permissions and
  14
+* limitations under the License.
  15
+*/
  16
+package blackberry.ui.dialog;
  17
+
  18
+import net.rim.device.api.script.Scriptable;
  19
+import net.rim.device.api.script.ScriptableFunction;
  20
+import net.rim.device.api.ui.UiApplication;
  21
+import net.rim.device.api.ui.component.Dialog;
  22
+import blackberry.core.FunctionSignature;
  23
+import blackberry.core.ScriptableFunctionBase;
  24
+
  25
+/**
  26
+ * Implementation of asynchronous standard ask function (blackberry.ui.dialog.standardAskAsync)
  27
+ * 
  28
+ * @author dmateescu
  29
+ * 
  30
+ */
  31
+public class StandardAskAsyncFunction extends ScriptableFunctionBase {
  32
+
  33
+    public static final String NAME = "standardAskAsync";
  34
+
  35
+    /**
  36
+     * @see blackberry.core.ScriptableFunctionBase#execute(Object, Object[])
  37
+     */
  38
+    public Object execute( Object thiz, Object[] args ) throws Exception {
  39
+    	String message;
  40
+    	int type;      
  41
+        final boolean global = false;
  42
+
  43
+        // message
  44
+        message = (String) args[ 0 ];
  45
+        // type
  46
+        type = ( (Integer) args[ 1 ] ).intValue();
  47
+        if( type < Dialog.D_OK || type > Dialog.D_OK_CANCEL ) {
  48
+            throw new IllegalArgumentException();
  49
+        }
  50
+        // default choice
  51
+        final int defaultChoice = DialogNamespace.getDefaultChoice( type );
  52
+        //callback function
  53
+        ScriptableFunction callback = (ScriptableFunction) args[ 2 ];
  54
+        
  55
+        Runnable dr = DialogRunnableFactory.getStandardAskRunnable(message, type, defaultChoice, global, callback);
  56
+        // queue
  57
+        UiApplication.getUiApplication().invokeLater(dr);
  58
+        // return value
  59
+        return Scriptable.UNDEFINED;
  60
+    }
  61
+
  62
+    /**
  63
+     * @see blackberry.core.ScriptableFunctionBase#getFunctionSignatures()
  64
+     */
  65
+    protected FunctionSignature[] getFunctionSignatures() {
  66
+        FunctionSignature fs = new FunctionSignature( 3 );
  67
+        // message
  68
+        fs.addParam( String.class, true );
  69
+        // type
  70
+        fs.addParam( Integer.class, true );
  71
+        // callback
  72
+        fs.addParam( ScriptableFunction.class, true );
  73
+	// filler
  74
+        fs.addParam( Object.class, false );
  75
+        return new FunctionSignature[] { fs };
  76
+    }
  77
+}
59  api/system.event/src/main/java/blackberry/system/event/KeyPressHandler.java
@@ -19,6 +19,7 @@
19 19
 import net.rim.device.api.system.Application;
20 20
 import net.rim.device.api.system.KeyListener;
21 21
 import net.rim.device.api.ui.Keypad;
  22
+import net.rim.device.api.ui.UiApplication;
22 23
 
23 24
 /** 
24 25
  * Key listener implementation. Proxy for system key listener that
@@ -40,6 +41,9 @@
40 41
     
41 42
     private KeyListener _keyMonitor;
42 43
     
  44
+    private UiApplication _app;
  45
+    private boolean _dialogUp;
  46
+    
43 47
     private boolean[] _listenerForKey = new boolean[] { false, false, false, false, false, false, false, false};
44 48
     
45 49
     KeyPressHandler(ISystemEventListener manager) {
@@ -53,13 +57,13 @@
53 57
      * @param forKey the key code to listen for
54 58
      */
55 59
     public void listen(String forKey) {
56  
-        int keyToListenFor = Integer.parseInt(forKey);
57  
-        
58  
-        if(keyToListenFor < 0 || keyToListenFor > _listenerForKey.length) {
59  
-            throw new IllegalArgumentException("Invalid key code requested [" + keyToListenFor + "]");
  60
+        int keyToListenFor = Integer.parseInt( forKey );
  61
+
  62
+        if( keyToListenFor < 0 || keyToListenFor > _listenerForKey.length ) {
  63
+            throw new IllegalArgumentException( "Invalid key code requested [" + keyToListenFor + "]" );
60 64
         }
61  
-        
62  
-        if(_keyMonitor == null) {
  65
+
  66
+        if( _keyMonitor == null ) {
63 67
             
64 68
             //Anonymous implementation of the net.rim.device.api.system.KeyListener interface
65 69
             _keyMonitor = new KeyListener() {
@@ -70,7 +74,8 @@ public void listen(String forKey) {
70 74
                 public boolean keyDown( int keycode, int time ) {
71 75
                     int keyPressed = Keypad.key( keycode );
72 76
                     int event;
73  
-            
  77
+                    _dialogUp = false;
  78
+
74 79
                     switch( keyPressed ) {
75 80
                         case Keypad.KEY_CONVENIENCE_1:
76 81
                             event = IKEY_CONVENIENCE_1;
@@ -80,6 +85,7 @@ public boolean keyDown( int keycode, int time ) {
80 85
                             break;
81 86
                         case Keypad.KEY_MENU:
82 87
                             event = IKEY_MENU;
  88
+                            isDialogUp();
83 89
                             break;
84 90
                         case Keypad.KEY_SEND:
85 91
                             event = IKEY_STARTCALL;
@@ -89,27 +95,54 @@ public boolean keyDown( int keycode, int time ) {
89 95
                             break;
90 96
                         case Keypad.KEY_ESCAPE:
91 97
                             event = IKEY_BACK;
  98
+                            isDialogUp();
92 99
                             break;
93 100
                         case Keypad.KEY_VOLUME_DOWN:
94 101
                             event = IKEY_VOLUME_DOWN;
  102
+                            isDialogUp();
95 103
                             break;
96 104
                         case Keypad.KEY_VOLUME_UP:
97 105
                             event = IKEY_VOLUME_UP;
  106
+                            isDialogUp();
98 107
                             break;
99 108
                         default:
100 109
                             return false;
101 110
                     }
102  
-            
103  
-                    //If we're listening for this hardware key, queue up an event for it
104  
-                    if(_listenerForKey[event]) {
105  
-                        _manager.onSystemEvent(_manager.EVENT_HARDWARE_KEY, String.valueOf(event));
106  
-            
  111
+
  112
+                    // If we're listening for this hardware key, queue up an event for it,
  113
+                    // only queue if the active screen is not a dialog.
  114
+                    if( _listenerForKey[ event ] && !_dialogUp ) {
  115
+                        _manager.onSystemEvent( _manager.EVENT_HARDWARE_KEY, String.valueOf( event ) );
  116
+
107 117
                         return true;
108 118
                     }
109  
-            
110 119
                     return false;
111 120
                 }
112 121
                 
  122
+                /*
  123
+                 * Checks to see if the current active screen is a Dialog.
  124
+                 */
  125
+                private void isDialogUp() {
  126
+                    _app = UiApplication.getUiApplication();
  127
+                    if( _app.isEventThread() ) {
  128
+                        isDialogUpHelper();
  129
+                    } else {
  130
+                        _app.invokeLater( new Runnable() {
  131
+                            public void run() {
  132
+                                isDialogUpHelper();
  133
+                            }
  134
+                        } );
  135
+                    }
  136
+                }
  137
+                
  138
+                public void isDialogUpHelper() {
  139
+                    if( _app.getActiveScreen().getScreenBelow() == null ) {
  140
+                        _dialogUp = false;
  141
+                    } else {
  142
+                        _dialogUp = true;
  143
+                    }
  144
+                }
  145
+                
113 146
                 /**
114 147
                 * @see net.rim.device.api.system.KeyListener#keyChar(char, int, int)
115 148
                 */
28  framework/src/blackberry/web/widget/Widget.java
@@ -53,18 +53,18 @@ public Widget( WidgetConfig wConfig, String locationURI ) {
53 53
         initialize();
54 54
         _locationURI = locationURI;
55 55
 
56  
-		// Set our orientation
57  
-		WidgetConfigImpl configImpl = (WidgetConfigImpl) _wConfig;
58  
-		if (configImpl.isOrientationDefined()) {
59  
-			int direction;
60  
-			if (configImpl.getOrientation() == 0) {
61  
-				direction = net.rim.device.api.system.Display.DIRECTION_PORTRAIT;   
62  
-			} else {
63  
-				direction = net.rim.device.api.system.Display.DIRECTION_LANDSCAPE;   
64  
-			}
65  
-			net.rim.device.api.ui.Ui.getUiEngineInstance().setAcceptableDirections(direction);
66  
-		}
67  
-		
  56
+        // Set our orientation
  57
+        WidgetConfigImpl configImpl = (WidgetConfigImpl) _wConfig;
  58
+        if( configImpl.isOrientationDefined() ) {
  59
+            int direction;
  60
+            if( configImpl.getOrientation() == 0 ) {
  61
+                direction = net.rim.device.api.system.Display.DIRECTION_NORTH;
  62
+            } else {
  63
+                direction = net.rim.device.api.system.Display.DIRECTION_LANDSCAPE;
  64
+            }
  65
+            net.rim.device.api.ui.Ui.getUiEngineInstance().setAcceptableDirections( direction );
  66
+        }
  67
+
68 68
         // Create PageManager
69 69
         PageManager pageManager = new PageManager( this, (WidgetConfigImpl) _wConfig );
70 70
 
@@ -143,9 +143,9 @@ public static void main( String[] args ) {
143 143
                 waitForStartupComplete();
144 144
             }
145 145
             Widget widget = makeWidget( args, wConfig );
146  
-            
  146
+
147 147
             widget.enterEventDispatcher();
148  
-			
  148
+
149 149
             MemoryMaid mm = MemoryMaid.getInstance();
150 150
             if( mm != null ) {
151 151
                 mm.stop();
1,102  framework/src/js/html5_init.js
... ...
@@ -1 +1,1101 @@
1  
-(function(){function o(){this.hasArgument=function(a){return a&&a.length>0};this.hasTooManyArguments=function(a){return a&&a.length>a.callee.length};this.nullUndefinedArgument=function(a){return this.isNull(a)||this.isUndefined(a)};this.isUndefined=function(a){return a==null&&a!==null};this.isNull=function(a){return a===null};this.isNumber=function(a){return typeof a=="number"};this.isPositiveNumber=function(a){return this.isNumber(a)&&a>=0};this.isNumberInRange=function(a,b,c){return this.isNumber(a)&&a>=b&&a<=c};this.isString=function(a){return typeof a=="string"};this.isNonEmptyString=function(a){return this.isString(a)&&a.length>0};this.isFunction=function(a){return typeof a=="function"};this.isBoolean=function(a){return typeof a=="boolean"};this.isObject=function(a){return typeof a=="object"};this.isArray=function(a){return this.isObject(a)&&a instanceof Array};this.isStringArray=function(a){var b=false;var c=this;if(this.isArray(a)){b=function(a){for(var b=0;b<a.length;b++){if(!c.isString(a[b])){return false}}return true}(a)}return b};this.argumentsLength=function(a){return a.length}}function m(a){var b=new Array;while(a.isValidRow()){fieldCount=a.fieldCount();var c=new Object;for(var d=0;d<fieldCount;d++){var e=a.fieldName(d);c[e]=a.field(d)}b.push(c);a.next()}return new k(b)}function l(a,b){a=a||0;b=b||q["db_error_unknown"];this.__defineGetter__("code",function(){return a});this.__defineGetter__("message",function(){return b});this.toString=function(){return"[object SQLError]"}}function k(a){this.__defineGetter__("length",function(){return a.length});this.item=function(b){if(b<0||b>=this.length){return null}return a[b]};this.toString=function(){return"[object SQLResultSetRowList]"}}function j(a,b,c){this.__defineGetter__("insertId",function(){return a});this.__defineGetter__("rowsAffected",function(){return b});this.__defineGetter__("rows",function(){return c});this.toString=function(){return"[object SQLResultSet]"}}function i(a,b){var c=b;var d;this.executeSql=function(b,e,f,g){if(!p.hasArgument(arguments)){throw q["syntax_err"]}try{if(c){b=b.replace(/^\s+|\s+$/g,"");if(b.search(/^select/i)!=0){throw new l(1,q["not_authorized"])}}var h;try{h=a.execute(b,e)}catch(i){if(i.toString().search(/constraint failed/)!=-1){throw new l(6,q["constraint_failed"])}else{throw new l}}if(p.isFunction(f)){f(this,new j(a.lastInsertRowId,a.rowsAffected,m(h)))}if(h){h.close();h=null}}catch(i){d=i instanceof l?i:new l;if(p.isFunction(g)){g(this,d)}}};this.getLastError=function(){return d};this.toString=function(){return"[object SQLTransaction]"}}function h(a){function d(a,c,d,e){try{b.execute("begin",null);var f=new i(b,e);a(f);var g=f.getLastError();if(g){throw g}}catch(h){if(c){c(h instanceof l?h:new l)}return}finally{b.execute("commit",null)}if(d){d()}}var b=google.gears.factory.create("beta.database");try{b.open(a)}catch(c){throw q["TMP_ERROR"]}this.transaction=function(a,b,c){if(!p.hasArgument(arguments)){throw q["invalid_state_err"]}else if(!p.isFunction(a)||b&&!p.isFunction(b)||c&&!p.isFunction(c)){throw q["type_mismatch_err"]}setTimeout(function(){d(a,b,c)},50)};this.readTransaction=function(a,b,c){if(!p.hasArgument(arguments)){throw q["type_mismatch_err"]}else if(!p.isFunction(a)||b&&!p.isFunction(b)||c&&!p.isFunction(c)){throw q["type_mismatch_err"]}setTimeout(function(){d(a,b,c,true)},50)};this.__defineGetter__("version",function(){return"0.0"});this.changeVersion=function(){};this.toString=function(){return"[object Database]"}}function f(){function e(a){a=a||{};this.__defineGetter__("enableHighAccuracy",function(){return a.enableHighAccuracy||false});this.__defineSetter__("enableHighAccuracy",function(b){if(!p.isUndefined(b)&&!p.isBoolean(b)){throw q["TMP_ERROR"]}a.enableHighAccuracy=b});this.__defineGetter__("timeout",function(){return a.timeout});this.__defineSetter__("timeout",function(b){if(!p.isUndefined(b)&&!p.isNumberInRange(b,0,Infinity)){throw q["TMP_ERROR"]}a.timeout=b});this.__defineGetter__("maximumAge",function(){return a.maximumAge||0});this.__defineSetter__("maximumAge",function(b){if(!p.isUndefined(b)&&!p.isNumberInRange(b,0,Infinity)){throw q["TMP_ERROR"]}a.maximumAge=b})}function d(a,b){this.__defineGetter__("coords",function(){return a});this.__defineGetter__("timestamp",function(){return b})}function c(a){var b=null;if(p.isFunction(a)){b=function(b){a(g(b))}}return b}function b(a){var b;if(p.isFunction(a)){b=function(b){a(new d(f(b.coords),b.timestamp))}}return b}var a=google.gears.factory.create("beta.geolocation");this.getCurrentPosition=function(d,f,g){try{a.getCurrentPosition(b(d),c(f),new e(g))}catch(h){throw q["geo_watch_getCurrent"]}};this.watchPosition=function(d,f,g){try{return a.watchPosition(b(d),c(f),new e(g))}catch(h){throw q["geo_watch_getCurrent"]}};this.clearWatch=function(b){if(p.isUndefined(b)){throw q["geo_clearWatch"]}if(p.isPositiveNumber(b)){a.clearWatch(b)}};var f=function(a){var b=function(a,b,c,d,e){this.__defineGetter__("latitude",function(){return a});this.__defineGetter__("longitude",function(){return b});this.__defineGetter__("altitude",function(){return p.isPositiveNumber(c)?c:null});this.__defineGetter__("accuracy",function(){return p.isPositiveNumber(d)?d:Number.MAX_VALUE});this.__defineGetter__("altitudeAccuracy",function(){return p.isPositiveNumber(e)?e:null});this.__defineGetter__("heading",function(){return null});this.__defineGetter__("speed",function(){return null})};if(p.nullUndefinedArgument(a.latitude)){throw q["geo_coordinates_nullUndefinedLatitude"]}if(p.nullUndefinedArgument(a.longitude)){throw q["geo_coordinates_nullUndefinedLongitude"]}return new b(a.latitude,a.longitude,a.altitude,a.accuracy,a.altitudeAccuracy)};var g=function(a){var b=function(a,b){this.__defineGetter__("code",function(){return a});this.__defineGetter__("message",function(){return b})};b.prototype.__defineGetter__("PERMISSION_DENIED",function(){return 1});b.prototype.__defineGetter__("POSITION_UNAVAILABLE",function(){return 2});b.prototype.__defineGetter__("TIMEOUT",function(){return 3});switch(a.code){case a.PERMISSION_DENIED:return new b(b.prototype.PERMISSION_DENIED,a.message);case a.TIMEOUT:return new b(b.prototype.TIMEOUT,a.message);default:return new b(b.prototype.POSITION_UNAVAILABLE,a.message)}}}function e(a){var b=a[0];if(p.isFunction(b)&&p.argumentsLength(a)>2){var c=new Array;for(var d=0;d<p.argumentsLength(a)-2;d++){c[d]=a[d+2]}b=b.apply(this,c)}return b}function d(a){if(!isFinite(a)||!p.isPositiveNumber(a)){a=0}return a}function c(a){return p.isString(a)||p.isFunction(a)}function b(){navigator.geolocation=new f}if(!window.google||!google.gears){return}b();var a=google.gears.factory.create("beta.timer");window.setTimeout=function(){if(!c(arguments[0])){return a.setTimeout("",0)}var b=e(arguments);var f=d(arguments[1]);return a.setTimeout(b,f)};window.setInterval=function(){const b=10;if(!c(arguments[0])){return a.setInterval("",0)}var f=e(arguments);var g=d(arguments[1]);g=Math.max(g,b);return a.setInterval(f,g)};window.clearTimeout=function(){if(p.isPositiveNumber(arguments[0])){a.clearTimeout(arguments[0])}};window.clearInterval=function(){if(p.isPositiveNumber(arguments[0])){return a.clearInterval(arguments[0])}};var g=XMLHttpRequest;XMLHttpRequest=function(){var a=this;var b=new g;var c=false;this.__defineGetter__("UNSENT",function(){return 0});this.__defineGetter__("OPENED",function(){return 1});this.__defineGetter__("HEADERS_RECEIVED",function(){return 2});this.__defineGetter__("LOADING",function(){return 3});this.__defineGetter__("DONE",function(){return 4});this.__defineGetter__("readyState",function(){return b.readyState});this.__defineGetter__("status",function(){var a=0;try{a=b.status}catch(c){}return a});this.__defineGetter__("statusText",function(){var a="";try{a=b.statusText}catch(c){}return a});this.__defineGetter__("responseText",function(){var a="";try{a=b.responseText}catch(c){}return a});this.__defineGetter__("responseXML",function(){if(!(this.readyState==this.DONE)){return null}var a=new DOMParser;var b=null;try{b=a.parseFromString(this.responseText,"text/xml")}catch(c){}return b});this.open=function(a,c,d,e,f){if(!p.hasArgument(arguments)||arguments.length==1){throw q["not_enough_args"]}try{switch(arguments.length){case 2:b.open(a,c,true);break;case 3:b.open(a,c,d);break;case 4:b.open(a,c,d,e);break;default:b.open(a,c,d,e,f)}}catch(g){}};this.send=function(a){if(p.hasTooManyArguments(arguments)){throw q["invalid_state_err"]}if(a&&!p.isString(a)){throw q["TMP_ERROR"]}try{b.send(a)}catch(c){throw q["invalid_state_err"]}};this.abort=function(){try{b.abort()}catch(a){}};this.getResponseHeader=function(a){if(!p.isString(a)){return null}try{return b.getResponseHeader(a)}catch(c){throw q["invalid_state_err"]}};this.getAllResponseHeaders=function(){try{return b.getAllResponseHeaders()}catch(a){throw q["invalid_state_err"]}};this.setRequestHeader=function(a,c){if(!p.hasArgument(arguments)||arguments.length==1){throw q["not_enough_args"]}else if(!a||!p.isString(a)||!c||!p.isString(c)){return}try{b.setRequestHeader(a,c)}catch(d){throw q["invalid_state_err"]}};this.__defineSetter__("onreadystatechange",function(d){if(p.isFunction(d)){c=true;b.onreadystatechange=function(){d.apply(a)}}else{c=false}});this.__defineGetter__("onreadystatechange",function(){if(c){return b.onreadystatechange}return null});this.toString=function(){return"[object XMLHttpRequest]"}};openDatabase=function(a,b,c,d){if(!p.hasArgument(arguments)){throw q["syntax_err"]}else if(!p.isString(a)){throw q["invalid_state_err"]}try{return new h(a)}catch(e){}};var n=function(){function f(a,b){var d=google.gears.factory.create("beta.httprequest");d.open("GET",a);d.onreadystatechange=function(){if(d.readyState==4&&d.status==200){c.sendMessage(d.responseText,b)}};d.send()}function e(a,c){b[c].queue.push(a)}function d(a){while(b[a].queue.length){var d=b[a].queue.shift();c.sendMessage(d,a)}}var a="html5_worker.js";var b={};var c=google.gears.factory.create("beta.workerpool");c.onmessage=function(a,c,e){if(e.body.type=="ready"){b[e.sender].ready=true;d(e.sender)}else if(e.body.type=="message"){var f=b[e.sender].main;var g=f.onmessage;if(p.isFunction(g)){g.call(f,{data:e.body.content})}}else if(e.body.type=="error"){var f=b[e.sender].main;var h=f.onerror;if(p.isFunction(h)){h.call(f,e.body.content)}}else if(e.body.type=="debug"){}};this.createNewWorker=function(d,e){var g=c.createWorkerFromUrl(a);f(d,g);b[g]={queue:new Array,main:e,ready:false};return g};this.postToWorker=function(a,d){if(b[d].ready&&!b[d].queue.length){c.sendMessage(a,d)}else{e(a,d)}};return this}();Worker=function(a){if(!n){throw"Elemented with id 'html5_init' is not found. Worker with "+a+" cannot be created"}if(!p.hasArgument(arguments)){throw q["not_enough_args"]}if(!p.isString(a)){a=" "}else if(!a.length){throw q["syntax_err"]}var b=null;var c;var d=this;this.__defineSetter__("onmessage",function(a){if(!p.isFunction(a)){b=null;return}else{b=a}});this.__defineGetter__("onmessage",function(){return b});this.postMessage=function(a){if(!p.isPositiveNumber(c)){return}if(p.hasTooManyArguments(arguments)){throw q["worker_error_message_port"]}n.postToWorker(a,c)};this.__defineSetter__("onerror",function(a){window.onerror=a});this.__defineGetter__("onerror",function(){return window.onerror});this.toString=function(){return"[object Worker]"};if(a.indexOf(".js")!=-1){c=n.createNewWorker(a,d)}};var p=new o;var q=function(){var a={geo_watch_getCurrent:new Error("TYPE_MISMATCH_ERR:DOM Exception 17"),geo_clearWatch:new Error("Unexpected error: Not enough arguments [nsIDOMGeoGeolocation.clearWatch]"),geo_coordinates_nullUndefinedLatitude:new Error("Latitude should not be null or undefined"),geo_coordinates_nullUndefinedLongitude:new Error("Longitude should not be null or undefined"),invalid_state_err:new Error("INVALID_STATE_ERR: DOM Exception 11"),syntax_err:new Error("SYNTAX_ERR: DOM Exception 12"),type_mismatch_err:new Error("TYPE_MISMATCH_ERR: DOM Exception 17"),not_enough_args:new SyntaxError("Not enough arguments"),not_authorized:"not authorized",constraint_failed:"constraint failed",db_error_unknown:"Unknown database error occured",worker_error_message_port:new Error("Type error"),TMP_ERROR:new Error("Temporary Error Message")};return a}()})()
  1
+/**
  2
+
  3
+Date: 07/29/2010
  4
+Version: 1.0.0.4
  5
+
  6
+Copyright (c) 2010 Research In Motion Limited.
  7
+
  8
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  9
+
  10
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  11
+
  12
+This License shall be included in all copies or substantial portions of the Software.
  13
+
  14
+The name(s) of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization.
  15
+
  16
+ **/  
  17
+
  18
+/*
  19
+ Device 5.0 HTML 5 wrapper on Google Gears.
  20
+ */
  21
+
  22
+(function() {
  23
+
  24
+    //Check pre-requisites and attach the various namespaces
  25
+    if (!window.google || !google.gears) {
  26
+        return; //Nothing else we can do
  27
+    }
  28
+    
  29
+    attachNamespaces();
  30
+    
  31
+    //-----INITIALIZATION AREA-----
  32
+    var timer = google.gears.factory.create("beta.timer");
  33
+   
  34
+    function attachNamespaces() {
  35
+             
  36
+        navigator.geolocation = new Geolocation();
  37
+    }
  38
+  
  39
+    //-----END OF INITIALIZATION AREA-----
  40
+    
  41
+    /*
  42
+     * HTML5 API
  43
+     *
  44
+     * handle = window.setTimeout( handler [, timeout [, arguments ] ] ); handle =
  45
+     * window.setTimeout( code [, timeout ] )
  46
+     *
  47
+     */
  48
+    window.setTimeout = function() {
  49
+        /*
  50
+         * Even though a non-string non-function handler is not part of HTML5
  51
+         * API, the browser on 6.0 does not fail in those cases (returns a handler),
  52
+         * so here we are just making a dummy call.
  53
+         */
  54
+        if (!isHandlerValid(arguments[0])) {
  55
+            return timer.setTimeout("", 0);
  56
+        }
  57
+        
  58
+        // The first argument is required to be function/code
  59
+        var handler = getTimerTask(arguments);
  60
+        // The second argument is the timeout value
  61
+        var timeout = getTimeout(arguments[1]);
  62
+        
  63
+        return timer.setTimeout(handler, timeout);
  64
+    };
  65
+    
  66
+    window.setInterval = function() {
  67
+        const MIN_INTERVAL = 10;
  68
+        /*
  69
+         * Even though a non-string non-function handler is not part of HTML5
  70
+         * API, the browser on 6.0 does not fail in those cases (returns a handler),
  71
+         * so here we are just making a dummy call.
  72
+         */
  73
+        if (!isHandlerValid(arguments[0])) {
  74
+            return timer.setInterval("", 0);
  75
+        }
  76
+        
  77
+        // The first argument is required to be function/code
  78
+        var handler = getTimerTask(arguments);
  79
+        // The second argument is the timeout value
  80
+        var timeout = getTimeout(arguments[1]);
  81
+        
  82
+        //If timeout is less than MIN_INTERVAL, then increase timeout to MIN_INTERVAL.
  83
+        timeout = Math.max(timeout, MIN_INTERVAL);
  84
+        
  85
+        return timer.setInterval(handler, timeout);
  86
+    };
  87
+    
  88
+    window.clearTimeout = function() {
  89
+        /*
  90
+         * illegal arguments would throw exception in Gears, but only fail
  91
+         * silently in 6.0 browser
  92
+         */
  93
+        if (util.isPositiveNumber(arguments[0])) {
  94
+            timer.clearTimeout(arguments[0]);
  95
+        }
  96
+    };
  97
+    
  98
+    window.clearInterval = function() {
  99
+        if (util.isPositiveNumber(arguments[0])) {
  100
+            return timer.clearInterval(arguments[0]);
  101
+        }
  102
+    };
  103
+    
  104
+    /*
  105
+     * check whether the handler is valid
  106
+     */
  107
+    function isHandlerValid(handler) {
  108
+        return (util.isString(handler) || util.isFunction(handler));
  109
+    }
  110
+    
  111
+    /*
  112
+     * HTML5 Documentation - get timeout
  113
+     *
  114
+     * 1. Let timeout be the second argument to the method, or zero if the
  115
+     * argument was omitted. 2. Apply the ToString() abstract operation to
  116
+     * timeout, and let timeout be the result. [ECMA262] 3. Apply the ToNumber()
  117
+     * abstract operation to timeout, and let timeout be the result. [ECMA262]
  118
+     * 4. If timeout is an Infinity value, a Not-a-Number (NaN) value, or
  119
+     * negative, let timeout be zero. 5. Round timeout down to the nearest
  120
+     * integer, and let timeout be the result. 6. Return timeout.
  121
+     */
  122
+    function getTimeout(timeout) {
  123
+        if (!isFinite(timeout) || !util.isPositiveNumber(timeout)) {
  124
+            timeout = 0;
  125
+        }
  126
+        
  127
+        return timeout;
  128
+    }
  129
+    
  130
+    /*
  131
+     * getTimerTask take the whole array of arguments.
  132
+     * If the handler is a funciton, it pass any arguments straight through to the handler
  133
+     */
  134
+    function getTimerTask(arguments) {
  135
+        var handler = arguments[0];
  136
+        if (util.isFunction(handler) && util.argumentsLength(arguments) > 2) {
  137
+            // The user put a function signature as the first argument
  138
+            // The third arguments and onwards are parameters for the first
  139
+            // function
  140
+            var args = new Array();
  141
+            for (var i = 0; i < util.argumentsLength(arguments) - 2; i++) {
  142
+                args[i] = arguments[i + 2];
  143
+            }
  144
+            
  145
+            handler = handler.apply(this, args);
  146
+        }
  147
+        return handler;
  148
+    }
  149
+    
  150
+    function Geolocation() {
  151
+        var geolocation = google.gears.factory.create("beta.geolocation");
  152
+        
  153
+        this.getCurrentPosition = function(positionCB, positionErrorCB, positionOptions) {
  154
+            try {
  155
+                geolocation.getCurrentPosition(wrapSuccessCB(positionCB), wrapErrorCB(positionErrorCB), new PositionOptions(positionOptions));
  156
+            } 
  157
+            catch (e) {
  158
+                throw (errorsMap["geo_watch_getCurrent"]);
  159
+            }
  160
+        };
  161
+        
  162
+        this.watchPosition = function(positionCB, positionErrorCB, positionOptions) {
  163
+            try {
  164
+                return geolocation.watchPosition(wrapSuccessCB(positionCB), wrapErrorCB(positionErrorCB), new PositionOptions(positionOptions));
  165
+            } 
  166
+            catch (e) {
  167
+                throw (errorsMap["geo_watch_getCurrent"]);
  168
+            }
  169
+        };
  170
+        
  171
+        function wrapSuccessCB(positionCB) {
  172
+            var result;
  173
+            
  174
+            if (util.isFunction(positionCB)) {
  175
+                result = function(position) {
  176
+                    positionCB(new Position(createCoordinates(position.coords), position.timestamp));
  177
+                };
  178
+            }
  179
+            
  180
+            return result;
  181
+        }
  182
+        
  183
+        function wrapErrorCB(positionErrorCB) {
  184
+            // Pass null when there is no usage of the callback
  185
+            var result = null;
  186
+            
  187
+            if (util.isFunction(positionErrorCB)) {
  188
+                result = function(error) {
  189
+                    positionErrorCB(createPositionError(error));
  190
+                };
  191
+            }
  192
+            
  193
+            return result;
  194
+        }
  195
+        
  196
+        this.clearWatch = function(watchId) {
  197
+            //Throw the only error required by HTML 5
  198
+            if (util.isUndefined(watchId)) {
  199
+                throw (errorsMap["geo_clearWatch"]);
  200
+            }
  201
+            
  202
+            /* Only pass the call to Gears if we have a positive integer watchId.
  203
+             * Gears throws exceptions for invalid parameter values that HTML 5
  204
+             * ignores
  205
+             */
  206
+            if (util.isPositiveNumber(watchId)) {
  207
+                geolocation.clearWatch(watchId);
  208
+            }
  209
+        };
  210
+        
  211
+        function Position(coords, timestamp) {
  212
+            this.__defineGetter__("coords", function() {
  213
+                return coords;
  214
+            });
  215
+            
  216
+            this.__defineGetter__("timestamp", function() {
  217
+                return timestamp;
  218
+            });
  219
+        }
  220
+        
  221
+        function PositionOptions(args) {
  222
+            args = args || {};
  223
+            
  224
+            this.__defineGetter__("enableHighAccuracy", function() {
  225
+                return args.enableHighAccuracy || false;
  226
+            });
  227
+            
  228
+            this.__defineSetter__("enableHighAccuracy", function(value) {
  229
+                if (!util.isUndefined(value) && !util.isBoolean(value)) {
  230
+                    throw (errorsMap["TMP_ERROR"]);
  231
+                }
  232
+                
  233
+                args.enableHighAccuracy = value;
  234
+            });
  235
+            
  236
+            this.__defineGetter__("timeout", function() {
  237
+                return args.timeout;
  238
+            });
  239
+            
  240
+            this.__defineSetter__("timeout", function(value) {
  241
+                if (!util.isUndefined(value) && !util.isNumberInRange(value, 0, Infinity)) {
  242
+                    throw (errorsMap["TMP_ERROR"]);
  243
+                }
  244
+                
  245
+                args.timeout = value;
  246
+            });
  247
+            
  248
+            this.__defineGetter__("maximumAge", function() {
  249
+                return args.maximumAge || 0;
  250
+            });
  251
+            
  252
+            this.__defineSetter__("maximumAge", function(value) {
  253
+                if (!util.isUndefined(value) && !util.isNumberInRange(value, 0, Infinity)) {
  254
+                    throw (errorsMap["TMP_ERROR"]);
  255
+                }
  256
+                
  257
+                args.maximumAge = value;
  258
+            });
  259
+        }
  260
+        
  261
+        //Factory function that checks Gears object to ensure that it contains
  262
+        //valid coordinate data and creates an HTML 5 Coordinates object from it
  263
+        var createCoordinates = function(fromGearsCoords) {
  264
+        
  265
+            //Keep the Coordinates object private so we only navigator members can instantiate it
  266
+            var Coordinates = function(lat, lon, alt, acc, altAcc) {
  267
+                this.__defineGetter__("latitude", function() {
  268
+                    return lat;
  269
+                });
  270
+                
  271
+                this.__defineGetter__("longitude", function() {
  272
+                    return lon;
  273
+                });
  274
+                
  275
+                this.__defineGetter__("altitude", function() {
  276
+                    return util.isPositiveNumber(alt) ? alt : null;
  277
+                });
  278
+                
  279
+                this.__defineGetter__("accuracy", function() {
  280
+                    return util.isPositiveNumber(acc) ? acc : Number.MAX_VALUE;
  281
+                });
  282
+                
  283
+                this.__defineGetter__("altitudeAccuracy", function() {
  284
+                    return util.isPositiveNumber(altAcc) ? altAcc : null;
  285
+                });
  286
+                
  287
+                this.__defineGetter__("heading", function() {
  288
+                    return null; //Not supported by Gears
  289
+                });
  290
+                
  291
+                this.__defineGetter__("speed", function() {
  292
+                    return null; //Not supported by Gears
  293
+                });
  294
+            };
  295
+            
  296
+            if (util.nullUndefinedArgument(fromGearsCoords.latitude)) {
  297
+                throw errorsMap["geo_coordinates_nullUndefinedLatitude"];
  298
+            }
  299
+            
  300
+            if (util.nullUndefinedArgument(fromGearsCoords.longitude)) {
  301
+                throw errorsMap["geo_coordinates_nullUndefinedLongitude"];
  302
+            }
  303
+            
  304
+            return new Coordinates(fromGearsCoords.latitude, fromGearsCoords.longitude, fromGearsCoords.altitude, fromGearsCoords.accuracy, fromGearsCoords.altitudeAccuracy);
  305
+        };
  306
+        
  307
+        var createPositionError = function(fromGearsError) {
  308
+            var PositionError = function(errorCode, msg) {
  309
+                this.__defineGetter__("code", function() {
  310
+                    return errorCode;
  311
+                });
  312
+                
  313
+                this.__defineGetter__("message", function() {
  314
+                    return msg;
  315
+                });
  316
+            };
  317
+            
  318
+            //Getters for the instance error codes used by clients
  319
+            PositionError.prototype.__defineGetter__("PERMISSION_DENIED", function() {
  320
+                return 1;
  321
+            });
  322
+            
  323
+            PositionError.prototype.__defineGetter__("POSITION_UNAVAILABLE", function() {
  324
+                return 2;
  325
+            });
  326
+            
  327
+            PositionError.prototype.__defineGetter__("TIMEOUT", function() {
  328
+                return 3;
  329
+            });
  330
+            
  331
+            //Map the Gears error code to the HTML 5 error codes and return the Gears error message
  332
+            switch (fromGearsError.code) {
  333
+                //Not used by Gears but included for completeness
  334
+                case fromGearsError.PERMISSION_DENIED:
  335
+                    return new PositionError(PositionError.prototype.PERMISSION_DENIED, fromGearsError.message);
  336
+                case fromGearsError.TIMEOUT:
  337
+                    return new PositionError(PositionError.prototype.TIMEOUT, fromGearsError.message);
  338
+                default:
  339
+                    return new PositionError(PositionError.prototype.POSITION_UNAVAILABLE, fromGearsError.message);
  340
+            }
  341
+        };
  342
+         
  343
+    }
  344
+    var nativeXMLHttpRequest = XMLHttpRequest;
  345
+    
  346
+    XMLHttpRequest = function() {
  347
+        var that = this;
  348
+        var request = new nativeXMLHttpRequest();
  349
+        var hasValidOnReadyStateChange = false;
  350
+        
  351
+        // The object has been constructed.
  352
+        this.__defineGetter__("UNSENT", function() {
  353
+            return 0;
  354
+        });
  355
+        
  356
+        // The open() method has been successfully invoked. During this state request headers can be set using setRequestHeader() and the request can be made using the send() method.
  357
+        this.__defineGetter__("OPENED", function() {
  358
+            return 1;
  359
+        });
  360
+        
  361
+        /*
  362
+         * All HTTP headers have been received. Several response members of the object are now available.
  363
+         * HEADERS_RECEIVED is same as SENT of Google Gears.
  364
+         */
  365
+        this.__defineGetter__("HEADERS_RECEIVED", function() {
  366
+            return 2;
  367
+        });
  368
+        
  369
+        /*
  370
+         * The response entity body is being received.
  371
+         * LOADING is same as Interactive of Google Gears.
  372
+         */
  373
+        this.__defineGetter__("LOADING", function() {
  374
+            return 3;
  375
+        });
  376
+        
  377
+        // The data transfer has been completed or something went wrong during the transfer (e.g. infinite redirects).
  378
+        this.__defineGetter__("DONE", function() {
  379
+            return 4;
  380
+        });
  381
+        
  382
+        // The XMLHttpRequest object can be in several states. The readyState attribute, on getting, must return the current state, which must be one of the above values.
  383
+        this.__defineGetter__("readyState", function() {
  384
+            return request.readyState;
  385
+        });
  386
+        
  387
+        this.__defineGetter__("status", function() {
  388
+            var result = 0;
  389
+            
  390
+            try {
  391
+                result = request.status;
  392
+            } 
  393
+            catch (e) {
  394
+            }
  395
+            
  396
+            // Return the HTTP status text.
  397
+            return result;
  398
+        });
  399
+        
  400
+        this.__defineGetter__("statusText", function() {
  401
+            var result = "";
  402
+            
  403
+            try {
  404
+                result = request.statusText;
  405
+            } 
  406
+            catch (e) {
  407
+            }
  408
+            
  409
+            // Return the HTTP status text. 
  410
+            return result;
  411
+        });
  412
+        
  413
+        this.__defineGetter__("responseText", function() {
  414
+            var result = "";
  415
+            
  416
+            try {
  417
+                result = request.responseText;
  418
+            } 
  419
+            catch (e) {
  420
+            }
  421
+            
  422
+            // Return the text response entity body. 
  423
+            return result;
  424
+        });
  425
+        
  426
+        this.__defineGetter__("responseXML", function() {
  427
+            // If the state is not DONE return null and terminate these steps
  428
+            if (!(this.readyState == this.DONE)) {
  429
+                return null;
  430
+            }
  431
+
  432
+            //parse responseText to XML Document
  433
+            var parser = new DOMParser();
  434
+            var xmlDoc = null;
  435
+
  436
+            try{
  437
+                xmlDoc = parser.parseFromString (this.responseText, "text/xml");
  438
+            }
  439
+            catch (e) {
  440
+            }
  441
+            //Return the XML response entity body.
  442
+            return xmlDoc;
  443
+        });
  444
+        
  445
+        this.open = function(method, url, sync, username, password) {
  446
+            if (!util.hasArgument(arguments) || arguments.length == 1) {
  447
+                throw errorsMap["not_enough_args"];
  448
+            }
  449
+            
  450
+            try {
  451
+            	switch(arguments.length) {
  452
+            		case 2:
  453
+            			// Native XMLHttp Request must have three arguments
  454
+            			// However, gears only takes two. Therefore, we
  455
+            			// should make request asynchronous to support
  456
+            			// previous functionality.
  457
+            			request.open(method, url, true);
  458
+            			break;
  459
+            		case 3:
  460
+            			request.open(method, url, sync);
  461
+            			break;
  462
+            		case 4:
  463
+            			request.open(method, url, sync, username);
  464
+            			break;
  465
+            		default:
  466
+            			request.open(method, url, sync, username, password);
  467
+            	}
  468
+            } 
  469
+            catch (e) {
  470
+            }
  471
+        };
  472
+        
  473
+        this.send = function(data) {
  474
+            if (util.hasTooManyArguments(arguments)) {
  475
+                throw errorsMap["invalid_state_err"];
  476
+            }
  477
+            
  478
+            // Gears accept data to be a blob which we are not supporting here.
  479
+            if (data && !util.isString(data)) {
  480
+                throw errorsMap["TMP_ERROR"];
  481
+            }
  482
+            
  483
+            try {
  484
+                request.send(data);
  485
+            } 
  486