Chromium Code Reviews| 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/panels/panel_layout_manager.h" | 5 #include "ash/wm/panels/panel_layout_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "ash/screen_util.h" | |
| 12 #include "ash/shelf/shelf.h" | 11 #include "ash/shelf/shelf.h" |
| 13 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
| 14 #include "ash/shelf/shelf_types.h" | 13 #include "ash/shelf/shelf_types.h" |
| 15 #include "ash/shelf/shelf_util.h" | 14 #include "ash/shelf/shelf_util.h" |
| 16 #include "ash/shelf/shelf_widget.h" | 15 #include "ash/shelf/shelf_widget.h" |
| 17 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 18 #include "ash/shell_window_ids.h" | 17 #include "ash/shell_window_ids.h" |
| 19 #include "ash/wm/aura/wm_window_aura.h" | 18 #include "ash/wm/aura/wm_window_aura.h" |
| 20 #include "ash/wm/common/window_animation_types.h" | 19 #include "ash/wm/common/window_animation_types.h" |
| 21 #include "ash/wm/common/window_parenting_utils.h" | 20 #include "ash/wm/common/window_parenting_utils.h" |
| 21 #include "ash/wm/common/wm_globals.h" | |
| 22 #include "ash/wm/common/wm_root_window_controller.h" | |
| 23 #include "ash/wm/common/wm_window.h" | |
| 24 #include "ash/wm/common/wm_window_property.h" | |
| 22 #include "ash/wm/overview/window_selector_controller.h" | 25 #include "ash/wm/overview/window_selector_controller.h" |
| 23 #include "ash/wm/window_animations.h" | 26 #include "ash/wm/window_animations.h" |
| 24 #include "ash/wm/window_state.h" | 27 #include "ash/wm/window_state.h" |
| 25 #include "ash/wm/window_state_aura.h" | |
| 26 #include "ash/wm/window_util.h" | |
| 27 #include "base/auto_reset.h" | 28 #include "base/auto_reset.h" |
| 28 #include "base/bind.h" | |
| 29 #include "base/bind_helpers.h" | |
| 30 #include "third_party/skia/include/core/SkColor.h" | 29 #include "third_party/skia/include/core/SkColor.h" |
| 31 #include "third_party/skia/include/core/SkPaint.h" | 30 #include "third_party/skia/include/core/SkPaint.h" |
| 32 #include "third_party/skia/include/core/SkPath.h" | 31 #include "third_party/skia/include/core/SkPath.h" |
| 33 #include "ui/aura/client/focus_client.h" | |
| 34 #include "ui/aura/client/window_tree_client.h" | |
| 35 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
| 36 #include "ui/aura/window_delegate.h" | |
| 37 #include "ui/aura/window_event_dispatcher.h" | |
| 38 #include "ui/compositor/scoped_layer_animation_settings.h" | 33 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 39 #include "ui/gfx/canvas.h" | 34 #include "ui/gfx/canvas.h" |
| 40 #include "ui/gfx/geometry/rect.h" | 35 #include "ui/gfx/geometry/rect.h" |
| 41 #include "ui/gfx/geometry/vector2d.h" | 36 #include "ui/gfx/geometry/vector2d.h" |
| 42 #include "ui/views/background.h" | 37 #include "ui/views/background.h" |
| 43 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
| 44 #include "ui/wm/public/activation_client.h" | |
| 45 | 39 |
| 46 namespace ash { | 40 namespace ash { |
| 47 namespace { | 41 namespace { |
| 48 | 42 |
| 49 const int kPanelIdealSpacing = 4; | 43 const int kPanelIdealSpacing = 4; |
| 50 | 44 |
| 51 const float kMaxHeightFactor = .80f; | 45 const float kMaxHeightFactor = .80f; |
| 52 const float kMaxWidthFactor = .50f; | 46 const float kMaxWidthFactor = .50f; |
| 53 | 47 |
| 54 // Duration for panel animations. | 48 // Duration for panel animations. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 max_major(0), | 107 max_major(0), |
| 114 major_pos(0), | 108 major_pos(0), |
| 115 major_length(0), | 109 major_length(0), |
| 116 window(NULL), | 110 window(NULL), |
| 117 slide_in(false) {} | 111 slide_in(false) {} |
| 118 | 112 |
| 119 int min_major; | 113 int min_major; |
| 120 int max_major; | 114 int max_major; |
| 121 int major_pos; | 115 int major_pos; |
| 122 int major_length; | 116 int major_length; |
| 123 aura::Window* window; | 117 wm::WmWindow* window; |
| 124 bool slide_in; | 118 bool slide_in; |
| 125 }; | 119 }; |
| 126 | 120 |
| 127 bool CompareWindowMajor(const VisiblePanelPositionInfo& win1, | 121 bool CompareWindowMajor(const VisiblePanelPositionInfo& win1, |
| 128 const VisiblePanelPositionInfo& win2) { | 122 const VisiblePanelPositionInfo& win2) { |
| 129 return win1.major_pos < win2.major_pos; | 123 return win1.major_pos < win2.major_pos; |
| 130 } | 124 } |
| 131 | 125 |
| 132 void FanOutPanels(std::vector<VisiblePanelPositionInfo>::iterator first, | 126 void FanOutPanels(std::vector<VisiblePanelPositionInfo>::iterator first, |
| 133 std::vector<VisiblePanelPositionInfo>::iterator last) { | 127 std::vector<VisiblePanelPositionInfo>::iterator last) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 offset.set_x(kPanelSlideInOffset); | 178 offset.set_x(kPanelSlideInOffset); |
| 185 else | 179 else |
| 186 offset.set_y(kPanelSlideInOffset); | 180 offset.set_y(kPanelSlideInOffset); |
| 187 return offset; | 181 return offset; |
| 188 } | 182 } |
| 189 | 183 |
| 190 } // namespace | 184 } // namespace |
| 191 | 185 |
| 192 class PanelCalloutWidget : public views::Widget { | 186 class PanelCalloutWidget : public views::Widget { |
| 193 public: | 187 public: |
| 194 explicit PanelCalloutWidget(aura::Window* container) | 188 explicit PanelCalloutWidget(wm::WmWindow* container) : background_(NULL) { |
|
James Cook
2016/04/25 17:16:05
optional: NULL -> nullptr while you're here?
sky
2016/04/25 18:17:57
Done.
| |
| 195 : background_(NULL) { | |
| 196 InitWidget(container); | 189 InitWidget(container); |
| 197 } | 190 } |
| 198 | 191 |
| 199 void SetAlignment(ShelfAlignment alignment) { | 192 void SetAlignment(ShelfAlignment alignment) { |
| 200 gfx::Rect callout_bounds = GetWindowBoundsInScreen(); | 193 gfx::Rect callout_bounds = GetWindowBoundsInScreen(); |
| 201 if (IsHorizontalAlignment(alignment)) { | 194 if (IsHorizontalAlignment(alignment)) { |
| 202 callout_bounds.set_width(kArrowWidth); | 195 callout_bounds.set_width(kArrowWidth); |
| 203 callout_bounds.set_height(kArrowHeight); | 196 callout_bounds.set_height(kArrowHeight); |
| 204 } else { | 197 } else { |
| 205 callout_bounds.set_width(kArrowHeight); | 198 callout_bounds.set_width(kArrowHeight); |
| 206 callout_bounds.set_height(kArrowWidth); | 199 callout_bounds.set_height(kArrowWidth); |
| 207 } | 200 } |
| 208 GetNativeWindow()->SetBounds(callout_bounds); | 201 SetBounds(callout_bounds); |
| 209 if (background_->alignment() != alignment) { | 202 if (background_->alignment() != alignment) { |
| 210 background_->set_alignment(alignment); | 203 background_->set_alignment(alignment); |
| 211 SchedulePaintInRect(gfx::Rect(gfx::Point(), callout_bounds.size())); | 204 SchedulePaintInRect(gfx::Rect(callout_bounds.size())); |
| 212 } | 205 } |
| 213 } | 206 } |
| 214 | 207 |
| 215 private: | 208 private: |
| 216 void InitWidget(aura::Window* parent) { | 209 void InitWidget(wm::WmWindow* parent) { |
| 217 views::Widget::InitParams params; | 210 views::Widget::InitParams params; |
| 218 params.type = views::Widget::InitParams::TYPE_POPUP; | 211 params.type = views::Widget::InitParams::TYPE_POPUP; |
| 219 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 212 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 220 params.keep_on_top = true; | 213 params.keep_on_top = true; |
| 221 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 214 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 222 params.parent = parent; | 215 params.bounds = parent->ConvertRectToScreen(gfx::Rect()); |
| 223 params.bounds = ScreenUtil::ConvertRectToScreen(parent, gfx::Rect()); | |
| 224 params.bounds.set_width(kArrowWidth); | 216 params.bounds.set_width(kArrowWidth); |
| 225 params.bounds.set_height(kArrowHeight); | 217 params.bounds.set_height(kArrowHeight); |
| 226 params.accept_events = false; | 218 params.accept_events = false; |
| 219 parent->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( | |
| 220 this, parent->GetShellWindowId(), ¶ms); | |
| 227 set_focus_on_creation(false); | 221 set_focus_on_creation(false); |
| 228 Init(params); | 222 Init(params); |
| 229 DCHECK_EQ(GetNativeView()->GetRootWindow(), parent->GetRootWindow()); | 223 wm::WmWindow* widget_window = wm::WmWindow::Get(this); |
| 224 DCHECK_EQ(widget_window->GetRootWindow(), parent->GetRootWindow()); | |
| 230 views::View* content_view = new views::View; | 225 views::View* content_view = new views::View; |
| 231 background_ = new CalloutWidgetBackground; | 226 background_ = new CalloutWidgetBackground; |
| 232 content_view->set_background(background_); | 227 content_view->set_background(background_); |
| 233 SetContentsView(content_view); | 228 SetContentsView(content_view); |
| 234 GetNativeWindow()->layer()->SetOpacity(0); | 229 widget_window->GetLayer()->SetOpacity(0); |
| 235 } | 230 } |
| 236 | 231 |
| 237 // Weak pointer owned by this widget's content view. | 232 // Weak pointer owned by this widget's content view. |
| 238 CalloutWidgetBackground* background_; | 233 CalloutWidgetBackground* background_; |
| 239 | 234 |
| 240 DISALLOW_COPY_AND_ASSIGN(PanelCalloutWidget); | 235 DISALLOW_COPY_AND_ASSIGN(PanelCalloutWidget); |
| 241 }; | 236 }; |
| 242 | 237 |
| 238 views::Widget* PanelLayoutManager::PanelInfo::CalloutWidget() { | |
| 239 return callout_widget; | |
| 240 } | |
| 241 | |
| 243 //////////////////////////////////////////////////////////////////////////////// | 242 //////////////////////////////////////////////////////////////////////////////// |
| 244 // PanelLayoutManager public implementation: | 243 // PanelLayoutManager public implementation: |
| 245 PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container) | 244 PanelLayoutManager::PanelLayoutManager(wm::WmWindow* panel_container) |
| 246 : panel_container_(panel_container), | 245 : panel_container_(panel_container), |
| 246 root_window_controller_(panel_container->GetRootWindowController()), | |
| 247 in_add_window_(false), | 247 in_add_window_(false), |
| 248 in_layout_(false), | 248 in_layout_(false), |
| 249 show_callout_widgets_(true), | 249 show_callout_widgets_(true), |
| 250 dragged_panel_(NULL), | 250 dragged_panel_(NULL), |
| 251 shelf_(NULL), | 251 shelf_(NULL), |
| 252 shelf_layout_manager_(NULL), | 252 shelf_layout_manager_(NULL), |
| 253 last_active_panel_(NULL), | 253 last_active_panel_(NULL), |
| 254 weak_factory_(this) { | 254 weak_factory_(this) { |
| 255 DCHECK(panel_container); | 255 DCHECK(panel_container); |
| 256 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> | 256 wm::WmGlobals* globals = panel_container->GetGlobals(); |
| 257 AddObserver(this); | 257 globals->AddActivationObserver(this); |
| 258 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); | 258 globals->AddDisplayObserver(this); |
| 259 Shell::GetInstance()->AddShellObserver(this); | 259 globals->AddOverviewModeObserver(this); |
| 260 root_window_controller_->AddObserver(this); | |
| 260 } | 261 } |
| 261 | 262 |
| 262 PanelLayoutManager::~PanelLayoutManager() { | 263 PanelLayoutManager::~PanelLayoutManager() { |
| 263 Shutdown(); | 264 Shutdown(); |
| 264 } | 265 } |
| 265 | 266 |
| 267 // static | |
| 268 PanelLayoutManager* PanelLayoutManager::Get(wm::WmWindow* window) { | |
| 269 if (!window) | |
| 270 return nullptr; | |
| 271 | |
| 272 return static_cast<PanelLayoutManager*>( | |
| 273 window->GetRootWindow() | |
| 274 ->GetChildByShellWindowId(kShellWindowId_PanelContainer) | |
| 275 ->GetLayoutManager()); | |
| 276 } | |
| 277 | |
| 266 void PanelLayoutManager::Shutdown() { | 278 void PanelLayoutManager::Shutdown() { |
| 267 if (shelf_layout_manager_) | 279 if (shelf_layout_manager_) |
| 268 shelf_layout_manager_->RemoveObserver(this); | 280 shelf_layout_manager_->RemoveObserver(this); |
| 269 shelf_layout_manager_ = NULL; | 281 shelf_layout_manager_ = NULL; |
| 270 for (PanelList::iterator iter = panel_windows_.begin(); | 282 for (PanelList::iterator iter = panel_windows_.begin(); |
| 271 iter != panel_windows_.end(); ++iter) { | 283 iter != panel_windows_.end(); ++iter) { |
| 272 delete iter->callout_widget; | 284 delete iter->callout_widget; |
| 273 } | 285 } |
| 274 panel_windows_.clear(); | 286 panel_windows_.clear(); |
| 275 if (shelf_) | 287 if (shelf_) |
| 276 shelf_->RemoveIconObserver(this); | 288 shelf_->RemoveIconObserver(this); |
| 277 shelf_ = NULL; | 289 shelf_ = NULL; |
| 278 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> | 290 wm::WmGlobals* globals = panel_container_->GetGlobals(); |
| 279 RemoveObserver(this); | 291 globals->RemoveActivationObserver(this); |
| 280 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | 292 globals->RemoveDisplayObserver(this); |
| 281 Shell::GetInstance()->RemoveShellObserver(this); | 293 globals->RemoveOverviewModeObserver(this); |
| 294 root_window_controller_->RemoveObserver(this); | |
| 282 } | 295 } |
| 283 | 296 |
| 284 void PanelLayoutManager::StartDragging(aura::Window* panel) { | 297 void PanelLayoutManager::StartDragging(wm::WmWindow* panel) { |
| 285 DCHECK(!dragged_panel_); | 298 DCHECK(!dragged_panel_); |
| 286 dragged_panel_ = panel; | 299 dragged_panel_ = panel; |
| 287 Relayout(); | 300 Relayout(); |
| 288 } | 301 } |
| 289 | 302 |
| 290 void PanelLayoutManager::FinishDragging() { | 303 void PanelLayoutManager::FinishDragging() { |
| 291 dragged_panel_ = NULL; | 304 dragged_panel_ = NULL; |
| 292 Relayout(); | 305 Relayout(); |
| 293 } | 306 } |
| 294 | 307 |
| 295 void PanelLayoutManager::SetShelf(Shelf* shelf) { | 308 void PanelLayoutManager::SetShelf(Shelf* shelf) { |
| 296 DCHECK(!shelf_); | 309 DCHECK(!shelf_); |
| 297 DCHECK(!shelf_layout_manager_); | 310 DCHECK(!shelf_layout_manager_); |
| 298 shelf_ = shelf; | 311 shelf_ = shelf; |
| 299 shelf_->AddIconObserver(this); | 312 shelf_->AddIconObserver(this); |
| 300 if (shelf_->shelf_layout_manager()) { | 313 if (shelf_->shelf_layout_manager()) { |
| 301 shelf_layout_manager_ = shelf_->shelf_layout_manager(); | 314 shelf_layout_manager_ = shelf_->shelf_layout_manager(); |
| 302 WillChangeVisibilityState(shelf_layout_manager_->visibility_state()); | 315 WillChangeVisibilityState(shelf_layout_manager_->visibility_state()); |
| 303 shelf_layout_manager_->AddObserver(this); | 316 shelf_layout_manager_->AddObserver(this); |
| 304 } | 317 } |
| 305 } | 318 } |
| 306 | 319 |
| 307 void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { | 320 void PanelLayoutManager::ToggleMinimize(wm::WmWindow* panel) { |
| 308 DCHECK(panel->parent() == panel_container_); | 321 DCHECK(panel->GetParent() == panel_container_); |
| 309 wm::WindowState* window_state = wm::GetWindowState(panel); | 322 wm::WindowState* window_state = panel->GetWindowState(); |
| 310 if (window_state->IsMinimized()) | 323 if (window_state->IsMinimized()) |
| 311 window_state->Restore(); | 324 window_state->Restore(); |
| 312 else | 325 else |
| 313 window_state->Minimize(); | 326 window_state->Minimize(); |
| 314 } | 327 } |
| 315 | 328 |
| 316 void PanelLayoutManager::SetShowCalloutWidgets(bool show) { | 329 void PanelLayoutManager::SetShowCalloutWidgets(bool show) { |
| 317 if (show_callout_widgets_ == show) | 330 if (show_callout_widgets_ == show) |
| 318 return; | 331 return; |
| 319 show_callout_widgets_ = show; | 332 show_callout_widgets_ = show; |
| 320 UpdateCallouts(); | 333 UpdateCallouts(); |
| 321 } | 334 } |
| 322 | 335 |
| 323 views::Widget* PanelLayoutManager::GetCalloutWidgetForPanel( | 336 views::Widget* PanelLayoutManager::GetCalloutWidgetForPanel( |
| 324 aura::Window* panel) { | 337 wm::WmWindow* panel) { |
| 325 DCHECK(panel->parent() == panel_container_); | 338 DCHECK(panel->GetParent() == panel_container_); |
| 326 PanelList::iterator found = | 339 PanelList::iterator found = |
| 327 std::find(panel_windows_.begin(), panel_windows_.end(), panel); | 340 std::find(panel_windows_.begin(), panel_windows_.end(), panel); |
| 328 DCHECK(found != panel_windows_.end()); | 341 DCHECK(found != panel_windows_.end()); |
| 329 return found->callout_widget; | 342 return found->callout_widget; |
| 330 } | 343 } |
| 331 | 344 |
| 332 //////////////////////////////////////////////////////////////////////////////// | 345 //////////////////////////////////////////////////////////////////////////////// |
| 333 // PanelLayoutManager, aura::LayoutManager implementation: | 346 // PanelLayoutManager, wm::WmLayoutManager implementation: |
| 334 void PanelLayoutManager::OnWindowResized() { | 347 void PanelLayoutManager::OnWindowResized() { |
| 335 Relayout(); | 348 Relayout(); |
| 336 } | 349 } |
| 337 | 350 |
| 338 void PanelLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 351 void PanelLayoutManager::OnWindowAddedToLayout(wm::WmWindow* child) { |
| 339 if (child->type() == ui::wm::WINDOW_TYPE_POPUP) | 352 if (child->GetType() == ui::wm::WINDOW_TYPE_POPUP) |
| 340 return; | 353 return; |
| 341 if (in_add_window_) | 354 if (in_add_window_) |
| 342 return; | 355 return; |
| 343 base::AutoReset<bool> auto_reset_in_add_window(&in_add_window_, true); | 356 base::AutoReset<bool> auto_reset_in_add_window(&in_add_window_, true); |
| 344 if (!wm::GetWindowState(child)->panel_attached()) { | 357 if (!child->GetWindowState()->panel_attached()) { |
| 345 // This should only happen when a window is added to panel container as a | 358 // This should only happen when a window is added to panel container as a |
| 346 // result of bounds change from within the application during a drag. | 359 // result of bounds change from within the application during a drag. |
| 347 // If so we have already stopped the drag and should reparent the panel | 360 // If so we have already stopped the drag and should reparent the panel |
| 348 // back to appropriate container and ignore it. | 361 // back to appropriate container and ignore it. |
| 349 // TODO(varkha): Updating bounds during a drag can cause problems and a more | 362 // TODO(varkha): Updating bounds during a drag can cause problems and a more |
| 350 // general solution is needed. See http://crbug.com/251813 . | 363 // general solution is needed. See http://crbug.com/251813 . |
| 351 aura::Window* old_parent = child->parent(); | 364 wm::WmWindow* old_parent = child->GetParent(); |
| 352 aura::client::ParentWindowWithContext( | 365 child->SetParentUsingContext(child, |
| 353 child, child, child->GetRootWindow()->GetBoundsInScreen()); | 366 child->GetRootWindow()->GetBoundsInScreen()); |
| 354 wm::ReparentTransientChildrenOfChild( | 367 wm::ReparentTransientChildrenOfChild(child, old_parent, child->GetParent()); |
| 355 wm::WmWindowAura::Get(child), wm::WmWindowAura::Get(old_parent), | 368 DCHECK(child->GetParent()->GetShellWindowId() != |
| 356 wm::WmWindowAura::Get(child->parent())); | 369 kShellWindowId_PanelContainer); |
| 357 DCHECK(child->parent()->id() != kShellWindowId_PanelContainer); | |
| 358 return; | 370 return; |
| 359 } | 371 } |
| 360 PanelInfo panel_info; | 372 PanelInfo panel_info; |
| 361 panel_info.window = child; | 373 panel_info.window = child; |
| 362 panel_info.callout_widget = new PanelCalloutWidget(panel_container_); | 374 panel_info.callout_widget = new PanelCalloutWidget(panel_container_); |
| 363 panel_info.slide_in = child != dragged_panel_; | 375 panel_info.slide_in = child != dragged_panel_; |
| 364 panel_windows_.push_back(panel_info); | 376 panel_windows_.push_back(panel_info); |
| 365 child->AddObserver(this); | 377 child->AddObserver(this); |
| 366 wm::GetWindowState(child)->AddObserver(this); | 378 child->GetWindowState()->AddObserver(this); |
| 367 Relayout(); | 379 Relayout(); |
| 368 } | 380 } |
| 369 | 381 |
| 370 void PanelLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { | 382 void PanelLayoutManager::OnWillRemoveWindowFromLayout(wm::WmWindow* child) {} |
| 371 } | |
| 372 | 383 |
| 373 void PanelLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | 384 void PanelLayoutManager::OnWindowRemovedFromLayout(wm::WmWindow* child) { |
| 374 if (child->type() == ui::wm::WINDOW_TYPE_POPUP) | 385 if (child->GetType() == ui::wm::WINDOW_TYPE_POPUP) |
| 375 return; | 386 return; |
| 376 PanelList::iterator found = | 387 PanelList::iterator found = |
| 377 std::find(panel_windows_.begin(), panel_windows_.end(), child); | 388 std::find(panel_windows_.begin(), panel_windows_.end(), child); |
| 378 if (found != panel_windows_.end()) { | 389 if (found != panel_windows_.end()) { |
| 379 delete found->callout_widget; | 390 delete found->callout_widget; |
| 380 panel_windows_.erase(found); | 391 panel_windows_.erase(found); |
| 381 } | 392 } |
| 382 if (restore_windows_on_shelf_visible_) | 393 if (restore_windows_on_shelf_visible_) |
| 383 restore_windows_on_shelf_visible_->Remove(child); | 394 restore_windows_on_shelf_visible_->Remove(child); |
| 384 child->RemoveObserver(this); | 395 child->RemoveObserver(this); |
| 385 wm::GetWindowState(child)->RemoveObserver(this); | 396 child->GetWindowState()->RemoveObserver(this); |
| 386 | 397 |
| 387 if (dragged_panel_ == child) | 398 if (dragged_panel_ == child) |
| 388 dragged_panel_ = NULL; | 399 dragged_panel_ = NULL; |
| 389 | 400 |
| 390 if (last_active_panel_ == child) | 401 if (last_active_panel_ == child) |
| 391 last_active_panel_ = NULL; | 402 last_active_panel_ = NULL; |
| 392 | 403 |
| 393 Relayout(); | 404 Relayout(); |
| 394 } | 405 } |
| 395 | 406 |
| 396 void PanelLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | 407 void PanelLayoutManager::OnChildWindowVisibilityChanged(wm::WmWindow* child, |
| 397 bool visible) { | 408 bool visible) { |
| 398 if (visible) | 409 if (visible) |
| 399 wm::GetWindowState(child)->Restore(); | 410 child->GetWindowState()->Restore(); |
| 400 Relayout(); | 411 Relayout(); |
| 401 } | 412 } |
| 402 | 413 |
| 403 void PanelLayoutManager::SetChildBounds(aura::Window* child, | 414 void PanelLayoutManager::SetChildBounds(wm::WmWindow* child, |
| 404 const gfx::Rect& requested_bounds) { | 415 const gfx::Rect& requested_bounds) { |
| 405 gfx::Rect bounds(requested_bounds); | 416 gfx::Rect bounds(requested_bounds); |
| 406 const gfx::Rect& max_bounds = panel_container_->GetRootWindow()->bounds(); | 417 const gfx::Rect& max_bounds = panel_container_->GetRootWindow()->GetBounds(); |
| 407 const int max_width = max_bounds.width() * kMaxWidthFactor; | 418 const int max_width = max_bounds.width() * kMaxWidthFactor; |
| 408 const int max_height = max_bounds.height() * kMaxHeightFactor; | 419 const int max_height = max_bounds.height() * kMaxHeightFactor; |
| 409 if (bounds.width() > max_width) | 420 if (bounds.width() > max_width) |
| 410 bounds.set_width(max_width); | 421 bounds.set_width(max_width); |
| 411 if (bounds.height() > max_height) | 422 if (bounds.height() > max_height) |
| 412 bounds.set_height(max_height); | 423 bounds.set_height(max_height); |
| 413 | 424 |
| 414 // Reposition dragged panel in the panel order. | 425 // Reposition dragged panel in the panel order. |
| 415 if (dragged_panel_ == child) { | 426 if (dragged_panel_ == child) { |
| 416 PanelList::iterator dragged_panel_iter = | 427 PanelList::iterator dragged_panel_iter = |
| 417 std::find(panel_windows_.begin(), panel_windows_.end(), dragged_panel_); | 428 std::find(panel_windows_.begin(), panel_windows_.end(), dragged_panel_); |
| 418 DCHECK(dragged_panel_iter != panel_windows_.end()); | 429 DCHECK(dragged_panel_iter != panel_windows_.end()); |
| 419 PanelList::iterator new_position; | 430 PanelList::iterator new_position; |
| 420 for (new_position = panel_windows_.begin(); | 431 for (new_position = panel_windows_.begin(); |
| 421 new_position != panel_windows_.end(); | 432 new_position != panel_windows_.end(); |
| 422 ++new_position) { | 433 ++new_position) { |
| 423 const gfx::Rect& bounds = (*new_position).window->bounds(); | 434 const gfx::Rect& bounds = (*new_position).window->GetBounds(); |
| 424 if (bounds.x() + bounds.width()/2 <= requested_bounds.x()) break; | 435 if (bounds.x() + bounds.width() / 2 <= requested_bounds.x()) |
| 436 break; | |
| 425 } | 437 } |
| 426 if (new_position != dragged_panel_iter) { | 438 if (new_position != dragged_panel_iter) { |
| 427 PanelInfo dragged_panel_info = *dragged_panel_iter; | 439 PanelInfo dragged_panel_info = *dragged_panel_iter; |
| 428 panel_windows_.erase(dragged_panel_iter); | 440 panel_windows_.erase(dragged_panel_iter); |
| 429 panel_windows_.insert(new_position, dragged_panel_info); | 441 panel_windows_.insert(new_position, dragged_panel_info); |
| 430 } | 442 } |
| 431 } | 443 } |
| 432 // Respect the minimum size of the window. | 444 // Respect the minimum size of the window. |
| 433 if (child->delegate()) { | 445 if (child->HasNonClientArea()) { |
| 434 const gfx::Size& min_size = child->delegate()->GetMinimumSize(); | 446 const gfx::Size min_size = child->GetMinimumSize(); |
| 435 bounds.set_width(std::max(min_size.width(), bounds.width())); | 447 bounds.set_width(std::max(min_size.width(), bounds.width())); |
| 436 bounds.set_height(std::max(min_size.height(), bounds.height())); | 448 bounds.set_height(std::max(min_size.height(), bounds.height())); |
| 437 } | 449 } |
| 438 | 450 |
| 439 SetChildBoundsDirect(child, bounds); | 451 child->SetBoundsDirect(bounds); |
| 440 Relayout(); | 452 Relayout(); |
| 441 } | 453 } |
| 442 | 454 |
| 443 //////////////////////////////////////////////////////////////////////////////// | 455 //////////////////////////////////////////////////////////////////////////////// |
| 444 // PanelLayoutManager, ShelfIconObserver implementation: | 456 // PanelLayoutManager, ShelfIconObserver implementation: |
| 445 | 457 |
| 446 void PanelLayoutManager::OnShelfIconPositionsChanged() { | 458 void PanelLayoutManager::OnShelfIconPositionsChanged() { |
| 447 // TODO: As this is called for every animation step now. Relayout needs to be | 459 // TODO: As this is called for every animation step now. Relayout needs to be |
| 448 // updated to use current icon position instead of use the ideal bounds so | 460 // updated to use current icon position instead of use the ideal bounds so |
| 449 // that the panels slide with their icons instead of jumping. | 461 // that the panels slide with their icons instead of jumping. |
| 450 Relayout(); | 462 Relayout(); |
| 451 } | 463 } |
| 452 | 464 |
| 453 //////////////////////////////////////////////////////////////////////////////// | 465 //////////////////////////////////////////////////////////////////////////////// |
| 454 // PanelLayoutManager, ash::ShellObserver implementation: | 466 // PanelLayoutManager, ash::ShellObserver implementation: |
| 455 | 467 |
| 456 void PanelLayoutManager::OnOverviewModeEnded() { | 468 void PanelLayoutManager::OnOverviewModeEnded() { |
| 457 Relayout(); | 469 Relayout(); |
| 458 } | 470 } |
| 459 | 471 |
| 460 void PanelLayoutManager::OnShelfAlignmentChanged(aura::Window* root_window) { | 472 void PanelLayoutManager::OnShelfAlignmentChanged() { |
| 461 if (panel_container_->GetRootWindow() == root_window) | 473 Relayout(); |
| 462 Relayout(); | |
| 463 } | 474 } |
| 464 | 475 |
| 465 ///////////////////////////////////////////////////////////////////////////// | 476 ///////////////////////////////////////////////////////////////////////////// |
| 466 // PanelLayoutManager, WindowObserver implementation: | 477 // PanelLayoutManager, WindowObserver implementation: |
| 467 | 478 |
| 468 void PanelLayoutManager::OnWindowPropertyChanged(aura::Window* window, | 479 void PanelLayoutManager::OnWindowPropertyChanged(wm::WmWindow* window, |
| 469 const void* key, | 480 wm::WmWindowProperty property, |
| 470 intptr_t old) { | 481 intptr_t old) { |
| 471 // Trigger a relayout to position the panels whenever the panel icon is set | 482 // Trigger a relayout to position the panels whenever the panel icon is set |
| 472 // or changes. | 483 // or changes. |
| 473 if (key == kShelfID) | 484 if (property == wm::WmWindowProperty::SHELF_ID) |
| 474 Relayout(); | 485 Relayout(); |
| 475 } | 486 } |
| 476 | 487 |
| 477 ///////////////////////////////////////////////////////////////////////////// | 488 ///////////////////////////////////////////////////////////////////////////// |
| 478 // PanelLayoutManager, WindowStateObserver implementation: | 489 // PanelLayoutManager, WindowStateObserver implementation: |
| 479 | 490 |
| 480 void PanelLayoutManager::OnPostWindowStateTypeChange( | 491 void PanelLayoutManager::OnPostWindowStateTypeChange( |
| 481 wm::WindowState* window_state, | 492 wm::WindowState* window_state, |
| 482 wm::WindowStateType old_type) { | 493 wm::WindowStateType old_type) { |
| 483 // If the shelf is currently hidden then windows will not actually be shown | 494 // If the shelf is currently hidden then windows will not actually be shown |
| 484 // but the set to restore when the shelf becomes visible is updated. | 495 // but the set to restore when the shelf becomes visible is updated. |
| 485 if (restore_windows_on_shelf_visible_) { | 496 if (restore_windows_on_shelf_visible_) { |
| 486 if (window_state->IsMinimized()) { | 497 if (window_state->IsMinimized()) { |
| 487 MinimizePanel(window_state->aura_window()); | 498 MinimizePanel(window_state->window()); |
| 488 restore_windows_on_shelf_visible_->Remove(window_state->aura_window()); | 499 restore_windows_on_shelf_visible_->Remove(window_state->window()); |
| 489 } else { | 500 } else { |
| 490 restore_windows_on_shelf_visible_->Add(window_state->aura_window()); | 501 restore_windows_on_shelf_visible_->Add(window_state->window()); |
| 491 } | 502 } |
| 492 return; | 503 return; |
| 493 } | 504 } |
| 494 | 505 |
| 495 if (window_state->IsMinimized()) | 506 if (window_state->IsMinimized()) |
| 496 MinimizePanel(window_state->aura_window()); | 507 MinimizePanel(window_state->window()); |
| 497 else | 508 else |
| 498 RestorePanel(window_state->aura_window()); | 509 RestorePanel(window_state->window()); |
| 499 } | 510 } |
| 500 | 511 |
| 501 //////////////////////////////////////////////////////////////////////////////// | 512 //////////////////////////////////////////////////////////////////////////////// |
| 502 // PanelLayoutManager, aura::client::ActivationChangeObserver implementation: | 513 // PanelLayoutManager, aura::client::ActivationChangeObserver implementation: |
| 503 | 514 |
| 504 void PanelLayoutManager::OnWindowActivated( | 515 void PanelLayoutManager::OnWindowActivated(wm::WmWindow* gained_active, |
| 505 aura::client::ActivationChangeObserver::ActivationReason reason, | 516 wm::WmWindow* lost_active) { |
| 506 aura::Window* gained_active, | |
| 507 aura::Window* lost_active) { | |
| 508 // Ignore if the panel that is not managed by this was activated. | 517 // Ignore if the panel that is not managed by this was activated. |
| 509 if (gained_active && gained_active->type() == ui::wm::WINDOW_TYPE_PANEL && | 518 if (gained_active && gained_active->GetType() == ui::wm::WINDOW_TYPE_PANEL && |
| 510 gained_active->parent() == panel_container_) { | 519 gained_active->GetParent() == panel_container_) { |
| 511 UpdateStacking(gained_active); | 520 UpdateStacking(gained_active); |
| 512 UpdateCallouts(); | 521 UpdateCallouts(); |
| 513 } | 522 } |
| 514 } | 523 } |
| 515 | 524 |
| 516 //////////////////////////////////////////////////////////////////////////////// | 525 //////////////////////////////////////////////////////////////////////////////// |
| 517 // PanelLayoutManager, WindowTreeHostManager::Observer implementation: | 526 // PanelLayoutManager, wm::WmDisplayObserver::Observer implementation: |
| 518 | 527 |
| 519 void PanelLayoutManager::OnDisplayConfigurationChanged() { | 528 void PanelLayoutManager::OnDisplayConfigurationChanged() { |
| 520 Relayout(); | 529 Relayout(); |
| 521 } | 530 } |
| 522 | 531 |
| 523 //////////////////////////////////////////////////////////////////////////////// | 532 //////////////////////////////////////////////////////////////////////////////// |
| 524 // PanelLayoutManager, ShelfLayoutManagerObserver implementation: | 533 // PanelLayoutManager, ShelfLayoutManagerObserver implementation: |
| 525 | 534 |
| 526 void PanelLayoutManager::WillChangeVisibilityState( | 535 void PanelLayoutManager::WillChangeVisibilityState( |
| 527 ShelfVisibilityState new_state) { | 536 ShelfVisibilityState new_state) { |
| 528 // On entering / leaving full screen mode the shelf visibility state is | 537 // On entering / leaving full screen mode the shelf visibility state is |
| 529 // changed to / from SHELF_HIDDEN. In this state, panel windows should hide | 538 // changed to / from SHELF_HIDDEN. In this state, panel windows should hide |
| 530 // to allow the full-screen application to use the full screen. | 539 // to allow the full-screen application to use the full screen. |
| 531 bool shelf_hidden = new_state == ash::SHELF_HIDDEN; | 540 bool shelf_hidden = new_state == ash::SHELF_HIDDEN; |
| 532 if (!shelf_hidden) { | 541 if (!shelf_hidden) { |
| 533 if (restore_windows_on_shelf_visible_) { | 542 if (restore_windows_on_shelf_visible_) { |
| 534 std::unique_ptr<aura::WindowTracker> restore_windows( | 543 std::unique_ptr<wm::WmWindowTracker> restore_windows( |
| 535 std::move(restore_windows_on_shelf_visible_)); | 544 std::move(restore_windows_on_shelf_visible_)); |
| 536 for (aura::Window::Windows::const_iterator iter = | 545 for (wm::WmWindow* window : restore_windows->windows()) |
| 537 restore_windows->windows().begin(); | 546 RestorePanel(window); |
| 538 iter != restore_windows->windows().end(); ++iter) { | |
| 539 RestorePanel(*iter); | |
| 540 } | |
| 541 } | 547 } |
| 542 return; | 548 return; |
| 543 } | 549 } |
| 544 | 550 |
| 545 if (restore_windows_on_shelf_visible_) | 551 if (restore_windows_on_shelf_visible_) |
| 546 return; | 552 return; |
| 547 std::unique_ptr<aura::WindowTracker> minimized_windows( | 553 std::unique_ptr<wm::WmWindowTracker> minimized_windows( |
| 548 new aura::WindowTracker); | 554 new wm::WmWindowTracker); |
| 549 for (PanelList::iterator iter = panel_windows_.begin(); | 555 for (PanelList::iterator iter = panel_windows_.begin(); |
| 550 iter != panel_windows_.end();) { | 556 iter != panel_windows_.end();) { |
| 551 aura::Window* window = iter->window; | 557 wm::WmWindow* window = iter->window; |
| 552 // Minimizing a panel window may remove it from the panel_windows_ list. | 558 // Minimizing a panel window may remove it from the panel_windows_ list. |
| 553 // Advance the iterator before minimizing it: http://crbug.com/393047. | 559 // Advance the iterator before minimizing it: http://crbug.com/393047. |
| 554 ++iter; | 560 ++iter; |
| 555 if (window != dragged_panel_ && window->IsVisible()) { | 561 if (window != dragged_panel_ && window->IsVisible()) { |
| 556 minimized_windows->Add(window); | 562 minimized_windows->Add(window); |
| 557 wm::GetWindowState(window)->Minimize(); | 563 window->GetWindowState()->Minimize(); |
| 558 } | 564 } |
| 559 } | 565 } |
| 560 restore_windows_on_shelf_visible_ = std::move(minimized_windows); | 566 restore_windows_on_shelf_visible_ = std::move(minimized_windows); |
| 561 } | 567 } |
| 562 | 568 |
| 563 //////////////////////////////////////////////////////////////////////////////// | 569 //////////////////////////////////////////////////////////////////////////////// |
| 564 // PanelLayoutManager private implementation: | 570 // PanelLayoutManager private implementation: |
| 565 | 571 |
| 566 void PanelLayoutManager::MinimizePanel(aura::Window* panel) { | 572 void PanelLayoutManager::MinimizePanel(wm::WmWindow* panel) { |
| 567 ::wm::SetWindowVisibilityAnimationType( | 573 panel->SetVisibilityAnimationType( |
| 568 panel, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | 574 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); |
| 569 ui::Layer* layer = panel->layer(); | 575 ui::Layer* layer = panel->GetLayer(); |
| 570 ui::ScopedLayerAnimationSettings panel_slide_settings(layer->GetAnimator()); | 576 ui::ScopedLayerAnimationSettings panel_slide_settings(layer->GetAnimator()); |
| 571 panel_slide_settings.SetPreemptionStrategy( | 577 panel_slide_settings.SetPreemptionStrategy( |
| 572 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 578 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 573 panel_slide_settings.SetTransitionDuration( | 579 panel_slide_settings.SetTransitionDuration( |
| 574 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); | 580 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); |
| 575 gfx::Rect bounds(panel->bounds()); | 581 gfx::Rect bounds(panel->GetBounds()); |
| 576 bounds.Offset(GetSlideInAnimationOffset(shelf_->alignment())); | 582 bounds.Offset(GetSlideInAnimationOffset(shelf_->alignment())); |
| 577 SetChildBoundsDirect(panel, bounds); | 583 panel->SetBoundsDirect(bounds); |
| 578 panel->Hide(); | 584 panel->Hide(); |
| 579 layer->SetOpacity(0); | 585 layer->SetOpacity(0); |
| 580 if (wm::IsActiveWindow(panel)) | 586 if (panel->IsActive()) |
| 581 wm::DeactivateWindow(panel); | 587 panel->Deactivate(); |
| 582 Relayout(); | 588 Relayout(); |
| 583 } | 589 } |
| 584 | 590 |
| 585 void PanelLayoutManager::RestorePanel(aura::Window* panel) { | 591 void PanelLayoutManager::RestorePanel(wm::WmWindow* panel) { |
| 586 PanelList::iterator found = | 592 PanelList::iterator found = |
| 587 std::find(panel_windows_.begin(), panel_windows_.end(), panel); | 593 std::find(panel_windows_.begin(), panel_windows_.end(), panel); |
| 588 DCHECK(found != panel_windows_.end()); | 594 DCHECK(found != panel_windows_.end()); |
| 589 found->slide_in = true; | 595 found->slide_in = true; |
| 590 Relayout(); | 596 Relayout(); |
| 591 } | 597 } |
| 592 | 598 |
| 593 void PanelLayoutManager::Relayout() { | 599 void PanelLayoutManager::Relayout() { |
| 594 if (!shelf_ || !shelf_->shelf_widget()) | 600 if (!shelf_ || !shelf_->shelf_widget()) |
| 595 return; | 601 return; |
| 596 | 602 |
| 597 // Suppress layouts during overview mode because changing window bounds | 603 // Suppress layouts during overview mode because changing window bounds |
| 598 // interfered with overview mode animations. However, layouts need to be done | 604 // interfered with overview mode animations. However, layouts need to be done |
| 599 // when the WindowSelectorController is restoring minimized windows so that | 605 // when the WindowSelectorController is restoring minimized windows so that |
| 600 // they actually become visible. | 606 // they actually become visible. |
| 601 WindowSelectorController* window_selector_controller = | 607 WindowSelectorController* window_selector_controller = |
| 602 Shell::GetInstance()->window_selector_controller(); | 608 Shell::GetInstance()->window_selector_controller(); |
| 603 if (in_layout_ || !window_selector_controller || | 609 if (in_layout_ || !window_selector_controller || |
| 604 (window_selector_controller->IsSelecting() && | 610 (window_selector_controller->IsSelecting() && |
| 605 !window_selector_controller->IsRestoringMinimizedWindows())) | 611 !window_selector_controller->IsRestoringMinimizedWindows())) |
| 606 return; | 612 return; |
| 613 | |
| 607 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | 614 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
| 608 | 615 |
| 609 const ShelfAlignment alignment = shelf_->alignment(); | 616 const ShelfAlignment alignment = shelf_->alignment(); |
| 610 const bool horizontal = shelf_->IsHorizontalAlignment(); | 617 const bool horizontal = shelf_->IsHorizontalAlignment(); |
| 611 gfx::Rect shelf_bounds = ash::ScreenUtil::ConvertRectFromScreen( | 618 gfx::Rect shelf_bounds = panel_container_->ConvertRectFromScreen( |
| 612 panel_container_, shelf_->shelf_widget()->GetWindowBoundsInScreen()); | 619 shelf_->shelf_widget()->GetWindowBoundsInScreen()); |
| 613 int panel_start_bounds = kPanelIdealSpacing; | 620 int panel_start_bounds = kPanelIdealSpacing; |
| 614 int panel_end_bounds = horizontal ? | 621 int panel_end_bounds = |
| 615 panel_container_->bounds().width() - kPanelIdealSpacing : | 622 horizontal ? panel_container_->GetBounds().width() - kPanelIdealSpacing |
| 616 panel_container_->bounds().height() - kPanelIdealSpacing; | 623 : panel_container_->GetBounds().height() - kPanelIdealSpacing; |
| 617 aura::Window* active_panel = NULL; | 624 wm::WmWindow* active_panel = nullptr; |
| 618 std::vector<VisiblePanelPositionInfo> visible_panels; | 625 std::vector<VisiblePanelPositionInfo> visible_panels; |
| 619 for (PanelList::iterator iter = panel_windows_.begin(); | 626 for (PanelList::iterator iter = panel_windows_.begin(); |
| 620 iter != panel_windows_.end(); ++iter) { | 627 iter != panel_windows_.end(); ++iter) { |
| 621 aura::Window* panel = iter->window; | 628 wm::WmWindow* panel = iter->window; |
| 622 iter->callout_widget->SetAlignment(alignment); | 629 iter->callout_widget->SetAlignment(alignment); |
| 623 | 630 |
| 624 // Consider the dragged panel as part of the layout as long as it is | 631 // Consider the dragged panel as part of the layout as long as it is |
| 625 // touching the shelf. | 632 // touching the shelf. |
| 626 if ((!panel->IsVisible() && !iter->slide_in) || | 633 if ((!panel->IsVisible() && !iter->slide_in) || |
| 627 (panel == dragged_panel_ && | 634 (panel == dragged_panel_ && |
| 628 !BoundsAdjacent(panel->bounds(), shelf_bounds))) { | 635 !BoundsAdjacent(panel->GetBounds(), shelf_bounds))) { |
| 629 continue; | 636 continue; |
| 630 } | 637 } |
| 631 | 638 |
| 632 // If the shelf is currently hidden (full-screen mode), minimize panel until | 639 // If the shelf is currently hidden (full-screen mode), minimize panel until |
| 633 // full-screen mode is exited. When a panel is dragged from another display | 640 // full-screen mode is exited. When a panel is dragged from another display |
| 634 // the shelf state does not update before the panel is added so we exclude | 641 // the shelf state does not update before the panel is added so we exclude |
| 635 // the dragged panel. | 642 // the dragged panel. |
| 636 if (panel != dragged_panel_ && restore_windows_on_shelf_visible_) { | 643 if (panel != dragged_panel_ && restore_windows_on_shelf_visible_) { |
| 637 wm::GetWindowState(panel)->Minimize(); | 644 panel->GetWindowState()->Minimize(); |
| 638 restore_windows_on_shelf_visible_->Add(panel); | 645 restore_windows_on_shelf_visible_->Add(panel); |
| 639 continue; | 646 continue; |
| 640 } | 647 } |
| 641 | 648 |
| 642 gfx::Rect icon_bounds = shelf_->GetScreenBoundsOfItemIconForWindow(panel); | 649 gfx::Rect icon_bounds = shelf_->GetScreenBoundsOfItemIconForWindow( |
| 650 wm::WmWindowAura::GetAuraWindow(panel)); | |
| 643 | 651 |
| 644 // If both the icon width and height are 0 then there is no icon in the | 652 // If both the icon width and height are 0 then there is no icon in the |
| 645 // shelf. If the shelf is hidden, one of the height or width will be | 653 // shelf. If the shelf is hidden, one of the height or width will be |
| 646 // 0 but the position in the shelf and major dimension is still reported | 654 // 0 but the position in the shelf and major dimension is still reported |
| 647 // correctly and the panel can be aligned above where the hidden icon is. | 655 // correctly and the panel can be aligned above where the hidden icon is. |
| 648 if (icon_bounds.width() == 0 && icon_bounds.height() == 0) | 656 if (icon_bounds.width() == 0 && icon_bounds.height() == 0) |
| 649 continue; | 657 continue; |
| 650 | 658 |
| 651 if (panel->HasFocus() || | 659 if (panel->IsFocused() || |
| 652 panel->Contains( | 660 panel->Contains(panel->GetGlobals()->GetFocusedWindow())) { |
| 653 aura::client::GetFocusClient(panel)->GetFocusedWindow())) { | |
| 654 DCHECK(!active_panel); | 661 DCHECK(!active_panel); |
| 655 active_panel = panel; | 662 active_panel = panel; |
| 656 } | 663 } |
| 657 icon_bounds = ScreenUtil::ConvertRectFromScreen(panel_container_, | 664 icon_bounds = panel_container_->ConvertRectFromScreen(icon_bounds); |
| 658 icon_bounds); | |
| 659 gfx::Point icon_origin = icon_bounds.origin(); | 665 gfx::Point icon_origin = icon_bounds.origin(); |
| 660 VisiblePanelPositionInfo position_info; | 666 VisiblePanelPositionInfo position_info; |
| 661 int icon_start = horizontal ? icon_origin.x() : icon_origin.y(); | 667 int icon_start = horizontal ? icon_origin.x() : icon_origin.y(); |
| 662 int icon_end = icon_start + (horizontal ? icon_bounds.width() : | 668 int icon_end = icon_start + (horizontal ? icon_bounds.width() : |
| 663 icon_bounds.height()); | 669 icon_bounds.height()); |
| 664 position_info.major_length = horizontal ? | 670 position_info.major_length = |
| 665 panel->bounds().width() : panel->bounds().height(); | 671 horizontal ? panel->GetBounds().width() : panel->GetBounds().height(); |
| 666 position_info.min_major = std::max( | 672 position_info.min_major = std::max( |
| 667 panel_start_bounds + position_info.major_length / 2, | 673 panel_start_bounds + position_info.major_length / 2, |
| 668 icon_end - position_info.major_length / 2); | 674 icon_end - position_info.major_length / 2); |
| 669 position_info.max_major = std::min( | 675 position_info.max_major = std::min( |
| 670 icon_start + position_info.major_length / 2, | 676 icon_start + position_info.major_length / 2, |
| 671 panel_end_bounds - position_info.major_length / 2); | 677 panel_end_bounds - position_info.major_length / 2); |
| 672 position_info.major_pos = (icon_start + icon_end) / 2; | 678 position_info.major_pos = (icon_start + icon_end) / 2; |
| 673 position_info.window = panel; | 679 position_info.window = panel; |
| 674 position_info.slide_in = iter->slide_in; | 680 position_info.slide_in = iter->slide_in; |
| 675 iter->slide_in = false; | 681 iter->slide_in = false; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 bool on_shelf = visible_panels[i].window->GetTargetBounds() == bounds; | 715 bool on_shelf = visible_panels[i].window->GetTargetBounds() == bounds; |
| 710 | 716 |
| 711 if (horizontal) { | 717 if (horizontal) { |
| 712 bounds.set_x(visible_panels[i].major_pos - | 718 bounds.set_x(visible_panels[i].major_pos - |
| 713 visible_panels[i].major_length / 2); | 719 visible_panels[i].major_length / 2); |
| 714 } else { | 720 } else { |
| 715 bounds.set_y(visible_panels[i].major_pos - | 721 bounds.set_y(visible_panels[i].major_pos - |
| 716 visible_panels[i].major_length / 2); | 722 visible_panels[i].major_length / 2); |
| 717 } | 723 } |
| 718 | 724 |
| 719 ui::Layer* layer = visible_panels[i].window->layer(); | 725 ui::Layer* layer = visible_panels[i].window->GetLayer(); |
| 720 if (slide_in) { | 726 if (slide_in) { |
| 721 // New windows shift up from the shelf into position and fade in. | 727 // New windows shift up from the shelf into position and fade in. |
| 722 layer->SetOpacity(0); | 728 layer->SetOpacity(0); |
| 723 gfx::Rect initial_bounds(bounds); | 729 gfx::Rect initial_bounds(bounds); |
| 724 initial_bounds.Offset(GetSlideInAnimationOffset(alignment)); | 730 initial_bounds.Offset(GetSlideInAnimationOffset(alignment)); |
| 725 SetChildBoundsDirect(visible_panels[i].window, initial_bounds); | 731 visible_panels[i].window->SetBoundsDirect(initial_bounds); |
| 726 // Set on shelf so that the panel animates into its target position. | 732 // Set on shelf so that the panel animates into its target position. |
| 727 on_shelf = true; | 733 on_shelf = true; |
| 728 } | 734 } |
| 729 | 735 |
| 730 if (on_shelf) { | 736 if (on_shelf) { |
| 731 ui::ScopedLayerAnimationSettings panel_slide_settings( | 737 ui::ScopedLayerAnimationSettings panel_slide_settings( |
| 732 layer->GetAnimator()); | 738 layer->GetAnimator()); |
| 733 panel_slide_settings.SetPreemptionStrategy( | 739 panel_slide_settings.SetPreemptionStrategy( |
| 734 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 740 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 735 panel_slide_settings.SetTransitionDuration( | 741 panel_slide_settings.SetTransitionDuration( |
| 736 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); | 742 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); |
| 737 SetChildBoundsDirect(visible_panels[i].window, bounds); | 743 visible_panels[i].window->SetBoundsDirect(bounds); |
| 738 if (slide_in) { | 744 if (slide_in) { |
| 739 layer->SetOpacity(1); | 745 layer->SetOpacity(1); |
| 740 visible_panels[i].window->Show(); | 746 visible_panels[i].window->Show(); |
| 741 } | 747 } |
| 742 } else { | 748 } else { |
| 743 // If the shelf moved don't animate, move immediately to the new | 749 // If the shelf moved don't animate, move immediately to the new |
| 744 // target location. | 750 // target location. |
| 745 SetChildBoundsDirect(visible_panels[i].window, bounds); | 751 visible_panels[i].window->SetBoundsDirect(bounds); |
| 746 } | 752 } |
| 747 } | 753 } |
| 748 | 754 |
| 749 UpdateStacking(active_panel); | 755 UpdateStacking(active_panel); |
| 750 UpdateCallouts(); | 756 UpdateCallouts(); |
| 751 } | 757 } |
| 752 | 758 |
| 753 void PanelLayoutManager::UpdateStacking(aura::Window* active_panel) { | 759 void PanelLayoutManager::UpdateStacking(wm::WmWindow* active_panel) { |
| 754 if (!active_panel) { | 760 if (!active_panel) { |
| 755 if (!last_active_panel_) | 761 if (!last_active_panel_) |
| 756 return; | 762 return; |
| 757 active_panel = last_active_panel_; | 763 active_panel = last_active_panel_; |
| 758 } | 764 } |
| 759 | 765 |
| 760 // We want to to stack the panels like a deck of cards: | 766 // We want to to stack the panels like a deck of cards: |
| 761 // ,--,--,--,-------.--.--. | 767 // ,--,--,--,-------.--.--. |
| 762 // | | | | | | | | 768 // | | | | | | | |
| 763 // | | | | | | | | 769 // | | | | | | | |
| 764 // | 770 // |
| 765 // We use the middle of each panel to figure out how to stack the panels. This | 771 // We use the middle of each panel to figure out how to stack the panels. This |
| 766 // allows us to update the stacking when a panel is being dragged around by | 772 // allows us to update the stacking when a panel is being dragged around by |
| 767 // the titlebar--even though it doesn't update the shelf icon positions, we | 773 // the titlebar--even though it doesn't update the shelf icon positions, we |
| 768 // still want the visual effect. | 774 // still want the visual effect. |
| 769 std::map<int, aura::Window*> window_ordering; | 775 std::map<int, wm::WmWindow*> window_ordering; |
| 770 const bool horizontal = shelf_->IsHorizontalAlignment(); | 776 const bool horizontal = shelf_->IsHorizontalAlignment(); |
| 771 for (PanelList::const_iterator it = panel_windows_.begin(); | 777 for (PanelList::const_iterator it = panel_windows_.begin(); |
| 772 it != panel_windows_.end(); ++it) { | 778 it != panel_windows_.end(); ++it) { |
| 773 gfx::Rect bounds = it->window->bounds(); | 779 gfx::Rect bounds = it->window->GetBounds(); |
| 774 window_ordering.insert(std::make_pair(horizontal ? | 780 window_ordering.insert(std::make_pair(horizontal ? |
| 775 bounds.x() + bounds.width() / 2 : | 781 bounds.x() + bounds.width() / 2 : |
| 776 bounds.y() + bounds.height() / 2, | 782 bounds.y() + bounds.height() / 2, |
| 777 it->window)); | 783 it->window)); |
| 778 } | 784 } |
| 779 | 785 |
| 780 aura::Window* previous_panel = NULL; | 786 wm::WmWindow* previous_panel = nullptr; |
| 781 for (std::map<int, aura::Window*>::const_iterator it = | 787 for (std::map<int, wm::WmWindow*>::const_iterator it = |
| 782 window_ordering.begin(); | 788 window_ordering.begin(); |
| 783 it != window_ordering.end() && it->second != active_panel; ++it) { | 789 it != window_ordering.end() && it->second != active_panel; ++it) { |
| 784 if (previous_panel) | 790 if (previous_panel) |
| 785 panel_container_->StackChildAbove(it->second, previous_panel); | 791 panel_container_->StackChildAbove(it->second, previous_panel); |
| 786 previous_panel = it->second; | 792 previous_panel = it->second; |
| 787 } | 793 } |
| 788 | 794 |
| 789 previous_panel = NULL; | 795 previous_panel = NULL; |
| 790 for (std::map<int, aura::Window*>::const_reverse_iterator it = | 796 for (std::map<int, wm::WmWindow*>::const_reverse_iterator it = |
| 791 window_ordering.rbegin(); | 797 window_ordering.rbegin(); |
| 792 it != window_ordering.rend() && it->second != active_panel; ++it) { | 798 it != window_ordering.rend() && it->second != active_panel; ++it) { |
| 793 if (previous_panel) | 799 if (previous_panel) |
| 794 panel_container_->StackChildAbove(it->second, previous_panel); | 800 panel_container_->StackChildAbove(it->second, previous_panel); |
| 795 previous_panel = it->second; | 801 previous_panel = it->second; |
| 796 } | 802 } |
| 797 | 803 |
| 798 panel_container_->StackChildAtTop(active_panel); | 804 panel_container_->StackChildAtTop(active_panel); |
| 799 if (dragged_panel_ && dragged_panel_->parent() == panel_container_) | 805 if (dragged_panel_ && dragged_panel_->GetParent() == panel_container_) |
| 800 panel_container_->StackChildAtTop(dragged_panel_); | 806 panel_container_->StackChildAtTop(dragged_panel_); |
| 801 last_active_panel_ = active_panel; | 807 last_active_panel_ = active_panel; |
| 802 } | 808 } |
| 803 | 809 |
| 804 void PanelLayoutManager::UpdateCallouts() { | 810 void PanelLayoutManager::UpdateCallouts() { |
| 805 const bool horizontal = shelf_->IsHorizontalAlignment(); | 811 const bool horizontal = shelf_->IsHorizontalAlignment(); |
| 806 for (PanelList::iterator iter = panel_windows_.begin(); | 812 for (PanelList::iterator iter = panel_windows_.begin(); |
| 807 iter != panel_windows_.end(); ++iter) { | 813 iter != panel_windows_.end(); ++iter) { |
| 808 aura::Window* panel = iter->window; | 814 wm::WmWindow* panel = iter->window; |
| 809 views::Widget* callout_widget = iter->callout_widget; | 815 views::Widget* callout_widget = iter->callout_widget; |
| 816 wm::WmWindow* callout_widget_window = wm::WmWindow::Get(callout_widget); | |
| 810 | 817 |
| 811 gfx::Rect current_bounds = panel->GetBoundsInScreen(); | 818 gfx::Rect current_bounds = panel->GetBoundsInScreen(); |
| 812 gfx::Rect bounds = ScreenUtil::ConvertRectToScreen( | 819 gfx::Rect bounds = |
| 813 panel->parent(), | 820 panel->GetParent()->ConvertRectToScreen(panel->GetTargetBounds()); |
| 814 panel->GetTargetBounds()); | 821 gfx::Rect icon_bounds = shelf_->GetScreenBoundsOfItemIconForWindow( |
| 815 gfx::Rect icon_bounds = shelf_->GetScreenBoundsOfItemIconForWindow(panel); | 822 wm::WmWindowAura::GetAuraWindow(panel)); |
| 816 if (icon_bounds.IsEmpty() || !panel->layer()->GetTargetVisibility() || | 823 if (icon_bounds.IsEmpty() || !panel->GetLayer()->GetTargetVisibility() || |
| 817 panel == dragged_panel_ || !show_callout_widgets_) { | 824 panel == dragged_panel_ || !show_callout_widgets_) { |
| 818 callout_widget->Hide(); | 825 callout_widget->Hide(); |
| 819 callout_widget->GetNativeWindow()->layer()->SetOpacity(0); | 826 callout_widget_window->GetLayer()->SetOpacity(0); |
| 820 continue; | 827 continue; |
| 821 } | 828 } |
| 822 | 829 |
| 823 gfx::Rect callout_bounds = callout_widget->GetWindowBoundsInScreen(); | 830 gfx::Rect callout_bounds = callout_widget->GetWindowBoundsInScreen(); |
| 824 gfx::Vector2d slide_vector = bounds.origin() - current_bounds.origin(); | 831 gfx::Vector2d slide_vector = bounds.origin() - current_bounds.origin(); |
| 825 int slide_distance = horizontal ? slide_vector.x() : slide_vector.y(); | 832 int slide_distance = horizontal ? slide_vector.x() : slide_vector.y(); |
| 826 int distance_until_over_panel = 0; | 833 int distance_until_over_panel = 0; |
| 827 if (horizontal) { | 834 if (horizontal) { |
| 828 callout_bounds.set_x( | 835 callout_bounds.set_x( |
| 829 icon_bounds.x() + (icon_bounds.width() - callout_bounds.width()) / 2); | 836 icon_bounds.x() + (icon_bounds.width() - callout_bounds.width()) / 2); |
| 830 distance_until_over_panel = std::max( | 837 distance_until_over_panel = std::max( |
| 831 current_bounds.x() - callout_bounds.x(), | 838 current_bounds.x() - callout_bounds.x(), |
| 832 callout_bounds.right() - current_bounds.right()); | 839 callout_bounds.right() - current_bounds.right()); |
| 833 } else { | 840 } else { |
| 834 callout_bounds.set_y( | 841 callout_bounds.set_y( |
| 835 icon_bounds.y() + (icon_bounds.height() - | 842 icon_bounds.y() + (icon_bounds.height() - |
| 836 callout_bounds.height()) / 2); | 843 callout_bounds.height()) / 2); |
| 837 distance_until_over_panel = std::max( | 844 distance_until_over_panel = std::max( |
| 838 current_bounds.y() - callout_bounds.y(), | 845 current_bounds.y() - callout_bounds.y(), |
| 839 callout_bounds.bottom() - current_bounds.bottom()); | 846 callout_bounds.bottom() - current_bounds.bottom()); |
| 840 } | 847 } |
| 841 if (shelf_->alignment() == SHELF_ALIGNMENT_LEFT) | 848 if (shelf_->alignment() == SHELF_ALIGNMENT_LEFT) |
| 842 callout_bounds.set_x(bounds.x() - callout_bounds.width()); | 849 callout_bounds.set_x(bounds.x() - callout_bounds.width()); |
| 843 else if (shelf_->alignment() == SHELF_ALIGNMENT_RIGHT) | 850 else if (shelf_->alignment() == SHELF_ALIGNMENT_RIGHT) |
| 844 callout_bounds.set_x(bounds.right()); | 851 callout_bounds.set_x(bounds.right()); |
| 845 else | 852 else |
| 846 callout_bounds.set_y(bounds.bottom()); | 853 callout_bounds.set_y(bounds.bottom()); |
| 847 callout_bounds = ScreenUtil::ConvertRectFromScreen( | 854 callout_bounds = callout_widget_window->GetParent()->ConvertRectFromScreen( |
| 848 callout_widget->GetNativeWindow()->parent(), | |
| 849 callout_bounds); | 855 callout_bounds); |
| 850 | 856 |
| 851 SetChildBoundsDirect(callout_widget->GetNativeWindow(), callout_bounds); | 857 callout_widget_window->SetBoundsDirect(callout_bounds); |
| 852 panel_container_->StackChildAbove(callout_widget->GetNativeWindow(), | 858 panel_container_->StackChildAbove(callout_widget_window, panel); |
| 853 panel); | |
| 854 | 859 |
| 855 ui::Layer* layer = callout_widget->GetNativeWindow()->layer(); | 860 ui::Layer* layer = callout_widget_window->GetLayer(); |
| 856 // If the panel is not over the callout position or has just become visible | 861 // If the panel is not over the callout position or has just become visible |
| 857 // then fade in the callout. | 862 // then fade in the callout. |
| 858 if ((distance_until_over_panel > 0 || layer->GetTargetOpacity() < 1)) { | 863 if ((distance_until_over_panel > 0 || layer->GetTargetOpacity() < 1)) { |
| 859 if (distance_until_over_panel > 0 && | 864 if (distance_until_over_panel > 0 && |
| 860 slide_distance >= distance_until_over_panel) { | 865 slide_distance >= distance_until_over_panel) { |
| 861 // If the panel is not yet over the callout, then delay fading in | 866 // If the panel is not yet over the callout, then delay fading in |
| 862 // the callout until after the panel should be over it. | 867 // the callout until after the panel should be over it. |
| 863 int delay = kPanelSlideDurationMilliseconds * | 868 int delay = kPanelSlideDurationMilliseconds * |
| 864 distance_until_over_panel / slide_distance; | 869 distance_until_over_panel / slide_distance; |
| 865 layer->SetOpacity(0); | 870 layer->SetOpacity(0); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 881 // state where the widget is visible but the opacity is 0. | 886 // state where the widget is visible but the opacity is 0. |
| 882 callout_widget->Show(); | 887 callout_widget->Show(); |
| 883 } | 888 } |
| 884 } | 889 } |
| 885 | 890 |
| 886 //////////////////////////////////////////////////////////////////////////////// | 891 //////////////////////////////////////////////////////////////////////////////// |
| 887 // keyboard::KeyboardControllerObserver implementation: | 892 // keyboard::KeyboardControllerObserver implementation: |
| 888 | 893 |
| 889 void PanelLayoutManager::OnKeyboardBoundsChanging( | 894 void PanelLayoutManager::OnKeyboardBoundsChanging( |
| 890 const gfx::Rect& keyboard_bounds) { | 895 const gfx::Rect& keyboard_bounds) { |
| 891 gfx::Rect parent_bounds = panel_container_->bounds(); | 896 gfx::Rect parent_bounds = panel_container_->GetBounds(); |
| 892 int available_space = parent_bounds.height() - keyboard_bounds.height(); | 897 int available_space = parent_bounds.height() - keyboard_bounds.height(); |
| 893 for (PanelList::iterator iter = panel_windows_.begin(); | 898 for (PanelList::iterator iter = panel_windows_.begin(); |
| 894 iter != panel_windows_.end(); | 899 iter != panel_windows_.end(); |
| 895 ++iter) { | 900 ++iter) { |
| 896 aura::Window* panel = iter->window; | 901 wm::WmWindow* panel = iter->window; |
| 897 wm::WindowState* panel_state = wm::GetWindowState(panel); | 902 wm::WindowState* panel_state = panel->GetWindowState(); |
| 898 if (keyboard_bounds.height() > 0) { | 903 if (keyboard_bounds.height() > 0) { |
| 899 // Save existing bounds, so that we can restore them when the keyboard | 904 // Save existing bounds, so that we can restore them when the keyboard |
| 900 // hides. | 905 // hides. |
| 901 panel_state->SaveCurrentBoundsForRestore(); | 906 panel_state->SaveCurrentBoundsForRestore(); |
| 902 | 907 |
| 903 gfx::Rect panel_bounds = ScreenUtil::ConvertRectToScreen( | 908 gfx::Rect panel_bounds = |
| 904 panel->parent(), panel->GetTargetBounds()); | 909 panel->GetParent()->ConvertRectToScreen(panel->GetTargetBounds()); |
| 905 int delta = panel_bounds.height() - available_space; | 910 int delta = panel_bounds.height() - available_space; |
| 906 // Ensure panels are not pushed above the parent boundaries, shrink any | 911 // Ensure panels are not pushed above the parent boundaries, shrink any |
| 907 // panels that violate this constraint. | 912 // panels that violate this constraint. |
| 908 if (delta > 0) { | 913 if (delta > 0) { |
| 909 SetChildBounds(panel, | 914 panel->SetBoundsDirect( |
| 910 gfx::Rect(panel_bounds.x(), | 915 gfx::Rect(panel_bounds.x(), panel_bounds.y() + delta, |
| 911 panel_bounds.y() + delta, | 916 panel_bounds.width(), panel_bounds.height() - delta)); |
| 912 panel_bounds.width(), | |
| 913 panel_bounds.height() - delta)); | |
| 914 } | 917 } |
| 915 } else if (panel_state->HasRestoreBounds()) { | 918 } else if (panel_state->HasRestoreBounds()) { |
| 916 // Keyboard hidden, restore original bounds if they exist. | 919 // Keyboard hidden, restore original bounds if they exist. |
| 917 SetChildBounds(panel, panel_state->GetRestoreBoundsInScreen()); | 920 panel->SetBoundsDirect(panel_state->GetRestoreBoundsInScreen()); |
| 918 } | 921 } |
| 919 } | 922 } |
| 920 // This bounds change will have caused a change to the Shelf which does not | 923 // This bounds change will have caused a change to the Shelf which does not |
| 921 // propogate automatically to this class, so manually recalculate bounds. | 924 // propogate automatically to this class, so manually recalculate bounds. |
| 922 OnWindowResized(); | 925 OnWindowResized(); |
| 923 } | 926 } |
| 924 | 927 |
| 925 } // namespace ash | 928 } // namespace ash |
| OLD | NEW |