Bug 825499: Add caretPositionFromPoint to Document.webidl. [r=Ms2ger]

--HG--
rename : content/base/test/test_bug654352.html => content/base/test/test_caretPositionFromPoint.html
This commit is contained in:
Scott Johnson 2013-01-07 11:56:48 -06:00
Родитель 5f2be7b450
Коммит 9904b56d5f
5 изменённых файлов: 42 добавлений и 13 удалений

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

@ -74,6 +74,7 @@ class nsStyleSet;
class nsTextNode;
class nsWindowSizes;
class nsSmallVoidArray;
class nsDOMCaretPosition;
namespace mozilla {
class ErrorResult;
@ -1916,6 +1917,19 @@ public:
virtual nsIDOMDOMStringList* StyleSheetSets() = 0;
virtual void EnableStyleSheetsForSet(const nsAString& aSheetSet) = 0;
Element* ElementFromPoint(float aX, float aY);
/**
* Retrieve the location of the caret position (DOM node and character
* offset within that node), given a point.
*
* @param aX Horizontal point at which to determine the caret position, in
* page coordinates.
* @param aY Vertical point at which to determine the caret position, in
* page coordinates.
*/
already_AddRefed<nsDOMCaretPosition>
CaretPositionFromPoint(float aX, float aY);
// QuerySelector and QuerySelectorAll already defined on nsINode
nsINodeList* GetAnonymousNodes(Element& aElement);
Element* GetAnonymousElementByAttribute(Element& aElement,

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

@ -8853,32 +8853,29 @@ ResetFullScreen(nsIDocument* aDocument, void* aData)
return true;
}
NS_IMETHODIMP
nsDocument::CaretPositionFromPoint(float aX, float aY, nsISupports** aCaretPos)
already_AddRefed<nsDOMCaretPosition>
nsIDocument::CaretPositionFromPoint(float aX, float aY)
{
NS_ENSURE_ARG_POINTER(aCaretPos);
*aCaretPos = nullptr;
nscoord x = nsPresContext::CSSPixelsToAppUnits(aX);
nscoord y = nsPresContext::CSSPixelsToAppUnits(aY);
nsPoint pt(x, y);
nsIPresShell *ps = GetShell();
if (!ps) {
return NS_OK;
return nullptr;
}
nsIFrame *rootFrame = ps->GetRootFrame();
// XUL docs, unlike HTML, have no frame tree until everything's done loading
if (!rootFrame) {
return NS_OK; // return null to premature XUL callers as a reminder to wait
return nullptr;
}
nsIFrame *ptFrame = nsLayoutUtils::GetFrameForPoint(rootFrame, pt, true,
false);
if (!ptFrame) {
return NS_OK;
return nullptr;
}
// GetContentOffsetsFromPoint requires frame-relative coordinates, so we need
@ -8906,8 +8903,15 @@ nsDocument::CaretPositionFromPoint(float aX, float aY, nsISupports** aCaretPos)
}
}
*aCaretPos = new nsDOMCaretPosition(node, offset);
NS_ADDREF(*aCaretPos);
nsRefPtr<nsDOMCaretPosition> aCaretPos = new nsDOMCaretPosition(node, offset);
return aCaretPos.forget();
}
NS_IMETHODIMP
nsDocument::CaretPositionFromPoint(float aX, float aY, nsISupports** aCaretPos)
{
NS_ENSURE_ARG_POINTER(aCaretPos);
*aCaretPos = nsIDocument::CaretPositionFromPoint(aX, aY).get();
return NS_OK;
}

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

@ -506,8 +506,8 @@ MOCHITEST_FILES_B = \
file_html_in_xhr3.html \
file_html_in_xhr.sjs \
test_bug647518.html \
test_bug654352.html \
Ahem.ttf \
test_caretPositionFromPoint.html \
Ahem.ttf \
test_bug664916.html \
test_bug666604.html \
test_bug675121.html \

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

@ -64,6 +64,16 @@
checkOffsetsFromPoint(test4Rect.left + 1, test4Rect.top + 1, 0);
checkOffsetsFromPoint(Math.round(test4Rect.left + convertEmToPx(3)), Math.round(test4Rect.top + 10), 3);
// Check to make sure that x or y outside the viewport returns null.
var nullCp1 = document.caretPositionFromPoint(-10, 0);
ok(!nullCp1, "caret position with negative x should be null");
var nullCp2 = document.caretPositionFromPoint(0, -10);
ok(!nullCp2, "caret position with negative y should be null");
var nullCp3 = document.caretPositionFromPoint(9000, 0);
ok(!nullCp3, "caret position with x > viewport width should be null");
var nullCp4 = document.caretPositionFromPoint(0, 9000);
ok(!nullCp4, "caret position with x > viewport height should be null");
// Check the first and last characters of the marquee.
SimpleTest.finish();
}

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

@ -376,7 +376,8 @@ http://dev.w3.org/csswg/cssom-view/#extensions-to-the-document-interface
partial interface Document {
*/
Element? elementFromPoint (float x, float y);
//(Not implemented)CaretPosition? caretPositionFromPoint (float x, float y);
CaretPosition? caretPositionFromPoint (float x, float y);
/*
};