diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-06 20:47:17 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-06 20:47:17 +0000 |
commit | 869f63584313127e61ba26413a1fca3fa66c7819 (patch) | |
tree | 4aa76974e20c0efdf966d4f51e45ee7dafc173b3 /ui | |
parent | 69793ad506993edd0330fa52a81ad80ca280d0fb (diff) | |
download | chromium_src-869f63584313127e61ba26413a1fca3fa66c7819.zip chromium_src-869f63584313127e61ba26413a1fca3fa66c7819.tar.gz chromium_src-869f63584313127e61ba26413a1fca3fa66c7819.tar.bz2 |
Get some of the ash_unittests to run without crashing.
We currently make it as far as RootWindowControllerTest.MoveWindows_Basic.
This CL:
- changes ui::EventTarget::CanAcceptEvents to be CanAcceptEvent and take an event. This allows the event type to determine whether or not it can be accepted by the target.
- copy-pasta from ActivationController to AshActivationRules (GetNextWindowToActivate())
- forwarding to target handler for generic events in EventTarget
- RootWindowControllerTest needs to handle activation events @ the target and forward to OnBlur impl.
http://crbug.com/162100
R=sadrul@chromium.org
Review URL: https://codereview.chromium.org/11445023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171583 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/env.cc | 2 | ||||
-rw-r--r-- | ui/aura/env.h | 2 | ||||
-rw-r--r-- | ui/aura/root_window_host_win.cc | 2 | ||||
-rw-r--r-- | ui/aura/root_window_unittest.cc | 4 | ||||
-rw-r--r-- | ui/aura/window.cc | 11 | ||||
-rw-r--r-- | ui/aura/window.h | 2 | ||||
-rw-r--r-- | ui/base/events/event.cc | 3 | ||||
-rw-r--r-- | ui/base/events/event.h | 7 | ||||
-rw-r--r-- | ui/base/events/event_dispatcher.h | 2 | ||||
-rw-r--r-- | ui/base/events/event_dispatcher_unittest.cc | 2 | ||||
-rw-r--r-- | ui/base/events/event_target.cc | 8 | ||||
-rw-r--r-- | ui/base/events/event_target.h | 3 | ||||
-rw-r--r-- | ui/views/corewm/focus_change_event.cc | 1 | ||||
-rw-r--r-- | ui/views/corewm/focus_controller.cc | 10 | ||||
-rw-r--r-- | ui/views/corewm/focus_controller_unittest.cc | 4 | ||||
-rw-r--r-- | ui/views/corewm/focus_rules.h | 1 | ||||
-rw-r--r-- | ui/views/view.cc | 4 | ||||
-rw-r--r-- | ui/views/view.h | 2 |
18 files changed, 54 insertions, 16 deletions
diff --git a/ui/aura/env.cc b/ui/aura/env.cc index d46783f..19083d9 100644 --- a/ui/aura/env.cc +++ b/ui/aura/env.cc @@ -126,7 +126,7 @@ void Env::NotifyWindowInitialized(Window* window) { //////////////////////////////////////////////////////////////////////////////// // Env, ui::EventTarget implementation: -bool Env::CanAcceptEvents() { +bool Env::CanAcceptEvent(const ui::Event& event) { return true; } diff --git a/ui/aura/env.h b/ui/aura/env.h index d6db1ed..76b03cf 100644 --- a/ui/aura/env.h +++ b/ui/aura/env.h @@ -91,7 +91,7 @@ class AURA_EXPORT Env : public ui::EventTarget { void NotifyWindowInitialized(Window* window); // Overridden from ui::EventTarget: - virtual bool CanAcceptEvents() OVERRIDE; + virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE; virtual ui::EventTarget* GetParentTarget() OVERRIDE; ObserverList<EnvObserver> observers_; diff --git a/ui/aura/root_window_host_win.cc b/ui/aura/root_window_host_win.cc index e8d50f9..f7c6209 100644 --- a/ui/aura/root_window_host_win.cc +++ b/ui/aura/root_window_host_win.cc @@ -294,7 +294,7 @@ void RootWindowHostWin::OnPaint(HDC dc) { void RootWindowHostWin::OnSize(UINT param, const CSize& size) { // Minimizing resizes the window to 0x0 which causes our layout to go all // screwy, so we just ignore it. - if (param != SIZE_MINIMIZED) + if (delegate_ && param != SIZE_MINIMIZED) delegate_->OnHostResized(gfx::Size(size.cx, size.cy)); } diff --git a/ui/aura/root_window_unittest.cc b/ui/aura/root_window_unittest.cc index 98d3eb1..5a6739a 100644 --- a/ui/aura/root_window_unittest.cc +++ b/ui/aura/root_window_unittest.cc @@ -302,7 +302,9 @@ class TestEventClient : public client::EventClient { // Overridden from client::EventClient: virtual bool CanProcessEventsWithinSubtree( const Window* window) const OVERRIDE { - return lock_ ? GetLockWindow()->Contains(window) : true; + return lock_ ? + window->Contains(GetLockWindow()) || GetLockWindow()->Contains(window) : + true; } virtual ui::EventTarget* GetToplevelEventTarget() OVERRIDE { diff --git a/ui/aura/window.cc b/ui/aura/window.cc index b9a5a17..56d5ba2 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -933,8 +933,15 @@ base::Closure Window::PrepareForLayerBoundsChange() { bounds(), ContainsMouse()); } -bool Window::CanAcceptEvents() { - return CanReceiveEvents(); +bool Window::CanAcceptEvent(const ui::Event& event) { + // The client may forbid certain windows from receiving events at a given + // point in time. + client::EventClient* client = client::GetEventClient(GetRootWindow()); + if (client && !client->CanProcessEventsWithinSubtree(this)) + return false; + + bool visible = event.dispatch_to_hidden_targets() || IsVisible(); + return visible && (!parent_ || parent_->CanAcceptEvent(event)); } ui::EventTarget* Window::GetParentTarget() { diff --git a/ui/aura/window.h b/ui/aura/window.h index 3f2192f..af3ad89 100644 --- a/ui/aura/window.h +++ b/ui/aura/window.h @@ -431,7 +431,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate, virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE; // Overridden from ui::EventTarget: - virtual bool CanAcceptEvents() OVERRIDE; + virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE; virtual EventTarget* GetParentTarget() OVERRIDE; // Updates the layer name with a name based on the window's name and id. diff --git a/ui/base/events/event.cc b/ui/base/events/event.cc index 26391cd..e6cbd25 100644 --- a/ui/base/events/event.cc +++ b/ui/base/events/event.cc @@ -134,6 +134,7 @@ Event::Event(EventType type, base::TimeDelta time_stamp, int flags) : type_(type), time_stamp_(time_stamp), flags_(flags), + dispatch_to_hidden_targets_(false), delete_native_event_(false), target_(NULL), phase_(EP_PREDISPATCH), @@ -149,6 +150,7 @@ Event::Event(const base::NativeEvent& native_event, : type_(type), time_stamp_(EventTimeFromNative(native_event)), flags_(flags), + dispatch_to_hidden_targets_(false), delete_native_event_(false), target_(NULL), phase_(EP_PREDISPATCH), @@ -163,6 +165,7 @@ Event::Event(const Event& copy) type_(copy.type_), time_stamp_(copy.time_stamp_), flags_(copy.flags_), + dispatch_to_hidden_targets_(false), delete_native_event_(false), target_(NULL), phase_(EP_PREDISPATCH), diff --git a/ui/base/events/event.h b/ui/base/events/event.h index 2dc9996..2115402 100644 --- a/ui/base/events/event.h +++ b/ui/base/events/event.h @@ -76,6 +76,9 @@ class UI_EXPORT Event { EventTarget* target() const { return target_; } EventPhase phase() const { return phase_; } EventResult result() const { return result_; } + bool dispatch_to_hidden_targets() const { + return dispatch_to_hidden_targets_; + } // The following methods return true if the respective keys were pressed at // the time the event was created. @@ -180,6 +183,9 @@ class UI_EXPORT Event { delete_native_event_ = delete_native_event; } void set_time_stamp(base::TimeDelta time_stamp) { time_stamp_ = time_stamp; } + void set_dispatch_to_hidden_targets(bool dispatch_to_hidden_targets) { + dispatch_to_hidden_targets_ = dispatch_to_hidden_targets; + } void set_name(const std::string& name) { name_ = name; } @@ -195,6 +201,7 @@ class UI_EXPORT Event { std::string name_; base::TimeDelta time_stamp_; int flags_; + bool dispatch_to_hidden_targets_; bool delete_native_event_; EventTarget* target_; EventPhase phase_; diff --git a/ui/base/events/event_dispatcher.h b/ui/base/events/event_dispatcher.h index 38ab6eb..79c8618 100644 --- a/ui/base/events/event_dispatcher.h +++ b/ui/base/events/event_dispatcher.h @@ -56,7 +56,7 @@ class UI_EXPORT EventDispatcher { template<class T> void ProcessEvent(EventTarget* target, T* event) { - if (!target || !target->CanAcceptEvents()) + if (!target || !target->CanAcceptEvent(*event)) return; ScopedDispatchHelper dispatch_helper(event); diff --git a/ui/base/events/event_dispatcher_unittest.cc b/ui/base/events/event_dispatcher_unittest.cc index cbfb19d..4be96bf 100644 --- a/ui/base/events/event_dispatcher_unittest.cc +++ b/ui/base/events/event_dispatcher_unittest.cc @@ -32,7 +32,7 @@ class TestTarget : public EventTarget { private: // Overridden from EventTarget: - virtual bool CanAcceptEvents() OVERRIDE { + virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE { return true; } diff --git a/ui/base/events/event_target.cc b/ui/base/events/event_target.cc index 6c1d671..a7d93dd 100644 --- a/ui/base/events/event_target.cc +++ b/ui/base/events/event_target.cc @@ -44,6 +44,14 @@ void EventTarget::RemovePostTargetHandler(EventHandler* handler) { post_target_list_.erase(find); } +void EventTarget::OnEvent(Event* event) { + CHECK_EQ(this, event->target()); + if (target_handler_) + target_handler_->OnEvent(event); + else + EventHandler::OnEvent(event); +} + EventResult EventTarget::OnKeyEvent(KeyEvent* event) { CHECK_EQ(this, event->target()); return target_handler_ ? target_handler_->OnKeyEvent(event) : ER_UNHANDLED; diff --git a/ui/base/events/event_target.h b/ui/base/events/event_target.h index 4531db8..fa05d02 100644 --- a/ui/base/events/event_target.h +++ b/ui/base/events/event_target.h @@ -51,7 +51,7 @@ class UI_EXPORT EventTarget : public EventHandler { EventTarget(); virtual ~EventTarget(); - virtual bool CanAcceptEvents() = 0; + virtual bool CanAcceptEvent(const ui::Event& event) = 0; virtual EventTarget* GetParentTarget() = 0; // Adds a handler to receive events before the target. The handler must be @@ -72,6 +72,7 @@ class UI_EXPORT EventTarget : public EventHandler { } // Overridden from EventHandler: + virtual void OnEvent(Event* event) OVERRIDE; virtual EventResult OnKeyEvent(KeyEvent* event) OVERRIDE; virtual EventResult OnMouseEvent(MouseEvent* event) OVERRIDE; virtual EventResult OnScrollEvent(ScrollEvent* event) OVERRIDE; diff --git a/ui/views/corewm/focus_change_event.cc b/ui/views/corewm/focus_change_event.cc index 9df66ea..2c82f02 100644 --- a/ui/views/corewm/focus_change_event.cc +++ b/ui/views/corewm/focus_change_event.cc @@ -40,6 +40,7 @@ FocusChangeEvent::FocusChangeEvent(int type) last_focus_(NULL) { DCHECK_NE(type, ui::ET_UNKNOWN) << "Call RegisterEventTypes() before instantiating this class"; + set_dispatch_to_hidden_targets(true); set_name(FocusChangeEventName(type)); } diff --git a/ui/views/corewm/focus_controller.cc b/ui/views/corewm/focus_controller.cc index b403f4b..40143c5 100644 --- a/ui/views/corewm/focus_controller.cc +++ b/ui/views/corewm/focus_controller.cc @@ -99,7 +99,8 @@ void FocusController::ActivateWindow(aura::Window* window) { } void FocusController::DeactivateWindow(aura::Window* window) { - FocusWindow(rules_->GetNextActivatableWindow(window), NULL); + if (window) + FocusWindow(rules_->GetNextActivatableWindow(window), NULL); } aura::Window* FocusController::GetActiveWindow() { @@ -138,8 +139,11 @@ void FocusController::FocusWindow(aura::Window* window, // Focusing a window also activates its containing activatable window. Note // that the rules could redirect activation activation and/or focus. aura::Window* focusable = rules_->GetFocusableWindow(window); - SetActiveWindow(rules_->GetActivatableWindow(focusable)); - DCHECK(GetActiveWindow()->Contains(focusable)); + aura::Window* activatable = + focusable ? rules_->GetActivatableWindow(focusable) : NULL; + SetActiveWindow(activatable); + if (focusable && activatable) + DCHECK(GetActiveWindow()->Contains(focusable)); SetFocusedWindow(focusable); } diff --git a/ui/views/corewm/focus_controller_unittest.cc b/ui/views/corewm/focus_controller_unittest.cc index ae78074..51a7517 100644 --- a/ui/views/corewm/focus_controller_unittest.cc +++ b/ui/views/corewm/focus_controller_unittest.cc @@ -280,6 +280,10 @@ class FocusControllerDirectTestBase : public FocusControllerTestBase { EXPECT_EQ(1, GetActiveWindowId()); ActivateWindowById(2); EXPECT_EQ(2, GetActiveWindowId()); + // Verify that attempting to deactivate NULL does not crash and does not + // change activation. + DeactivateWindow(NULL); + EXPECT_EQ(2, GetActiveWindowId()); DeactivateWindow(GetActiveWindow()); EXPECT_EQ(1, GetActiveWindowId()); } diff --git a/ui/views/corewm/focus_rules.h b/ui/views/corewm/focus_rules.h index e69549e..9c17c8b 100644 --- a/ui/views/corewm/focus_rules.h +++ b/ui/views/corewm/focus_rules.h @@ -44,6 +44,7 @@ class VIEWS_EXPORT FocusRules { // RootWindow. // - it is being destroyed. // - it is being explicitly deactivated. + // |ignore| cannot be NULL. virtual aura::Window* GetNextActivatableWindow( aura::Window* ignore) const = 0; virtual aura::Window* GetNextFocusableWindow( diff --git a/ui/views/view.cc b/ui/views/view.cc index 1ec3d9a..ba0023c2 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -895,8 +895,8 @@ InputMethod* View::GetInputMethod() { return widget ? widget->GetInputMethod() : NULL; } -bool View::CanAcceptEvents() { - return IsDrawn(); +bool View::CanAcceptEvent(const ui::Event& event) { + return event.dispatch_to_hidden_targets() || IsDrawn(); } ui::EventTarget* View::GetParentTarget() { diff --git a/ui/views/view.h b/ui/views/view.h index edec526..fee62b6 100644 --- a/ui/views/view.h +++ b/ui/views/view.h @@ -647,7 +647,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, virtual InputMethod* GetInputMethod(); // Overridden from ui::EventTarget: - virtual bool CanAcceptEvents() OVERRIDE; + virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE; virtual ui::EventTarget* GetParentTarget() OVERRIDE; // Overridden from ui::EventHandler: |