Commit 245fe212 authored by Eliot Courtney's avatar Eliot Courtney Committed by Commit Bot

Add property to mark windows as ignored for PIP collision detection.

Also, mark status bar tooltip bubbles as ignored for PIP collision
detection using this mechanism.

Bug: b/127838266
Test: unit test
Change-Id: I02d4fb093199eef97f29dc1283105f12b36cbe1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1530275
Commit-Queue: Eliot Courtney <edcourtney@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645233}
parent bb0991fc
......@@ -5,6 +5,7 @@
#include "ash/shelf/shelf_tooltip_bubble.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/wm/pip/pip_positioner.h"
#include "ui/aura/window.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
......@@ -60,6 +61,8 @@ ShelfTooltipBubble::ShelfTooltipBubble(views::View* anchor,
set_anchor_view_insets(insets);
CreateBubble();
PipPositioner::MarkWindowAsIgnoredForCollisionDetection(
GetWidget()->GetNativeWindow());
}
gfx::Size ShelfTooltipBubble::CalculatePreferredSize() const {
......
......@@ -14,6 +14,7 @@
#include "ash/shelf/shelf_view_test_api.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/pip/pip_positioner.h"
#include "base/run_loop.h"
#include "ui/events/event_constants.h"
#include "ui/events/test/event_generator.h"
......@@ -219,4 +220,16 @@ TEST_F(ShelfTooltipManagerTest, KeyEvents) {
EXPECT_FALSE(tooltip_manager_->IsVisible());
}
TEST_F(ShelfTooltipManagerTest, ShelfTooltipDoesNotAffectPipWindow) {
tooltip_manager_->ShowTooltip(shelf_view_->GetAppListButton());
EXPECT_TRUE(tooltip_manager_->IsVisible());
auto display = display::Screen::GetScreen()->GetPrimaryDisplay();
auto tooltip_bounds = GetTooltip()->GetWindowBoundsInScreen();
tooltip_bounds.Intersect(PipPositioner::GetMovementArea(display));
EXPECT_FALSE(tooltip_bounds.IsEmpty());
EXPECT_EQ(tooltip_bounds,
PipPositioner::GetRestingPosition(display, tooltip_bounds));
}
} // namespace ash
......@@ -5,6 +5,7 @@
#include "ash/shelf/shelf_tooltip_preview_bubble.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/wm/pip/pip_positioner.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/views/bubble/bubble_frame_view.h"
......@@ -41,6 +42,8 @@ ShelfTooltipPreviewBubble::ShelfTooltipPreviewBubble(
}
CreateBubble();
PipPositioner::MarkWindowAsIgnoredForCollisionDetection(
GetWidget()->GetNativeWindow());
}
ShelfTooltipPreviewBubble::~ShelfTooltipPreviewBubble() = default;
......
......@@ -24,6 +24,10 @@ namespace {
const int kPipWorkAreaInsetsDp = 8;
const float kPipDismissMovementProportion = 1.5f;
// A property key to store whether the a window should be ignored for PIP
// collision detection. For example, StatusBubble windows.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kIgnoreForPipCollisionDetection, false)
enum { GRAVITY_LEFT, GRAVITY_RIGHT, GRAVITY_TOP, GRAVITY_BOTTOM };
// Returns the result of adjusting |bounds| according to |gravity| inside
......@@ -85,6 +89,10 @@ gfx::Rect ComputeCollisionRectFromBounds(const gfx::Rect& bounds,
return collision_rect;
}
bool ShouldIgnoreWindowForCollision(const aura::Window* window) {
return window->GetProperty(kIgnoreForPipCollisionDetection);
}
std::vector<gfx::Rect> CollectCollisionRects(const display::Display& display) {
std::vector<gfx::Rect> rects;
auto* root_window = Shell::GetRootWindowForDisplayId(display.id());
......@@ -95,6 +103,8 @@ std::vector<gfx::Rect> CollectCollisionRects(const display::Display& display) {
for (auto* window : settings_bubble_container->children()) {
if (!window->IsVisible() && !window->GetTargetBounds().IsEmpty())
continue;
if (ShouldIgnoreWindowForCollision(window))
continue;
// Use the target bounds in case an animation is in progress.
rects.push_back(ComputeCollisionRectFromBounds(window->GetTargetBounds(),
window->parent()));
......@@ -103,7 +113,7 @@ std::vector<gfx::Rect> CollectCollisionRects(const display::Display& display) {
// Check auto-hide shelf, which isn't included normally in the work area:
auto* shelf = Shelf::ForWindow(root_window);
auto* shelf_window = shelf->GetWindow();
if (shelf->IsVisible())
if (shelf->IsVisible() && !ShouldIgnoreWindowForCollision(shelf_window))
rects.push_back(ComputeCollisionRectFromBounds(
shelf_window->GetTargetBounds(), shelf_window->parent()));
}
......@@ -113,7 +123,9 @@ std::vector<gfx::Rect> CollectCollisionRects(const display::Display& display) {
keyboard_controller->GetActiveContainerType() ==
keyboard::mojom::ContainerType::kFloating &&
keyboard_controller->GetRootWindow() == root_window &&
!keyboard_controller->visual_bounds_in_screen().IsEmpty()) {
!keyboard_controller->visual_bounds_in_screen().IsEmpty() &&
!ShouldIgnoreWindowForCollision(
keyboard_controller->GetKeyboardWindow())) {
// TODO(shend): visual_bounds_in_screen should return the bounds in screen
// coordinates. See crbug.com/943446.
rects.push_back(ComputeCollisionRectFromBounds(
......@@ -273,6 +285,11 @@ gfx::Rect PipPositioner::GetPositionAfterMovementAreaChange(
return GetRestingPosition(window_state->GetDisplay(), bounds_in_screen);
}
void PipPositioner::MarkWindowAsIgnoredForCollisionDetection(
aura::Window* window) {
window->SetProperty(kIgnoreForPipCollisionDetection, true);
}
gfx::Rect PipPositioner::AvoidObstacles(const display::Display& display,
const gfx::Rect& bounds_in_screen) {
gfx::Rect work_area = GetMovementArea(display);
......
......@@ -10,6 +10,7 @@
#include "ash/ash_export.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "ui/aura/window.h"
#include "ui/display/display.h"
#include "ui/gfx/geometry/rect.h"
......@@ -56,6 +57,9 @@ class ASH_EXPORT PipPositioner {
static gfx::Rect GetPositionAfterMovementAreaChange(
wm::WindowState* window_state);
// Mark a window as ignored for PIP collision detection.
static void MarkWindowAsIgnoredForCollisionDetection(aura::Window* window);
private:
friend class PipPositionerDisplayTest;
friend class PipPositionerLogicTest;
......
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