diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-05 22:14:52 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-05 22:14:52 +0000 |
commit | 37533821562c1f1c48c5c89f6161175b4e6ad569 (patch) | |
tree | 30dea38eb263292d4a853e9af9ee5379e38a246a /ash | |
parent | d2066ecd0fc75fb50a737e6d4b36a8d652bff6c5 (diff) | |
download | chromium_src-37533821562c1f1c48c5c89f6161175b4e6ad569.zip chromium_src-37533821562c1f1c48c5c89f6161175b4e6ad569.tar.gz chromium_src-37533821562c1f1c48c5c89f6161175b4e6ad569.tar.bz2 |
Remove old activation code and disable-focus-controller flags
BUG=285339,285364
Review URL: https://chromiumcodereview.appspot.com/23874013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221529 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 7 | ||||
-rw-r--r-- | ash/shelf/shelf_widget_unittest.cc | 8 | ||||
-rw-r--r-- | ash/shell.cc | 35 | ||||
-rw-r--r-- | ash/shell.h | 2 | ||||
-rw-r--r-- | ash/wm/activation_controller.cc | 413 | ||||
-rw-r--r-- | ash/wm/activation_controller.h | 126 | ||||
-rw-r--r-- | ash/wm/activation_controller_delegate.h | 37 | ||||
-rw-r--r-- | ash/wm/activation_controller_unittest.cc | 575 | ||||
-rw-r--r-- | ash/wm/ash_activation_controller.cc | 96 | ||||
-rw-r--r-- | ash/wm/ash_activation_controller.h | 37 | ||||
-rw-r--r-- | ash/wm/ash_activation_controller_unittest.cc | 168 | ||||
-rw-r--r-- | ash/wm/base_layout_manager.cc | 10 | ||||
-rw-r--r-- | ash/wm/mru_window_tracker.cc | 2 | ||||
-rw-r--r-- | ash/wm/overview/window_selector.cc | 2 | ||||
-rw-r--r-- | ash/wm/panels/panel_layout_manager_unittest.cc | 3 | ||||
-rw-r--r-- | ash/wm/window_manager_unittest.cc | 7 | ||||
-rw-r--r-- | ash/wm/window_util.cc | 1 | ||||
-rw-r--r-- | ash/wm/workspace_controller_unittest.cc | 3 |
18 files changed, 20 insertions, 1512 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 6f17a00..864a68b 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -376,13 +376,8 @@ 'volume_control_delegate.h', 'wm/app_list_controller.cc', 'wm/app_list_controller.h', - 'wm/activation_controller.cc', - 'wm/activation_controller.h', - 'wm/activation_controller_delegate.h', 'wm/always_on_top_controller.cc', 'wm/always_on_top_controller.h', - 'wm/ash_activation_controller.cc', - 'wm/ash_activation_controller.h', 'wm/ash_native_cursor_manager.cc', 'wm/ash_native_cursor_manager.h', 'wm/ash_focus_rules.cc', @@ -749,8 +744,6 @@ 'test/ash_unittests.cc', 'tooltips/tooltip_controller_unittest.cc', 'touch/touch_observer_hud_unittest.cc', - 'wm/activation_controller_unittest.cc', - 'wm/ash_activation_controller_unittest.cc', 'wm/ash_native_cursor_manager_unittest.cc', 'wm/base_layout_manager_unittest.cc', 'wm/custom_frame_view_ash_unittest.cc', diff --git a/ash/shelf/shelf_widget_unittest.cc b/ash/shelf/shelf_widget_unittest.cc index 6168787..2de02bc 100644 --- a/ash/shelf/shelf_widget_unittest.cc +++ b/ash/shelf/shelf_widget_unittest.cc @@ -39,11 +39,9 @@ typedef test::AshTestBase ShelfWidgetTest; // Launcher can't be activated on mouse click, but it is activable from // the focus cycler or as fallback. -TEST_F(ShelfWidgetTest, ActivateAsFallback) { - // TODO(mtomasz): make this test work with the FocusController. - if (views::corewm::UseFocusController()) - return; - +// TODO(mtomasz): make this test work with the FocusController. +// crbug.com/285364. +TEST_F(ShelfWidgetTest, DISABLED_ActivateAsFallback) { Launcher* launcher = Launcher::ForPrimaryDisplay(); ShelfWidget* shelf_widget = launcher->shelf_widget(); EXPECT_FALSE(shelf_widget->CanActivate()); diff --git a/ash/shell.cc b/ash/shell.cc index 96a8921..5348542 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -42,9 +42,7 @@ #include "ash/system/status_area_widget.h" #include "ash/system/tray/system_tray_delegate.h" #include "ash/system/tray/system_tray_notifier.h" -#include "ash/wm/activation_controller.h" #include "ash/wm/app_list_controller.h" -#include "ash/wm/ash_activation_controller.h" #include "ash/wm/ash_focus_rules.h" #include "ash/wm/ash_native_cursor_manager.h" #include "ash/wm/base_layout_manager.h" @@ -322,10 +320,6 @@ Shell::~Shell() { display_controller_.reset(); screen_position_controller_.reset(); - // Delete the activation controller after other controllers and launcher - // because they might have registered ActivationChangeObserver. - activation_controller_.reset(); - #if defined(OS_CHROMEOS) && defined(USE_X11) if (display_change_observer_) output_configurator_->RemoveObserver(display_change_observer_.get()); @@ -482,22 +476,11 @@ void Shell::Init() { // initialized first by the ActivationController, but now that FocusController // no longer does this we need to do it explicitly. aura::Env::GetInstance(); - if (views::corewm::UseFocusController()) { - views::corewm::FocusController* focus_controller = - new views::corewm::FocusController(new wm::AshFocusRules); - focus_client_.reset(focus_controller); - activation_client_ = focus_controller; - activation_client_->AddObserver(this); - } else { - focus_client_.reset(new aura::FocusManager); - activation_controller_.reset( - new internal::ActivationController( - focus_client_.get(), - new internal::AshActivationController)); - activation_client_ = activation_controller_.get(); - AddPreTargetHandler(activation_controller_.get()); - } - + views::corewm::FocusController* focus_controller = + new views::corewm::FocusController(new wm::AshFocusRules); + focus_client_.reset(focus_controller); + activation_client_ = focus_controller; + activation_client_->AddObserver(this); focus_cycler_.reset(new internal::FocusCycler()); screen_position_controller_.reset(new internal::ScreenPositionController); @@ -927,11 +910,9 @@ void Shell::InitRootWindowController( aura::client::SetFocusClient(root_window, focus_client_.get()); input_method_filter_->SetInputMethodPropertyInRootWindow(root_window); aura::client::SetActivationClient(root_window, activation_client_); - if (views::corewm::UseFocusController()) { - views::corewm::FocusController* controller = - static_cast<views::corewm::FocusController*>(activation_client_); - root_window->AddPreTargetHandler(controller); - } + views::corewm::FocusController* focus_controller = + static_cast<views::corewm::FocusController*>(activation_client_); + root_window->AddPreTargetHandler(focus_controller); aura::client::SetVisibilityClient(root_window, visibility_controller_.get()); aura::client::SetDragDropClient(root_window, drag_drop_controller_.get()); aura::client::SetScreenPositionClient(root_window, diff --git a/ash/shell.h b/ash/shell.h index 718d1f8..c4762ab7 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -100,7 +100,6 @@ class WindowSelectorController; namespace internal { class AcceleratorFilter; -class ActivationController; class AppListController; class AppListLauncherItemDelegate; class CaptureController; @@ -555,7 +554,6 @@ class ASH_EXPORT Shell scoped_ptr<internal::AppListController> app_list_controller_; - scoped_ptr<internal::ActivationController> activation_controller_; scoped_ptr<internal::DragDropController> drag_drop_controller_; scoped_ptr<internal::ResizeShadowController> resize_shadow_controller_; scoped_ptr<views::corewm::ShadowController> shadow_controller_; diff --git a/ash/wm/activation_controller.cc b/ash/wm/activation_controller.cc deleted file mode 100644 index 328c34c..0000000 --- a/ash/wm/activation_controller.cc +++ /dev/null @@ -1,413 +0,0 @@ -// 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. - -#include "ash/wm/activation_controller.h" - -#include "ash/root_window_controller.h" -#include "ash/shell.h" -#include "ash/shell_window_ids.h" -#include "ash/wm/activation_controller_delegate.h" -#include "ash/wm/property_util.h" -#include "ash/wm/window_util.h" -#include "base/auto_reset.h" -#include "ui/aura/client/activation_change_observer.h" -#include "ui/aura/client/activation_delegate.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/client/focus_client.h" -#include "ui/aura/env.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura/window_delegate.h" -#include "ui/base/ui_base_types.h" -#include "ui/compositor/layer.h" -#include "ui/views/corewm/window_modality_controller.h" - -namespace ash { -namespace internal { -namespace { - -// These are the list of container ids of containers which may contain windows -// that need to be activated in the order that they should be activated. -const int kWindowContainerIds[] = { - kShellWindowId_LockSystemModalContainer, - kShellWindowId_SettingBubbleContainer, - kShellWindowId_LockScreenContainer, - kShellWindowId_SystemModalContainer, - kShellWindowId_AlwaysOnTopContainer, - kShellWindowId_AppListContainer, - kShellWindowId_DefaultContainer, - - // Docked, panel, launcher and status are intentionally checked after other - // containers even though these layers are higher. The user expects their - // windows to be focused before these elements. - kShellWindowId_DockedContainer, - kShellWindowId_PanelContainer, - kShellWindowId_ShelfContainer, - kShellWindowId_StatusContainer, -}; - -bool BelongsToContainerWithEqualOrGreaterId(const aura::Window* window, - int container_id) { - for (; window; window = window->parent()) { - if (window->id() >= container_id) - return true; - } - return false; -} - -// Returns true if children of |window| can be activated. -// These are the only containers in which windows can receive focus. -bool SupportsChildActivation(aura::Window* window) { - for (size_t i = 0; i < arraysize(kWindowContainerIds); i++) { - if (window->id() == kWindowContainerIds[i]) - return true; - } - return false; -} - -bool HasModalTransientChild(aura::Window* window) { - aura::Window::Windows::const_iterator it; - for (it = window->transient_children().begin(); - it != window->transient_children().end(); - ++it) { - if ((*it)->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_WINDOW) - return true; - } - return false; -} - -// See description in VisibilityMatches. -enum ActivateVisibilityType { - TARGET_VISIBILITY, - CURRENT_VISIBILITY, -}; - -// Used by CanActivateWindowWithEvent() to test the visibility of a window. -// This is used by two distinct code paths: -// . when activating from an event we only care about the actual visibility. -// . when activating because of a keyboard accelerator, in which case we -// care about the TargetVisibility. -bool VisibilityMatches(aura::Window* window, ActivateVisibilityType type) { - bool visible = (type == CURRENT_VISIBILITY) ? window->IsVisible() : - window->TargetVisibility(); - return visible || wm::IsWindowMinimized(window) || - (window->TargetVisibility() && - (window->parent()->id() == kShellWindowId_DefaultContainer || - window->parent()->id() == kShellWindowId_LockScreenContainer)); -} - -// Returns true if |window| can be activated or deactivated. -// A window manager typically defines some notion of "top level window" that -// supports activation/deactivation. -bool CanActivateWindowWithEvent(aura::Window* window, - const ui::Event* event, - ActivateVisibilityType visibility_type) { - return window && - VisibilityMatches(window, visibility_type) && - (!aura::client::GetActivationDelegate(window) || - aura::client::GetActivationDelegate(window)->ShouldActivate()) && - SupportsChildActivation(window->parent()) && - (BelongsToContainerWithEqualOrGreaterId( - window, kShellWindowId_SystemModalContainer) || - !Shell::GetInstance()->IsSystemModalWindowOpen()); -} - -// When a modal window is activated, we bring its entire transient parent chain -// to the front. This function must be called before the modal transient is -// stacked at the top to ensure correct stacking order. -void StackTransientParentsBelowModalWindow(aura::Window* window) { - if (window->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_WINDOW) - return; - - aura::Window* transient_parent = window->transient_parent(); - while (transient_parent) { - transient_parent->parent()->StackChildAtTop(transient_parent); - transient_parent = transient_parent->transient_parent(); - } -} - -aura::Window* FindFocusableWindowFor(aura::Window* window) { - while (window && !window->CanFocus()) - window = window->parent(); - return window; -} - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, public: - -ActivationController::ActivationController( - aura::client::FocusClient* focus_client, - ActivationControllerDelegate* delegate) - : focus_client_(focus_client), - updating_activation_(false), - active_window_(NULL), - observer_manager_(this), - delegate_(delegate) { - aura::Env::GetInstance()->AddObserver(this); - focus_client_->AddObserver(this); -} - -ActivationController::~ActivationController() { - aura::Env::GetInstance()->RemoveObserver(this); - focus_client_->RemoveObserver(this); -} - -// static -aura::Window* ActivationController::GetActivatableWindow( - aura::Window* window, - const ui::Event* event) { - aura::Window* parent = window->parent(); - aura::Window* child = window; - while (parent) { - if (CanActivateWindowWithEvent(child, event, CURRENT_VISIBILITY)) - return child; - // If |child| isn't activatable, but has transient parent, trace - // that path instead. - if (child->transient_parent()) - return GetActivatableWindow(child->transient_parent(), event); - parent = parent->parent(); - child = child->parent(); - } - return NULL; -} - -bool ActivationController::CanActivateWindow(aura::Window* window) const { - return CanActivateWindowWithEvent(window, NULL, TARGET_VISIBILITY) && - !HasModalTransientChild(window); -} - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, aura::client::ActivationClient implementation: - -void ActivationController::AddObserver( - aura::client::ActivationChangeObserver* observer) { - observers_.AddObserver(observer); -} - -void ActivationController::RemoveObserver( - aura::client::ActivationChangeObserver* observer) { - observers_.RemoveObserver(observer); -} - -void ActivationController::ActivateWindow(aura::Window* window) { - ActivateWindowWithEvent(window, NULL); -} - -void ActivationController::DeactivateWindow(aura::Window* window) { - if (window) - ActivateNextWindow(window); -} - -aura::Window* ActivationController::GetActiveWindow() { - return active_window_; -} - -aura::Window* ActivationController::GetActivatableWindow(aura::Window* window) { - return GetActivatableWindow(window, NULL); -} - -aura::Window* ActivationController::GetToplevelWindow(aura::Window* window) { - return GetActivatableWindow(window, NULL); -} - -bool ActivationController::OnWillFocusWindow(aura::Window* window, - const ui::Event* event) { - return CanActivateWindowWithEvent( - GetActivatableWindow(window, event), event, CURRENT_VISIBILITY); -} - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, aura::WindowObserver implementation: - -void ActivationController::OnWindowVisibilityChanged(aura::Window* window, - bool visible) { - if (!visible) { - aura::Window* next_window = ActivateNextWindow(window); - if (next_window && next_window->parent() == window->parent()) { - // Despite the activation change, we need to keep the window being hidden - // stacked above the new window so it stays on top as it animates away. - window->layer()->parent()->StackAbove(window->layer(), - next_window->layer()); - } - } -} - -void ActivationController::OnWindowDestroying(aura::Window* window) { - // Don't use wm::IsActiveWidnow in case the |window| has already been - // removed from the root tree. - if (active_window_ == window) { - active_window_ = NULL; - FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, - observers_, - OnWindowActivated(NULL, window)); - ActivateWindow(GetTopmostWindowToActivate(window)); - } - observer_manager_.Remove(window); -} - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, aura::EnvObserver implementation: - -void ActivationController::OnWindowInitialized(aura::Window* window) { - observer_manager_.Add(window); -} - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, aura::RootWindowObserver implementation: - -void ActivationController::OnWindowFocused(aura::Window* gained_focus, - aura::Window* lost_focus) { - if (gained_focus) - ActivateWindow(GetActivatableWindow(gained_focus, NULL)); -} - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, ui::EventHandler implementation: - -void ActivationController::OnKeyEvent(ui::KeyEvent* event) { -} - -void ActivationController::OnMouseEvent(ui::MouseEvent* event) { - if (event->type() == ui::ET_MOUSE_PRESSED) - FocusWindowWithEvent(event); -} - -void ActivationController::OnScrollEvent(ui::ScrollEvent* event) { -} - -void ActivationController::OnTouchEvent(ui::TouchEvent* event) { - if (event->type() == ui::ET_TOUCH_PRESSED) - FocusWindowWithEvent(event); -} - -void ActivationController::OnGestureEvent(ui::GestureEvent* event) { - if (event->type() == ui::ET_GESTURE_BEGIN && - event->details().touch_points() == 1) { - FocusWindowWithEvent(event); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, private: - -void ActivationController::ActivateWindowWithEvent(aura::Window* window, - const ui::Event* event) { - // Prevent recursion when called from focus. - if (updating_activation_) - return; - base::AutoReset<bool> in_activate_window(&updating_activation_, true); - - // We allow the delegate to change which window gets activated, or to prevent - // activation changes. - aura::Window* original_active_window = window; - window = delegate_->WillActivateWindow(window); - // TODO(beng): note that this breaks the previous behavior where an activation - // attempt by a window behind the lock screen would at least - // restack that window frontmost within its container. fix this. - if (!window && original_active_window != window) - return; - - // TODO(beng): This encapsulates additional Ash-specific restrictions on - // whether activation can change. Should move to the delegate. - if (window && !CanActivateWindowWithEvent(window, event, CURRENT_VISIBILITY)) - return; - - if (active_window_ == window) - return; - - aura::Window* old_active = active_window_; - active_window_ = window; - - if (window && - !window->Contains(aura::client::GetFocusClient(window)-> - GetFocusedWindow())) { - aura::client::GetFocusClient(window)->FocusWindow(window); - } - - if (window) { - StackTransientParentsBelowModalWindow(window); - window->parent()->StackChildAtTop(window); - } - - FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, - observers_, - OnWindowActivated(window, old_active)); - if (aura::client::GetActivationChangeObserver(old_active)) { - aura::client::GetActivationChangeObserver(old_active)->OnWindowActivated( - window, old_active); - } - if (aura::client::GetActivationChangeObserver(window)) { - aura::client::GetActivationChangeObserver(window)->OnWindowActivated( - window, old_active); - } -} - -aura::Window* ActivationController::ActivateNextWindow(aura::Window* window) { - aura::Window* next_window = NULL; - if (wm::IsActiveWindow(window)) { - next_window = GetTopmostWindowToActivate(window); - ActivateWindow(next_window); - } - return next_window; -} - -aura::Window* ActivationController::GetTopmostWindowToActivate( - aura::Window* ignore) const { - size_t current_container_index = 0; - // If the container of the window losing focus is in the list, start from that - // container. - aura::RootWindow* root = ignore->GetRootWindow(); - if (!root) - root = Shell::GetActiveRootWindow(); - for (size_t i = 0; ignore && i < arraysize(kWindowContainerIds); i++) { - aura::Window* container = Shell::GetContainer(root, kWindowContainerIds[i]); - if (container && container->Contains(ignore)) { - current_container_index = i; - break; - } - } - - // Look for windows to focus in that container and below. - aura::Window* window = NULL; - for (; !window && current_container_index < arraysize(kWindowContainerIds); - current_container_index++) { - aura::Window::Windows containers = Shell::GetContainersFromAllRootWindows( - kWindowContainerIds[current_container_index], - root); - for (aura::Window::Windows::const_iterator iter = containers.begin(); - iter != containers.end() && !window; ++iter) { - window = GetTopmostWindowToActivateInContainer((*iter), ignore); - } - } - return window; -} - -aura::Window* ActivationController::GetTopmostWindowToActivateInContainer( - aura::Window* container, - aura::Window* ignore) const { - for (aura::Window::Windows::const_reverse_iterator i = - container->children().rbegin(); - i != container->children().rend(); - ++i) { - if (*i != ignore && - CanActivateWindowWithEvent(*i, NULL, CURRENT_VISIBILITY) && - !wm::IsWindowMinimized(*i)) - return *i; - } - return NULL; -} - -void ActivationController::FocusWindowWithEvent(const ui::Event* event) { - aura::Window* window = static_cast<aura::Window*>(event->target()); - window = delegate_->WillFocusWindow(window); - if (GetActiveWindow() != window) { - aura::client::GetFocusClient(window)->FocusWindow( - FindFocusableWindowFor(window)); - } -} - -} // namespace internal -} // namespace ash diff --git a/ash/wm/activation_controller.h b/ash/wm/activation_controller.h deleted file mode 100644 index 11e09b9..0000000 --- a/ash/wm/activation_controller.h +++ /dev/null @@ -1,126 +0,0 @@ -// 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. - -#ifndef ASH_WM_ACTIVATION_CONTROLLER_H_ -#define ASH_WM_ACTIVATION_CONTROLLER_H_ - -#include "ash/ash_export.h" -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/observer_list.h" -#include "base/scoped_observer.h" -#include "ui/aura/client/activation_client.h" -#include "ui/aura/client/focus_change_observer.h" -#include "ui/aura/env_observer.h" -#include "ui/aura/window_observer.h" -#include "ui/base/events/event_handler.h" - -namespace aura { -namespace client { -class ActivationChangeObserver; -class FocusClient; -} -} - -namespace ash { -namespace internal { - -class ActivationControllerDelegate; - -// Exported for unit tests. -class ASH_EXPORT ActivationController - : public aura::client::ActivationClient, - public aura::WindowObserver, - public aura::EnvObserver, - public aura::client::FocusChangeObserver, - public ui::EventHandler { - public: - // The ActivationController takes ownership of |delegate|. - ActivationController(aura::client::FocusClient* focus_client, - ActivationControllerDelegate* delegate); - virtual ~ActivationController(); - - // Returns true if |window| exists within a container that supports - // activation. |event| is the event responsible for initiating the change, or - // NULL if there is no event. - static aura::Window* GetActivatableWindow(aura::Window* window, - const ui::Event* event); - - // Overridden from aura::client::ActivationClient: - virtual void AddObserver( - aura::client::ActivationChangeObserver* observer) OVERRIDE; - virtual void RemoveObserver( - aura::client::ActivationChangeObserver* observer) OVERRIDE; - virtual void ActivateWindow(aura::Window* window) OVERRIDE; - virtual void DeactivateWindow(aura::Window* window) OVERRIDE; - virtual aura::Window* GetActiveWindow() OVERRIDE; - virtual aura::Window* GetActivatableWindow(aura::Window* window) OVERRIDE; - virtual aura::Window* GetToplevelWindow(aura::Window* window) OVERRIDE; - virtual bool OnWillFocusWindow(aura::Window* window, - const ui::Event* event) OVERRIDE; - virtual bool CanActivateWindow(aura::Window* window) const OVERRIDE; - - // Overridden from aura::WindowObserver: - virtual void OnWindowVisibilityChanged(aura::Window* window, - bool visible) OVERRIDE; - virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; - - // Overridden from aura::EnvObserver: - virtual void OnWindowInitialized(aura::Window* window) OVERRIDE; - - // Overridden from aura::client::FocusChangeObserver: - virtual void OnWindowFocused(aura::Window* gained_focus, - aura::Window* lost_focus) OVERRIDE; - - private: - // Overridden from ui::EventHandler: - virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; - virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; - virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; - virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; - virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; - - // Implementation of ActivateWindow() with an Event. - void ActivateWindowWithEvent(aura::Window* window, - const ui::Event* event); - - // Shifts activation to the next window, ignoring |window|. Returns the next - // window. - aura::Window* ActivateNextWindow(aura::Window* window); - - // Returns the next window that should be activated, ignoring |ignore|. - aura::Window* GetTopmostWindowToActivate(aura::Window* ignore) const; - - // Returns the next window that should be activated in |container| ignoring - // the window |ignore|. - aura::Window* GetTopmostWindowToActivateInContainer( - aura::Window* container, - aura::Window* ignore) const; - - // Called from the ActivationController's event handler implementation to - // handle focus to the |event|'s target. Not all targets are focusable or - // result in focus changes. - void FocusWindowWithEvent(const ui::Event* event); - - aura::client::FocusClient* focus_client_; - - // True inside ActivateWindow(). Used to prevent recursion of focus - // change notifications causing activation. - bool updating_activation_; - - aura::Window* active_window_; - - ObserverList<aura::client::ActivationChangeObserver> observers_; - - ScopedObserver<aura::Window, aura::WindowObserver> observer_manager_; - - scoped_ptr<ActivationControllerDelegate> delegate_; - - DISALLOW_COPY_AND_ASSIGN(ActivationController); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_WM_ACTIVATION_CONTROLLER_H_ diff --git a/ash/wm/activation_controller_delegate.h b/ash/wm/activation_controller_delegate.h deleted file mode 100644 index 5cebfc6..0000000 --- a/ash/wm/activation_controller_delegate.h +++ /dev/null @@ -1,37 +0,0 @@ -// 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. - -#ifndef ASH_WM_ACTIVATION_CONTROLLER_DELEGATE_H_ -#define ASH_WM_ACTIVATION_CONTROLLER_DELEGATE_H_ - -#include "ash/ash_export.h" - -namespace aura { -class Window; -} - -namespace ash { -namespace internal { - -class ASH_EXPORT ActivationControllerDelegate { - public: - virtual ~ActivationControllerDelegate() {} - - // Called when the ActivationController is about to activate |window|. The - // delegate gets an opportunity to take action and modify activation. - // Modification occurs via the return value: - // Returning |window| will activate |window|. - // Returning some other window will activate that window instead. - // Returning NULL will not change activation. - virtual aura::Window* WillActivateWindow(aura::Window* window) = 0; - - // Called when the ActivationController is about to focus |window|. Returns - // the window that should be focused instead. - virtual aura::Window* WillFocusWindow(aura::Window* window) = 0; -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_WM_ACTIVATION_CONTROLLER_DELEGATE_H_ diff --git a/ash/wm/activation_controller_unittest.cc b/ash/wm/activation_controller_unittest.cc deleted file mode 100644 index 74ad9b8..0000000 --- a/ash/wm/activation_controller_unittest.cc +++ /dev/null @@ -1,575 +0,0 @@ -// 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. - -#include "ash/wm/activation_controller.h" - -#include "ash/shell.h" -#include "ash/shell_window_ids.h" -#include "ash/test/ash_test_base.h" -#include "ash/test/test_activation_delegate.h" -#include "ash/wm/window_util.h" -#include "ui/aura/client/aura_constants.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/compositor/layer.h" -#include "ui/views/corewm/corewm_switches.h" - -#if defined(OS_WIN) -// Windows headers define macros for these function names which screw with us. -#if defined(CreateWindow) -#undef CreateWindow -#endif -#endif - -namespace { - -// Containers used for the tests. -const int kDefaultContainerID = -1; // Used to identify the default container. -const int c2 = ash::internal::kShellWindowId_AlwaysOnTopContainer; -const int c3 = ash::internal::kShellWindowId_LockScreenContainer; - -} // namespace - -namespace ash { -namespace test { - -typedef test::AshTestBase ActivationControllerTest; - -// Utilities for a set of tests that test -// ActivationController::GetTopmostWindowToActivate(). -class GetTopmostWindowToActivateTest : public ActivationControllerTest { - public: - GetTopmostWindowToActivateTest() : ad_1_(false), ad_3_(false) {} - virtual ~GetTopmostWindowToActivateTest() {} - - // Overridden from ActivationControllerTest: - virtual void SetUp() OVERRIDE { - ActivationControllerTest::SetUp(); - CreateWindows(); - } - virtual void TearDown() OVERRIDE { - DestroyWindows(); - ActivationControllerTest::TearDown(); - } - - protected: - aura::Window* w1() { return w1_.get(); } - aura::Window* w2() { return w2_.get(); } - aura::Window* w3() { return w3_.get(); } - aura::Window* w4() { return w4_.get(); } - aura::Window* w5() { return w5_.get(); } - aura::Window* w6() { return w6_.get(); } - aura::Window* w7() { return w7_.get(); } - - void DestroyWindow2() { - w2_.reset(); - } - - private: - void CreateWindows() { - // Create four windows, the first and third are not activatable, the second - // and fourth are. - w1_.reset(CreateWindowInShell(1, &ad_1_)); - w2_.reset(CreateWindowInShell(2, &ad_2_)); - w3_.reset(CreateWindowInShell(3, &ad_3_)); - w4_.reset(CreateWindowInShell(4, &ad_4_)); - w5_.reset(CreateWindowWithID(5, &ad_5_, c2)); - w6_.reset(CreateWindowWithID(6, &ad_6_, c2)); - w7_.reset(CreateWindowWithID(7, &ad_7_, c3)); - } - - aura::Window* CreateWindowInShell(int id, - TestActivationDelegate* delegate) { - aura::Window* window = CreateTestWindowInShellWithDelegate( - &delegate_, - id, - gfx::Rect()); - delegate->SetWindow(window); - return window; - } - - aura::Window* CreateWindowWithID(int id, - TestActivationDelegate* delegate, - int container_id) { - aura::Window* parent = - Shell::GetContainer(Shell::GetPrimaryRootWindow(), container_id); - aura::Window* window = aura::test::CreateTestWindowWithDelegate( - &delegate_, - id, - gfx::Rect(), - parent); - delegate->SetWindow(window); - return window; - } - - void DestroyWindows() { - w1_.reset(); - w2_.reset(); - w3_.reset(); - w4_.reset(); - w5_.reset(); - w6_.reset(); - w7_.reset(); - } - - aura::test::TestWindowDelegate delegate_; - TestActivationDelegate ad_1_; - TestActivationDelegate ad_2_; - TestActivationDelegate ad_3_; - TestActivationDelegate ad_4_; - TestActivationDelegate ad_5_; - TestActivationDelegate ad_6_; - TestActivationDelegate ad_7_; - scoped_ptr<aura::Window> w1_; // Non-activatable. - scoped_ptr<aura::Window> w2_; // Activatable. - scoped_ptr<aura::Window> w3_; // Non-activatable. - scoped_ptr<aura::Window> w4_; // Activatable. - scoped_ptr<aura::Window> w5_; // Activatable - Always on top. - scoped_ptr<aura::Window> w6_; // Activatable - Always on top. - scoped_ptr<aura::Window> w7_; // Activatable - Lock screen window. - - DISALLOW_COPY_AND_ASSIGN(GetTopmostWindowToActivateTest); -}; - -// Hiding the active window should activate the next valid activatable window. -TEST_F(GetTopmostWindowToActivateTest, HideActivatesNext) { - wm::ActivateWindow(w2()); - EXPECT_TRUE(wm::IsActiveWindow(w2())); - - w2()->Hide(); - EXPECT_TRUE(wm::IsActiveWindow(w4())); -} - -// Destroying the active window should activate the next valid activatable -// window. -TEST_F(GetTopmostWindowToActivateTest, DestroyActivatesNext) { - wm::ActivateWindow(w2()); - EXPECT_TRUE(wm::IsActiveWindow(w2())); - - DestroyWindow2(); - EXPECT_EQ(NULL, w2()); - EXPECT_TRUE(wm::IsActiveWindow(w4())); -} - -// Deactivating the active window should activate the next valid activatable -// window. -TEST_F(GetTopmostWindowToActivateTest, DeactivateActivatesNext) { - wm::ActivateWindow(w2()); - EXPECT_TRUE(wm::IsActiveWindow(w2())); - - wm::DeactivateWindow(w2()); - EXPECT_TRUE(wm::IsActiveWindow(w4())); -} - -// Test that hiding a window in a higher container will activate another window -// in that container. -TEST_F(GetTopmostWindowToActivateTest, HideActivatesSameContainer) { - wm::ActivateWindow(w6()); - EXPECT_TRUE(wm::IsActiveWindow(w6())); - - w6()->Hide(); - EXPECT_TRUE(wm::IsActiveWindow(w5())); -} - -// Test that hiding the lock window will activate a window from the next highest -// container. -TEST_F(GetTopmostWindowToActivateTest, UnlockActivatesNextHighestContainer) { - wm::ActivateWindow(w7()); - EXPECT_TRUE(wm::IsActiveWindow(w7())); - - w7()->Hide(); - EXPECT_TRUE(wm::IsActiveWindow(w6())); -} - -// Test that hiding a window in a higher container with no other windows will -// activate a window in a lower container. -TEST_F(GetTopmostWindowToActivateTest, HideActivatesNextHighestContainer) { - w5()->Hide(); - wm::ActivateWindow(w6()); - EXPECT_TRUE(wm::IsActiveWindow(w6())); - - w6()->Hide(); - EXPECT_TRUE(wm::IsActiveWindow(w4())); -} - -// Test if the clicking on a menu picks the transient parent as activatable -// window. -TEST_F(ActivationControllerTest, ClickOnMenu) { - aura::test::TestWindowDelegate wd; - TestActivationDelegate ad1; - TestActivationDelegate ad2(false); - - scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( - &wd, 1, gfx::Rect(100, 100))); - ad1.SetWindow(w1.get()); - EXPECT_EQ(NULL, wm::GetActiveWindow()); - - // Clicking on an activatable window activates the window. - aura::test::EventGenerator& generator(GetEventGenerator()); - generator.MoveMouseToCenterOf(w1.get()); - generator.ClickLeftButton(); - EXPECT_TRUE(wm::IsActiveWindow(w1.get())); - - // Creates a menu that covers the transient parent. - scoped_ptr<aura::Window> menu(CreateTestWindowInShellWithDelegateAndType( - &wd, aura::client::WINDOW_TYPE_MENU, 2, gfx::Rect(100, 100))); - ad2.SetWindow(menu.get()); - w1->AddTransientChild(menu.get()); - - // Clicking on a menu whose transient parent is active window shouldn't - // change the active window. - generator.ClickLeftButton(); - EXPECT_TRUE(wm::IsActiveWindow(w1.get())); -} - -// Various assertions for activating/deactivating. -TEST_F(ActivationControllerTest, Deactivate) { - aura::test::TestWindowDelegate d1; - aura::test::TestWindowDelegate d2; - scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( - &d1, 1, gfx::Rect())); - scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( - &d2, 2, gfx::Rect())); - aura::Window* parent = w1->parent(); - parent->Show(); - ASSERT_TRUE(parent); - ASSERT_EQ(2u, parent->children().size()); - // Activate w2 and make sure it's active and frontmost. - wm::ActivateWindow(w2.get()); - EXPECT_TRUE(wm::IsActiveWindow(w2.get())); - EXPECT_FALSE(wm::IsActiveWindow(w1.get())); - EXPECT_EQ(w2.get(), parent->children()[1]); - - // Activate w1 and make sure it's active and frontmost. - wm::ActivateWindow(w1.get()); - EXPECT_TRUE(wm::IsActiveWindow(w1.get())); - EXPECT_FALSE(wm::IsActiveWindow(w2.get())); - EXPECT_EQ(w1.get(), parent->children()[1]); - - // Deactivate w1 and make sure w2 becomes active and frontmost. - wm::DeactivateWindow(w1.get()); - EXPECT_FALSE(wm::IsActiveWindow(w1.get())); - EXPECT_TRUE(wm::IsActiveWindow(w2.get())); - EXPECT_EQ(w2.get(), parent->children()[1]); -} - -// Verifies that when WindowDelegate::OnLostActive is invoked the window is not -// active. -TEST_F(ActivationControllerTest, NotActiveInLostActive) { - // TODO(beng): remove this test once the new focus controller is on. - if (views::corewm::UseFocusController()) - return; - - TestActivationDelegate ad1; - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( - &wd, 1, gfx::Rect(10, 10, 50, 50))); - ad1.SetWindow(w1.get()); - scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( - NULL, 1, gfx::Rect(10, 10, 50, 50))); - - // Activate w1. - wm::ActivateWindow(w1.get()); - EXPECT_TRUE(wm::IsActiveWindow(w1.get())); - EXPECT_EQ(1, ad1.activated_count()); - // Should not have gotten a OnLostActive yet. - EXPECT_EQ(0, ad1.lost_active_count()); - - // Deactivate the active window. - wm::DeactivateWindow(w1.get()); - EXPECT_FALSE(wm::IsActiveWindow(w1.get())); - EXPECT_EQ(1, ad1.lost_active_count()); - EXPECT_FALSE(ad1.window_was_active()); - - // Activate w1 again. w1 should have gotten OnActivated. - wm::ActivateWindow(w1.get()); - EXPECT_EQ(2, ad1.activated_count()); - EXPECT_EQ(1, ad1.lost_active_count()); - - // Reset the delegate. - ad1.Clear(); - - // Now activate another window. - wm::ActivateWindow(w2.get()); - - // Should have gotten OnLostActive and w1 shoouldn't have been - // active window in OnLostActive. - EXPECT_EQ(0, ad1.activated_count()); - EXPECT_EQ(1, ad1.lost_active_count()); - EXPECT_FALSE(ad1.window_was_active()); -} - -// Verifies that focusing another window or its children causes it to become -// active. -TEST_F(ActivationControllerTest, FocusTriggersActivation) { - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( - &wd, -1, gfx::Rect(50, 50))); - scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( - &wd, -2, gfx::Rect(50, 50))); - scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( - &wd, -21, gfx::Rect(50, 50), w2.get())); - - wm::ActivateWindow(w1.get()); - EXPECT_TRUE(wm::IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); - - w2->Focus(); - EXPECT_TRUE(wm::IsActiveWindow(w2.get())); - EXPECT_TRUE(w2->HasFocus()); - - wm::ActivateWindow(w1.get()); - EXPECT_TRUE(wm::IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); - - w21->Focus(); - EXPECT_TRUE(wm::IsActiveWindow(w2.get())); - EXPECT_TRUE(w21->HasFocus()); -} - -// Verifies that we prevent all attempts to focus a child of a non-activatable -// window from claiming focus to that window. -TEST_F(ActivationControllerTest, PreventFocusToNonActivatableWindow) { - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( - &wd, -1, gfx::Rect(50, 50))); - // The RootWindow is a non-activatable parent. - scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( - &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow())); - scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( - &wd, -21, gfx::Rect(50, 50), w2.get())); - - wm::ActivateWindow(w1.get()); - EXPECT_TRUE(wm::IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); - - // Try activating |w2|. It's not a child of an activatable container, so it - // should neither be activated nor get focus. - wm::ActivateWindow(w2.get()); - EXPECT_FALSE(wm::IsActiveWindow(w2.get())); - EXPECT_FALSE(w2->HasFocus()); - EXPECT_TRUE(wm::IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); - - // Try focusing |w2|. Same rules apply. - w2->Focus(); - EXPECT_FALSE(wm::IsActiveWindow(w2.get())); - EXPECT_FALSE(w2->HasFocus()); - EXPECT_TRUE(wm::IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); - - // Try focusing |w21|. Same rules apply. - EXPECT_FALSE(wm::IsActiveWindow(w2.get())); - EXPECT_FALSE(w21->HasFocus()); - EXPECT_TRUE(wm::IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); -} - -TEST_F(ActivationControllerTest, CanActivateWindowIteselfTest) -{ - aura::test::TestWindowDelegate wd; - - // Normal Window - scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( - &wd, -1, gfx::Rect(50, 50))); - EXPECT_TRUE(wm::CanActivateWindow(w1.get())); - - // The RootWindow is a non-activatable parent. - scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( - &wd, -2, gfx::Rect(50, 50), Shell::GetPrimaryRootWindow())); - scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( - &wd, -21, gfx::Rect(50, 50), w2.get())); - EXPECT_FALSE(wm::CanActivateWindow(w2.get())); - EXPECT_FALSE(wm::CanActivateWindow(w21.get())); - - // The window has a transient child. - scoped_ptr<aura::Window> w3(CreateTestWindowInShellWithDelegate( - &wd, -3, gfx::Rect(50, 50))); - scoped_ptr<aura::Window> w31(CreateTestWindowInShellWithDelegate( - &wd, -31, gfx::Rect(50, 50))); - w3->AddTransientChild(w31.get()); - EXPECT_TRUE(wm::CanActivateWindow(w3.get())); - EXPECT_TRUE(wm::CanActivateWindow(w31.get())); - - // The window has a transient window-modal child. - scoped_ptr<aura::Window> w4(CreateTestWindowInShellWithDelegate( - &wd, -4, gfx::Rect(50, 50))); - scoped_ptr<aura::Window> w41(CreateTestWindowInShellWithDelegate( - &wd, -41, gfx::Rect(50, 50))); - w4->AddTransientChild(w41.get()); - w41->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); - EXPECT_FALSE(wm::CanActivateWindow(w4.get())); - EXPECT_TRUE(wm::CanActivateWindow(w41.get())); - - // The window has a transient system-modal child. - scoped_ptr<aura::Window> w5(CreateTestWindowInShellWithDelegate( - &wd, -5, gfx::Rect(50, 50))); - scoped_ptr<aura::Window> w51(CreateTestWindowInShellWithDelegate( - &wd, -51, gfx::Rect(50, 50))); - w5->AddTransientChild(w51.get()); - w51->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); - EXPECT_FALSE(wm::CanActivateWindow(w5.get())); - EXPECT_TRUE(wm::CanActivateWindow(w51.get())); -} - -// Verifies code in ActivationController::OnWindowVisibilityChanged() that keeps -// hiding windows layers stacked above the newly active window while they -// animate away. -// TODO(beng): This test now duplicates a test in: -// ui/views/corewm/focus_controller_unittest.cc -// ...and can be removed once the new focus controller is enabled. -TEST_F(ActivationControllerTest, AnimateHideMaintainsStacking) { - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( - &wd, -1, gfx::Rect(50, 50, 50, 50))); - scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( - &wd, -2, gfx::Rect(75, 75, 50, 50))); - wm::ActivateWindow(w2.get()); - EXPECT_TRUE(wm::IsActiveWindow(w2.get())); - w2->Hide(); - typedef std::vector<ui::Layer*> Layers; - const Layers& children = w1->parent()->layer()->children(); - Layers::const_iterator w1_iter = - std::find(children.begin(), children.end(), w1->layer()); - Layers::const_iterator w2_iter = - std::find(children.begin(), children.end(), w2->layer()); - EXPECT_TRUE(w2_iter > w1_iter); -} - -// Verifies that activating a minimized window would restore it. -TEST_F(ActivationControllerTest, ActivateMinimizedWindow) { - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( - &wd, -1, gfx::Rect(50, 50))); - - wm::MinimizeWindow(w1.get()); - EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); - - wm::ActivateWindow(w1.get()); - EXPECT_TRUE(wm::IsActiveWindow(w1.get())); - EXPECT_FALSE(wm::IsWindowMinimized(w1.get())); -} - -// Verifies that a minimized window would not be automatically activated as -// a replacement active window. -TEST_F(ActivationControllerTest, NoAutoActivateMinimizedWindow) { - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( - &wd, -1, gfx::Rect(50, 50, 50, 50))); - scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( - &wd, -2, gfx::Rect(75, 75, 50, 50))); - - wm::MinimizeWindow(w1.get()); - EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); - - wm::ActivateWindow(w2.get()); - EXPECT_TRUE(wm::IsActiveWindow(w2.get())); - - w2->Hide(); - - EXPECT_FALSE(wm::IsActiveWindow(w1.get())); - EXPECT_TRUE(wm::IsWindowMinimized(w1.get())); -} - -// Verifies that a window with a hidden layer can be activated. -TEST_F(ActivationControllerTest, ActivateWithHiddenLayer) { - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( - &wd, -1, gfx::Rect(50, 50, 50, 50))); - - EXPECT_TRUE(wm::CanActivateWindow(w1.get())); - w1->layer()->SetVisible(false); - EXPECT_TRUE(wm::CanActivateWindow(w1.get())); -} - -// Verifies that a unrelated window cannot be activated when in a system modal -// dialog. -TEST_F(ActivationControllerTest, DontActivateWindowWhenInSystemModalDialog) { - scoped_ptr<aura::Window> normal_window(CreateTestWindowInShellWithId(-1)); - EXPECT_FALSE(wm::IsActiveWindow(normal_window.get())); - wm::ActivateWindow(normal_window.get()); - EXPECT_TRUE(wm::IsActiveWindow(normal_window.get())); - - // Create and activate a system modal window. - aura::Window* modal_container = - ash::Shell::GetContainer( - Shell::GetPrimaryRootWindow(), - ash::internal::kShellWindowId_SystemModalContainer); - scoped_ptr<aura::Window> modal_window( - aura::test::CreateTestWindowWithId(-2, modal_container)); - modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); - wm::ActivateWindow(modal_window.get()); - EXPECT_TRUE(ash::Shell::GetInstance()->IsSystemModalWindowOpen()); - EXPECT_FALSE(wm::IsActiveWindow(normal_window.get())); - EXPECT_TRUE(wm::IsActiveWindow(modal_window.get())); - - // We try to but cannot activate the normal window while we - // have the system modal window. - wm::ActivateWindow(normal_window.get()); - EXPECT_TRUE(ash::Shell::GetInstance()->IsSystemModalWindowOpen()); - EXPECT_FALSE(wm::IsActiveWindow(normal_window.get())); - EXPECT_TRUE(wm::IsActiveWindow(modal_window.get())); - - modal_window->Hide(); - modal_window.reset(); - EXPECT_FALSE(ash::Shell::GetInstance()->IsSystemModalWindowOpen()); - EXPECT_TRUE(wm::IsActiveWindow(normal_window.get())); -} - -// Verifies that a lock window can get focus even if lock -// container is not visible (e.g. before animating it). -TEST_F(ActivationControllerTest, ActivateLockScreen) { - aura::Window* lock_container = - Shell::GetContainer(Shell::GetPrimaryRootWindow(), c3); - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( - &wd, -1, gfx::Rect(50, 50, 50, 50), lock_container)); - - lock_container->layer()->SetVisible(false); - w1->Focus(); - EXPECT_TRUE(w1->HasFocus()); -} - -// Verifies that a next active window is chosen from current -// active display. -TEST_F(ActivationControllerTest, NextActiveWindowOnMultipleDisplays) { - if (!SupportsMultipleDisplays()) - return; - - UpdateDisplay("300x300,300x300"); - Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); - - scoped_ptr<aura::Window> w1_d1(CreateTestWindowInShellWithBounds( - gfx::Rect(10, 10, 100, 100))); - scoped_ptr<aura::Window> w2_d1(CreateTestWindowInShellWithBounds( - gfx::Rect(20, 20, 100, 100))); - - EXPECT_EQ(root_windows[0], w1_d1->GetRootWindow()); - EXPECT_EQ(root_windows[0], w2_d1->GetRootWindow()); - - scoped_ptr<aura::Window> w3_d2(CreateTestWindowInShellWithBounds( - gfx::Rect(310, 10, 100, 100))); - scoped_ptr<aura::Window> w4_d2(CreateTestWindowInShellWithBounds( - gfx::Rect(320, 20, 100, 100))); - EXPECT_EQ(root_windows[1], w3_d2->GetRootWindow()); - EXPECT_EQ(root_windows[1], w4_d2->GetRootWindow()); - - aura::client::ActivationClient* client = - aura::client::GetActivationClient(root_windows[0]); - client->ActivateWindow(w1_d1.get()); - EXPECT_EQ(w1_d1.get(), client->GetActiveWindow()); - - w1_d1.reset(); - EXPECT_EQ(w2_d1.get(), client->GetActiveWindow()); - - client->ActivateWindow(w3_d2.get()); - EXPECT_EQ(w3_d2.get(), client->GetActiveWindow()); - w3_d2.reset(); - EXPECT_EQ(w4_d2.get(), client->GetActiveWindow()); -} - -} // namespace test -} // namespace ash diff --git a/ash/wm/ash_activation_controller.cc b/ash/wm/ash_activation_controller.cc deleted file mode 100644 index 146cf49..0000000 --- a/ash/wm/ash_activation_controller.cc +++ /dev/null @@ -1,96 +0,0 @@ -// 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. - -#include "ash/wm/ash_activation_controller.h" - -#include "ash/launcher/launcher.h" -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/shell_delegate.h" -#include "ash/wm/activation_controller.h" -#include "ash/wm/property_util.h" -#include "ash/wm/window_util.h" -#include "ash/wm/workspace_controller.h" -#include "ui/views/corewm/window_modality_controller.h" -#include "ui/views/widget/widget.h" - -namespace ash { -namespace internal { - -//////////////////////////////////////////////////////////////////////////////// -// AshActivationController, public: - -AshActivationController::AshActivationController() { -} - -AshActivationController::~AshActivationController() { -} - -//////////////////////////////////////////////////////////////////////////////// -// AshActivationController, ActivationControllerDelegate implementation: - -aura::Window* AshActivationController::WillActivateWindow( - aura::Window* window) { - aura::Window* window_modal_transient = - views::corewm::GetModalTransient(window); - if (window_modal_transient) - return window_modal_transient; - - // Fallback to launcher - if (!window) - window = PrepareToActivateLauncher(); - - // Restore minimized window. This needs to be done before CanReceiveEvents() - // is called as that function checks window visibility. - if (window && wm::IsWindowMinimized(window)) - window->Show(); - - // If the screen is locked, just bring the window to top so that - // it will be activated when the lock window is destroyed. - // TODO(beng): Call EventClient directly here, rather than conflating with - // window visibility. - if (window && !window->CanReceiveEvents()) - return NULL; - - // TODO(beng): could probably move to being a ActivationChangeObserver on - // Shell. - if (window) { - DCHECK(window->GetRootWindow()); - Shell::GetInstance()->set_active_root_window(window->GetRootWindow()); - } - return window; -} - -aura::Window* AshActivationController::WillFocusWindow( - aura::Window* window) { - aura::Window* window_modal_transient = - views::corewm::GetModalTransient(window); - if (window_modal_transient) - return window_modal_transient; - return window; -} - -aura::Window* AshActivationController::PrepareToActivateLauncher() { - // If workspace controller is not available, then it means that the root - // window is being destroyed. We can't activate any window then. - if (!GetRootWindowController( - Shell::GetActiveRootWindow())->workspace_controller()) { - return NULL; - } - // Fallback to a launcher only when Spoken feedback is enabled. - if (!Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled()) - return NULL; - ShelfWidget* shelf = GetRootWindowController( - Shell::GetActiveRootWindow())->shelf(); - // Launcher's window may be already destroyed in shutting down process. - if (!shelf) - return NULL; - // Notify launcher to allow activation via CanActivate(). - shelf->WillActivateAsFallback(); - return shelf->GetNativeWindow(); -} - -} // namespace internal -} // namespace ash diff --git a/ash/wm/ash_activation_controller.h b/ash/wm/ash_activation_controller.h deleted file mode 100644 index c3961f9..0000000 --- a/ash/wm/ash_activation_controller.h +++ /dev/null @@ -1,37 +0,0 @@ -// 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. - -#ifndef ASH_WM_ASH_ACTIVATION_CONTROLLER_H_ -#define ASH_WM_ASH_ACTIVATION_CONTROLLER_H_ - -#include "ash/ash_export.h" -#include "ash/wm/activation_controller_delegate.h" -#include "base/compiler_specific.h" -#include "base/basictypes.h" - -namespace ash { -namespace internal { - -class ASH_EXPORT AshActivationController : public ActivationControllerDelegate { - public: - AshActivationController(); - virtual ~AshActivationController(); - - private: - // Overridden from ActivationControllerDelegate: - virtual aura::Window* WillActivateWindow(aura::Window* window) OVERRIDE; - virtual aura::Window* WillFocusWindow(aura::Window* window) OVERRIDE; - - // Returns a handle to the launcher on the active root window which will - // be activated as fallback. Also notifies the launcher, so it can return - // true from Launcher::CanActivate(). - aura::Window* PrepareToActivateLauncher(); - - DISALLOW_COPY_AND_ASSIGN(AshActivationController); -}; - -} // namespace internal -} // namespace ash - -#endif // ASH_WM_ASH_ACTIVATION_CONTROLLER_H_ diff --git a/ash/wm/ash_activation_controller_unittest.cc b/ash/wm/ash_activation_controller_unittest.cc deleted file mode 100644 index e332990..0000000 --- a/ash/wm/ash_activation_controller_unittest.cc +++ /dev/null @@ -1,168 +0,0 @@ -// 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. - -#include "ash/wm/ash_activation_controller.h" - -#include "ash/launcher/launcher.h" -#include "ash/root_window_controller.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell_delegate.h" -#include "ash/test/ash_test_base.h" -#include "ash/wm/property_util.h" -#include "ash/wm/window_util.h" -#include "ui/aura/window.h" -#include "ui/views/corewm/corewm_switches.h" - -namespace ash { - -namespace wm { - -namespace { - -class AshActivationControllerTest : public test::AshTestBase { - public: - AshActivationControllerTest() - : launcher_(NULL), launcher_widget_(NULL), launcher_window_(NULL) {} - virtual ~AshActivationControllerTest() {} - - virtual void SetUp() OVERRIDE { - test::AshTestBase::SetUp(); - ash_activation_controller_.reset(new internal::AshActivationController()); - launcher_ = Launcher::ForPrimaryDisplay(); - ASSERT_TRUE(launcher_); - launcher_widget_ = launcher_->shelf_widget(); - ASSERT_TRUE(launcher_widget_); - launcher_window_ = launcher_widget_->GetNativeWindow(); - ASSERT_TRUE(launcher_window_); - } - - void SetSpokenFeedbackState(bool enabled) { - if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled() != - enabled) { - Shell::GetInstance()->delegate()->ToggleSpokenFeedback( - A11Y_NOTIFICATION_NONE); - } - } - - protected: - scoped_ptr<internal::ActivationControllerDelegate> ash_activation_controller_; - ash::Launcher* launcher_; - views::Widget* launcher_widget_; - aura::Window* launcher_window_; - - DISALLOW_COPY_AND_ASSIGN(AshActivationControllerTest); -}; - -TEST_F(AshActivationControllerTest, LauncherFallback) { - // When spoken feedback is disabled, then fallback should not occur. - { - SetSpokenFeedbackState(false); - aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL); - EXPECT_EQ(NULL, result); - } - - // When spoken feedback is enabled, then fallback should occur. - { - SetSpokenFeedbackState(true); - aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL); - EXPECT_EQ(launcher_window_, result); - } - - // No fallback when activating another window. - { - aura::Window* test_window = CreateTestWindowInShellWithId(0); - aura::Window* result = ash_activation_controller_-> - WillActivateWindow(test_window); - EXPECT_EQ(test_window, result); - } -} - -TEST_F(AshActivationControllerTest, LauncherFallbackOnShutdown) { - SetSpokenFeedbackState(true); - // While shutting down a root window controller, activation controller - // is notified about destroyed windows and therefore will try to activate - // a launcher as fallback, which would result in segmentation faults since - // the launcher's window or the workspace's controller may be already - // destroyed. - GetRootWindowController(Shell::GetActiveRootWindow())->CloseChildWindows(); - - aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL); - EXPECT_EQ(NULL, result); -} - -TEST_F(AshActivationControllerTest, LauncherEndToEndFallbackOnDestroyTest) { - // TODO(mtomasz): make this test work with the FocusController. - if (views::corewm::UseFocusController()) - return; - - // This test checks the whole fallback activation flow. - SetSpokenFeedbackState(true); - - scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0)); - ActivateWindow(test_window.get()); - ASSERT_EQ(test_window.get(), GetActiveWindow()); - - // Close the window. - test_window.reset(); - - // Verify if the launcher got activated as fallback. - ASSERT_EQ(launcher_window_, GetActiveWindow()); -} - -TEST_F(AshActivationControllerTest, LauncherEndToEndFallbackOnMinimizeTest) { - // TODO(mtomasz): make this test work with the FocusController. - if (views::corewm::UseFocusController()) - return; - - // This test checks the whole fallback activation flow. - SetSpokenFeedbackState(true); - - scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0)); - ActivateWindow(test_window.get()); - ASSERT_EQ(test_window.get(), GetActiveWindow()); - - // Minimize the window. - MinimizeWindow(test_window.get()); - - // Verify if the launcher got activated as fallback. - ASSERT_EQ(launcher_window_, GetActiveWindow()); -} - -TEST_F(AshActivationControllerTest, LauncherEndToEndNoFallbackOnDestroyTest) { - // This test checks the whole fallback activation flow when spoken feedback - // is disabled. - SetSpokenFeedbackState(false); - - scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0)); - ActivateWindow(test_window.get()); - ASSERT_EQ(test_window.get(), GetActiveWindow()); - - // Close the window. - test_window.reset(); - - // Verify if the launcher didn't get activated as fallback. - ASSERT_NE(launcher_window_, GetActiveWindow()); -} - -TEST_F(AshActivationControllerTest, LauncherEndToEndNoFallbackOnMinimizeTest) { - // This test checks the whole fallback activation flow when spoken feedback - // is disabled. - SetSpokenFeedbackState(false); - - scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0)); - ActivateWindow(test_window.get()); - ASSERT_EQ(test_window.get(), GetActiveWindow()); - - // Minimize the window. - MinimizeWindow(test_window.get()); - - // Verify if the launcher didn't get activated as fallback. - ASSERT_NE(launcher_window_, GetActiveWindow()); -} - -} // namespace - -} // namespace wm - -} // namespace ash diff --git a/ash/wm/base_layout_manager.cc b/ash/wm/base_layout_manager.cc index 6842f3e..f22b07e 100644 --- a/ash/wm/base_layout_manager.cc +++ b/ash/wm/base_layout_manager.cc @@ -154,12 +154,10 @@ void BaseLayoutManager::OnWindowBoundsChanged(aura::Window* window, void BaseLayoutManager::OnWindowActivated(aura::Window* gained_active, aura::Window* lost_active) { - if (views::corewm::UseFocusController()) { - if (gained_active && wm::IsWindowMinimized(gained_active) && - !gained_active->IsVisible()) { - gained_active->Show(); - DCHECK(!wm::IsWindowMinimized(gained_active)); - } + if (gained_active && wm::IsWindowMinimized(gained_active) && + !gained_active->IsVisible()) { + gained_active->Show(); + DCHECK(!wm::IsWindowMinimized(gained_active)); } } diff --git a/ash/wm/mru_window_tracker.cc b/ash/wm/mru_window_tracker.cc index a1b1b13..8c90efb 100644 --- a/ash/wm/mru_window_tracker.cc +++ b/ash/wm/mru_window_tracker.cc @@ -9,10 +9,10 @@ #include "ash/session_state_delegate.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" -#include "ash/wm/activation_controller.h" #include "ash/wm/window_cycle_list.h" #include "ash/wm/window_util.h" #include "ash/wm/workspace_controller.h" +#include "ui/aura/client/activation_client.h" #include "ui/aura/root_window.h" #include "ui/base/events/event.h" #include "ui/base/events/event_handler.h" diff --git a/ash/wm/overview/window_selector.cc b/ash/wm/overview/window_selector.cc index a39c145..847740c 100644 --- a/ash/wm/overview/window_selector.cc +++ b/ash/wm/overview/window_selector.cc @@ -7,13 +7,13 @@ #include <algorithm> #include "ash/shell.h" -#include "ash/wm/activation_controller.h" #include "ash/wm/mru_window_tracker.h" #include "ash/wm/overview/window_overview.h" #include "ash/wm/overview/window_selector_delegate.h" #include "ash/wm/overview/window_selector_window.h" #include "base/auto_reset.h" #include "base/timer/timer.h" +#include "ui/aura/client/activation_client.h" #include "ui/aura/client/focus_client.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" diff --git a/ash/wm/panels/panel_layout_manager_unittest.cc b/ash/wm/panels/panel_layout_manager_unittest.cc index 08f53f7..0670b44 100644 --- a/ash/wm/panels/panel_layout_manager_unittest.cc +++ b/ash/wm/panels/panel_layout_manager_unittest.cc @@ -446,8 +446,7 @@ TEST_F(PanelLayoutManagerTest, MultiplePanelCallout) { wm::ActivateWindow(w3.get()); EXPECT_NO_FATAL_FAILURE(IsCalloutAboveLauncherIcon(w3.get())); w3.reset(); - if (views::corewm::UseFocusController()) - EXPECT_NO_FATAL_FAILURE(IsCalloutAboveLauncherIcon(w2.get())); + EXPECT_NO_FATAL_FAILURE(IsCalloutAboveLauncherIcon(w2.get())); } // Tests removing panels. diff --git a/ash/wm/window_manager_unittest.cc b/ash/wm/window_manager_unittest.cc index 936b29a..9351cc76 100644 --- a/ash/wm/window_manager_unittest.cc +++ b/ash/wm/window_manager_unittest.cc @@ -7,7 +7,6 @@ #include "ash/test/ash_test_base.h" #include "ash/test/shell_test_api.h" #include "ash/test/test_activation_delegate.h" -#include "ash/wm/activation_controller.h" #include "ash/wm/window_util.h" #include "ui/aura/client/activation_client.h" #include "ui/aura/client/activation_delegate.h" @@ -319,8 +318,7 @@ TEST_F(WindowManagerTest, ActivateOnMouse) { d1.set_activate(true); w2.reset(); EXPECT_EQ(0, d2.activated_count()); - EXPECT_EQ(views::corewm::UseFocusController() ? 1 : 0, - d2.lost_active_count()); + EXPECT_EQ(1, d2.lost_active_count()); EXPECT_TRUE(wm::IsActiveWindow(w1.get())); EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); EXPECT_EQ(1, d1.activated_count()); @@ -473,8 +471,7 @@ TEST_F(WindowManagerTest, ActivateOnTouch) { d1.set_activate(true); w2.reset(); EXPECT_EQ(0, d2.activated_count()); - EXPECT_EQ(views::corewm::UseFocusController() ? 1 : 0, - d2.lost_active_count()); + EXPECT_EQ(1, d2.lost_active_count()); EXPECT_TRUE(wm::IsActiveWindow(w1.get())); EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); EXPECT_EQ(1, d1.activated_count()); diff --git a/ash/wm/window_util.cc b/ash/wm/window_util.cc index c3101c7..ca205e9 100644 --- a/ash/wm/window_util.cc +++ b/ash/wm/window_util.cc @@ -10,7 +10,6 @@ #include "ash/root_window_controller.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" -#include "ash/wm/activation_controller.h" #include "ash/wm/window_properties.h" #include "ui/aura/client/activation_client.h" #include "ui/aura/client/aura_constants.h" diff --git a/ash/wm/workspace_controller_unittest.cc b/ash/wm/workspace_controller_unittest.cc index 0410bf0..4327225 100644 --- a/ash/wm/workspace_controller_unittest.cc +++ b/ash/wm/workspace_controller_unittest.cc @@ -16,7 +16,6 @@ #include "ash/system/status_area_widget.h" #include "ash/test/ash_test_base.h" #include "ash/test/shell_test_api.h" -#include "ash/wm/activation_controller.h" #include "ash/wm/property_util.h" #include "ash/wm/window_properties.h" #include "ash/wm/window_util.h" @@ -138,8 +137,6 @@ class WorkspaceControllerTest : public test::AshTestBase { } private: - scoped_ptr<ActivationController> activation_controller_; - DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTest); }; |