Chromium Code Reviews| Index: ash/wm/panel_layout_manager.cc |
| diff --git a/ash/wm/panel_layout_manager.cc b/ash/wm/panel_layout_manager.cc |
| index d793428d12e41b278e119e66eaea1f9dc6ce21d2..54f20bb9209681829f12ce39b4a9cddf8c804674 100644 |
| --- a/ash/wm/panel_layout_manager.cc |
| +++ b/ash/wm/panel_layout_manager.cc |
| @@ -36,11 +36,15 @@ namespace internal { |
| PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container) |
| : panel_container_(panel_container), |
| in_layout_(false), |
| - dragged_panel_(NULL) { |
| + dragged_panel_(NULL), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(launcher_icons_observer_(this)){ |
| DCHECK(panel_container); |
| } |
| PanelLayoutManager::~PanelLayoutManager() { |
| + ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
| + if (launcher != NULL) |
| + launcher->RemoveIconsObserver(&launcher_icons_observer_); |
| } |
| void PanelLayoutManager::StartDragging(aura::Window* panel) { |
| @@ -55,6 +59,10 @@ void PanelLayoutManager::FinishDragging() { |
| Relayout(); |
| } |
| +void PanelLayoutManager::SetLauncher(ash::Launcher* launcher) { |
| + launcher->AddIconsObserver(&launcher_icons_observer_); |
| +} |
| + |
| void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { |
| DCHECK(panel->parent() == panel_container_); |
| if (panel->GetProperty(aura::client::kShowStateKey) == |
| @@ -148,44 +156,51 @@ void PanelLayoutManager::SetChildBounds(aura::Window* child, |
| //////////////////////////////////////////////////////////////////////////////// |
| // PanelLayoutManager private implementation: |
| +PanelLayoutManager::LauncherIconsObserver::LauncherIconsObserver( |
| + PanelLayoutManager* layout_manager) |
| + : layout_manager_(layout_manager) { |
| +} |
| + |
| +void PanelLayoutManager::LauncherIconsObserver |
| + ::OnLauncherIconPositionsChanged() { |
| + layout_manager_->Relayout(); |
| +} |
| + |
| // This is a rough outline of a simple panel layout manager. |
| void PanelLayoutManager::Relayout() { |
| if (in_layout_) |
| return; |
| AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
| - // Panels are currently laid out just above the launcher (if it exists), |
| - // otherwise at the bottom of the root window. |
| - int right, bottom; |
| ash::Shell* shell = ash::Shell::GetInstance(); |
| - if (shell->launcher() && shell->launcher()->widget()->IsVisible()) { |
| - const gfx::Rect& bounds = |
| - shell->launcher()->widget()->GetWindowScreenBounds(); |
| - right = bounds.width() - 1 - kPanelMarginEdge; |
| - bottom = bounds.y() - 1; |
| - } else { |
| - const gfx::Rect& bounds = panel_container_->GetRootWindow()->bounds(); |
| - right = bounds.width() - 1 - kPanelMarginEdge; |
| - bottom = bounds.bottom() - 1; |
| - } |
| - // Layout the panel windows right to left. |
| for (PanelList::iterator iter = panel_windows_.begin(); |
| iter != panel_windows_.end(); ++iter) { |
| aura::Window* panel_win = *iter; |
| + gfx::Rect icon_rect = |
| + shell->launcher()->GetScreenBoundsOfItemIconForWindow(panel_win); |
| + |
| + if (icon_rect.width() == 0 && icon_rect.height() == 0) |
|
stevenjb
2012/04/03 20:59:28
I believe this happens when the icon is not visibl
Dmitry Lomov (no reviews)
2012/04/03 21:18:23
Right, and used does not get any notification on i
|
| + continue; |
| + |
| + gfx::Point icon_origin = icon_rect.origin(); |
| + aura::Window::ConvertPointToWindow(panel_container_->GetRootWindow(), |
| + panel_container_, &icon_origin); |
|
stevenjb
2012/04/03 20:59:28
icon_origin only appears to be needed in the if bl
Dmitry Lomov (no reviews)
2012/04/03 21:18:23
You are right.
|
| + |
| if (!panel_win->IsVisible()) |
|
stevenjb
2012/04/03 20:59:28
We should probably move this early exit up to imme
Dmitry Lomov (no reviews)
2012/04/03 21:18:23
Right again.
|
| continue; |
| - int x = right - panel_win->bounds().width(); |
| - int y = bottom - panel_win->bounds().height(); |
| // Do not relayout dragged panel, but pretend it is in place |
| if (panel_win != dragged_panel_) { |
| - gfx::Rect bounds(x, y, |
| - panel_win->bounds().width(), |
| - panel_win->bounds().height()); |
| + gfx::Rect current_bounds = panel_win->bounds(); |
| + |
| + gfx::Rect bounds( |
| + icon_origin.x() + icon_rect.width()/2 - current_bounds.width()/2, |
| + icon_origin.y() - current_bounds.height(), |
| + current_bounds.width(), |
| + current_bounds.height()); |
| SetChildBoundsDirect(panel_win, bounds); |
| } |
| - right = x - kPanelMarginMiddle; |
| } |
| } |