Commit 2dc34bfc authored by Jazz Xu's avatar Jazz Xu Committed by Commit Bot

GMC: Enable dragging for overlay media notifications.

Bug: 1093968
Change-Id: I4a9d9de174a3a48713f7333c45e2aee3c7f8f07c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2240896
Commit-Queue: Jazz Xu <jazzhsu@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779791}
parent 6472cb97
......@@ -162,9 +162,18 @@ bool MediaNotificationContainerImplView::OnMouseDragged(
if (movement.LengthSquared() >= kMinMovementSquaredToBeDragging)
is_dragging_ = true;
// If we are in an overlay notification, we want to drag the overlay
// instead.
if (dragged_out_) {
overlay_->SetBoundsConstrained(overlay_->GetWindowBoundsInScreen() +
movement);
return true;
}
gfx::Transform transform;
transform.Translate(movement);
swipeable_container_->layer()->SetTransform(transform);
return true;
}
......@@ -174,6 +183,9 @@ void MediaNotificationContainerImplView::OnMouseReleased(
if (!ShouldHandleMouseEvent(event, /*is_press=*/false))
return;
if (dragged_out_)
return;
gfx::Vector2d movement = event.location() - initial_drag_location_;
gfx::Rect bounds_in_screen = GetBoundsInScreen();
......@@ -383,10 +395,6 @@ bool MediaNotificationContainerImplView::ShouldHandleMouseEvent(
if (!base::FeatureList::IsEnabled(media::kGlobalMediaControlsOverlayControls))
return false;
// We also don't need to handle if we're already dragged out.
if (dragged_out_)
return false;
// We only handle non-press events if we've handled the associated press
// event.
if (!is_press && !is_mouse_pressed_)
......
......@@ -31,15 +31,7 @@ class OverlayMediaNotificationFrameView : public views::NonClientFrameView {
return bounds();
}
int NonClientHitTest(const gfx::Point& point) override {
if (!bounds().Contains(point))
return HTNOWHERE;
// TODO(steimel): This should be smarter, but we need to figure out how we
// want to handle dragging vs click-to-go-to-tab.
if (GetDraggingBounds().Contains(point))
return HTCAPTION;
return HTCLIENT;
return bounds().Contains(point) ? HTCLIENT : HTNOWHERE;
}
void GetWindowMask(const gfx::Size& size, SkPath* window_mask) override {}
void ResetWindowControls() override {}
......
......@@ -4,10 +4,13 @@
#include "chrome/browser/ui/views/global_media_controls/overlay_media_notification_view.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/global_media_controls/overlay_media_notifications_manager.h"
#include "chrome/browser/ui/views/global_media_controls/media_notification_container_impl_view.h"
#include "chrome/test/views/chrome_views_test_base.h"
#include "media/base/media_switches.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/events/base_event_utils.h"
#include "ui/views/widget/widget_delegate.h"
namespace {
......@@ -32,11 +35,14 @@ class OverlayMediaNotificationViewTest : public ChromeViewsTestBase {
void SetUp() override {
ViewsTestBase::SetUp();
feature_list_.InitAndEnableFeature(
media::kGlobalMediaControlsOverlayControls);
manager_ = std::make_unique<MockOverlayMediaNotificationsManager>();
auto notification = std::make_unique<MediaNotificationContainerImplView>(
kTestNotificationId, nullptr);
notification->PopOut();
overlay_ = std::make_unique<OverlayMediaNotificationView>(
kTestNotificationId, std::move(notification),
......@@ -64,6 +70,18 @@ class OverlayMediaNotificationViewTest : public ChromeViewsTestBase {
overlay_->notification_for_testing()->OnExpanded(expand);
}
void SimulateMouseDrag(const gfx::Vector2d drag_distance) {
gfx::Point start_point = GetContainer()->bounds().CenterPoint();
gfx::Point end_point = start_point + drag_distance;
GetContainer()->OnMousePressed(
ui::MouseEvent(ui::ET_MOUSE_PRESSED, start_point, start_point,
ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0));
GetContainer()->OnMouseDragged(
ui::MouseEvent(ui::ET_MOUSE_DRAGGED, end_point, end_point,
ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0));
}
base::string16 GetWindowTitle() {
return overlay_->widget_delegate()->GetWindowTitle();
}
......@@ -72,6 +90,12 @@ class OverlayMediaNotificationViewTest : public ChromeViewsTestBase {
return overlay_->GetWindowBoundsInScreen().size();
}
MediaNotificationContainerImplView* GetContainer() {
return overlay_->notification_for_testing();
}
OverlayMediaNotificationView* GetOverlay() { return overlay_.get(); }
private:
media_message_center::MediaNotificationViewImpl* GetView() {
return overlay_->notification_for_testing()->view_for_testing();
......@@ -80,6 +104,8 @@ class OverlayMediaNotificationViewTest : public ChromeViewsTestBase {
std::unique_ptr<MockOverlayMediaNotificationsManager> manager_ = nullptr;
std::unique_ptr<OverlayMediaNotificationView> overlay_ = nullptr;
base::test::ScopedFeatureList feature_list_;
};
TEST_F(OverlayMediaNotificationViewTest, TaskBarTitle) {
......@@ -104,3 +130,13 @@ TEST_F(OverlayMediaNotificationViewTest, ResizeOnExpandStateChanged) {
SimulateExpandStateChanged(false);
EXPECT_EQ(kNormalHeight, GetWindowSize().height());
}
TEST_F(OverlayMediaNotificationViewTest, Dragging) {
gfx::Point start_position = GetOverlay()->GetWindowBoundsInScreen().origin();
gfx::Vector2d drag_distance(100, 100);
SimulateMouseDrag(drag_distance);
EXPECT_EQ(GetOverlay()->GetWindowBoundsInScreen().origin(),
start_position + drag_distance);
}
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