Skip to content

Commit

Permalink
open new window in the same root window where the launcher was in
Browse files Browse the repository at this point in the history
* Introduced ScopedRootWindowActivator to temporarily switch
active root window.


BUG=241571
TEST=covered by test

Review URL: https://chromiumcodereview.appspot.com/19945008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215000 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
oshima@chromium.org committed Aug 1, 2013
1 parent 44ea8c7 commit b42910f
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 27 deletions.
2 changes: 2 additions & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
'root_window_controller.h',
'rotator/screen_rotation.cc',
'rotator/screen_rotation.h',
'scoped_target_root_window.cc',
'scoped_target_root_window.h',
'screen_ash.cc',
'screen_ash.h',
'screensaver/screensaver_view.cc',
Expand Down
6 changes: 6 additions & 0 deletions ash/launcher/launcher_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ash/launcher/overflow_button.h"
#include "ash/launcher/tabbed_launcher_button.h"
#include "ash/root_window_controller.h"
#include "ash/scoped_target_root_window.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell_delegate.h"
Expand Down Expand Up @@ -1496,6 +1497,8 @@ void LauncherView::ButtonPressed(views::Button* sender,
return;

{
ScopedTargetRootWindow scoped_target(
sender->GetWidget()->GetNativeView()->GetRootWindow());
// Slow down activation animations if shift key is pressed.
scoped_ptr<ui::ScopedAnimationDurationScaleMode> slowing_animations;
if (event.IsShiftDown()) {
Expand Down Expand Up @@ -1596,6 +1599,9 @@ void LauncherView::ShowMenu(
launcher_menu_runner_.reset(
new views::MenuRunner(menu_model_adapter->CreateMenu()));

ScopedTargetRootWindow scoped_target(
source->GetWidget()->GetNativeView()->GetRootWindow());

// Determine the menu alignment dependent on the shelf.
views::MenuItemView::AnchorPosition menu_alignment =
views::MenuItemView::TOPLEFT;
Expand Down
21 changes: 21 additions & 0 deletions ash/scoped_target_root_window.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2013 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/scoped_target_root_window.h"

#include "ash/shell.h"

namespace ash {
namespace internal {

ScopedTargetRootWindow::ScopedTargetRootWindow(
aura::RootWindow* root_window) {
Shell::GetInstance()->scoped_target_root_window_ = root_window;
}

ScopedTargetRootWindow::~ScopedTargetRootWindow() {
Shell::GetInstance()->scoped_target_root_window_ = NULL;
}

} // namespace internal
} // namespace ash
33 changes: 33 additions & 0 deletions ash/scoped_target_root_window.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2013 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_SCOPED_TARGET_ROOT_WINDOW_H_
#define ASH_SCOPED_TARGET_ROOT_WINDOW_H_

#include "base/basictypes.h"

namespace aura {
class RootWindow;
}

namespace ash {
namespace internal {

// Constructing a ScopedTargetRootWindow allows temporarily
// switching a target root window so that a new window gets created
// in the same window where a user interaction happened.
// An example usage is to specify the target root window when creating
// a new window using launcher's icon.
class ScopedTargetRootWindow {
public:
explicit ScopedTargetRootWindow(aura::RootWindow* root_window);
~ScopedTargetRootWindow();

private:
DISALLOW_COPY_AND_ASSIGN(ScopedTargetRootWindow);
};

} // namespace internal
} // namespace ash

#endif // ASH_SCOPED_TARGET_ROOT_WINDOW_H_
18 changes: 11 additions & 7 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ bool Shell::initially_hide_cursor_ = false;

Shell::Shell(ShellDelegate* delegate)
: screen_(new ScreenAsh),
active_root_window_(NULL),
target_root_window_(NULL),
scoped_target_root_window_(NULL),
delegate_(delegate),
activation_client_(NULL),
#if defined(OS_CHROMEOS) && defined(USE_X11)
Expand Down Expand Up @@ -249,8 +250,7 @@ Shell::~Shell() {
// Remove the focus from any window. This will prevent overhead and side
// effects (e.g. crashes) from changing focus during shutdown.
// See bug crbug.com/134502.
if (active_root_window_)
aura::client::GetFocusClient(active_root_window_)->FocusWindow(NULL);
aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(NULL);

// Please keep in same order as in Init() because it's easy to miss one.
RemovePreTargetHandler(event_rewriter_filter_.get());
Expand Down Expand Up @@ -386,7 +386,10 @@ aura::RootWindow* Shell::GetPrimaryRootWindow() {

// static
aura::RootWindow* Shell::GetActiveRootWindow() {
return GetInstance()->active_root_window_;
Shell* shell = GetInstance();
if (shell->scoped_target_root_window_)
return shell->scoped_target_root_window_;
return shell->target_root_window_;
}

// static
Expand Down Expand Up @@ -499,7 +502,7 @@ void Shell::Init() {
display_controller_->Start();
display_controller_->InitPrimaryDisplay();
aura::RootWindow* root_window = display_controller_->GetPrimaryRootWindow();
active_root_window_ = root_window;
target_root_window_ = root_window;

cursor_manager_.SetDisplay(DisplayController::GetPrimaryDisplay());

Expand Down Expand Up @@ -883,7 +886,8 @@ void Shell::InitRootWindowForSecondaryDisplay(aura::RootWindow* root) {
high_contrast_controller_->OnRootWindowAdded(root);
root->ShowRootWindow();
// Activate new root for testing.
active_root_window_ = root;
// TODO(oshima): remove this.
target_root_window_ = root;

// Create a launcher if a user is already logged.
if (Shell::GetInstance()->session_state_delegate()->NumberOfLoggedInUsers())
Expand Down Expand Up @@ -970,7 +974,7 @@ void Shell::OnEvent(ui::Event* event) {
void Shell::OnWindowActivated(aura::Window* gained_active,
aura::Window* lost_active) {
if (gained_active)
active_root_window_ = gained_active->GetRootWindow();
target_root_window_ = gained_active->GetRootWindow();
}

} // namespace ash
24 changes: 16 additions & 8 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class OverlayEventFilter;
class ResizeShadowController;
class RootWindowController;
class RootWindowLayoutManager;
class ScopedTargetRootWindow;
class ScreenPositionController;
class SlowAnimationEventFilter;
class StatusAreaWidget;
Expand Down Expand Up @@ -178,10 +179,12 @@ class ASH_EXPORT Shell
// that has a launcher.
static aura::RootWindow* GetPrimaryRootWindow();

// Returns the active RootWindow. The active RootWindow is the one that
// contains the current active window as a decendant child. The active
// RootWindow remains the same even when the active window becomes NULL,
// until the another window who has a different root window becomes active.
// Returns a RootWindow when used as a target when creating a new window.
// The root window of the active window is used in most cases, but can
// be overridden by using ScopedTargetRootWindow().
// If you want to get a RootWindow of the active window, just use
// |wm::GetActiveWindow()->GetRootWindow()|.
// TODO(oshima): Rename to GetTargetRootWindow() crbug.com/266378.
static aura::RootWindow* GetActiveRootWindow();

// Returns the global Screen object that's always active in ash.
Expand All @@ -206,8 +209,8 @@ class ASH_EXPORT Shell
// application windows to be maximized only.
static bool IsForcedMaximizeMode();

void set_active_root_window(aura::RootWindow* active_root_window) {
active_root_window_ = active_root_window;
void set_active_root_window(aura::RootWindow* target_root_window) {
target_root_window_ = target_root_window;
}

// Shows the context menu for the background and launcher at
Expand Down Expand Up @@ -473,6 +476,7 @@ class ASH_EXPORT Shell
FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, TransformActivate);
friend class internal::RootWindowController;
friend class internal::ScopedTargetRootWindow;
friend class test::ShellTestApi;
friend class shell::WindowWatcher;

Expand Down Expand Up @@ -510,8 +514,12 @@ class ASH_EXPORT Shell

ScreenAsh* screen_;

// Active root window. Never becomes NULL during the session.
aura::RootWindow* active_root_window_;
// When no explicit target display/RootWindow is given, new windows are
// created on |scoped_target_root_window_| , unless NULL in
// which case they are created on |target_root_window_|.
// |target_root_window_| never becomes NULL during the session.
aura::RootWindow* target_root_window_;
aura::RootWindow* scoped_target_root_window_;

// The CompoundEventFilter owned by aura::Env object.
scoped_ptr<views::corewm::CompoundEventFilter> env_filter_;
Expand Down
14 changes: 2 additions & 12 deletions chrome/browser/ui/window_sizer/window_sizer_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,6 @@ bool MoveRect(const gfx::Rect& work_area,
return false;
}

// Adjust the |target_in_screen| rectangle so it moves as much as possible into
// the |work_area| .
void AdjustTargetRectVerticallyAgainstWorkspace(const gfx::Rect& work_area,
gfx::Rect* target_in_screen) {
if (target_in_screen->bottom() > work_area.bottom())
target_in_screen->set_y(std::max(work_area.y(),
work_area.bottom() - target_in_screen->height()));
}

} // namespace

// static
Expand Down Expand Up @@ -205,8 +196,7 @@ bool WindowSizer::GetBoundsOverrideAsh(gfx::Rect* bounds_in_screen,
if ((!count || !top_window)) {
if (has_saved_bounds) {
// Restore to previous state - if there is one.
AdjustTargetRectVerticallyAgainstWorkspace(work_area,
bounds_in_screen);
bounds_in_screen->AdjustToFit(work_area);
return true;
}
// When using "small screens" we want to always open in full screen mode.
Expand Down Expand Up @@ -239,7 +229,7 @@ bool WindowSizer::GetBoundsOverrideAsh(gfx::Rect* bounds_in_screen,
bounds_in_screen->CenterPoint().x() < work_area.CenterPoint().x();

MoveRect(work_area, *bounds_in_screen, move_right);
AdjustTargetRectVerticallyAgainstWorkspace(work_area, bounds_in_screen);
bounds_in_screen->AdjustToFit(work_area);
return true;
}

Expand Down
Loading

0 comments on commit b42910f

Please sign in to comment.