Skip to content

Commit

Permalink
Bug 1620867 - Move all InputTypes into mozilla::dom namespace. r=smaug
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D65918

--HG--
extra : moz-landing-system : lando
  • Loading branch information
hiikezoe committed Mar 10, 2020
1 parent 45bbeae commit 42615ab
Show file tree
Hide file tree
Showing 18 changed files with 293 additions and 270 deletions.
4 changes: 2 additions & 2 deletions dom/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/dom/Directory.h"
#include "mozilla/dom/DocumentOrShadowRoot.h"
#include "mozilla/dom/HTMLFormSubmission.h"
#include "mozilla/dom/FileSystemUtils.h"
#include "mozilla/dom/GetFilesHelper.h"
#include "mozilla/dom/HTMLFormSubmission.h"
#include "mozilla/dom/InputType.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/WheelEventBinding.h"
#include "mozilla/PresShell.h"
Expand All @@ -25,7 +26,6 @@
#include "nsQueryObject.h"

#include "nsIRadioVisitor.h"
#include "InputType.h"

#include "HTMLFormSubmissionConstants.h"
#include "mozilla/Telemetry.h"
Expand Down
41 changes: 20 additions & 21 deletions dom/html/HTMLInputElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,22 @@
#include "mozilla/dom/HTMLInputElementBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/dom/SingleLineTextInputTypes.h"
#include "mozilla/dom/NumericInputTypes.h"
#include "mozilla/dom/CheckableInputTypes.h"
#include "mozilla/dom/ButtonInputTypes.h"
#include "mozilla/dom/DateTimeInputTypes.h"
#include "mozilla/dom/ColorInputType.h"
#include "mozilla/dom/FileInputType.h"
#include "mozilla/dom/HiddenInputType.h"
#include "nsGenericHTMLElement.h"
#include "nsImageLoadingContent.h"
#include "nsCOMPtr.h"
#include "nsIConstraintValidation.h"
#include "nsIFilePicker.h"
#include "nsIContentPrefService2.h"
#include "nsContentUtils.h"
#include "SingleLineTextInputTypes.h"
#include "NumericInputTypes.h"
#include "CheckableInputTypes.h"
#include "ButtonInputTypes.h"
#include "DateTimeInputTypes.h"
#include "ColorInputType.h"
#include "FileInputType.h"
#include "HiddenInputType.h"

static constexpr size_t INPUT_TYPE_SIZE = sizeof(
mozilla::Variant<TextInputType, SearchInputType, TelInputType, URLInputType,
EmailInputType, PasswordInputType, NumberInputType,
RangeInputType, RadioInputType, CheckboxInputType,
ButtonInputType, ImageInputType, ResetInputType,
SubmitInputType, DateInputType, TimeInputType,
WeekInputType, MonthInputType, DateTimeLocalInputType,
FileInputType, ColorInputType, HiddenInputType>);

class InputType;
struct DoNotDelete;
class nsIRadioGroupContainer;
class nsIRadioVisitor;

Expand All @@ -62,6 +51,7 @@ class File;
class FileList;
class FileSystemEntry;
class GetFilesHelper;
class InputType;

/**
* A class we use to create a singleton object that is used to keep track of
Expand Down Expand Up @@ -121,7 +111,7 @@ class HTMLInputElement final : public TextControlElement,
public nsIConstraintValidation {
friend class AfterSetFilesOrDirectoriesCallback;
friend class DispatchChangeEventCallback;
friend class ::InputType;
friend class InputType;

public:
using nsGenericHTMLFormElementWithState::GetForm;
Expand Down Expand Up @@ -1496,7 +1486,16 @@ class HTMLInputElement final : public TextControlElement,
/*
* InputType object created based on input type.
*/
UniquePtr<::InputType, DoNotDelete> mInputType;
UniquePtr<InputType, InputType::DoNotDelete> mInputType;

static constexpr size_t INPUT_TYPE_SIZE =
sizeof(mozilla::Variant<
TextInputType, SearchInputType, TelInputType, URLInputType,
EmailInputType, PasswordInputType, NumberInputType, RangeInputType,
RadioInputType, CheckboxInputType, ButtonInputType, ImageInputType,
ResetInputType, SubmitInputType, DateInputType, TimeInputType,
WeekInputType, MonthInputType, DateTimeLocalInputType,
FileInputType, ColorInputType, HiddenInputType>);

// Memory allocated for mInputType, reused when type changes.
char mInputTypeMem[INPUT_TYPE_SIZE];
Expand Down
38 changes: 20 additions & 18 deletions dom/html/input/ButtonInputTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,72 @@
* 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/. */

#ifndef ButtonInputTypes_h__
#define ButtonInputTypes_h__
#ifndef mozilla_dom_ButtonInputTypes_h__
#define mozilla_dom_ButtonInputTypes_h__

#include "InputType.h"
#include "mozilla/dom/InputType.h"

class ButtonInputTypeBase : public ::InputType {
namespace mozilla {
namespace dom {

class ButtonInputTypeBase : public InputType {
public:
~ButtonInputTypeBase() override = default;

protected:
explicit ButtonInputTypeBase(mozilla::dom::HTMLInputElement* aInputElement)
explicit ButtonInputTypeBase(HTMLInputElement* aInputElement)
: InputType(aInputElement) {}
};

// input type=button
class ButtonInputType : public ButtonInputTypeBase {
public:
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
void* aMemory) {
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
return new (aMemory) ButtonInputType(aInputElement);
}

private:
explicit ButtonInputType(mozilla::dom::HTMLInputElement* aInputElement)
explicit ButtonInputType(HTMLInputElement* aInputElement)
: ButtonInputTypeBase(aInputElement) {}
};

// input type=image
class ImageInputType : public ButtonInputTypeBase {
public:
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
void* aMemory) {
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
return new (aMemory) ImageInputType(aInputElement);
}

private:
explicit ImageInputType(mozilla::dom::HTMLInputElement* aInputElement)
explicit ImageInputType(HTMLInputElement* aInputElement)
: ButtonInputTypeBase(aInputElement) {}
};

// input type=reset
class ResetInputType : public ButtonInputTypeBase {
public:
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
void* aMemory) {
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
return new (aMemory) ResetInputType(aInputElement);
}

private:
explicit ResetInputType(mozilla::dom::HTMLInputElement* aInputElement)
explicit ResetInputType(HTMLInputElement* aInputElement)
: ButtonInputTypeBase(aInputElement) {}
};

// input type=submit
class SubmitInputType : public ButtonInputTypeBase {
public:
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
void* aMemory) {
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
return new (aMemory) SubmitInputType(aInputElement);
}

private:
explicit SubmitInputType(mozilla::dom::HTMLInputElement* aInputElement)
explicit SubmitInputType(HTMLInputElement* aInputElement)
: ButtonInputTypeBase(aInputElement) {}
};

#endif /* ButtonInputTypes_h__ */
} // namespace dom
} // namespace mozilla

#endif /* mozilla_dom_ButtonInputTypes_h__ */
5 changes: 4 additions & 1 deletion dom/html/input/CheckableInputTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
* 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/. */

#include "CheckableInputTypes.h"
#include "mozilla/dom/CheckableInputTypes.h"

#include "mozilla/dom/HTMLInputElement.h"

using namespace mozilla;
using namespace mozilla::dom;

/* input type=checkbox */

bool CheckboxInputType::IsValueMissing() const {
Expand Down
28 changes: 16 additions & 12 deletions dom/html/input/CheckableInputTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
* 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/. */

#ifndef CheckableInputTypes_h__
#define CheckableInputTypes_h__
#ifndef mozilla_dom_CheckableInputTypes_h__
#define mozilla_dom_CheckableInputTypes_h__

#include "InputType.h"
#include "mozilla/dom/InputType.h"

class CheckableInputTypeBase : public ::InputType {
namespace mozilla {
namespace dom {

class CheckableInputTypeBase : public InputType {
public:
~CheckableInputTypeBase() override = default;

protected:
explicit CheckableInputTypeBase(mozilla::dom::HTMLInputElement* aInputElement)
explicit CheckableInputTypeBase(HTMLInputElement* aInputElement)
: InputType(aInputElement) {}
};

// input type=checkbox
class CheckboxInputType : public CheckableInputTypeBase {
public:
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
void* aMemory) {
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
return new (aMemory) CheckboxInputType(aInputElement);
}

Expand All @@ -31,23 +33,25 @@ class CheckboxInputType : public CheckableInputTypeBase {
nsresult GetValueMissingMessage(nsAString& aMessage) override;

private:
explicit CheckboxInputType(mozilla::dom::HTMLInputElement* aInputElement)
explicit CheckboxInputType(HTMLInputElement* aInputElement)
: CheckableInputTypeBase(aInputElement) {}
};

// input type=radio
class RadioInputType : public CheckableInputTypeBase {
public:
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
void* aMemory) {
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
return new (aMemory) RadioInputType(aInputElement);
}

nsresult GetValueMissingMessage(nsAString& aMessage) override;

private:
explicit RadioInputType(mozilla::dom::HTMLInputElement* aInputElement)
explicit RadioInputType(HTMLInputElement* aInputElement)
: CheckableInputTypeBase(aInputElement) {}
};

#endif /* CheckableInputTypes_h__ */
} // namespace dom
} // namespace mozilla

#endif /* mozilla_dom_CheckableInputTypes_h__ */
21 changes: 13 additions & 8 deletions dom/html/input/ColorInputType.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@
* 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/. */

#ifndef ColorInputType_h__
#define ColorInputType_h__
#ifndef mozilla_dom_ColorInputType_h__
#define mozilla_dom_ColorInputType_h__

#include "InputType.h"
#include "mozilla/dom/InputType.h"

namespace mozilla {
namespace dom {

// input type=color
class ColorInputType : public ::InputType {
class ColorInputType : public InputType {
public:
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
void* aMemory) {
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
return new (aMemory) ColorInputType(aInputElement);
}

private:
explicit ColorInputType(mozilla::dom::HTMLInputElement* aInputElement)
explicit ColorInputType(HTMLInputElement* aInputElement)
: InputType(aInputElement) {}
};

#endif /* ColorInputType_h__ */
} // namespace dom
} // namespace mozilla

#endif /* mozilla_dom_ColorInputType_h__ */
Loading

0 comments on commit 42615ab

Please sign in to comment.