/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
void SelectionManager::ClearControlSelectionListener() { // Remove 'this' registered as selection listener for the normal selection. if (mCurrCtrlNormalSel) {
mCurrCtrlNormalSel->RemoveSelectionListener(this);
mCurrCtrlNormalSel = nullptr;
}
}
void SelectionManager::SetControlSelectionListener(dom::Element* aFocusedElm) { // When focus moves such that the caret is part of a new frame selection // this removes the old selection listener and attaches a new one for // the current focus.
ClearControlSelectionListener();
nsIFrame* controlFrame = aFocusedElm->GetPrimaryFrame(); if (!controlFrame) return;
const nsFrameSelection* frameSel = controlFrame->GetConstFrameSelection();
NS_ASSERTION(frameSel, "No frame selection for focused element!"); if (!frameSel) return;
// Register 'this' as selection listener for the normal selection.
Selection& normalSel = frameSel->NormalSelection();
normalSel.AddSelectionListener(this);
mCurrCtrlNormalSel = &normalSel;
}
// Register 'this' as selection listener for the normal selection.
Selection& normalSel = frameSel->NormalSelection();
normalSel.AddSelectionListener(this);
}
// Remove 'this' registered as selection listener for the normal selection.
Selection& normalSel = frameSel->NormalSelection();
normalSel.RemoveSelectionListener(this);
if (mCurrCtrlNormalSel) { if (mCurrCtrlNormalSel->GetPresShell() == aPresShell) { // Remove 'this' registered as selection listener for the normal selection // if we are removing listeners for its PresShell.
mCurrCtrlNormalSel->RemoveSelectionListener(this);
mCurrCtrlNormalSel = nullptr;
}
}
}
void SelectionManager::ProcessTextSelChangeEvent(AccEvent* aEvent) { // Fire selection change event if it's not pure caret-move selection change, // i.e. the accessible has or had not collapsed selection. Also, it must not // be a collapsed selection on the container of a focused text field, since // the text field has an independent selection and will thus fire its own // selection events.
AccTextSelChangeEvent* event = downcast_accEvent(aEvent); if (!event->IsCaretMoveOnly() &&
!(event->mSel->IsCollapsed() && event->mSel != mCurrCtrlNormalSel &&
FocusMgr() && FocusMgr()->FocusedLocalAccessible() &&
FocusMgr()->FocusedLocalAccessible()->IsTextField())) {
nsEventShell::FireEvent(aEvent);
}
// Fire caret move event if there's a caret in the selection.
nsINode* caretCntrNode = nsCoreUtils::GetDOMNodeFromDOMPoint(
event->mSel->GetFocusNode(), event->mSel->FocusOffset()); if (!caretCntrNode) return;
HyperTextAccessible* caretCntr = nsAccUtils::GetTextContainer(caretCntrNode);
NS_ASSERTION(
caretCntr, "No text container for focus while there's one for common ancestor?!"); if (!caretCntr) return;
Selection* selection = caretCntr->DOMSelection();
// XXX Sometimes we can't get a selection for caretCntr, in that case assume // event->mSel is correct. if (!selection) selection = event->mSel;
#ifdef A11Y_LOG if (logging::IsEnabled(logging::eSelection)) {
logging::SelChange(aSelection, document, aReason);
} #endif
if (document) { // Selection manager has longer lifetime than any document accessible, // so that we are guaranteed that the notification is processed before // the selection manager is destroyed.
RefPtr<SelData> selData = new SelData(aSelection, aReason, aAmount);
document->HandleNotification<SelectionManager, SelData>( this, &SelectionManager::ProcessSelectionChanged, selData);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.