Commit 3da399bb authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Move LayoutListBox::size() to HTMLSelectElement as ListBoxSize()

Also, this CL removes DEFINE_LAYOUT_OBJECT_TYPE_CASTS for LayoutListBox
because this CL removes the last usage of ToLayoutListBox().

This CL has no behavior changes.

Bug: 1040828
Change-Id: I0f531e1f059a3a85046711a1a11cb91450621069
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2040494
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738956}
parent 6a196c81
......@@ -92,6 +92,10 @@ namespace blink {
// signed.
static const unsigned kMaxListItems = INT_MAX;
// Default size when the multiple attribute is present but size attribute is
// absent.
const int kDefaultListBoxSize = 4;
HTMLSelectElement::HTMLSelectElement(Document& document)
: HTMLFormControlElementWithState(html_names::kSelectTag, document),
type_ahead_(this),
......@@ -200,6 +204,14 @@ void HTMLSelectElement::SelectMultipleOptionsByPopup(
ListBoxOnChange();
}
unsigned HTMLSelectElement::ListBoxSize() const {
DCHECK(!UsesMenuList());
const unsigned specified_size = size();
if (specified_size >= 1)
return specified_size;
return kDefaultListBoxSize;
}
bool HTMLSelectElement::UsesMenuList() const {
if (LayoutTheme::GetTheme().DelegatesMenuListRendering())
return true;
......@@ -545,13 +557,10 @@ HTMLOptionElement* HTMLSelectElement::LastSelectableOption() const {
HTMLOptionElement* HTMLSelectElement::NextSelectableOptionPageAway(
HTMLOptionElement* start_option,
SkipDirection direction) const {
DCHECK(!UsesMenuList());
const ListItems& items = GetListItems();
// Can't use size_ because LayoutObject forces a minimum size.
int page_size = 0;
if (GetLayoutObject()->IsListBox()) {
// -1 so we still show context.
page_size = ToLayoutListBox(GetLayoutObject())->size() - 1;
}
// -1 so we still show context.
int page_size = ListBoxSize() - 1;
// One page away, but not outside valid bounds.
// If there is a valid option item one page away, the index is chosen.
......
......@@ -75,6 +75,9 @@ class CORE_EXPORT HTMLSelectElement final
// TODO(tkent): Rename |size| to |Size|. This is not an implementation of
// |size| IDL attribute.
unsigned size() const { return size_; }
// The number of items to be shown in the LisBox mode.
// Do not call this in the MenuList mode.
unsigned ListBoxSize() const;
bool IsMultiple() const { return is_multiple_; }
bool UsesMenuList() const;
......
......@@ -43,10 +43,6 @@
namespace blink {
// Default size when the multiple attribute is present but size attribute is
// absent.
const int kDefaultSize = 4;
const int kDefaultPaddingBottom = 1;
LayoutListBox::LayoutListBox(Element* element) : LayoutBlockFlow(element) {
......@@ -61,14 +57,6 @@ inline HTMLSelectElement* LayoutListBox::SelectElement() const {
return To<HTMLSelectElement>(GetNode());
}
unsigned LayoutListBox::size() const {
unsigned specified_size = SelectElement()->size();
if (specified_size >= 1)
return specified_size;
return kDefaultSize;
}
LayoutUnit LayoutListBox::DefaultItemHeight() const {
const SimpleFontData* font_data = StyleRef().GetFont().PrimaryFont();
if (!font_data)
......@@ -113,7 +101,7 @@ void LayoutListBox::ComputeLogicalHeight(
if (HasOverrideIntrinsicContentLogicalHeight()) {
height = OverrideIntrinsicContentLogicalHeight();
} else {
height = ItemHeight() * size();
height = ItemHeight() * SelectElement()->ListBoxSize();
}
// FIXME: The item height should have been added before updateLogicalHeight
......
......@@ -42,8 +42,6 @@ class CORE_EXPORT LayoutListBox final : public LayoutBlockFlow {
explicit LayoutListBox(Element*);
~LayoutListBox() override;
unsigned size() const;
const char* GetName() const override { return "LayoutListBox"; }
private:
......@@ -64,8 +62,6 @@ class CORE_EXPORT LayoutListBox final : public LayoutBlockFlow {
LayoutUnit ItemHeight() const;
};
DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutListBox, IsListBox());
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_LIST_BOX_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment