From 6fd60e78fea457922057a61c12dc791145c7189d Mon Sep 17 00:00:00 2001 From: "nkostylev@chromium.org" Date: Tue, 6 Dec 2011 11:41:44 +0000 Subject: [cros, Aura] Refresh status area widget bounds on StatusAreaView layout. Make ShelfLayoutController a ShelfLayoutManager for launcher, status windows. BUG=105661 TEST=Manual. Status area is represented with all icons on Aura. Review URL: http://codereview.chromium.org/8743014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113185 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/aura_shell/aura_shell.gyp | 6 +- ui/aura_shell/desktop_layout_manager.cc | 8 +- ui/aura_shell/desktop_layout_manager.h | 6 -- ui/aura_shell/shelf_layout_controller.cc | 119 ---------------------- ui/aura_shell/shelf_layout_controller.h | 83 --------------- ui/aura_shell/shelf_layout_manager.cc | 153 ++++++++++++++++++++++++++++ ui/aura_shell/shelf_layout_manager.h | 101 ++++++++++++++++++ ui/aura_shell/shell.cc | 18 +++- ui/aura_shell/shell.h | 2 - ui/aura_shell/status_area_layout_manager.cc | 62 +++++++++++ ui/aura_shell/status_area_layout_manager.h | 52 ++++++++++ ui/aura_shell/toplevel_layout_manager.cc | 2 +- ui/aura_shell/toplevel_layout_manager.h | 6 +- 13 files changed, 390 insertions(+), 228 deletions(-) delete mode 100644 ui/aura_shell/shelf_layout_controller.cc delete mode 100644 ui/aura_shell/shelf_layout_controller.h create mode 100644 ui/aura_shell/shelf_layout_manager.cc create mode 100644 ui/aura_shell/shelf_layout_manager.h create mode 100644 ui/aura_shell/status_area_layout_manager.cc create mode 100644 ui/aura_shell/status_area_layout_manager.h (limited to 'ui') diff --git a/ui/aura_shell/aura_shell.gyp b/ui/aura_shell/aura_shell.gyp index 656c536..74f9431 100644 --- a/ui/aura_shell/aura_shell.gyp +++ b/ui/aura_shell/aura_shell.gyp @@ -80,8 +80,8 @@ 'shadow.h', 'shadow_controller.cc', 'shadow_controller.h', - 'shelf_layout_controller.cc', - 'shelf_layout_controller.h', + 'shelf_layout_manager.cc', + 'shelf_layout_manager.h', 'shell.cc', 'shell.h', 'shell_accelerator_controller.cc', @@ -97,6 +97,8 @@ 'show_state_controller.cc', 'stacking_controller.cc', 'stacking_controller.h', + 'status_area_layout_manager.cc', + 'status_area_layout_manager.h', 'status_area_view.cc', 'status_area_view.h', 'toplevel_frame_view.cc', diff --git a/ui/aura_shell/desktop_layout_manager.cc b/ui/aura_shell/desktop_layout_manager.cc index d54e186..7c05e1b 100644 --- a/ui/aura_shell/desktop_layout_manager.cc +++ b/ui/aura_shell/desktop_layout_manager.cc @@ -5,7 +5,6 @@ #include "ui/aura_shell/desktop_layout_manager.h" #include "ui/aura/window.h" -#include "ui/aura_shell/shelf_layout_controller.h" #include "ui/views/widget/widget.h" namespace aura_shell { @@ -16,8 +15,7 @@ namespace internal { DesktopLayoutManager::DesktopLayoutManager(aura::Window* owner) : owner_(owner), - background_widget_(NULL), - shelf_(NULL) { + background_widget_(NULL) { } DesktopLayoutManager::~DesktopLayoutManager() { @@ -35,9 +33,6 @@ void DesktopLayoutManager::OnWindowResized() { (*i)->SetBounds(fullscreen_bounds); background_widget_->SetBounds(fullscreen_bounds); - - if (shelf_) - shelf_->LayoutShelf(); } void DesktopLayoutManager::OnWindowAddedToLayout(aura::Window* child) { @@ -55,6 +50,5 @@ void DesktopLayoutManager::SetChildBounds(aura::Window* child, SetChildBoundsDirect(child, requested_bounds); } - } // namespace internal } // namespace aura_shell diff --git a/ui/aura_shell/desktop_layout_manager.h b/ui/aura_shell/desktop_layout_manager.h index 7af3039..80efb19 100644 --- a/ui/aura_shell/desktop_layout_manager.h +++ b/ui/aura_shell/desktop_layout_manager.h @@ -23,8 +23,6 @@ class Widget; namespace aura_shell { namespace internal { -class ShelfLayoutController; - // A layout manager for the root window. // Resizes all of its immediate children to fill the bounds of the root window. class DesktopLayoutManager : public aura::LayoutManager { @@ -32,8 +30,6 @@ class DesktopLayoutManager : public aura::LayoutManager { explicit DesktopLayoutManager(aura::Window* owner); virtual ~DesktopLayoutManager(); - void set_shelf(ShelfLayoutController* shelf) { shelf_ = shelf; } - void set_background_widget(views::Widget* background_widget) { background_widget_ = background_widget; } @@ -52,8 +48,6 @@ class DesktopLayoutManager : public aura::LayoutManager { views::Widget* background_widget_; - ShelfLayoutController* shelf_; - DISALLOW_COPY_AND_ASSIGN(DesktopLayoutManager); }; diff --git a/ui/aura_shell/shelf_layout_controller.cc b/ui/aura_shell/shelf_layout_controller.cc deleted file mode 100644 index d26af3c..0000000 --- a/ui/aura_shell/shelf_layout_controller.cc +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) 2011 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 "ui/aura_shell/shelf_layout_controller.h" - -#include "ui/aura/desktop.h" -#include "ui/aura/screen_aura.h" -#include "ui/gfx/compositor/layer.h" -#include "ui/gfx/compositor/layer_animator.h" -#include "ui/views/widget/widget.h" - -namespace aura_shell { -namespace internal { - -namespace { - -ui::Layer* GetLayer(views::Widget* widget) { - return widget->GetNativeView()->layer(); -} - -} // namespace - -ShelfLayoutController::ShelfLayoutController(views::Widget* launcher, - views::Widget* status) - : animating_(false), - visible_(true), - max_height_(-1), - launcher_(launcher), - status_(status) { - gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds(); - gfx::Rect status_bounds = status->GetWindowScreenBounds(); - max_height_ = std::max(launcher_bounds.height(), status_bounds.height()); - GetLayer(launcher)->GetAnimator()->AddObserver(this); -} - -ShelfLayoutController::~ShelfLayoutController() { - // Do not try to remove observer from layer as the Launcher is - // already deleted. -} - -void ShelfLayoutController::LayoutShelf() { - StopAnimating(); - TargetBounds target_bounds; - float target_opacity = visible_ ? 1.0f : 0.0f; - CalculateTargetBounds(visible_, &target_bounds); - GetLayer(launcher_)->SetOpacity(target_opacity); - GetLayer(status_)->SetOpacity(target_opacity); - launcher_->SetBounds(target_bounds.launcher_bounds); - status_->SetBounds(target_bounds.status_bounds); - aura::Desktop::GetInstance()->screen()->set_work_area_insets( - target_bounds.work_area_insets); -} - -void ShelfLayoutController::SetVisible(bool visible) { - bool current_visibility = animating_ ? !visible_ : visible_; - if (visible == current_visibility) - return; // Nothing changed. - - StopAnimating(); - - TargetBounds target_bounds; - float target_opacity = visible ? 1.0f : 0.0f; - CalculateTargetBounds(visible, &target_bounds); - AnimateWidgetTo(launcher_, target_bounds.launcher_bounds, target_opacity); - AnimateWidgetTo(status_, target_bounds.status_bounds, target_opacity); - animating_ = true; - // |visible_| is updated once the animation completes. -} - -void ShelfLayoutController::StopAnimating() { - if (animating_) { - animating_ = false; - visible_ = !visible_; - } - GetLayer(launcher_)->GetAnimator()->StopAnimating(); -} - -void ShelfLayoutController::CalculateTargetBounds(bool visible, - TargetBounds* target_bounds) { - const gfx::Rect& available_bounds(aura::Desktop::GetInstance()->bounds()); - int y = available_bounds.bottom() - (visible ? max_height_ : 0); - gfx::Rect status_bounds(status_->GetWindowScreenBounds()); - target_bounds->status_bounds = gfx::Rect( - available_bounds.right() - status_bounds.width(), - y + (max_height_ - status_bounds.height()) / 2, - status_bounds.width(), status_bounds.height()); - gfx::Rect launcher_bounds(launcher_->GetWindowScreenBounds()); - target_bounds->launcher_bounds = gfx::Rect( - available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2, - available_bounds.width() - status_bounds.width(), - launcher_bounds.height()); - if (visible) - target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0); -} - -void ShelfLayoutController::AnimateWidgetTo(views::Widget* widget, - const gfx::Rect& target_bounds, - float target_opacity) { - ui::Layer* layer = GetLayer(widget); - ui::LayerAnimator::ScopedSettings animation_setter(layer->GetAnimator()); - widget->SetBounds(target_bounds); - layer->SetOpacity(target_opacity); -} - -void ShelfLayoutController::OnLayerAnimationEnded( - const ui::LayerAnimationSequence* sequence) { - if (!animating_) - return; - animating_ = false; - visible_ = !visible_; - TargetBounds target_bounds; - CalculateTargetBounds(visible_, &target_bounds); - aura::Desktop::GetInstance()->screen()->set_work_area_insets( - target_bounds.work_area_insets); -} - -} // internal -} // aura_shell diff --git a/ui/aura_shell/shelf_layout_controller.h b/ui/aura_shell/shelf_layout_controller.h deleted file mode 100644 index a675699..0000000 --- a/ui/aura_shell/shelf_layout_controller.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) 2011 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 UI_AURA_SHELL_SHELF_LAYOUT_CONTROLLER_H_ -#define UI_AURA_SHELL_SHELF_LAYOUT_CONTROLLER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/gfx/compositor/layer_animation_observer.h" -#include "ui/gfx/insets.h" -#include "ui/gfx/rect.h" - -namespace views { -class Widget; -} - -namespace aura_shell { -namespace internal { - -// ShelfLayoutController is responsible for showing and hiding the launcher and -// status area as well as positioning them. -class ShelfLayoutController : public ui::LayerAnimationObserver { - public: - ShelfLayoutController(views::Widget* launcher, - views::Widget* status); - virtual ~ShelfLayoutController(); - - // Stops any animations and sets the bounds of the launcher and status - // widgets. - void LayoutShelf(); - - // Sets the visbility of the shelf to |visible|. - void SetVisible(bool visible); - - private: - struct TargetBounds { - gfx::Rect launcher_bounds; - gfx::Rect status_bounds; - gfx::Insets work_area_insets; - }; - - // Stops any animations. - void StopAnimating(); - - // Calculates the target bounds assuming visibility of |visibile|. - void CalculateTargetBounds(bool visible, - TargetBounds* target_bounds); - - // Animates |widget| to the specified bounds and opacity. - void AnimateWidgetTo(views::Widget* widget, - const gfx::Rect& target_bounds, - float target_opacity); - - // LayerAnimationObserver overrides: - virtual void OnLayerAnimationEnded( - const ui::LayerAnimationSequence* sequence) OVERRIDE; - virtual void OnLayerAnimationAborted( - const ui::LayerAnimationSequence* sequence) OVERRIDE {} - virtual void OnLayerAnimationScheduled( - const ui::LayerAnimationSequence* sequence) OVERRIDE {} - - // Are we animating? - bool animating_; - - // Current visibility. When the visibility changes this field is reset once - // the animation completes. - bool visible_; - - // Max height needed. - int max_height_; - - views::Widget* launcher_; - views::Widget* status_; - - DISALLOW_COPY_AND_ASSIGN(ShelfLayoutController); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_SHELF_LAYOUT_CONTROLLER_H_ diff --git a/ui/aura_shell/shelf_layout_manager.cc b/ui/aura_shell/shelf_layout_manager.cc new file mode 100644 index 0000000..c01d112 --- /dev/null +++ b/ui/aura_shell/shelf_layout_manager.cc @@ -0,0 +1,153 @@ +// Copyright (c) 2011 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 "ui/aura_shell/shelf_layout_manager.h" + +#include "base/auto_reset.h" +#include "ui/aura/desktop.h" +#include "ui/aura/screen_aura.h" +#include "ui/gfx/compositor/layer.h" +#include "ui/gfx/compositor/layer_animator.h" +#include "ui/views/widget/widget.h" + +namespace aura_shell { +namespace internal { + +namespace { + +ui::Layer* GetLayer(views::Widget* widget) { + return widget->GetNativeView()->layer(); +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// +// ShelfLayoutManager, public: + +ShelfLayoutManager::ShelfLayoutManager(views::Widget* launcher, + views::Widget* status) + : animating_(false), + in_layout_(false), + visible_(true), + max_height_(-1), + launcher_(launcher), + status_(status) { + gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds(); + gfx::Rect status_bounds = status->GetWindowScreenBounds(); + max_height_ = std::max(launcher_bounds.height(), status_bounds.height()); + GetLayer(launcher)->GetAnimator()->AddObserver(this); +} + + +ShelfLayoutManager::~ShelfLayoutManager() { + // Do not try to remove observer from layer as the Launcher is + // already deleted. +} + +void ShelfLayoutManager::LayoutShelf() { + AutoReset auto_reset_in_layout(&in_layout_, true); + StopAnimating(); + TargetBounds target_bounds; + float target_opacity = visible_ ? 1.0f : 0.0f; + CalculateTargetBounds(visible_, &target_bounds); + GetLayer(launcher_)->SetOpacity(target_opacity); + GetLayer(status_)->SetOpacity(target_opacity); + launcher_->SetBounds(target_bounds.launcher_bounds); + status_->SetBounds(target_bounds.status_bounds); + aura::Desktop::GetInstance()->screen()->set_work_area_insets( + target_bounds.work_area_insets); +} + +void ShelfLayoutManager::SetVisible(bool visible) { + bool current_visibility = animating_ ? !visible_ : visible_; + if (visible == current_visibility) + return; // Nothing changed. + + StopAnimating(); + + TargetBounds target_bounds; + float target_opacity = visible ? 1.0f : 0.0f; + CalculateTargetBounds(visible, &target_bounds); + AnimateWidgetTo(launcher_, target_bounds.launcher_bounds, target_opacity); + AnimateWidgetTo(status_, target_bounds.status_bounds, target_opacity); + animating_ = true; + // |visible_| is updated once the animation completes. +} + +//////////////////////////////////////////////////////////////////////////////// +// ShelfLayoutManager, aura::LayoutManager implementation: + +void ShelfLayoutManager::OnWindowResized() { + LayoutShelf(); +} + +void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) { +} + +void ShelfLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { +} + +void ShelfLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, + bool visible) { +} + +void ShelfLayoutManager::SetChildBounds(aura::Window* child, + const gfx::Rect& requested_bounds) { + SetChildBoundsDirect(child, requested_bounds); + if (!in_layout_) + LayoutShelf(); +} + +//////////////////////////////////////////////////////////////////////////////// +// ShelfLayoutManager, private: + +void ShelfLayoutManager::StopAnimating() { + if (animating_) { + animating_ = false; + visible_ = !visible_; + } + GetLayer(launcher_)->GetAnimator()->StopAnimating(); +} + +void ShelfLayoutManager::CalculateTargetBounds(bool visible, + TargetBounds* target_bounds) { + const gfx::Rect& available_bounds(aura::Desktop::GetInstance()->bounds()); + int y = available_bounds.bottom() - (visible ? max_height_ : 0); + gfx::Rect status_bounds(status_->GetWindowScreenBounds()); + target_bounds->status_bounds = gfx::Rect( + available_bounds.right() - status_bounds.width(), + y + (max_height_ - status_bounds.height()) / 2, + status_bounds.width(), status_bounds.height()); + gfx::Rect launcher_bounds(launcher_->GetWindowScreenBounds()); + target_bounds->launcher_bounds = gfx::Rect( + available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2, + available_bounds.width() - status_bounds.width(), + launcher_bounds.height()); + if (visible) + target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0); +} + +void ShelfLayoutManager::AnimateWidgetTo(views::Widget* widget, + const gfx::Rect& target_bounds, + float target_opacity) { + ui::Layer* layer = GetLayer(widget); + ui::LayerAnimator::ScopedSettings animation_setter(layer->GetAnimator()); + widget->SetBounds(target_bounds); + layer->SetOpacity(target_opacity); +} + +void ShelfLayoutManager::OnLayerAnimationEnded( + const ui::LayerAnimationSequence* sequence) { + if (!animating_) + return; + animating_ = false; + visible_ = !visible_; + TargetBounds target_bounds; + CalculateTargetBounds(visible_, &target_bounds); + aura::Desktop::GetInstance()->screen()->set_work_area_insets( + target_bounds.work_area_insets); +} + +} // internal +} // aura_shell diff --git a/ui/aura_shell/shelf_layout_manager.h b/ui/aura_shell/shelf_layout_manager.h new file mode 100644 index 0000000..2c46867 --- /dev/null +++ b/ui/aura_shell/shelf_layout_manager.h @@ -0,0 +1,101 @@ +// Copyright (c) 2011 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 UI_AURA_SHELL_SHELF_LAYOUT_MANAGER_H_ +#define UI_AURA_SHELL_SHELF_LAYOUT_MANAGER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ui/aura/layout_manager.h" +#include "ui/gfx/compositor/layer_animation_observer.h" +#include "ui/gfx/insets.h" +#include "ui/gfx/rect.h" + +namespace views { +class Widget; +} + +namespace aura_shell { +namespace internal { + +// ShelfLayoutManager is a layout manager responsible for the launcher. +// Also supports showing and hiding the launcher/status area +// as well as positioning them. +class ShelfLayoutManager : public aura::LayoutManager, + public ui::LayerAnimationObserver { + public: + ShelfLayoutManager(views::Widget* launcher, + views::Widget* status); + virtual ~ShelfLayoutManager(); + + bool in_layout() const { return in_layout_; } + + // Stops any animations and sets the bounds of the launcher and status + // widgets. + void LayoutShelf(); + + // Sets the visbility of the shelf to |visible|. + void SetVisible(bool visible); + + // Overridden from aura::LayoutManager: + virtual void OnWindowResized() OVERRIDE; + virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; + virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; + virtual void OnChildWindowVisibilityChanged(aura::Window* child, + bool visible) OVERRIDE; + virtual void SetChildBounds(aura::Window* child, + const gfx::Rect& requested_bounds) OVERRIDE; + + private: + struct TargetBounds { + gfx::Rect launcher_bounds; + gfx::Rect status_bounds; + gfx::Insets work_area_insets; + }; + + // Stops any animations. + void StopAnimating(); + + // Calculates the target bounds assuming visibility of |visibile|. + void CalculateTargetBounds(bool visible, + TargetBounds* target_bounds); + + // Animates |widget| to the specified bounds and opacity. + void AnimateWidgetTo(views::Widget* widget, + const gfx::Rect& target_bounds, + float target_opacity); + + // LayerAnimationObserver overrides: + virtual void OnLayerAnimationEnded( + const ui::LayerAnimationSequence* sequence) OVERRIDE; + virtual void OnLayerAnimationAborted( + const ui::LayerAnimationSequence* sequence) OVERRIDE {} + virtual void OnLayerAnimationScheduled( + const ui::LayerAnimationSequence* sequence) OVERRIDE {} + + // Are we animating? + bool animating_; + + // True when inside LayoutShelf method. Used to prevent calling LayoutShelf + // again from SetChildBounds(). + bool in_layout_; + + // Current visibility. When the visibility changes this field is reset once + // the animation completes. + bool visible_; + + // Max height needed. + int max_height_; + + views::Widget* launcher_; + views::Widget* status_; + + DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManager); +}; + +} // namespace internal +} // namespace aura_shell + +#endif // UI_AURA_SHELL_SHELF_LAYOUT_MANAGER_H_ diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc index ded7967..53acecb 100644 --- a/ui/aura_shell/shell.cc +++ b/ui/aura_shell/shell.cc @@ -10,6 +10,7 @@ #include "ui/aura/client/aura_constants.h" #include "ui/aura/client/drag_drop_client.h" #include "ui/aura/desktop.h" +#include "ui/aura/layout_manager.h" #include "ui/aura/window.h" #include "ui/aura/window_types.h" #include "ui/aura_shell/app_list.h" @@ -21,7 +22,7 @@ #include "ui/aura_shell/launcher/launcher.h" #include "ui/aura_shell/modal_container_layout_manager.h" #include "ui/aura_shell/shadow_controller.h" -#include "ui/aura_shell/shelf_layout_controller.h" +#include "ui/aura_shell/shelf_layout_manager.h" #include "ui/aura_shell/shell_accelerator_controller.h" #include "ui/aura_shell/shell_accelerator_filter.h" #include "ui/aura_shell/shell_delegate.h" @@ -29,6 +30,7 @@ #include "ui/aura_shell/shell_tooltip_manager.h" #include "ui/aura_shell/shell_window_ids.h" #include "ui/aura_shell/stacking_controller.h" +#include "ui/aura_shell/status_area_layout_manager.h" #include "ui/aura_shell/toplevel_layout_manager.h" #include "ui/aura_shell/toplevel_window_event_filter.h" #include "ui/aura_shell/workspace_controller.h" @@ -204,9 +206,15 @@ void Shell::Init() { if (!status_widget) status_widget = internal::CreateStatusArea(); - shelf_layout_controller_.reset(new internal::ShelfLayoutController( - launcher_->widget(), status_widget)); - desktop_layout->set_shelf(shelf_layout_controller_.get()); + internal::ShelfLayoutManager* shelf_layout_manager = + new internal::ShelfLayoutManager(launcher_->widget(), status_widget); + GetContainer(aura_shell::internal::kShellWindowId_LauncherContainer)-> + SetLayoutManager(shelf_layout_manager); + + internal::StatusAreaLayoutManager* status_area_layout_manager = + new internal::StatusAreaLayoutManager(shelf_layout_manager); + GetContainer(aura_shell::internal::kShellWindowId_StatusContainer)-> + SetLayoutManager(status_area_layout_manager); if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraNoShadows)) shadow_controller_.reset(new internal::ShadowController()); @@ -217,7 +225,7 @@ void Shell::Init() { internal::ToplevelLayoutManager* toplevel_layout_manager = new internal::ToplevelLayoutManager(); default_container->SetLayoutManager(toplevel_layout_manager); - toplevel_layout_manager->set_shelf(shelf_layout_controller_.get()); + toplevel_layout_manager->set_shelf(shelf_layout_manager); } // Force a layout. diff --git a/ui/aura_shell/shell.h b/ui/aura_shell/shell.h index ae5f7c1..ca8d2bf 100644 --- a/ui/aura_shell/shell.h +++ b/ui/aura_shell/shell.h @@ -35,7 +35,6 @@ namespace internal { class AppList; class DragDropController; class ShadowController; -class ShelfLayoutController; class ShellAcceleratorFilter; class WorkspaceController; } @@ -112,7 +111,6 @@ class AURA_SHELL_EXPORT Shell { scoped_ptr drag_drop_controller_; scoped_ptr workspace_controller_; - scoped_ptr shelf_layout_controller_; scoped_ptr shadow_controller_; // An event filter that pre-handles global accelerators. diff --git a/ui/aura_shell/status_area_layout_manager.cc b/ui/aura_shell/status_area_layout_manager.cc new file mode 100644 index 0000000..0ac94ed --- /dev/null +++ b/ui/aura_shell/status_area_layout_manager.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2011 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 "ui/aura_shell/status_area_layout_manager.h" + +#include "base/auto_reset.h" +#include "ui/aura_shell/shelf_layout_manager.h" + +namespace aura_shell { +namespace internal { + +//////////////////////////////////////////////////////////////////////////////// +// StatusAreaLayoutManager, public: + +StatusAreaLayoutManager::StatusAreaLayoutManager(ShelfLayoutManager* shelf) + : in_layout_(false), + shelf_(shelf) { +} + +StatusAreaLayoutManager::~StatusAreaLayoutManager() { +} + +//////////////////////////////////////////////////////////////////////////////// +// StatusAreaLayoutManager, aura::LayoutManager implementation: + +void StatusAreaLayoutManager::OnWindowResized() { + LayoutStatusArea(); +} + +void StatusAreaLayoutManager::OnWindowAddedToLayout(aura::Window* child) { +} + +void StatusAreaLayoutManager::OnWillRemoveWindowFromLayout( + aura::Window* child) { +} + +void StatusAreaLayoutManager::OnChildWindowVisibilityChanged( + aura::Window* child, bool visible) { +} + +void StatusAreaLayoutManager::SetChildBounds( + aura::Window* child, const gfx::Rect& requested_bounds) { + SetChildBoundsDirect(child, requested_bounds); + if (!in_layout_) + LayoutStatusArea(); +} + +//////////////////////////////////////////////////////////////////////////////// +// StatusAreaLayoutManager, private: + +void StatusAreaLayoutManager::LayoutStatusArea() { + // Shelf layout manager may be already doing layout. + if (shelf_->in_layout()) + return; + + AutoReset auto_reset_in_layout(&in_layout_, true); + shelf_->LayoutShelf(); +} + +} // internal +} // aura_shell diff --git a/ui/aura_shell/status_area_layout_manager.h b/ui/aura_shell/status_area_layout_manager.h new file mode 100644 index 0000000..a5984b0 --- /dev/null +++ b/ui/aura_shell/status_area_layout_manager.h @@ -0,0 +1,52 @@ +// Copyright (c) 2011 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 UI_AURA_SHELL_STATUS_AREA_LAYOUT_MANAGER_H_ +#define UI_AURA_SHELL_STATUS_AREA_LAYOUT_MANAGER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ui/aura/layout_manager.h" + +namespace aura_shell { +namespace internal { + +class ShelfLayoutManager; + +// StatusAreaLayoutManager is a layout manager responsible for the status area. +// In any case when status area needs relayout it redirects this call to +// ShelfLayoutManager. +class StatusAreaLayoutManager : public aura::LayoutManager { + public: + explicit StatusAreaLayoutManager(ShelfLayoutManager* shelf); + virtual ~StatusAreaLayoutManager(); + + // Overridden from aura::LayoutManager: + virtual void OnWindowResized() OVERRIDE; + virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; + virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; + virtual void OnChildWindowVisibilityChanged(aura::Window* child, + bool visible) OVERRIDE; + virtual void SetChildBounds(aura::Window* child, + const gfx::Rect& requested_bounds) OVERRIDE; + + private: + // Updates layout of the status area. Effectively calls ShelfLayoutManager + // to update layout of the shelf. + void LayoutStatusArea(); + + // True when inside LayoutStatusArea method. + // Used to prevent calling itself again from SetChildBounds(). + bool in_layout_; + + ShelfLayoutManager* shelf_; + + DISALLOW_COPY_AND_ASSIGN(StatusAreaLayoutManager); +}; + +} // namespace internal +} // namespace aura_shell + +#endif // UI_AURA_SHELL_STATUS_AREA_LAYOUT_MANAGER_H_ diff --git a/ui/aura_shell/toplevel_layout_manager.cc b/ui/aura_shell/toplevel_layout_manager.cc index 6c6e715..05d5f47 100644 --- a/ui/aura_shell/toplevel_layout_manager.cc +++ b/ui/aura_shell/toplevel_layout_manager.cc @@ -7,7 +7,7 @@ #include "ui/aura/client/aura_constants.h" #include "ui/aura/window.h" #include "ui/aura_shell/property_util.h" -#include "ui/aura_shell/shelf_layout_controller.h" +#include "ui/aura_shell/shelf_layout_manager.h" #include "ui/aura_shell/workspace/workspace.h" #include "ui/aura_shell/workspace/workspace_manager.h" #include "ui/base/ui_base_types.h" diff --git a/ui/aura_shell/toplevel_layout_manager.h b/ui/aura_shell/toplevel_layout_manager.h index 4c66ce7..a02b8b1 100644 --- a/ui/aura_shell/toplevel_layout_manager.h +++ b/ui/aura_shell/toplevel_layout_manager.h @@ -17,7 +17,7 @@ namespace aura_shell { namespace internal { -class ShelfLayoutController; +class ShelfLayoutManager; // ToplevelLayoutManager is the LayoutManager installed on a container that // hosts what the shell considers to be top-level windows. It is used if the @@ -29,7 +29,7 @@ class AURA_SHELL_EXPORT ToplevelLayoutManager : public aura::LayoutManager, ToplevelLayoutManager(); virtual ~ToplevelLayoutManager(); - void set_shelf(ShelfLayoutController* shelf) { shelf_ = shelf; } + void set_shelf(ShelfLayoutManager* shelf) { shelf_ = shelf; } // LayoutManager overrides: virtual void OnWindowResized() OVERRIDE; @@ -58,7 +58,7 @@ class AURA_SHELL_EXPORT ToplevelLayoutManager : public aura::LayoutManager, // Set of windows we're listening to. Windows windows_; - ShelfLayoutController* shelf_; + ShelfLayoutManager* shelf_; DISALLOW_COPY_AND_ASSIGN(ToplevelLayoutManager); }; -- cgit v1.1