Commit 1128681f authored by oshima@chromium.org's avatar oshima@chromium.org

* 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
parent 7bca40f5
...@@ -377,15 +377,7 @@ void Shell::ToggleAppList() { ...@@ -377,15 +377,7 @@ void Shell::ToggleAppList() {
bool Shell::IsScreenLocked() const { bool Shell::IsScreenLocked() const {
const aura::Window* lock_screen_container = GetContainer( const aura::Window* lock_screen_container = GetContainer(
internal::kShellWindowId_LockScreenContainer); internal::kShellWindowId_LockScreenContainer);
const aura::Window::Windows& lock_screen_windows = return lock_screen_container->StopsEventPropagation();
lock_screen_container->children();
aura::Window::Windows::const_iterator lock_screen_it =
std::find_if(lock_screen_windows.begin(), lock_screen_windows.end(),
std::mem_fun(&aura::Window::IsVisible));
if (lock_screen_it != lock_screen_windows.end())
return true;
return false;
} }
bool Shell::IsModalWindowOpen() const { bool Shell::IsModalWindowOpen() const {
......
...@@ -119,6 +119,13 @@ void ActivationController::ActivateWindow(aura::Window* window) { ...@@ -119,6 +119,13 @@ void ActivationController::ActivateWindow(aura::Window* window) {
// activated or deactivated. // activated or deactivated.
if (!CanActivateWindow(window)) if (!CanActivateWindow(window))
return; return;
// If the screen is locked, just bring the window to top so that
// it will be activated when the lock window is destroyed.
if (window && !window->CanReceiveEvents()) {
StackTransientParentsBelowModalWindow(window);
window->parent()->StackChildAtTop(window);
return;
}
if (!window->Contains(window->GetFocusManager()->GetFocusedWindow())) if (!window->Contains(window->GetFocusManager()->GetFocusedWindow()))
window->GetFocusManager()->SetFocusedWindow(window); window->GetFocusManager()->SetFocusedWindow(window);
...@@ -130,6 +137,7 @@ void ActivationController::ActivateWindow(aura::Window* window) { ...@@ -130,6 +137,7 @@ void ActivationController::ActivateWindow(aura::Window* window) {
// active. // active.
if (old_active && aura::client::GetActivationDelegate(old_active)) if (old_active && aura::client::GetActivationDelegate(old_active))
aura::client::GetActivationDelegate(old_active)->OnLostActive(); aura::client::GetActivationDelegate(old_active)->OnLostActive();
if (window) { if (window) {
StackTransientParentsBelowModalWindow(window); StackTransientParentsBelowModalWindow(window);
window->parent()->StackChildAtTop(window); window->parent()->StackChildAtTop(window);
......
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -451,6 +451,10 @@ bool RootWindow::CanFocus() const { ...@@ -451,6 +451,10 @@ bool RootWindow::CanFocus() const {
return IsVisible(); return IsVisible();
} }
bool RootWindow::CanReceiveEvents() const {
return IsVisible();
}
internal::FocusManager* RootWindow::GetFocusManager() { internal::FocusManager* RootWindow::GetFocusManager() {
return this; return this;
} }
......
...@@ -159,6 +159,7 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, ...@@ -159,6 +159,7 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// Overridden from Window: // Overridden from Window:
virtual bool CanFocus() const OVERRIDE; virtual bool CanFocus() const OVERRIDE;
virtual bool CanReceiveEvents() const OVERRIDE;
virtual internal::FocusManager* GetFocusManager() OVERRIDE; virtual internal::FocusManager* GetFocusManager() OVERRIDE;
virtual RootWindow* GetRootWindow() OVERRIDE; virtual RootWindow* GetRootWindow() OVERRIDE;
virtual void WindowDetachedFromRootWindow(Window* window) OVERRIDE; virtual void WindowDetachedFromRootWindow(Window* window) OVERRIDE;
......
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -348,22 +348,20 @@ bool Window::HasFocus() const { ...@@ -348,22 +348,20 @@ bool Window::HasFocus() const {
return focus_manager ? focus_manager->IsFocusedWindow(this) : false; return focus_manager ? focus_manager->IsFocusedWindow(this) : false;
} }
// For a given window, we determine its focusability by inspecting each sibling // For a given window, we determine its focusability and ability to
// after it (i.e. drawn in front of it in the z-order) to see if it stops // receive events by inspecting each sibling after it (i.e. drawn in
// propagation of events that would otherwise be targeted at windows behind it. // front of it in the z-order) to see if it stops propagation of
// We then perform this same check on every window up to the root. // 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 { bool Window::CanFocus() const {
if (!IsVisible() || !parent_ || (delegate_ && !delegate_->CanFocus())) if (!IsVisible() || !parent_ || (delegate_ && !delegate_->CanFocus()))
return false; return false;
return !IsBehindStopEventsWindow() && parent_->CanFocus();
}
Windows::const_iterator i = std::find(parent_->children().begin(), bool Window::CanReceiveEvents() const {
parent_->children().end(), return parent_ && IsVisible() && !IsBehindStopEventsWindow() &&
this); parent_->CanReceiveEvents();
for (++i; i != parent_->children().end(); ++i) {
if ((*i)->StopsEventPropagation())
return false;
}
return parent_->CanFocus();
} }
internal::FocusManager* Window::GetFocusManager() { internal::FocusManager* Window::GetFocusManager() {
...@@ -425,6 +423,15 @@ int Window::GetIntProperty(const char* name) const { ...@@ -425,6 +423,15 @@ int Window::GetIntProperty(const char* name) const {
GetProperty(name))); 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() { RootWindow* Window::GetRootWindow() {
return parent_ ? parent_->GetRootWindow() : NULL; return parent_ ? parent_->GetRootWindow() : NULL;
} }
...@@ -487,10 +494,6 @@ void Window::SchedulePaint() { ...@@ -487,10 +494,6 @@ void Window::SchedulePaint() {
SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); 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, Window* Window::GetWindowForPoint(const gfx::Point& local_point,
bool return_tightest, bool return_tightest,
bool for_event_handling) { bool for_event_handling) {
...@@ -556,4 +559,15 @@ void Window::UpdateLayerName(const std::string& name) { ...@@ -556,4 +559,15 @@ void Window::UpdateLayerName(const std::string& name) {
#endif #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 } // namespace aura
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -220,6 +220,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate { ...@@ -220,6 +220,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// Returns true if the Window can be focused. // Returns true if the Window can be focused.
virtual bool CanFocus() const; 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 // Returns the FocusManager for the Window, which may be attached to a parent
// Window. Can return NULL if the Window has no FocusManager. // Window. Can return NULL if the Window has no FocusManager.
virtual internal::FocusManager* GetFocusManager(); virtual internal::FocusManager* GetFocusManager();
...@@ -250,6 +253,10 @@ class AURA_EXPORT Window : public ui::LayerDelegate { ...@@ -250,6 +253,10 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
void* GetProperty(const char* name) const; void* GetProperty(const char* name) const;
int GetIntProperty(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: protected:
// Returns the root window or NULL if we aren't yet attached to the root // Returns the root window or NULL if we aren't yet attached to the root
// window. // window.
...@@ -272,10 +279,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate { ...@@ -272,10 +279,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// Schedules a paint for the Window's entire bounds. // Schedules a paint for the Window's entire bounds.
void SchedulePaint(); 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|. // Gets a Window (either this one or a subwindow) containing |local_point|.
// If |return_tightest| is true, returns the tightest-containing (i.e. // If |return_tightest| is true, returns the tightest-containing (i.e.
// furthest down the hierarchy) Window containing the point; otherwise, // furthest down the hierarchy) Window containing the point; otherwise,
...@@ -298,6 +301,10 @@ class AURA_EXPORT Window : public ui::LayerDelegate { ...@@ -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. // Updates the layer name with a name based on the window's name and id.
void UpdateLayerName(const std::string& name); 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_; client::WindowType type_;
WindowDelegate* delegate_; WindowDelegate* delegate_;
......
// 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -660,6 +660,7 @@ TEST_F(WindowTest, StopsEventPropagation) { ...@@ -660,6 +660,7 @@ TEST_F(WindowTest, StopsEventPropagation) {
EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10)));
EXPECT_TRUE(w111->CanFocus()); EXPECT_TRUE(w111->CanFocus());
EXPECT_TRUE(w111->CanReceiveEvents());
w111->Focus(); w111->Focus();
EXPECT_EQ(w111.get(), w1->GetFocusManager()->GetFocusedWindow()); EXPECT_EQ(w111.get(), w1->GetFocusManager()->GetFocusedWindow());
...@@ -671,14 +672,22 @@ TEST_F(WindowTest, StopsEventPropagation) { ...@@ -671,14 +672,22 @@ TEST_F(WindowTest, StopsEventPropagation) {
// It should be possible to focus w121 since it is at or above the // It should be possible to focus w121 since it is at or above the
// consumes_events_ window. // consumes_events_ window.
EXPECT_TRUE(w121->CanFocus()); EXPECT_TRUE(w121->CanFocus());
EXPECT_TRUE(w121->CanReceiveEvents());
w121->Focus(); w121->Focus();
EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow());
// An attempt to focus 111 should be ignored and w121 should retain focus, // 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. // 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(); w111->Focus();
EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); 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) { TEST_F(WindowTest, IgnoreEventsTest) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment