Index: chrome/browser/resources/uber/uber_utils.js |
diff --git a/chrome/browser/resources/uber/uber_utils.js b/chrome/browser/resources/uber/uber_utils.js |
index 3d85044dc1897c105e4feef1584810e11282c852..d4f30db61d303cf6751b5abc37b0d03b81c15010 100644 |
--- a/chrome/browser/resources/uber/uber_utils.js |
+++ b/chrome/browser/resources/uber/uber_utils.js |
@@ -8,7 +8,6 @@ |
*/ |
cr.define('uber', function() { |
- |
/** |
* Fixed position header elements on the page to be shifted by handleScroll. |
* @type {NodeList} |
@@ -21,6 +20,7 @@ cr.define('uber', function() { |
function onContentFrameLoaded() { |
headerElements = document.getElementsByTagName('header'); |
document.addEventListener('scroll', handleScroll); |
+ document.addEventListener('mousedown', handleMouseDownInFrame, true); |
invokeMethodOnParent('ready'); |
@@ -38,7 +38,6 @@ cr.define('uber', function() { |
/** |
* Handles scroll events on the document. This adjusts the position of all |
* headers and updates the parent frame when the page is scrolled. |
- * @private |
*/ |
function handleScroll() { |
var scrollLeft = scrollLeftForDocument(document); |
@@ -54,6 +53,16 @@ cr.define('uber', function() { |
} |
/** |
+ * Tells the parent to focus the current frame if the mouse goes down in the |
+ * current frame (and it doesn't already have focus). |
+ * @param {Event} e A mousedown event. |
+ */ |
+ function handleMouseDownInFrame(e) { |
+ if (!e.isSynthetic && !document.hasFocus()) |
+ window.focus(); |
+ } |
+ |
+ /** |
* Handles 'message' events on window. |
* @param {Event} e The message event. |
*/ |
@@ -74,7 +83,6 @@ cr.define('uber', function() { |
/** |
* This is called when a user selects this frame via the navigation bar |
* frame (and is triggered via postMessage() from the uber page). |
- * @private |
*/ |
function handleFrameSelected() { |
setScrollTopForDocument(document, 0); |
@@ -101,7 +109,9 @@ cr.define('uber', function() { |
* settings/history/extensions don't need to know about their embedder. |
*/ |
function handleMouseDown() { |
- document.body.dispatchEvent(new MouseEvent('mousedown')); |
+ var mouseEvent = new MouseEvent('mousedown'); |
+ mouseEvent.isSynthetic = true; |
+ document.dispatchEvent(mouseEvent); |
} |
/** |
@@ -129,7 +139,6 @@ cr.define('uber', function() { |
* @param {string} method The name of the method to invoke. |
* @param {?=} opt_params Optional property bag of parameters to pass to the |
* invoked method. |
- * @private |
*/ |
function invokeMethodOnParent(method, opt_params) { |
if (!hasParent()) |
@@ -144,7 +153,6 @@ cr.define('uber', function() { |
* @param {?=} opt_params Optional property bag of parameters to pass to the |
* invoked method. |
* @param {string=} opt_url The origin of the target window. |
- * @private |
*/ |
function invokeMethodOnWindow(targetWindow, method, opt_params, opt_url) { |
var data = {method: method, params: opt_params}; |
@@ -158,7 +166,6 @@ cr.define('uber', function() { |
* @param {Object} state A state object for replaceState and pushState. |
* @param {string} path The path the page navigated to. |
* @param {boolean} replace If true, navigate with replacement. |
- * @private |
*/ |
function updateHistory(state, path, replace) { |
var historyFunction = replace ? |