Commit ed6a1c0d authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Make ScrollView in MessageBoxView fill the dialog.

Previously the ScrollView scrollbar and vertical borders did not span
across the entire horizontal dialog, with this change the scroll bar is
all the way to the right, and scrollview top/bottom dividers span past
dialog insets.

The insets are instead applied to the ScrollView contents, so the text
content is still inset properly. This Harmonizes dialogs that make use
of MessageBoxView, specifically JavaScript prompt/alert dialogs.

Bug: chromium:683346
Change-Id: Icbaa18b26a22975ba3fcf9d2b584416636cba07f
Reviewed-on: https://chromium-review.googlesource.com/767450
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: 's avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516145}
parent 5af2ff8b
......@@ -21,6 +21,7 @@
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_provider.h"
#include "ui/views/widget/widget.h"
......@@ -220,56 +221,71 @@ void MessageBoxView::ResetLayoutManager() {
GridLayout* layout = GridLayout::CreateAndInstall(this);
// Add the column set for the message displayed at the top of the dialog box.
const int message_column_view_set_id = 0;
ColumnSet* column_set = layout->AddColumnSet(message_column_view_set_id);
constexpr int kMessageViewColumnSetId = 0;
ColumnSet* column_set = layout->AddColumnSet(kMessageViewColumnSetId);
column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
GridLayout::FIXED, message_width_, 0);
gfx::Insets horizontal_insets =
views::LayoutProvider::Get()->GetInsetsMetric(views::INSETS_DIALOG);
horizontal_insets.Set(0, horizontal_insets.left(), 0,
horizontal_insets.right());
// Column set for extra elements, if any.
const int extra_column_view_set_id = 1;
constexpr int kExtraViewColumnSetId = 1;
if (prompt_field_ || checkbox_ || link_) {
column_set = layout->AddColumnSet(extra_column_view_set_id);
column_set = layout->AddColumnSet(kExtraViewColumnSetId);
column_set->AddPaddingColumn(0, horizontal_insets.left());
column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
GridLayout::USE_PREF, 0, 0);
column_set->AddPaddingColumn(0, horizontal_insets.right());
}
const int kMaxScrollViewHeight = 400;
views::View* message_contents = new views::View();
// We explicitly set insets on the message contents instead of the scroll view
// so that the scroll view borders are not capped by dialog insets.
message_contents->SetBorder(CreateEmptyBorder(horizontal_insets));
message_contents->SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kVertical));
for (size_t i = 0; i < message_labels_.size(); ++i)
message_contents->AddChildView(message_labels_[i]);
ScrollView* scroll_view = new views::ScrollView();
scroll_view->ClipHeightTo(0, kMaxScrollViewHeight);
scroll_view->SetContents(message_contents);
layout->StartRow(0, message_column_view_set_id);
layout->StartRow(0, kMessageViewColumnSetId);
layout->AddView(scroll_view);
views::DialogContentType trailing_content_type = views::TEXT;
if (prompt_field_) {
layout->AddPaddingRow(0, inter_row_vertical_spacing_);
layout->StartRow(0, extra_column_view_set_id);
layout->StartRow(0, kExtraViewColumnSetId);
layout->AddView(prompt_field_);
trailing_content_type = views::CONTROL;
}
if (checkbox_) {
layout->AddPaddingRow(0, inter_row_vertical_spacing_);
layout->StartRow(0, extra_column_view_set_id);
layout->StartRow(0, kExtraViewColumnSetId);
layout->AddView(checkbox_);
trailing_content_type = views::CONTROL;
}
if (link_) {
layout->AddPaddingRow(0, inter_row_vertical_spacing_);
layout->StartRow(0, extra_column_view_set_id);
layout->StartRow(0, kExtraViewColumnSetId);
layout->AddView(link_);
trailing_content_type = views::TEXT;
}
SetBorder(
CreateEmptyBorder(LayoutProvider::Get()->GetDialogInsetsForContentType(
views::TEXT, trailing_content_type)));
gfx::Insets border_insets =
LayoutProvider::Get()->GetDialogInsetsForContentType(
views::TEXT, trailing_content_type);
// Horizontal insets have already been applied to the message contents and
// controls as padding columns. Only apply the missing vertical insets.
border_insets.Set(border_insets.top(), 0, border_insets.bottom(), 0);
SetBorder(CreateEmptyBorder(border_insets));
}
} // namespace views
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