diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-18 23:08:00 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-18 23:08:00 +0000 |
commit | 7c3befe537a84fb0b4dddb9536d353866f89a5a8 (patch) | |
tree | db1bbd31b484f32728e3efdd379b4263c5525d0a /ash | |
parent | 148543e2616b68e9e90b1ab7b49e944fe873f309 (diff) | |
download | chromium_src-7c3befe537a84fb0b4dddb9536d353866f89a5a8.zip chromium_src-7c3befe537a84fb0b4dddb9536d353866f89a5a8.tar.gz chromium_src-7c3befe537a84fb0b4dddb9536d353866f89a5a8.tar.bz2 |
aura: Dispatch mouse events using the EventProcessor interface.
This would be the last major patch for converting to the new event-dispatch
mechanism. Subsequent CLs will start removing the old code path (and
corresponding API where appropriate).
BUG=318879
R=ben@chromium.org
Review URL: https://codereview.chromium.org/136863005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245797 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/wm/frame_border_hit_test_controller.cc | 122 | ||||
-rw-r--r-- | ash/wm/frame_border_hit_test_controller.h | 23 | ||||
-rw-r--r-- | ash/wm/window_manager_unittest.cc | 2 | ||||
-rw-r--r-- | ash/wm/workspace/multi_window_resize_controller_unittest.cc | 10 |
4 files changed, 101 insertions, 56 deletions
diff --git a/ash/wm/frame_border_hit_test_controller.cc b/ash/wm/frame_border_hit_test_controller.cc index 28a5726..5504d2a 100644 --- a/ash/wm/frame_border_hit_test_controller.cc +++ b/ash/wm/frame_border_hit_test_controller.cc @@ -7,8 +7,11 @@ #include "ash/ash_constants.h" #include "ash/wm/header_painter.h" #include "ash/wm/window_state.h" +#include "ash/wm/window_state_observer.h" #include "ui/aura/env.h" #include "ui/aura/window.h" +#include "ui/aura/window_observer.h" +#include "ui/aura/window_targeter.h" #include "ui/base/hit_test.h" #include "ui/views/widget/widget.h" #include "ui/views/widget/widget_delegate.h" @@ -16,6 +19,90 @@ namespace ash { +namespace { + +// To allow easy resize, the resize handles should slightly overlap the content +// area of non-maximized and non-fullscreen windows. +class ResizeHandleWindowTargeter : public wm::WindowStateObserver, + public aura::WindowObserver, + public aura::WindowTargeter { + public: + explicit ResizeHandleWindowTargeter(aura::Window* window) + : window_(window) { + wm::WindowState* window_state = wm::GetWindowState(window_); + OnWindowShowTypeChanged(window_state, wm::SHOW_TYPE_DEFAULT); + window_state->AddObserver(this); + window_->AddObserver(this); + } + + virtual ~ResizeHandleWindowTargeter() { + if (window_) { + window_->RemoveObserver(this); + wm::GetWindowState(window_)->RemoveObserver(this); + } + } + + private: + // wm::WindowStateObserver: + virtual void OnWindowShowTypeChanged(wm::WindowState* window_state, + wm::WindowShowType old_type) OVERRIDE { + if (window_state->IsMaximizedOrFullscreen()) { + frame_border_inset_ = gfx::Insets(); + } else { + frame_border_inset_ = gfx::Insets(kResizeInsideBoundsSize, + kResizeInsideBoundsSize, + kResizeInsideBoundsSize, + kResizeInsideBoundsSize); + } + } + + // aura::WindowObserver: + virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { + CHECK_EQ(window_, window); + wm::GetWindowState(window_)->RemoveObserver(this); + window_ = NULL; + } + + // aura::WindowTargeter: + virtual ui::EventTarget* FindTargetForLocatedEvent( + ui::EventTarget* root, + ui::LocatedEvent* event) OVERRIDE { + // If the event falls very close to the inside of the frame border, then + // target the window itself, so that the window can be resized easily. + aura::Window* window = static_cast<aura::Window*>(root); + if (window == window_ && !frame_border_inset_.empty()) { + gfx::Rect bounds = gfx::Rect(window_->bounds().size()); + bounds.Inset(frame_border_inset_); + if (!bounds.Contains(event->location())) + return window_; + } + return aura::WindowTargeter::FindTargetForLocatedEvent(root, event); + } + + virtual bool SubtreeShouldBeExploredForEvent( + ui::EventTarget* target, + const ui::LocatedEvent& event) OVERRIDE { + if (target == window_) { + // Defer to the parent's targeter on whether |window_| should be able to + // receive the event. + ui::EventTarget* parent = target->GetParentTarget(); + if (parent) { + ui::EventTargeter* targeter = parent->GetEventTargeter(); + if (targeter) + return targeter->SubtreeShouldBeExploredForEvent(target, event); + } + } + return aura::WindowTargeter::SubtreeShouldBeExploredForEvent(target, event); + } + + aura::Window* window_; + gfx::Insets frame_border_inset_; + + DISALLOW_COPY_AND_ASSIGN(ResizeHandleWindowTargeter); +}; + +} // namespace + FrameBorderHitTestController::FrameBorderHitTestController(views::Widget* frame) : frame_window_(frame->GetNativeWindow()) { gfx::Insets mouse_outer_insets(-kResizeOutsideBoundsSize, @@ -27,18 +114,12 @@ FrameBorderHitTestController::FrameBorderHitTestController(views::Widget* frame) // Ensure we get resize cursors for a few pixels outside our bounds. frame_window_->SetHitTestBoundsOverrideOuter(mouse_outer_insets, touch_outer_insets); - // Ensure we get resize cursors just inside our bounds as well. - UpdateHitTestBoundsOverrideInner(); - frame_window_->AddObserver(this); - ash::wm::GetWindowState(frame_window_)->AddObserver(this); + frame_window_->set_event_targeter(scoped_ptr<ui::EventTargeter>( + new ResizeHandleWindowTargeter(frame_window_))); } FrameBorderHitTestController::~FrameBorderHitTestController() { - if (frame_window_) { - frame_window_->RemoveObserver(this); - ash::wm::GetWindowState(frame_window_)->RemoveObserver(this); - } } // static @@ -81,29 +162,4 @@ int FrameBorderHitTestController::NonClientHitTest( return header_painter->NonClientHitTest(point); } -void FrameBorderHitTestController::UpdateHitTestBoundsOverrideInner() { - // Maximized and fullscreen windows don't want resize handles overlapping the - // content area, because when the user moves the cursor to the right screen - // edge we want them to be able to hit the scroll bar. - if (wm::GetWindowState(frame_window_)->IsMaximizedOrFullscreen()) { - frame_window_->set_hit_test_bounds_override_inner(gfx::Insets()); - } else { - frame_window_->set_hit_test_bounds_override_inner( - gfx::Insets(kResizeInsideBoundsSize, kResizeInsideBoundsSize, - kResizeInsideBoundsSize, kResizeInsideBoundsSize)); - } -} - -void FrameBorderHitTestController::OnWindowShowTypeChanged( - wm::WindowState* window_state, - wm::WindowShowType old_type) { - UpdateHitTestBoundsOverrideInner(); -} - -void FrameBorderHitTestController::OnWindowDestroying(aura::Window* window) { - frame_window_->RemoveObserver(this); - ash::wm::GetWindowState(frame_window_)->RemoveObserver(this); - frame_window_ = NULL; -} - } // namespace ash diff --git a/ash/wm/frame_border_hit_test_controller.h b/ash/wm/frame_border_hit_test_controller.h index 21fe9cf..126f406 100644 --- a/ash/wm/frame_border_hit_test_controller.h +++ b/ash/wm/frame_border_hit_test_controller.h @@ -6,10 +6,12 @@ #define ASH_WM_FRAME_BORDER_HITTEST_CONTROLLER_H_ #include "ash/ash_export.h" -#include "ash/wm/window_state_observer.h" #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "ui/aura/window_observer.h" + +namespace aura { +class Window; +} namespace gfx { class Point; @@ -23,11 +25,8 @@ class Widget; namespace ash { class HeaderPainter; -// Class which manages the hittest override bounds for |frame|. The override -// bounds are used to ensure that the resize cursors are shown when the user -// hovers over |frame|'s edges. -class ASH_EXPORT FrameBorderHitTestController : public wm::WindowStateObserver, - public aura::WindowObserver { +// Class which manages the hittest override bounds for |frame|. +class ASH_EXPORT FrameBorderHitTestController { public: explicit FrameBorderHitTestController(views::Widget* frame); virtual ~FrameBorderHitTestController(); @@ -39,16 +38,6 @@ class ASH_EXPORT FrameBorderHitTestController : public wm::WindowStateObserver, const gfx::Point& point); private: - // Updates the size of the region inside of |window_| in which the resize - // handles are shown based on |window_|'s show type. - void UpdateHitTestBoundsOverrideInner(); - - // WindowStateObserver override: - virtual void OnWindowShowTypeChanged(wm::WindowState* window_state, - wm::WindowShowType old_type) OVERRIDE; - // WindowObserver override: - virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; - // The window whose hittest override bounds are being managed. aura::Window* frame_window_; diff --git a/ash/wm/window_manager_unittest.cc b/ash/wm/window_manager_unittest.cc index 579bbfa..5acd123 100644 --- a/ash/wm/window_manager_unittest.cc +++ b/ash/wm/window_manager_unittest.cc @@ -597,7 +597,7 @@ TEST_F(WindowManagerTest, MAYBE_TransformActivate) { test::TestActivationDelegate d1; aura::test::TestWindowDelegate wd; scoped_ptr<aura::Window> w1( - CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 10, 50, 50))); + CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 15, 50, 50))); d1.SetWindow(w1.get()); w1->Show(); diff --git a/ash/wm/workspace/multi_window_resize_controller_unittest.cc b/ash/wm/workspace/multi_window_resize_controller_unittest.cc index 311e568..056e7d2 100644 --- a/ash/wm/workspace/multi_window_resize_controller_unittest.cc +++ b/ash/wm/workspace/multi_window_resize_controller_unittest.cc @@ -107,7 +107,7 @@ TEST_F(MultiWindowResizeControllerTest, BasicTests) { CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100))); delegate2.set_window_component(HTRIGHT); aura::test::EventGenerator generator(w1->GetRootWindow()); - generator.MoveMouseTo(99, 50); + generator.MoveMouseTo(w1->bounds().CenterPoint()); EXPECT_TRUE(HasPendingShow()); EXPECT_TRUE(IsShowing()); EXPECT_FALSE(HasPendingHide()); @@ -138,7 +138,7 @@ TEST_F(MultiWindowResizeControllerTest, DeleteWindow) { CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100))); delegate2.set_window_component(HTRIGHT); aura::test::EventGenerator generator(w1->GetRootWindow()); - generator.MoveMouseTo(99, 50); + generator.MoveMouseTo(w1->bounds().CenterPoint()); EXPECT_TRUE(HasPendingShow()); EXPECT_TRUE(IsShowing()); EXPECT_FALSE(HasPendingHide()); @@ -181,7 +181,7 @@ TEST_F(MultiWindowResizeControllerTest, Drag) { CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100))); delegate2.set_window_component(HTRIGHT); aura::test::EventGenerator generator(w1->GetRootWindow()); - generator.MoveMouseTo(99, 50); + generator.MoveMouseTo(w1->bounds().CenterPoint()); EXPECT_TRUE(HasPendingShow()); EXPECT_TRUE(IsShowing()); EXPECT_FALSE(HasPendingHide()); @@ -225,11 +225,11 @@ TEST_F(MultiWindowResizeControllerTest, Three) { delegate2.set_window_component(HTRIGHT); aura::test::TestWindowDelegate delegate3; scoped_ptr<aura::Window> w3( - CreateTestWindow(&delegate2, gfx::Rect(200, 0, 100, 100))); + CreateTestWindow(&delegate3, gfx::Rect(200, 0, 100, 100))); delegate3.set_window_component(HTRIGHT); aura::test::EventGenerator generator(w1->GetRootWindow()); - generator.MoveMouseTo(99, 50); + generator.MoveMouseTo(w1->bounds().CenterPoint()); EXPECT_TRUE(HasPendingShow()); EXPECT_TRUE(IsShowing()); EXPECT_FALSE(HasPendingHide()); |