mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 1020802 - Pass collapsed and reason information to selectionchange event. r=ehsan, sr=smaug
This commit is contained in:
parent
8f9afc126a
commit
c1a76e5f84
@ -9286,6 +9286,29 @@ public:
|
||||
nsString mAction;
|
||||
};
|
||||
|
||||
static bool
|
||||
CheckReason(int16_t aReason, SelectionChangeReason aReasonType)
|
||||
{
|
||||
switch (aReasonType) {
|
||||
case SelectionChangeReason::Drag:
|
||||
return aReason & nsISelectionListener::DRAG_REASON;
|
||||
case SelectionChangeReason::Mousedown:
|
||||
return aReason & nsISelectionListener::MOUSEDOWN_REASON;
|
||||
case SelectionChangeReason::Mouseup:
|
||||
return aReason & nsISelectionListener::MOUSEUP_REASON;
|
||||
case SelectionChangeReason::Keypress:
|
||||
return aReason & nsISelectionListener::KEYPRESS_REASON;
|
||||
case SelectionChangeReason::Selectall:
|
||||
return aReason & nsISelectionListener::SELECTALL_REASON;
|
||||
case SelectionChangeReason::Collapsetostart:
|
||||
return aReason & nsISelectionListener::COLLAPSETOSTART_REASON;
|
||||
case SelectionChangeReason::Collapsetoend:
|
||||
return aReason & nsISelectionListener::COLLAPSETOEND_REASON;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalWindow::UpdateCommands(const nsAString& anAction, nsISelection* aSel, int16_t aReason)
|
||||
{
|
||||
@ -9318,7 +9341,16 @@ nsGlobalWindow::UpdateCommands(const nsAString& anAction, nsISelection* aSel, in
|
||||
nsRefPtr<nsRange> nsrange = static_cast<nsRange*>(range.get());
|
||||
init.mBoundingClientRect = nsrange->GetBoundingClientRect(true, false);
|
||||
range->ToString(init.mSelectedText);
|
||||
init.mReason = aReason;
|
||||
|
||||
for (uint32_t reasonType = 0;
|
||||
reasonType < static_cast<uint32_t>(SelectionChangeReason::EndGuard_);
|
||||
++reasonType) {
|
||||
SelectionChangeReason strongReasonType =
|
||||
static_cast<SelectionChangeReason>(reasonType);
|
||||
if (CheckReason(aReason, strongReasonType)) {
|
||||
init.mReasons.AppendElement(strongReasonType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsRefPtr<SelectionChangeEvent> event =
|
||||
|
@ -616,18 +616,12 @@ BrowserElementChild.prototype = {
|
||||
},
|
||||
|
||||
_selectionChangeHandler: function(e) {
|
||||
let isMouseUp = e.reason & Ci.nsISelectionListener.MOUSEUP_REASON;
|
||||
let isSelectAll = e.reason & Ci.nsISelectionListener.SELECTALL_REASON;
|
||||
// When selectall happened, gecko will first collapse the range then
|
||||
// select all. So we will receive two selection change events with
|
||||
// SELECTALL_REASON. We filter first event by check the length of
|
||||
// selectedText.
|
||||
if (!(isMouseUp || (isSelectAll && e.selectedText.length > 0))) {
|
||||
e.stopPropagation();
|
||||
let boundingClientRect = e.boundingClientRect;
|
||||
if (!boundingClientRect) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
let boundingClientRect = e.boundingClientRect;
|
||||
let zoomFactor = content.screen.width / content.innerWidth;
|
||||
|
||||
let detail = {
|
||||
@ -646,6 +640,8 @@ BrowserElementChild.prototype = {
|
||||
canPaste: this._isCommandEnabled("paste"),
|
||||
},
|
||||
zoomFactor: zoomFactor,
|
||||
reasons: e.reasons,
|
||||
isCollapsed: (e.selectedText.length == 0),
|
||||
};
|
||||
|
||||
// Get correct geometry information if we have nested <iframe mozbrowser>
|
||||
|
@ -4,10 +4,20 @@
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
enum SelectionChangeReason {
|
||||
"drag",
|
||||
"mousedown",
|
||||
"mouseup",
|
||||
"keypress",
|
||||
"selectall",
|
||||
"collapsetostart",
|
||||
"collapsetoend"
|
||||
};
|
||||
|
||||
dictionary SelectionChangeEventInit : EventInit {
|
||||
DOMString selectedText = "";
|
||||
DOMRectReadOnly? boundingClientRect = null;
|
||||
short reason = 0;
|
||||
sequence<SelectionChangeReason> reasons = [];
|
||||
};
|
||||
|
||||
[Constructor(DOMString type, optional SelectionChangeEventInit eventInit),
|
||||
@ -15,5 +25,5 @@ dictionary SelectionChangeEventInit : EventInit {
|
||||
interface SelectionChangeEvent : Event {
|
||||
readonly attribute DOMString selectedText;
|
||||
readonly attribute DOMRectReadOnly? boundingClientRect;
|
||||
readonly attribute short reason;
|
||||
[Cached, Pure] readonly attribute sequence<SelectionChangeReason> reasons;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user