Commit 9c1aa718 authored by Patti's avatar Patti Committed by Commit Bot

Desktop Page Info/Harmony: Limit combobox width to a maximum.

Make all page info combobox widths be the same as the longest currently
displayed item, provided it doesn't exceed a max threshold.

Screenshot -
https://drive.google.com/file/d/0BzEa5HU1aAqBc1U4SjdhZnVONzA/view?usp=sharing

Bug: 535074, 778088
Change-Id: I235e51e9b7d8c77eff43c5690c62e4008a411fef
Reviewed-on: https://chromium-review.googlesource.com/730243Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Commit-Queue: Patti <patricialor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513065}
parent 003376aa
......@@ -770,6 +770,25 @@ void PageInfoBubbleView::SetPermissionInfo(
selector_rows_.push_back(std::move(selector));
}
// In Harmony, ensure most comboboxes are the same width by setting them all
// to the widest combobox size, provided it does not exceed a maximum width.
// For selected options that are over the maximum width, allow them to assume
// their full width. If the combobox selection is changed, this may make the
// widths inconsistent again, but that is OK since the widths will be updated
// on the next time the bubble is opened.
if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
const int maximum_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_BUTTON_MAX_LINKABLE_WIDTH);
int combobox_width = 0;
for (const auto& selector : selector_rows_) {
int curr_width = selector->GetComboboxWidth();
if (maximum_width >= curr_width)
combobox_width = std::max(combobox_width, curr_width);
}
for (const auto& selector : selector_rows_)
selector->SetMinComboboxWidth(combobox_width);
}
for (auto& object : chosen_object_info_list) {
// Since chosen objects are presented after permissions in the same list,
// make sure its height is the same as the permissions row's minimum height
......
......@@ -213,11 +213,21 @@ class PermissionCombobox : public views::Combobox,
void UpdateSelectedIndex(bool use_default);
void set_min_width(int width) { min_width_ = width; }
// views::Combobox:
gfx::Size CalculatePreferredSize() const override;
private:
// views::ComboboxListener:
void OnPerformAction(Combobox* combobox) override;
ComboboxModelAdapter* model_;
// Minimum width for |PermissionCombobox|.
int min_width_ = 0;
DISALLOW_COPY_AND_ASSIGN(PermissionCombobox);
};
PermissionCombobox::PermissionCombobox(ComboboxModelAdapter* model,
......@@ -243,6 +253,12 @@ void PermissionCombobox::UpdateSelectedIndex(bool use_default) {
SetSelectedIndex(index);
}
gfx::Size PermissionCombobox::CalculatePreferredSize() const {
gfx::Size preferred_size = Combobox::CalculatePreferredSize();
preferred_size.SetToMax(gfx::Size(min_width_, 0));
return preferred_size;
}
void PermissionCombobox::OnPerformAction(Combobox* combobox) {
model_->OnPerformAction(combobox->selected_index());
}
......@@ -404,6 +420,16 @@ void PermissionSelectorRow::PermissionChanged(
}
}
int PermissionSelectorRow::GetComboboxWidth() const {
DCHECK(combobox_);
return combobox_->Combobox::GetPreferredSize().width();
}
void PermissionSelectorRow::SetMinComboboxWidth(int width) {
DCHECK(combobox_);
combobox_->set_min_width(width);
}
views::View* PermissionSelectorRow::button() {
// These casts are required because the two arms of a ?: cannot have different
// types T1 and T2, even if the resulting value of the ?: is about to be a T
......
......@@ -57,6 +57,13 @@ class PermissionSelectorRow {
void PermissionChanged(const PageInfoUI::PermissionInfo& permission);
// Returns the preferred width for the currently selected combobox option
// (unchanged by any minimum width set using SetMinComboboxWidth()).
int GetComboboxWidth() const;
// Sets the minimum width for |combobox_|.
void SetMinComboboxWidth(int width);
private:
friend class test::PageInfoBubbleViewTestApi;
......
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