зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1455674 part 9. Remove nsIDOMElement use from nsIFocusManager. r=qdot
This commit is contained in:
Родитель
f33eebd4cb
Коммит
ffa08d7425
|
@ -11055,19 +11055,14 @@ nsIDocument::FullscreenElementReadyCheck(Element* aElement,
|
|||
return false;
|
||||
}
|
||||
// Deny requests when a windowed plugin is focused.
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (!fm) {
|
||||
NS_WARNING("Failed to retrieve focus manager in full-screen request.");
|
||||
return false;
|
||||
}
|
||||
nsCOMPtr<nsIDOMElement> focusedElement;
|
||||
fm->GetFocusedElement(getter_AddRefs(focusedElement));
|
||||
if (focusedElement) {
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(focusedElement);
|
||||
if (nsContentUtils::HasPluginWithUncontrolledEventDispatch(content)) {
|
||||
DispatchFullscreenError("FullscreenDeniedFocusedPlugin");
|
||||
return false;
|
||||
}
|
||||
if (nsContentUtils::HasPluginWithUncontrolledEventDispatch(fm->GetFocusedElement())) {
|
||||
DispatchFullscreenError("FullscreenDeniedFocusedPlugin");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -485,12 +485,10 @@ NS_IMETHODIMP nsFocusManager::SetFocusedWindow(mozIDOMWindowProxy* aWindowToFocu
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFocusManager::GetFocusedElement(nsIDOMElement** aFocusedElement)
|
||||
nsFocusManager::GetFocusedElement(Element** aFocusedElement)
|
||||
{
|
||||
if (mFocusedElement)
|
||||
CallQueryInterface(mFocusedElement, aFocusedElement);
|
||||
else
|
||||
*aFocusedElement = nullptr;
|
||||
RefPtr<Element> focusedElement = mFocusedElement;
|
||||
focusedElement.forget(aFocusedElement);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -637,7 +635,7 @@ NS_IMETHODIMP
|
|||
nsFocusManager::GetFocusedElementForWindow(mozIDOMWindowProxy* aWindow,
|
||||
bool aDeep,
|
||||
mozIDOMWindowProxy** aFocusedWindow,
|
||||
nsIDOMElement** aElement)
|
||||
Element** aElement)
|
||||
{
|
||||
*aElement = nullptr;
|
||||
if (aFocusedWindow)
|
||||
|
@ -647,13 +645,13 @@ nsFocusManager::GetFocusedElementForWindow(mozIDOMWindowProxy* aWindow,
|
|||
nsCOMPtr<nsPIDOMWindowOuter> window = nsPIDOMWindowOuter::From(aWindow);
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
|
||||
nsCOMPtr<nsIContent> focusedContent =
|
||||
RefPtr<Element> focusedElement =
|
||||
GetFocusedDescendant(window,
|
||||
aDeep ? nsFocusManager::eIncludeAllDescendants :
|
||||
nsFocusManager::eOnlyCurrentWindow,
|
||||
getter_AddRefs(focusedWindow));
|
||||
if (focusedContent)
|
||||
CallQueryInterface(focusedContent, aElement);
|
||||
|
||||
focusedElement.forget(aElement);
|
||||
|
||||
if (aFocusedWindow)
|
||||
NS_IF_ADDREF(*aFocusedWindow = focusedWindow);
|
||||
|
|
|
@ -4873,10 +4873,9 @@ nsGlobalWindowOuter::BlurOuter()
|
|||
// if the root is focused, clear the focus
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (fm && mDoc) {
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
RefPtr<Element> element;
|
||||
fm->GetFocusedElementForWindow(this, false, nullptr, getter_AddRefs(element));
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(element);
|
||||
if (content == mDoc->GetRootElement()) {
|
||||
if (element == mDoc->GetRootElement()) {
|
||||
fm->ClearFocus(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3379,12 +3379,10 @@ bool CanvasRenderingContext2D::DrawCustomFocusRing(mozilla::dom::Element& aEleme
|
|||
return false;
|
||||
}
|
||||
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (fm) {
|
||||
// check that the element i focused
|
||||
nsCOMPtr<nsIDOMElement> focusedElement;
|
||||
fm->GetFocusedElement(getter_AddRefs(focusedElement));
|
||||
if (SameCOMIdentity(aElement.AsDOMNode(), focusedElement)) {
|
||||
// check that the element is focused
|
||||
if (&aElement == fm->GetFocusedElement()) {
|
||||
if (nsPIDOMWindowOuter* window = aElement.OwnerDoc()->GetWindow()) {
|
||||
return window->ShouldShowFocusRing();
|
||||
}
|
||||
|
|
|
@ -3283,7 +3283,7 @@ HTMLInputElement::Select()
|
|||
}
|
||||
}
|
||||
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
|
||||
RefPtr<nsPresContext> presContext = GetPresContext(eForComposedDoc);
|
||||
if (state == eInactiveWindow) {
|
||||
|
@ -3297,9 +3297,7 @@ HTMLInputElement::Select()
|
|||
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
|
||||
|
||||
// ensure that the element is actually focused
|
||||
nsCOMPtr<nsIDOMElement> focusedElement;
|
||||
fm->GetFocusedElement(getter_AddRefs(focusedElement));
|
||||
if (SameCOMIdentity(static_cast<nsIDOMNode*>(this), focusedElement)) {
|
||||
if (this == fm->GetFocusedElement()) {
|
||||
// Now Select all the text!
|
||||
SelectAll(presContext);
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ HTMLTextAreaElement::Select()
|
|||
return;
|
||||
}
|
||||
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
|
||||
RefPtr<nsPresContext> presContext = GetPresContext(eForComposedDoc);
|
||||
if (state == eInactiveWindow) {
|
||||
|
@ -156,9 +156,7 @@ HTMLTextAreaElement::Select()
|
|||
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
|
||||
|
||||
// ensure that the element is actually focused
|
||||
nsCOMPtr<nsIDOMElement> focusedElement;
|
||||
fm->GetFocusedElement(getter_AddRefs(focusedElement));
|
||||
if (SameCOMIdentity(static_cast<nsIDOMNode*>(this), focusedElement)) {
|
||||
if (this == fm->GetFocusedElement()) {
|
||||
// Now Select all the text!
|
||||
SelectAll(presContext);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ interface nsIFocusManager : nsISupports
|
|||
* within the document loaded in focusedWindow or null if no element in that
|
||||
* document is focused.
|
||||
*/
|
||||
readonly attribute nsIDOMElement focusedElement;
|
||||
readonly attribute Element focusedElement;
|
||||
|
||||
/**
|
||||
* Returns the method that was used to focus the element in window. This
|
||||
|
@ -131,9 +131,9 @@ interface nsIFocusManager : nsISupports
|
|||
*
|
||||
* @throws NS_ERROR_INVALID_ARG if aWindow is null
|
||||
*/
|
||||
nsIDOMElement getFocusedElementForWindow(in mozIDOMWindowProxy aWindow,
|
||||
in boolean aDeep,
|
||||
out mozIDOMWindowProxy aFocusedWindow);
|
||||
Element getFocusedElementForWindow(in mozIDOMWindowProxy aWindow,
|
||||
in boolean aDeep,
|
||||
out mozIDOMWindowProxy aFocusedWindow);
|
||||
|
||||
/**
|
||||
* Moves the selection caret within aWindow to the current focus.
|
||||
|
|
|
@ -591,7 +591,7 @@ nsXBLWindowKeyHandler::HandleEventOnCaptureInSystemEventGroup(
|
|||
bool
|
||||
nsXBLWindowKeyHandler::IsHTMLEditableFieldFocused()
|
||||
{
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (!fm)
|
||||
return false;
|
||||
|
||||
|
@ -617,10 +617,8 @@ nsXBLWindowKeyHandler::IsHTMLEditableFieldFocused()
|
|||
return true;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMElement> focusedElement;
|
||||
fm->GetFocusedElement(getter_AddRefs(focusedElement));
|
||||
nsCOMPtr<nsINode> focusedNode = do_QueryInterface(focusedElement);
|
||||
if (focusedNode) {
|
||||
nsINode* focusedNode = fm->GetFocusedElement();
|
||||
if (focusedNode && focusedNode->IsElement()) {
|
||||
// If there is a focused element, make sure it's in the active editing host.
|
||||
// Note that GetActiveEditingHost finds the current editing host based on
|
||||
// the document's selection. Even though the document selection is usually
|
||||
|
|
|
@ -4953,13 +4953,11 @@ HTMLEditor::GetFocusedNode()
|
|||
// FocusedContent() returns the root element, but we want to return
|
||||
// the document.
|
||||
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
NS_ASSERTION(fm, "Focus manager is null");
|
||||
nsCOMPtr<nsIDOMElement> focusedElement;
|
||||
fm->GetFocusedElement(getter_AddRefs(focusedElement));
|
||||
RefPtr<Element> focusedElement = fm->GetFocusedElement();
|
||||
if (focusedElement) {
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(focusedElement);
|
||||
return node.forget();
|
||||
return focusedElement.forget();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> document = GetDocument();
|
||||
|
|
|
@ -6507,15 +6507,14 @@ PresShell::GetFocusedDOMWindowInOurWindow()
|
|||
already_AddRefed<nsIContent>
|
||||
nsIPresShell::GetFocusedContentInOurWindow() const
|
||||
{
|
||||
nsCOMPtr<nsIContent> focusedContent;
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (fm && mDocument) {
|
||||
nsCOMPtr<nsIDOMElement> focusedElement;
|
||||
RefPtr<Element> focusedElement;
|
||||
fm->GetFocusedElementForWindow(mDocument->GetWindow(), false, nullptr,
|
||||
getter_AddRefs(focusedElement));
|
||||
focusedContent = do_QueryInterface(focusedElement);
|
||||
return focusedElement.forget();
|
||||
}
|
||||
return focusedContent.forget();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIPresShell>
|
||||
|
@ -8189,10 +8188,11 @@ PresShell::AdjustContextMenuKeyEvent(WidgetMouseEvent* aEvent)
|
|||
// If we're here because of the key-equiv for showing context menus, we
|
||||
// have to reset the event target to the currently focused element. Get it
|
||||
// from the focus controller.
|
||||
nsCOMPtr<nsIDOMElement> currentFocus;
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (fm)
|
||||
fm->GetFocusedElement(getter_AddRefs(currentFocus));
|
||||
RefPtr<Element> currentFocus;
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (fm) {
|
||||
currentFocus = fm->GetFocusedElement();
|
||||
}
|
||||
|
||||
// Reset event coordinates relative to focused frame in view
|
||||
if (currentFocus) {
|
||||
|
@ -8332,12 +8332,12 @@ PresShell::PrepareToUseCaretPosition(nsIWidget* aEventWidget,
|
|||
}
|
||||
|
||||
void
|
||||
PresShell::GetCurrentItemAndPositionForElement(nsIDOMElement *aCurrentEl,
|
||||
PresShell::GetCurrentItemAndPositionForElement(Element* aFocusedElement,
|
||||
nsIContent** aTargetToUse,
|
||||
LayoutDeviceIntPoint& aTargetPt,
|
||||
nsIWidget *aRootWidget)
|
||||
{
|
||||
nsCOMPtr<nsIContent> focusedContent(do_QueryInterface(aCurrentEl));
|
||||
nsCOMPtr<nsIContent> focusedContent = aFocusedElement;
|
||||
ScrollContentIntoView(focusedContent,
|
||||
ScrollAxis(),
|
||||
ScrollAxis(),
|
||||
|
@ -8355,7 +8355,7 @@ PresShell::GetCurrentItemAndPositionForElement(nsIDOMElement *aCurrentEl,
|
|||
// as is.
|
||||
nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
|
||||
do_QueryInterface(aCurrentEl);
|
||||
do_QueryInterface(aFocusedElement);
|
||||
if (multiSelect) {
|
||||
checkLineHeight = false;
|
||||
|
||||
|
@ -8407,10 +8407,10 @@ PresShell::GetCurrentItemAndPositionForElement(nsIDOMElement *aCurrentEl,
|
|||
}
|
||||
else {
|
||||
// don't check menulists as the selected item will be inside a popup.
|
||||
nsCOMPtr<nsIDOMXULMenuListElement> menulist = do_QueryInterface(aCurrentEl);
|
||||
nsCOMPtr<nsIDOMXULMenuListElement> menulist = do_QueryInterface(aFocusedElement);
|
||||
if (!menulist) {
|
||||
nsCOMPtr<nsIDOMXULSelectControlElement> select =
|
||||
do_QueryInterface(aCurrentEl);
|
||||
do_QueryInterface(aFocusedElement);
|
||||
if (select) {
|
||||
checkLineHeight = false;
|
||||
select->GetSelectedItem(getter_AddRefs(item));
|
||||
|
|
|
@ -695,7 +695,7 @@ private:
|
|||
|
||||
// Get the selected item and coordinates in device pixels relative to root
|
||||
// document's root view for element, first ensuring the element is onscreen
|
||||
void GetCurrentItemAndPositionForElement(nsIDOMElement *aCurrentEl,
|
||||
void GetCurrentItemAndPositionForElement(dom::Element* aFocusedElement,
|
||||
nsIContent **aTargetToUse,
|
||||
LayoutDeviceIntPoint& aTargetPt,
|
||||
nsIWidget *aRootWidget);
|
||||
|
|
|
@ -1496,7 +1496,7 @@ nsXULPopupManager::FirePopupShowingEvent(nsIContent* aPopup,
|
|||
!popup->AsElement()->AttrValueIs(kNameSpaceID_None,
|
||||
nsGkAtoms::noautofocus,
|
||||
nsGkAtoms::_true, eCaseMatters)) {
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (fm) {
|
||||
nsIDocument* doc = popup->GetUncomposedDoc();
|
||||
|
||||
|
@ -1505,9 +1505,7 @@ nsXULPopupManager::FirePopupShowingEvent(nsIContent* aPopup,
|
|||
// inside the popup as that shouldn't be visible. This check ensures that
|
||||
// a node inside the popup that is focused during a popupshowing event
|
||||
// remains focused.
|
||||
nsCOMPtr<nsIDOMElement> currentFocusElement;
|
||||
fm->GetFocusedElement(getter_AddRefs(currentFocusElement));
|
||||
nsCOMPtr<nsIContent> currentFocus = do_QueryInterface(currentFocusElement);
|
||||
RefPtr<Element> currentFocus = fm->GetFocusedElement();
|
||||
if (doc && currentFocus &&
|
||||
!nsContentUtils::ContentIsCrossDocDescendantOf(currentFocus, popup)) {
|
||||
fm->ClearFocus(doc->GetWindow());
|
||||
|
@ -1568,14 +1566,12 @@ nsXULPopupManager::FirePopupHidingEvent(nsIContent* aPopup,
|
|||
!aPopup->AsElement()->AttrValueIs(kNameSpaceID_None,
|
||||
nsGkAtoms::noautofocus,
|
||||
nsGkAtoms::_true, eCaseMatters))) {
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (fm) {
|
||||
nsIDocument* doc = aPopup->GetUncomposedDoc();
|
||||
|
||||
// Remove the focus from the focused node only if it is inside the popup.
|
||||
nsCOMPtr<nsIDOMElement> currentFocusElement;
|
||||
fm->GetFocusedElement(getter_AddRefs(currentFocusElement));
|
||||
nsCOMPtr<nsIContent> currentFocus = do_QueryInterface(currentFocusElement);
|
||||
RefPtr<Element> currentFocus = fm->GetFocusedElement();
|
||||
if (doc && currentFocus &&
|
||||
nsContentUtils::ContentIsCrossDocDescendantOf(currentFocus, aPopup)) {
|
||||
fm->ClearFocus(doc->GetWindow());
|
||||
|
|
|
@ -1855,7 +1855,7 @@ nsWebBrowser::GetFocusedWindow(mozIDOMWindowProxy** aFocusedWindow)
|
|||
nsCOMPtr<nsPIDOMWindowOuter> window = mDocShell->GetWindow();
|
||||
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDOMElement> focusedElement;
|
||||
RefPtr<Element> focusedElement;
|
||||
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
|
||||
return fm ? fm->GetFocusedElementForWindow(window, true, aFocusedWindow,
|
||||
getter_AddRefs(focusedElement)) :
|
||||
|
@ -1885,17 +1885,7 @@ nsWebBrowser::GetFocusedElement(dom::Element** aFocusedElement)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
nsresult rv =
|
||||
fm->GetFocusedElementForWindow(window, true, nullptr,
|
||||
getter_AddRefs(element));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!element) {
|
||||
*aFocusedElement = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return CallQueryInterface(element, aFocusedElement);
|
||||
return fm->GetFocusedElementForWindow(window, true, nullptr, aFocusedElement);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -1092,15 +1092,14 @@ nsTypeAheadFind::Find(const nsAString& aSearchString, bool aLinksOnly,
|
|||
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
|
||||
if (fm) {
|
||||
nsPIDOMWindowOuter* window = document->GetWindow();
|
||||
nsCOMPtr<nsIDOMElement> focusedElement;
|
||||
RefPtr<Element> focusedElement;
|
||||
nsCOMPtr<mozIDOMWindowProxy> focusedWindow;
|
||||
fm->GetFocusedElementForWindow(window, false,
|
||||
getter_AddRefs(focusedWindow),
|
||||
getter_AddRefs(focusedElement));
|
||||
// If the root element is focused, then it's actually the document
|
||||
// that has the focus, so ignore this.
|
||||
if (focusedElement &&
|
||||
!SameCOMIdentity(focusedElement, document->GetRootElement())) {
|
||||
if (focusedElement && focusedElement != document->GetRootElement()) {
|
||||
fm->MoveCaretToFocus(window);
|
||||
isFirstVisiblePreferred = false;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче