зеркало из https://github.com/mozilla/gecko-dev.git
Bug 795610 - Part e: Prepare HTMLElement.focus() for WebIDL bindings; r=mounir
This commit is contained in:
Родитель
d34370b699
Коммит
7053e6b5df
|
@ -484,7 +484,7 @@ HTMLTextFieldAccessible::DoAction(uint8_t aIndex)
|
|||
if (aIndex == 0) {
|
||||
nsHTMLInputElement* element = nsHTMLInputElement::FromContent(mContent);
|
||||
if (element)
|
||||
return element->Focus();
|
||||
return element->DOMFocus();
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ public:
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> topDoc = do_QueryInterface(window->GetExtantDocument());
|
||||
nsCOMPtr<nsIDocument> topDoc = window->GetExtantDoc();
|
||||
if (topDoc && topDoc->GetReadyStateEnum() == nsIDocument::READYSTATE_COMPLETE) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -202,7 +202,9 @@ public:
|
|||
// If something is focused in the same document, ignore autofocus.
|
||||
if (!fm->GetFocusedContent() ||
|
||||
fm->GetFocusedContent()->OwnerDoc() != document) {
|
||||
return mElement->Focus();
|
||||
mozilla::ErrorResult rv;
|
||||
mElement->Focus(rv);
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -3800,12 +3802,14 @@ nsGenericHTMLElement::Blur()
|
|||
return (win && fm) ? fm->ClearFocus(win) : NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericHTMLElement::Focus()
|
||||
void
|
||||
nsGenericHTMLElement::Focus(ErrorResult& aError)
|
||||
{
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(this);
|
||||
return fm ? fm->SetFocus(elem, 0) : NS_OK;
|
||||
if (fm) {
|
||||
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(this);
|
||||
aError = fm->SetFocus(elem, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -94,6 +94,7 @@ public:
|
|||
{
|
||||
aError = SetIntAttr(nsGkAtoms::tabindex, aTabIndex);
|
||||
}
|
||||
virtual void Focus(mozilla::ErrorResult& aError);
|
||||
virtual bool Draggable() const
|
||||
{
|
||||
return AttrValueIs(kNameSpaceID_None, nsGkAtoms::draggable,
|
||||
|
@ -136,6 +137,11 @@ public:
|
|||
SetTabIndex(aTabIndex, rv);
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
nsresult DOMFocus() {
|
||||
mozilla::ErrorResult rv;
|
||||
Focus(rv);
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
nsresult GetDraggable(bool* aDraggable)
|
||||
{
|
||||
*aDraggable = Draggable();
|
||||
|
@ -160,10 +166,9 @@ public:
|
|||
NS_IMETHOD InsertAdjacentHTML(const nsAString& aPosition,
|
||||
const nsAString& aText);
|
||||
nsresult ScrollIntoView(bool aTop, uint8_t optional_argc);
|
||||
// Declare Focus(), Blur(), GetHidden(), SetHidden(), GetSpellcheck(), and
|
||||
// Declare Blur(), GetHidden(), SetHidden(), GetSpellcheck(), and
|
||||
// SetSpellcheck() such that classes that inherit interfaces with those
|
||||
// methods properly override them.
|
||||
NS_IMETHOD Focus();
|
||||
NS_IMETHOD Blur();
|
||||
NS_IMETHOD GetHidden(bool* aHidden);
|
||||
NS_IMETHOD SetHidden(bool aHidden);
|
||||
|
@ -1401,7 +1406,6 @@ protected:
|
|||
/* Use this macro to declare functions that forward the behavior of this
|
||||
* interface to another object.
|
||||
* This macro doesn't forward
|
||||
* - Focus
|
||||
* - GetInnerHTML
|
||||
* - SetInnerHTML
|
||||
* because sometimes elements want to override them.
|
||||
|
@ -1455,6 +1459,9 @@ protected:
|
|||
NS_IMETHOD SetTabIndex(int32_t aTabIndex) { \
|
||||
return _to SetTabIndex(aTabIndex); \
|
||||
} \
|
||||
NS_IMETHOD DOMFocus() { \
|
||||
return _to DOMFocus(); \
|
||||
} \
|
||||
NS_IMETHOD Blur() { \
|
||||
return _to Blur(); \
|
||||
} \
|
||||
|
|
|
@ -28,9 +28,6 @@ public:
|
|||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT_BASIC(nsGenericHTMLElement::)
|
||||
NS_IMETHOD Focus() {
|
||||
return nsGenericHTMLElement::Focus();
|
||||
}
|
||||
NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML);
|
||||
NS_IMETHOD SetInnerHTML(const nsAString& aInnerHTML) {
|
||||
return nsGenericHTMLElement::SetInnerHTML(aInnerHTML);
|
||||
|
|
|
@ -1872,11 +1872,12 @@ nsHTMLInputElement::SetCheckedInternal(bool aChecked, bool aNotify)
|
|||
UpdateState(aNotify);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::Focus()
|
||||
void
|
||||
nsHTMLInputElement::Focus(ErrorResult& aError)
|
||||
{
|
||||
if (mType != NS_FORM_INPUT_FILE) {
|
||||
return nsGenericHTMLElement::Focus();
|
||||
nsGenericHTMLElement::Focus(aError);
|
||||
return;
|
||||
}
|
||||
|
||||
// For file inputs, focus the button instead.
|
||||
|
@ -1899,7 +1900,7 @@ nsHTMLInputElement::Focus()
|
|||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -2389,7 +2390,7 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
|||
nsCOMPtr<nsIContent> radioContent =
|
||||
do_QueryInterface(selectedRadioButton);
|
||||
if (radioContent) {
|
||||
rv = selectedRadioButton->Focus();
|
||||
rv = selectedRadioButton->DOMFocus();
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
nsMouseEvent event(NS_IS_TRUSTED_EVENT(aVisitor.mEvent),
|
||||
|
|
|
@ -75,16 +75,10 @@ public:
|
|||
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
|
||||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT_BASIC(nsGenericHTMLFormElement::)
|
||||
NS_IMETHOD Focus();
|
||||
NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) {
|
||||
return nsGenericHTMLFormElement::GetInnerHTML(aInnerHTML);
|
||||
}
|
||||
NS_IMETHOD SetInnerHTML(const nsAString& aInnerHTML) {
|
||||
return nsGenericHTMLFormElement::SetInnerHTML(aInnerHTML);
|
||||
}
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
|
||||
virtual void Click() MOZ_OVERRIDE;
|
||||
virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
|
||||
virtual void Focus(mozilla::ErrorResult& aError) MOZ_OVERRIDE;
|
||||
|
||||
// nsIDOMHTMLInputElement
|
||||
NS_DECL_NSIDOMHTMLINPUTELEMENT
|
||||
|
|
|
@ -20,9 +20,11 @@
|
|||
#include "nsEventDispatcher.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsFocusManager.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
|
||||
// construction, destruction
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
NS_IMPL_NS_NEW_HTML_ELEMENT(Label)
|
||||
|
@ -79,8 +81,8 @@ nsHTMLLabelElement::GetControl(nsIDOMHTMLElement** aElement)
|
|||
|
||||
NS_IMPL_STRING_ATTR(nsHTMLLabelElement, HtmlFor, _for)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLLabelElement::Focus()
|
||||
void
|
||||
nsHTMLLabelElement::Focus(ErrorResult& aError)
|
||||
{
|
||||
// retarget the focus method at the for content
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
|
@ -89,8 +91,6 @@ nsHTMLLabelElement::Focus()
|
|||
if (elem)
|
||||
fm->SetFocus(elem, 0);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -41,14 +41,8 @@ public:
|
|||
NS_DECL_NSIDOMHTMLLABELELEMENT
|
||||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT_BASIC(nsGenericHTMLFormElement::)
|
||||
NS_IMETHOD Focus();
|
||||
NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) {
|
||||
return nsGenericHTMLFormElement::GetInnerHTML(aInnerHTML);
|
||||
}
|
||||
NS_IMETHOD SetInnerHTML(const nsAString& aInnerHTML) {
|
||||
return nsGenericHTMLFormElement::SetInnerHTML(aInnerHTML);
|
||||
}
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
|
||||
virtual void Focus(mozilla::ErrorResult& aError) MOZ_OVERRIDE;
|
||||
|
||||
// nsIFormControl
|
||||
NS_IMETHOD_(uint32_t) GetType() const { return NS_FORM_LABEL; }
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
#include "nsFocusManager.h"
|
||||
#include "nsIFrame.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
NS_IMPL_NS_NEW_HTML_ELEMENT(Legend)
|
||||
|
||||
|
||||
|
@ -137,27 +140,31 @@ nsHTMLLegendElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
|||
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLLegendElement::Focus()
|
||||
void
|
||||
nsHTMLLegendElement::Focus(ErrorResult& aError)
|
||||
{
|
||||
nsIFrame* frame = GetPrimaryFrame();
|
||||
if (!frame)
|
||||
return NS_OK;
|
||||
if (!frame) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t tabIndex;
|
||||
if (frame->IsFocusable(&tabIndex, false))
|
||||
return nsGenericHTMLElement::Focus();
|
||||
if (frame->IsFocusable(&tabIndex, false)) {
|
||||
nsGenericHTMLElement::Focus(aError);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the legend isn't focusable, focus whatever is focusable following
|
||||
// the legend instead, bug 81481.
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (!fm)
|
||||
return NS_OK;
|
||||
if (!fm) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMElement> result;
|
||||
return fm->MoveFocus(nullptr, this, nsIFocusManager::MOVEFOCUS_FORWARD,
|
||||
nsIFocusManager::FLAG_NOPARENTFRAME,
|
||||
getter_AddRefs(result));
|
||||
aError = fm->MoveFocus(nullptr, this, nsIFocusManager::MOVEFOCUS_FORWARD,
|
||||
nsIFocusManager::FLAG_NOPARENTFRAME,
|
||||
getter_AddRefs(result));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -165,6 +172,7 @@ nsHTMLLegendElement::PerformAccesskey(bool aKeyCausesActivation,
|
|||
bool aIsTrustedEvent)
|
||||
{
|
||||
// just use the same behaviour as the focus method
|
||||
Focus();
|
||||
mozilla::ErrorResult rv;
|
||||
Focus(rv);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,14 +36,8 @@ public:
|
|||
NS_DECL_NSIDOMHTMLLEGENDELEMENT
|
||||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT_BASIC(nsGenericHTMLElement::)
|
||||
NS_IMETHOD Focus();
|
||||
NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) {
|
||||
return nsGenericHTMLElement::GetInnerHTML(aInnerHTML);
|
||||
}
|
||||
NS_IMETHOD SetInnerHTML(const nsAString& aInnerHTML) {
|
||||
return nsGenericHTMLElement::SetInnerHTML(aInnerHTML);
|
||||
}
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
|
||||
virtual void Focus(mozilla::ErrorResult& aError) MOZ_OVERRIDE;
|
||||
|
||||
virtual void PerformAccesskey(bool aKeyCausesActivation,
|
||||
bool aIsTrustedEvent);
|
||||
|
|
|
@ -50,9 +50,6 @@ public:
|
|||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT_BASIC(nsGenericHTMLElement::)
|
||||
NS_IMETHOD Focus() {
|
||||
return nsGenericHTMLElement::Focus();
|
||||
}
|
||||
NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML);
|
||||
NS_IMETHOD SetInnerHTML(const nsAString& aInnerHTML);
|
||||
|
||||
|
|
|
@ -38,9 +38,6 @@ public:
|
|||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT_BASIC(nsGenericHTMLElement::)
|
||||
NS_IMETHOD Focus() {
|
||||
return nsGenericHTMLElement::Focus();
|
||||
}
|
||||
NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML);
|
||||
NS_IMETHOD SetInnerHTML(const nsAString& aInnerHTML);
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ interface nsIDOMHTMLElement : nsIDOMElement
|
|||
[binaryname(DOMClick)]
|
||||
void click();
|
||||
attribute long tabIndex;
|
||||
[binaryname(DOMFocus)]
|
||||
void focus();
|
||||
void blur();
|
||||
attribute DOMString accessKey;
|
||||
|
|
Загрузка…
Ссылка в новой задаче