diff --git a/ash/wm/dock/docked_window_layout_manager.cc b/ash/wm/dock/docked_window_layout_manager.cc index 71b8929049eb3f..87144109f02156 100644 --- a/ash/wm/dock/docked_window_layout_manager.cc +++ b/ash/wm/dock/docked_window_layout_manager.cc @@ -8,7 +8,6 @@ #include "ash/shelf/shelf.h" #include "ash/shelf/shelf_constants.h" #include "ash/shelf/shelf_layout_manager.h" -#include "ash/shelf/shelf_layout_manager_observer.h" #include "ash/shelf/shelf_types.h" #include "ash/shelf/shelf_widget.h" #include "ash/shell.h" @@ -58,8 +57,7 @@ const int kFadeDurationMs = 60; const int kMinimizeDurationMs = 720; class DockedBackgroundWidget : public views::Widget, - public BackgroundAnimatorDelegate, - public ShelfLayoutManagerObserver { + public BackgroundAnimatorDelegate { public: explicit DockedBackgroundWidget(aura::Window* container) : alignment_(DOCKED_ALIGNMENT_NONE), @@ -68,19 +66,9 @@ class DockedBackgroundWidget : public views::Widget, opaque_background_(ui::LAYER_SOLID_COLOR), visible_background_type_(SHELF_BACKGROUND_DEFAULT), visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { - Shelf* shelf = Shelf::ForWindow(container); - visible_background_type_ = shelf->shelf_widget()->GetBackgroundType(); - shelf->shelf_layout_manager()->AddObserver(this); - InitWidget(container); } - ~DockedBackgroundWidget() override { - Shelf* shelf = Shelf::ForWindow(GetNativeWindow()); - if (shelf && shelf->shelf_layout_manager()) - shelf->shelf_layout_manager()->RemoveObserver(this); - } - // Sets widget bounds and sizes opaque background layer to fill the widget. void SetBackgroundBounds(const gfx::Rect bounds, DockedAlignment alignment) { SetBounds(bounds); @@ -88,7 +76,17 @@ class DockedBackgroundWidget : public views::Widget, alignment_ = alignment; } - private: + // Sets the background type. Starts an animation to transition to + // |background_type| if the widget is visible. If the widget is not visible, + // the animation is postponed till the widget becomes visible. + void SetBackgroundType(ShelfBackgroundType background_type, + BackgroundAnimatorChangeType change_type) { + visible_background_type_ = background_type; + visible_background_change_type_ = change_type; + if (IsVisible()) + UpdateBackground(); + } + // views::Widget: void OnNativeWidgetVisibilityChanged(bool visible) override { views::Widget::OnNativeWidgetVisibilityChanged(visible); @@ -126,18 +124,7 @@ class DockedBackgroundWidget : public views::Widget, SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); } - // ShelfLayoutManagerObserver: - void OnBackgroundUpdated(ShelfBackgroundType background_type, - BackgroundAnimatorChangeType change_type) override { - // Sets the background type. Starts an animation to transition to - // |background_type| if the widget is visible. If the widget is not visible, - // the animation is postponed till the widget becomes visible. - visible_background_type_ = background_type; - visible_background_change_type_ = change_type; - if (IsVisible()) - UpdateBackground(); - } - + private: void InitWidget(aura::Window* parent) { views::Widget::InitParams params; params.type = views::Widget::InitParams::TYPE_POPUP; @@ -154,6 +141,7 @@ class DockedBackgroundWidget : public views::Widget, opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size())); opaque_background_.SetOpacity(0.0f); GetNativeWindow()->layer()->Add(&opaque_background_); + Hide(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); gfx::ImageSkia shelf_background = @@ -162,9 +150,6 @@ class DockedBackgroundWidget : public views::Widget, shelf_background, SkBitmapOperations::ROTATION_90_CW); shelf_background_right_ = gfx::ImageSkiaOperations::CreateRotatedImage( shelf_background, SkBitmapOperations::ROTATION_270_CW); - - // Stack the background below any windows already in the dock container. - parent->StackChildAtBottom(GetNativeWindow()); } // Transitions to |visible_background_type_| if the widget is visible and to @@ -416,10 +401,10 @@ DockedWindowLayoutManager::DockedWindowLayoutManager( : SnapToPixelLayoutManager(dock_container), dock_container_(dock_container), in_layout_(false), - dragged_window_(nullptr), + dragged_window_(NULL), is_dragged_window_docked_(false), is_dragged_from_dock_(false), - shelf_(nullptr), + shelf_(NULL), workspace_controller_(workspace_controller), in_fullscreen_(workspace_controller_->GetWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN), @@ -427,9 +412,9 @@ DockedWindowLayoutManager::DockedWindowLayoutManager( alignment_(DOCKED_ALIGNMENT_NONE), preferred_alignment_(DOCKED_ALIGNMENT_NONE), event_source_(DOCKED_ACTION_SOURCE_UNKNOWN), - last_active_window_(nullptr), + last_active_window_(NULL), last_action_time_(base::Time::Now()), - background_widget_(nullptr) { + background_widget_(new DockedBackgroundWidget(dock_container_)) { DCHECK(dock_container); aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> AddObserver(this); @@ -441,9 +426,11 @@ DockedWindowLayoutManager::~DockedWindowLayoutManager() { } void DockedWindowLayoutManager::Shutdown() { - background_widget_.reset(); - shelf_observer_.reset(); - shelf_ = nullptr; + if (shelf_ && shelf_->shelf_layout_manager()) { + shelf_->shelf_layout_manager()->RemoveObserver(this); + shelf_observer_.reset(); + } + shelf_ = NULL; for (size_t i = 0; i < dock_container_->children().size(); ++i) { aura::Window* child = dock_container_->children()[i]; child->RemoveObserver(this); @@ -530,7 +517,7 @@ void DockedWindowLayoutManager::FinishDragging(DockedAction action, dragged_window_->RemoveObserver(this); wm::GetWindowState(dragged_window_)->RemoveObserver(this); if (last_active_window_ == dragged_window_) - last_active_window_ = nullptr; + last_active_window_ = NULL; } else { // If this is the first window that got docked by a move update alignment. if (alignment_ == DOCKED_ALIGNMENT_NONE) @@ -541,7 +528,7 @@ void DockedWindowLayoutManager::FinishDragging(DockedAction action, // count limit so do it here. MaybeMinimizeChildrenExcept(dragged_window_); } - dragged_window_ = nullptr; + dragged_window_ = NULL; dragged_bounds_ = gfx::Rect(); Relayout(); UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); @@ -551,7 +538,10 @@ void DockedWindowLayoutManager::FinishDragging(DockedAction action, void DockedWindowLayoutManager::SetShelf(Shelf* shelf) { DCHECK(!shelf_); shelf_ = shelf; - shelf_observer_.reset(new ShelfWindowObserver(this)); + if (shelf_->shelf_layout_manager()) { + shelf_->shelf_layout_manager()->AddObserver(this); + shelf_observer_.reset(new ShelfWindowObserver(this)); + } } DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow( @@ -724,7 +714,7 @@ void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { UpdateDockedWidth(0); } if (last_active_window_ == child) - last_active_window_ = nullptr; + last_active_window_ = NULL; child->RemoveObserver(this); wm::GetWindowState(child)->RemoveObserver(this); Relayout(); @@ -830,6 +820,14 @@ void DockedWindowLayoutManager::OnShelfAlignmentChanged( UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED); } +///////////////////////////////////////////////////////////////////////////// +// DockedWindowLayoutManager, ShelfLayoutManagerObserver implementation: +void DockedWindowLayoutManager::OnBackgroundUpdated( + ShelfBackgroundType background_type, + BackgroundAnimatorChangeType change_type) { + background_widget_->SetBackgroundType(background_type, change_type); +} + ///////////////////////////////////////////////////////////////////////////// // DockedWindowLayoutManager, WindowStateObserver implementation: @@ -894,10 +892,11 @@ void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { DCHECK(!is_dragged_window_docked_); } if (window == last_active_window_) - last_active_window_ = nullptr; + last_active_window_ = NULL; RecordUmaAction(DOCKED_ACTION_CLOSE, event_source_); } + //////////////////////////////////////////////////////////////////////////////// // DockedWindowLayoutManager, aura::client::ActivationChangeObserver // implementation: @@ -909,7 +908,7 @@ void DockedWindowLayoutManager::OnWindowActivated( if (gained_active && IsPopupOrTransient(gained_active)) return; // Ignore if the window that is not managed by this was activated. - aura::Window* ancestor = nullptr; + aura::Window* ancestor = NULL; for (aura::Window* parent = gained_active; parent; parent = parent->parent()) { if (parent->parent() == dock_container_) { @@ -1076,7 +1075,7 @@ void DockedWindowLayoutManager::Relayout() { base::AutoReset auto_reset_in_layout(&in_layout_, true); gfx::Rect dock_bounds = dock_container_->GetBoundsInScreen(); - aura::Window* active_window = nullptr; + aura::Window* active_window = NULL; std::vector visible_windows; for (size_t i = 0; i < dock_container_->children().size(); ++i) { aura::Window* window(dock_container_->children()[i]); @@ -1207,8 +1206,9 @@ void DockedWindowLayoutManager::FanOutChildren( // Sort windows by their center positions and fan out overlapping // windows. std::sort(visible_windows->begin(), visible_windows->end(), - CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : nullptr, - dock_container_, delta)); + CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : NULL, + dock_container_, + delta)); for (std::vector::iterator iter = visible_windows->begin(); iter != visible_windows->end(); ++iter) { aura::Window* window = iter->window(); @@ -1292,14 +1292,11 @@ void DockedWindowLayoutManager::UpdateDockBounds( gfx::Rect background_bounds(docked_bounds_); if (shelf_observer_) background_bounds.Subtract(shelf_observer_->shelf_bounds_in_screen()); - if (docked_width_ > 0) { - if (!background_widget_) - background_widget_.reset(new DockedBackgroundWidget(dock_container_)); - background_widget_->SetBackgroundBounds(background_bounds, alignment_); + background_widget_->SetBackgroundBounds(background_bounds, alignment_); + if (docked_width_ > 0) background_widget_->Show(); - } else if (background_widget_) { + else background_widget_->Hide(); - } } void DockedWindowLayoutManager::UpdateStacking(aura::Window* active_window) { @@ -1335,7 +1332,7 @@ void DockedWindowLayoutManager::UpdateStacking(aura::Window* active_window) { } int active_center_y = active_window->bounds().CenterPoint().y(); - aura::Window* previous_window = nullptr; + aura::Window* previous_window = NULL; for (std::map::const_iterator it = window_ordering.begin(); it != window_ordering.end() && it->first < active_center_y; ++it) { diff --git a/ash/wm/dock/docked_window_layout_manager.h b/ash/wm/dock/docked_window_layout_manager.h index e89be0d814d2f9..b1589bd7110a0f 100644 --- a/ash/wm/dock/docked_window_layout_manager.h +++ b/ash/wm/dock/docked_window_layout_manager.h @@ -8,6 +8,7 @@ #include #include "ash/ash_export.h" +#include "ash/shelf/shelf_layout_manager_observer.h" #include "ash/shell_observer.h" #include "ash/snap_to_pixel_layout_manager.h" #include "ash/wm/dock/dock_types.h" @@ -40,6 +41,7 @@ class DockedBackgroundWidget; class DockedWindowLayoutManagerObserver; class DockedWindowResizerTest; class Shelf; +class ShelfLayoutManager; class WorkspaceController; struct WindowWithHeight { @@ -70,6 +72,7 @@ class ASH_EXPORT DockedWindowLayoutManager public aura::WindowObserver, public aura::client::ActivationChangeObserver, public keyboard::KeyboardControllerObserver, + public ShelfLayoutManagerObserver, public wm::WindowStateObserver { public: // Maximum width of the docked windows area. @@ -160,6 +163,10 @@ class ASH_EXPORT DockedWindowLayoutManager aura::Window* root_window) override; void OnShelfAlignmentChanged(aura::Window* root_window) override; + // ShelfLayoutManagerObserver: + void OnBackgroundUpdated(ShelfBackgroundType background_type, + BackgroundAnimatorChangeType change_type) override; + // wm::WindowStateObserver: void OnPreWindowStateTypeChange(wm::WindowState* window_state, wm::WindowStateType old_type) override;