summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-11 18:23:09 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-11 18:23:09 +0000
commitdbf835d86cb73a253b4d36d75416895637f10d28 (patch)
tree68ec294a698aa822cb57c2132cc4a6cc153e6714 /ash
parent21f3fe0616125a0716edd6f28fbf4465ebf4d824 (diff)
downloadchromium_src-dbf835d86cb73a253b4d36d75416895637f10d28.zip
chromium_src-dbf835d86cb73a253b4d36d75416895637f10d28.tar.gz
chromium_src-dbf835d86cb73a253b4d36d75416895637f10d28.tar.bz2
Defocus the focused object before moving windows when a display is disconnected.
BUG=chrome-os-partner:11131 TEST=updated the test to cover the case. Review URL: https://chromiumcodereview.appspot.com/10915198 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156065 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/root_window_controller.cc15
-rw-r--r--ash/root_window_controller_unittest.cc39
2 files changed, 49 insertions, 5 deletions
diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc
index 1e38059..ef8df72 100644
--- a/ash/root_window_controller.cc
+++ b/ash/root_window_controller.cc
@@ -366,19 +366,24 @@ bool RootWindowController::IsInMaximizedMode() const {
void RootWindowController::MoveWindowsTo(aura::RootWindow* dst) {
aura::Window* focused = dst->GetFocusManager()->GetFocusedWindow();
+ aura::WindowTracker tracker;
+ if (focused)
+ tracker.Add(focused);
aura::client::ActivationClient* activation_client =
aura::client::GetActivationClient(dst);
aura::Window* active = activation_client->GetActiveWindow();
+ if (active && focused != active)
+ tracker.Add(active);
// Deactivate the window to close menu / bubble windows.
activation_client->DeactivateWindow(active);
// Release capture if any.
aura::client::GetCaptureClient(root_window_.get())->
SetCapture(NULL);
- aura::WindowTracker tracker;
- if (focused)
- tracker.Add(focused);
- if (active && focused != active)
- tracker.Add(active);
+ // Clear the focused window if any. This is necessary because a
+ // window may be deleted when losing focus (fullscreen flash for
+ // example). If the focused window is still alive after move, it'll
+ // be re-focused below.
+ dst->GetFocusManager()->SetFocusedWindow(NULL, NULL);
ReparentAllWindows(root_window_.get(), dst);
diff --git a/ash/root_window_controller_unittest.cc b/ash/root_window_controller_unittest.cc
index 12b27e8..2ed60e8 100644
--- a/ash/root_window_controller_unittest.cc
+++ b/ash/root_window_controller_unittest.cc
@@ -9,9 +9,13 @@
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_util.h"
#include "ui/aura/env.h"
+#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
+#include "ui/aura/test/test_window_delegate.h"
+#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
+#include "ui/aura/window_tracker.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
@@ -38,6 +42,27 @@ class TestDelegate : public views::WidgetDelegateView {
DISALLOW_COPY_AND_ASSIGN(TestDelegate);
};
+class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate {
+ public:
+ DeleteOnBlurDelegate() : window_(NULL) {}
+ virtual ~DeleteOnBlurDelegate() {}
+
+ void set_window(aura::Window* window) { window_ = window; }
+
+ // aura::test::TestWindowDelegate overrides:
+ virtual bool CanFocus() OVERRIDE {
+ return true;
+ }
+ virtual void OnBlur() OVERRIDE {
+ delete window_;
+ }
+
+ private:
+ aura::Window* window_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate);
+};
+
views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
views::Widget* widget =
views::Widget::CreateWindowWithBounds(NULL, bounds);
@@ -101,8 +126,22 @@ TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
#endif
+ // Make sure a window that will delete itself when losing focus
+ // will not crash.
+ aura::WindowTracker tracker;
+ DeleteOnBlurDelegate delete_on_blur_delegate;
+ aura::Window* d2 = aura::test::CreateTestWindowWithDelegate(
+ &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100), NULL);
+ delete_on_blur_delegate.set_window(d2);
+ root_windows[0]->GetFocusManager()->SetFocusedWindow(
+ d2, NULL);
+ tracker.Add(d2);
+
UpdateDisplay("600x600");
+ // d2 must have been deleted.
+ EXPECT_FALSE(tracker.Contains(d2));
+
EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
EXPECT_EQ("50,10 100x100", normal->GetWindowBoundsInScreen().ToString());
EXPECT_EQ("50,10 100x100",