Commit 3c575f83 authored by Jenny Zhang's avatar Jenny Zhang Committed by Commit Bot

Fix the query removal dialog rotation issue.

Bug: 932058
Change-Id: I139538ff5bf93d61229e682bb04b2d38b758e4d3
Reviewed-on: https://chromium-review.googlesource.com/c/1492975Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Jenny Zhang <jennyz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636524}
parent 27f87c91
...@@ -365,6 +365,9 @@ void ContentsView::UpdateSearchBox(double progress, ...@@ -365,6 +365,9 @@ void ContentsView::UpdateSearchBox(double progress,
gfx::Transform transform; gfx::Transform transform;
transform.Scale(scale, scale); transform.Scale(scale, scale);
search_box->GetWidget()->GetNativeView()->SetTransform(transform); search_box->GetWidget()->GetNativeView()->SetTransform(transform);
for (auto& observer : search_box_observers_)
observer.OnSearchBoxBoundsUpdated();
} }
void ContentsView::UpdateExpandArrowOpacity(double progress, void ContentsView::UpdateExpandArrowOpacity(double progress,
...@@ -636,6 +639,16 @@ void ContentsView::SetExpandArrowViewVisibility(bool show) { ...@@ -636,6 +639,16 @@ void ContentsView::SetExpandArrowViewVisibility(bool show) {
expand_arrow_view_->SetVisible(show); expand_arrow_view_->SetVisible(show);
} }
void ContentsView::AddSearchBoxUpdateObserver(
SearchBoxUpdateObserver* observer) {
search_box_observers_.AddObserver(observer);
}
void ContentsView::RemoveSearchBoxUpdateObserver(
SearchBoxUpdateObserver* observer) {
search_box_observers_.RemoveObserver(observer);
}
bool ContentsView::ShouldLayoutPage(AppListPage* page, bool ContentsView::ShouldLayoutPage(AppListPage* page,
ash::AppListState current_state, ash::AppListState current_state,
ash::AppListState target_state) const { ash::AppListState target_state) const {
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "ash/app_list/pagination_model_observer.h" #include "ash/app_list/pagination_model_observer.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/view_model.h" #include "ui/views/view_model.h"
...@@ -51,6 +53,13 @@ class SearchResultTileItemListView; ...@@ -51,6 +53,13 @@ class SearchResultTileItemListView;
class APP_LIST_EXPORT ContentsView : public views::View, class APP_LIST_EXPORT ContentsView : public views::View,
public PaginationModelObserver { public PaginationModelObserver {
public: public:
// This class observes the search box Updates.
class SearchBoxUpdateObserver : public base::CheckedObserver {
public:
// Called when search box bounds is updated.
virtual void OnSearchBoxBoundsUpdated() = 0;
};
explicit ContentsView(AppListView* app_list_view); explicit ContentsView(AppListView* app_list_view);
~ContentsView() override; ~ContentsView() override;
...@@ -182,6 +191,9 @@ class APP_LIST_EXPORT ContentsView : public views::View, ...@@ -182,6 +191,9 @@ class APP_LIST_EXPORT ContentsView : public views::View,
// and tablet mode is enabled. // and tablet mode is enabled.
void SetExpandArrowViewVisibility(bool show); void SetExpandArrowViewVisibility(bool show);
void AddSearchBoxUpdateObserver(SearchBoxUpdateObserver* observer);
void RemoveSearchBoxUpdateObserver(SearchBoxUpdateObserver* observer);
private: private:
// Sets the active launcher page, accounting for whether the change is for // Sets the active launcher page, accounting for whether the change is for
// search results. // search results.
...@@ -271,6 +283,8 @@ class APP_LIST_EXPORT ContentsView : public views::View, ...@@ -271,6 +283,8 @@ class APP_LIST_EXPORT ContentsView : public views::View,
// Manages the pagination for the launcher pages. // Manages the pagination for the launcher pages.
PaginationModel pagination_model_; PaginationModel pagination_model_;
base::ObserverList<SearchBoxUpdateObserver> search_box_observers_;
DISALLOW_COPY_AND_ASSIGN(ContentsView); DISALLOW_COPY_AND_ASSIGN(ContentsView);
}; };
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ash/app_list/views/remove_query_confirmation_dialog.h" #include "ash/app_list/views/remove_query_confirmation_dialog.h"
#include "ash/app_list/views/search_box_view.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
...@@ -21,9 +22,11 @@ constexpr int kDialogYOffset = 32; ...@@ -21,9 +22,11 @@ constexpr int kDialogYOffset = 32;
RemoveQueryConfirmationDialog::RemoveQueryConfirmationDialog( RemoveQueryConfirmationDialog::RemoveQueryConfirmationDialog(
RemovalConfirmationCallback confirm_callback, RemovalConfirmationCallback confirm_callback,
int event_flags) int event_flags,
ContentsView* contents_view)
: confirm_callback_(std::move(confirm_callback)), : confirm_callback_(std::move(confirm_callback)),
event_flags_(event_flags) { event_flags_(event_flags),
contents_view_(contents_view) {
const views::LayoutProvider* provider = views::LayoutProvider::Get(); const views::LayoutProvider* provider = views::LayoutProvider::Get();
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::kVertical, views::BoxLayout::kVertical,
...@@ -36,23 +39,18 @@ RemoveQueryConfirmationDialog::RemoveQueryConfirmationDialog( ...@@ -36,23 +39,18 @@ RemoveQueryConfirmationDialog::RemoveQueryConfirmationDialog(
label->SetHorizontalAlignment(gfx::ALIGN_LEFT); label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
label->SetAllowCharacterBreak(true); label->SetAllowCharacterBreak(true);
AddChildView(label); AddChildView(label);
contents_view_->AddSearchBoxUpdateObserver(this);
} }
RemoveQueryConfirmationDialog::~RemoveQueryConfirmationDialog() {} RemoveQueryConfirmationDialog::~RemoveQueryConfirmationDialog() {
contents_view_->RemoveSearchBoxUpdateObserver(this);
}
void RemoveQueryConfirmationDialog::Show(gfx::NativeWindow parent, void RemoveQueryConfirmationDialog::Show(gfx::NativeWindow parent) {
const gfx::Rect& anchor_rect) {
views::DialogDelegate::CreateDialogWidget(this, nullptr, parent); views::DialogDelegate::CreateDialogWidget(this, nullptr, parent);
UpdateBounds();
views::Widget* widget = GetWidget(); GetWidget()->Show();
DCHECK(widget);
gfx::Rect widget_rect = widget->GetWindowBoundsInScreen();
gfx::Point origin(anchor_rect.CenterPoint().x() - kDialogWidth / 2,
anchor_rect.y() + kDialogYOffset);
widget_rect.set_origin(origin);
widget->SetBounds(widget_rect);
widget->Show();
} }
base::string16 RemoveQueryConfirmationDialog::GetWindowTitle() const { base::string16 RemoveQueryConfirmationDialog::GetWindowTitle() const {
...@@ -93,4 +91,22 @@ gfx::Size RemoveQueryConfirmationDialog::CalculatePreferredSize() const { ...@@ -93,4 +91,22 @@ gfx::Size RemoveQueryConfirmationDialog::CalculatePreferredSize() const {
return gfx::Size(default_width, GetHeightForWidth(default_width)); return gfx::Size(default_width, GetHeightForWidth(default_width));
} }
void RemoveQueryConfirmationDialog::OnSearchBoxBoundsUpdated() {
UpdateBounds();
}
void RemoveQueryConfirmationDialog::UpdateBounds() {
// Calculate confirmation dialog's origin in screen coordinates.
gfx::Rect anchor_rect =
contents_view_->GetSearchBoxView()->GetBoundsInScreen();
gfx::Point origin(anchor_rect.CenterPoint().x() - kDialogWidth / 2,
anchor_rect.y() + kDialogYOffset);
views::Widget* widget = GetWidget();
DCHECK(widget);
gfx::Rect widget_rect = widget->GetWindowBoundsInScreen();
widget_rect.set_origin(origin);
widget->SetBounds(widget_rect);
}
} // namespace app_list } // namespace app_list
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef ASH_APP_LIST_VIEWS_REMOVE_QUERY_CONFIRMATION_DIALOG_H_ #ifndef ASH_APP_LIST_VIEWS_REMOVE_QUERY_CONFIRMATION_DIALOG_H_
#define ASH_APP_LIST_VIEWS_REMOVE_QUERY_CONFIRMATION_DIALOG_H_ #define ASH_APP_LIST_VIEWS_REMOVE_QUERY_CONFIRMATION_DIALOG_H_
#include "ash/app_list/views/contents_view.h"
#include "base/callback.h" #include "base/callback.h"
#include "ui/views/window/dialog_delegate.h" #include "ui/views/window/dialog_delegate.h"
...@@ -12,7 +13,9 @@ namespace app_list { ...@@ -12,7 +13,9 @@ namespace app_list {
// RemoveQueryConfirmationDialog displays the confirmation dialog for removing // RemoveQueryConfirmationDialog displays the confirmation dialog for removing
// a recent query suggestion. // a recent query suggestion.
class RemoveQueryConfirmationDialog : public views::DialogDelegateView { class RemoveQueryConfirmationDialog
: public views::DialogDelegateView,
public ContentsView::SearchBoxUpdateObserver {
public: public:
// Callback to notify user's confirmation for removing the zero state // Callback to notify user's confirmation for removing the zero state
// suggestion query. Invoked with true if user confirms removing query // suggestion query. Invoked with true if user confirms removing query
...@@ -22,11 +25,12 @@ class RemoveQueryConfirmationDialog : public views::DialogDelegateView { ...@@ -22,11 +25,12 @@ class RemoveQueryConfirmationDialog : public views::DialogDelegateView {
using RemovalConfirmationCallback = base::OnceCallback<void(bool, int)>; using RemovalConfirmationCallback = base::OnceCallback<void(bool, int)>;
RemoveQueryConfirmationDialog(RemovalConfirmationCallback callback, RemoveQueryConfirmationDialog(RemovalConfirmationCallback callback,
int event_flgas); int event_flgas,
ContentsView* contents_view);
~RemoveQueryConfirmationDialog() override; ~RemoveQueryConfirmationDialog() override;
// Shows the dialog with |parent| and |anchor_rect| in screen coordinates. // Shows the dialog with |parent|.
void Show(gfx::NativeWindow parent, const gfx::Rect& anchor_rect); void Show(gfx::NativeWindow parent);
private: private:
// views::WidgetDelegate: // views::WidgetDelegate:
...@@ -42,8 +46,14 @@ class RemoveQueryConfirmationDialog : public views::DialogDelegateView { ...@@ -42,8 +46,14 @@ class RemoveQueryConfirmationDialog : public views::DialogDelegateView {
// views::View: // views::View:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
// ContentsView::SearchBoxUpdateObserver
void OnSearchBoxBoundsUpdated() override;
void UpdateBounds();
RemovalConfirmationCallback confirm_callback_; RemovalConfirmationCallback confirm_callback_;
int event_flags_; int event_flags_;
ContentsView* const contents_view_; // Owned by the views hierarchy
DISALLOW_COPY_AND_ASSIGN(RemoveQueryConfirmationDialog); DISALLOW_COPY_AND_ASSIGN(RemoveQueryConfirmationDialog);
}; };
......
...@@ -479,13 +479,9 @@ void SearchResultView::OnSearchResultActionActivated(size_t index, ...@@ -479,13 +479,9 @@ void SearchResultView::OnSearchResultActionActivated(size_t index,
RemoveQueryConfirmationDialog* dialog = new RemoveQueryConfirmationDialog( RemoveQueryConfirmationDialog* dialog = new RemoveQueryConfirmationDialog(
base::BindOnce(&SearchResultView::OnQueryRemovalAccepted, base::BindOnce(&SearchResultView::OnQueryRemovalAccepted,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
event_flags); event_flags, list_view_->app_list_main_view()->contents_view());
// Calculate confirmation dialog's origin in screen coordinates. dialog->Show(GetWidget()->GetNativeWindow());
gfx::Rect search_box_rect = list_view_->app_list_main_view()
->search_box_view()
->GetBoundsInScreen();
dialog->Show(GetWidget()->GetNativeWindow(), search_box_rect);
} else if (button_action == } else if (button_action ==
ash::OmniBoxZeroStateAction::kAppendSuggestion) { ash::OmniBoxZeroStateAction::kAppendSuggestion) {
RecordZeroStateSearchResultUserActionHistogram( RecordZeroStateSearchResultUserActionHistogram(
......
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