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( | 225 ScreenAsh::ConvertRectToScreen( |
| 235 ScreenAsh::ConvertRectToScreen( | 226 shelf_->GetNativeView()->parent(), |
| 236 launcher_widget()->GetNativeView()->parent(), | 227 target_bounds.shelf_bounds_in_root)); |
| 237 target_bounds.launcher_bounds_in_root)); | 228 if (shelf_->launcher()) { |
| 238 launcher_->SetStatusSize(target_bounds.status_bounds_in_root.size()); | 229 shelf_->launcher()->SetViewBounds(target_bounds.launcher_bounds_in_shelf); |
| 239 } | 230 } |
|
Mr4D (OOO till 08-26)
2013/03/02 02:02:12
These brackets are unnecessary
Harry McCleave
2013/03/04 02:47:41
Done.
| |
| 240 GetLayer(status_area_widget_)->SetOpacity(target_bounds.opacity); | 231 GetLayer(shelf_->status_area_widget())->SetOpacity(target_bounds.opacity); |
| 241 status_area_widget_->SetBounds( | 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( | |
| 242 ScreenAsh::ConvertRectToScreen( | 240 ScreenAsh::ConvertRectToScreen( |
| 243 status_area_widget_->GetNativeView()->parent(), | 241 shelf_->status_area_widget()->GetNativeView()->parent(), |
| 244 target_bounds.status_bounds_in_root)); | 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_ && 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 if (RootWindowController::ForLauncher(window)->shelf()) |
|
Mr4D (OOO till 08-26)
2013/03/02 02:02:12
You might want to assign this to a variable to avo
Harry McCleave
2013/03/04 02:47:41
Done.
| |
| 505 return RootWindowController::ForLauncher(window)-> | |
| 506 shelf()->shelf_layout_manager(); | |
| 507 return NULL; | |
| 509 } | 508 } |
| 510 | 509 |
| 511 //////////////////////////////////////////////////////////////////////////////// | 510 //////////////////////////////////////////////////////////////////////////////// |
| 512 // ShelfLayoutManager, private: | 511 // ShelfLayoutManager, private: |
| 513 | 512 |
| 514 ShelfLayoutManager::TargetBounds::TargetBounds() : opacity(0.0f) {} | 513 ShelfLayoutManager::TargetBounds::TargetBounds() : opacity(0.0f) {} |
| 515 | 514 |
| 516 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { | 515 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { |
| 517 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | 516 ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
| 518 State state; | 517 State state; |
| 519 state.visibility_state = visibility_state; | 518 state.visibility_state = visibility_state; |
| 520 state.auto_hide_state = CalculateAutoHideState(visibility_state); | 519 state.auto_hide_state = CalculateAutoHideState(visibility_state); |
| 521 state.is_screen_locked = delegate && delegate->IsScreenLocked(); | 520 state.is_screen_locked = delegate && delegate->IsScreenLocked(); |
| 522 | 521 |
| 523 // It's possible for SetState() when a window becomes maximized but the state | 522 // 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. | 523 // won't have changed value. Do the dimming check before the early exit. |
| 525 if (launcher_ && workspace_controller_) { | 524 if (shelf_ && workspace_controller_) { |
| 526 launcher_->SetDimsShelf( | 525 shelf_->SetDimsShelf( |
| 527 (state.visibility_state == SHELF_VISIBLE) && | 526 (state.visibility_state == SHELF_VISIBLE) && |
| 528 workspace_controller_->GetWindowState() == | 527 workspace_controller_->GetWindowState() == |
| 529 WORKSPACE_WINDOW_STATE_MAXIMIZED); | 528 WORKSPACE_WINDOW_STATE_MAXIMIZED); |
| 530 } | 529 } |
| 531 | 530 |
| 532 if (state_.Equals(state)) | 531 if (state_.Equals(state)) |
| 533 return; // Nothing changed. | 532 return; // Nothing changed. |
| 534 | 533 |
| 535 FOR_EACH_OBSERVER(Observer, observers_, | 534 FOR_EACH_OBSERVER(Observer, observers_, |
| 536 WillChangeVisibilityState(visibility_state)); | 535 WillChangeVisibilityState(visibility_state)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 552 (state_.visibility_state == SHELF_AUTO_HIDE && | 551 (state_.visibility_state == SHELF_AUTO_HIDE && |
| 553 state_.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && | 552 state_.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && |
| 554 state.visibility_state == SHELF_VISIBLE) ? | 553 state.visibility_state == SHELF_VISIBLE) ? |
| 555 BackgroundAnimator::CHANGE_IMMEDIATE : BackgroundAnimator::CHANGE_ANIMATE; | 554 BackgroundAnimator::CHANGE_IMMEDIATE : BackgroundAnimator::CHANGE_ANIMATE; |
| 556 StopAnimating(); | 555 StopAnimating(); |
| 557 | 556 |
| 558 State old_state = state_; | 557 State old_state = state_; |
| 559 state_ = state; | 558 state_ = state; |
| 560 TargetBounds target_bounds; | 559 TargetBounds target_bounds; |
| 561 CalculateTargetBounds(state_, &target_bounds); | 560 CalculateTargetBounds(state_, &target_bounds); |
| 562 if (launcher_widget()) { | 561 |
| 563 ui::ScopedLayerAnimationSettings launcher_animation_setter( | 562 ui::ScopedLayerAnimationSettings launcher_animation_setter( |
|
Mr4D (OOO till 08-26)
2013/03/02 02:02:12
According to line 524 shelf_ can get NULL (as laun
Harry McCleave
2013/03/04 02:47:41
Done.
| |
| 564 GetLayer(launcher_widget())->GetAnimator()); | 563 GetLayer(shelf_)->GetAnimator()); |
| 565 launcher_animation_setter.SetTransitionDuration( | 564 launcher_animation_setter.SetTransitionDuration( |
| 566 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); | 565 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); |
| 567 launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT); | 566 launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT); |
| 568 GetLayer(launcher_widget())->SetBounds( | 567 GetLayer(shelf_)->SetBounds( |
| 569 target_bounds.launcher_bounds_in_root); | 568 target_bounds.shelf_bounds_in_root); |
| 570 GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity); | 569 GetLayer(shelf_)->SetOpacity(target_bounds.opacity); |
| 571 } | |
| 572 ui::ScopedLayerAnimationSettings status_animation_setter( | 570 ui::ScopedLayerAnimationSettings status_animation_setter( |
| 573 GetLayer(status_area_widget_)->GetAnimator()); | 571 GetLayer(shelf_->status_area_widget())->GetAnimator()); |
| 574 status_animation_setter.SetTransitionDuration( | 572 status_animation_setter.SetTransitionDuration( |
| 575 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); | 573 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); |
| 576 status_animation_setter.SetTweenType(ui::Tween::EASE_OUT); | 574 status_animation_setter.SetTweenType(ui::Tween::EASE_OUT); |
| 577 | 575 |
| 578 // Delay updating the background when going from SHELF_AUTO_HIDE_SHOWN to | 576 // 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 | 577 // SHELF_AUTO_HIDE_HIDDEN until the shelf animates out. Otherwise during the |
| 580 // animation you see the background change. | 578 // animation you see the background change. |
| 581 // Also delay the animation when the shelf was hidden, and has just been made | 579 // Also delay the animation when the shelf was hidden, and has just been made |
| 582 // visible (e.g. using a gesture-drag). | 580 // visible (e.g. using a gesture-drag). |
| 583 bool delay_shelf_update = | 581 bool delay_shelf_update = |
| 584 state.visibility_state == SHELF_AUTO_HIDE && | 582 state.visibility_state == SHELF_AUTO_HIDE && |
| 585 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && | 583 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && |
| 586 old_state.visibility_state == SHELF_AUTO_HIDE; | 584 old_state.visibility_state == SHELF_AUTO_HIDE; |
| 587 | 585 |
| 588 if (state.visibility_state == SHELF_VISIBLE && | 586 if (state.visibility_state == SHELF_VISIBLE && |
| 589 old_state.visibility_state == SHELF_AUTO_HIDE && | 587 old_state.visibility_state == SHELF_AUTO_HIDE && |
| 590 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) | 588 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) |
| 591 delay_shelf_update = true; | 589 delay_shelf_update = true; |
| 592 | 590 |
| 593 if (delay_shelf_update) { | 591 if (delay_shelf_update) { |
| 594 if (update_shelf_observer_) | 592 if (update_shelf_observer_) |
| 595 update_shelf_observer_->Detach(); | 593 update_shelf_observer_->Detach(); |
| 596 // UpdateShelfBackground deletes itself when the animation is done. | 594 // UpdateShelfBackground deletes itself when the animation is done. |
| 597 update_shelf_observer_ = new UpdateShelfObserver(this); | 595 update_shelf_observer_ = new UpdateShelfObserver(this); |
| 598 status_animation_setter.AddObserver(update_shelf_observer_); | 596 status_animation_setter.AddObserver(update_shelf_observer_); |
| 599 } | 597 } |
| 600 ui::Layer* layer = GetLayer(status_area_widget_); | 598 ui::Layer* layer = GetLayer(shelf_->status_area_widget()); |
| 601 layer->SetBounds(target_bounds.status_bounds_in_root); | 599 // TODO(harrym): Remove when status_area is view. |
| 600 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; | |
| 601 status_bounds.set_x(status_bounds.x() + | |
| 602 target_bounds.shelf_bounds_in_root.x()); | |
| 603 status_bounds.set_y(status_bounds.y() + | |
| 604 target_bounds.shelf_bounds_in_root.y()); | |
| 605 layer->SetBounds(status_bounds); | |
| 602 layer->SetOpacity(target_bounds.opacity); | 606 layer->SetOpacity(target_bounds.opacity); |
| 603 Shell::GetInstance()->SetDisplayWorkAreaInsets( | 607 Shell::GetInstance()->SetDisplayWorkAreaInsets( |
| 604 root_window_, target_bounds.work_area_insets); | 608 root_window_, target_bounds.work_area_insets); |
| 605 UpdateHitTestBounds(); | 609 UpdateHitTestBounds(); |
| 606 if (!delay_shelf_update) | 610 if (!delay_shelf_update) |
| 607 UpdateShelfBackground(change_type); | 611 UpdateShelfBackground(change_type); |
| 608 } | 612 } |
| 609 | 613 |
| 610 void ShelfLayoutManager::StopAnimating() { | 614 void ShelfLayoutManager::StopAnimating() { |
| 611 ui::Layer* layer = GetLayer(status_area_widget_); | 615 GetLayer(shelf_)->GetAnimator()->StopAnimating(); |
| 612 if (launcher_widget()) | 616 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); |
| 613 layer->GetAnimator()->StopAnimating(); | |
| 614 layer->GetAnimator()->StopAnimating(); | |
| 615 } | 617 } |
| 616 | 618 |
| 617 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { | 619 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { |
| 618 *width = *height = 0; | 620 *width = *height = 0; |
| 619 gfx::Size status_size(status_area_widget_->GetWindowBoundsInScreen().size()); | 621 gfx::Size status_size( |
| 620 gfx::Size launcher_size = launcher_ ? | 622 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); |
| 621 launcher_widget()->GetContentsView()->GetPreferredSize() : gfx::Size(); | 623 if (IsHorizontalAlignment()) { |
| 622 if (IsHorizontalAlignment()) | 624 *height = std::max(kLauncherPreferredSize, status_size.height()); |
| 623 *height = std::max(launcher_size.height(), status_size.height()); | 625 } else { |
|
Mr4D (OOO till 08-26)
2013/03/02 02:02:12
These brackets are not necessary - see on the left
Harry McCleave
2013/03/04 02:47:41
Done.
| |
| 624 else | 626 *width = std::max(kLauncherPreferredSize, status_size.width()); |
| 625 *width = std::max(launcher_size.width(), status_size.width()); | 627 } |
| 626 } | 628 } |
| 627 | 629 |
| 628 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, | 630 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, |
| 629 gfx::Rect* bounds) const { | 631 gfx::Rect* bounds) const { |
| 630 bounds->Inset(SelectValueForShelfAlignment( | 632 bounds->Inset(SelectValueForShelfAlignment( |
| 631 gfx::Insets(0, 0, inset, 0), | 633 gfx::Insets(0, 0, inset, 0), |
| 632 gfx::Insets(0, inset, 0, 0), | 634 gfx::Insets(0, inset, 0, 0), |
| 633 gfx::Insets(0, 0, 0, inset), | 635 gfx::Insets(0, 0, 0, inset), |
| 634 gfx::Insets(inset, 0, 0, 0))); | 636 gfx::Insets(inset, 0, 0, 0))); |
| 635 } | 637 } |
| 636 | 638 |
| 637 void ShelfLayoutManager::CalculateTargetBounds( | 639 void ShelfLayoutManager::CalculateTargetBounds( |
| 638 const State& state, | 640 const State& state, |
| 639 TargetBounds* target_bounds) { | 641 TargetBounds* target_bounds) { |
| 640 const gfx::Rect& available_bounds(root_window_->bounds()); | 642 const gfx::Rect& available_bounds(root_window_->bounds()); |
| 641 gfx::Rect status_size(status_area_widget_->GetWindowBoundsInScreen().size()); | 643 gfx::Rect status_size( |
| 642 gfx::Size launcher_size = launcher_ ? | 644 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; | 645 int shelf_width = 0, shelf_height = 0; |
| 646 GetShelfSize(&shelf_width, &shelf_height); | 646 GetShelfSize(&shelf_width, &shelf_height); |
| 647 if (state.visibility_state == SHELF_VISIBLE || | 647 if (IsHorizontalAlignment()) |
| 648 (state.visibility_state == SHELF_AUTO_HIDE && | 648 shelf_width = available_bounds.width(); |
| 649 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)) { | 649 else |
| 650 shelf_size = std::max(shelf_width, shelf_height); | 650 shelf_height = available_bounds.height(); |
| 651 launcher_size.set_width(std::max(shelf_width,launcher_size.width())); | 651 |
| 652 launcher_size.set_height(std::max(shelf_height,launcher_size.height())); | 652 if (state.visibility_state == SHELF_AUTO_HIDE && |
| 653 } else if (state.visibility_state == SHELF_AUTO_HIDE && | 653 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. | 654 // Keep the launcher to its full height when dragging is in progress. |
| 657 if (gesture_drag_status_ == GESTURE_DRAG_NONE) { | 655 if (gesture_drag_status_ == GESTURE_DRAG_NONE) { |
| 658 if (IsHorizontalAlignment()) | 656 if (IsHorizontalAlignment()) |
| 659 launcher_size.set_height(kAutoHideSize); | 657 shelf_height = kAutoHideSize; |
| 660 else | 658 else |
| 661 launcher_size.set_width(kAutoHideSize); | 659 shelf_width = kAutoHideSize; |
| 662 } | 660 } |
| 661 } else if (state.visibility_state == SHELF_HIDDEN) { | |
| 662 if (IsHorizontalAlignment()) | |
| 663 shelf_height = 0; | |
| 664 else | |
| 665 shelf_width = 0; | |
| 663 } | 666 } |
| 664 switch(alignment_) { | 667 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( |
| 665 case SHELF_ALIGNMENT_BOTTOM: | 668 gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height, |
| 666 // The status widget should extend to the bottom and right edges. | 669 available_bounds.width(), shelf_height), |
| 667 target_bounds->status_bounds_in_root = gfx::Rect( | 670 gfx::Rect(available_bounds.x(), available_bounds.y(), |
| 668 base::i18n::IsRTL() ? available_bounds.x() : | 671 shelf_width, available_bounds.height()), |
| 669 available_bounds.right() - status_size.width(), | 672 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), |
| 670 available_bounds.bottom() - shelf_size + shelf_height - | 673 shelf_width, available_bounds.height()), |
| 671 status_size.height(), | 674 gfx::Rect(available_bounds.x(), available_bounds.y(), |
| 672 status_size.width(), status_size.height()); | 675 available_bounds.width(), shelf_height)); |
| 673 if (launcher_widget()) | 676 |
| 674 target_bounds->launcher_bounds_in_root = gfx::Rect( | 677 int status_inset = (kLauncherPreferredSize - |
| 675 available_bounds.x(), | 678 PrimaryAxisValue(status_size.height(), status_size.width())); |
| 676 available_bounds.bottom() - shelf_size, | 679 |
| 677 available_bounds.width(), | 680 target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( |
| 678 launcher_size.height()); | 681 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
| 679 target_bounds->work_area_insets.Set( | 682 status_inset, status_size.width(), status_size.height()), |
| 680 0, 0, GetWorkAreaSize(state, shelf_height), 0); | 683 gfx::Rect(shelf_width - (status_size.width() + status_inset), |
| 681 break; | 684 shelf_height - status_size.height(), status_size.width(), |
| 682 case SHELF_ALIGNMENT_LEFT: | 685 status_size.height()), |
| 683 target_bounds->status_bounds_in_root = gfx::Rect( | 686 gfx::Rect(status_inset, shelf_height - status_size.height(), |
| 684 available_bounds.x() + launcher_size.width() - status_size.width(), | 687 status_size.width(), status_size.height()), |
| 685 available_bounds.bottom() - status_size.height(), | 688 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
| 686 shelf_width, status_size.height()); | 689 shelf_height - (status_size.height() + status_inset), |
| 687 if (launcher_widget()) | 690 status_size.width(), status_size.height())); |
| 688 target_bounds->launcher_bounds_in_root = gfx::Rect( | 691 |
| 689 available_bounds.x(), available_bounds.y(), | 692 target_bounds->launcher_bounds_in_shelf = SelectValueForShelfAlignment( |
| 690 launcher_size.width(), available_bounds.height()); | 693 gfx::Rect(base::i18n::IsRTL() ? status_size.width() : 0, 0, |
| 691 target_bounds->work_area_insets.Set( | 694 shelf_width - status_size.width(), shelf_height), |
| 692 0, GetWorkAreaSize(state, launcher_size.width()), 0, 0); | 695 gfx::Rect(0, 0, shelf_width, shelf_height - status_size.height()), |
| 693 break; | 696 gfx::Rect(0, 0, shelf_width, shelf_height - status_size.height()), |
| 694 case SHELF_ALIGNMENT_RIGHT: | 697 gfx::Rect(base::i18n::IsRTL() ? status_size.width() : 0, 0, |
| 695 target_bounds->status_bounds_in_root = gfx::Rect( | 698 shelf_width - status_size.width(), shelf_height)); |
| 696 available_bounds.right()- status_size.width() - | 699 |
| 697 shelf_size + shelf_width, | 700 target_bounds->work_area_insets = SelectValueForShelfAlignment( |
| 698 available_bounds.bottom() - status_size.height(), | 701 gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0), |
| 699 shelf_width, status_size.height()); | 702 gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0), |
| 700 if (launcher_widget()) | 703 gfx::Insets(0, 0, 0, GetWorkAreaSize(state, shelf_width)), |
| 701 target_bounds->launcher_bounds_in_root = gfx::Rect( | 704 gfx::Insets(GetWorkAreaSize(state, shelf_height), 0, 0, 0)); |
| 702 available_bounds.right() - launcher_size.width(), | 705 |
| 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 = | 706 target_bounds->opacity = |
| 725 (gesture_drag_status_ != GESTURE_DRAG_NONE || | 707 (gesture_drag_status_ != GESTURE_DRAG_NONE || |
| 726 state.visibility_state == SHELF_VISIBLE || | 708 state.visibility_state == SHELF_VISIBLE || |
| 727 state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; | 709 state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; |
| 728 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS) | 710 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS) |
| 729 UpdateTargetBoundsForGesture(target_bounds); | 711 UpdateTargetBoundsForGesture(target_bounds); |
| 730 } | 712 } |
| 731 | 713 |
| 732 void ShelfLayoutManager::UpdateTargetBoundsForGesture( | 714 void ShelfLayoutManager::UpdateTargetBoundsForGesture( |
| 733 TargetBounds* target_bounds) const { | 715 TargetBounds* target_bounds) const { |
| 734 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); | 716 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); |
| 735 bool horizontal = IsHorizontalAlignment(); | 717 bool horizontal = IsHorizontalAlignment(); |
| 736 int resistance_free_region = 0; | 718 int resistance_free_region = 0; |
| 737 | 719 |
| 738 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 720 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
| 739 visibility_state() == SHELF_AUTO_HIDE && | 721 visibility_state() == SHELF_AUTO_HIDE && |
| 740 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { | 722 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
| 741 // If the shelf was hidden when the drag started (and the state hasn't | 723 // 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 | 724 // 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 | 725 // 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. | 726 // sure the shelf sticks with the finger until the shelf is visible. |
| 745 resistance_free_region += horizontal ? | 727 resistance_free_region += horizontal ? |
| 746 target_bounds->launcher_bounds_in_root.height() : | 728 target_bounds->shelf_bounds_in_root.height() : |
| 747 target_bounds->launcher_bounds_in_root.width(); | 729 target_bounds->shelf_bounds_in_root.width(); |
| 748 resistance_free_region -= kAutoHideSize; | 730 resistance_free_region -= kAutoHideSize; |
| 749 } | 731 } |
| 750 | 732 |
| 751 bool resist = SelectValueForShelfAlignment( | 733 bool resist = SelectValueForShelfAlignment( |
| 752 gesture_drag_amount_ < -resistance_free_region, | 734 gesture_drag_amount_ < -resistance_free_region, |
| 753 gesture_drag_amount_ > resistance_free_region, | 735 gesture_drag_amount_ > resistance_free_region, |
| 754 gesture_drag_amount_ < -resistance_free_region, | 736 gesture_drag_amount_ < -resistance_free_region, |
| 755 gesture_drag_amount_ > resistance_free_region); | 737 gesture_drag_amount_ > resistance_free_region); |
| 756 | 738 |
| 757 float translate = 0.f; | 739 float translate = 0.f; |
| 758 if (resist) { | 740 if (resist) { |
| 759 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; | 741 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; |
| 760 diff = std::min(diff, sqrtf(diff)); | 742 diff = std::min(diff, sqrtf(diff)); |
| 761 if (gesture_drag_amount_ < 0) | 743 if (gesture_drag_amount_ < 0) |
| 762 translate = -resistance_free_region - diff; | 744 translate = -resistance_free_region - diff; |
| 763 else | 745 else |
| 764 translate = resistance_free_region + diff; | 746 translate = resistance_free_region + diff; |
| 765 } else { | 747 } else { |
| 766 translate = gesture_drag_amount_; | 748 translate = gesture_drag_amount_; |
| 767 } | 749 } |
| 768 | 750 |
| 769 if (horizontal) { | 751 if (horizontal) { |
| 770 // Move the launcher with the gesture. | 752 // Move the launcher with the gesture. |
| 771 target_bounds->launcher_bounds_in_root.Offset(0, translate); | 753 target_bounds->shelf_bounds_in_root.Offset(0, translate); |
| 772 target_bounds->status_bounds_in_root.Offset(0, translate); | |
| 773 | 754 |
| 774 if (translate < 0) { | 755 if (translate < 0) { |
| 775 // When dragging up, the launcher height should increase. | 756 // When dragging up, the launcher height should increase. |
| 776 float move = std::max(translate, | 757 float move = std::max(translate, |
| 777 -static_cast<float>(resistance_free_region)); | 758 -static_cast<float>(resistance_free_region)); |
| 778 target_bounds->launcher_bounds_in_root.set_height( | 759 target_bounds->shelf_bounds_in_root.set_height( |
| 779 target_bounds->launcher_bounds_in_root.height() + move - translate); | 760 target_bounds->shelf_bounds_in_root.height() + move - translate); |
| 761 | |
| 762 // The statusbar should be in the center. | |
| 763 gfx::Rect status_y = target_bounds->shelf_bounds_in_root; | |
| 764 status_y.ClampToCenteredSize( | |
| 765 target_bounds->status_bounds_in_shelf.size()); | |
| 766 target_bounds->status_bounds_in_shelf.set_y(status_y.y()); | |
| 780 } | 767 } |
| 781 } else { | 768 } else { |
| 782 // Move the launcher with the gesture. | 769 // Move the launcher with the gesture. |
| 783 if (alignment_ == SHELF_ALIGNMENT_RIGHT) | 770 if (alignment_ == SHELF_ALIGNMENT_RIGHT) |
| 784 target_bounds->launcher_bounds_in_root.Offset(translate, 0); | 771 target_bounds->shelf_bounds_in_root.Offset(translate, 0); |
| 785 | 772 |
| 786 if ((translate > 0 && alignment_ == SHELF_ALIGNMENT_RIGHT) || | 773 if ((translate > 0 && alignment_ == SHELF_ALIGNMENT_RIGHT) || |
| 787 (translate < 0 && alignment_ == SHELF_ALIGNMENT_LEFT)) { | 774 (translate < 0 && alignment_ == SHELF_ALIGNMENT_LEFT)) { |
| 788 // When dragging towards the edge, the statusbar should move. | 775 // When dragging towards the edge, the statusbar should move. |
| 789 target_bounds->status_bounds_in_root.Offset(translate, 0); | 776 target_bounds->status_bounds_in_shelf.Offset(translate, 0); |
| 790 } else { | 777 } else { |
| 791 // When dragging away from the edge, the launcher width should increase. | 778 // When dragging away from the edge, the launcher width should increase. |
| 792 float move = alignment_ == SHELF_ALIGNMENT_RIGHT ? | 779 float move = alignment_ == SHELF_ALIGNMENT_RIGHT ? |
| 793 std::max(translate, -static_cast<float>(resistance_free_region)) : | 780 std::max(translate, -static_cast<float>(resistance_free_region)) : |
| 794 std::min(translate, static_cast<float>(resistance_free_region)); | 781 std::min(translate, static_cast<float>(resistance_free_region)); |
| 795 | 782 |
| 796 if (alignment_ == SHELF_ALIGNMENT_RIGHT) { | 783 if (alignment_ == SHELF_ALIGNMENT_RIGHT) { |
| 797 target_bounds->launcher_bounds_in_root.set_width( | 784 target_bounds->shelf_bounds_in_root.set_width( |
| 798 target_bounds->launcher_bounds_in_root.width() + move - translate); | 785 target_bounds->shelf_bounds_in_root.width() + move - translate); |
| 799 } else { | 786 } else { |
| 800 target_bounds->launcher_bounds_in_root.set_width( | 787 target_bounds->shelf_bounds_in_root.set_width( |
| 801 target_bounds->launcher_bounds_in_root.width() - move + translate); | 788 target_bounds->shelf_bounds_in_root.width() - move + translate); |
| 802 } | 789 } |
| 803 | 790 |
| 804 // The statusbar should be in the center. | 791 // The statusbar should be in the center. |
| 805 gfx::Rect status_x = target_bounds->launcher_bounds_in_root; | 792 gfx::Rect status_x = target_bounds->shelf_bounds_in_root; |
| 806 status_x.ClampToCenteredSize( | 793 status_x.ClampToCenteredSize( |
| 807 target_bounds->status_bounds_in_root.size()); | 794 target_bounds->status_bounds_in_shelf.size()); |
| 808 target_bounds->status_bounds_in_root.set_x(status_x.x()); | 795 target_bounds->status_bounds_in_shelf.set_x(status_x.x()); |
| 809 } | 796 } |
| 810 } | 797 } |
| 811 } | 798 } |
| 812 | 799 |
| 813 void ShelfLayoutManager::UpdateShelfBackground( | 800 void ShelfLayoutManager::UpdateShelfBackground( |
| 814 BackgroundAnimator::ChangeType type) { | 801 BackgroundAnimator::ChangeType type) { |
| 815 bool launcher_paints = GetLauncherPaintsBackground(); | 802 bool launcher_paints = GetLauncherPaintsBackground(); |
| 816 if (launcher_) | 803 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 } | 804 } |
| 826 | 805 |
| 827 bool ShelfLayoutManager::GetLauncherPaintsBackground() const { | 806 bool ShelfLayoutManager::GetLauncherPaintsBackground() const { |
| 828 return gesture_drag_status_ != GESTURE_DRAG_NONE || | 807 return gesture_drag_status_ != GESTURE_DRAG_NONE || |
| 829 (!state_.is_screen_locked && window_overlaps_shelf_) || | 808 (!state_.is_screen_locked && window_overlaps_shelf_) || |
| 830 (state_.visibility_state == SHELF_AUTO_HIDE) ; | 809 (state_.visibility_state == SHELF_AUTO_HIDE) ; |
| 831 } | 810 } |
| 832 | 811 |
| 833 void ShelfLayoutManager::UpdateAutoHideStateNow() { | 812 void ShelfLayoutManager::UpdateAutoHideStateNow() { |
| 834 SetState(state_.visibility_state); | 813 SetState(state_.visibility_state); |
| 835 } | 814 } |
| 836 | 815 |
| 837 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( | 816 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( |
| 838 ShelfVisibilityState visibility_state) const { | 817 ShelfVisibilityState visibility_state) const { |
| 839 if (visibility_state != SHELF_AUTO_HIDE || !launcher_widget()) | 818 if (visibility_state != SHELF_AUTO_HIDE || !shelf_) |
| 840 return SHELF_AUTO_HIDE_HIDDEN; | 819 return SHELF_AUTO_HIDE_HIDDEN; |
| 841 | 820 |
| 842 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) | 821 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) |
| 843 return gesture_drag_auto_hide_state_; | 822 return gesture_drag_auto_hide_state_; |
| 844 | 823 |
| 845 Shell* shell = Shell::GetInstance(); | 824 Shell* shell = Shell::GetInstance(); |
| 846 if (shell->GetAppListTargetVisibility()) | 825 if (shell->GetAppListTargetVisibility()) |
| 847 return SHELF_AUTO_HIDE_SHOWN; | 826 return SHELF_AUTO_HIDE_SHOWN; |
| 848 | 827 |
| 849 if (status_area_widget_ && status_area_widget_->ShouldShowLauncher()) | 828 if (shelf_->status_area_widget() && |
| 829 shelf_->status_area_widget()->ShouldShowLauncher()) | |
| 850 return SHELF_AUTO_HIDE_SHOWN; | 830 return SHELF_AUTO_HIDE_SHOWN; |
| 851 | 831 |
| 852 if (launcher_ && launcher_->IsShowingMenu()) | 832 if (shelf_->launcher() && shelf_->launcher()->IsShowingMenu()) |
| 853 return SHELF_AUTO_HIDE_SHOWN; | 833 return SHELF_AUTO_HIDE_SHOWN; |
| 854 | 834 |
| 855 if (launcher_ && launcher_->IsShowingOverflowBubble()) | 835 if (shelf_->launcher() && shelf_->launcher()->IsShowingOverflowBubble()) |
| 856 return SHELF_AUTO_HIDE_SHOWN; | 836 return SHELF_AUTO_HIDE_SHOWN; |
| 857 | 837 |
| 858 if (launcher_widget()->IsActive() || status_area_widget_->IsActive()) | 838 if (shelf_->IsActive() || shelf_->status_area_widget()->IsActive()) |
| 859 return SHELF_AUTO_HIDE_SHOWN; | 839 return SHELF_AUTO_HIDE_SHOWN; |
| 860 | 840 |
| 861 // Don't show if the user is dragging the mouse. | 841 // Don't show if the user is dragging the mouse. |
| 862 if (event_filter_.get() && event_filter_->in_mouse_drag()) | 842 if (event_filter_.get() && event_filter_->in_mouse_drag()) |
| 863 return SHELF_AUTO_HIDE_HIDDEN; | 843 return SHELF_AUTO_HIDE_HIDDEN; |
| 864 | 844 |
| 865 gfx::Rect shelf_region = launcher_widget()->GetWindowBoundsInScreen(); | 845 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); |
| 866 if (status_area_widget_ && | 846 if (shelf_->status_area_widget() && |
| 867 status_area_widget_->IsMessageBubbleShown() && | 847 shelf_->status_area_widget()->IsMessageBubbleShown() && |
| 868 IsVisible()) { | 848 IsVisible()) { |
| 869 // Increase the the hit test area to prevent the shelf from disappearing | 849 // Increase the the hit test area to prevent the shelf from disappearing |
| 870 // when the mouse is over the bubble gap. | 850 // when the mouse is over the bubble gap. |
| 871 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? | 851 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? |
| 872 -kNotificationBubbleGapHeight : 0, | 852 -kNotificationBubbleGapHeight : 0, |
| 873 alignment_ == SHELF_ALIGNMENT_BOTTOM ? | 853 alignment_ == SHELF_ALIGNMENT_BOTTOM ? |
| 874 -kNotificationBubbleGapHeight : 0, | 854 -kNotificationBubbleGapHeight : 0, |
| 875 alignment_ == SHELF_ALIGNMENT_LEFT ? | 855 alignment_ == SHELF_ALIGNMENT_LEFT ? |
| 876 -kNotificationBubbleGapHeight : 0, | 856 -kNotificationBubbleGapHeight : 0, |
| 877 alignment_ == SHELF_ALIGNMENT_TOP ? | 857 alignment_ == SHELF_ALIGNMENT_TOP ? |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 910 insets.Set(0, 0, 0, kWorkspaceAreaBottomInset); | 890 insets.Set(0, 0, 0, kWorkspaceAreaBottomInset); |
| 911 break; | 891 break; |
| 912 case SHELF_ALIGNMENT_RIGHT: | 892 case SHELF_ALIGNMENT_RIGHT: |
| 913 insets.Set(0, kWorkspaceAreaBottomInset, 0, 0); | 893 insets.Set(0, kWorkspaceAreaBottomInset, 0, 0); |
| 914 break; | 894 break; |
| 915 case SHELF_ALIGNMENT_TOP: | 895 case SHELF_ALIGNMENT_TOP: |
| 916 insets.Set(0, 0, kWorkspaceAreaBottomInset, 0); | 896 insets.Set(0, 0, kWorkspaceAreaBottomInset, 0); |
| 917 break; | 897 break; |
| 918 } | 898 } |
| 919 } | 899 } |
| 920 if (launcher_widget() && launcher_widget()->GetNativeWindow()) { | 900 if (shelf_ && shelf_->GetNativeWindow()) { |
| 921 launcher_widget()->GetNativeWindow()->SetHitTestBoundsOverrideOuter( | 901 shelf_->GetNativeWindow()->SetHitTestBoundsOverrideOuter( |
| 922 insets, 1); | 902 insets, 1); |
| 923 } | 903 } |
| 924 status_area_widget_->GetNativeWindow()-> | 904 shelf_->status_area_widget()->GetNativeWindow()-> |
| 925 SetHitTestBoundsOverrideOuter(insets, 1); | 905 SetHitTestBoundsOverrideOuter(insets, 1); |
| 926 } | 906 } |
| 927 | 907 |
| 928 bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) { | 908 bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) { |
| 929 if (!window) | 909 if (!window) |
| 930 return false; | 910 return false; |
| 931 return (launcher_widget() && | 911 return (shelf_ && |
| 932 launcher_widget()->GetNativeWindow()->Contains(window)) || | 912 shelf_->GetNativeWindow()->Contains(window)) || |
| 933 (status_area_widget_->GetNativeWindow()->Contains(window)); | 913 (shelf_->status_area_widget()->GetNativeWindow()->Contains(window)); |
| 934 } | 914 } |
| 935 | 915 |
| 936 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { | 916 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { |
| 937 if (state.visibility_state == SHELF_VISIBLE) | 917 if (state.visibility_state == SHELF_VISIBLE) |
| 938 return size; | 918 return size; |
| 939 if (state.visibility_state == SHELF_AUTO_HIDE) | 919 if (state.visibility_state == SHELF_AUTO_HIDE) |
| 940 return kAutoHideSize; | 920 return kAutoHideSize; |
| 941 return 0; | 921 return 0; |
| 942 } | 922 } |
| 943 | 923 |
| 944 } // namespace internal | 924 } // namespace internal |
| 945 } // namespace ash | 925 } // namespace ash |
| OLD | NEW |