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/shelf_layout_manager.h" | 5 #include "ash/shelf/shelf_layout_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/launcher/launcher.h" | 11 #include "ash/launcher/launcher.h" |
| 12 #include "ash/launcher/launcher_types.h" | |
| 12 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
| 13 #include "ash/screen_ash.h" | 14 #include "ash/screen_ash.h" |
| 15 #include "ash/shelf/shelf_widget.h" | |
| 14 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 15 #include "ash/shell_delegate.h" | 17 #include "ash/shell_delegate.h" |
| 16 #include "ash/shell_window_ids.h" | 18 #include "ash/shell_window_ids.h" |
| 17 #include "ash/system/status_area_widget.h" | 19 #include "ash/system/status_area_widget.h" |
| 18 #include "ash/wm/property_util.h" | 20 #include "ash/wm/property_util.h" |
| 19 #include "ash/wm/window_cycle_controller.h" | 21 #include "ash/wm/window_cycle_controller.h" |
| 20 #include "ash/wm/window_util.h" | 22 #include "ash/wm/window_util.h" |
| 21 #include "ash/wm/workspace_controller.h" | 23 #include "ash/wm/workspace_controller.h" |
| 22 #include "ash/wm/workspace/workspace_animations.h" | 24 #include "ash/wm/workspace/workspace_animations.h" |
| 23 #include "base/auto_reset.h" | 25 #include "base/auto_reset.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 } | 141 } |
| 140 | 142 |
| 141 // Shelf we're in. NULL if deleted before we're deleted. | 143 // Shelf we're in. NULL if deleted before we're deleted. |
| 142 ShelfLayoutManager* shelf_; | 144 ShelfLayoutManager* shelf_; |
| 143 | 145 |
| 144 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); | 146 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); |
| 145 }; | 147 }; |
| 146 | 148 |
| 147 // ShelfLayoutManager ---------------------------------------------------------- | 149 // ShelfLayoutManager ---------------------------------------------------------- |
| 148 | 150 |
| 149 ShelfLayoutManager::ShelfLayoutManager(StatusAreaWidget* status_area_widget) | 151 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf) |
| 150 : root_window_(status_area_widget->GetNativeView()->GetRootWindow()), | 152 : root_window_(shelf->GetNativeView()->GetRootWindow()), |
| 151 in_layout_(false), | 153 in_layout_(false), |
| 152 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), | 154 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), |
| 153 alignment_(SHELF_ALIGNMENT_BOTTOM), | 155 alignment_(SHELF_ALIGNMENT_BOTTOM), |
| 154 launcher_(NULL), | 156 shelf_(shelf), |
| 155 status_area_widget_(status_area_widget), | |
| 156 workspace_controller_(NULL), | 157 workspace_controller_(NULL), |
| 157 window_overlaps_shelf_(false), | 158 window_overlaps_shelf_(false), |
| 158 gesture_drag_status_(GESTURE_DRAG_NONE), | 159 gesture_drag_status_(GESTURE_DRAG_NONE), |
| 159 gesture_drag_amount_(0.f), | 160 gesture_drag_amount_(0.f), |
| 160 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), | 161 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), |
| 161 update_shelf_observer_(NULL) { | 162 update_shelf_observer_(NULL) { |
| 162 Shell::GetInstance()->AddShellObserver(this); | 163 Shell::GetInstance()->AddShellObserver(this); |
| 163 aura::client::GetActivationClient(root_window_)->AddObserver(this); | 164 aura::client::GetActivationClient(root_window_)->AddObserver(this); |
| 164 } | 165 } |
| 165 | 166 |
| 166 ShelfLayoutManager::~ShelfLayoutManager() { | 167 ShelfLayoutManager::~ShelfLayoutManager() { |
| 167 if (update_shelf_observer_) | 168 if (update_shelf_observer_) |
| 168 update_shelf_observer_->Detach(); | 169 update_shelf_observer_->Detach(); |
| 169 | 170 |
| 170 FOR_EACH_OBSERVER(Observer, observers_, WillDeleteShelf()); | 171 FOR_EACH_OBSERVER(Observer, observers_, WillDeleteShelf()); |
| 171 Shell::GetInstance()->RemoveShellObserver(this); | 172 Shell::GetInstance()->RemoveShellObserver(this); |
| 172 aura::client::GetActivationClient(root_window_)->RemoveObserver(this); | 173 aura::client::GetActivationClient(root_window_)->RemoveObserver(this); |
| 173 } | 174 } |
| 174 | 175 |
| 175 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { | 176 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { |
| 176 if (auto_hide_behavior_ == behavior) | 177 if (auto_hide_behavior_ == behavior) |
| 177 return; | 178 return; |
| 178 auto_hide_behavior_ = behavior; | 179 auto_hide_behavior_ = behavior; |
| 179 UpdateVisibilityState(); | 180 UpdateVisibilityState(); |
| 180 FOR_EACH_OBSERVER(Observer, observers_, | 181 FOR_EACH_OBSERVER(Observer, observers_, |
| 181 OnAutoHideStateChanged(state_.auto_hide_state)); | 182 OnAutoHideStateChanged(state_.auto_hide_state)); |
| 182 } | 183 } |
| 183 | 184 |
| 184 bool ShelfLayoutManager::IsVisible() const { | 185 bool ShelfLayoutManager::IsVisible() const { |
| 185 return status_area_widget_->IsVisible() && | 186 return shelf_->status_area_widget()->IsVisible() && |
| 186 (state_.visibility_state == SHELF_VISIBLE || | 187 (state_.visibility_state == SHELF_VISIBLE || |
| 187 (state_.visibility_state == SHELF_AUTO_HIDE && | 188 (state_.visibility_state == SHELF_AUTO_HIDE && |
| 188 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); | 189 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); |
| 189 } | 190 } |
| 190 | 191 |
| 191 void ShelfLayoutManager::SetLauncher(Launcher* launcher) { | |
| 192 if (launcher == launcher_) | |
| 193 return; | |
| 194 | |
| 195 launcher_ = launcher; | |
| 196 if (launcher_) | |
| 197 launcher_->SetAlignment(alignment_); | |
| 198 LayoutShelf(); | |
| 199 } | |
| 200 | |
| 201 bool ShelfLayoutManager::SetAlignment(ShelfAlignment alignment) { | 192 bool ShelfLayoutManager::SetAlignment(ShelfAlignment alignment) { |
| 202 if (alignment_ == alignment) | 193 if (alignment_ == alignment) |
| 203 return false; | 194 return false; |
| 204 | 195 |
| 205 alignment_ = alignment; | 196 alignment_ = alignment; |
| 206 if (launcher_) | 197 if (shelf_->launcher()) |
| 207 launcher_->SetAlignment(alignment); | 198 shelf_->launcher()->SetAlignment(alignment); |
| 208 status_area_widget_->SetShelfAlignment(alignment); | 199 shelf_->status_area_widget()->SetShelfAlignment(alignment); |
| 209 LayoutShelf(); | 200 LayoutShelf(); |
| 210 return true; | 201 return true; |
| 211 } | 202 } |
| 212 | 203 |
| 213 gfx::Rect ShelfLayoutManager::GetIdealBounds() { | 204 gfx::Rect ShelfLayoutManager::GetIdealBounds() { |
| 214 // TODO(oshima): this is wrong. Figure out what display shelf is on | 205 // TODO(oshima): this is wrong. Figure out what display shelf is on |
| 215 // and everything should be based on it. | 206 // and everything should be based on it. |
| 216 gfx::Rect bounds(ScreenAsh::GetDisplayBoundsInParent( | 207 gfx::Rect bounds( |
| 217 status_area_widget_->GetNativeView())); | 208 ScreenAsh::GetDisplayBoundsInParent(shelf_->GetNativeView())); |
| 218 int width = 0, height = 0; | 209 int width = 0, height = 0; |
| 219 GetShelfSize(&width, &height); | 210 GetShelfSize(&width, &height); |
| 220 return SelectValueForShelfAlignment( | 211 return SelectValueForShelfAlignment( |
| 221 gfx::Rect(bounds.x(), bounds.bottom() - height, bounds.width(), height), | 212 gfx::Rect(bounds.x(), bounds.bottom() - height, bounds.width(), height), |
| 222 gfx::Rect(bounds.x(), bounds.y(), width, bounds.height()), | 213 gfx::Rect(bounds.x(), bounds.y(), width, bounds.height()), |
| 223 gfx::Rect(bounds.right() - width, bounds.y(), width, bounds.height()), | 214 gfx::Rect(bounds.right() - width, bounds.y(), width, bounds.height()), |
| 224 gfx::Rect(bounds.x(), bounds.y(), bounds.width(), height)); | 215 gfx::Rect(bounds.x(), bounds.y(), bounds.width(), height)); |
| 225 } | 216 } |
| 226 | 217 |
| 227 void ShelfLayoutManager::LayoutShelf() { | 218 void ShelfLayoutManager::LayoutShelf() { |
| 228 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | 219 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
| 229 StopAnimating(); | 220 StopAnimating(); |
| 230 TargetBounds target_bounds; | 221 TargetBounds target_bounds; |
| 231 CalculateTargetBounds(state_, &target_bounds); | 222 CalculateTargetBounds(state_, &target_bounds); |
| 232 if (launcher_widget()) { | 223 GetLayer(shelf_)->SetOpacity(target_bounds.opacity); |
| 233 GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity); | 224 shelf_->SetBounds( |
| 234 launcher_->SetWidgetBounds( | |
| 235 ScreenAsh::ConvertRectToScreen( | |
| 236 launcher_widget()->GetNativeView()->parent(), | |
| 237 target_bounds.launcher_bounds_in_root)); | |
| 238 launcher_->SetStatusSize(target_bounds.status_bounds_in_root.size()); | |
| 239 } | |
| 240 GetLayer(status_area_widget_)->SetOpacity(target_bounds.opacity); | |
| 241 status_area_widget_->SetBounds( | |
| 242 ScreenAsh::ConvertRectToScreen( | 225 ScreenAsh::ConvertRectToScreen( |
| 243 status_area_widget_->GetNativeView()->parent(), | 226 shelf_->GetNativeView()->parent(), |
| 244 target_bounds.status_bounds_in_root)); | 227 target_bounds.shelf_bounds_in_root)); |
| 228 if (shelf_->launcher()) | |
| 229 shelf_->launcher()->SetLauncherViewBounds( | |
| 230 target_bounds.launcher_bounds_in_shelf); | |
| 231 GetLayer(shelf_->status_area_widget())->SetOpacity(target_bounds.opacity); | |
| 232 // TODO(harrym): Once status area widget is a child view of shelf | |
| 233 // this can be simplified. | |
| 234 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; | |
| 235 status_bounds.set_x(status_bounds.x() + | |
| 236 target_bounds.shelf_bounds_in_root.x()); | |
| 237 status_bounds.set_y(status_bounds.y() + | |
| 238 target_bounds.shelf_bounds_in_root.y()); | |
| 239 shelf_->status_area_widget()->SetBounds( | |
| 240 ScreenAsh::ConvertRectToScreen( | |
| 241 shelf_->status_area_widget()->GetNativeView()->parent(), | |
| 242 status_bounds)); | |
| 245 Shell::GetInstance()->SetDisplayWorkAreaInsets( | 243 Shell::GetInstance()->SetDisplayWorkAreaInsets( |
| 246 root_window_, target_bounds.work_area_insets); | 244 root_window_, target_bounds.work_area_insets); |
| 247 UpdateHitTestBounds(); | 245 UpdateHitTestBounds(); |
| 248 } | 246 } |
| 249 | 247 |
| 250 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { | 248 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { |
| 251 switch(auto_hide_behavior_) { | 249 switch(auto_hide_behavior_) { |
| 252 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: | 250 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
| 253 return SHELF_AUTO_HIDE; | 251 return SHELF_AUTO_HIDE; |
| 254 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: | 252 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 bool horizontal = IsHorizontalAlignment(); | 355 bool horizontal = IsHorizontalAlignment(); |
| 358 gesture_drag_amount_ += horizontal ? gesture.details().scroll_y() : | 356 gesture_drag_amount_ += horizontal ? gesture.details().scroll_y() : |
| 359 gesture.details().scroll_x(); | 357 gesture.details().scroll_x(); |
| 360 LayoutShelf(); | 358 LayoutShelf(); |
| 361 | 359 |
| 362 // Start reveling the status menu when: | 360 // Start reveling the status menu when: |
| 363 // - dragging up on an already visible shelf | 361 // - dragging up on an already visible shelf |
| 364 // - dragging up on a hidden shelf, but it is currently completely visible. | 362 // - dragging up on a hidden shelf, but it is currently completely visible. |
| 365 if (horizontal && gesture.details().scroll_y() < 0) { | 363 if (horizontal && gesture.details().scroll_y() < 0) { |
| 366 int min_height = 0; | 364 int min_height = 0; |
| 367 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 365 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && shelf_) |
| 368 launcher_widget()) | 366 min_height = shelf_->GetContentsView()->GetPreferredSize().height(); |
| 369 min_height = launcher_widget()->GetContentsView()-> | |
| 370 GetPreferredSize().height(); | |
| 371 | 367 |
| 372 if (min_height < launcher_widget()->GetWindowBoundsInScreen().height() && | 368 if (min_height < shelf_->GetWindowBoundsInScreen().height() && |
| 373 gesture.root_location().x() >= | 369 gesture.root_location().x() >= |
| 374 status_area_widget_->GetWindowBoundsInScreen().x() && | 370 shelf_->status_area_widget()->GetWindowBoundsInScreen().x() && |
| 375 IsDraggingTrayEnabled()) | 371 IsDraggingTrayEnabled()) |
| 376 return DRAG_TRAY; | 372 return DRAG_TRAY; |
| 377 } | 373 } |
| 378 | 374 |
| 379 return DRAG_SHELF; | 375 return DRAG_SHELF; |
| 380 } | 376 } |
| 381 | 377 |
| 382 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { | 378 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { |
| 383 bool horizontal = IsHorizontalAlignment(); | 379 bool horizontal = IsHorizontalAlignment(); |
| 384 bool should_change = false; | 380 bool should_change = false; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 } | 418 } |
| 423 | 419 |
| 424 if (!should_change) { | 420 if (!should_change) { |
| 425 CancelGestureDrag(); | 421 CancelGestureDrag(); |
| 426 return; | 422 return; |
| 427 } | 423 } |
| 428 | 424 |
| 429 gesture_drag_auto_hide_state_ = | 425 gesture_drag_auto_hide_state_ = |
| 430 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN ? | 426 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN ? |
| 431 SHELF_AUTO_HIDE_HIDDEN : SHELF_AUTO_HIDE_SHOWN; | 427 SHELF_AUTO_HIDE_HIDDEN : SHELF_AUTO_HIDE_SHOWN; |
| 432 if (launcher_widget()) | 428 if (shelf_) |
| 433 launcher_widget()->Deactivate(); | 429 shelf_->Deactivate(); |
| 434 status_area_widget_->Deactivate(); | 430 shelf_->status_area_widget()->Deactivate(); |
| 435 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 431 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
| 436 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS) { | 432 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS) { |
| 437 gesture_drag_status_ = GESTURE_DRAG_NONE; | 433 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 438 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 434 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 439 } else if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN && | 435 } else if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN && |
| 440 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_NEVER) { | 436 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_NEVER) { |
| 441 gesture_drag_status_ = GESTURE_DRAG_NONE; | 437 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 442 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 438 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 443 } else { | 439 } else { |
| 444 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; | 440 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; |
| 445 UpdateVisibilityState(); | 441 UpdateVisibilityState(); |
| 446 gesture_drag_status_ = GESTURE_DRAG_NONE; | 442 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 447 } | 443 } |
| 448 } | 444 } |
| 449 | 445 |
| 450 void ShelfLayoutManager::CancelGestureDrag() { | 446 void ShelfLayoutManager::CancelGestureDrag() { |
| 451 gesture_drag_status_ = GESTURE_DRAG_NONE; | 447 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 452 ui::ScopedLayerAnimationSettings | 448 ui::ScopedLayerAnimationSettings |
| 453 launcher_settings(GetLayer(launcher_widget())->GetAnimator()), | 449 launcher_settings(GetLayer(shelf_)->GetAnimator()), |
| 454 status_settings(GetLayer(status_area_widget_)->GetAnimator()); | 450 status_settings(GetLayer(shelf_->status_area_widget())->GetAnimator()); |
| 455 LayoutShelf(); | 451 LayoutShelf(); |
| 456 UpdateVisibilityState(); | 452 UpdateVisibilityState(); |
| 457 UpdateShelfBackground(BackgroundAnimator::CHANGE_ANIMATE); | 453 UpdateShelfBackground(BackgroundAnimator::CHANGE_ANIMATE); |
| 458 } | 454 } |
| 459 | 455 |
| 460 //////////////////////////////////////////////////////////////////////////////// | 456 //////////////////////////////////////////////////////////////////////////////// |
| 461 // ShelfLayoutManager, aura::LayoutManager implementation: | 457 // ShelfLayoutManager, aura::LayoutManager implementation: |
| 462 | 458 |
| 463 void ShelfLayoutManager::OnWindowResized() { | 459 void ShelfLayoutManager::OnWindowResized() { |
| 464 LayoutShelf(); | 460 LayoutShelf(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 476 void ShelfLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | 472 void ShelfLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, |
| 477 bool visible) { | 473 bool visible) { |
| 478 } | 474 } |
| 479 | 475 |
| 480 void ShelfLayoutManager::SetChildBounds(aura::Window* child, | 476 void ShelfLayoutManager::SetChildBounds(aura::Window* child, |
| 481 const gfx::Rect& requested_bounds) { | 477 const gfx::Rect& requested_bounds) { |
| 482 SetChildBoundsDirect(child, requested_bounds); | 478 SetChildBoundsDirect(child, requested_bounds); |
| 483 // We may contain other widgets (such as frame maximize bubble) but they don't | 479 // We may contain other widgets (such as frame maximize bubble) but they don't |
| 484 // effect the layout in anyway. | 480 // effect the layout in anyway. |
| 485 if (!in_layout_ && | 481 if (!in_layout_ && |
| 486 ((launcher_widget() && launcher_widget()->GetNativeView() == child) || | 482 ((shelf_->GetNativeView() == child) || |
| 487 (status_area_widget_->GetNativeView() == child))) { | 483 (shelf_->status_area_widget()->GetNativeView() == child))) { |
| 488 LayoutShelf(); | 484 LayoutShelf(); |
| 489 } | 485 } |
| 490 } | 486 } |
| 491 | 487 |
| 492 void ShelfLayoutManager::OnLockStateChanged(bool locked) { | 488 void ShelfLayoutManager::OnLockStateChanged(bool locked) { |
| 493 UpdateVisibilityState(); | 489 UpdateVisibilityState(); |
| 494 } | 490 } |
| 495 | 491 |
| 496 void ShelfLayoutManager::OnWindowActivated(aura::Window* gained_active, | 492 void ShelfLayoutManager::OnWindowActivated(aura::Window* gained_active, |
| 497 aura::Window* lost_active) { | 493 aura::Window* lost_active) { |
| 498 UpdateAutoHideStateNow(); | 494 UpdateAutoHideStateNow(); |
| 499 } | 495 } |
| 500 | 496 |
| 501 bool ShelfLayoutManager::IsHorizontalAlignment() const { | 497 bool ShelfLayoutManager::IsHorizontalAlignment() const { |
| 502 return alignment_ == SHELF_ALIGNMENT_BOTTOM || | 498 return alignment_ == SHELF_ALIGNMENT_BOTTOM || |
| 503 alignment_ == SHELF_ALIGNMENT_TOP; | 499 alignment_ == SHELF_ALIGNMENT_TOP; |
| 504 } | 500 } |
| 505 | 501 |
| 506 // static | 502 // static |
| 507 ShelfLayoutManager* ShelfLayoutManager::ForLauncher(aura::Window* window) { | 503 ShelfLayoutManager* ShelfLayoutManager::ForLauncher(aura::Window* window) { |
| 508 return RootWindowController::ForLauncher(window)->shelf(); | 504 ShelfWidget* shelf = RootWindowController::ForLauncher(window)->shelf(); |
| 505 return shelf ? shelf->shelf_layout_manager() : NULL; | |
| 509 } | 506 } |
| 510 | 507 |
| 511 //////////////////////////////////////////////////////////////////////////////// | 508 //////////////////////////////////////////////////////////////////////////////// |
| 512 // ShelfLayoutManager, private: | 509 // ShelfLayoutManager, private: |
| 513 | 510 |
| 514 ShelfLayoutManager::TargetBounds::TargetBounds() : opacity(0.0f) {} | 511 ShelfLayoutManager::TargetBounds::TargetBounds() : opacity(0.0f) {} |
| 515 | 512 |
| 516 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { | 513 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { |
| 517 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | 514 ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
| 518 State state; | 515 State state; |
| 519 state.visibility_state = visibility_state; | 516 state.visibility_state = visibility_state; |
| 520 state.auto_hide_state = CalculateAutoHideState(visibility_state); | 517 state.auto_hide_state = CalculateAutoHideState(visibility_state); |
| 521 state.is_screen_locked = delegate && delegate->IsScreenLocked(); | 518 state.is_screen_locked = delegate && delegate->IsScreenLocked(); |
| 522 | 519 |
| 523 // It's possible for SetState() when a window becomes maximized but the state | 520 // It's possible for SetState() when a window becomes maximized but the state |
| 524 // won't have changed value. Do the dimming check before the early exit. | 521 // won't have changed value. Do the dimming check before the early exit. |
| 525 if (launcher_ && workspace_controller_) { | 522 if (workspace_controller_) { |
| 526 launcher_->SetDimsShelf( | 523 shelf_->SetDimsShelf( |
| 527 (state.visibility_state == SHELF_VISIBLE) && | 524 (state.visibility_state == SHELF_VISIBLE) && |
| 528 workspace_controller_->GetWindowState() == | 525 workspace_controller_->GetWindowState() == |
| 529 WORKSPACE_WINDOW_STATE_MAXIMIZED); | 526 WORKSPACE_WINDOW_STATE_MAXIMIZED); |
| 530 } | 527 } |
| 531 | 528 |
| 532 if (state_.Equals(state)) | 529 if (state_.Equals(state)) |
| 533 return; // Nothing changed. | 530 return; // Nothing changed. |
| 534 | 531 |
| 535 FOR_EACH_OBSERVER(Observer, observers_, | 532 FOR_EACH_OBSERVER(Observer, observers_, |
| 536 WillChangeVisibilityState(visibility_state)); | 533 WillChangeVisibilityState(visibility_state)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 552 (state_.visibility_state == SHELF_AUTO_HIDE && | 549 (state_.visibility_state == SHELF_AUTO_HIDE && |
| 553 state_.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && | 550 state_.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && |
| 554 state.visibility_state == SHELF_VISIBLE) ? | 551 state.visibility_state == SHELF_VISIBLE) ? |
| 555 BackgroundAnimator::CHANGE_IMMEDIATE : BackgroundAnimator::CHANGE_ANIMATE; | 552 BackgroundAnimator::CHANGE_IMMEDIATE : BackgroundAnimator::CHANGE_ANIMATE; |
| 556 StopAnimating(); | 553 StopAnimating(); |
| 557 | 554 |
| 558 State old_state = state_; | 555 State old_state = state_; |
| 559 state_ = state; | 556 state_ = state; |
| 560 TargetBounds target_bounds; | 557 TargetBounds target_bounds; |
| 561 CalculateTargetBounds(state_, &target_bounds); | 558 CalculateTargetBounds(state_, &target_bounds); |
| 562 if (launcher_widget()) { | 559 |
| 563 ui::ScopedLayerAnimationSettings launcher_animation_setter( | 560 ui::ScopedLayerAnimationSettings launcher_animation_setter( |
| 564 GetLayer(launcher_widget())->GetAnimator()); | 561 GetLayer(shelf_)->GetAnimator()); |
| 565 launcher_animation_setter.SetTransitionDuration( | 562 launcher_animation_setter.SetTransitionDuration( |
| 566 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); | 563 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); |
| 567 launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT); | 564 launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT); |
| 568 GetLayer(launcher_widget())->SetBounds( | 565 GetLayer(shelf_)->SetBounds( |
| 569 target_bounds.launcher_bounds_in_root); | 566 target_bounds.shelf_bounds_in_root); |
| 570 GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity); | 567 GetLayer(shelf_)->SetOpacity(target_bounds.opacity); |
| 571 } | |
| 572 ui::ScopedLayerAnimationSettings status_animation_setter( | 568 ui::ScopedLayerAnimationSettings status_animation_setter( |
| 573 GetLayer(status_area_widget_)->GetAnimator()); | 569 GetLayer(shelf_->status_area_widget())->GetAnimator()); |
| 574 status_animation_setter.SetTransitionDuration( | 570 status_animation_setter.SetTransitionDuration( |
| 575 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); | 571 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); |
| 576 status_animation_setter.SetTweenType(ui::Tween::EASE_OUT); | 572 status_animation_setter.SetTweenType(ui::Tween::EASE_OUT); |
| 577 | 573 |
| 578 // Delay updating the background when going from SHELF_AUTO_HIDE_SHOWN to | 574 // Delay updating the background when going from SHELF_AUTO_HIDE_SHOWN to |
| 579 // SHELF_AUTO_HIDE_HIDDEN until the shelf animates out. Otherwise during the | 575 // SHELF_AUTO_HIDE_HIDDEN until the shelf animates out. Otherwise during the |
| 580 // animation you see the background change. | 576 // animation you see the background change. |
| 581 // Also delay the animation when the shelf was hidden, and has just been made | 577 // Also delay the animation when the shelf was hidden, and has just been made |
| 582 // visible (e.g. using a gesture-drag). | 578 // visible (e.g. using a gesture-drag). |
| 583 bool delay_shelf_update = | 579 bool delay_shelf_update = |
| 584 state.visibility_state == SHELF_AUTO_HIDE && | 580 state.visibility_state == SHELF_AUTO_HIDE && |
| 585 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && | 581 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && |
| 586 old_state.visibility_state == SHELF_AUTO_HIDE; | 582 old_state.visibility_state == SHELF_AUTO_HIDE; |
| 587 | 583 |
| 588 if (state.visibility_state == SHELF_VISIBLE && | 584 if (state.visibility_state == SHELF_VISIBLE && |
| 589 old_state.visibility_state == SHELF_AUTO_HIDE && | 585 old_state.visibility_state == SHELF_AUTO_HIDE && |
| 590 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) | 586 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) |
| 591 delay_shelf_update = true; | 587 delay_shelf_update = true; |
| 592 | 588 |
| 593 if (delay_shelf_update) { | 589 if (delay_shelf_update) { |
| 594 if (update_shelf_observer_) | 590 if (update_shelf_observer_) |
| 595 update_shelf_observer_->Detach(); | 591 update_shelf_observer_->Detach(); |
| 596 // UpdateShelfBackground deletes itself when the animation is done. | 592 // UpdateShelfBackground deletes itself when the animation is done. |
| 597 update_shelf_observer_ = new UpdateShelfObserver(this); | 593 update_shelf_observer_ = new UpdateShelfObserver(this); |
| 598 status_animation_setter.AddObserver(update_shelf_observer_); | 594 status_animation_setter.AddObserver(update_shelf_observer_); |
| 599 } | 595 } |
| 600 ui::Layer* layer = GetLayer(status_area_widget_); | 596 ui::Layer* layer = GetLayer(shelf_->status_area_widget()); |
| 601 layer->SetBounds(target_bounds.status_bounds_in_root); | 597 // TODO(harrym): Remove when status_area is view. |
|
James Cook
2013/03/05 20:30:38
Do you have a bug open for this "convert to view"
Harry McCleave
2013/03/06 01:59:49
Created: https://code.google.com/p/chromium/issues
| |
| 598 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; | |
| 599 status_bounds.set_x(status_bounds.x() + | |
| 600 target_bounds.shelf_bounds_in_root.x()); | |
| 601 status_bounds.set_y(status_bounds.y() + | |
| 602 target_bounds.shelf_bounds_in_root.y()); | |
| 603 layer->SetBounds(status_bounds); | |
| 602 layer->SetOpacity(target_bounds.opacity); | 604 layer->SetOpacity(target_bounds.opacity); |
| 603 Shell::GetInstance()->SetDisplayWorkAreaInsets( | 605 Shell::GetInstance()->SetDisplayWorkAreaInsets( |
| 604 root_window_, target_bounds.work_area_insets); | 606 root_window_, target_bounds.work_area_insets); |
| 605 UpdateHitTestBounds(); | 607 UpdateHitTestBounds(); |
| 606 if (!delay_shelf_update) | 608 if (!delay_shelf_update) |
| 607 UpdateShelfBackground(change_type); | 609 UpdateShelfBackground(change_type); |
| 608 } | 610 } |
| 609 | 611 |
| 610 void ShelfLayoutManager::StopAnimating() { | 612 void ShelfLayoutManager::StopAnimating() { |
| 611 ui::Layer* layer = GetLayer(status_area_widget_); | 613 GetLayer(shelf_)->GetAnimator()->StopAnimating(); |
| 612 if (launcher_widget()) | 614 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); |
| 613 layer->GetAnimator()->StopAnimating(); | |
| 614 layer->GetAnimator()->StopAnimating(); | |
| 615 } | 615 } |
| 616 | 616 |
| 617 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { | 617 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { |
| 618 *width = *height = 0; | 618 *width = *height = 0; |
| 619 gfx::Size status_size(status_area_widget_->GetWindowBoundsInScreen().size()); | 619 gfx::Size status_size( |
| 620 gfx::Size launcher_size = launcher_ ? | 620 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); |
| 621 launcher_widget()->GetContentsView()->GetPreferredSize() : gfx::Size(); | |
| 622 if (IsHorizontalAlignment()) | 621 if (IsHorizontalAlignment()) |
| 623 *height = std::max(launcher_size.height(), status_size.height()); | 622 *height = std::max(kLauncherPreferredSize, status_size.height()); |
| 624 else | 623 else |
| 625 *width = std::max(launcher_size.width(), status_size.width()); | 624 *width = std::max(kLauncherPreferredSize, status_size.width()); |
| 626 } | 625 } |
| 627 | 626 |
| 628 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, | 627 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, |
| 629 gfx::Rect* bounds) const { | 628 gfx::Rect* bounds) const { |
| 630 bounds->Inset(SelectValueForShelfAlignment( | 629 bounds->Inset(SelectValueForShelfAlignment( |
| 631 gfx::Insets(0, 0, inset, 0), | 630 gfx::Insets(0, 0, inset, 0), |
| 632 gfx::Insets(0, inset, 0, 0), | 631 gfx::Insets(0, inset, 0, 0), |
| 633 gfx::Insets(0, 0, 0, inset), | 632 gfx::Insets(0, 0, 0, inset), |
| 634 gfx::Insets(inset, 0, 0, 0))); | 633 gfx::Insets(inset, 0, 0, 0))); |
| 635 } | 634 } |
| 636 | 635 |
| 637 void ShelfLayoutManager::CalculateTargetBounds( | 636 void ShelfLayoutManager::CalculateTargetBounds( |
| 638 const State& state, | 637 const State& state, |
| 639 TargetBounds* target_bounds) { | 638 TargetBounds* target_bounds) { |
| 640 const gfx::Rect& available_bounds(root_window_->bounds()); | 639 const gfx::Rect& available_bounds(root_window_->bounds()); |
| 641 gfx::Rect status_size(status_area_widget_->GetWindowBoundsInScreen().size()); | 640 gfx::Rect status_size( |
| 642 gfx::Size launcher_size = launcher_ ? | 641 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); |
| 643 launcher_widget()->GetContentsView()->GetPreferredSize() : gfx::Size(); | |
| 644 int shelf_size = 0; | |
| 645 int shelf_width = 0, shelf_height = 0; | 642 int shelf_width = 0, shelf_height = 0; |
| 646 GetShelfSize(&shelf_width, &shelf_height); | 643 GetShelfSize(&shelf_width, &shelf_height); |
| 647 if (state.visibility_state == SHELF_VISIBLE || | 644 if (IsHorizontalAlignment()) |
| 648 (state.visibility_state == SHELF_AUTO_HIDE && | 645 shelf_width = available_bounds.width(); |
| 649 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)) { | 646 else |
| 650 shelf_size = std::max(shelf_width, shelf_height); | 647 shelf_height = available_bounds.height(); |
| 651 launcher_size.set_width(std::max(shelf_width,launcher_size.width())); | 648 |
| 652 launcher_size.set_height(std::max(shelf_height,launcher_size.height())); | 649 if (state.visibility_state == SHELF_AUTO_HIDE && |
| 653 } else if (state.visibility_state == SHELF_AUTO_HIDE && | 650 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
| 654 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { | |
| 655 shelf_size = kAutoHideSize; | |
| 656 // Keep the launcher to its full height when dragging is in progress. | 651 // Keep the launcher to its full height when dragging is in progress. |
| 657 if (gesture_drag_status_ == GESTURE_DRAG_NONE) { | 652 if (gesture_drag_status_ == GESTURE_DRAG_NONE) { |
| 658 if (IsHorizontalAlignment()) | 653 if (IsHorizontalAlignment()) |
| 659 launcher_size.set_height(kAutoHideSize); | 654 shelf_height = kAutoHideSize; |
| 660 else | 655 else |
| 661 launcher_size.set_width(kAutoHideSize); | 656 shelf_width = kAutoHideSize; |
| 662 } | 657 } |
| 658 } else if (state.visibility_state == SHELF_HIDDEN) { | |
| 659 if (IsHorizontalAlignment()) | |
| 660 shelf_height = 0; | |
| 661 else | |
| 662 shelf_width = 0; | |
| 663 } | 663 } |
| 664 switch(alignment_) { | 664 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( |
|
James Cook
2013/03/05 20:30:38
Wow. I hope there are unit tests for this. :-)
Harry McCleave
2013/03/06 01:59:49
ShelfWidgetTest.LauncherInitiallySized
ShelfLayout
| |
| 665 case SHELF_ALIGNMENT_BOTTOM: | 665 gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height, |
| 666 // The status widget should extend to the bottom and right edges. | 666 available_bounds.width(), shelf_height), |
| 667 target_bounds->status_bounds_in_root = gfx::Rect( | 667 gfx::Rect(available_bounds.x(), available_bounds.y(), |
| 668 base::i18n::IsRTL() ? available_bounds.x() : | 668 shelf_width, available_bounds.height()), |
| 669 available_bounds.right() - status_size.width(), | 669 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), |
| 670 available_bounds.bottom() - shelf_size + shelf_height - | 670 shelf_width, available_bounds.height()), |
| 671 status_size.height(), | 671 gfx::Rect(available_bounds.x(), available_bounds.y(), |
| 672 status_size.width(), status_size.height()); | 672 available_bounds.width(), shelf_height)); |
| 673 if (launcher_widget()) | 673 |
| 674 target_bounds->launcher_bounds_in_root = gfx::Rect( | 674 int status_inset = (kLauncherPreferredSize - |
| 675 available_bounds.x(), | 675 PrimaryAxisValue(status_size.height(), status_size.width())); |
| 676 available_bounds.bottom() - shelf_size, | 676 |
| 677 available_bounds.width(), | 677 target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( |
| 678 launcher_size.height()); | 678 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
| 679 target_bounds->work_area_insets.Set( | 679 status_inset, status_size.width(), status_size.height()), |
| 680 0, 0, GetWorkAreaSize(state, shelf_height), 0); | 680 gfx::Rect(shelf_width - (status_size.width() + status_inset), |
| 681 break; | 681 shelf_height - status_size.height(), status_size.width(), |
| 682 case SHELF_ALIGNMENT_LEFT: | 682 status_size.height()), |
| 683 target_bounds->status_bounds_in_root = gfx::Rect( | 683 gfx::Rect(status_inset, shelf_height - status_size.height(), |
| 684 available_bounds.x() + launcher_size.width() - status_size.width(), | 684 status_size.width(), status_size.height()), |
| 685 available_bounds.bottom() - status_size.height(), | 685 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
| 686 shelf_width, status_size.height()); | 686 shelf_height - (status_size.height() + status_inset), |
| 687 if (launcher_widget()) | 687 status_size.width(), status_size.height())); |
| 688 target_bounds->launcher_bounds_in_root = gfx::Rect( | 688 |
| 689 available_bounds.x(), available_bounds.y(), | 689 target_bounds->launcher_bounds_in_shelf = SelectValueForShelfAlignment( |
| 690 launcher_size.width(), available_bounds.height()); | 690 gfx::Rect(base::i18n::IsRTL() ? status_size.width() : 0, 0, |
| 691 target_bounds->work_area_insets.Set( | 691 shelf_width - status_size.width(), shelf_height), |
| 692 0, GetWorkAreaSize(state, launcher_size.width()), 0, 0); | 692 gfx::Rect(0, 0, shelf_width, shelf_height - status_size.height()), |
| 693 break; | 693 gfx::Rect(0, 0, shelf_width, shelf_height - status_size.height()), |
| 694 case SHELF_ALIGNMENT_RIGHT: | 694 gfx::Rect(base::i18n::IsRTL() ? status_size.width() : 0, 0, |
| 695 target_bounds->status_bounds_in_root = gfx::Rect( | 695 shelf_width - status_size.width(), shelf_height)); |
| 696 available_bounds.right()- status_size.width() - | 696 |
| 697 shelf_size + shelf_width, | 697 target_bounds->work_area_insets = SelectValueForShelfAlignment( |
| 698 available_bounds.bottom() - status_size.height(), | 698 gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0), |
| 699 shelf_width, status_size.height()); | 699 gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0), |
| 700 if (launcher_widget()) | 700 gfx::Insets(0, 0, 0, GetWorkAreaSize(state, shelf_width)), |
| 701 target_bounds->launcher_bounds_in_root = gfx::Rect( | 701 gfx::Insets(GetWorkAreaSize(state, shelf_height), 0, 0, 0)); |
| 702 available_bounds.right() - launcher_size.width(), | 702 |
| 703 available_bounds.y(), | |
| 704 launcher_size.width(), available_bounds.height()); | |
| 705 target_bounds->work_area_insets.Set( | |
| 706 0, 0, 0, GetWorkAreaSize(state, launcher_size.width())); | |
| 707 break; | |
| 708 case SHELF_ALIGNMENT_TOP: | |
| 709 target_bounds->status_bounds_in_root = gfx::Rect( | |
| 710 base::i18n::IsRTL() ? available_bounds.x() : | |
| 711 available_bounds.right() - status_size.width(), | |
| 712 available_bounds.y() + launcher_size.height() - status_size.height(), | |
| 713 status_size.width(), status_size.height()); | |
| 714 if (launcher_widget()) | |
| 715 target_bounds->launcher_bounds_in_root = gfx::Rect( | |
| 716 available_bounds.x(), | |
| 717 available_bounds.y(), | |
| 718 available_bounds.width(), | |
| 719 launcher_size.height()); | |
| 720 target_bounds->work_area_insets.Set( | |
| 721 GetWorkAreaSize(state, shelf_height), 0, 0, 0); | |
| 722 break; | |
| 723 } | |
| 724 target_bounds->opacity = | 703 target_bounds->opacity = |
| 725 (gesture_drag_status_ != GESTURE_DRAG_NONE || | 704 (gesture_drag_status_ != GESTURE_DRAG_NONE || |
| 726 state.visibility_state == SHELF_VISIBLE || | 705 state.visibility_state == SHELF_VISIBLE || |
| 727 state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; | 706 state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; |
| 728 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS) | 707 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS) |
| 729 UpdateTargetBoundsForGesture(target_bounds); | 708 UpdateTargetBoundsForGesture(target_bounds); |
| 730 } | 709 } |
| 731 | 710 |
| 732 void ShelfLayoutManager::UpdateTargetBoundsForGesture( | 711 void ShelfLayoutManager::UpdateTargetBoundsForGesture( |
| 733 TargetBounds* target_bounds) const { | 712 TargetBounds* target_bounds) const { |
| 734 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); | 713 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); |
| 735 bool horizontal = IsHorizontalAlignment(); | 714 bool horizontal = IsHorizontalAlignment(); |
| 736 int resistance_free_region = 0; | 715 int resistance_free_region = 0; |
| 737 | 716 |
| 738 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 717 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
| 739 visibility_state() == SHELF_AUTO_HIDE && | 718 visibility_state() == SHELF_AUTO_HIDE && |
| 740 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { | 719 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
| 741 // If the shelf was hidden when the drag started (and the state hasn't | 720 // If the shelf was hidden when the drag started (and the state hasn't |
| 742 // changed since then, e.g. because the tray-menu was shown because of the | 721 // changed since then, e.g. because the tray-menu was shown because of the |
| 743 // drag), then allow the drag some resistance-free region at first to make | 722 // drag), then allow the drag some resistance-free region at first to make |
| 744 // sure the shelf sticks with the finger until the shelf is visible. | 723 // sure the shelf sticks with the finger until the shelf is visible. |
| 745 resistance_free_region += horizontal ? | 724 resistance_free_region += horizontal ? |
| 746 target_bounds->launcher_bounds_in_root.height() : | 725 target_bounds->shelf_bounds_in_root.height() : |
| 747 target_bounds->launcher_bounds_in_root.width(); | 726 target_bounds->shelf_bounds_in_root.width(); |
| 748 resistance_free_region -= kAutoHideSize; | 727 resistance_free_region -= kAutoHideSize; |
| 749 } | 728 } |
| 750 | 729 |
| 751 bool resist = SelectValueForShelfAlignment( | 730 bool resist = SelectValueForShelfAlignment( |
| 752 gesture_drag_amount_ < -resistance_free_region, | 731 gesture_drag_amount_ < -resistance_free_region, |
| 753 gesture_drag_amount_ > resistance_free_region, | 732 gesture_drag_amount_ > resistance_free_region, |
| 754 gesture_drag_amount_ < -resistance_free_region, | 733 gesture_drag_amount_ < -resistance_free_region, |
| 755 gesture_drag_amount_ > resistance_free_region); | 734 gesture_drag_amount_ > resistance_free_region); |
| 756 | 735 |
| 757 float translate = 0.f; | 736 float translate = 0.f; |
| 758 if (resist) { | 737 if (resist) { |
| 759 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; | 738 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; |
| 760 diff = std::min(diff, sqrtf(diff)); | 739 diff = std::min(diff, sqrtf(diff)); |
| 761 if (gesture_drag_amount_ < 0) | 740 if (gesture_drag_amount_ < 0) |
| 762 translate = -resistance_free_region - diff; | 741 translate = -resistance_free_region - diff; |
| 763 else | 742 else |
| 764 translate = resistance_free_region + diff; | 743 translate = resistance_free_region + diff; |
| 765 } else { | 744 } else { |
| 766 translate = gesture_drag_amount_; | 745 translate = gesture_drag_amount_; |
| 767 } | 746 } |
| 768 | 747 |
| 769 if (horizontal) { | 748 if (horizontal) { |
| 770 // Move the launcher with the gesture. | 749 // Move the launcher with the gesture. |
| 771 target_bounds->launcher_bounds_in_root.Offset(0, translate); | 750 target_bounds->shelf_bounds_in_root.Offset(0, translate); |
| 772 target_bounds->status_bounds_in_root.Offset(0, translate); | |
| 773 | 751 |
| 774 if (translate < 0) { | 752 if (translate < 0) { |
| 775 // When dragging up, the launcher height should increase. | 753 // When dragging up, the launcher height should increase. |
| 776 float move = std::max(translate, | 754 float move = std::max(translate, |
| 777 -static_cast<float>(resistance_free_region)); | 755 -static_cast<float>(resistance_free_region)); |
| 778 target_bounds->launcher_bounds_in_root.set_height( | 756 target_bounds->shelf_bounds_in_root.set_height( |
| 779 target_bounds->launcher_bounds_in_root.height() + move - translate); | 757 target_bounds->shelf_bounds_in_root.height() + move - translate); |
| 758 | |
| 759 // The statusbar should be in the center. | |
| 760 gfx::Rect status_y = target_bounds->shelf_bounds_in_root; | |
| 761 status_y.ClampToCenteredSize( | |
| 762 target_bounds->status_bounds_in_shelf.size()); | |
| 763 target_bounds->status_bounds_in_shelf.set_y(status_y.y()); | |
| 780 } | 764 } |
| 781 } else { | 765 } else { |
| 782 // Move the launcher with the gesture. | 766 // Move the launcher with the gesture. |
| 783 if (alignment_ == SHELF_ALIGNMENT_RIGHT) | 767 if (alignment_ == SHELF_ALIGNMENT_RIGHT) |
| 784 target_bounds->launcher_bounds_in_root.Offset(translate, 0); | 768 target_bounds->shelf_bounds_in_root.Offset(translate, 0); |
| 785 | 769 |
| 786 if ((translate > 0 && alignment_ == SHELF_ALIGNMENT_RIGHT) || | 770 if ((translate > 0 && alignment_ == SHELF_ALIGNMENT_RIGHT) || |
| 787 (translate < 0 && alignment_ == SHELF_ALIGNMENT_LEFT)) { | 771 (translate < 0 && alignment_ == SHELF_ALIGNMENT_LEFT)) { |
| 788 // When dragging towards the edge, the statusbar should move. | 772 // When dragging towards the edge, the statusbar should move. |
| 789 target_bounds->status_bounds_in_root.Offset(translate, 0); | 773 target_bounds->status_bounds_in_shelf.Offset(translate, 0); |
| 790 } else { | 774 } else { |
| 791 // When dragging away from the edge, the launcher width should increase. | 775 // When dragging away from the edge, the launcher width should increase. |
| 792 float move = alignment_ == SHELF_ALIGNMENT_RIGHT ? | 776 float move = alignment_ == SHELF_ALIGNMENT_RIGHT ? |
| 793 std::max(translate, -static_cast<float>(resistance_free_region)) : | 777 std::max(translate, -static_cast<float>(resistance_free_region)) : |
| 794 std::min(translate, static_cast<float>(resistance_free_region)); | 778 std::min(translate, static_cast<float>(resistance_free_region)); |
| 795 | 779 |
| 796 if (alignment_ == SHELF_ALIGNMENT_RIGHT) { | 780 if (alignment_ == SHELF_ALIGNMENT_RIGHT) { |
| 797 target_bounds->launcher_bounds_in_root.set_width( | 781 target_bounds->shelf_bounds_in_root.set_width( |
| 798 target_bounds->launcher_bounds_in_root.width() + move - translate); | 782 target_bounds->shelf_bounds_in_root.width() + move - translate); |
| 799 } else { | 783 } else { |
| 800 target_bounds->launcher_bounds_in_root.set_width( | 784 target_bounds->shelf_bounds_in_root.set_width( |
| 801 target_bounds->launcher_bounds_in_root.width() - move + translate); | 785 target_bounds->shelf_bounds_in_root.width() - move + translate); |
| 802 } | 786 } |
| 803 | 787 |
| 804 // The statusbar should be in the center. | 788 // The statusbar should be in the center. |
| 805 gfx::Rect status_x = target_bounds->launcher_bounds_in_root; | 789 gfx::Rect status_x = target_bounds->shelf_bounds_in_root; |
| 806 status_x.ClampToCenteredSize( | 790 status_x.ClampToCenteredSize( |
| 807 target_bounds->status_bounds_in_root.size()); | 791 target_bounds->status_bounds_in_shelf.size()); |
| 808 target_bounds->status_bounds_in_root.set_x(status_x.x()); | 792 target_bounds->status_bounds_in_shelf.set_x(status_x.x()); |
| 809 } | 793 } |
| 810 } | 794 } |
| 811 } | 795 } |
| 812 | 796 |
| 813 void ShelfLayoutManager::UpdateShelfBackground( | 797 void ShelfLayoutManager::UpdateShelfBackground( |
| 814 BackgroundAnimator::ChangeType type) { | 798 BackgroundAnimator::ChangeType type) { |
| 815 bool launcher_paints = GetLauncherPaintsBackground(); | 799 bool launcher_paints = GetLauncherPaintsBackground(); |
| 816 if (launcher_) | 800 shelf_->SetPaintsBackground(launcher_paints, type); |
| 817 launcher_->SetPaintsBackground(launcher_paints, type); | |
| 818 // The status area normally draws a background, but we don't want it to draw a | |
| 819 // background when the launcher does or when we're at login/lock screen. | |
| 820 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | |
| 821 bool delegate_allows_tray_bg = | |
| 822 delegate->IsUserLoggedIn() && !delegate->IsScreenLocked(); | |
| 823 bool status_area_paints = !launcher_paints && delegate_allows_tray_bg; | |
| 824 status_area_widget_->SetPaintsBackground(status_area_paints, type); | |
| 825 } | 801 } |
| 826 | 802 |
| 827 bool ShelfLayoutManager::GetLauncherPaintsBackground() const { | 803 bool ShelfLayoutManager::GetLauncherPaintsBackground() const { |
| 828 return gesture_drag_status_ != GESTURE_DRAG_NONE || | 804 return gesture_drag_status_ != GESTURE_DRAG_NONE || |
| 829 (!state_.is_screen_locked && window_overlaps_shelf_) || | 805 (!state_.is_screen_locked && window_overlaps_shelf_) || |
| 830 (state_.visibility_state == SHELF_AUTO_HIDE) ; | 806 (state_.visibility_state == SHELF_AUTO_HIDE) ; |
| 831 } | 807 } |
| 832 | 808 |
| 833 void ShelfLayoutManager::UpdateAutoHideStateNow() { | 809 void ShelfLayoutManager::UpdateAutoHideStateNow() { |
| 834 SetState(state_.visibility_state); | 810 SetState(state_.visibility_state); |
| 835 } | 811 } |
| 836 | 812 |
| 837 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( | 813 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( |
| 838 ShelfVisibilityState visibility_state) const { | 814 ShelfVisibilityState visibility_state) const { |
| 839 if (visibility_state != SHELF_AUTO_HIDE || !launcher_widget()) | 815 if (visibility_state != SHELF_AUTO_HIDE || !shelf_) |
| 840 return SHELF_AUTO_HIDE_HIDDEN; | 816 return SHELF_AUTO_HIDE_HIDDEN; |
| 841 | 817 |
| 842 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) | 818 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) |
| 843 return gesture_drag_auto_hide_state_; | 819 return gesture_drag_auto_hide_state_; |
| 844 | 820 |
| 845 Shell* shell = Shell::GetInstance(); | 821 Shell* shell = Shell::GetInstance(); |
| 846 if (shell->GetAppListTargetVisibility()) | 822 if (shell->GetAppListTargetVisibility()) |
| 847 return SHELF_AUTO_HIDE_SHOWN; | 823 return SHELF_AUTO_HIDE_SHOWN; |
| 848 | 824 |
| 849 if (status_area_widget_ && status_area_widget_->ShouldShowLauncher()) | 825 if (shelf_->status_area_widget() && |
| 826 shelf_->status_area_widget()->ShouldShowLauncher()) | |
| 850 return SHELF_AUTO_HIDE_SHOWN; | 827 return SHELF_AUTO_HIDE_SHOWN; |
| 851 | 828 |
| 852 if (launcher_ && launcher_->IsShowingMenu()) | 829 if (shelf_->launcher() && shelf_->launcher()->IsShowingMenu()) |
| 853 return SHELF_AUTO_HIDE_SHOWN; | 830 return SHELF_AUTO_HIDE_SHOWN; |
| 854 | 831 |
| 855 if (launcher_ && launcher_->IsShowingOverflowBubble()) | 832 if (shelf_->launcher() && shelf_->launcher()->IsShowingOverflowBubble()) |
| 856 return SHELF_AUTO_HIDE_SHOWN; | 833 return SHELF_AUTO_HIDE_SHOWN; |
| 857 | 834 |
| 858 if (launcher_widget()->IsActive() || status_area_widget_->IsActive()) | 835 if (shelf_->IsActive() || shelf_->status_area_widget()->IsActive()) |
| 859 return SHELF_AUTO_HIDE_SHOWN; | 836 return SHELF_AUTO_HIDE_SHOWN; |
| 860 | 837 |
| 861 // Don't show if the user is dragging the mouse. | 838 // Don't show if the user is dragging the mouse. |
| 862 if (event_filter_.get() && event_filter_->in_mouse_drag()) | 839 if (event_filter_.get() && event_filter_->in_mouse_drag()) |
| 863 return SHELF_AUTO_HIDE_HIDDEN; | 840 return SHELF_AUTO_HIDE_HIDDEN; |
| 864 | 841 |
| 865 gfx::Rect shelf_region = launcher_widget()->GetWindowBoundsInScreen(); | 842 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); |
| 866 if (status_area_widget_ && | 843 if (shelf_->status_area_widget() && |
| 867 status_area_widget_->IsMessageBubbleShown() && | 844 shelf_->status_area_widget()->IsMessageBubbleShown() && |
| 868 IsVisible()) { | 845 IsVisible()) { |
| 869 // Increase the the hit test area to prevent the shelf from disappearing | 846 // Increase the the hit test area to prevent the shelf from disappearing |
| 870 // when the mouse is over the bubble gap. | 847 // when the mouse is over the bubble gap. |
| 871 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? | 848 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? |
| 872 -kNotificationBubbleGapHeight : 0, | 849 -kNotificationBubbleGapHeight : 0, |
| 873 alignment_ == SHELF_ALIGNMENT_BOTTOM ? | 850 alignment_ == SHELF_ALIGNMENT_BOTTOM ? |
| 874 -kNotificationBubbleGapHeight : 0, | 851 -kNotificationBubbleGapHeight : 0, |
| 875 alignment_ == SHELF_ALIGNMENT_LEFT ? | 852 alignment_ == SHELF_ALIGNMENT_LEFT ? |
| 876 -kNotificationBubbleGapHeight : 0, | 853 -kNotificationBubbleGapHeight : 0, |
| 877 alignment_ == SHELF_ALIGNMENT_TOP ? | 854 alignment_ == SHELF_ALIGNMENT_TOP ? |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 910 insets.Set(0, 0, 0, kWorkspaceAreaBottomInset); | 887 insets.Set(0, 0, 0, kWorkspaceAreaBottomInset); |
| 911 break; | 888 break; |
| 912 case SHELF_ALIGNMENT_RIGHT: | 889 case SHELF_ALIGNMENT_RIGHT: |
| 913 insets.Set(0, kWorkspaceAreaBottomInset, 0, 0); | 890 insets.Set(0, kWorkspaceAreaBottomInset, 0, 0); |
| 914 break; | 891 break; |
| 915 case SHELF_ALIGNMENT_TOP: | 892 case SHELF_ALIGNMENT_TOP: |
| 916 insets.Set(0, 0, kWorkspaceAreaBottomInset, 0); | 893 insets.Set(0, 0, kWorkspaceAreaBottomInset, 0); |
| 917 break; | 894 break; |
| 918 } | 895 } |
| 919 } | 896 } |
| 920 if (launcher_widget() && launcher_widget()->GetNativeWindow()) { | 897 if (shelf_ && shelf_->GetNativeWindow()) { |
| 921 launcher_widget()->GetNativeWindow()->SetHitTestBoundsOverrideOuter( | 898 shelf_->GetNativeWindow()->SetHitTestBoundsOverrideOuter( |
| 922 insets, 1); | 899 insets, 1); |
| 923 } | 900 } |
| 924 status_area_widget_->GetNativeWindow()-> | 901 shelf_->status_area_widget()->GetNativeWindow()-> |
| 925 SetHitTestBoundsOverrideOuter(insets, 1); | 902 SetHitTestBoundsOverrideOuter(insets, 1); |
| 926 } | 903 } |
| 927 | 904 |
| 928 bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) { | 905 bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) { |
| 929 if (!window) | 906 if (!window) |
| 930 return false; | 907 return false; |
| 931 return (launcher_widget() && | 908 return (shelf_ && |
| 932 launcher_widget()->GetNativeWindow()->Contains(window)) || | 909 shelf_->GetNativeWindow()->Contains(window)) || |
| 933 (status_area_widget_->GetNativeWindow()->Contains(window)); | 910 (shelf_->status_area_widget()->GetNativeWindow()->Contains(window)); |
| 934 } | 911 } |
| 935 | 912 |
| 936 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { | 913 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { |
| 937 if (state.visibility_state == SHELF_VISIBLE) | 914 if (state.visibility_state == SHELF_VISIBLE) |
| 938 return size; | 915 return size; |
| 939 if (state.visibility_state == SHELF_AUTO_HIDE) | 916 if (state.visibility_state == SHELF_AUTO_HIDE) |
| 940 return kAutoHideSize; | 917 return kAutoHideSize; |
| 941 return 0; | 918 return 0; |
| 942 } | 919 } |
| 943 | 920 |
| 944 } // namespace internal | 921 } // namespace internal |
| 945 } // namespace ash | 922 } // namespace ash |
| OLD | NEW |