| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/wm/panel_layout_manager.h" | 5 #include "ash/wm/panel_layout_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/launcher/launcher.h" | 9 #include "ash/launcher/launcher.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // PanelLayoutManager public implementation: | 34 // PanelLayoutManager public implementation: |
| 35 | 35 |
| 36 PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container) | 36 PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container) |
| 37 : panel_container_(panel_container), | 37 : panel_container_(panel_container), |
| 38 in_layout_(false), | 38 in_layout_(false), |
| 39 dragged_panel_(NULL) { | 39 dragged_panel_(NULL) { |
| 40 DCHECK(panel_container); | 40 DCHECK(panel_container); |
| 41 } | 41 } |
| 42 | 42 |
| 43 PanelLayoutManager::~PanelLayoutManager() { | 43 PanelLayoutManager::~PanelLayoutManager() { |
| 44 ash::Launcher* launcher = ash::Shell::GetInstance()->launcher(); |
| 45 if (launcher != NULL) |
| 46 launcher->RemoveIconObserver(this); |
| 44 } | 47 } |
| 45 | 48 |
| 46 void PanelLayoutManager::StartDragging(aura::Window* panel) { | 49 void PanelLayoutManager::StartDragging(aura::Window* panel) { |
| 47 DCHECK(dragged_panel_ == NULL); | 50 DCHECK(dragged_panel_ == NULL); |
| 48 DCHECK(panel->parent() == panel_container_); | 51 DCHECK(panel->parent() == panel_container_); |
| 49 dragged_panel_ = panel; | 52 dragged_panel_ = panel; |
| 50 } | 53 } |
| 51 | 54 |
| 52 void PanelLayoutManager::FinishDragging() { | 55 void PanelLayoutManager::FinishDragging() { |
| 53 DCHECK(dragged_panel_ != NULL); | 56 DCHECK(dragged_panel_ != NULL); |
| 54 dragged_panel_ = NULL; | 57 dragged_panel_ = NULL; |
| 55 Relayout(); | 58 Relayout(); |
| 56 } | 59 } |
| 57 | 60 |
| 61 void PanelLayoutManager::SetLauncher(ash::Launcher* launcher) { |
| 62 launcher->AddIconObserver(this); |
| 63 } |
| 64 |
| 58 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { | 65 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { |
| 59 DCHECK(panel->parent() == panel_container_); | 66 DCHECK(panel->parent() == panel_container_); |
| 60 if (panel->GetProperty(aura::client::kShowStateKey) == | 67 if (panel->GetProperty(aura::client::kShowStateKey) == |
| 61 ui::SHOW_STATE_MINIMIZED) { | 68 ui::SHOW_STATE_MINIMIZED) { |
| 62 const gfx::Rect& old_bounds = panel->bounds(); | 69 const gfx::Rect& old_bounds = panel->bounds(); |
| 63 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 70 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 64 | 71 |
| 65 gfx::Rect new_bounds(old_bounds); | 72 gfx::Rect new_bounds(old_bounds); |
| 66 const gfx::Rect* restore_bounds = GetRestoreBounds(panel); | 73 const gfx::Rect* restore_bounds = GetRestoreBounds(panel); |
| 67 if (restore_bounds != NULL) { | 74 if (restore_bounds != NULL) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 148 } |
| 142 } | 149 } |
| 143 | 150 |
| 144 SetChildBoundsDirect(child, bounds); | 151 SetChildBoundsDirect(child, bounds); |
| 145 Relayout(); | 152 Relayout(); |
| 146 } | 153 } |
| 147 | 154 |
| 148 //////////////////////////////////////////////////////////////////////////////// | 155 //////////////////////////////////////////////////////////////////////////////// |
| 149 // PanelLayoutManager private implementation: | 156 // PanelLayoutManager private implementation: |
| 150 | 157 |
| 158 |
| 159 void PanelLayoutManager::OnLauncherIconPositionsChanged() { |
| 160 Relayout(); |
| 161 } |
| 162 |
| 151 // This is a rough outline of a simple panel layout manager. | 163 // This is a rough outline of a simple panel layout manager. |
| 152 void PanelLayoutManager::Relayout() { | 164 void PanelLayoutManager::Relayout() { |
| 153 if (in_layout_) | 165 if (in_layout_) |
| 154 return; | 166 return; |
| 155 AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | 167 AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
| 156 | 168 |
| 157 // Panels are currently laid out just above the launcher (if it exists), | |
| 158 // otherwise at the bottom of the root window. | |
| 159 int right, bottom; | |
| 160 ash::Shell* shell = ash::Shell::GetInstance(); | 169 ash::Shell* shell = ash::Shell::GetInstance(); |
| 161 if (shell->launcher() && shell->launcher()->widget()->IsVisible()) { | |
| 162 const gfx::Rect& bounds = | |
| 163 shell->launcher()->widget()->GetWindowScreenBounds(); | |
| 164 right = bounds.width() - 1 - kPanelMarginEdge; | |
| 165 bottom = bounds.y() - 1; | |
| 166 } else { | |
| 167 const gfx::Rect& bounds = panel_container_->GetRootWindow()->bounds(); | |
| 168 right = bounds.width() - 1 - kPanelMarginEdge; | |
| 169 bottom = bounds.bottom() - 1; | |
| 170 } | |
| 171 | 170 |
| 172 // Layout the panel windows right to left. | |
| 173 for (PanelList::iterator iter = panel_windows_.begin(); | 171 for (PanelList::iterator iter = panel_windows_.begin(); |
| 174 iter != panel_windows_.end(); ++iter) { | 172 iter != panel_windows_.end(); ++iter) { |
| 175 aura::Window* panel_win = *iter; | 173 aura::Window* panel_win = *iter; |
| 176 if (!panel_win->IsVisible()) | 174 if (!panel_win->IsVisible()) |
| 177 continue; | 175 continue; |
| 178 int x = right - panel_win->bounds().width(); | 176 |
| 179 int y = bottom - panel_win->bounds().height(); | 177 gfx::Rect icon_rect = |
| 178 shell->launcher()->GetScreenBoundsOfItemIconForWindow(panel_win); |
| 179 |
| 180 // Empty rect indicates that there is no icon for the panel in the launcher, |
| 181 // so there is nowhere to attach it to. Keeping the bounds. |
| 182 if (icon_rect.IsEmpty()) |
| 183 continue; |
| 180 | 184 |
| 181 // Do not relayout dragged panel, but pretend it is in place | 185 // Do not relayout dragged panel, but pretend it is in place |
| 182 if (panel_win != dragged_panel_) { | 186 if (panel_win != dragged_panel_) { |
| 183 gfx::Rect bounds(x, y, | 187 gfx::Point icon_origin = icon_rect.origin(); |
| 184 panel_win->bounds().width(), | 188 aura::Window::ConvertPointToWindow(panel_container_->GetRootWindow(), |
| 185 panel_win->bounds().height()); | 189 panel_container_, &icon_origin); |
| 190 |
| 191 gfx::Rect current_bounds = panel_win->bounds(); |
| 192 |
| 193 gfx::Rect bounds( |
| 194 icon_origin.x() + icon_rect.width()/2 - current_bounds.width()/2, |
| 195 icon_origin.y() - current_bounds.height(), |
| 196 current_bounds.width(), |
| 197 current_bounds.height()); |
| 186 SetChildBoundsDirect(panel_win, bounds); | 198 SetChildBoundsDirect(panel_win, bounds); |
| 187 } | 199 } |
| 188 right = x - kPanelMarginMiddle; | |
| 189 } | 200 } |
| 190 } | 201 } |
| 191 | 202 |
| 192 } // namespace internal | 203 } // namespace internal |
| 193 } // namespace ash | 204 } // namespace ash |
| OLD | NEW |