diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-13 03:15:40 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-13 03:15:40 +0000 |
commit | 1128681f3f257f6726b58ba35dba2c6e720115ac (patch) | |
tree | 3c274eef89a739d0911641761f20361043bb176d /ui/aura | |
parent | 7bca40f56e2a04482e1ccb5d89f90c9335dd4329 (diff) | |
download | chromium_src-1128681f3f257f6726b58ba35dba2c6e720115ac.zip chromium_src-1128681f3f257f6726b58ba35dba2c6e720115ac.tar.gz chromium_src-1128681f3f257f6726b58ba35dba2c6e720115ac.tar.bz2 |
* Don't activate a window if screen is locked.
* StopEventsPropagation should check window visibility.
* Changed IsScreenLocked to use the same logic as
CanFocus.
BUG=none
TEST=new test case is added to window_unittests.cc
Review URL: http://codereview.chromium.org/9181012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117600 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r-- | ui/aura/root_window.cc | 6 | ||||
-rw-r--r-- | ui/aura/root_window.h | 1 | ||||
-rw-r--r-- | ui/aura/window.cc | 48 | ||||
-rw-r--r-- | ui/aura/window.h | 17 | ||||
-rw-r--r-- | ui/aura/window_unittest.cc | 13 |
5 files changed, 60 insertions, 25 deletions
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index ab3c0f1..3013790b 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -451,6 +451,10 @@ bool RootWindow::CanFocus() const { return IsVisible(); } +bool RootWindow::CanReceiveEvents() const { + return IsVisible(); +} + internal::FocusManager* RootWindow::GetFocusManager() { return this; } diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h index 89eaa17..d38a535 100644 --- a/ui/aura/root_window.h +++ b/ui/aura/root_window.h @@ -159,6 +159,7 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, // Overridden from Window: virtual bool CanFocus() const OVERRIDE; + virtual bool CanReceiveEvents() const OVERRIDE; virtual internal::FocusManager* GetFocusManager() OVERRIDE; virtual RootWindow* GetRootWindow() OVERRIDE; virtual void WindowDetachedFromRootWindow(Window* window) OVERRIDE; diff --git a/ui/aura/window.cc b/ui/aura/window.cc index f985944..b0a1ed6 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -348,22 +348,20 @@ bool Window::HasFocus() const { return focus_manager ? focus_manager->IsFocusedWindow(this) : false; } -// For a given window, we determine its focusability by inspecting each sibling -// after it (i.e. drawn in front of it in the z-order) to see if it stops -// propagation of events that would otherwise be targeted at windows behind it. -// We then perform this same check on every window up to the root. +// For a given window, we determine its focusability and ability to +// receive events by inspecting each sibling after it (i.e. drawn in +// front of it in the z-order) to see if it stops propagation of +// events that would otherwise be targeted at windows behind it. We +// then perform this same check on every window up to the root. bool Window::CanFocus() const { if (!IsVisible() || !parent_ || (delegate_ && !delegate_->CanFocus())) return false; + return !IsBehindStopEventsWindow() && parent_->CanFocus(); +} - Windows::const_iterator i = std::find(parent_->children().begin(), - parent_->children().end(), - this); - for (++i; i != parent_->children().end(); ++i) { - if ((*i)->StopsEventPropagation()) - return false; - } - return parent_->CanFocus(); +bool Window::CanReceiveEvents() const { + return parent_ && IsVisible() && !IsBehindStopEventsWindow() && + parent_->CanReceiveEvents(); } internal::FocusManager* Window::GetFocusManager() { @@ -425,6 +423,15 @@ int Window::GetIntProperty(const char* name) const { GetProperty(name))); } +bool Window::StopsEventPropagation() const { + if (!stops_event_propagation_ || children_.empty()) + return false; + aura::Window::Windows::const_iterator it = + std::find_if(children_.begin(), children_.end(), + std::mem_fun(&aura::Window::IsVisible)); + return it != children_.end(); +} + RootWindow* Window::GetRootWindow() { return parent_ ? parent_->GetRootWindow() : NULL; } @@ -487,10 +494,6 @@ void Window::SchedulePaint() { SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); } -bool Window::StopsEventPropagation() const { - return stops_event_propagation_ && !children_.empty(); -} - Window* Window::GetWindowForPoint(const gfx::Point& local_point, bool return_tightest, bool for_event_handling) { @@ -556,4 +559,15 @@ void Window::UpdateLayerName(const std::string& name) { #endif } +bool Window::IsBehindStopEventsWindow() const { + Windows::const_iterator i = std::find(parent_->children().begin(), + parent_->children().end(), + this); + for (++i; i != parent_->children().end(); ++i) { + if ((*i)->StopsEventPropagation()) + return true; + } + return false; +} + } // namespace aura diff --git a/ui/aura/window.h b/ui/aura/window.h index a97194c..73ba2dd 100644 --- a/ui/aura/window.h +++ b/ui/aura/window.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -220,6 +220,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate { // Returns true if the Window can be focused. virtual bool CanFocus() const; + // Returns true if the Window can receive events. + virtual bool CanReceiveEvents() const; + // Returns the FocusManager for the Window, which may be attached to a parent // Window. Can return NULL if the Window has no FocusManager. virtual internal::FocusManager* GetFocusManager(); @@ -250,6 +253,10 @@ class AURA_EXPORT Window : public ui::LayerDelegate { void* GetProperty(const char* name) const; int GetIntProperty(const char* name) const; + // Returns true if this window is currently stopping event + // propagation for any windows behind it in the z-order. + bool StopsEventPropagation() const; + protected: // Returns the root window or NULL if we aren't yet attached to the root // window. @@ -272,10 +279,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate { // Schedules a paint for the Window's entire bounds. void SchedulePaint(); - // This window is currently stopping event propagation for any windows behind - // it in the z-order. - bool StopsEventPropagation() const; - // Gets a Window (either this one or a subwindow) containing |local_point|. // If |return_tightest| is true, returns the tightest-containing (i.e. // furthest down the hierarchy) Window containing the point; otherwise, @@ -298,6 +301,10 @@ class AURA_EXPORT Window : public ui::LayerDelegate { // Updates the layer name with a name based on the window's name and id. void UpdateLayerName(const std::string& name); + // Returns true if this window is behind a window that stops event + // propagation. + bool IsBehindStopEventsWindow() const; + client::WindowType type_; WindowDelegate* delegate_; diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index ccd9fe8..763e40a 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -660,6 +660,7 @@ TEST_F(WindowTest, StopsEventPropagation) { EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); EXPECT_TRUE(w111->CanFocus()); + EXPECT_TRUE(w111->CanReceiveEvents()); w111->Focus(); EXPECT_EQ(w111.get(), w1->GetFocusManager()->GetFocusedWindow()); @@ -671,14 +672,22 @@ TEST_F(WindowTest, StopsEventPropagation) { // It should be possible to focus w121 since it is at or above the // consumes_events_ window. EXPECT_TRUE(w121->CanFocus()); + EXPECT_TRUE(w121->CanReceiveEvents()); w121->Focus(); EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); // An attempt to focus 111 should be ignored and w121 should retain focus, // since a consumes_events_ window with a child is in the z-index above w111. - EXPECT_FALSE(w111->CanFocus()); + EXPECT_FALSE(w111->CanReceiveEvents()); w111->Focus(); EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); + + // Hiding w121 should make 111 focusable. + w121->Hide(); + EXPECT_TRUE(w111->CanFocus()); + EXPECT_TRUE(w111->CanReceiveEvents()); + w111->Focus(); + EXPECT_EQ(w111.get(), w1->GetFocusManager()->GetFocusedWindow()); } TEST_F(WindowTest, IgnoreEventsTest) { |