diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 186cd5faf03b..57fea968aab1 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -2203,6 +2203,7 @@ NS_IMETHODIMP nsDOMWindowUtils::SendQueryContentEvent(uint32_t aType, uint32_t aOffset, uint32_t aLength, int32_t aX, int32_t aY, + uint32_t aAdditionalFlags, nsIQueryContentEventResult **aResult) { *aResult = nullptr; @@ -2241,9 +2242,13 @@ nsDOMWindowUtils::SendQueryContentEvent(uint32_t aType, nsCOMPtr targetWidget = widget; LayoutDeviceIntPoint pt(aX, aY); + bool useNativeLineBreak = + !(aAdditionalFlags & QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK); + if (aType == QUERY_CHARACTER_AT_POINT) { // Looking for the widget at the point. WidgetQueryContentEvent dummyEvent(true, NS_QUERY_CONTENT_STATE, widget); + dummyEvent.mUseNativeLineBreak = useNativeLineBreak; InitEvent(dummyEvent, &pt); nsIFrame* popupFrame = nsLayoutUtils::GetPopupFrameForEventCoordinates(presContext->GetRootPresContext(), &dummyEvent); @@ -2273,13 +2278,16 @@ nsDOMWindowUtils::SendQueryContentEvent(uint32_t aType, switch (aType) { case NS_QUERY_TEXT_CONTENT: - queryEvent.InitForQueryTextContent(aOffset, aLength); + queryEvent.InitForQueryTextContent(aOffset, aLength, useNativeLineBreak); break; case NS_QUERY_CARET_RECT: - queryEvent.InitForQueryCaretRect(aOffset); + queryEvent.InitForQueryCaretRect(aOffset, useNativeLineBreak); break; case NS_QUERY_TEXT_RECT: - queryEvent.InitForQueryTextRect(aOffset, aLength); + queryEvent.InitForQueryTextRect(aOffset, aLength, useNativeLineBreak); + break; + default: + queryEvent.mUseNativeLineBreak = useNativeLineBreak; break; } @@ -2297,7 +2305,7 @@ nsDOMWindowUtils::SendQueryContentEvent(uint32_t aType, NS_IMETHODIMP nsDOMWindowUtils::SendSelectionSetEvent(uint32_t aOffset, uint32_t aLength, - bool aReverse, + uint32_t aAdditionalFlags, bool *aResult) { *aResult = false; @@ -2317,7 +2325,9 @@ nsDOMWindowUtils::SendSelectionSetEvent(uint32_t aOffset, selectionEvent.mOffset = aOffset; selectionEvent.mLength = aLength; - selectionEvent.mReversed = aReverse; + selectionEvent.mReversed = (aAdditionalFlags & SELECTION_SET_FLAG_REVERSE); + selectionEvent.mUseNativeLineBreak = + !(aAdditionalFlags & SELECTION_SET_FLAG_USE_XP_LINE_BREAK); nsEventStatus status; nsresult rv = widget->DispatchEvent(&selectionEvent, status); diff --git a/dom/base/test/chrome.ini b/dom/base/test/chrome.ini index 89066923fe22..e65b8b7ec1f2 100644 --- a/dom/base/test/chrome.ini +++ b/dom/base/test/chrome.ini @@ -8,3 +8,4 @@ support-files = [test_url.xul] [test_console.xul] [test_navigator_resolve_identity_xrays.xul] +[test_sendQueryContentAndSelectionSetEvent.html] diff --git a/dom/base/test/test_sendQueryContentAndSelectionSetEvent.html b/dom/base/test/test_sendQueryContentAndSelectionSetEvent.html new file mode 100644 index 000000000000..cc6b5a271882 --- /dev/null +++ b/dom/base/test/test_sendQueryContentAndSelectionSetEvent.html @@ -0,0 +1,224 @@ + + + + Test for nsIDOMWindowUtils.sendQueryContentEvent() and .sendSelectionSetEvent() + + + + +

+ +
abc
def
+
+
+
+ + diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index c48cd908bfe8..c0d4868265f9 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -43,7 +43,7 @@ interface nsIRunnable; interface nsICompositionStringSynthesizer; interface nsITranslationNodeList; -[scriptable, uuid(926c7450-ab88-11e3-a5e2-0800200c9a66)] +[scriptable, uuid(9376bafe-e7b1-48e7-87e2-1e64a7b5d54d)] interface nsIDOMWindowUtils : nsISupports { /** @@ -1020,18 +1020,32 @@ interface nsIDOMWindowUtils : nsISupports { */ nsICompositionStringSynthesizer createCompositionStringSynthesizer(); + /** + * If sendQueryContentEvent()'s aAdditionalFlags argument is + * QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK, plain text generated from content + * is created with "\n". + * Otherwise, platform dependent. E.g., on Windows, "\r\n" is used. + * aOffset and aLength are offset and length in/of the plain text content. + * This flag also affects the result values such as offset, length and string. + */ + const unsigned long QUERY_CONTENT_FLAG_USE_NATIVE_LINE_BREAK = 0x0000; + const unsigned long QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK = 0x0001; + /** * Synthesize a query content event. Note that the result value returned here * is in LayoutDevice pixels rather than CSS pixels. * * @param aType One of the following const values. And see also each comment * for the other parameters and the result. + * @param aAdditionalFlags See the description of QUERY_CONTENT_FLAG_*. */ - nsIQueryContentEventResult sendQueryContentEvent(in unsigned long aType, - in unsigned long aOffset, - in unsigned long aLength, - in long aX, - in long aY); + nsIQueryContentEventResult sendQueryContentEvent( + in unsigned long aType, + in unsigned long aOffset, + in unsigned long aLength, + in long aX, + in long aY, + [optional] in unsigned long aAdditionalFlags); // NOTE: following values are same as NS_QUERY_* in BasicEvents.h @@ -1143,6 +1157,22 @@ interface nsIDOMWindowUtils : nsISupports { */ void exitFullscreen(); + /** + * If sendQueryContentEvent()'s aAdditionalFlags argument is + * SELECTION_SET_FLAG_USE_NATIVE_LINE_BREAK, aOffset and aLength are offset + * and length in/of plain text generated from content is created with "\n". + * Otherwise, platform dependent. E.g., on Windows, "\r\n" is used. + */ + const unsigned long SELECTION_SET_FLAG_USE_NATIVE_LINE_BREAK = 0x0000; + const unsigned long SELECTION_SET_FLAG_USE_XP_LINE_BREAK = 0x0001; + + /** + * If SELECTION_SET_FLAG_REVERSE is set, the selection is set from + * |aOffset + aLength| to |aOffset|. Otherwise, it's set from |aOffset| to + * |aOffset + aLength|. + */ + const unsigned long SELECTION_SET_FLAG_REVERSE = 0x0002; + /** * Synthesize a selection set event to the window. * @@ -1151,14 +1181,12 @@ interface nsIDOMWindowUtils : nsISupports { * @param aOffset The caret offset of the selection start. * @param aLength The length of the selection. If this is too long, the * extra length is ignored. - * @param aReverse If true, the selection set from |aOffset + aLength| to - * |aOffset|. Otherwise, set from |aOffset| to - * |aOffset + aLength|. + * @param aAdditionalFlags See the description of SELECTION_SET_FLAG_*. * @return True, if succeeded. Otherwise, false. */ boolean sendSelectionSetEvent(in unsigned long aOffset, in unsigned long aLength, - in boolean aReverse); + [optional] in unsigned long aAdditionalFlags); /* Selection behaviors - mirror nsIFrame's nsSelectionAmount constants */ const unsigned long SELECT_CHARACTER = 0;