Bug 1301312 - Part 5: Handle input element's attribute change explicitly. r=smaug

MozReview-Commit-ID: AswWoeGasXZ

--HG--
extra : rebase_source : 10591d31c76a4745a9953cd944533cb2fd6940b4
This commit is contained in:
Jessica Jong 2017-03-15 11:39:02 +08:00
Родитель 24b91bfb0b
Коммит a162417a23
3 изменённых файлов: 100 добавлений и 24 удалений

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

@ -33,4 +33,16 @@ interface nsIDateTimeInputArea : nsISupports
* Set the current state of the picker, true if it's opened, false otherwise.
*/
void setPickerState(in boolean isOpen);
/**
* Set the attribute of the inner text boxes. Only "tabindex", "readonly",
* and "disabled" are allowed.
*/
void setEditAttribute(in DOMString name, in DOMString value);
/**
* Remove the attribute of the inner text boxes. Only "tabindex", "readonly",
* and "disabled" are allowed.
*/
void removeEditAttribute(in DOMString name);
};

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

@ -316,21 +316,25 @@ nsDateTimeControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
NS_TrustedNewXULElement(getter_AddRefs(mInputAreaContent), nodeInfo.forget());
aElements.AppendElement(mInputAreaContent);
// Propogate our tabindex.
nsAutoString tabIndexStr;
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::tabindex, tabIndexStr)) {
mInputAreaContent->SetAttr(kNameSpaceID_None, nsGkAtoms::tabindex,
tabIndexStr, false);
}
nsCOMPtr<nsIDateTimeInputArea> inputAreaContent =
do_QueryInterface(mInputAreaContent);
if (inputAreaContent) {
// Propogate our tabindex.
nsAutoString tabIndexStr;
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::tabindex, tabIndexStr)) {
inputAreaContent->SetEditAttribute(NS_LITERAL_STRING("tabindex"),
tabIndexStr);
}
// Propagate our readonly state.
nsAutoString readonly;
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::readonly, readonly)) {
mInputAreaContent->SetAttr(kNameSpaceID_None, nsGkAtoms::readonly, readonly,
false);
}
// Propagate our readonly state.
nsAutoString readonly;
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::readonly, readonly)) {
inputAreaContent->SetEditAttribute(NS_LITERAL_STRING("readonly"),
readonly);
}
SyncDisabledState();
SyncDisabledState();
}
return NS_OK;
}
@ -347,12 +351,19 @@ nsDateTimeControlFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElement
void
nsDateTimeControlFrame::SyncDisabledState()
{
NS_ASSERTION(mInputAreaContent, "The input area content must exist!");
nsCOMPtr<nsIDateTimeInputArea> inputAreaContent =
do_QueryInterface(mInputAreaContent);
if (!inputAreaContent) {
return;
}
EventStates eventStates = mContent->AsElement()->State();
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
mInputAreaContent->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled,
EmptyString(), true);
inputAreaContent->SetEditAttribute(NS_LITERAL_STRING("disabled"),
EmptyString());
} else {
mInputAreaContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, true);
inputAreaContent->RemoveEditAttribute(NS_LITERAL_STRING("disabled"));
}
}
@ -374,22 +385,28 @@ nsDateTimeControlFrame::AttributeChanged(int32_t aNameSpaceID,
// then we don't need to do anything since we are going to be reframed.
if (contentAsInputElem->GetType() == NS_FORM_INPUT_TIME ||
contentAsInputElem->GetType() == NS_FORM_INPUT_DATE) {
nsCOMPtr<nsIDateTimeInputArea> inputAreaContent =
do_QueryInterface(mInputAreaContent);
if (aAttribute == nsGkAtoms::value) {
nsCOMPtr<nsIDateTimeInputArea> inputAreaContent =
do_QueryInterface(mInputAreaContent);
if (inputAreaContent) {
nsContentUtils::AddScriptRunner(NewRunnableMethod(inputAreaContent,
&nsIDateTimeInputArea::NotifyInputElementValueChanged));
}
} else {
if (aModType == nsIDOMMutationEvent::REMOVAL) {
mInputAreaContent->UnsetAttr(aNameSpaceID, aAttribute, true);
if (inputAreaContent) {
nsAtomString name(aAttribute);
inputAreaContent->RemoveEditAttribute(name);
}
} else {
MOZ_ASSERT(aModType == nsIDOMMutationEvent::ADDITION ||
aModType == nsIDOMMutationEvent::MODIFICATION);
nsAutoString value;
mContent->GetAttr(aNameSpaceID, aAttribute, value);
mInputAreaContent->SetAttr(aNameSpaceID, aAttribute, value, true);
if (inputAreaContent) {
nsAtomString name(aAttribute);
nsAutoString value;
mContent->GetAttr(aNameSpaceID, aAttribute, value);
inputAreaContent->SetEditAttribute(name, value);
}
}
}
}

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

@ -1280,6 +1280,53 @@
</body>
</method>
<method name="setEditAttribute">
<parameter name="aName"/>
<parameter name="aValue"/>
<body>
<![CDATA[
this.log("setAttribute: " + aName + "=" + aValue);
if (aName != "tabindex" && aName != "disabled" &&
aName != "readonly") {
return;
}
let editRoot =
document.getAnonymousElementByAttribute(this, "anonid", "edit-wrapper");
for (let child = editRoot.firstChild; child; child = child.nextSibling) {
if (child instanceof HTMLInputElement) {
child.setAttribute(aName, aValue);
}
}
]]>
</body>
</method>
<method name="removeEditAttribute">
<parameter name="aName"/>
<body>
<![CDATA[
this.log("removeAttribute: " + aName);
if (aName != "tabindex" && aName != "disabled" &&
aName != "readonly") {
return;
}
let editRoot =
document.getAnonymousElementByAttribute(this, "anonid", "edit-wrapper");
for (let child = editRoot.firstChild; child; child = child.nextSibling) {
if (child instanceof HTMLInputElement) {
child.removeAttribute(aName);
}
}
]]>
</body>
</method>
<method name="isEmpty">
<parameter name="aValue"/>
<body>
@ -1362,7 +1409,7 @@
<method name="isDisabled">
<body>
<![CDATA[
return this.hasAttribute("disabled");
return this.mInputElement.hasAttribute("disabled");
]]>
</body>
</method>
@ -1370,7 +1417,7 @@
<method name="isReadonly">
<body>
<![CDATA[
return this.hasAttribute("readonly");
return this.mInputElement.hasAttribute("readonly");
]]>
</body>
</method>