diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-13 01:40:42 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-13 01:40:42 +0000 |
commit | b9b3097e1b40dd32b8853fef3343a8519ccebe71 (patch) | |
tree | 31b6246fb76b22a7a6de483996f8b525e4fefb5c | |
parent | e3538ea7413f92927c190757c9bfe8bb96b98bc1 (diff) | |
download | chromium_src-b9b3097e1b40dd32b8853fef3343a8519ccebe71.zip chromium_src-b9b3097e1b40dd32b8853fef3343a8519ccebe71.tar.gz chromium_src-b9b3097e1b40dd32b8853fef3343a8519ccebe71.tar.bz2 |
Don't deactivate/unfocus unless a display is removed.
Because pepper flash exits fullscreen when it loses focus.
BUG=283173
TEST=covered by test
Review URL: https://chromiumcodereview.appspot.com/23890016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222949 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/display/display_controller.cc | 15 | ||||
-rw-r--r-- | ash/display/display_controller.h | 2 | ||||
-rw-r--r-- | ash/display/display_controller_unittest.cc | 134 | ||||
-rw-r--r-- | ash/display/display_manager.cc | 2 | ||||
-rw-r--r-- | ash/display/display_manager.h | 2 |
5 files changed, 135 insertions, 20 deletions
diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc index 2141e0c..8dde730 100644 --- a/ash/display/display_controller.cc +++ b/ash/display/display_controller.cc @@ -141,7 +141,7 @@ class FocusActivationStore { active_(NULL) { } - void Store() { + void Store(bool display_removed) { if (!activation_client_) { aura::RootWindow* root = Shell::GetPrimaryRootWindow(); activation_client_ = aura::client::GetActivationClient(root); @@ -156,14 +156,17 @@ class FocusActivationStore { tracker_.Add(active_); // Deactivate the window to close menu / bubble windows. - activation_client_->DeactivateWindow(active_); + if (display_removed) + activation_client_->DeactivateWindow(active_); + // Release capture if any. capture_client_->SetCapture(NULL); // 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. - focus_client_->FocusWindow(NULL); + if (display_removed) + focus_client_->FocusWindow(NULL); } void Restore() { @@ -386,7 +389,7 @@ void DisplayController::SetLayoutForCurrentDisplays( to_set.primary_id = primary.id(); layout_store->RegisterLayoutForDisplayIdPair( pair.first, pair.second, to_set); - PreDisplayConfigurationChange(); + PreDisplayConfigurationChange(false); // TODO(oshima): Call UpdateDisplays instead. UpdateDisplayBoundsForLayout(); // Primary's bounds stay the same. Just notify bounds change @@ -711,9 +714,9 @@ void DisplayController::CloseMirrorWindow() { mirror_window_controller_->Close(); } -void DisplayController::PreDisplayConfigurationChange() { +void DisplayController::PreDisplayConfigurationChange(bool display_removed) { FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); - focus_activation_store_->Store(); + focus_activation_store_->Store(display_removed); gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); gfx::Display display = diff --git a/ash/display/display_controller.h b/ash/display/display_controller.h index 97620fc..bbfd55a 100644 --- a/ash/display/display_controller.h +++ b/ash/display/display_controller.h @@ -166,7 +166,7 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver, virtual void CreateOrUpdateMirrorWindow( const internal::DisplayInfo& info) OVERRIDE; virtual void CloseMirrorWindow() OVERRIDE; - virtual void PreDisplayConfigurationChange() OVERRIDE; + virtual void PreDisplayConfigurationChange(bool dispay_removed) OVERRIDE; virtual void PostDisplayConfigurationChange() OVERRIDE; private: diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc index 5ff0d7e..9e89cff 100644 --- a/ash/display/display_controller_unittest.cc +++ b/ash/display/display_controller_unittest.cc @@ -15,6 +15,10 @@ #include "ash/test/ash_test_base.h" #include "ash/test/cursor_manager_test_api.h" #include "base/command_line.h" +#include "ui/aura/client/activation_change_observer.h" +#include "ui/aura/client/activation_client.h" +#include "ui/aura/client/focus_change_observer.h" +#include "ui/aura/client/focus_client.h" #include "ui/aura/env.h" #include "ui/aura/root_window.h" #include "ui/aura/test/event_generator.h" @@ -35,21 +39,47 @@ namespace { const char kDesktopBackgroundView[] = "DesktopBackgroundView"; +template<typename T> +class Resetter { + public: + explicit Resetter(T* value) : value_(*value) { + *value = 0; + } + ~Resetter() { } + T value() { return value_; } + + private: + T value_; + DISALLOW_COPY_AND_ASSIGN(Resetter); +}; + class TestObserver : public DisplayController::Observer, - public gfx::DisplayObserver { + public gfx::DisplayObserver, + public aura::client::FocusChangeObserver, + public aura::client::ActivationChangeObserver { public: TestObserver() : changing_count_(0), changed_count_(0), bounds_changed_count_(0), - changed_display_id_(0) { + changed_display_id_(0), + focus_changed_count_(0), + activation_changed_count_(0) { Shell::GetInstance()->display_controller()->AddObserver(this); Shell::GetScreen()->AddObserver(this); + aura::client::GetFocusClient(Shell::GetPrimaryRootWindow())-> + AddObserver(this); + aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> + AddObserver(this); } virtual ~TestObserver() { Shell::GetInstance()->display_controller()->RemoveObserver(this); Shell::GetScreen()->RemoveObserver(this); + aura::client::GetFocusClient(Shell::GetPrimaryRootWindow())-> + RemoveObserver(this); + aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> + RemoveObserver(this); } // Overridden from DisplayController::Observer @@ -70,23 +100,42 @@ class TestObserver : public DisplayController::Observer, virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE { } + // Overridden from aura::client::FocusChangeObserver + virtual void OnWindowFocused(aura::Window* gained_focus, + aura::Window* lost_focus) OVERRIDE { + focus_changed_count_++; + } + + // Overridden from aura::client::ActivationChangeObserver + virtual void OnWindowActivated(aura::Window* gained_active, + aura::Window* lost_active) OVERRIDE { + activation_changed_count_++; + } + virtual void OnAttemptToReactivateWindow( + aura::Window* request_active, + aura::Window* actual_active) OVERRIDE { + } + int CountAndReset() { EXPECT_EQ(changing_count_, changed_count_); - int count = changing_count_; - changing_count_ = changed_count_ = 0; - return count; + changed_count_ = 0; + return Resetter<int>(&changing_count_).value(); } int64 GetBoundsChangedCountAndReset() { - int count = bounds_changed_count_; - bounds_changed_count_ = 0; - return count; + return Resetter<int>(&bounds_changed_count_).value(); } int64 GetChangedDisplayIdAndReset() { - int64 id = changed_display_id_; - changed_display_id_ = 0; - return id; + return Resetter<int64>(&changed_display_id_).value(); + } + + int GetFocusChangedCountAndReset() { + return Resetter<int>(&focus_changed_count_).value(); + } + + int GetActivationChangedCountAndReset() { + return Resetter<int>(&activation_changed_count_).value(); } private: @@ -96,6 +145,9 @@ class TestObserver : public DisplayController::Observer, int bounds_changed_count_; int64 changed_display_id_; + int focus_changed_count_; + int activation_changed_count_; + DISALLOW_COPY_AND_ASSIGN(TestObserver); }; @@ -258,10 +310,16 @@ TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { if (!SupportsMultipleDisplays()) return; + // Creates windows to catch activation change event. + scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(1)); + w1->Focus(); + TestObserver observer; UpdateDisplay("500x500,400x400"); EXPECT_EQ(1, observer.CountAndReset()); // resize and add EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); gfx::Insets insets(5, 5, 5, 5); int64 secondary_display_id = ScreenAsh::GetSecondaryDisplay().id(); Shell::GetInstance()->display_manager()->UpdateWorkAreaOfDisplay( @@ -271,11 +329,15 @@ TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); // Layout the secondary display to the bottom of the primary. SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); EXPECT_EQ(1, observer.CountAndReset()); EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); @@ -285,6 +347,8 @@ TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { SetSecondaryDisplayLayout(DisplayLayout::LEFT); EXPECT_EQ(1, observer.CountAndReset()); EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString()); @@ -294,6 +358,8 @@ TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { SetSecondaryDisplayLayout(DisplayLayout::TOP); EXPECT_EQ(1, observer.CountAndReset()); EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString()); @@ -303,6 +369,8 @@ TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 300); EXPECT_EQ(1, observer.CountAndReset()); // resize and add EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("500,300 400x400", GetSecondaryDisplay().bounds().ToString()); @@ -311,6 +379,8 @@ TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 490); EXPECT_EQ(1, observer.CountAndReset()); // resize and add EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("500,400 400x400", GetSecondaryDisplay().bounds().ToString()); @@ -319,6 +389,8 @@ TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); EXPECT_EQ(1, observer.CountAndReset()); // resize and add + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("500,-300 400x400", GetSecondaryDisplay().bounds().ToString()); @@ -327,6 +399,8 @@ TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); EXPECT_EQ(1, observer.CountAndReset()); // resize and add + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("-200,500 400x400", GetSecondaryDisplay().bounds().ToString()); @@ -335,6 +409,8 @@ TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); EXPECT_EQ(1, observer.CountAndReset()); // resize and add + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("400,500 400x400", GetSecondaryDisplay().bounds().ToString()); @@ -342,6 +418,8 @@ TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); EXPECT_EQ(1, observer.CountAndReset()); // resize and add + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString()); @@ -350,18 +428,30 @@ TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { EXPECT_EQ(0, observer.GetChangedDisplayIdAndReset()); EXPECT_EQ(0, observer.GetBoundsChangedCountAndReset()); EXPECT_EQ(0, observer.CountAndReset()); // resize and add + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString()); + + UpdateDisplay("500x500"); + EXPECT_LE(1, observer.GetFocusChangedCountAndReset()); + EXPECT_LE(1, observer.GetActivationChangedCountAndReset()); } TEST_F(DisplayControllerTest, BoundsUpdated) { if (!SupportsMultipleDisplays()) return; + // Creates windows to catch activation change event. + scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(1)); + w1->Focus(); + TestObserver observer; SetDefaultDisplayLayout(DisplayLayout::BOTTOM); UpdateDisplay("200x200,300x300"); // layout, resize and add. EXPECT_EQ(1, observer.CountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); internal::DisplayManager* display_manager = Shell::GetInstance()->display_manager(); @@ -375,21 +465,29 @@ TEST_F(DisplayControllerTest, BoundsUpdated) { UpdateDisplay("400x400,200x200"); EXPECT_EQ(1, observer.CountAndReset()); // two resizes + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("0,400 200x200", GetSecondaryDisplay().bounds().ToString()); UpdateDisplay("400x400,300x300"); EXPECT_EQ(1, observer.CountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("0,400 300x300", GetSecondaryDisplay().bounds().ToString()); UpdateDisplay("400x400"); EXPECT_EQ(1, observer.CountAndReset()); + EXPECT_LE(1, observer.GetFocusChangedCountAndReset()); + EXPECT_LE(1, observer.GetActivationChangedCountAndReset()); EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays()); UpdateDisplay("400x500*2,300x300"); EXPECT_EQ(1, observer.CountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); EXPECT_EQ("0,0 200x250", GetPrimaryDisplay().bounds().ToString()); EXPECT_EQ("0,250 300x300", GetSecondaryDisplay().bounds().ToString()); @@ -397,25 +495,39 @@ TEST_F(DisplayControllerTest, BoundsUpdated) { // No change UpdateDisplay("400x500*2,300x300"); EXPECT_EQ(0, observer.CountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); // Rotation int64 primary_id = GetPrimaryDisplay().id(); display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); EXPECT_EQ(1, observer.CountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); EXPECT_EQ(0, observer.CountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); // UI scale is eanbled only on internal display. int64 secondary_id = GetSecondaryDisplay().id(); gfx::Display::SetInternalDisplayId(secondary_id); display_manager->SetDisplayUIScale(secondary_id, 1.125f); EXPECT_EQ(1, observer.CountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); display_manager->SetDisplayUIScale(secondary_id, 1.125f); EXPECT_EQ(0, observer.CountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); display_manager->SetDisplayUIScale(primary_id, 1.125f); EXPECT_EQ(0, observer.CountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); display_manager->SetDisplayUIScale(primary_id, 1.125f); EXPECT_EQ(0, observer.CountAndReset()); + EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); + EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); } TEST_F(DisplayControllerTest, InvertLayout) { diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc index 1c3edea..9f6b7ea 100644 --- a/ash/display/display_manager.cc +++ b/ash/display/display_manager.cc @@ -636,7 +636,7 @@ void DisplayManager::UpdateDisplays( return; } if (delegate_) - delegate_->PreDisplayConfigurationChange(); + delegate_->PreDisplayConfigurationChange(!removed_displays.empty()); size_t updated_index; if (UpdateSecondaryDisplayBoundsForLayout(&new_displays, &updated_index) && diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h index 4699eee..93c203b 100644 --- a/ash/display/display_manager.h +++ b/ash/display/display_manager.h @@ -59,7 +59,7 @@ class ASH_EXPORT DisplayManager virtual void CloseMirrorWindow() = 0; // Called before and after the display configuration changes. - virtual void PreDisplayConfigurationChange() = 0; + virtual void PreDisplayConfigurationChange(bool display_removed) = 0; virtual void PostDisplayConfigurationChange() = 0; }; |