# HG changeset patch # User Aleh Zasypkin # Date 1390850704 -3600 # Mon Jan 27 20:25:04 2014 +0100 # Node ID 906a4b950ea1fbec4ce7cfa1aafac60fc6380060 # Parent c5ab96fc7eba7b13795e9abd19dc0f3d7f18af7c Bug 960889 - monocles moving when swiping up/down through gmail email draft. diff --git a/browser/metro/base/content/contenthandlers/SelectionHandler.js b/browser/metro/base/content/contenthandlers/SelectionHandler.js --- a/browser/metro/base/content/contenthandlers/SelectionHandler.js +++ b/browser/metro/base/content/contenthandlers/SelectionHandler.js @@ -295,22 +295,30 @@ var SelectionHandler = { } this.closeSelection(); }, /* * Called any time SelectionHelperUI would like us to * recalculate the selection bounds. */ - _onSelectionUpdate: function _onSelectionUpdate() { + _onSelectionUpdate: function _onSelectionUpdate(aMsg) { if (!this._contentWindow) { this._onFail("_onSelectionUpdate was called without proper view set up"); return; } + // TODO(azasypkin): Investigate performance impact of calculating content + // offset on every selection update triggered by apzc. + if (aMsg && aMsg.isInitiatedByAPZC) { + let {offset: offset} = Content.getCurrentWindowAndOffset( + this._targetCoordinates.x, this._targetCoordinates.y); + this._contentOffset = offset; + } + // Update the position of our selection monocles this._updateSelectionUI("update", true, true); }, /* * Called if for any reason we fail during the selection * process. Cancels the selection. */ @@ -382,16 +390,17 @@ var SelectionHandler = { this._clearTimers(); this._cache = null; this._contentWindow = null; this._targetElement = null; this._selectionMoveActive = false; this._contentOffset = null; this._domWinUtils = null; this._targetIsEditable = false; + this._targetCoordinates = null; sendSyncMessage("Content:HandlerShutdown", {}); }, /* * Find content within frames - cache the target nsIDOMWindow, * client coordinate offset, target element, and dom utils interface. */ _initTargetInfo: function _initTargetInfo(aX, aY) { @@ -404,16 +413,21 @@ var SelectionHandler = { if (!contentWindow) { return false; } this._targetElement = element; this._contentWindow = contentWindow; this._contentOffset = offset; this._domWinUtils = utils; this._targetIsEditable = Util.isEditable(this._targetElement); + this._targetCoordinates = { + x: aX, + y: aY + }; + return true; }, /* * _calcNewContentPosition - calculates the distance the browser should be * raised to move the focused form input out of the way of the soft * keyboard. * @@ -528,17 +542,17 @@ var SelectionHandler = { this._onSelectionCopy(json); break; case "Browser:SelectionDebug": this._onSelectionDebug(json); break; case "Browser:SelectionUpdate": - this._onSelectionUpdate(); + this._onSelectionUpdate(json); break; case "Browser:RepositionInfoRequest": // This message is sent simultaneously with a tap event. // Wait a bit to make sure we have the most up-to-date tap co-ordinates // before a call to _calcNewContentPosition() which accesses them. content.setTimeout (function () { SelectionHandler._repositionInfoRequest(json); diff --git a/browser/metro/base/content/helperui/SelectionHelperUI.js b/browser/metro/base/content/helperui/SelectionHelperUI.js --- a/browser/metro/base/content/helperui/SelectionHelperUI.js +++ b/browser/metro/base/content/helperui/SelectionHelperUI.js @@ -356,17 +356,19 @@ var SelectionHelperUI = { break; case "apzc-transform-end": // The selection range callback will check to see if the new // position is off the screen, in which case it shuts down and // clears the selection. if (this.isActive && this.layerMode == kContentLayer) { this._showAfterUpdate = true; - this._sendAsyncMessage("Browser:SelectionUpdate", {}); + this._sendAsyncMessage("Browser:SelectionUpdate", { + isInitiatedByAPZC: true + }); } break; } }, /* * Public apis */ diff --git a/browser/metro/base/tests/mochitest/browser_selection_frame_in_scrollable_container.html b/browser/metro/base/tests/mochitest/browser_selection_frame_in_scrollable_container.html new file mode 100644 --- /dev/null +++ b/browser/metro/base/tests/mochitest/browser_selection_frame_in_scrollable_container.html @@ -0,0 +1,33 @@ + + + + + + +
+ +
+ + diff --git a/browser/metro/base/tests/mochitest/browser_selection_frame_in_scrollable_container.js b/browser/metro/base/tests/mochitest/browser_selection_frame_in_scrollable_container.js new file mode 100644 --- /dev/null +++ b/browser/metro/base/tests/mochitest/browser_selection_frame_in_scrollable_container.js @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +let gWindow = null; +var gFrame = null; + +function setUpAndTearDown() { + emptyClipboard(); + + if (gWindow) { + clearSelection(gWindow); + } + + if (gFrame) { + clearSelection(gFrame); + } + + yield waitForCondition(function () { + return !SelectionHelperUI.isSelectionUIVisible; + }); + + InputSourceHelper.isPrecise = false; + InputSourceHelper.fireUpdate(); +} + +gTests.push({ + desc: "Selection monocles for frame content that is located inside " + + "scrollable container.", + setUp: setUpAndTearDown, + tearDown: setUpAndTearDown, + run: function test() { + let urlToLoad = chromeRoot + + "browser_selection_frame_in_scrollable_container.html"; + info(urlToLoad); + yield addTab(urlToLoad); + + ContextUI.dismiss(); + yield waitForCondition(() => !ContextUI.navbarVisible); + + gWindow = Browser.selectedTab.browser.contentWindow; + gFrame = gWindow.document.getElementById("frame1"); + + // Select some content inside frame. + let promise = waitForEvent(document, "popupshown"); + sendContextMenuClickToWindow(gFrame.contentWindow, 10, 10); + yield promise; + + let selectMenuItem = document.getElementById("context-select"); + promise = waitForEvent(document, "popuphidden"); + sendNativeTap(selectMenuItem); + yield promise; + yield waitForCondition(()=>SelectionHelperUI.isSelectionUIVisible); + + // Scroll frame inside scrollable container. + let initialYPos = SelectionHelperUI.endMark.yPos; + let touchDrag = new TouchDragAndHold(); + touchDrag.useNativeEvents = true; + yield touchDrag.start(gWindow, 100, 90, 100, 50); + touchDrag.end(); + + yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag); + yield SelectionHelperUI.pingSelectionHandler(); + + yield waitForCondition(()=>SelectionHelperUI.isSelectionUIVisible); + + ok(initialYPos - SelectionHelperUI.endMark.yPos > 10, + "Selection monocles followed scrolled content."); + } +}); + +function test() { + // We need this until bug 859742 is fully resolved. + setDevPixelEqualToPx(); + runTests(); +} diff --git a/browser/metro/base/tests/mochitest/metro.ini b/browser/metro/base/tests/mochitest/metro.ini --- a/browser/metro/base/tests/mochitest/metro.ini +++ b/browser/metro/base/tests/mochitest/metro.ini @@ -11,16 +11,17 @@ support-files = browser_link_click.html browser_onscreen_keyboard.html browser_progress_indicator.xul browser_selection_basic.html browser_selection_caretfocus.html browser_selection_contenteditable.html browser_selection_frame_content.html browser_selection_frame_inputs.html + browser_selection_frame_in_scrollable_container.html browser_selection_frame_textarea.html browser_selection_inputs.html browser_selection_textarea.html browser_tilegrid.xul head.js helpers/BookmarksHelper.js helpers/HistoryHelper.js helpers/ViewStateHelper.js @@ -28,16 +29,17 @@ support-files = res/textblock01.html res/textdivs01.html res/textinput01.html res/textarea01.html res/testEngine.xml res/blankpage1.html res/blankpage2.html res/blankpage3.html + res/documentindesignmode.html [browser_apzc_basic.js] [browser_bookmarks.js] [browser_canonizeURL.js] [browser_circular_progress_indicator.js] [browser_colorUtils.js] [browser_crashprompt.js] [browser_context_menu_tests.js] @@ -69,16 +71,18 @@ support-files = # These tests have known failures in debug builds [browser_selection_basic.js] skip-if = debug [browser_selection_textarea.js] skip-if = debug [browser_selection_frame_content.js] skip-if = debug +[browser_selection_frame_in_scrollable_container.js] +skip-if = debug [browser_selection_inputs.js] skip-if = debug [browser_selection_frame_textarea.js] skip-if = debug [browser_selection_frame_inputs.js] skip-if = debug [browser_selection_urlbar.js] skip-if = debug diff --git a/browser/metro/base/tests/mochitest/res/documentindesignmode.html b/browser/metro/base/tests/mochitest/res/documentindesignmode.html new file mode 100644 --- /dev/null +++ b/browser/metro/base/tests/mochitest/res/documentindesignmode.html @@ -0,0 +1,32 @@ + + + + + + +
1
+
2
+
3
+
4
+
5
+ + +