summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 04:52:28 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 04:52:28 +0000
commit0d9334b2f76e4fe937a19c44671a8c53bf0f1a59 (patch)
tree68ac391d2b0d382a6844621be98292cc4e934478 /ash
parent3257d94006f4a5773c29c5dcd0b1a61b2c0f2fdb (diff)
downloadchromium_src-0d9334b2f76e4fe937a19c44671a8c53bf0f1a59.zip
chromium_src-0d9334b2f76e4fe937a19c44671a8c53bf0f1a59.tar.gz
chromium_src-0d9334b2f76e4fe937a19c44671a8c53bf0f1a59.tar.bz2
Always look for a transient child from the activatable window.
Re-upload of http://codereview.chromium.org/9635003 BUG=114546 TEST=See issue. Also ensure that behavior is expected with multiple windows open, including multiple windows with modal dialogs. Review URL: http://codereview.chromium.org/9694050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126565 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/wm/activation_controller.cc3
-rw-r--r--ash/wm/window_modality_controller.cc54
-rw-r--r--ash/wm/window_modality_controller.h12
-rw-r--r--ash/wm/window_modality_controller_unittest.cc34
4 files changed, 77 insertions, 26 deletions
diff --git a/ash/wm/activation_controller.cc b/ash/wm/activation_controller.cc
index 75fa135..b3127f7 100644
--- a/ash/wm/activation_controller.cc
+++ b/ash/wm/activation_controller.cc
@@ -116,8 +116,7 @@ aura::Window* ActivationController::GetActivatableWindow(aura::Window* window) {
// ActivationController, aura::client::ActivationClient implementation:
void ActivationController::ActivateWindow(aura::Window* window) {
- aura::Window* window_modal_transient =
- WindowModalityController::GetWindowModalTransient(window);
+ aura::Window* window_modal_transient = wm::GetWindowModalTransient(window);
if (window_modal_transient) {
ActivateWindow(window_modal_transient);
return;
diff --git a/ash/wm/window_modality_controller.cc b/ash/wm/window_modality_controller.cc
index 934c687..91ffe9b 100644
--- a/ash/wm/window_modality_controller.cc
+++ b/ash/wm/window_modality_controller.cc
@@ -11,7 +11,8 @@
#include "ui/base/ui_base_types.h"
namespace ash {
-namespace internal {
+
+namespace wm {
namespace {
@@ -19,46 +20,59 @@ bool TransientChildIsWindowModal(aura::Window* window) {
return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_WINDOW;
}
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowModalityController, public:
-
-WindowModalityController::WindowModalityController() {
-}
-
-WindowModalityController::~WindowModalityController() {
-}
-
-aura::Window* WindowModalityController::GetWindowModalTransient(
- aura::Window* window) {
- if (!window)
- return NULL;
-
+aura::Window* GetWindowModalTransientChild(aura::Window* window) {
aura::Window::Windows::const_iterator it;
for (it = window->transient_children().begin();
it != window->transient_children().end();
++it) {
if (TransientChildIsWindowModal(*it) && (*it)->IsVisible()) {
if (!(*it)->transient_children().empty())
- return GetWindowModalTransient(*it);
+ return GetWindowModalTransientChild(*it);
return *it;
}
}
return NULL;
}
+} // namespace
+
+aura::Window* GetWindowModalTransient(aura::Window* window) {
+ if (!window)
+ return NULL;
+
+ // We always want to check the for the transient child of the activatable
+ // window.
+ window = wm::GetActivatableWindow(window);
+ if (!window)
+ return NULL;
+
+ return GetWindowModalTransientChild(window);
+}
+
+} // namespace wm
+
+namespace internal {
+
+////////////////////////////////////////////////////////////////////////////////
+// WindowModalityController, public:
+
+WindowModalityController::WindowModalityController() {
+}
+
+WindowModalityController::~WindowModalityController() {
+}
+
////////////////////////////////////////////////////////////////////////////////
// WindowModalityController, aura::EventFilter implementation:
bool WindowModalityController::PreHandleKeyEvent(aura::Window* target,
aura::KeyEvent* event) {
- return !!GetWindowModalTransient(target);
+ return !!wm::GetWindowModalTransient(target);
}
bool WindowModalityController::PreHandleMouseEvent(aura::Window* target,
aura::MouseEvent* event) {
- aura::Window* modal_transient_child = GetWindowModalTransient(target);
+ aura::Window* modal_transient_child = wm::GetWindowModalTransient(target);
if (modal_transient_child && event->type() == ui::ET_MOUSE_PRESSED)
wm::ActivateWindow(modal_transient_child);
return !!modal_transient_child;
diff --git a/ash/wm/window_modality_controller.h b/ash/wm/window_modality_controller.h
index 0251a77..a12ab3f 100644
--- a/ash/wm/window_modality_controller.h
+++ b/ash/wm/window_modality_controller.h
@@ -6,10 +6,18 @@
#define ASH_WM_WINDOW_MODALITY_CONTROLLER_H_
#pragma once
+#include "ash/ash_export.h"
#include "base/compiler_specific.h"
#include "ui/aura/event_filter.h"
namespace ash {
+
+namespace wm {
+// Returns the window-modal transient child of |window|, or NULL if |window|
+// does not have any window-modal transient children.
+ASH_EXPORT aura::Window* GetWindowModalTransient(aura::Window* window);
+}
+
namespace internal {
// WindowModalityController is an event filter that consumes events sent to
@@ -20,10 +28,6 @@ class WindowModalityController : public aura::EventFilter {
WindowModalityController();
virtual ~WindowModalityController();
- // Returns the window-modal transient child of |window|, or NULL if |window|
- // does not have any window-modal transient children.
- static aura::Window* GetWindowModalTransient(aura::Window* window);
-
// Overridden from aura::EventFilter:
virtual bool PreHandleKeyEvent(aura::Window* target,
aura::KeyEvent* event) OVERRIDE;
diff --git a/ash/wm/window_modality_controller_unittest.cc b/ash/wm/window_modality_controller_unittest.cc
index 666ca99..e196514 100644
--- a/ash/wm/window_modality_controller_unittest.cc
+++ b/ash/wm/window_modality_controller_unittest.cc
@@ -202,5 +202,39 @@ TEST_F(WindowModalityControllerTest, Events) {
}
}
+// Creates windows w1 and non activatiable child w11. Creates transient window
+// w2 and adds it as a transeint child of w1. Ensures that w2 is parented to
+// the parent of w1, and that GetWindowModalTransient(w11) returns w2.
+TEST_F(WindowModalityControllerTest, GetWindowModalTransient) {
+ aura::test::TestWindowDelegate d;
+ scoped_ptr<aura::Window> w1(
+ aura::test::CreateTestWindowWithDelegate(&d, -1, gfx::Rect(), NULL));
+ scoped_ptr<aura::Window> w11(
+ aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
+ scoped_ptr<aura::Window> w2(
+ aura::test::CreateTestWindowWithDelegate(&d, -2, gfx::Rect(), NULL));
+ w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
+
+ aura::Window* wt;
+ wt = wm::GetWindowModalTransient(w1.get());
+ ASSERT_EQ(static_cast<aura::Window*>(NULL), wt);
+
+ // Parent w2 to w1. It should get parented to the parent of w1.
+ w1->AddTransientChild(w2.get());
+ ASSERT_EQ(2U, w1->parent()->children().size());
+ EXPECT_EQ(-2, w1->parent()->children().at(1)->id());
+
+ // Request the modal transient window for w1, it should be w2.
+ wt = wm::GetWindowModalTransient(w1.get());
+ ASSERT_NE(static_cast<aura::Window*>(NULL), wt);
+ EXPECT_EQ(-2, wt->id());
+
+ // Request the modal transient window for w11, it should also be w2.
+ wt = wm::GetWindowModalTransient(w11.get());
+ ASSERT_NE(static_cast<aura::Window*>(NULL), wt);
+ EXPECT_EQ(-2, wt->id());
+}
+
+
} // namespace internal
} // namespace ash