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:
ash
chrome/browser/ui/views/extensions
ui
@ -13,8 +13,8 @@ namespace ash {
|
|||||||
DEFINE_WINDOW_PROPERTY_KEY(bool, kConstrainedWindowKey, false);
|
DEFINE_WINDOW_PROPERTY_KEY(bool, kConstrainedWindowKey, false);
|
||||||
|
|
||||||
const int kResizeAreaCornerSize = 16;
|
const int kResizeAreaCornerSize = 16;
|
||||||
const int kResizeOutsideBoundsSizeTouch = 30;
|
|
||||||
const int kResizeOutsideBoundsSize = 6;
|
const int kResizeOutsideBoundsSize = 6;
|
||||||
|
const int kResizeOutsideBoundsScaleForTouch = 5;
|
||||||
const int kResizeInsideBoundsSize = 1;
|
const int kResizeInsideBoundsSize = 1;
|
||||||
|
|
||||||
} // namespace ash
|
} // 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
|
// 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
|
// window bounds and an even smaller region overlapping the window to be the
|
||||||
// "non-client" area and use it for resizing.
|
// "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 kResizeOutsideBoundsSize;
|
||||||
|
ASH_EXPORT extern const int kResizeOutsideBoundsScaleForTouch;
|
||||||
ASH_EXPORT extern const int kResizeInsideBoundsSize;
|
ASH_EXPORT extern const int kResizeInsideBoundsSize;
|
||||||
|
|
||||||
} // namespace ash
|
} // namespace ash
|
||||||
|
@ -181,12 +181,10 @@ void FramePainter::Init(views::Widget* frame,
|
|||||||
|
|
||||||
window_ = frame->GetNativeWindow();
|
window_ = frame->GetNativeWindow();
|
||||||
// Ensure we get resize cursors for a few pixels outside our bounds.
|
// Ensure we get resize cursors for a few pixels outside our bounds.
|
||||||
int outside_bounds = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ?
|
window_->SetHitTestBoundsOverrideOuter(
|
||||||
kResizeOutsideBoundsSizeTouch :
|
gfx::Insets(-kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize,
|
||||||
kResizeOutsideBoundsSize;
|
-kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize),
|
||||||
window_->set_hit_test_bounds_override_outer(
|
kResizeOutsideBoundsScaleForTouch);
|
||||||
gfx::Insets(-outside_bounds, -outside_bounds,
|
|
||||||
-outside_bounds, -outside_bounds));
|
|
||||||
// Ensure we get resize cursors just inside our bounds as well.
|
// Ensure we get resize cursors just inside our bounds as well.
|
||||||
window_->set_hit_test_bounds_override_inner(
|
window_->set_hit_test_bounds_override_inner(
|
||||||
gfx::Insets(kResizeInsideBoundsSize, kResizeInsideBoundsSize,
|
gfx::Insets(kResizeInsideBoundsSize, kResizeInsideBoundsSize,
|
||||||
@ -224,7 +222,7 @@ int FramePainter::NonClientHitTest(views::NonClientFrameView* view,
|
|||||||
|
|
||||||
if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH &&
|
if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH &&
|
||||||
aura::Env::GetInstance()->is_touch_down()) {
|
aura::Env::GetInstance()->is_touch_down()) {
|
||||||
outside_bounds = kResizeOutsideBoundsSizeTouch;
|
outside_bounds *= kResizeOutsideBoundsScaleForTouch;
|
||||||
}
|
}
|
||||||
expanded_bounds.Inset(-outside_bounds, -outside_bounds);
|
expanded_bounds.Inset(-outside_bounds, -outside_bounds);
|
||||||
|
|
||||||
|
@ -585,10 +585,11 @@ void ShelfLayoutManager::UpdateHitTestBounds() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (launcher_widget() && launcher_widget()->GetNativeWindow())
|
if (launcher_widget() && launcher_widget()->GetNativeWindow()) {
|
||||||
launcher_widget()->GetNativeWindow()->set_hit_test_bounds_override_outer(
|
launcher_widget()->GetNativeWindow()->SetHitTestBoundsOverrideOuter(
|
||||||
insets);
|
insets, 1);
|
||||||
status_->GetNativeWindow()->set_hit_test_bounds_override_outer(insets);
|
}
|
||||||
|
status_->GetNativeWindow()->SetHitTestBoundsOverrideOuter( insets, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) {
|
bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) {
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#if defined(USE_ASH)
|
#if defined(USE_ASH)
|
||||||
#include "ash/ash_constants.h"
|
#include "ash/ash_constants.h"
|
||||||
#include "ash/wm/custom_frame_view_ash.h"
|
#include "ash/wm/custom_frame_view_ash.h"
|
||||||
|
#include "ui/aura/env.h"
|
||||||
#include "ui/aura/window.h"
|
#include "ui/aura/window.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -121,12 +122,12 @@ void ShellWindowFrameView::Init(views::Widget* frame) {
|
|||||||
#if defined(USE_ASH)
|
#if defined(USE_ASH)
|
||||||
aura::Window* window = frame->GetNativeWindow();
|
aura::Window* window = frame->GetNativeWindow();
|
||||||
// Ensure we get resize cursors for a few pixels outside our bounds.
|
// Ensure we get resize cursors for a few pixels outside our bounds.
|
||||||
int outside_bounds = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ?
|
window->SetHitTestBoundsOverrideOuter(
|
||||||
ash::kResizeOutsideBoundsSizeTouch :
|
gfx::Insets(-ash::kResizeOutsideBoundsSize,
|
||||||
ash::kResizeOutsideBoundsSize;
|
-ash::kResizeOutsideBoundsSize,
|
||||||
window->set_hit_test_bounds_override_outer(
|
-ash::kResizeOutsideBoundsSize,
|
||||||
gfx::Insets(-outside_bounds, -outside_bounds,
|
-ash::kResizeOutsideBoundsSize),
|
||||||
-outside_bounds, -outside_bounds));
|
ash::kResizeOutsideBoundsScaleForTouch);
|
||||||
// Ensure we get resize cursors just inside our bounds as well.
|
// Ensure we get resize cursors just inside our bounds as well.
|
||||||
// TODO(jeremya): do we need to update these when in fullscreen/maximized?
|
// TODO(jeremya): do we need to update these when in fullscreen/maximized?
|
||||||
window->set_hit_test_bounds_override_inner(
|
window->set_hit_test_bounds_override_inner(
|
||||||
@ -162,9 +163,11 @@ int ShellWindowFrameView::NonClientHitTest(const gfx::Point& point) {
|
|||||||
|
|
||||||
#if defined(USE_ASH)
|
#if defined(USE_ASH)
|
||||||
gfx::Rect expanded_bounds = bounds();
|
gfx::Rect expanded_bounds = bounds();
|
||||||
int outside_bounds = ui::GetDisplayLayout() == ui::LAYOUT_TOUCH ?
|
int outside_bounds = ash::kResizeOutsideBoundsSize;
|
||||||
ash::kResizeOutsideBoundsSizeTouch :
|
if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH &&
|
||||||
ash::kResizeOutsideBoundsSize;
|
aura::Env::GetInstance()->is_touch_down()) {
|
||||||
|
outside_bounds *= ash::kResizeOutsideBoundsScaleForTouch;
|
||||||
|
}
|
||||||
expanded_bounds.Inset(-outside_bounds, -outside_bounds);
|
expanded_bounds.Inset(-outside_bounds, -outside_bounds);
|
||||||
if (!expanded_bounds.Contains(point))
|
if (!expanded_bounds.Contains(point))
|
||||||
return HTNOWHERE;
|
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
|
// Expand my bounds for hit testing (override is usually zero but it's
|
||||||
// probably cheaper to do the math every time than to branch).
|
// probably cheaper to do the math every time than to branch).
|
||||||
gfx::Rect local_bounds(gfx::Point(), bounds().size());
|
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())
|
if (!delegate_ || !delegate_->HasHitTestMask())
|
||||||
return local_bounds.Contains(local_point);
|
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; }
|
void set_ignore_events(bool ignore_events) { ignore_events_ = ignore_events; }
|
||||||
|
|
||||||
// Sets the window to grab hits for an area extending -|insets| pixels outside
|
// 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
|
// example if your windows have no visible frames but still need to have
|
||||||
// resize edges.
|
// resize edges. It is possible to set a larger hit-region for touch-events.
|
||||||
void set_hit_test_bounds_override_outer(const gfx::Insets& insets) {
|
void SetHitTestBoundsOverrideOuter(const gfx::Insets& mouse_insets,
|
||||||
hit_test_bounds_override_outer_ = 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
|
// 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_;
|
bool ignore_events_;
|
||||||
|
|
||||||
// See set_hit_test_outer_override().
|
// 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_;
|
gfx::Insets hit_test_bounds_override_inner_;
|
||||||
|
|
||||||
ObserverList<WindowObserver> observers_;
|
ObserverList<WindowObserver> observers_;
|
||||||
|
@ -429,10 +429,21 @@ TEST_F(WindowTest, HitTest) {
|
|||||||
EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1)));
|
EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1)));
|
||||||
|
|
||||||
// We can expand the bounds slightly to track events outside our border.
|
// 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_TRUE(w1.HitTest(gfx::Point(-1, -1)));
|
||||||
EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2)));
|
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.
|
// TODO(beng): clip Window to parent.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ string16 OakAuraWindowDisplay::GetText(int row, int column_id) {
|
|||||||
return PropertyWithBool("Can Focus: ", window_->CanFocus());
|
return PropertyWithBool("Can Focus: ", window_->CanFocus());
|
||||||
case ROW_HITTESTBOUNDSOVERRIDEOUTER:
|
case ROW_HITTESTBOUNDSOVERRIDEOUTER:
|
||||||
return PropertyWithInsets("Hit test bounds override outer: ",
|
return PropertyWithInsets("Hit test bounds override outer: ",
|
||||||
window_->hit_test_bounds_override_outer());
|
window_->hit_test_bounds_override_outer_mouse());
|
||||||
case ROW_HITTESTBOUNDSOVERRIDEINNER:
|
case ROW_HITTESTBOUNDSOVERRIDEINNER:
|
||||||
return PropertyWithInsets("Hit test bounds override inner: ",
|
return PropertyWithInsets("Hit test bounds override inner: ",
|
||||||
window_->hit_test_bounds_override_inner());
|
window_->hit_test_bounds_override_inner());
|
||||||
|
Reference in New Issue
Block a user