Bug 1120750 - Part 3: Dispatch taponcaret using selectionstatechanged event. r=roc

This commit is contained in:
Morris Tseng 2015-01-21 23:42:00 -05:00
Родитель 868f2258f9
Коммит 1b3e94152e
3 изменённых файлов: 37 добавлений и 14 удалений

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

@ -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