Commit a8c00288 authored by Matthew Mourgos's avatar Matthew Mourgos Committed by Commit Bot

Reland Multipaste: Adjust the clipboard nudge bounds when hotseat is shown

This change has the clipboard nudge observe the hotseat state and will
animate the bounds of the clipboard nudge so that the nudge is always
placed above the hotseat.

Also, because the ClipboardNudge uses RootWindows the
clipboard_history_controller_ must be reset in before the
window_tree_host_manager_ is shutdown. This fixes the original CL which
was reverted due to msan issues.

Bug: 1137019
Change-Id: Ibbe8f06132f51d569a5ea4993df77ef042eabeb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2477524
Commit-Queue: Matthew Mourgos <mmourgos@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818547}
parent 0989247f
...@@ -8,11 +8,14 @@ ...@@ -8,11 +8,14 @@
#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/hotseat_widget.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h" #include "ash/style/ash_color_provider.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/chromeos/events/keyboard_layout_util.h" #include "ui/chromeos/events/keyboard_layout_util.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/border.h" #include "ui/views/border.h"
...@@ -49,6 +52,9 @@ constexpr int kIconLabelSpacing = 16; ...@@ -49,6 +52,9 @@ constexpr int kIconLabelSpacing = 16;
// The padding which separates the nudge's border with its inner contents. // The padding which separates the nudge's border with its inner contents.
constexpr int kNudgePadding = 16; constexpr int kNudgePadding = 16;
constexpr base::TimeDelta kNudgeBoundsAnimationTime =
base::TimeDelta::FromMilliseconds(250);
bool IsAssistantAvailable() { bool IsAssistantAvailable() {
AssistantStateBase* state = AssistantState::Get(); AssistantStateBase* state = AssistantState::Get();
return state->allowed_state() == return state->allowed_state() ==
...@@ -143,7 +149,11 @@ class ClipboardNudge::ClipboardNudgeView : public views::View { ...@@ -143,7 +149,11 @@ class ClipboardNudge::ClipboardNudgeView : public views::View {
views::ImageView* clipboard_icon_ = nullptr; views::ImageView* clipboard_icon_ = nullptr;
}; };
ClipboardNudge::ClipboardNudge() : widget_(std::make_unique<views::Widget>()) { ClipboardNudge::ClipboardNudge()
: widget_(std::make_unique<views::Widget>()),
root_window_(Shell::GetRootWindowForNewWindows()) {
shelf_observer_.Add(RootWindowController::ForWindow(root_window_)->shelf());
views::Widget::InitParams params( views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.z_order = ui::ZOrderLevel::kFloatingWindow; params.z_order = ui::ZOrderLevel::kFloatingWindow;
...@@ -151,8 +161,8 @@ ClipboardNudge::ClipboardNudge() : widget_(std::make_unique<views::Widget>()) { ...@@ -151,8 +161,8 @@ ClipboardNudge::ClipboardNudge() : widget_(std::make_unique<views::Widget>()) {
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.name = "ClipboardContextualNudge"; params.name = "ClipboardContextualNudge";
params.layer_type = ui::LAYER_NOT_DRAWN; params.layer_type = ui::LAYER_NOT_DRAWN;
params.parent = Shell::GetPrimaryRootWindow()->GetChildById( params.parent =
kShellWindowId_OverlayContainer); root_window_->GetChildById(kShellWindowId_SettingBubbleContainer);
widget_->Init(std::move(params)); widget_->Init(std::move(params));
nudge_view_ = nudge_view_ =
...@@ -163,14 +173,18 @@ ClipboardNudge::ClipboardNudge() : widget_(std::make_unique<views::Widget>()) { ...@@ -163,14 +173,18 @@ ClipboardNudge::ClipboardNudge() : widget_(std::make_unique<views::Widget>()) {
ClipboardNudge::~ClipboardNudge() = default; ClipboardNudge::~ClipboardNudge() = default;
void ClipboardNudge::OnHotseatStateChanged(HotseatState old_state,
HotseatState new_state) {
CalculateAndSetWidgetBounds();
}
void ClipboardNudge::Close() { void ClipboardNudge::Close() {
widget_->CloseWithReason(views::Widget::ClosedReason::kUnspecified); widget_->CloseWithReason(views::Widget::ClosedReason::kUnspecified);
} }
void ClipboardNudge::CalculateAndSetWidgetBounds() { void ClipboardNudge::CalculateAndSetWidgetBounds() {
aura::Window* root_window = Shell::GetRootWindowForNewWindows(); gfx::Rect display_bounds = root_window_->bounds();
gfx::Rect display_bounds = root_window->bounds(); ::wm::ConvertRectToScreen(root_window_, &display_bounds);
::wm::ConvertRectToScreen(root_window, &display_bounds);
gfx::Rect widget_bounds; gfx::Rect widget_bounds;
// Calculate the nudge's size to ensure the label text accurately fits. // Calculate the nudge's size to ensure the label text accurately fits.
...@@ -188,6 +202,26 @@ void ClipboardNudge::CalculateAndSetWidgetBounds() { ...@@ -188,6 +202,26 @@ void ClipboardNudge::CalculateAndSetWidgetBounds() {
if (base::i18n::IsRTL()) if (base::i18n::IsRTL())
widget_bounds.set_x(display_bounds.right() - nudge_width - kNudgeMargin); widget_bounds.set_x(display_bounds.right() - nudge_width - kNudgeMargin);
// Set the nudge's bounds above the hotseat when it is extended.
HotseatWidget* hotseat_widget =
RootWindowController::ForWindow(root_window_)->shelf()->hotseat_widget();
if (hotseat_widget->state() == HotseatState::kExtended) {
widget_bounds.set_y(hotseat_widget->GetTargetBounds().y() - nudge_height -
kNudgeMargin);
}
// Only run the widget bounds animation if the widget's bounds have already
// been initialized.
std::unique_ptr<ui::ScopedLayerAnimationSettings> settings;
if (widget_->GetWindowBoundsInScreen().size() != gfx::Size()) {
settings = std::make_unique<ui::ScopedLayerAnimationSettings>(
widget_->GetLayer()->GetAnimator());
settings->SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
settings->SetTransitionDuration(kNudgeBoundsAnimationTime);
settings->SetTweenType(gfx::Tween::EASE_OUT);
}
widget_->SetBounds(widget_bounds); widget_->SetBounds(widget_bounds);
} }
......
...@@ -6,18 +6,24 @@ ...@@ -6,18 +6,24 @@
#define ASH_CLIPBOARD_CLIPBOARD_NUDGE_H_ #define ASH_CLIPBOARD_CLIPBOARD_NUDGE_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_observer.h"
#include "base/scoped_observer.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace ash { namespace ash {
// Implements a contextual nudge for multipaste. // Implements a contextual nudge for multipaste.
class ASH_EXPORT ClipboardNudge { class ASH_EXPORT ClipboardNudge : public ShelfObserver {
public: public:
ClipboardNudge(); ClipboardNudge();
ClipboardNudge(const ClipboardNudge&) = delete; ClipboardNudge(const ClipboardNudge&) = delete;
ClipboardNudge& operator=(const ClipboardNudge&) = delete; ClipboardNudge& operator=(const ClipboardNudge&) = delete;
~ClipboardNudge(); ~ClipboardNudge() override;
// ShelfObserver overrides:
void OnHotseatStateChanged(HotseatState old_state,
HotseatState new_state) override;
void Close(); void Close();
private: private:
...@@ -30,8 +36,12 @@ class ASH_EXPORT ClipboardNudge { ...@@ -30,8 +36,12 @@ class ASH_EXPORT ClipboardNudge {
std::unique_ptr<views::Widget> widget_; std::unique_ptr<views::Widget> widget_;
ClipboardNudgeView* nudge_view_ = nullptr; // not_owned ClipboardNudgeView* nudge_view_ = nullptr; // not_owned
aura::Window* const root_window_;
ScopedObserver<Shelf, ShelfObserver> shelf_observer_{this};
}; };
} // namespace ash } // namespace ash
#endif // ASH_CLIPBOARD_CLIPBOARD_NUDGE_H_ #endif // ASH_CLIPBOARD_CLIPBOARD_NUDGE_H_
\ No newline at end of file
...@@ -822,6 +822,10 @@ Shell::~Shell() { ...@@ -822,6 +822,10 @@ Shell::~Shell() {
// Stop observing window activation changes before closing all windows. // Stop observing window activation changes before closing all windows.
focus_controller_->RemoveObserver(this); focus_controller_->RemoveObserver(this);
// Depends on shelf owned by RootWindowController so destroy this before the
// |window_tree_host_manager_|.
clipboard_history_controller_.reset();
// This also deletes all RootWindows. Note that we invoke Shutdown() on // This also deletes all RootWindows. Note that we invoke Shutdown() on
// WindowTreeHostManager before resetting |window_tree_host_manager_|, since // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
// destruction of its owned RootWindowControllers relies on the value. // destruction of its owned RootWindowControllers relies on the value.
......
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