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..227168847f4633178b0ccdc8ec69d37efdda8588 100644 |
--- a/ash/wm/panel_layout_manager.cc |
+++ b/ash/wm/panel_layout_manager.cc |
@@ -41,6 +41,9 @@ PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container) |
} |
PanelLayoutManager::~PanelLayoutManager() { |
+ ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
+ if (launcher != NULL) |
+ launcher->RemoveIconObserver(this); |
} |
void PanelLayoutManager::StartDragging(aura::Window* panel) { |
@@ -55,6 +58,10 @@ void PanelLayoutManager::FinishDragging() { |
Relayout(); |
} |
+void PanelLayoutManager::SetLauncher(ash::Launcher* launcher) { |
+ launcher->AddIconObserver(this); |
+} |
+ |
void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { |
DCHECK(panel->parent() == panel_container_); |
if (panel->GetProperty(aura::client::kShowStateKey) == |
@@ -148,44 +155,48 @@ void PanelLayoutManager::SetChildBounds(aura::Window* child, |
//////////////////////////////////////////////////////////////////////////////// |
// PanelLayoutManager private implementation: |
+ |
+void PanelLayoutManager::OnLauncherIconPositionsChanged() { |
+ 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; |
if (!panel_win->IsVisible()) |
continue; |
- int x = right - panel_win->bounds().width(); |
- int y = bottom - panel_win->bounds().height(); |
+ |
+ gfx::Rect icon_rect = |
+ shell->launcher()->GetScreenBoundsOfItemIconForWindow(panel_win); |
+ |
+ // Empty rect indicates that there is no icon for the panel in the launcher, |
+ // so there is nowhere to attach it to. Keeping the bounds. |
+ if (icon_rect.IsEmpty()) |
+ continue; |
// 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::Point icon_origin = icon_rect.origin(); |
+ aura::Window::ConvertPointToWindow(panel_container_->GetRootWindow(), |
+ panel_container_, &icon_origin); |
+ |
+ 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; |
} |
} |