[M87]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.
(cherry picked from commit d1b3da5abdca2855ea6d6d02d82543a073e4bf72)
Bug: 1137019
Change-Id: If00afa1585e0382d7aa41789eca2a981b1323f1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2469364
Commit-Queue: Matthew Mourgos <[email protected]>
Reviewed-by: Alex Newcomer <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#817235}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2473765
Reviewed-by: Matthew Mourgos <[email protected]>
Cr-Commit-Position: refs/branch-heads/4280@{#406}
Cr-Branched-From: ea420fb963f9658c9969b6513c56b8f47efa1a2a-refs/heads/master@{#812852}
diff --git a/ash/clipboard/clipboard_nudge.cc b/ash/clipboard/clipboard_nudge.cc
index 41c23eb..6a5aab1 100644
--- a/ash/clipboard/clipboard_nudge.cc
+++ b/ash/clipboard/clipboard_nudge.cc
@@ -8,11 +8,14 @@
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shell_window_ids.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/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ui/base/l10n/l10n_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/paint_vector_icon.h"
#include "ui/views/border.h"
@@ -49,6 +52,9 @@
// The padding which separates the nudge's border with its inner contents.
constexpr int kNudgePadding = 16;
+constexpr base::TimeDelta kNudgeBoundsAnimationTime =
+ base::TimeDelta::FromMilliseconds(250);
+
bool IsAssistantAvailable() {
AssistantStateBase* state = AssistantState::Get();
return state->allowed_state() ==
@@ -143,7 +149,11 @@
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::TYPE_WINDOW_FRAMELESS);
params.z_order = ui::ZOrderLevel::kFloatingWindow;
@@ -151,8 +161,8 @@
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.name = "ClipboardContextualNudge";
params.layer_type = ui::LAYER_NOT_DRAWN;
- params.parent = Shell::GetPrimaryRootWindow()->GetChildById(
- kShellWindowId_OverlayContainer);
+ params.parent =
+ root_window_->GetChildById(kShellWindowId_SettingBubbleContainer);
widget_->Init(std::move(params));
nudge_view_ =
@@ -163,14 +173,18 @@
ClipboardNudge::~ClipboardNudge() = default;
+void ClipboardNudge::OnHotseatStateChanged(HotseatState old_state,
+ HotseatState new_state) {
+ CalculateAndSetWidgetBounds();
+}
+
void ClipboardNudge::Close() {
widget_->CloseWithReason(views::Widget::ClosedReason::kUnspecified);
}
void ClipboardNudge::CalculateAndSetWidgetBounds() {
- aura::Window* root_window = Shell::GetRootWindowForNewWindows();
- gfx::Rect display_bounds = root_window->bounds();
- ::wm::ConvertRectToScreen(root_window, &display_bounds);
+ gfx::Rect display_bounds = root_window_->bounds();
+ ::wm::ConvertRectToScreen(root_window_, &display_bounds);
gfx::Rect widget_bounds;
// Calculate the nudge's size to ensure the label text accurately fits.
@@ -188,6 +202,26 @@
if (base::i18n::IsRTL())
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);
}
diff --git a/ash/clipboard/clipboard_nudge.h b/ash/clipboard/clipboard_nudge.h
index 2724461..e5010eb 100644
--- a/ash/clipboard/clipboard_nudge.h
+++ b/ash/clipboard/clipboard_nudge.h
@@ -6,18 +6,24 @@
#define ASH_CLIPBOARD_CLIPBOARD_NUDGE_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"
namespace ash {
// Implements a contextual nudge for multipaste.
-class ASH_EXPORT ClipboardNudge {
+class ASH_EXPORT ClipboardNudge : public ShelfObserver {
public:
ClipboardNudge();
ClipboardNudge(const ClipboardNudge&) = delete;
ClipboardNudge& operator=(const ClipboardNudge&) = delete;
- ~ClipboardNudge();
+ ~ClipboardNudge() override;
+ // ShelfObserver overrides:
+ void OnHotseatStateChanged(HotseatState old_state,
+ HotseatState new_state) override;
void Close();
private:
@@ -30,6 +36,10 @@
std::unique_ptr<views::Widget> widget_;
ClipboardNudgeView* nudge_view_ = nullptr; // not_owned
+
+ aura::Window* const root_window_;
+
+ ScopedObserver<Shelf, ShelfObserver> shelf_observer_{this};
};
} // namespace ash