0

ash: Use different hit-test outer-region for mouse and touch events.

The hit-region for windows need to be larger for touch events to allow
resizing windows easily, while continuing to use a smaller hit-region
for mouse-events.

BUG=135187

Review URL: https://chromiumcodereview.appspot.com/10854060

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150870 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
sadrul@chromium.org
2012-08-09 19:42:39 +00:00
parent 37e47023fb
commit a86445bd3d
9 changed files with 51 additions and 32 deletions

@ -13,8 +13,8 @@ namespace ash {
DEFINE_WINDOW_PROPERTY_KEY(bool, kConstrainedWindowKey, false);
const int kResizeAreaCornerSize = 16;
const int kResizeOutsideBoundsSizeTouch = 30;
const int kResizeOutsideBoundsSize = 6;
const int kResizeOutsideBoundsScaleForTouch = 5;
const int kResizeInsideBoundsSize = 1;
} // namespace ash

@ -24,8 +24,8 @@ ASH_EXPORT extern const int kResizeAreaCornerSize;
// extends to the edge of the window. We consider a small region outside the
// window bounds and an even smaller region overlapping the window to be the
// "non-client" area and use it for resizing.
ASH_EXPORT extern const int kResizeOutsideBoundsSizeTouch;
ASH_EXPORT extern const int kResizeOutsideBoundsSize;
ASH_EXPORT extern const int kResizeOutsideBoundsScaleForTouch;
ASH_EXPORT extern const int kResizeInsideBoundsSize;
} // namespace ash

@ -181,12 +181,10 @@ void FramePainter::Init(views::Widget* frame,
window_ = frame->GetNativeWindow();
// Ensure we get resize cursors for a few pixels outside our bounds.
int outside_bounds = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ?
kResizeOutsideBoundsSizeTouch :
kResizeOutsideBoundsSize;
window_->set_hit_test_bounds_override_outer(
gfx::Insets(-outside_bounds, -outside_bounds,
-outside_bounds, -outside_bounds));
window_->SetHitTestBoundsOverrideOuter(
gfx::Insets(-kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize,
-kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize),
kResizeOutsideBoundsScaleForTouch);
// Ensure we get resize cursors just inside our bounds as well.
window_->set_hit_test_bounds_override_inner(
gfx::Insets(kResizeInsideBoundsSize, kResizeInsideBoundsSize,
@ -224,7 +222,7 @@ int FramePainter::NonClientHitTest(views::NonClientFrameView* view,
if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH &&
aura::Env::GetInstance()->is_touch_down()) {
outside_bounds = kResizeOutsideBoundsSizeTouch;
outside_bounds *= kResizeOutsideBoundsScaleForTouch;
}
expanded_bounds.Inset(-outside_bounds, -outside_bounds);

@ -585,10 +585,11 @@ void ShelfLayoutManager::UpdateHitTestBounds() {
break;
}
}
if (launcher_widget() && launcher_widget()->GetNativeWindow())
launcher_widget()->GetNativeWindow()->set_hit_test_bounds_override_outer(
insets);
status_->GetNativeWindow()->set_hit_test_bounds_override_outer(insets);
if (launcher_widget() && launcher_widget()->GetNativeWindow()) {
launcher_widget()->GetNativeWindow()->SetHitTestBoundsOverrideOuter(
insets, 1);
}
status_->GetNativeWindow()->SetHitTestBoundsOverrideOuter( insets, 1);
}
bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) {

@ -37,6 +37,7 @@
#if defined(USE_ASH)
#include "ash/ash_constants.h"
#include "ash/wm/custom_frame_view_ash.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#endif
@ -121,12 +122,12 @@ void ShellWindowFrameView::Init(views::Widget* frame) {
#if defined(USE_ASH)
aura::Window* window = frame->GetNativeWindow();
// Ensure we get resize cursors for a few pixels outside our bounds.
int outside_bounds = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ?
ash::kResizeOutsideBoundsSizeTouch :
ash::kResizeOutsideBoundsSize;
window->set_hit_test_bounds_override_outer(
gfx::Insets(-outside_bounds, -outside_bounds,
-outside_bounds, -outside_bounds));
window->SetHitTestBoundsOverrideOuter(
gfx::Insets(-ash::kResizeOutsideBoundsSize,
-ash::kResizeOutsideBoundsSize,
-ash::kResizeOutsideBoundsSize,
-ash::kResizeOutsideBoundsSize),
ash::kResizeOutsideBoundsScaleForTouch);
// 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(
@ -162,9 +163,11 @@ int ShellWindowFrameView::NonClientHitTest(const gfx::Point& point) {
#if defined(USE_ASH)
gfx::Rect expanded_bounds = bounds();
int outside_bounds = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ?
ash::kResizeOutsideBoundsSizeTouch :
ash::kResizeOutsideBoundsSize;
int outside_bounds = ash::kResizeOutsideBoundsSize;
if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH &&
aura::Env::GetInstance()->is_touch_down()) {
outside_bounds *= ash::kResizeOutsideBoundsScaleForTouch;
}
expanded_bounds.Inset(-outside_bounds, -outside_bounds);
if (!expanded_bounds.Contains(point))
return HTNOWHERE;

@ -496,7 +496,9 @@ bool Window::HitTest(const gfx::Point& local_point) {
// Expand my bounds for hit testing (override is usually zero but it's
// probably cheaper to do the math every time than to branch).
gfx::Rect local_bounds(gfx::Point(), bounds().size());
local_bounds.Inset(hit_test_bounds_override_outer_);
local_bounds.Inset(aura::Env::GetInstance()->is_touch_down() ?
hit_test_bounds_override_outer_touch_ :
hit_test_bounds_override_outer_mouse_);
if (!delegate_ || !delegate_->HasHitTestMask())
return local_bounds.Contains(local_point);

@ -241,14 +241,17 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
void set_ignore_events(bool ignore_events) { ignore_events_ = ignore_events; }
// Sets the window to grab hits for an area extending -|insets| pixels outside
// its bounds. This can be used to create an invisible non- client area, for
// its bounds. This can be used to create an invisible non-client area, for
// example if your windows have no visible frames but still need to have
// resize edges.
void set_hit_test_bounds_override_outer(const gfx::Insets& insets) {
hit_test_bounds_override_outer_ = insets;
// resize edges. It is possible to set a larger hit-region for touch-events.
void SetHitTestBoundsOverrideOuter(const gfx::Insets& mouse_insets,
int touch_scale) {
hit_test_bounds_override_outer_mouse_ = mouse_insets;
hit_test_bounds_override_outer_touch_ = mouse_insets.Scale(touch_scale);
}
gfx::Insets hit_test_bounds_override_outer() const {
return hit_test_bounds_override_outer_;
gfx::Insets hit_test_bounds_override_outer_mouse() const {
return hit_test_bounds_override_outer_mouse_;
}
// Sets the window to grab hits for an area extending |insets| pixels inside
@ -469,7 +472,8 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
bool ignore_events_;
// See set_hit_test_outer_override().
gfx::Insets hit_test_bounds_override_outer_;
gfx::Insets hit_test_bounds_override_outer_mouse_;
gfx::Insets hit_test_bounds_override_outer_touch_;
gfx::Insets hit_test_bounds_override_inner_;
ObserverList<WindowObserver> observers_;

@ -429,10 +429,21 @@ TEST_F(WindowTest, HitTest) {
EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1)));
// We can expand the bounds slightly to track events outside our border.
w1.set_hit_test_bounds_override_outer(gfx::Insets(-1, -1, -1, -1));
w1.SetHitTestBoundsOverrideOuter(gfx::Insets(-1, -1, -1, -1), 5);
EXPECT_TRUE(w1.HitTest(gfx::Point(-1, -1)));
EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2)));
ui::TouchEventImpl pressed(
ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 0, getTime());
root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&pressed);
EXPECT_TRUE(w1.HitTest(gfx::Point(-2, -2)));
EXPECT_TRUE(w1.HitTest(gfx::Point(-5, -5)));
EXPECT_FALSE(w1.HitTest(gfx::Point(-5, -6)));
ui::TouchEventImpl released(
ui::ET_TOUCH_RELEASED, gfx::Point(50, 50), 0, getTime());
root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&released);
EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2)));
// TODO(beng): clip Window to parent.
}

@ -145,7 +145,7 @@ string16 OakAuraWindowDisplay::GetText(int row, int column_id) {
return PropertyWithBool("Can Focus: ", window_->CanFocus());
case ROW_HITTESTBOUNDSOVERRIDEOUTER:
return PropertyWithInsets("Hit test bounds override outer: ",
window_->hit_test_bounds_override_outer());
window_->hit_test_bounds_override_outer_mouse());
case ROW_HITTESTBOUNDSOVERRIDEINNER:
return PropertyWithInsets("Hit test bounds override inner: ",
window_->hit_test_bounds_override_inner());