Commit c26cde39 authored by Muyuan Li's avatar Muyuan Li Committed by Commit Bot

assistant: update assistant location when display metrics change

Bug: b/111900963, b/112102455
Test: Manual
Change-Id: I69f296f8eae6eb320eb5be122629b8e1658868ce
Reviewed-on: https://chromium-review.googlesource.com/1173478
Commit-Queue: Muyuan Li <muyuanli@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582786}
parent 2b080c39
...@@ -115,8 +115,7 @@ AssistantContainerView::AssistantContainerView( ...@@ -115,8 +115,7 @@ AssistantContainerView::AssistantContainerView(
AssistantController* assistant_controller) AssistantController* assistant_controller)
: assistant_controller_(assistant_controller) { : assistant_controller_(assistant_controller) {
set_accept_events(true); set_accept_events(true);
SetAnchor(); SetAnchor(nullptr);
set_arrow(views::BubbleBorder::Arrow::BOTTOM_CENTER);
set_close_on_deactivate(false); set_close_on_deactivate(false);
set_color(kBackgroundColor); set_color(kBackgroundColor);
set_margins(gfx::Insets()); set_margins(gfx::Insets());
...@@ -131,9 +130,11 @@ AssistantContainerView::AssistantContainerView( ...@@ -131,9 +130,11 @@ AssistantContainerView::AssistantContainerView(
// The AssistantController owns the view hierarchy to which // The AssistantController owns the view hierarchy to which
// AssistantContainerView belongs so is guaranteed to outlive it. // AssistantContainerView belongs so is guaranteed to outlive it.
assistant_controller_->ui_controller()->AddModelObserver(this); assistant_controller_->ui_controller()->AddModelObserver(this);
display::Screen::GetScreen()->AddObserver(this);
} }
AssistantContainerView::~AssistantContainerView() { AssistantContainerView::~AssistantContainerView() {
display::Screen::GetScreen()->RemoveObserver(this);
assistant_controller_->ui_controller()->RemoveModelObserver(this); assistant_controller_->ui_controller()->RemoveModelObserver(this);
} }
...@@ -237,11 +238,12 @@ void AssistantContainerView::RequestFocus() { ...@@ -237,11 +238,12 @@ void AssistantContainerView::RequestFocus() {
} }
} }
// TODO(dmblack): Handle dynamic re-anchoring due to shelf repositioning, etc. void AssistantContainerView::SetAnchor(aura::Window* root_window) {
void AssistantContainerView::SetAnchor() { if (!root_window)
root_window = Shell::Get()->GetRootWindowForNewWindows();
// Anchor to the display matching where new windows will be opened. // Anchor to the display matching where new windows will be opened.
display::Display display = display::Screen::GetScreen()->GetDisplayMatching( display::Display display = display::Screen::GetScreen()->GetDisplayMatching(
Shell::Get()->GetRootWindowForNewWindows()->GetBoundsInScreen()); root_window->GetBoundsInScreen());
// Anchor to the bottom center of the work area. // Anchor to the bottom center of the work area.
gfx::Rect work_area = display.work_area(); gfx::Rect work_area = display.work_area();
...@@ -249,6 +251,7 @@ void AssistantContainerView::SetAnchor() { ...@@ -249,6 +251,7 @@ void AssistantContainerView::SetAnchor() {
work_area.width(), 0); work_area.width(), 0);
SetAnchorRect(anchor); SetAnchorRect(anchor);
set_arrow(views::BubbleBorder::Arrow::BOTTOM_CENTER);
} }
void AssistantContainerView::OnUiModeChanged(AssistantUiMode ui_mode) { void AssistantContainerView::OnUiModeChanged(AssistantUiMode ui_mode) {
...@@ -301,4 +304,12 @@ void AssistantContainerView::AnimationProgressed( ...@@ -301,4 +304,12 @@ void AssistantContainerView::AnimationProgressed(
GetWidget()->SetBounds(bounds); GetWidget()->SetBounds(bounds);
} }
void AssistantContainerView::OnDisplayMetricsChanged(
const display::Display& display,
uint32_t changed_metrics) {
aura::Window* root_window = GetWidget()->GetNativeWindow()->GetRootWindow();
if (root_window == Shell::Get()->GetRootWindowForDisplayId(display.id()))
SetAnchor(root_window);
}
} // namespace ash } // namespace ash
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/assistant/model/assistant_ui_model_observer.h" #include "ash/assistant/model/assistant_ui_model_observer.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/display/display_observer.h"
#include "ui/gfx/animation/animation_delegate.h" #include "ui/gfx/animation/animation_delegate.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h" #include "ui/views/bubble/bubble_dialog_delegate_view.h"
...@@ -14,6 +15,10 @@ namespace gfx { ...@@ -14,6 +15,10 @@ namespace gfx {
class SlideAnimation; class SlideAnimation;
} // namespace gfx } // namespace gfx
namespace aura {
class Window;
} // namespace aura
namespace ash { namespace ash {
class AssistantController; class AssistantController;
...@@ -23,6 +28,7 @@ class AssistantWebView; ...@@ -23,6 +28,7 @@ class AssistantWebView;
class AssistantContainerView : public views::BubbleDialogDelegateView, class AssistantContainerView : public views::BubbleDialogDelegateView,
public AssistantUiModelObserver, public AssistantUiModelObserver,
public display::DisplayObserver,
public gfx::AnimationDelegate { public gfx::AnimationDelegate {
public: public:
explicit AssistantContainerView(AssistantController* assistant_controller); explicit AssistantContainerView(AssistantController* assistant_controller);
...@@ -44,8 +50,18 @@ class AssistantContainerView : public views::BubbleDialogDelegateView, ...@@ -44,8 +50,18 @@ class AssistantContainerView : public views::BubbleDialogDelegateView,
// gfx::AnimationDelegate: // gfx::AnimationDelegate:
void AnimationProgressed(const gfx::Animation* animation) override; void AnimationProgressed(const gfx::Animation* animation) override;
// display::DisplayObserver:
void OnWillProcessDisplayChanges() override {}
void OnDidProcessDisplayChanges() override {}
void OnDisplayAdded(const display::Display& new_display) override {}
void OnDisplayRemoved(const display::Display& old_display) override {}
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t changed_metrics) override;
private: private:
void SetAnchor(); // Sets anchor rect to |root_window|. If it's null,
// result of GetRootWindowForNewWindows() will be used.
void SetAnchor(aura::Window* root_window);
AssistantController* const assistant_controller_; // Owned by Shell. AssistantController* const assistant_controller_; // Owned by Shell.
......
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