Commit c133a234 authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] Re-align the dropdown to the omnibox on device scale change

Currently, when the device scale changes, we accept the Window Manager's
instructions on how to re-position the omnibox popup.

That doesn't work anymore in the WebUI tab-strip world, and actually if
it ever worked in the past, it seems like it must have by chance only.

This CL makes it so that on widget resize (which should only happen
during device scale change or rotation), we explicitly update the popup
appearance, which should re-align it to wherever the omnibox currently
is.

I tested this by changing the device scale (Ctrl+Shift+Plus) on
ChromeOS on Linux with the omnibox popup open.

Bug: 1027387
Change-Id: If80e20ef276704363c01ec98a685eb791f29ae56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1951335
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721703}
parent a014b111
...@@ -280,6 +280,7 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() { ...@@ -280,6 +280,7 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() {
popup_->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); popup_->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE);
popup_->SetPopupContentsView(this); popup_->SetPopupContentsView(this);
popup_->AddObserver(this);
popup_->StackAbove(omnibox_view_->GetRelativeWindowForPopup()); popup_->StackAbove(omnibox_view_->GetRelativeWindowForPopup());
// For some IMEs GetRelativeWindowForPopup triggers the omnibox to lose // For some IMEs GetRelativeWindowForPopup triggers the omnibox to lose
// focus, thereby closing (and destroying) the popup. TODO(sky): this won't // focus, thereby closing (and destroying) the popup. TODO(sky): this won't
...@@ -349,6 +350,15 @@ void OmniboxPopupContentsView::OnGestureEvent(ui::GestureEvent* event) { ...@@ -349,6 +350,15 @@ void OmniboxPopupContentsView::OnGestureEvent(ui::GestureEvent* event) {
event->SetHandled(); event->SetHandled();
} }
void OmniboxPopupContentsView::OnWidgetBoundsChanged(
views::Widget* widget,
const gfx::Rect& new_bounds) {
// This is called on rotation or device scale change. We have to re-align to
// the new location bar location.
DCHECK_EQ(popup_.get(), widget);
UpdatePopupAppearance();
}
gfx::Rect OmniboxPopupContentsView::GetTargetBounds() { gfx::Rect OmniboxPopupContentsView::GetTargetBounds() {
DCHECK_GE(children().size(), model_->result().size()); DCHECK_GE(children().size(), model_->result().size());
int popup_height = std::accumulate( int popup_height = std::accumulate(
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/widget_observer.h"
struct AutocompleteMatch; struct AutocompleteMatch;
class LocationBarView; class LocationBarView;
...@@ -23,7 +24,9 @@ class OmniboxResultView; ...@@ -23,7 +24,9 @@ class OmniboxResultView;
class OmniboxViewViews; class OmniboxViewViews;
// A view representing the contents of the autocomplete popup. // A view representing the contents of the autocomplete popup.
class OmniboxPopupContentsView : public views::View, public OmniboxPopupView { class OmniboxPopupContentsView : public views::View,
public OmniboxPopupView,
public views::WidgetObserver {
public: public:
OmniboxPopupContentsView(OmniboxViewViews* omnibox_view, OmniboxPopupContentsView(OmniboxViewViews* omnibox_view,
OmniboxEditModel* edit_model, OmniboxEditModel* edit_model,
...@@ -81,6 +84,10 @@ class OmniboxPopupContentsView : public views::View, public OmniboxPopupView { ...@@ -81,6 +84,10 @@ class OmniboxPopupContentsView : public views::View, public OmniboxPopupView {
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// views::WidgetObserver:
void OnWidgetBoundsChanged(views::Widget* widget,
const gfx::Rect& new_bounds) override;
private: private:
friend class OmniboxPopupContentsViewTest; friend class OmniboxPopupContentsViewTest;
class AutocompletePopupWidget; class AutocompletePopupWidget;
......
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