Bug 1507895 - Part II, Remove the datetimebox binding r=smaug

This patch removes the datetimebox binding and always use
UA Widget for the job.

Depends on D17571

Differential Revision: https://phabricator.services.mozilla.com/D17572
This commit is contained in:
Timothy Guan-tin Chien
2019-01-28 18:32:39 +00:00
parent 08bfd1c4d4
commit 3c2ce5972b
51 changed files with 61 additions and 11485 deletions

View File

@@ -52,7 +52,6 @@
#include "nsError.h"
#include "nsIEditor.h"
#include "nsAttrValueOrString.h"
#include "nsDateTimeControlFrame.h"
#include "mozilla/PresState.h"
#include "nsLinebreakConverter.h" //to strip out carriage returns
@@ -2057,28 +2056,22 @@ void HTMLInputElement::GetDateTimeInputBoxValue(DateTimeValue& aValue) {
aValue = *mDateTimeInputBoxValue;
}
Element* HTMLInputElement::GetDateTimeBoxElementInUAWidget() {
if (GetShadowRoot()) {
// The datetimebox <div> is the only child of the UA Widget Shadow Root
// if it is present.
MOZ_ASSERT(GetShadowRoot()->IsUAWidget());
MOZ_ASSERT(1 >= GetShadowRoot()->GetChildCount());
if (nsIContent* inputAreaContent = GetShadowRoot()->GetFirstChild()) {
return inputAreaContent->AsElement();
}
Element* HTMLInputElement::GetDateTimeBoxElement() {
if (!GetShadowRoot()) {
return nullptr;
}
// The datetimebox <div> is the only child of the UA Widget Shadow Root
// if it is present.
MOZ_ASSERT(GetShadowRoot()->IsUAWidget());
MOZ_ASSERT(1 >= GetShadowRoot()->GetChildCount());
if (nsIContent* inputAreaContent = GetShadowRoot()->GetFirstChild()) {
return inputAreaContent->AsElement();
}
return nullptr;
}
Element* HTMLInputElement::GetDateTimeBoxElement() {
nsDateTimeControlFrame* frame = do_QueryFrame(GetPrimaryFrame());
if (frame && frame->GetInputAreaContent()) {
return frame->GetInputAreaContent()->AsElement();
}
return GetDateTimeBoxElementInUAWidget();
}
void HTMLInputElement::OpenDateTimePicker(const DateTimeValue& aInitialValue) {
if (NS_WARN_IF(!IsDateTimeInputType(mType))) {
return;
@@ -2634,17 +2627,12 @@ nsresult HTMLInputElement::SetValueInternal(const nsAString& aValue,
mType == NS_FORM_INPUT_DATE) &&
!IsExperimentalMobileType(mType) &&
!(aFlags & nsTextEditorState::eSetValue_BySetUserInput)) {
if (Element* dateTimeBoxElement = GetDateTimeBoxElementInUAWidget()) {
if (Element* dateTimeBoxElement = GetDateTimeBoxElement()) {
AsyncEventDispatcher* dispatcher = new AsyncEventDispatcher(
dateTimeBoxElement,
NS_LITERAL_STRING("MozDateTimeValueChanged"), CanBubble::eNo,
ChromeOnlyDispatch::eNo);
dispatcher->RunDOMEventWhenSafe();
} else {
nsDateTimeControlFrame* frame = do_QueryFrame(GetPrimaryFrame());
if (frame) {
frame->OnValueChanged();
}
}
}
if (mDoneCreating) {
@@ -2931,18 +2919,12 @@ void HTMLInputElement::Blur(ErrorResult& aError) {
if ((mType == NS_FORM_INPUT_TIME || mType == NS_FORM_INPUT_DATE) &&
!IsExperimentalMobileType(mType)) {
if (Element* dateTimeBoxElement = GetDateTimeBoxElementInUAWidget()) {
if (Element* dateTimeBoxElement = GetDateTimeBoxElement()) {
AsyncEventDispatcher* dispatcher = new AsyncEventDispatcher(
dateTimeBoxElement, NS_LITERAL_STRING("MozBlurInnerTextBox"),
CanBubble::eNo, ChromeOnlyDispatch::eNo);
dispatcher->RunDOMEventWhenSafe();
return;
} else {
nsDateTimeControlFrame* frame = do_QueryFrame(GetPrimaryFrame());
if (frame) {
frame->HandleBlurEvent();
return;
}
}
}
@@ -2965,18 +2947,12 @@ void HTMLInputElement::Focus(ErrorResult& aError) {
if ((mType == NS_FORM_INPUT_TIME || mType == NS_FORM_INPUT_DATE) &&
!IsExperimentalMobileType(mType)) {
if (Element* dateTimeBoxElement = GetDateTimeBoxElementInUAWidget()) {
if (Element* dateTimeBoxElement = GetDateTimeBoxElement()) {
AsyncEventDispatcher* dispatcher = new AsyncEventDispatcher(
dateTimeBoxElement, NS_LITERAL_STRING("MozFocusInnerTextBox"),
CanBubble::eNo, ChromeOnlyDispatch::eNo);
dispatcher->RunDOMEventWhenSafe();
return;
} else {
nsDateTimeControlFrame* frame = do_QueryFrame(GetPrimaryFrame());
if (frame) {
frame->HandleFocusEvent();
return;
}
}
}
@@ -3285,16 +3261,11 @@ void HTMLInputElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
aVisitor.mEvent->mOriginalTarget == this) {
// If original target is this and not the inner text control, we should
// pass the focus to the inner text control.
if (Element* dateTimeBoxElement = GetDateTimeBoxElementInUAWidget()) {
if (Element* dateTimeBoxElement = GetDateTimeBoxElement()) {
AsyncEventDispatcher* dispatcher = new AsyncEventDispatcher(
dateTimeBoxElement, NS_LITERAL_STRING("MozFocusInnerTextBox"),
CanBubble::eNo, ChromeOnlyDispatch::eNo);
dispatcher->RunDOMEventWhenSafe();
} else {
nsDateTimeControlFrame* frame = do_QueryFrame(GetPrimaryFrame());
if (frame) {
frame->HandleFocusEvent();
}
}
}
@@ -4370,7 +4341,7 @@ nsresult HTMLInputElement::BindToTree(Document* aDocument, nsIContent* aParent,
UpdateState(false);
if ((mType == NS_FORM_INPUT_TIME || mType == NS_FORM_INPUT_DATE) &&
nsContentUtils::IsUAWidgetEnabled() && IsInComposedDoc()) {
IsInComposedDoc()) {
// Construct Shadow Root so web content can be hidden in the DOM.
AttachAndSetUAShadowRoot();
NotifyUAWidgetSetupOrChange();
@@ -4403,7 +4374,7 @@ void HTMLInputElement::UnbindFromTree(bool aDeep, bool aNullParent) {
}
if ((mType == NS_FORM_INPUT_TIME || mType == NS_FORM_INPUT_DATE) &&
nsContentUtils::IsUAWidgetEnabled() && IsInComposedDoc()) {
IsInComposedDoc()) {
NotifyUAWidgetTeardown();
}
@@ -4582,7 +4553,7 @@ void HTMLInputElement::HandleTypeChange(uint8_t aNewType, bool aNotify) {
dispatcher->PostDOMEvent();
}
if (nsContentUtils::IsUAWidgetEnabled() && IsInComposedDoc()) {
if (IsInComposedDoc()) {
if (oldType == NS_FORM_INPUT_TIME || oldType == NS_FORM_INPUT_DATE) {
if (mType != NS_FORM_INPUT_TIME && mType != NS_FORM_INPUT_DATE) {
// Switch away from date/time type.