Skip to content

Commit

Permalink
Adds the ability for windows to persist across all workspaces. Chrome
Browse files Browse the repository at this point in the history
makes the default that all windows persist across all workspaces and
explicitly disables this for browsers. As part of this I promoted
duplicated code from WorkspaceLayoutManager and
AlwaysOnTopLayoutManager to BaseLayoutManager.

BUG=122301,122390,121280,121784
TEST=see bugs, covered by unit tests too.
R=ben@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131986 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sky@chromium.org committed Apr 12, 2012
1 parent 6a24fcc commit 24eea16
Show file tree
Hide file tree
Showing 25 changed files with 251 additions and 319 deletions.
2 changes: 0 additions & 2 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@
'wm/window_util.h',
'wm/workspace_controller.cc',
'wm/workspace_controller.h',
'wm/workspace/always_on_top_layout_manager.cc',
'wm/workspace/always_on_top_layout_manager.h',
'wm/workspace/frame_maximize_button.cc',
'wm/workspace/frame_maximize_button.h',
'wm/workspace/managed_workspace.cc',
Expand Down
3 changes: 1 addition & 2 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
#include "ash/wm/window_cycle_controller.h"
#include "ash/wm/window_modality_controller.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace/always_on_top_layout_manager.h"
#include "ash/wm/workspace/workspace_event_filter.h"
#include "ash/wm/workspace/workspace_layout_manager.h"
#include "ash/wm/workspace/workspace_manager.h"
Expand Down Expand Up @@ -925,7 +924,7 @@ void Shell::InitLayoutManagers() {
aura::Window* always_on_top_container =
GetContainer(internal::kShellWindowId_AlwaysOnTopContainer);
always_on_top_container->SetLayoutManager(
new internal::AlwaysOnTopLayoutManager(
new internal::BaseLayoutManager(
always_on_top_container->GetRootWindow()));

// Create desktop background widget.
Expand Down
13 changes: 11 additions & 2 deletions ash/shell/toplevel_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "ash/shell/toplevel_window.h"

#include "ash/wm/property_util.h"
#include "base/utf_string_conversions.h"
#include "ui/aura/window.h"
#include "ui/gfx/canvas.h"
Expand All @@ -14,7 +15,8 @@ namespace shell {

ToplevelWindow::CreateParams::CreateParams()
: can_resize(false),
can_maximize(false) {
can_maximize(false),
persist_across_all_workspaces(false) {
}

// static
Expand All @@ -26,6 +28,11 @@ void ToplevelWindow::CreateToplevelWindow(const CreateParams& params) {
views::Widget::CreateWindowWithBounds(new ToplevelWindow(params),
gfx::Rect(x, 150, 300, 300));
widget->GetNativeView()->SetName("Examples:ToplevelWindow");
if (params.persist_across_all_workspaces) {
SetPersistsAcrossAllWorkspaces(
widget->GetNativeView(),
WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES);
}
widget->Show();
}

Expand All @@ -40,7 +47,9 @@ void ToplevelWindow::OnPaint(gfx::Canvas* canvas) {
}

string16 ToplevelWindow::GetWindowTitle() const {
return ASCIIToUTF16("Examples: Toplevel Window");
return params_.persist_across_all_workspaces ?
ASCIIToUTF16("Examples: Toplevel Window (P)") :
ASCIIToUTF16("Examples: Toplevel Window");
}

views::View* ToplevelWindow::GetContentsView() {
Expand Down
1 change: 1 addition & 0 deletions ash/shell/toplevel_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ToplevelWindow : public views::WidgetDelegateView {

bool can_resize;
bool can_maximize;
bool persist_across_all_workspaces;
};
static void CreateToplevelWindow(const CreateParams& params);

Expand Down
109 changes: 38 additions & 71 deletions ash/shell/window_type_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/examples/examples_window.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/widget/widget.h"

using views::MenuItemView;
Expand Down Expand Up @@ -164,6 +165,12 @@ class NonModalTransient : public views::WidgetDelegateView {
// static
views::Widget* NonModalTransient::non_modal_transient_ = NULL;

void AddViewToLayout(views::GridLayout* layout, views::View* view) {
layout->StartRow(0, 0);
layout->AddView(view);
layout->AddPaddingRow(0, 5);
}

} // namespace

void InitWindowTypeLauncher() {
Expand All @@ -179,6 +186,9 @@ void InitWindowTypeLauncher() {
WindowTypeLauncher::WindowTypeLauncher()
: ALLOW_THIS_IN_INITIALIZER_LIST(create_button_(
new views::NativeTextButton(this, ASCIIToUTF16("Create Window")))),
ALLOW_THIS_IN_INITIALIZER_LIST(create_persistant_button_(
new views::NativeTextButton(
this, ASCIIToUTF16("Create Persistant Window")))),
ALLOW_THIS_IN_INITIALIZER_LIST(panel_button_(
new views::NativeTextButton(this, ASCIIToUTF16("Create Panel")))),
ALLOW_THIS_IN_INITIALIZER_LIST(create_nonresizable_button_(
Expand Down Expand Up @@ -207,17 +217,28 @@ WindowTypeLauncher::WindowTypeLauncher()
ALLOW_THIS_IN_INITIALIZER_LIST(show_hide_window_button_(
new views::NativeTextButton(
this, ASCIIToUTF16("Show/Hide a Window")))) {
AddChildView(create_button_);
AddChildView(panel_button_);
AddChildView(create_nonresizable_button_);
AddChildView(bubble_button_);
AddChildView(lock_button_);
AddChildView(widgets_button_);
AddChildView(system_modal_button_);
AddChildView(window_modal_button_);
AddChildView(transient_button_);
AddChildView(examples_button_);
AddChildView(show_hide_window_button_);
views::GridLayout* layout = new views::GridLayout(this);
layout->SetInsets(5, 5, 5, 5);
SetLayoutManager(layout);
views::ColumnSet* column_set = layout->AddColumnSet(0);
column_set->AddColumn(views::GridLayout::LEADING,
views::GridLayout::CENTER,
0,
views::GridLayout::USE_PREF,
0,
0);
AddViewToLayout(layout, create_button_);
AddViewToLayout(layout, create_persistant_button_);
AddViewToLayout(layout, panel_button_);
AddViewToLayout(layout, create_nonresizable_button_);
AddViewToLayout(layout, bubble_button_);
AddViewToLayout(layout, lock_button_);
AddViewToLayout(layout, widgets_button_);
AddViewToLayout(layout, system_modal_button_);
AddViewToLayout(layout, window_modal_button_);
AddViewToLayout(layout, transient_button_);
AddViewToLayout(layout, examples_button_);
AddViewToLayout(layout, show_hide_window_button_);
#if !defined(OS_MACOSX)
set_context_menu_controller(this);
#endif
Expand All @@ -230,66 +251,6 @@ void WindowTypeLauncher::OnPaint(gfx::Canvas* canvas) {
canvas->FillRect(GetLocalBounds(), SK_ColorWHITE);
}

void WindowTypeLauncher::Layout() {
gfx::Size create_button_ps = create_button_->GetPreferredSize();
gfx::Rect local_bounds = GetLocalBounds();
create_button_->SetBounds(
5, local_bounds.bottom() - create_button_ps.height() - 5,
create_button_ps.width(), create_button_ps.height());

gfx::Size panel_button_ps = panel_button_->GetPreferredSize();
panel_button_->SetBounds(
5, create_button_->y() - panel_button_ps.height() - 5,
panel_button_ps.width(), panel_button_ps.height());

gfx::Size bubble_button_ps = bubble_button_->GetPreferredSize();
bubble_button_->SetBounds(
5, panel_button_->y() - bubble_button_ps.height() - 5,
bubble_button_ps.width(), bubble_button_ps.height());

gfx::Size create_nr_button_ps =
create_nonresizable_button_->GetPreferredSize();
create_nonresizable_button_->SetBounds(
5, bubble_button_->y() - create_nr_button_ps.height() - 5,
create_nr_button_ps.width(), create_nr_button_ps.height());

gfx::Size lock_ps = lock_button_->GetPreferredSize();
lock_button_->SetBounds(
5, create_nonresizable_button_->y() - lock_ps.height() - 5,
lock_ps.width(), lock_ps.height());

gfx::Size widgets_ps = widgets_button_->GetPreferredSize();
widgets_button_->SetBounds(
5, lock_button_->y() - widgets_ps.height() - 5,
widgets_ps.width(), widgets_ps.height());

gfx::Size system_modal_ps = system_modal_button_->GetPreferredSize();
system_modal_button_->SetBounds(
5, widgets_button_->y() - system_modal_ps.height() - 5,
system_modal_ps.width(), system_modal_ps.height());

gfx::Size window_modal_ps = window_modal_button_->GetPreferredSize();
window_modal_button_->SetBounds(
5, system_modal_button_->y() - window_modal_ps.height() - 5,
window_modal_ps.width(), window_modal_ps.height());

gfx::Size transient_ps = transient_button_->GetPreferredSize();
transient_button_->SetBounds(
5, window_modal_button_->y() - transient_ps.height() - 5,
transient_ps.width(), transient_ps.height());

gfx::Size examples_ps = examples_button_->GetPreferredSize();
examples_button_->SetBounds(
5, transient_button_->y() - examples_ps.height() - 5,
examples_ps.width(), examples_ps.height());

gfx::Size show_hide_window_ps =
show_hide_window_button_->GetPreferredSize();
show_hide_window_button_->SetBounds(
5, examples_button_->y() - show_hide_window_ps.height() - 5,
show_hide_window_ps.width(), show_hide_window_ps.height());
}

bool WindowTypeLauncher::OnMousePressed(const views::MouseEvent& event) {
// Overridden so we get OnMouseReleased and can show the context menu.
return true;
Expand Down Expand Up @@ -318,6 +279,12 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender,
params.can_resize = true;
params.can_maximize = true;
ToplevelWindow::CreateToplevelWindow(params);
} else if (sender == create_persistant_button_) {
ToplevelWindow::CreateParams params;
params.can_resize = true;
params.can_maximize = true;
params.persist_across_all_workspaces = true;
ToplevelWindow::CreateToplevelWindow(params);
} else if (sender == panel_button_) {
PanelWindow::CreatePanelWindow(gfx::Rect());
} else if (sender == create_nonresizable_button_) {
Expand Down
2 changes: 1 addition & 1 deletion ash/shell/window_type_launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class WindowTypeLauncher : public views::WidgetDelegateView,

// Overridden from views::View:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void Layout() OVERRIDE;
virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;

// Overridden from views::WidgetDelegate:
Expand All @@ -67,6 +66,7 @@ class WindowTypeLauncher : public views::WidgetDelegateView,
#endif // !defined(OS_MACOSX)

views::NativeTextButton* create_button_;
views::NativeTextButton* create_persistant_button_;
views::NativeTextButton* panel_button_;
views::NativeTextButton* create_nonresizable_button_;
views::NativeTextButton* bubble_button_;
Expand Down
43 changes: 41 additions & 2 deletions ash/wm/base_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
#include "ash/shell.h"
#include "ash/wm/property_util.h"
#include "ash/wm/shelf_layout_manager.h"
#include "ash/wm/window_animations.h"
#include "ash/wm/window_util.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/aura/window_property.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/screen.h"

DECLARE_WINDOW_PROPERTY_TYPE(ui::WindowShowState)

namespace {

// Given a |window| and tentative |restore_bounds|, returns new bounds that
Expand All @@ -36,6 +41,10 @@ gfx::Rect BoundsWithScreenEdgeVisible(aura::Window* window,
return restore_bounds;
}

// Used to remember the show state before the window was minimized.
DEFINE_WINDOW_PROPERTY_KEY(
ui::WindowShowState, kRestoreShowStateKey, ui::SHOW_STATE_DEFAULT);

} // namespace

namespace ash {
Expand Down Expand Up @@ -82,7 +91,13 @@ void BaseLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) {
}

void BaseLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child,
bool visibile) {
bool visible) {
if (visible && wm::IsWindowMinimized(child)) {
// Attempting to show a minimized window. Unminimize it.
child->SetProperty(aura::client::kShowStateKey,
child->GetProperty(kRestoreShowStateKey));
child->ClearProperty(kRestoreShowStateKey);
}
}

void BaseLayoutManager::SetChildBounds(aura::Window* child,
Expand Down Expand Up @@ -118,8 +133,10 @@ void BaseLayoutManager::OnMonitorWorkAreaInsetsChanged() {
void BaseLayoutManager::OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) {
if (key == aura::client::kShowStateKey)
if (key == aura::client::kShowStateKey) {
UpdateBoundsFromShowState(window);
ShowStateChanged(window, static_cast<ui::WindowShowState>(old));
}
}

void BaseLayoutManager::OnWindowDestroying(aura::Window* window) {
Expand All @@ -132,6 +149,28 @@ void BaseLayoutManager::OnWindowDestroying(aura::Window* window) {
//////////////////////////////////////////////////////////////////////////////
// BaseLayoutManager, private:

void BaseLayoutManager::ShowStateChanged(aura::Window* window,
ui::WindowShowState last_show_state) {
if (wm::IsWindowMinimized(window)) {
// Save the previous show state so that we can correctly restore it.
window->SetProperty(kRestoreShowStateKey, last_show_state);
SetWindowVisibilityAnimationType(
window, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);

// Hide the window.
window->Hide();
// Activate another window.
if (wm::IsActiveWindow(window))
wm::DeactivateWindow(window);
} else if ((window->TargetVisibility() ||
last_show_state == ui::SHOW_STATE_MINIMIZED) &&
!window->layer()->visible()) {
// The layer may be hidden if the window was previously minimized. Make
// sure it's visible.
window->Show();
}
}

void BaseLayoutManager::UpdateBoundsFromShowState(aura::Window* window) {
switch (window->GetProperty(aura::client::kShowStateKey)) {
case ui::SHOW_STATE_DEFAULT:
Expand Down
6 changes: 6 additions & 0 deletions ash/wm/base_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/compiler_specific.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/root_window_observer.h"
#include "ui/base/ui_base_types.h"
#include "ui/aura/window_observer.h"

namespace aura {
Expand Down Expand Up @@ -63,6 +64,11 @@ class ASH_EXPORT BaseLayoutManager : public aura::LayoutManager,
intptr_t old) OVERRIDE;
virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;

protected:
// Invoked from OnWindowPropertyChanged() if |kShowStateKey| changes.
virtual void ShowStateChanged(aura::Window* window,
ui::WindowShowState last_show_state);

private:
// Update window bounds based on a change in show state.
void UpdateBoundsFromShowState(aura::Window* window);
Expand Down
Loading

0 comments on commit 24eea16

Please sign in to comment.