Commit c8ed3063 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Convert OmniboxPopupContentsView to use a LayoutManager.

No functional change intended, ideally just more maintainable code.

Bug: 1005568
Change-Id: I94bec353c48114e79546e38474d4f55edb04442f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1812317
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Kevin Bailey <krb@chromium.org>
Reviewed-by: default avatarKevin Bailey <krb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700465}
parent d35041d5
......@@ -22,6 +22,7 @@
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/image/image.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h"
class OmniboxPopupContentsView::AutocompletePopupWidget
......@@ -148,6 +149,9 @@ OmniboxPopupContentsView::OmniboxPopupContentsView(
// The contents is owned by the LocationBarView.
set_owned_by_client();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
for (size_t i = 0; i < AutocompleteResult::GetMaxMatches(); ++i) {
OmniboxResultView* result_view =
new OmniboxResultView(this, i, theme_provider);
......@@ -273,7 +277,7 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() {
if (popup_) {
popup_->SetTargetBounds(new_target_bounds);
Layout();
InvalidateLayout();
return;
}
......@@ -307,7 +311,7 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() {
result_view_at(0)->NotifyAccessibilityEvent(ax::mojom::Event::kSelection,
true);
}
Layout();
InvalidateLayout();
}
void OmniboxPopupContentsView::OnMatchIconUpdated(size_t match_index) {
......@@ -321,15 +325,6 @@ void OmniboxPopupContentsView::OnDragCanceled() {
////////////////////////////////////////////////////////////////////////////////
// OmniboxPopupContentsView, views::View overrides:
void OmniboxPopupContentsView::Layout() {
// Size our children to the available content area.
LayoutChildren();
// We need to manually schedule a paint here since we are a layered window and
// won't implicitly require painting until we ask for one.
SchedulePaint();
}
bool OmniboxPopupContentsView::OnMouseDragged(const ui::MouseEvent& event) {
size_t index = GetIndexForPoint(event.location());
......@@ -401,18 +396,6 @@ gfx::Rect OmniboxPopupContentsView::GetTargetBounds() {
return content_rect;
}
void OmniboxPopupContentsView::LayoutChildren() {
gfx::Rect contents_rect = GetContentsBounds();
int top = contents_rect.y();
for (View* v : children()) {
if (v->GetVisible()) {
v->SetBounds(contents_rect.x(), top, contents_rect.width(),
v->GetPreferredSize().height());
top = v->bounds().bottom();
}
}
}
bool OmniboxPopupContentsView::HasMatchAt(size_t index) const {
return index < model_->result().size();
}
......
......@@ -76,7 +76,6 @@ class OmniboxPopupContentsView : public views::View, public OmniboxPopupView {
void OnDragCanceled() override;
// views::View:
void Layout() override;
bool OnMouseDragged(const ui::MouseEvent& event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
......@@ -89,9 +88,6 @@ class OmniboxPopupContentsView : public views::View, public OmniboxPopupView {
// of |location_bar_view_|.
gfx::Rect GetTargetBounds();
// Size our children to the available content area.
void LayoutChildren();
// Returns true if the model has a match at the specified index.
bool HasMatchAt(size_t index) const;
......
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