Backed out 3 changesets (bug 1828295) for causing failures on browser_caret_rect.js. CLOSED TREE

Backed out changeset 52b9bf7e6344 (bug 1828295)
Backed out changeset 6e6ee5fe337f (bug 1828295)
Backed out changeset 4e8ff9c439ef (bug 1828295)
This commit is contained in:
Natalia Csoregi 2023-05-31 08:44:34 +03:00
Родитель c342e57201
Коммит 6f5c0c586c
6 изменённых файлов: 18 добавлений и 205 удалений

Просмотреть файл

@ -33,7 +33,6 @@
#include "nsIInterfaceRequestorUtils.h"
#include "nsIScrollableFrame.h"
#include "nsIMathMLFrame.h"
#include "nsLayoutUtils.h"
#include "nsRange.h"
#include "nsTextFragment.h"
#include "mozilla/Assertions.h"
@ -732,25 +731,20 @@ LayoutDeviceIntRect HyperTextAccessible::GetCaretRect(nsIWidget** aWidget) {
nsIFrame* frame = caret->GetGeometry(&rect);
if (!frame || rect.IsEmpty()) return LayoutDeviceIntRect();
PresShell* presShell = mDoc->PresShellPtr();
// Transform rect to be relative to the root frame.
nsIFrame* rootFrame = presShell->GetRootFrame();
rect = nsLayoutUtils::TransformFrameRectToAncestor(frame, rect, rootFrame);
// We need to inverse translate with the offset of the edge of the visual
// viewport from top edge of the layout viewport.
nsPoint viewportOffset = presShell->GetVisualViewportOffset() -
presShell->GetLayoutViewportOffset();
rect.MoveBy(-viewportOffset);
// We need to take into account a non-1 resolution set on the presshell.
// This happens with async pinch zooming. Here we scale the bounds before
// adding the screen-relative offset.
rect.ScaleRoundOut(presShell->GetResolution());
// Now we need to put the rect in absolute screen coords.
nsRect rootScreenRect = rootFrame->GetScreenRectInAppUnits();
rect.MoveBy(rootScreenRect.TopLeft());
// Finally, convert from app units.
auto caretRect = LayoutDeviceIntRect::FromAppUnitsToNearest(
rect, presShell->GetPresContext()->AppUnitsPerDevPixel());
nsPoint offset;
// Offset from widget origin to the frame origin, which includes chrome
// on the widget.
*aWidget = frame->GetNearestWidget(offset);
NS_ENSURE_TRUE(*aWidget, LayoutDeviceIntRect());
rect.MoveBy(offset);
LayoutDeviceIntRect caretRect = LayoutDeviceIntRect::FromUnknownRect(
rect.ToOutsidePixels(frame->PresContext()->AppUnitsPerDevPixel()));
// clang-format off
// ((content screen origin) - (content offset in the widget)) = widget origin on the screen
// clang-format on
caretRect.MoveBy((*aWidget)->WidgetToScreenOffset() -
(*aWidget)->GetClientOffset());
// Correct for character size, so that caret always matches the size of
// the character. This is important for font size transitions, and is
@ -769,8 +763,6 @@ LayoutDeviceIntRect HyperTextAccessible::GetCaretRect(nsIWidget** aWidget) {
if (!charRect.IsEmpty()) {
caretRect.SetTopEdge(charRect.Y());
}
*aWidget = frame->GetNearestWidget();
return caretRect;
}

Просмотреть файл

@ -37,8 +37,6 @@ interface nsIAccessibleText : nsISupports
*/
attribute long caretOffset;
void getCaretRect(out long x, out long y, out long width, out long height);
readonly attribute long characterCount;
readonly attribute long selectionCount;

Просмотреть файл

@ -10,7 +10,6 @@ prefs =
javascript.options.asyncstack_capture_debuggee_only=false
[browser_accessible_moved.js]
[browser_caret_rect.js]
[browser_position.js]
[browser_test_resolution.js]
skip-if = os == 'win' # bug 1372296

Просмотреть файл

@ -1,155 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
async function getCaretRect(browser, id) {
// The caret rect can only be queried on LocalAccessible. On Windows, we do
// send it across processes with caret events, but this currently can't be
// queried outside of the event, nor with XPCOM.
const [x, y, w, h] = await invokeContentTask(browser, [id], contentId => {
const node = content.document.getElementById(contentId);
const contentAcc = content.CommonUtils.accService.getAccessibleFor(node);
contentAcc.QueryInterface(Ci.nsIAccessibleText);
const caretX = {};
const caretY = {};
const caretW = {};
const caretH = {};
contentAcc.getCaretRect(caretX, caretY, caretW, caretH);
return [caretX.value, caretY.value, caretW.value, caretH.value];
});
info(`Caret bounds: ${x}, ${y}, ${w}, ${h}`);
return [x, y, w, h];
}
async function testCaretRect(browser, docAcc, id, offset) {
const acc = findAccessibleChildByID(docAcc, id, [nsIAccessibleText]);
is(acc.caretOffset, offset, `Caret at offset ${offset}`);
const charX = {};
const charY = {};
const charW = {};
const charH = {};
const atEnd = offset == acc.characterCount;
const empty = offset == 0 && atEnd;
const queryOffset = atEnd && !empty ? offset - 1 : offset;
acc.getCharacterExtents(
queryOffset,
charX,
charY,
charW,
charH,
COORDTYPE_SCREEN_RELATIVE
);
info(
`Character ${queryOffset} bounds: ${charX.value}, ${charY.value}, ${charW.value}, ${charH.value}`
);
const [caretX, caretY, caretW, caretH] = await getCaretRect(browser, id);
if (atEnd) {
ok(caretX > charX.value, "Caret x after last character x");
} else {
is(caretX, charX.value, "Caret x same as character x");
}
is(caretY, charY.value, "Caret y same as character y");
is(caretW, 1, "Caret width is 1");
if (!empty) {
is(caretH, charH.value, "Caret height same as character height");
}
}
function getAccBounds(acc) {
const x = {};
const y = {};
const w = {};
const h = {};
acc.getBounds(x, y, w, h);
return [x.value, y.value, w.value, h.value];
}
/**
* Test the caret rect in content documents.
*/
addAccessibleTask(
`
<input id="input" value="ab">
<input id="emptyInput">
`,
async function (browser, docAcc) {
async function runTests() {
const input = findAccessibleChildByID(docAcc, "input", [
nsIAccessibleText,
]);
info("Focusing input");
let caretMoved = waitForEvent(EVENT_TEXT_CARET_MOVED, input);
input.takeFocus();
await caretMoved;
await testCaretRect(browser, docAcc, "input", 0);
info("Setting caretOffset to 1");
caretMoved = waitForEvent(EVENT_TEXT_CARET_MOVED, input);
input.caretOffset = 1;
await caretMoved;
await testCaretRect(browser, docAcc, "input", 1);
info("Setting caretOffset to 2");
caretMoved = waitForEvent(EVENT_TEXT_CARET_MOVED, input);
input.caretOffset = 2;
await caretMoved;
await testCaretRect(browser, docAcc, "input", 2);
info("Resetting caretOffset to 0");
input.caretOffset = 0;
const emptyInput = findAccessibleChildByID(docAcc, "emptyInput", [
nsIAccessibleText,
]);
info("Focusing emptyInput");
caretMoved = waitForEvent(EVENT_TEXT_CARET_MOVED, emptyInput);
emptyInput.takeFocus();
await caretMoved;
await testCaretRect(browser, docAcc, "emptyInput", 0);
}
await runTests();
// Check that the caret rect is correct when the title bar is shown.
if (LINUX || Services.env.get("MOZ_HEADLESS")) {
// Disabling tabs in title bar doesn't change the bounds on Linux or in
// headless mode.
info("Skipping title bar tests");
return;
}
const [origDocX, origDocY, origDocW, origDocH] = getAccBounds(docAcc);
info("Showing title bar");
let titleBarChanged = BrowserTestUtils.waitForMutationCondition(
document.documentElement,
{ attributes: true, attributeFilter: ["tabsintitlebar"] },
() => !document.documentElement.hasAttribute("tabsintitlebar")
);
await SpecialPowers.pushPrefEnv({
set: [["browser.tabs.inTitlebar", false]],
});
await titleBarChanged;
const [newDocX, newDocY, newDocW, newDocH] = getAccBounds(docAcc);
is(newDocX, origDocX, "Doc has same x after title bar change");
Assert.greater(
newDocY,
origDocY,
"Doc has larger y after title bar change"
);
is(newDocW, origDocW, "Doc has same width after title bar change");
if (browser.isRemoteBrowser) {
// The height is stale in the cache and an update isn't triggered.
// However, users normally won't see this because showing the title bar
// requires them to switch windows and switching windows triggers an
// appropriate cache update.
todo(false, "Doc height incorrect after title bar change");
} else {
Assert.less(
newDocH,
origDocH,
"Doc has smaller height after title bar change"
);
}
await runTests();
await SpecialPowers.popPrefEnv();
},
{ chrome: true, topLevel: true }
);

Просмотреть файл

@ -148,8 +148,9 @@ void AccessibleWrap::UpdateSystemCaretFor(
if (::CreateCaret(aCaretWnd, caretBitMap, 1,
aCaretRect.Height())) { // Also destroys the last caret
::ShowCaret(aCaretWnd);
POINT clientPoint{aCaretRect.X(), aCaretRect.Y()};
::ScreenToClient(aCaretWnd, &clientPoint);
::SetCaretPos(clientPoint.x, clientPoint.y);
RECT windowRect;
::GetWindowRect(aCaretWnd, &windowRect);
::SetCaretPos(aCaretRect.X() - windowRect.left,
aCaretRect.Y() - windowRect.top);
}
}

Просмотреть файл

@ -246,28 +246,6 @@ xpcAccessibleHyperText::SetCaretOffset(int32_t aCaretOffset) {
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetCaretRect(int32_t* aX, int32_t* aY, int32_t* aWidth,
int32_t* aHeight) {
NS_ENSURE_ARG_POINTER(aX);
NS_ENSURE_ARG_POINTER(aY);
NS_ENSURE_ARG_POINTER(aWidth);
NS_ENSURE_ARG_POINTER(aHeight);
*aX = *aY = *aWidth = *aHeight;
if (!mIntl) {
return NS_ERROR_FAILURE;
}
if (mIntl->IsRemote()) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsIWidget* widget;
LayoutDeviceIntRect rect = IntlLocal()->GetCaretRect(&widget);
rect.GetRect(aX, aY, aWidth, aHeight);
return NS_OK;
}
NS_IMETHODIMP
xpcAccessibleHyperText::GetSelectionCount(int32_t* aSelectionCount) {
NS_ENSURE_ARG_POINTER(aSelectionCount);