From dc450d8b1a13e924f44aed81dddd48db036911f1 Mon Sep 17 00:00:00 2001 From: "tdanderson@chromium.org" Date: Fri, 21 Feb 2014 02:09:16 +0000 Subject: [PATCH] Allow resizing of packaged app windows in Windows desktop mode Install an EasyResizeWindowTargeter on the containing root window to allow for selection handles to appear at the edges of the client area, allowing packaged apps to be resized. BUG=338671 TEST=ShapedAppWindowTargeterTest.ResizeInsetsWithinBounds Review URL: https://codereview.chromium.org/167633002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252458 0039d316-1c4b-4281-b951-d872f2087c98 --- apps/ui/views/app_window_frame_view.cc | 11 ----- .../ui/views/apps/native_app_window_views.cc | 17 +++++++ .../ui/views/apps/native_app_window_views.h | 7 +++ .../apps/shaped_app_window_targeter_unittest.cc | 52 ++++++++++++++++++++++ chrome/browser/ui/views/panels/panel_frame_view.cc | 1 + 5 files changed, 77 insertions(+), 11 deletions(-) diff --git a/apps/ui/views/app_window_frame_view.cc b/apps/ui/views/app_window_frame_view.cc index 57e9deb90e1f..a8c11c3d9c6e 100644 --- a/apps/ui/views/app_window_frame_view.cc +++ b/apps/ui/views/app_window_frame_view.cc @@ -118,17 +118,6 @@ void AppWindowFrameView::Init(views::Widget* frame, l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); AddChildView(minimize_button_); } - -#if defined(USE_AURA) - aura::Window* window = frame->GetNativeWindow(); - // Ensure we get resize cursors just inside our bounds as well. - // TODO(jeremya): do we need to update these when in fullscreen/maximized? - window->set_hit_test_bounds_override_inner( - gfx::Insets(resize_inside_bounds_size_, - resize_inside_bounds_size_, - resize_inside_bounds_size_, - resize_inside_bounds_size_)); -#endif } // views::NonClientFrameView implementation. diff --git a/chrome/browser/ui/views/apps/native_app_window_views.cc b/chrome/browser/ui/views/apps/native_app_window_views.cc index b835356a10fe..e465d1f5aff3 100644 --- a/chrome/browser/ui/views/apps/native_app_window_views.cc +++ b/chrome/browser/ui/views/apps/native_app_window_views.cc @@ -34,6 +34,7 @@ #include "ui/views/controls/webview/webview.h" #include "ui/views/widget/widget.h" #include "ui/views/window/non_client_view.h" +#include "ui/wm/public/easy_resize_window_targeter.h" #if defined(OS_LINUX) #include "chrome/browser/shell_integration_linux.h" @@ -229,6 +230,14 @@ void NativeAppWindowViews::Init(apps::AppWindow* app_window, OnViewWasResized(); window_->AddObserver(this); + +#if defined(OS_WIN) + if (ShouldUseChromeStyleFrame() && + chrome::GetHostDesktopTypeForNativeWindow(window_->GetNativeWindow()) != + chrome::HOST_DESKTOP_TYPE_ASH) { + InstallEasyResizeTargeterOnContainer(); + } +#endif } NativeAppWindowViews::~NativeAppWindowViews() { @@ -380,6 +389,14 @@ bool NativeAppWindowViews::ShouldUseChromeStyleFrame() const { switches::kAppsUseNativeFrame); } +void NativeAppWindowViews::InstallEasyResizeTargeterOnContainer() const { + aura::Window* root_window = window_->GetNativeWindow()->GetRootWindow(); + gfx::Insets inset(kResizeInsideBoundsSize, kResizeInsideBoundsSize, + kResizeInsideBoundsSize, kResizeInsideBoundsSize); + root_window->SetEventTargeter(scoped_ptr( + new wm::EasyResizeWindowTargeter(root_window, inset, inset))); +} + apps::AppWindowFrameView* NativeAppWindowViews::CreateAppWindowFrameView() { // By default the user can resize the window from slightly inside the bounds. int resize_inside_bounds_size = kResizeInsideBoundsSize; diff --git a/chrome/browser/ui/views/apps/native_app_window_views.h b/chrome/browser/ui/views/apps/native_app_window_views.h index ebcf654e57fe..3146b6eca1aa 100644 --- a/chrome/browser/ui/views/apps/native_app_window_views.h +++ b/chrome/browser/ui/views/apps/native_app_window_views.h @@ -86,11 +86,18 @@ class NativeAppWindowViews : public apps::NativeAppWindow, private: friend class ShapedAppWindowTargeterTest; + FRIEND_TEST_ALL_PREFIXES(ShapedAppWindowTargeterTest, + ResizeInsetsWithinBounds); void OnViewWasResized(); bool ShouldUseChromeStyleFrame() const; + // Installs an EasyResizeWindowTargeter on the containing window, which + // allows the window to be resized from within |kResizeInsideBoundsSize| + // pixels inside the window bounds. + void InstallEasyResizeTargeterOnContainer() const; + // Caller owns the returned object. apps::AppWindowFrameView* CreateAppWindowFrameView(); diff --git a/chrome/browser/ui/views/apps/shaped_app_window_targeter_unittest.cc b/chrome/browser/ui/views/apps/shaped_app_window_targeter_unittest.cc index 08bd65ed1fcf..59fc29ce8425 100644 --- a/chrome/browser/ui/views/apps/shaped_app_window_targeter_unittest.cc +++ b/chrome/browser/ui/views/apps/shaped_app_window_targeter_unittest.cc @@ -149,3 +149,55 @@ TEST_F(ShapedAppWindowTargeterTest, HitTestOnlyForShapedWindow) { EXPECT_EQ(window, move.target()); } } + +// Tests targeting of events on a window with an EasyResizeWindowTargeter +// installed on its container. +TEST_F(ShapedAppWindowTargeterTest, ResizeInsetsWithinBounds) { + aura::Window* window = widget()->GetNativeWindow(); + { + // An event in the center of the window should always have + // |window| as its target. + ui::MouseEvent move(ui::ET_MOUSE_MOVED, + gfx::Point(80, 80), gfx::Point(80, 80), + ui::EF_NONE, ui::EF_NONE); + ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); + ASSERT_FALSE(details.dispatcher_destroyed); + EXPECT_EQ(window, move.target()); + } + { + // Without an EasyResizeTargeter on the container, an event + // inside the window and within 5px of an edge should have + // |window| as its target. + ui::MouseEvent move(ui::ET_MOUSE_MOVED, + gfx::Point(32, 37), gfx::Point(32, 37), + ui::EF_NONE, ui::EF_NONE); + ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); + ASSERT_FALSE(details.dispatcher_destroyed); + EXPECT_EQ(window, move.target()); + } + + // The EasyResizeTargeter specifies an inset of 5px within the window. + app_window_views()->InstallEasyResizeTargeterOnContainer(); + + { + // An event in the center of the window should always have + // |window| as its target. + ui::MouseEvent move(ui::ET_MOUSE_MOVED, + gfx::Point(80, 80), gfx::Point(80, 80), + ui::EF_NONE, ui::EF_NONE); + ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); + ASSERT_FALSE(details.dispatcher_destroyed); + EXPECT_EQ(window, move.target()); + } + { + // With an EasyResizeTargeter on the container, an event + // inside the window and within 5px of an edge should have + // root_window() as its target. + ui::MouseEvent move(ui::ET_MOUSE_MOVED, + gfx::Point(32, 37), gfx::Point(32, 37), + ui::EF_NONE, ui::EF_NONE); + ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); + ASSERT_FALSE(details.dispatcher_destroyed); + EXPECT_EQ(root_window(), move.target()); + } +} diff --git a/chrome/browser/ui/views/panels/panel_frame_view.cc b/chrome/browser/ui/views/panels/panel_frame_view.cc index 6dda80077d23..30667d950f22 100644 --- a/chrome/browser/ui/views/panels/panel_frame_view.cc +++ b/chrome/browser/ui/views/panels/panel_frame_view.cc @@ -314,6 +314,7 @@ void PanelFrameView::Init() { #if defined(USE_AURA) // Compute the thickness of the client area that needs to be counted towards // mouse resizing. + // TODO(tdanderson): Remove this if possible (crbug.com/344924). int thickness_for_mouse_resizing = PanelView::kResizeInsideBoundsSize - BorderThickness(); aura::Window* window = panel_view_->GetNativePanelWindow(); -- 2.11.4.GIT