Bug 396542 nsFocusManager should restore caret browsing mode when an editor loses focus r=ehsan

This commit is contained in:
Masayuki Nakano 2013-05-22 12:28:43 +09:00
parent 99a6af2d1d
commit 94c8042239
3 changed files with 19 additions and 6 deletions

View File

@ -213,7 +213,7 @@ nsFocusManager::Observe(nsISupports *aSubject,
if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
nsDependentString data(aData);
if (data.EqualsLiteral("accessibility.browsewithcaret")) {
UpdateCaret(false, true, mFocusedContent);
UpdateCaretForCaretBrowsingMode();
}
else if (data.EqualsLiteral("accessibility.tabfocus_applies_to_xul")) {
nsIContent::sTabFocusModelAppliesToXUL =
@ -1994,6 +1994,12 @@ nsFocusManager::RaiseWindow(nsPIDOMWindow* aWindow)
#endif
}
void
nsFocusManager::UpdateCaretForCaretBrowsingMode()
{
UpdateCaret(false, true, mFocusedContent);
}
void
nsFocusManager::UpdateCaret(bool aMoveCaretToFocus,
bool aUpdateVisibility,
@ -2139,6 +2145,8 @@ nsFocusManager::SetCaretVisible(nsIPresShell* aPresShell,
// First, hide the caret to prevent attempting to show it in SetCaretDOMSelection
caret->SetCaretVisible(false);
// Caret must blink on non-editable elements
caret->SetIgnoreUserModify(true);
// Tell the caret which selection to use
caret->SetCaretDOMSelection(domSelection);
@ -2150,6 +2158,7 @@ nsFocusManager::SetCaretVisible(nsIPresShell* aPresShell,
if (!selCon)
return NS_ERROR_FAILURE;
selCon->SetCaretReadOnly(false);
selCon->SetCaretEnabled(aVisible);
caret->SetCaretVisible(aVisible);
}

View File

@ -84,6 +84,11 @@ public:
mMouseDownEventHandlingDocument = aDocument;
}
/**
* Update the caret with current mode (whether in caret browsing mode or not).
*/
void UpdateCaretForCaretBrowsingMode();
/**
* Returns the content node that would be focused if aWindow was in an
* active window. This will traverse down the frame hierarchy, starting at

View File

@ -4977,13 +4977,12 @@ nsEditor::FinalizeSelection()
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
NS_ENSURE_TRUE_VOID(presShell);
nsRefPtr<nsCaret> caret = presShell->GetCaret();
if (caret) {
caret->SetIgnoreUserModify(true);
}
selCon->SetCaretEnabled(false);
nsFocusManager* fm = nsFocusManager::GetFocusManager();
NS_ENSURE_TRUE_VOID(fm);
fm->UpdateCaretForCaretBrowsingMode();
if (!HasIndependentSelection()) {
// If this editor doesn't have an independent selection, i.e., it must
// mean that it is an HTML editor, the selection controller is shared with