Skip to content

Commit

Permalink
Moves management of transients out of Window
Browse files Browse the repository at this point in the history
And into TransientWindowManager. Additionally moves handling of NULL
layer stacking into TransientStackingWindowClient. The tests that were
exercising these code paths have all been moved to ui/views/corewm.

Also wires up TransientStackingWindowClient in a couple of places that
didn't have it.

The order of removing from transient parent as well as destroying of
transient children is slightly differently than before. To get the
order exactly as it was would require some new specific observer
functions. I'm hoping we don't need those. Hopefully this doesn't
cause issues, if it does I'll revisit.

I ended up exposing convenience functions. That's because typing
something like:

views::corewm::TransientWindowManager::Get(window)->AddTransientChild()

was too much for me. There is also some subtlety in so far as the
Get() function that takes a const Window* may return NULL, where as
non-const never returns NULL.

Lastly I had to make Window friend TransientWindowManager. This is
temporary until I create a specific TransientWindowManagerObserver
that contains the two transient related observer functions in
WindowObserver.

BUG=none
TEST=none
[email protected]

Review URL: https://codereview.chromium.org/115453004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243368 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
[email protected] committed Jan 7, 2014
1 parent 691b200 commit 751b13d
Show file tree
Hide file tree
Showing 57 changed files with 1,356 additions and 677 deletions.
6 changes: 4 additions & 2 deletions ash/display/screen_position_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ui/compositor/dip_util.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
#include "ui/views/corewm/window_util.h"

namespace ash {
namespace {
Expand All @@ -37,7 +38,8 @@ void MoveAllTransientChildrenToNewRoot(const gfx::Display& display,
aura::Window* window) {
aura::Window* dst_root = Shell::GetInstance()->display_controller()->
GetRootWindowForDisplayId(display.id());
aura::Window::Windows transient_children = window->transient_children();
aura::Window::Windows transient_children =
views::corewm::GetTransientChildren(window);
for (aura::Window::Windows::iterator iter = transient_children.begin();
iter != transient_children.end(); ++iter) {
aura::Window* transient_child = *iter;
Expand Down Expand Up @@ -162,7 +164,7 @@ void ScreenPositionController::SetBounds(aura::Window* window,
// b) if the window or its ancestor has kStayInSameRootWindowkey. It's
// intentionally kept in the same root window even if the bounds is
// outside of the display.
if (!window->transient_parent() &&
if (!views::corewm::GetTransientParent(window) &&
!ShouldStayInSameRootWindow(window)) {
aura::Window* dst_root =
Shell::GetInstance()->display_controller()->GetRootWindowForDisplayId(
Expand Down
3 changes: 2 additions & 1 deletion ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/corewm/capture_controller.h"
#include "ui/views/corewm/visibility_controller.h"
#include "ui/views/corewm/window_util.h"
#include "ui/views/view_model.h"
#include "ui/views/view_model_utils.h"
#include "ui/wm/public/easy_resize_window_targeter.h"
Expand Down Expand Up @@ -589,7 +590,7 @@ const aura::Window* RootWindowController::GetWindowForFullscreenMode() const {
while (topmost_window) {
if (wm::GetWindowState(topmost_window)->IsFullscreen())
return topmost_window;
topmost_window = topmost_window->transient_parent();
topmost_window = views::corewm::GetTransientParent(topmost_window);
}
return NULL;
}
Expand Down
3 changes: 2 additions & 1 deletion ash/wm/dock/docked_window_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/rect.h"
#include "ui/views/background.h"
#include "ui/views/corewm/window_util.h"

namespace ash {
namespace internal {
Expand Down Expand Up @@ -189,7 +190,7 @@ namespace {
// Returns true if a window is a popup or a transient child.
bool IsPopupOrTransient(const aura::Window* window) {
return (window->type() == ui::wm::WINDOW_TYPE_POPUP ||
window->transient_parent());
views::corewm::GetTransientParent(window));
}

// Certain windows (minimized, hidden or popups) do not matter to docking.
Expand Down
11 changes: 6 additions & 5 deletions ash/wm/dock/docked_window_resizer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "ui/aura/test/test_window_delegate.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_types.h"
#include "ui/views/corewm/window_util.h"
#include "ui/views/widget/widget.h"

namespace ash {
Expand Down Expand Up @@ -1295,10 +1296,10 @@ TEST_P(DockedWindowResizerTest, DragWindowWithTransientChild) {
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
scoped_ptr<aura::Window> child(CreateTestWindowInShellWithDelegateAndType(
NULL, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20)));
window->AddTransientChild(child.get());
views::corewm::AddTransientChild(window.get(), child.get());
if (window->parent() != child->parent())
window->parent()->AddChild(child.get());
EXPECT_EQ(window.get(), child->transient_parent());
EXPECT_EQ(window.get(), views::corewm::GetTransientParent(child.get()));

DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20);

Expand Down Expand Up @@ -1345,8 +1346,8 @@ TEST_P(DockedWindowResizerTest, DragWindowWithModalTransientChild) {
// While still dragging create a modal window and make it a transient child of
// the |window|.
scoped_ptr<aura::Window> child(CreateModalWindow(gfx::Rect(20, 20, 150, 20)));
window->AddTransientChild(child.get());
EXPECT_EQ(window.get(), child->transient_parent());
views::corewm::AddTransientChild(window.get(), child.get());
EXPECT_EQ(window.get(), views::corewm::GetTransientParent(child.get()));
EXPECT_EQ(internal::kShellWindowId_SystemModalContainer,
child->parent()->id());

Expand All @@ -1366,7 +1367,7 @@ TEST_P(DockedWindowResizerTest, DragWindowWithModalTransientChild) {
EXPECT_EQ(gfx::Point(20, 20).ToString(),
child->GetBoundsInScreen().origin().ToString());
// The |child| should still be a transient child of |window|.
EXPECT_EQ(window.get(), child->transient_parent());
EXPECT_EQ(window.get(), views::corewm::GetTransientParent(child.get()));
}

// Tests that side snapping a window undocks it, closes the dock and then snaps.
Expand Down
9 changes: 5 additions & 4 deletions ash/wm/drag_window_resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/screen.h"
#include "ui/views/corewm/window_util.h"

namespace ash {
namespace internal {
Expand Down Expand Up @@ -232,9 +233,9 @@ void DragWindowResizer::UpdateDragWindow(const gfx::Rect& bounds,

bool DragWindowResizer::ShouldAllowMouseWarp() {
return (details_.window_component == HTCAPTION) &&
!GetTarget()->transient_parent() &&
(GetTarget()->type() == ui::wm::WINDOW_TYPE_NORMAL ||
GetTarget()->type() == ui::wm::WINDOW_TYPE_PANEL);
!views::corewm::GetTransientParent(GetTarget()) &&
(GetTarget()->type() == ui::wm::WINDOW_TYPE_NORMAL ||
GetTarget()->type() == ui::wm::WINDOW_TYPE_PANEL);
}

TrayUser* DragWindowResizer::GetTrayUserItemAtPoint(
Expand All @@ -245,7 +246,7 @@ TrayUser* DragWindowResizer::GetTrayUserItemAtPoint(

// Check that this is a drag move operation from a suitable window.
if (details_.window_component != HTCAPTION ||
GetTarget()->transient_parent() ||
views::corewm::GetTransientParent(GetTarget()) ||
(GetTarget()->type() != ui::wm::WINDOW_TYPE_NORMAL &&
GetTarget()->type() != ui::wm::WINDOW_TYPE_PANEL &&
GetTarget()->type() != ui::wm::WINDOW_TYPE_POPUP))
Expand Down
3 changes: 2 additions & 1 deletion ash/wm/drag_window_resizer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ui/base/ui_base_types.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/screen.h"
#include "ui/views/corewm/window_util.h"
#include "ui/views/widget/widget.h"

#if defined(OS_CHROMEOS)
Expand Down Expand Up @@ -84,7 +85,7 @@ class DragWindowResizerTest : public test::AshTestBase {
transient_parent_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
transient_parent_->Init(ui::LAYER_NOT_DRAWN);
ParentWindowInPrimaryRootWindow(transient_parent_.get());
transient_parent_->AddTransientChild(transient_child_);
views::corewm::AddTransientChild(transient_parent_.get(), transient_child_);
transient_parent_->set_id(5);

panel_window_.reset(new aura::Window(&delegate6_));
Expand Down
10 changes: 6 additions & 4 deletions ash/wm/immersive_fullscreen_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/corewm/window_util.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"

Expand Down Expand Up @@ -88,7 +89,7 @@ bool IsWindowTransientChildOf(aura::Window* maybe_transient,
return false;

for (aura::Window* window = maybe_transient; window;
window = window->transient_parent()) {
window = views::corewm::GetTransientParent(window)) {
if (window == toplevel)
return true;
}
Expand Down Expand Up @@ -472,8 +473,9 @@ void ImmersiveFullscreenController::AnimationProgressed(
////////////////////////////////////////////////////////////////////////////////
// aura::WindowObserver overrides:

void ImmersiveFullscreenController::OnAddTransientChild(aura::Window* window,
aura::Window* transient) {
void ImmersiveFullscreenController::OnAddTransientChild(
aura::Window* window,
aura::Window* transient) {
views::BubbleDelegateView* bubble_delegate = AsBubbleDelegate(transient);
if (bubble_delegate &&
bubble_delegate->GetAnchorView() &&
Expand Down Expand Up @@ -915,7 +917,7 @@ bool ImmersiveFullscreenController::ShouldHandleGestureEvent(
void ImmersiveFullscreenController::RecreateBubbleManager() {
bubble_manager_.reset(new BubbleManager(this));
const std::vector<aura::Window*> transient_children =
native_window_->transient_children();
views::corewm::GetTransientChildren(native_window_);
for (size_t i = 0; i < transient_children.size(); ++i) {
aura::Window* transient_child = transient_children[i];
views::BubbleDelegateView* bubble_delegate =
Expand Down
5 changes: 4 additions & 1 deletion ash/wm/mru_window_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ void MruWindowTracker::OnWindowActivated(aura::Window* gained_active,
SetActiveWindow(gained_active);
}

void MruWindowTracker::OnWindowDestroying(aura::Window* window) {
void MruWindowTracker::OnWindowDestroyed(aura::Window* window) {
// It's possible for OnWindowActivated() to be called after
// OnWindowDestroying(). This means we need to override OnWindowDestroyed()
// else we may end up with a deleted window in |mru_windows_|.
mru_windows_.remove(window);
window->RemoveObserver(this);
}
Expand Down
2 changes: 1 addition & 1 deletion ash/wm/mru_window_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ASH_EXPORT MruWindowTracker
aura::Window* lost_active) OVERRIDE;

// Overridden from WindowObserver:
virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;

// List of windows that have been activated in containers that we cycle
// through, sorted by most recently used.
Expand Down
10 changes: 6 additions & 4 deletions ash/wm/overview/scoped_transform_overview_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/animation/tween.h"
#include "ui/views/corewm/window_animations.h"
#include "ui/views/corewm/window_util.h"
#include "ui/views/widget/widget.h"

namespace ash {
Expand Down Expand Up @@ -63,7 +64,8 @@ void SetTransformOnWindowAndAllTransientChildren(
bool animate) {
SetTransformOnWindow(window, transform, animate);

aura::Window::Windows transient_children = window->transient_children();
aura::Window::Windows transient_children =
views::corewm::GetTransientChildren(window);
for (aura::Window::Windows::iterator iter = transient_children.begin();
iter != transient_children.end(); ++iter) {
aura::Window* transient_child = *iter;
Expand All @@ -78,7 +80,7 @@ void SetTransformOnWindowAndAllTransientChildren(

aura::Window* GetModalTransientParent(aura::Window* window) {
if (window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_WINDOW)
return window->transient_parent();
return views::corewm::GetTransientParent(window);
return NULL;
}

Expand Down Expand Up @@ -237,8 +239,8 @@ void ScopedTransformOverviewWindow::SetTransformOnWindowAndTransientChildren(
bool animate) {
gfx::Point origin(GetBoundsInScreen().origin());
aura::Window* window = window_;
while (window->transient_parent())
window = window->transient_parent();
while (views::corewm::GetTransientParent(window))
window = views::corewm::GetTransientParent(window);
for (ScopedVector<ScopedWindowCopy>::const_iterator iter =
window_copies_.begin(); iter != window_copies_.end(); ++iter) {
SetTransformOnWindow(
Expand Down
3 changes: 2 additions & 1 deletion ash/wm/overview/window_selector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ui/aura/window_observer.h"
#include "ui/events/event.h"
#include "ui/events/event_handler.h"
#include "ui/views/corewm/window_util.h"

namespace ash {

Expand Down Expand Up @@ -400,7 +401,7 @@ void WindowSelector::OnWindowAdded(aura::Window* new_window) {

for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) {
if (new_window->parent()->id() == kSwitchableWindowContainerIds[i] &&
!new_window->transient_parent()) {
!views::corewm::GetTransientParent(new_window)) {
// The new window is in one of the switchable containers, abort overview.
CancelSelection();
return;
Expand Down
7 changes: 4 additions & 3 deletions ash/wm/overview/window_selector_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/transform.h"
#include "ui/views/corewm/window_util.h"

namespace ash {
namespace internal {
Expand Down Expand Up @@ -692,7 +693,7 @@ TEST_F(WindowSelectorTest, ModalChild) {
scoped_ptr<aura::Window> window1(CreateWindow(bounds));
scoped_ptr<aura::Window> child1(CreateWindow(bounds));
child1->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
window1->AddTransientChild(child1.get());
views::corewm::AddTransientChild(window1.get(), child1.get());
EXPECT_EQ(window1->parent(), child1->parent());
ToggleOverview();
EXPECT_TRUE(window1->IsVisible());
Expand All @@ -708,7 +709,7 @@ TEST_F(WindowSelectorTest, ClickModalWindowParent) {
scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(0, 0, 180, 180)));
scoped_ptr<aura::Window> child1(CreateWindow(gfx::Rect(200, 0, 180, 180)));
child1->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
window1->AddTransientChild(child1.get());
views::corewm::AddTransientChild(window1.get(), child1.get());
EXPECT_FALSE(WindowsOverlapping(window1.get(), child1.get()));
EXPECT_EQ(window1->parent(), child1->parent());
ToggleOverview();
Expand Down Expand Up @@ -829,7 +830,7 @@ TEST_F(WindowSelectorTest, CycleMultipleDisplaysCopiesWindows) {
unmoved2->SetName("unmoved2");
moved1->SetName("moved1");
moved1->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
moved1_trans_parent->AddTransientChild(moved1.get());
views::corewm::AddTransientChild(moved1_trans_parent.get(), moved1.get());
moved1_trans_parent->SetName("moved1_trans_parent");

EXPECT_EQ(root_windows[0], moved1->GetRootWindow());
Expand Down
5 changes: 3 additions & 2 deletions ash/wm/panels/panel_window_resizer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ui/base/hit_test.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_types.h"
#include "ui/views/corewm/window_util.h"
#include "ui/views/widget/widget.h"

namespace ash {
Expand Down Expand Up @@ -470,10 +471,10 @@ TEST_P(PanelWindowResizerTransientTest, PanelWithTransientChild) {
scoped_ptr<aura::Window> window(CreatePanelWindow(gfx::Point(0, 0)));
scoped_ptr<aura::Window> child(CreateTestWindowInShellWithDelegateAndType(
NULL, transient_window_type_, 0, gfx::Rect(20, 20, 150, 40)));
window->AddTransientChild(child.get());
views::corewm::AddTransientChild(window.get(), child.get());
if (window->parent() != child->parent())
window->parent()->AddChild(child.get());
EXPECT_EQ(window.get(), child->transient_parent());
EXPECT_EQ(window.get(), views::corewm::GetTransientParent(child.get()));

// Drag the child to the shelf. Its new position should not be overridden.
const gfx::Rect attached_bounds(window->GetBoundsInScreen());
Expand Down
20 changes: 12 additions & 8 deletions ash/wm/stacking_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/base/ui_base_types.h"
#include "ui/views/corewm/window_util.h"

namespace ash {
namespace {
Expand All @@ -37,9 +38,10 @@ bool IsSystemModal(aura::Window* window) {
return window->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM;
}

bool HasTransientParentWindow(aura::Window* window) {
return window->transient_parent() &&
window->transient_parent()->type() != ui::wm::WINDOW_TYPE_UNKNOWN;
bool HasTransientParentWindow(const aura::Window* window) {
return views::corewm::GetTransientParent(window) &&
views::corewm::GetTransientParent(window)->type() !=
ui::wm::WINDOW_TYPE_UNKNOWN;
}

internal::AlwaysOnTopController*
Expand All @@ -66,9 +68,10 @@ aura::Window* StackingController::GetDefaultParent(aura::Window* context,
aura::Window* window,
const gfx::Rect& bounds) {
aura::Window* target_root = NULL;
if (window->transient_parent()) {
aura::Window* transient_parent = views::corewm::GetTransientParent(window);
if (transient_parent) {
// Transient window should use the same root as its transient parent.
target_root = window->transient_parent()->GetRootWindow();
target_root = transient_parent->GetRootWindow();
} else {
target_root = FindContainerRoot(bounds);
}
Expand All @@ -80,7 +83,7 @@ aura::Window* StackingController::GetDefaultParent(aura::Window* context,
return GetSystemModalContainer(target_root, window);
else if (HasTransientParentWindow(window))
return internal::RootWindowController::GetContainerForWindow(
window->transient_parent());
views::corewm::GetTransientParent(window));
return GetAlwaysOnTopController(target_root)->GetContainer(window);
case ui::wm::WINDOW_TYPE_CONTROL:
return GetContainerById(
Expand Down Expand Up @@ -120,14 +123,15 @@ aura::Window* StackingController::GetSystemModalContainer(
SessionStateDelegate* session_state_delegate =
Shell::GetInstance()->session_state_delegate();
if (!session_state_delegate->IsUserSessionBlocked() ||
!window->transient_parent()) {
!views::corewm::GetTransientParent(window)) {
return GetContainerById(root,
internal::kShellWindowId_SystemModalContainer);
}

// Otherwise those that originate from LockScreen container and above are
// placed in the screen lock modal container.
int window_container_id = window->transient_parent()->parent()->id();
int window_container_id =
views::corewm::GetTransientParent(window)->parent()->id();
aura::Window* container = NULL;
if (window_container_id < internal::kShellWindowId_LockScreenContainer) {
container = GetContainerById(
Expand Down
3 changes: 2 additions & 1 deletion ash/wm/stacking_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/views/corewm/window_util.h"

using aura::Window;

Expand Down Expand Up @@ -48,7 +49,7 @@ TEST_F(StackingControllerTest, TransientParent) {

// Window with a transient parent.
scoped_ptr<Window> w1(CreateTestWindow());
w2->AddTransientChild(w1.get());
views::corewm::AddTransientChild(w2.get(), w1.get());
w1->SetBounds(gfx::Rect(10, 11, 250, 251));
ParentWindowInPrimaryRootWindow(w1.get());
w1->Show();
Expand Down
Loading

0 comments on commit 751b13d

Please sign in to comment.