Permalink
Browse files

Merge pull request #7080 from dscravag/nightly2

Nightly 2012-12-19
  • Loading branch information...
2 parents 2b77f0a + a0ecffc commit d38689acc60bddc6e54deda688a82e2777e9826c @dscravag dscravag committed Dec 19, 2012
Showing with 910 additions and 641 deletions.
  1. +1 −0 apps/calculator/index.html
  2. +23 −31 apps/calculator/js/calculator.js
  3. +128 −0 apps/calculator/js/parser.js
  4. +3 −2 apps/camera/index.html
  5. +34 −34 apps/camera/js/camera.js
  6. +2 −1 apps/camera/manifest.webapp
  7. +24 −1 apps/camera/style/camera.css
  8. BIN apps/camera/style/images/actionicon_cancel.png
  9. +12 −23 apps/communications/contacts/index.html
  10. +1 −1 apps/communications/contacts/js/contacts.js
  11. +11 −13 apps/communications/contacts/js/contacts_details.js
  12. +20 −107 apps/communications/contacts/js/navigation.js
  13. +17 −32 apps/communications/contacts/style/app.css
  14. +28 −31 apps/communications/contacts/style/contacts.css
  15. +17 −5 apps/communications/dialer/js/handled_call.js
  16. +9 −3 apps/communications/dialer/js/keypad.js
  17. +16 −10 apps/communications/dialer/js/ussd.js
  18. +15 −12 apps/communications/dialer/js/ussd_ui.js
  19. +4 −0 apps/communications/dialer/locales/dialer.en-US.properties
  20. +3 −1 apps/communications/dialer/ussd.html
  21. +1 −1 apps/gallery/style/gallery.css
  22. +187 −138 apps/keyboard/js/keyboard.js
  23. +2 −5 apps/keyboard/js/render.js
  24. +1 −24 apps/system/index.html
  25. +34 −82 apps/system/js/lockscreen.js
  26. +22 −4 apps/system/js/updatable.js
  27. +31 −18 apps/system/js/update_manager.js
  28. +1 −0 apps/system/locales/system.en-US.properties
  29. BIN apps/system/style/lockscreen/images/handle.png
  30. +89 −24 apps/system/style/lockscreen/lockscreen.css
  31. +5 −4 apps/system/test/unit/identity_test.js
  32. +4 −0 apps/system/test/unit/mock_l10n.js
  33. +6 −4 apps/system/test/unit/mock_trusted_ui_manager.js
  34. +10 −0 apps/system/test/unit/mock_updatable.js
  35. +8 −0 apps/system/test/unit/mock_update_manager.js
  36. +5 −1 apps/system/test/unit/notifications_test.js
  37. +51 −10 apps/system/test/unit/updatable_test.js
  38. +60 −10 apps/system/test/unit/update_manager_test.js
  39. +1 −2 apps/video/index.html
  40. +18 −6 apps/video/js/video.js
  41. +6 −1 build/webapp-manifests.js
@@ -4,6 +4,7 @@
<meta charset="utf-8"/>
<title>Calculator</title>
<link rel="stylesheet" type="text/css" media="screen" href="style/calculator.css"/>
+ <script type="text/javascript" src="js/parser.js" defer></script>
<script type="text/javascript" src="js/calculator.js" defer></script>
</head>
@@ -116,13 +116,6 @@ var Calculator = {
return key;
},
- formatNumber: function calculator_formatNumber(n) {
- if (n % 1 == 0) {
- return n;
- }
- return n.toFixed(3);
- },
-
calculate: function calculator_calculate() {
if (this.stack.length === 0)
return;
@@ -131,7 +124,7 @@ var Calculator = {
var postfix =
this.infix2postfix(this.stack.map(this.substitute).join(''));
var result = this.evaluatePostfix(postfix);
- this.stack = [this.formatNumber(result).toString()];
+ this.stack = [String(result)];
this.updateDisplay();
this.toClear = true;
} catch (err) {
@@ -177,41 +170,31 @@ var Calculator = {
// Currently functions are unimplemented and only operators with
// left association are used
infix2postfix: function calculator_infix2postfix(infix) {
- // We cant know up till this point whether - is for negation or subtraction
- // at this point we modify negation operators into (0-N) so 4+-5 -> 4+(0-5)
- infix = infix.replace(
- /(([^0-9])-|^-)([0-9.]+)/g,
- function(match, _, pre, num) {
- pre = pre || '';
- return pre + '(0-' + num + ')';
- }
- );
-
- // basic tokenisation to ensure we group numbers with >1 digit together
- var tokens = infix.match(/[0-9.]+|\*|\/|\+|\-|\(|\)/g);
+ var parser = new Parser(infix);
+ var tokens = parser.parse();
var output = [];
var stack = [];
tokens.forEach(function infix2postfix_inner(token) {
- if (/[0-9.]+/.test(token)) {
- output.push(parseFloat(token, 10));
+ if (token.number) {
+ output.push(parseFloat(token.value, 10));
}
var isOperator = this.isOperator;
- if (isOperator(token)) {
+ if (isOperator(token.value)) {
var precedence = this.precedence;
- while (isOperator(stack[stack.length - 1]) &&
- precedence(token) <= precedence(stack[stack.length - 1])) {
+ while (stack.length && isOperator(stack[stack.length - 1]) &&
+ precedence(token.value) <= precedence(stack[stack.length - 1])) {
output.push(stack.pop());
}
- stack.push(token);
+ stack.push(token.value);
}
- if (token === '(') {
- stack.push(token);
+ if (token.value === '(') {
+ stack.push(token.value);
}
- if (token === ')') {
+ if (token.value === ')') {
while (stack.length && stack[stack.length - 1] !== '(') {
output.push(stack.pop());
}
@@ -316,7 +299,17 @@ Calculator.test = function() {
['-5.5*6', -33],
['-5.5*-6.4', 35.2],
['-6-6-6', -18],
- ['6-6-6', -6]
+ ['6-6-6', -6],
+ ['.001 /2', .0005],
+ ['(0-.001)/2', -.0005],
+ ['-.001/(0-2)', .0005],
+ ['1000000000000000000000000+1', 1e+24],
+ ['1000000000000000000000000-1', 1e+24],
+ ['1e+30+10', 1e+30],
+ ['1e+30*10', 1e+31],
+ ['1e+30/100', 1e+28],
+ ['10/1000000000000000000000000', 1e-23],
+ ['10/-1000000000000000000000000', -1e-23]
];
var passed = formulas.every(run);
@@ -327,4 +320,3 @@ Calculator.test = function() {
return passed;
};
-
@@ -0,0 +1,128 @@
+'use strict';
+
+function Parser(input) { this.init(input); }
+Parser.prototype = {
+ init: function(input) {
+ // No spaces.
+ input = input.replace(/[ \t\v\n]/g, '');
+
+ // String to array:
+ this._chars = [];
+ for (var i = 0; i < input.length; ++i)
+ this._chars.push(input[i]);
+
+ this._tokens = [];
+ },
+
+ // This method returns an array of objects with these properties:
+ // - number: true/false
+ // - value: the token value
+ parse: function() {
+
+ // The input must be a 'block' without any digit left.
+ if (!this._tokenizeBlock() || this._chars.length)
+ throw ({ type: 'error', msg: 'Wrong input'});
+
+ return this._tokens;
+ },
+
+ _tokenizeBlock: function() {
+ if (!this._chars.length)
+ return false;
+
+ // '(' + something + ')'
+ if (this._chars[0] == '(') {
+ this._tokens.push({number: false, value: this._chars[0]});
+ this._chars.shift();
+
+ if (!this._tokenizeBlock())
+ return false;
+
+ if (!this._chars.length || this._chars[0] != ')')
+ return false;
+
+ this._chars.shift();
+
+ this._tokens.push({number: false, value: ')'});
+ } else {
+ // number + ...
+ if (!this._tokenizeNumber())
+ return false;
+ }
+
+ if (!this._chars.length || this._chars[0] == ')')
+ return true;
+
+ while(this._chars.length && this._chars[0] != ')') {
+ if (!this._tokenizeOther())
+ return false;
+
+ if (!this._tokenizeBlock())
+ return false;
+ }
+
+ return true;
+ },
+
+ // This is a simple float parser.
+ _tokenizeNumber: function() {
+ if (!this._chars.length)
+ return false;
+
+ // {+,-}something
+ var number = [];
+ if (/[+-]/.test(this._chars[0])) {
+ number.push(this._chars.shift());
+ }
+
+ var me = this;
+ function tokenizeNumberInternal() {
+ if (!me._chars.length || !/^[0-9.]/.test(me._chars[0]))
+ return false;
+
+ while (me._chars.length && /[0-9.]/.test(me._chars[0])) {
+ number.push(me._chars.shift());
+ }
+
+ return true;
+ }
+
+ if (!tokenizeNumberInternal())
+ return false;
+
+ // 123{e...}
+ if (!this._chars.length || this._chars[0] != 'e') {
+ this._tokens.push({number: true, value: number.join('')});
+ return true;
+ }
+
+ number.push(this._chars.shift());
+
+ // 123e{+,-}
+ if (/[+-]/.test(this._chars[0])) {
+ number.push(this._chars.shift());
+ }
+
+ if (!this._chars.length)
+ return false;
+
+ // the number
+ if (!tokenizeNumberInternal())
+ return false;
+
+ this._tokens.push({number: true, value: number.join('')});
+ return true;
+ },
+
+ _tokenizeOther: function() {
+ if (!this._chars.length)
+ return false;
+
+ if (['*', '/', '+', '-'].indexOf(this._chars[0]) != -1) {
+ this._tokens.push({number: false, value: this._chars.shift()});
+ return true;
+ }
+
+ return false;
+ }
+};
View
@@ -20,10 +20,11 @@
</div>
<div id="controls">
- <a id="switch-button" name="Switch source" disabled="disabled"><span></span></a>
+ <a id="switch-button" name="Switch source" class="hidden" disabled="disabled"><span></span></a>
<a id="capture-button" name="Capture" disabled="disabled"><span></span></a>
<div id="misc-button">
- <a id="gallery-button" name="View Gallery"><span></span></a>
+ <a id="gallery-button" class="hidden" name="View Gallery"><span></span></a>
+ <a id="cancel-pick" class="hidden"><span></span></a>
<span id="video-timer">00:00</span>
</div>
</div>
View
@@ -1,9 +1,6 @@
'use strict';
var Camera = {
-
- _started: false,
-
_cameras: null,
_camera: 0,
_captureMode: null,
@@ -152,6 +149,13 @@ var Camera = {
},
init: function camera_init() {
+ // If we don't have any pending messages, show the usual UI
+ // Otherwise, determine which buttons to show once we get our
+ // activity message
+ if (!navigator.mozHasPendingMessage('activity')) {
+ this.galleryButton.classList.remove('hidden');
+ this.switchButton.classList.remove('hidden');
+ }
// Dont let the phone go to sleep while the camera is
// active, user must manually close it
@@ -214,11 +218,18 @@ var Camera = {
this.setToggleCameraStyle();
this.setSource(this._camera);
- this._started = true;
-
- if (this._pendingPick) {
- this.initActivity();
- }
+ navigator.mozSetMessageHandler('activity', function(activity) {
+ var name = activity.source.name;
+ if (name === 'pick') {
+ Camera.initPick(activity);
+ }
+ else {
+ // We got another activity. Perhaps we were launched from gallery
+ // So show our usual buttons
+ Camera.galleryButton.classList.remove('hidden');
+ Camera.switchButton.classList.remove('hidden');
+ }
+ });
}).bind(this));
},
@@ -236,21 +247,24 @@ var Camera = {
// When inside an activity the user cannot switch between
// the gallery or video recording.
- initActivity: function camera_initActivity() {
- this.galleryButton.setAttribute('disabled', 'disabled');
- this.switchButton.setAttribute('disabled', 'disabled');
+ initPick: function camera_initPick(activity) {
+ this._pendingPick = activity;
+
+ // Hide the gallery and switch buttons, leaving only the shutter
+ this.galleryButton.classList.add('hidden');
+ this.switchButton.classList.add('hidden');
+
+ // Display the cancel button and add an event listener for it
+ var cancelButton = document.getElementById('cancel-pick');
+ cancelButton.classList.remove('hidden');
+ cancelButton.onclick = this.cancelPick.bind(this);
},
- cancelActivity: function camera_cancelActivity(error) {
- if (error && this._pendingPick) {
+ cancelPick: function camera_cancelPick() {
+ if (this._pendingPick) {
this._pendingPick.postError('pick cancelled');
}
this._pendingPick = null;
-
- if (!this._secureMode) {
- this.galleryButton.removeAttribute('disabled');
- }
- this.switchButton.removeAttribute('disabled');
},
toggleModePressed: function camera_toggleCaptureMode(e) {
@@ -655,7 +669,7 @@ var Camera = {
type: 'image/jpeg',
blob: getreq.result
});
- this.cancelActivity();
+ this.cancelPick();
}).bind(this);
return;
@@ -846,28 +860,14 @@ var Camera = {
}
};
-function actHandle(activity) {
- var name = activity.source.name;
- if (name === 'pick') {
- Camera._pendingPick = activity;
- if (Camera._started) {
- Camera.initActivity();
- }
- }
-}
-
-if (window.navigator.mozSetMessageHandler) {
- window.navigator.mozSetMessageHandler('activity', actHandle);
-}
-
window.addEventListener('DOMContentLoaded', function CameraInit() {
Camera.init();
});
document.addEventListener('mozvisibilitychange', function() {
if (document.mozHidden) {
Camera.stopPreview();
- Camera.cancelActivity(true);
+ Camera.cancelPick();
if (this._secureMode) // If the lockscreen is locked
Filmstrip.clear(); // then forget everything when closing camera
} else {
@@ -29,7 +29,8 @@
"type": ["image/jpeg"]
},
"returnValue": true,
- "disposition": "inline"
+ "disposition": "inline",
+ "href": "/index.html#pick"
}
},
"locales": {
Oops, something went wrong.

0 comments on commit d38689a

Please sign in to comment.