| 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 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "ash/launcher/launcher.h" | 10 #include "ash/launcher/launcher.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/wm/frame_painter.h" | 12 #include "ash/wm/frame_painter.h" |
| 13 #include "ash/wm/property_util.h" | 13 #include "ash/wm/property_util.h" |
| 14 #include "ash/wm/window_animations.h" |
| 15 #include "ash/wm/window_util.h" |
| 14 #include "base/auto_reset.h" | 16 #include "base/auto_reset.h" |
| 15 #include "base/bind.h" | 17 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 18 #include "base/bind_helpers.h" |
| 17 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
| 18 #include "third_party/skia/include/core/SkPaint.h" | 20 #include "third_party/skia/include/core/SkPaint.h" |
| 19 #include "third_party/skia/include/core/SkPath.h" | 21 #include "third_party/skia/include/core/SkPath.h" |
| 20 #include "ui/aura/client/activation_client.h" | 22 #include "ui/aura/client/activation_client.h" |
| 21 #include "ui/aura/client/aura_constants.h" | 23 #include "ui/aura/client/aura_constants.h" |
| 22 #include "ui/aura/root_window.h" | 24 #include "ui/aura/root_window.h" |
| 23 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| 24 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
| 25 #include "ui/gfx/rect.h" | 27 #include "ui/gfx/rect.h" |
| 26 #include "ui/views/background.h" | 28 #include "ui/views/background.h" |
| 27 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
| 28 | 30 |
| 29 namespace ash { | 31 namespace ash { |
| 30 namespace internal { | 32 namespace internal { |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 const int kPanelMarginEdge = 4; | 35 const int kPanelMarginEdge = 4; |
| 34 const int kPanelMarginMiddle = 8; | 36 const int kPanelMarginMiddle = 8; |
| 35 | 37 |
| 36 const int kMinimizedHeight = 24; | |
| 37 | |
| 38 const float kMaxHeightFactor = .80f; | 38 const float kMaxHeightFactor = .80f; |
| 39 const float kMaxWidthFactor = .50f; | 39 const float kMaxWidthFactor = .50f; |
| 40 | 40 |
| 41 // Callout arrow dimensions. | 41 // Callout arrow dimensions. |
| 42 const int kArrowWidth = 20; | 42 const int kArrowWidth = 20; |
| 43 const int kArrowHeight = 10; | 43 const int kArrowHeight = 10; |
| 44 | 44 |
| 45 class CalloutWidgetBackground : public views::Background { | 45 class CalloutWidgetBackground : public views::Background { |
| 46 public: | 46 public: |
| 47 CalloutWidgetBackground() {} | 47 CalloutWidgetBackground() {} |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 if (launcher_) | 100 if (launcher_) |
| 101 launcher_->RemoveIconObserver(this); | 101 launcher_->RemoveIconObserver(this); |
| 102 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> | 102 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> |
| 103 RemoveObserver(this); | 103 RemoveObserver(this); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void PanelLayoutManager::StartDragging(aura::Window* panel) { | 106 void PanelLayoutManager::StartDragging(aura::Window* panel) { |
| 107 DCHECK(!dragged_panel_); | 107 DCHECK(!dragged_panel_); |
| 108 DCHECK(panel->parent() == panel_container_); | 108 DCHECK(panel->parent() == panel_container_); |
| 109 dragged_panel_ = panel; | 109 dragged_panel_ = panel; |
| 110 Relayout(); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void PanelLayoutManager::FinishDragging() { | 113 void PanelLayoutManager::FinishDragging() { |
| 113 DCHECK(dragged_panel_); | 114 DCHECK(dragged_panel_); |
| 114 dragged_panel_ = NULL; | 115 dragged_panel_ = NULL; |
| 115 Relayout(); | 116 Relayout(); |
| 116 } | 117 } |
| 117 | 118 |
| 118 void PanelLayoutManager::SetLauncher(ash::Launcher* launcher) { | 119 void PanelLayoutManager::SetLauncher(ash::Launcher* launcher) { |
| 119 launcher_ = launcher; | 120 launcher_ = launcher; |
| 120 launcher_->AddIconObserver(this); | 121 launcher_->AddIconObserver(this); |
| 121 } | 122 } |
| 122 | 123 |
| 123 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { | 124 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { |
| 124 DCHECK(panel->parent() == panel_container_); | 125 DCHECK(panel->parent() == panel_container_); |
| 125 if (panel->GetProperty(aura::client::kShowStateKey) == | 126 if (panel->GetProperty(aura::client::kShowStateKey) == |
| 126 ui::SHOW_STATE_MINIMIZED) { | 127 ui::SHOW_STATE_MINIMIZED) { |
| 127 const gfx::Rect& old_bounds = panel->bounds(); | |
| 128 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 128 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 129 | |
| 130 gfx::Rect new_bounds(old_bounds); | |
| 131 const gfx::Rect* restore_bounds = GetRestoreBoundsInScreen(panel); | |
| 132 if (restore_bounds) { | |
| 133 new_bounds.set_height(restore_bounds->height()); | |
| 134 new_bounds.set_y(old_bounds.bottom() - restore_bounds->height()); | |
| 135 SetChildBounds(panel, new_bounds); | |
| 136 ClearRestoreBounds(panel); | |
| 137 } | |
| 138 } else { | 129 } else { |
| 139 const gfx::Rect& old_bounds = panel->bounds(); | |
| 140 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 130 panel->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 141 SetRestoreBoundsInParent(panel, old_bounds); | |
| 142 SetChildBounds(panel, | |
| 143 gfx::Rect(old_bounds.x(), | |
| 144 old_bounds.bottom() - kMinimizedHeight, | |
| 145 old_bounds.width(), | |
| 146 kMinimizedHeight)); | |
| 147 } | 131 } |
| 148 Relayout(); | |
| 149 } | 132 } |
| 150 | 133 |
| 151 //////////////////////////////////////////////////////////////////////////////// | 134 //////////////////////////////////////////////////////////////////////////////// |
| 152 // PanelLayoutManager, aura::LayoutManager implementation: | 135 // PanelLayoutManager, aura::LayoutManager implementation: |
| 153 void PanelLayoutManager::OnWindowResized() { | 136 void PanelLayoutManager::OnWindowResized() { |
| 154 Relayout(); | 137 Relayout(); |
| 155 } | 138 } |
| 156 | 139 |
| 157 void PanelLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 140 void PanelLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 158 if (child == callout_widget_->GetNativeWindow()) | 141 if (child == callout_widget_->GetNativeWindow()) |
| 159 return; | 142 return; |
| 160 panel_windows_.push_back(child); | 143 panel_windows_.push_back(child); |
| 144 child->AddObserver(this); |
| 161 Relayout(); | 145 Relayout(); |
| 162 } | 146 } |
| 163 | 147 |
| 164 void PanelLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { | 148 void PanelLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { |
| 165 PanelList::iterator found = | 149 PanelList::iterator found = |
| 166 std::find(panel_windows_.begin(), panel_windows_.end(), child); | 150 std::find(panel_windows_.begin(), panel_windows_.end(), child); |
| 167 if (found != panel_windows_.end()) | 151 if (found != panel_windows_.end()) |
| 168 panel_windows_.erase(found); | 152 panel_windows_.erase(found); |
| 153 child->RemoveObserver(this); |
| 169 | 154 |
| 170 if (dragged_panel_ == child) | 155 if (dragged_panel_ == child) |
| 171 dragged_panel_ = NULL; | 156 dragged_panel_ = NULL; |
| 172 | 157 |
| 173 if (last_active_panel_ == child) | 158 if (last_active_panel_ == child) |
| 174 last_active_panel_ = NULL; | 159 last_active_panel_ = NULL; |
| 175 | 160 |
| 176 Relayout(); | 161 Relayout(); |
| 177 } | 162 } |
| 178 | 163 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
| 221 // PanelLayoutManager, ash::LauncherIconObserver implementation: | 206 // PanelLayoutManager, ash::LauncherIconObserver implementation: |
| 222 | 207 |
| 223 void PanelLayoutManager::OnLauncherIconPositionsChanged() { | 208 void PanelLayoutManager::OnLauncherIconPositionsChanged() { |
| 224 // TODO: As this is called for every animation step now. Relayout needs to be | 209 // TODO: As this is called for every animation step now. Relayout needs to be |
| 225 // updated to use current icon position instead of use the ideal bounds so | 210 // updated to use current icon position instead of use the ideal bounds so |
| 226 // that the panels slide with their icons instead of jumping. | 211 // that the panels slide with their icons instead of jumping. |
| 227 Relayout(); | 212 Relayout(); |
| 228 } | 213 } |
| 229 | 214 |
| 215 ///////////////////////////////////////////////////////////////////////////// |
| 216 // PanelLayoutManager, WindowObserver implementation: |
| 217 |
| 218 void PanelLayoutManager::OnWindowPropertyChanged(aura::Window* window, |
| 219 const void* key, |
| 220 intptr_t old) { |
| 221 if (key != aura::client::kShowStateKey) |
| 222 return; |
| 223 ui::WindowShowState new_state = |
| 224 window->GetProperty(aura::client::kShowStateKey); |
| 225 if (new_state == ui::SHOW_STATE_MINIMIZED) |
| 226 MinimizePanel(window); |
| 227 else |
| 228 RestorePanel(window); |
| 229 } |
| 230 |
| 230 //////////////////////////////////////////////////////////////////////////////// | 231 //////////////////////////////////////////////////////////////////////////////// |
| 231 // PanelLayoutManager, aura::client::ActivationChangeObserver implementation: | 232 // PanelLayoutManager, aura::client::ActivationChangeObserver implementation: |
| 232 void PanelLayoutManager::OnWindowActivated(aura::Window* active, | 233 void PanelLayoutManager::OnWindowActivated(aura::Window* active, |
| 233 aura::Window* old_active) { | 234 aura::Window* old_active) { |
| 234 if (active && active->type() == aura::client::WINDOW_TYPE_PANEL) { | 235 if (active && active->type() == aura::client::WINDOW_TYPE_PANEL) { |
| 235 UpdateStacking(active); | 236 UpdateStacking(active); |
| 236 UpdateCallout(active); | 237 UpdateCallout(active); |
| 237 } else { | 238 } else { |
| 238 UpdateCallout(NULL); | 239 UpdateCallout(NULL); |
| 239 } | 240 } |
| 240 } | 241 } |
| 241 | 242 |
| 242 | 243 |
| 243 //////////////////////////////////////////////////////////////////////////////// | 244 //////////////////////////////////////////////////////////////////////////////// |
| 244 // PanelLayoutManager private implementation: | 245 // PanelLayoutManager private implementation: |
| 246 |
| 247 void PanelLayoutManager::MinimizePanel(aura::Window* panel) { |
| 248 SetWindowVisibilityAnimationType( |
| 249 panel, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); |
| 250 panel->Hide(); |
| 251 if (wm::IsActiveWindow(panel)) |
| 252 wm::DeactivateWindow(panel); |
| 253 Relayout(); |
| 254 } |
| 255 |
| 256 void PanelLayoutManager::RestorePanel(aura::Window* panel) { |
| 257 panel->Show(); |
| 258 wm::ActivateWindow(panel); |
| 259 Relayout(); |
| 260 } |
| 261 |
| 245 void PanelLayoutManager::Relayout() { | 262 void PanelLayoutManager::Relayout() { |
| 246 if (!launcher_ || !launcher_->widget()) | 263 if (!launcher_ || !launcher_->widget()) |
| 247 return; | 264 return; |
| 248 | 265 |
| 249 if (in_layout_) | 266 if (in_layout_) |
| 250 return; | 267 return; |
| 251 AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | 268 AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
| 252 | 269 |
| 253 int launcher_top = launcher_->widget()->GetWindowBoundsInScreen().y(); | 270 int launcher_top = launcher_->widget()->GetWindowBoundsInScreen().y(); |
| 254 aura::Window* active_panel = NULL; | 271 aura::Window* active_panel = NULL; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 callout_bounds.set_x( | 375 callout_bounds.set_x( |
| 359 bounds.x() + (bounds.width() - callout_bounds.width()) / 2); | 376 bounds.x() + (bounds.width() - callout_bounds.width()) / 2); |
| 360 callout_bounds.set_y(bounds.bottom()); | 377 callout_bounds.set_y(bounds.bottom()); |
| 361 SetChildBoundsDirect(callout_widget_->GetNativeWindow(), callout_bounds); | 378 SetChildBoundsDirect(callout_widget_->GetNativeWindow(), callout_bounds); |
| 362 panel_container_->StackChildAtTop(callout_widget_->GetNativeWindow()); | 379 panel_container_->StackChildAtTop(callout_widget_->GetNativeWindow()); |
| 363 callout_widget_->Show(); | 380 callout_widget_->Show(); |
| 364 } | 381 } |
| 365 | 382 |
| 366 } // namespace internal | 383 } // namespace internal |
| 367 } // namespace ash | 384 } // namespace ash |
| OLD | NEW |