forked from mirrors/gecko-dev
Bug 1905743 - Tweak TextControlElement to be able to tell if column count is explicit or not. r=dholbert a=RyanVM
This is needed because we want implicit width of number and text controls be the same, but explicit width be different to account for the spinners. See: data:text/html,<input type="number"><br><input type="text"><br><input type="number" min="1" max="9"><br><input type="text" size="1"> For example. This patch on its own shouldn't change behavior.
This commit is contained in:
parent
93e034b808
commit
8bee16d175
9 changed files with 29 additions and 21 deletions
|
|
@ -6974,20 +6974,20 @@ Maybe<int32_t> HTMLInputElement::GetNumberInputCols() const {
|
|||
(size.mAfterDecimal ? 1 : 0));
|
||||
}
|
||||
|
||||
int32_t HTMLInputElement::GetCols() {
|
||||
Maybe<int32_t> HTMLInputElement::GetCols() {
|
||||
if (const nsAttrValue* attr = GetParsedAttr(nsGkAtoms::size);
|
||||
attr && attr->Type() == nsAttrValue::eInteger) {
|
||||
int32_t cols = attr->GetIntegerValue();
|
||||
if (cols > 0) {
|
||||
return cols;
|
||||
return Some(cols);
|
||||
}
|
||||
}
|
||||
|
||||
if (Maybe<int32_t> cols = GetNumberInputCols(); cols && *cols > 0) {
|
||||
return *cols;
|
||||
return cols;
|
||||
}
|
||||
|
||||
return DEFAULT_COLS;
|
||||
return {};
|
||||
}
|
||||
|
||||
int32_t HTMLInputElement::GetWrapCols() {
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ class HTMLInputElement final : public TextControlElement,
|
|||
bool IsSingleLineTextControl() const override;
|
||||
bool IsTextArea() const override;
|
||||
bool IsPasswordTextControl() const override;
|
||||
int32_t GetCols() override;
|
||||
Maybe<int32_t> GetCols() override;
|
||||
int32_t GetWrapCols() override;
|
||||
int32_t GetRows() override;
|
||||
void GetDefaultValueFromContent(nsAString& aValue, bool aForDisplay) override;
|
||||
|
|
|
|||
|
|
@ -1053,7 +1053,13 @@ bool HTMLTextAreaElement::IsTextArea() const { return true; }
|
|||
|
||||
bool HTMLTextAreaElement::IsPasswordTextControl() const { return false; }
|
||||
|
||||
int32_t HTMLTextAreaElement::GetCols() { return Cols(); }
|
||||
Maybe<int32_t> HTMLTextAreaElement::GetCols() {
|
||||
const nsAttrValue* value = GetParsedAttr(nsGkAtoms::cols);
|
||||
if (!value || value->Type() != nsAttrValue::eInteger) {
|
||||
return {};
|
||||
}
|
||||
return Some(value->GetIntegerValue());
|
||||
}
|
||||
|
||||
int32_t HTMLTextAreaElement::GetWrapCols() {
|
||||
nsHTMLTextWrap wrapProp;
|
||||
|
|
@ -1064,7 +1070,7 @@ int32_t HTMLTextAreaElement::GetWrapCols() {
|
|||
}
|
||||
|
||||
// Otherwise we just wrap at the given number of columns
|
||||
return GetCols();
|
||||
return GetColsOrDefault();
|
||||
}
|
||||
|
||||
int32_t HTMLTextAreaElement::GetRows() {
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class HTMLTextAreaElement final : public TextControlElement,
|
|||
bool IsSingleLineTextControl() const override;
|
||||
bool IsTextArea() const override;
|
||||
bool IsPasswordTextControl() const override;
|
||||
int32_t GetCols() override;
|
||||
Maybe<int32_t> GetCols() override;
|
||||
int32_t GetWrapCols() override;
|
||||
int32_t GetRows() override;
|
||||
void GetDefaultValueFromContent(nsAString& aValue, bool aForDisplay) override;
|
||||
|
|
@ -171,7 +171,7 @@ class HTMLTextAreaElement final : public TextControlElement,
|
|||
void SetAutocomplete(const nsAString& aValue, ErrorResult& aRv) {
|
||||
SetHTMLAttr(nsGkAtoms::autocomplete, aValue, aRv);
|
||||
}
|
||||
uint32_t Cols() { return GetUnsignedIntAttr(nsGkAtoms::cols, DEFAULT_COLS); }
|
||||
uint32_t Cols() { return GetColsOrDefault(); }
|
||||
void SetCols(uint32_t aCols, ErrorResult& aError) {
|
||||
uint32_t cols = aCols ? aCols : DEFAULT_COLS;
|
||||
SetUnsignedIntAttr(nsGkAtoms::cols, cols, DEFAULT_COLS, aError);
|
||||
|
|
|
|||
|
|
@ -76,7 +76,8 @@ class TextControlElement : public nsGenericHTMLFormControlElementWithState {
|
|||
* Get the cols attribute (if textarea) or a default
|
||||
* @return the number of columns to use
|
||||
*/
|
||||
virtual int32_t GetCols() = 0;
|
||||
virtual Maybe<int32_t> GetCols() = 0;
|
||||
int32_t GetColsOrDefault() { return GetCols().valueOr(DEFAULT_COLS); }
|
||||
|
||||
/**
|
||||
* Get the column index to wrap at, or -1 if we shouldn't wrap
|
||||
|
|
@ -216,10 +217,10 @@ class TextControlElement : public nsGenericHTMLFormControlElementWithState {
|
|||
MOZ_CAN_RUN_SCRIPT virtual nsresult SetValueFromSetRangeText(
|
||||
const nsAString& aValue) = 0;
|
||||
|
||||
static const int32_t DEFAULT_COLS = 20;
|
||||
static const int32_t DEFAULT_ROWS = 1;
|
||||
static const int32_t DEFAULT_ROWS_TEXTAREA = 2;
|
||||
static const int32_t DEFAULT_UNDO_CAP = 1000;
|
||||
inline static constexpr int32_t DEFAULT_COLS = 20;
|
||||
inline static constexpr int32_t DEFAULT_ROWS = 1;
|
||||
inline static constexpr int32_t DEFAULT_ROWS_TEXTAREA = 2;
|
||||
inline static constexpr int32_t DEFAULT_UNDO_CAP = 1000;
|
||||
|
||||
// wrap can be one of these three values.
|
||||
typedef enum {
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ class TextControlState final : public SupportsWeakPtr {
|
|||
bool IsPasswordTextControl() const {
|
||||
return mTextCtrlElement->IsPasswordTextControl();
|
||||
}
|
||||
int32_t GetCols() { return mTextCtrlElement->GetCols(); }
|
||||
int32_t GetColsOrDefault() { return mTextCtrlElement->GetColsOrDefault(); }
|
||||
int32_t GetWrapCols() {
|
||||
int32_t wrapCols = mTextCtrlElement->GetWrapCols();
|
||||
MOZ_ASSERT(wrapCols >= 0);
|
||||
|
|
|
|||
|
|
@ -203,12 +203,11 @@ LogicalSize nsTextControlFrame::CalcIntrinsicSize(gfxContext* aRenderingContext,
|
|||
nsPresContext::CSSPixelsToAppUnits(4));
|
||||
internalPadding = RoundToMultiple(internalPadding, AppUnitsPerCSSPixel());
|
||||
intrinsicSize.ISize(aWM) += internalPadding;
|
||||
} else {
|
||||
} else if (PresContext()->CompatibilityMode() ==
|
||||
eCompatibility_FullStandards) {
|
||||
// This is to account for the anonymous <br> having a 1 twip width
|
||||
// in Full Standards mode, see BRFrame::Reflow and bug 228752.
|
||||
if (PresContext()->CompatibilityMode() == eCompatibility_FullStandards) {
|
||||
intrinsicSize.ISize(aWM) += 1;
|
||||
}
|
||||
intrinsicSize.ISize(aWM) += 1;
|
||||
}
|
||||
|
||||
// Increment width with cols * letter-spacing.
|
||||
|
|
|
|||
|
|
@ -211,7 +211,8 @@ class nsTextControlFrame : public nsContainerFrame,
|
|||
DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsSingleLineTextControl)
|
||||
DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsTextArea)
|
||||
DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsPasswordTextControl)
|
||||
DEFINE_TEXTCTRL_CONST_FORWARDER(int32_t, GetCols)
|
||||
DEFINE_TEXTCTRL_CONST_FORWARDER(Maybe<int32_t>, GetCols)
|
||||
DEFINE_TEXTCTRL_CONST_FORWARDER(int32_t, GetColsOrDefault)
|
||||
DEFINE_TEXTCTRL_CONST_FORWARDER(int32_t, GetRows)
|
||||
|
||||
#undef DEFINE_TEXTCTRL_CONST_FORWARDER
|
||||
|
|
|
|||
|
|
@ -345,7 +345,8 @@ void nsFontInflationData::ScanTextIn(nsIFrame* aFrame) {
|
|||
// We don't want changes to the amount of text in a text input
|
||||
// to change what we count towards inflation.
|
||||
nscoord fontSize = kid->StyleFont()->mFont.size.ToAppUnits();
|
||||
int32_t charCount = static_cast<nsTextControlFrame*>(kid)->GetCols();
|
||||
int32_t charCount =
|
||||
static_cast<nsTextControlFrame*>(kid)->GetColsOrDefault();
|
||||
mTextAmount += charCount * fontSize;
|
||||
} else if (fType == LayoutFrameType::ComboboxControl) {
|
||||
// See textInputFrame above (with s/amount of text/selected option/).
|
||||
|
|
|
|||
Loading…
Reference in a new issue