зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1120750 - Part 3: Dispatch taponcaret using selectionstatechanged event. r=roc
This commit is contained in:
Родитель
868f2258f9
Коммит
1b3e94152e
|
@ -625,6 +625,8 @@ BrowserElementChild.prototype = {
|
|||
// copied content easily
|
||||
} else if (e.states.indexOf('blur') == 0) {
|
||||
// Always dispatch to notify the blur for the focus content
|
||||
} else if (e.states.indexOf('taponcaret') == 0) {
|
||||
// Always dispatch to notify the caret be touched
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -607,9 +607,10 @@ SelectionCarets::SelectWord()
|
|||
SELECTIONCARETS_LOG("Select a editable content %p with empty text",
|
||||
editingHost);
|
||||
// Long tap on the content with empty text, no action for
|
||||
// selectioncarets but need to dispatch the touchcarettap event
|
||||
// selectioncarets but need to dispatch the taponcaret event
|
||||
// to support the short cut mode
|
||||
DispatchCustomEvent(NS_LITERAL_STRING("touchcarettap"));
|
||||
DispatchSelectionStateChangedEvent(GetSelection(),
|
||||
SelectionState::Taponcaret);
|
||||
return NS_OK;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -945,25 +945,45 @@ TouchCaret::DispatchTapEvent()
|
|||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = presShell->GetDocument();
|
||||
if (!doc) {
|
||||
nsRefPtr<nsCaret> caret = presShell->GetCaret();
|
||||
if (!caret) {
|
||||
return;
|
||||
}
|
||||
|
||||
ErrorResult res;
|
||||
nsRefPtr<dom::Event> domEvent =
|
||||
doc->CreateEvent(NS_LITERAL_STRING("CustomEvent"), res);
|
||||
if (res.Failed()) {
|
||||
Selection* sel = static_cast<Selection*>(caret->GetSelection());
|
||||
if (!sel) {
|
||||
return;
|
||||
}
|
||||
|
||||
dom::CustomEvent* customEvent = static_cast<dom::CustomEvent*>(domEvent.get());
|
||||
customEvent->InitCustomEvent(NS_LITERAL_STRING("touchcarettap"),
|
||||
true, false, nullptr);
|
||||
customEvent->SetTrusted(true);
|
||||
customEvent->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
|
||||
nsIDocument* doc = presShell->GetDocument();
|
||||
|
||||
MOZ_ASSERT(doc);
|
||||
|
||||
SelectionStateChangedEventInit init;
|
||||
init.mBubbles = true;
|
||||
|
||||
// XXX: Do we need to flush layout?
|
||||
presShell->FlushPendingNotifications(Flush_Layout);
|
||||
nsRect rect = nsContentUtils::GetSelectionBoundingRect(sel);
|
||||
nsRefPtr<DOMRect>domRect = new DOMRect(ToSupports(doc));
|
||||
|
||||
domRect->SetLayoutRect(rect);
|
||||
init.mBoundingClientRect = domRect;
|
||||
init.mVisible = false;
|
||||
|
||||
sel->Stringify(init.mSelectedText);
|
||||
|
||||
dom::Sequence<SelectionState> state;
|
||||
state.AppendElement(SelectionState::Taponcaret);
|
||||
init.mStates = state;
|
||||
|
||||
nsRefPtr<SelectionStateChangedEvent> event =
|
||||
SelectionStateChangedEvent::Constructor(doc, NS_LITERAL_STRING("mozselectionstatechanged"), init);
|
||||
|
||||
event->SetTrusted(true);
|
||||
event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
|
||||
bool ret;
|
||||
doc->DispatchEvent(domEvent, &ret);
|
||||
doc->DispatchEvent(event, &ret);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Загрузка…
Ссылка в новой задаче