Commit 779ce514 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Make ServerWindow responsible for interior resize handle event routing.

Bug: 883072
Change-Id: I24380dc595a7446e463422848916b73845945861
Reviewed-on: https://chromium-review.googlesource.com/1227357Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592943}
parent 404a6623
......@@ -10,7 +10,9 @@
#include "components/viz/host/host_frame_sink_manager.h"
#include "services/ws/drag_drop_delegate.h"
#include "services/ws/embedding.h"
#include "services/ws/public/mojom/window_tree_constants.mojom.h"
#include "services/ws/window_tree.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/capture_client_observer.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
......@@ -36,10 +38,22 @@ bool IsLocationInNonClientArea(const aura::Window* window,
if (!server_window || !server_window->IsTopLevel())
return false;
// Locations outside the bounds, assume it's in extended hit test area, which
// is non-client area.
if (!gfx::Rect(window->bounds().size()).Contains(location))
return true;
// Locations inside bounds but within the resize insets count as non-client
// area. Locations outside the bounds, assume it's in extended hit test area,
// which is non-client area.
ui::WindowShowState window_state =
window->GetProperty(aura::client::kShowStateKey);
if ((window->GetProperty(aura::client::kResizeBehaviorKey) &
ws::mojom::kResizeBehaviorCanResize) &&
(window_state != ui::WindowShowState::SHOW_STATE_MAXIMIZED) &&
(window_state != ui::WindowShowState::SHOW_STATE_FULLSCREEN)) {
int resize_handle_size =
window->GetProperty(aura::client::kResizeHandleInset);
gfx::Rect non_handle_area(window->bounds().size());
non_handle_area.Inset(gfx::Insets(resize_handle_size));
if (!non_handle_area.Contains(location))
return true;
}
gfx::Rect client_area(window->bounds().size());
client_area.Inset(server_window->client_area());
......
......@@ -11,6 +11,7 @@
#include "services/ws/window_tree.h"
#include "services/ws/window_tree_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/wm/core/easy_resize_window_targeter.h"
......@@ -48,4 +49,42 @@ TEST(ServerWindow, FindTargetForWindowWithEasyResizeTargeter) {
setup.root(), &mouse_event2));
}
TEST(ServerWindow, FindTargetForWindowWithResizeInset) {
WindowServiceTestSetup setup;
aura::Window* top_level =
setup.window_tree_test_helper()->NewTopLevelWindow();
ASSERT_TRUE(top_level);
const gfx::Rect top_level_bounds(100, 200, 200, 200);
top_level->SetBounds(top_level_bounds);
top_level->Show();
aura::Window* child_window = setup.window_tree_test_helper()->NewWindow();
ASSERT_TRUE(child_window);
top_level->AddChild(child_window);
child_window->SetBounds(gfx::Rect(top_level_bounds.size()));
child_window->Show();
const int kInset = 4;
// Target an event at the resize inset area.
gfx::Point click_point =
top_level_bounds.left_center() + gfx::Vector2d(kInset / 2, 0);
// With no resize inset set yet, the event should go to the child window.
ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, click_point, click_point,
base::TimeTicks::Now(),
/* flags */ 0,
/* changed_button_flags_ */ 0);
EXPECT_EQ(child_window, setup.root()->targeter()->FindTargetForEvent(
setup.root(), &mouse_event));
// With the resize inset, the event should go to the toplevel.
top_level->SetProperty(aura::client::kResizeHandleInset, kInset);
ui::MouseEvent mouse_event_2(ui::ET_MOUSE_PRESSED, click_point, click_point,
base::TimeTicks::Now(),
/* flags */ 0,
/* changed_button_flags_ */ 0);
EXPECT_EQ(top_level, setup.root()->targeter()->FindTargetForEvent(
setup.root(), &mouse_event_2));
}
} // namespace ws
......@@ -68,6 +68,7 @@ DEFINE_UI_CLASS_PROPERTY_KEY(
DEFINE_UI_CLASS_PROPERTY_KEY(int32_t,
kResizeBehaviorKey,
ws::mojom::kResizeBehaviorCanResize);
DEFINE_UI_CLASS_PROPERTY_KEY(int, kResizeHandleInset, 0);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect, kRestoreBoundsKey, nullptr);
DEFINE_UI_CLASS_PROPERTY_KEY(
ui::WindowShowState, kShowStateKey, ui::SHOW_STATE_DEFAULT);
......
......@@ -124,6 +124,12 @@ AURA_EXPORT extern const WindowProperty<ui::WindowShowState>* const
// ws::mojom::kResizeBehavior values.
AURA_EXPORT extern const WindowProperty<int32_t>* const kResizeBehaviorKey;
// Reserves a number of dip around the window (i.e. inset from its exterior
// border) for event routing back to the top level window. This is used for
// routing events to toplevel window resize handles. It should only be respected
// for restored windows (maximized and fullscreen can't be drag-resized).
AURA_EXPORT extern const WindowProperty<int>* const kResizeHandleInset;
// A property key to store the restore bounds in screen coordinates for a
// window.
AURA_EXPORT extern const WindowProperty<gfx::Rect*>* const kRestoreBoundsKey;
......
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