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/wm/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/root_window_controller.h" |
12 #include "ash/screen_ash.h" | 13 #include "ash/screen_ash.h" |
13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
14 #include "ash/shell_delegate.h" | 15 #include "ash/shell_delegate.h" |
15 #include "ash/shell_window_ids.h" | 16 #include "ash/shell_window_ids.h" |
16 #include "ash/system/status_area_widget.h" | 17 #include "ash/system/status_area_widget.h" |
17 #include "ash/wm/workspace_controller.h" | 18 #include "ash/wm/workspace_controller.h" |
18 #include "ash/wm/workspace/workspace_animations.h" | 19 #include "ash/wm/workspace/workspace_animations.h" |
19 #include "base/auto_reset.h" | 20 #include "base/auto_reset.h" |
20 #include "base/command_line.h" | 21 #include "base/command_line.h" |
21 #include "base/i18n/rtl.h" | 22 #include "base/i18n/rtl.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 166 } |
166 | 167 |
167 // Shelf we're in. NULL if deleted before we're deleted. | 168 // Shelf we're in. NULL if deleted before we're deleted. |
168 ShelfLayoutManager* shelf_; | 169 ShelfLayoutManager* shelf_; |
169 | 170 |
170 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); | 171 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); |
171 }; | 172 }; |
172 | 173 |
173 // ShelfLayoutManager ---------------------------------------------------------- | 174 // ShelfLayoutManager ---------------------------------------------------------- |
174 | 175 |
175 ShelfLayoutManager::ShelfLayoutManager(views::Widget* status) | 176 ShelfLayoutManager::ShelfLayoutManager(StatusAreaWidget* status_area_widget) |
176 : root_window_(Shell::GetPrimaryRootWindow()), | 177 : root_window_(status_area_widget->GetNativeView()->GetRootWindow()), |
177 in_layout_(false), | 178 in_layout_(false), |
178 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), | 179 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), |
179 alignment_(SHELF_ALIGNMENT_BOTTOM), | 180 alignment_(SHELF_ALIGNMENT_BOTTOM), |
180 launcher_(NULL), | 181 launcher_(NULL), |
181 status_(status), | 182 status_area_widget_(status_area_widget), |
182 workspace_controller_(NULL), | 183 workspace_controller_(NULL), |
183 window_overlaps_shelf_(false), | 184 window_overlaps_shelf_(false), |
184 gesture_drag_status_(GESTURE_DRAG_NONE), | 185 gesture_drag_status_(GESTURE_DRAG_NONE), |
185 gesture_drag_amount_(0.f), | 186 gesture_drag_amount_(0.f), |
186 gesture_drag_auto_hide_state_(AUTO_HIDE_SHOWN), | 187 gesture_drag_auto_hide_state_(AUTO_HIDE_SHOWN), |
187 update_shelf_observer_(NULL) { | 188 update_shelf_observer_(NULL) { |
188 Shell::GetInstance()->AddShellObserver(this); | 189 Shell::GetInstance()->AddShellObserver(this); |
189 aura::client::GetActivationClient(root_window_)->AddObserver(this); | 190 aura::client::GetActivationClient(root_window_)->AddObserver(this); |
190 } | 191 } |
191 | 192 |
192 ShelfLayoutManager::~ShelfLayoutManager() { | 193 ShelfLayoutManager::~ShelfLayoutManager() { |
193 if (update_shelf_observer_) | 194 if (update_shelf_observer_) |
194 update_shelf_observer_->Detach(); | 195 update_shelf_observer_->Detach(); |
195 | 196 |
196 FOR_EACH_OBSERVER(Observer, observers_, WillDeleteShelf()); | 197 FOR_EACH_OBSERVER(Observer, observers_, WillDeleteShelf()); |
197 Shell::GetInstance()->RemoveShellObserver(this); | 198 Shell::GetInstance()->RemoveShellObserver(this); |
198 aura::client::GetActivationClient(root_window_)->RemoveObserver(this); | 199 aura::client::GetActivationClient(root_window_)->RemoveObserver(this); |
199 } | 200 } |
200 | 201 |
201 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { | 202 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { |
202 if (auto_hide_behavior_ == behavior) | 203 if (auto_hide_behavior_ == behavior) |
203 return; | 204 return; |
204 auto_hide_behavior_ = behavior; | 205 auto_hide_behavior_ = behavior; |
205 UpdateVisibilityState(); | 206 UpdateVisibilityState(); |
206 FOR_EACH_OBSERVER(Observer, observers_, | 207 FOR_EACH_OBSERVER(Observer, observers_, |
207 OnAutoHideStateChanged(state_.auto_hide_state)); | 208 OnAutoHideStateChanged(state_.auto_hide_state)); |
208 } | 209 } |
209 | 210 |
210 bool ShelfLayoutManager::IsVisible() const { | 211 bool ShelfLayoutManager::IsVisible() const { |
211 return status_->IsVisible() && (state_.visibility_state == VISIBLE || | 212 return status_area_widget_->IsVisible() && |
212 (state_.visibility_state == AUTO_HIDE && | 213 (state_.visibility_state == VISIBLE || |
213 state_.auto_hide_state == AUTO_HIDE_SHOWN)); | 214 (state_.visibility_state == AUTO_HIDE && |
| 215 state_.auto_hide_state == AUTO_HIDE_SHOWN)); |
214 } | 216 } |
215 | 217 |
216 void ShelfLayoutManager::SetLauncher(Launcher* launcher) { | 218 void ShelfLayoutManager::SetLauncher(Launcher* launcher) { |
217 if (launcher == launcher_) | 219 if (launcher == launcher_) |
218 return; | 220 return; |
219 | 221 |
220 launcher_ = launcher; | 222 launcher_ = launcher; |
221 if (launcher_) | 223 if (launcher_) |
222 launcher_->SetAlignment(alignment_); | 224 launcher_->SetAlignment(alignment_); |
223 LayoutShelf(); | 225 LayoutShelf(); |
224 } | 226 } |
225 | 227 |
226 bool ShelfLayoutManager::SetAlignment(ShelfAlignment alignment) { | 228 bool ShelfLayoutManager::SetAlignment(ShelfAlignment alignment) { |
227 if (alignment_ == alignment) | 229 if (alignment_ == alignment) |
228 return false; | 230 return false; |
229 | 231 |
230 alignment_ = alignment; | 232 alignment_ = alignment; |
231 if (launcher_) | 233 if (launcher_) |
232 launcher_->SetAlignment(alignment); | 234 launcher_->SetAlignment(alignment); |
233 StatusAreaWidget* status_area_widget = | 235 status_area_widget_->SetShelfAlignment(alignment); |
234 Shell::GetInstance()->status_area_widget(); | |
235 if (status_area_widget) | |
236 Shell::GetInstance()->status_area_widget()->SetShelfAlignment(alignment); | |
237 LayoutShelf(); | 236 LayoutShelf(); |
238 return true; | 237 return true; |
239 } | 238 } |
240 | 239 |
241 gfx::Rect ShelfLayoutManager::GetIdealBounds() { | 240 gfx::Rect ShelfLayoutManager::GetIdealBounds() { |
242 // TODO(oshima): this is wrong. Figure out what display shelf is on | 241 // TODO(oshima): this is wrong. Figure out what display shelf is on |
243 // and everything should be based on it. | 242 // and everything should be based on it. |
244 gfx::Rect bounds(ScreenAsh::GetDisplayBoundsInParent( | 243 gfx::Rect bounds(ScreenAsh::GetDisplayBoundsInParent( |
245 status_->GetNativeView())); | 244 status_area_widget_->GetNativeView())); |
246 int width = 0, height = 0; | 245 int width = 0, height = 0; |
247 GetShelfSize(&width, &height); | 246 GetShelfSize(&width, &height); |
248 switch (alignment_) { | 247 switch (alignment_) { |
249 case SHELF_ALIGNMENT_BOTTOM: | 248 case SHELF_ALIGNMENT_BOTTOM: |
250 return gfx::Rect(bounds.x(), bounds.bottom() - height, | 249 return gfx::Rect(bounds.x(), bounds.bottom() - height, |
251 bounds.width(), height); | 250 bounds.width(), height); |
252 case SHELF_ALIGNMENT_LEFT: | 251 case SHELF_ALIGNMENT_LEFT: |
253 return gfx::Rect(bounds.x(), bounds.y(), width, bounds.height()); | 252 return gfx::Rect(bounds.x(), bounds.y(), width, bounds.height()); |
254 case SHELF_ALIGNMENT_RIGHT: | 253 case SHELF_ALIGNMENT_RIGHT: |
255 return gfx::Rect(bounds.right() - width, bounds.y(), width, | 254 return gfx::Rect(bounds.right() - width, bounds.y(), width, |
256 bounds.height()); | 255 bounds.height()); |
257 } | 256 } |
258 NOTREACHED(); | 257 NOTREACHED(); |
259 return gfx::Rect(); | 258 return gfx::Rect(); |
260 } | 259 } |
261 | 260 |
262 void ShelfLayoutManager::LayoutShelf() { | 261 void ShelfLayoutManager::LayoutShelf() { |
263 AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | 262 AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
264 StopAnimating(); | 263 StopAnimating(); |
265 TargetBounds target_bounds; | 264 TargetBounds target_bounds; |
266 CalculateTargetBounds(state_, &target_bounds); | 265 CalculateTargetBounds(state_, &target_bounds); |
267 if (launcher_widget()) { | 266 if (launcher_widget()) { |
268 GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity); | 267 GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity); |
269 launcher_->SetWidgetBounds( | 268 launcher_->SetWidgetBounds( |
270 ScreenAsh::ConvertRectToScreen( | 269 ScreenAsh::ConvertRectToScreen( |
271 launcher_widget()->GetNativeView()->parent(), | 270 launcher_widget()->GetNativeView()->parent(), |
272 target_bounds.launcher_bounds_in_root)); | 271 target_bounds.launcher_bounds_in_root)); |
273 launcher_->SetStatusSize(target_bounds.status_bounds_in_root.size()); | 272 launcher_->SetStatusSize(target_bounds.status_bounds_in_root.size()); |
274 } | 273 } |
275 GetLayer(status_)->SetOpacity(target_bounds.opacity); | 274 GetLayer(status_area_widget_)->SetOpacity(target_bounds.opacity); |
276 status_->SetBounds( | 275 status_area_widget_->SetBounds( |
277 ScreenAsh::ConvertRectToScreen( | 276 ScreenAsh::ConvertRectToScreen( |
278 status_->GetNativeView()->parent(), | 277 status_area_widget_->GetNativeView()->parent(), |
279 target_bounds.status_bounds_in_root)); | 278 target_bounds.status_bounds_in_root)); |
280 Shell::GetInstance()->SetDisplayWorkAreaInsets( | 279 Shell::GetInstance()->SetDisplayWorkAreaInsets( |
281 Shell::GetPrimaryRootWindow(), | 280 Shell::GetPrimaryRootWindow(), |
282 target_bounds.work_area_insets); | 281 target_bounds.work_area_insets); |
283 UpdateHitTestBounds(); | 282 UpdateHitTestBounds(); |
284 } | 283 } |
285 | 284 |
286 void ShelfLayoutManager::UpdateVisibilityState() { | 285 void ShelfLayoutManager::UpdateVisibilityState() { |
287 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | 286 ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
288 if (delegate && delegate->IsScreenLocked()) { | 287 if (delegate && delegate->IsScreenLocked()) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 // Start reveling the status menu when: | 368 // Start reveling the status menu when: |
370 // - dragging up on an already visible shelf | 369 // - dragging up on an already visible shelf |
371 // - dragging up on a hidden shelf, but it is currently completely visible. | 370 // - dragging up on a hidden shelf, but it is currently completely visible. |
372 if (horizontal && gesture.details().scroll_y() < 0) { | 371 if (horizontal && gesture.details().scroll_y() < 0) { |
373 int min_height = 0; | 372 int min_height = 0; |
374 if (gesture_drag_auto_hide_state_ == AUTO_HIDE_HIDDEN && launcher_widget()) | 373 if (gesture_drag_auto_hide_state_ == AUTO_HIDE_HIDDEN && launcher_widget()) |
375 min_height = launcher_widget()->GetContentsView()-> | 374 min_height = launcher_widget()->GetContentsView()-> |
376 GetPreferredSize().height(); | 375 GetPreferredSize().height(); |
377 | 376 |
378 if (min_height < launcher_widget()->GetWindowBoundsInScreen().height() && | 377 if (min_height < launcher_widget()->GetWindowBoundsInScreen().height() && |
379 gesture.root_location().x() >= status_->GetWindowBoundsInScreen().x() && | 378 gesture.root_location().x() >= |
| 379 status_area_widget_->GetWindowBoundsInScreen().x() && |
380 IsDraggingTrayEnabled()) | 380 IsDraggingTrayEnabled()) |
381 return DRAG_TRAY; | 381 return DRAG_TRAY; |
382 } | 382 } |
383 | 383 |
384 return DRAG_SHELF; | 384 return DRAG_SHELF; |
385 } | 385 } |
386 | 386 |
387 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { | 387 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { |
388 bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM; | 388 bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM; |
389 bool should_change = false; | 389 bool should_change = false; |
(...skipping 26 matching lines...) Expand all Loading... |
416 if (!should_change) { | 416 if (!should_change) { |
417 CancelGestureDrag(); | 417 CancelGestureDrag(); |
418 return; | 418 return; |
419 } | 419 } |
420 | 420 |
421 gesture_drag_auto_hide_state_ = | 421 gesture_drag_auto_hide_state_ = |
422 gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN ? AUTO_HIDE_HIDDEN : | 422 gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN ? AUTO_HIDE_HIDDEN : |
423 AUTO_HIDE_SHOWN; | 423 AUTO_HIDE_SHOWN; |
424 if (launcher_widget()) | 424 if (launcher_widget()) |
425 launcher_widget()->Deactivate(); | 425 launcher_widget()->Deactivate(); |
426 status_->Deactivate(); | 426 status_area_widget_->Deactivate(); |
427 if (gesture_drag_auto_hide_state_ == AUTO_HIDE_HIDDEN && | 427 if (gesture_drag_auto_hide_state_ == AUTO_HIDE_HIDDEN && |
428 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS) { | 428 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS) { |
429 gesture_drag_status_ = GESTURE_DRAG_NONE; | 429 gesture_drag_status_ = GESTURE_DRAG_NONE; |
430 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 430 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
431 } else if (gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN && | 431 } else if (gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN && |
432 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_NEVER) { | 432 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_NEVER) { |
433 gesture_drag_status_ = GESTURE_DRAG_NONE; | 433 gesture_drag_status_ = GESTURE_DRAG_NONE; |
434 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 434 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
435 } else { | 435 } else { |
436 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; | 436 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; |
437 UpdateVisibilityState(); | 437 UpdateVisibilityState(); |
438 gesture_drag_status_ = GESTURE_DRAG_NONE; | 438 gesture_drag_status_ = GESTURE_DRAG_NONE; |
439 } | 439 } |
440 } | 440 } |
441 | 441 |
442 void ShelfLayoutManager::CancelGestureDrag() { | 442 void ShelfLayoutManager::CancelGestureDrag() { |
443 gesture_drag_status_ = GESTURE_DRAG_NONE; | 443 gesture_drag_status_ = GESTURE_DRAG_NONE; |
444 ui::ScopedLayerAnimationSettings | 444 ui::ScopedLayerAnimationSettings |
445 launcher_settings(GetLayer(launcher_widget())->GetAnimator()), | 445 launcher_settings(GetLayer(launcher_widget())->GetAnimator()), |
446 status_settings(GetLayer(status_)->GetAnimator()); | 446 status_settings(GetLayer(status_area_widget_)->GetAnimator()); |
447 LayoutShelf(); | 447 LayoutShelf(); |
448 UpdateVisibilityState(); | 448 UpdateVisibilityState(); |
449 UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); | 449 UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); |
450 } | 450 } |
451 | 451 |
452 //////////////////////////////////////////////////////////////////////////////// | 452 //////////////////////////////////////////////////////////////////////////////// |
453 // ShelfLayoutManager, aura::LayoutManager implementation: | 453 // ShelfLayoutManager, aura::LayoutManager implementation: |
454 | 454 |
455 void ShelfLayoutManager::OnWindowResized() { | 455 void ShelfLayoutManager::OnWindowResized() { |
456 LayoutShelf(); | 456 LayoutShelf(); |
(...skipping 12 matching lines...) Expand all Loading... |
469 bool visible) { | 469 bool visible) { |
470 } | 470 } |
471 | 471 |
472 void ShelfLayoutManager::SetChildBounds(aura::Window* child, | 472 void ShelfLayoutManager::SetChildBounds(aura::Window* child, |
473 const gfx::Rect& requested_bounds) { | 473 const gfx::Rect& requested_bounds) { |
474 SetChildBoundsDirect(child, requested_bounds); | 474 SetChildBoundsDirect(child, requested_bounds); |
475 // We may contain other widgets (such as frame maximize bubble) but they don't | 475 // We may contain other widgets (such as frame maximize bubble) but they don't |
476 // effect the layout in anyway. | 476 // effect the layout in anyway. |
477 if (!in_layout_ && | 477 if (!in_layout_ && |
478 ((launcher_widget() && launcher_widget()->GetNativeView() == child) || | 478 ((launcher_widget() && launcher_widget()->GetNativeView() == child) || |
479 (status_->GetNativeView() == child))) { | 479 (status_area_widget_->GetNativeView() == child))) { |
480 LayoutShelf(); | 480 LayoutShelf(); |
481 } | 481 } |
482 } | 482 } |
483 | 483 |
484 void ShelfLayoutManager::OnLockStateChanged(bool locked) { | 484 void ShelfLayoutManager::OnLockStateChanged(bool locked) { |
485 UpdateVisibilityState(); | 485 UpdateVisibilityState(); |
486 } | 486 } |
487 | 487 |
488 void ShelfLayoutManager::OnWindowActivated(aura::Window* active, | 488 void ShelfLayoutManager::OnWindowActivated(aura::Window* active, |
489 aura::Window* old_active) { | 489 aura::Window* old_active) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 ui::ScopedLayerAnimationSettings launcher_animation_setter( | 546 ui::ScopedLayerAnimationSettings launcher_animation_setter( |
547 GetLayer(launcher_widget())->GetAnimator()); | 547 GetLayer(launcher_widget())->GetAnimator()); |
548 launcher_animation_setter.SetTransitionDuration( | 548 launcher_animation_setter.SetTransitionDuration( |
549 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); | 549 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); |
550 launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT); | 550 launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT); |
551 GetLayer(launcher_widget())->SetBounds( | 551 GetLayer(launcher_widget())->SetBounds( |
552 target_bounds.launcher_bounds_in_root); | 552 target_bounds.launcher_bounds_in_root); |
553 GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity); | 553 GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity); |
554 } | 554 } |
555 ui::ScopedLayerAnimationSettings status_animation_setter( | 555 ui::ScopedLayerAnimationSettings status_animation_setter( |
556 GetLayer(status_)->GetAnimator()); | 556 GetLayer(status_area_widget_)->GetAnimator()); |
557 status_animation_setter.SetTransitionDuration( | 557 status_animation_setter.SetTransitionDuration( |
558 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); | 558 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); |
559 status_animation_setter.SetTweenType(ui::Tween::EASE_OUT); | 559 status_animation_setter.SetTweenType(ui::Tween::EASE_OUT); |
560 | 560 |
561 // Delay updating the background when going from AUTO_HIDE_SHOWN to | 561 // Delay updating the background when going from AUTO_HIDE_SHOWN to |
562 // AUTO_HIDE_HIDDEN until the shelf animates out. Otherwise during the | 562 // AUTO_HIDE_HIDDEN until the shelf animates out. Otherwise during the |
563 // animation you see the background change. | 563 // animation you see the background change. |
564 // Also delay the animation when the shelf was hidden, and has just been made | 564 // Also delay the animation when the shelf was hidden, and has just been made |
565 // visible (e.g. using a gesture-drag). | 565 // visible (e.g. using a gesture-drag). |
566 bool delay_shelf_update = | 566 bool delay_shelf_update = |
567 state.visibility_state == AUTO_HIDE && | 567 state.visibility_state == AUTO_HIDE && |
568 state.auto_hide_state == AUTO_HIDE_HIDDEN && | 568 state.auto_hide_state == AUTO_HIDE_HIDDEN && |
569 old_state.visibility_state == AUTO_HIDE; | 569 old_state.visibility_state == AUTO_HIDE; |
570 | 570 |
571 if (state.visibility_state == VISIBLE && | 571 if (state.visibility_state == VISIBLE && |
572 old_state.visibility_state == AUTO_HIDE && | 572 old_state.visibility_state == AUTO_HIDE && |
573 old_state.auto_hide_state == AUTO_HIDE_HIDDEN) | 573 old_state.auto_hide_state == AUTO_HIDE_HIDDEN) |
574 delay_shelf_update = true; | 574 delay_shelf_update = true; |
575 | 575 |
576 if (delay_shelf_update) { | 576 if (delay_shelf_update) { |
577 if (update_shelf_observer_) | 577 if (update_shelf_observer_) |
578 update_shelf_observer_->Detach(); | 578 update_shelf_observer_->Detach(); |
579 // UpdateShelfBackground deletes itself when the animation is done. | 579 // UpdateShelfBackground deletes itself when the animation is done. |
580 update_shelf_observer_ = new UpdateShelfObserver(this); | 580 update_shelf_observer_ = new UpdateShelfObserver(this); |
581 status_animation_setter.AddObserver(update_shelf_observer_); | 581 status_animation_setter.AddObserver(update_shelf_observer_); |
582 } | 582 } |
583 GetLayer(status_)->SetBounds(target_bounds.status_bounds_in_root); | 583 ui::Layer* layer = GetLayer(status_area_widget_); |
584 GetLayer(status_)->SetOpacity(target_bounds.opacity); | 584 layer->SetBounds(target_bounds.status_bounds_in_root); |
| 585 layer->SetOpacity(target_bounds.opacity); |
585 Shell::GetInstance()->SetDisplayWorkAreaInsets( | 586 Shell::GetInstance()->SetDisplayWorkAreaInsets( |
586 Shell::GetPrimaryRootWindow(), | 587 Shell::GetPrimaryRootWindow(), |
587 target_bounds.work_area_insets); | 588 target_bounds.work_area_insets); |
588 UpdateHitTestBounds(); | 589 UpdateHitTestBounds(); |
589 if (!delay_shelf_update) | 590 if (!delay_shelf_update) |
590 UpdateShelfBackground(change_type); | 591 UpdateShelfBackground(change_type); |
591 } | 592 } |
592 | 593 |
593 void ShelfLayoutManager::StopAnimating() { | 594 void ShelfLayoutManager::StopAnimating() { |
| 595 ui::Layer* layer = GetLayer(status_area_widget_); |
594 if (launcher_widget()) | 596 if (launcher_widget()) |
595 GetLayer(launcher_widget())->GetAnimator()->StopAnimating(); | 597 layer->GetAnimator()->StopAnimating(); |
596 GetLayer(status_)->GetAnimator()->StopAnimating(); | 598 layer->GetAnimator()->StopAnimating(); |
597 } | 599 } |
598 | 600 |
599 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { | 601 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { |
600 *width = *height = 0; | 602 *width = *height = 0; |
601 gfx::Size status_size(status_->GetWindowBoundsInScreen().size()); | 603 gfx::Size status_size(status_area_widget_->GetWindowBoundsInScreen().size()); |
602 gfx::Size launcher_size = launcher_ ? | 604 gfx::Size launcher_size = launcher_ ? |
603 launcher_widget()->GetContentsView()->GetPreferredSize() : gfx::Size(); | 605 launcher_widget()->GetContentsView()->GetPreferredSize() : gfx::Size(); |
604 if (alignment_ == SHELF_ALIGNMENT_BOTTOM) | 606 if (alignment_ == SHELF_ALIGNMENT_BOTTOM) |
605 *height = std::max(launcher_size.height(), status_size.height()); | 607 *height = std::max(launcher_size.height(), status_size.height()); |
606 else | 608 else |
607 *width = std::max(launcher_size.width(), status_size.width()); | 609 *width = std::max(launcher_size.width(), status_size.width()); |
608 } | 610 } |
609 | 611 |
610 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, | 612 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, |
611 gfx::Rect* bounds) const { | 613 gfx::Rect* bounds) const { |
612 switch (alignment_) { | 614 switch (alignment_) { |
613 case SHELF_ALIGNMENT_BOTTOM: | 615 case SHELF_ALIGNMENT_BOTTOM: |
614 bounds->Inset(gfx::Insets(0, 0, inset, 0)); | 616 bounds->Inset(gfx::Insets(0, 0, inset, 0)); |
615 break; | 617 break; |
616 case SHELF_ALIGNMENT_LEFT: | 618 case SHELF_ALIGNMENT_LEFT: |
617 bounds->Inset(gfx::Insets(0, inset, 0, 0)); | 619 bounds->Inset(gfx::Insets(0, inset, 0, 0)); |
618 break; | 620 break; |
619 case SHELF_ALIGNMENT_RIGHT: | 621 case SHELF_ALIGNMENT_RIGHT: |
620 bounds->Inset(gfx::Insets(0, 0, 0, inset)); | 622 bounds->Inset(gfx::Insets(0, 0, 0, inset)); |
621 break; | 623 break; |
622 } | 624 } |
623 } | 625 } |
624 | 626 |
625 void ShelfLayoutManager::CalculateTargetBounds( | 627 void ShelfLayoutManager::CalculateTargetBounds( |
626 const State& state, | 628 const State& state, |
627 TargetBounds* target_bounds) { | 629 TargetBounds* target_bounds) { |
628 const gfx::Rect& available_bounds( | 630 const gfx::Rect& available_bounds(root_window_->bounds()); |
629 status_->GetNativeView()->GetRootWindow()->bounds()); | 631 gfx::Rect status_size(status_area_widget_->GetWindowBoundsInScreen().size()); |
630 gfx::Rect status_size(status_->GetWindowBoundsInScreen().size()); | |
631 gfx::Size launcher_size = launcher_ ? | 632 gfx::Size launcher_size = launcher_ ? |
632 launcher_widget()->GetContentsView()->GetPreferredSize() : gfx::Size(); | 633 launcher_widget()->GetContentsView()->GetPreferredSize() : gfx::Size(); |
633 int shelf_size = 0; | 634 int shelf_size = 0; |
634 int shelf_width = 0, shelf_height = 0; | 635 int shelf_width = 0, shelf_height = 0; |
635 GetShelfSize(&shelf_width, &shelf_height); | 636 GetShelfSize(&shelf_width, &shelf_height); |
636 if (state.visibility_state == VISIBLE || | 637 if (state.visibility_state == VISIBLE || |
637 (state.visibility_state == AUTO_HIDE && | 638 (state.visibility_state == AUTO_HIDE && |
638 state.auto_hide_state == AUTO_HIDE_SHOWN)) { | 639 state.auto_hide_state == AUTO_HIDE_SHOWN)) { |
639 shelf_size = std::max(shelf_width, shelf_height); | 640 shelf_size = std::max(shelf_width, shelf_height); |
640 } else if (state.visibility_state == AUTO_HIDE && | 641 } else if (state.visibility_state == AUTO_HIDE && |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 } | 781 } |
781 } | 782 } |
782 | 783 |
783 void ShelfLayoutManager::UpdateShelfBackground( | 784 void ShelfLayoutManager::UpdateShelfBackground( |
784 BackgroundAnimator::ChangeType type) { | 785 BackgroundAnimator::ChangeType type) { |
785 bool launcher_paints = GetLauncherPaintsBackground(); | 786 bool launcher_paints = GetLauncherPaintsBackground(); |
786 if (launcher_) | 787 if (launcher_) |
787 launcher_->SetPaintsBackground(launcher_paints, type); | 788 launcher_->SetPaintsBackground(launcher_paints, type); |
788 // The status area normally draws a background, but we don't want it to draw a | 789 // The status area normally draws a background, but we don't want it to draw a |
789 // background when the launcher does or when we're at login/lock screen. | 790 // background when the launcher does or when we're at login/lock screen. |
790 StatusAreaWidget* status_area_widget = | 791 ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
791 Shell::GetInstance()->status_area_widget(); | 792 bool delegate_allows_tray_bg = !delegate || |
792 if (status_area_widget) { | 793 (delegate->IsUserLoggedIn() && !delegate->IsScreenLocked()); |
793 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | 794 bool status_area_paints = !launcher_paints && delegate_allows_tray_bg; |
794 bool delegate_allows_tray_bg = !delegate || | 795 status_area_widget_->SetPaintsBackground(status_area_paints, type); |
795 (delegate->IsUserLoggedIn() && !delegate->IsScreenLocked()); | |
796 bool status_area_paints = !launcher_paints && delegate_allows_tray_bg; | |
797 status_area_widget->SetPaintsBackground(status_area_paints, type); | |
798 } | |
799 } | 796 } |
800 | 797 |
801 bool ShelfLayoutManager::GetLauncherPaintsBackground() const { | 798 bool ShelfLayoutManager::GetLauncherPaintsBackground() const { |
802 return gesture_drag_status_ != GESTURE_DRAG_NONE || | 799 return gesture_drag_status_ != GESTURE_DRAG_NONE || |
803 (!state_.is_screen_locked && window_overlaps_shelf_) || | 800 (!state_.is_screen_locked && window_overlaps_shelf_) || |
804 (state_.visibility_state == AUTO_HIDE) ; | 801 (state_.visibility_state == AUTO_HIDE) ; |
805 } | 802 } |
806 | 803 |
807 void ShelfLayoutManager::UpdateAutoHideStateNow() { | 804 void ShelfLayoutManager::UpdateAutoHideStateNow() { |
808 SetState(state_.visibility_state); | 805 SetState(state_.visibility_state); |
809 } | 806 } |
810 | 807 |
811 ShelfLayoutManager::AutoHideState ShelfLayoutManager::CalculateAutoHideState( | 808 ShelfLayoutManager::AutoHideState ShelfLayoutManager::CalculateAutoHideState( |
812 VisibilityState visibility_state) const { | 809 VisibilityState visibility_state) const { |
813 if (visibility_state != AUTO_HIDE || !launcher_widget()) | 810 if (visibility_state != AUTO_HIDE || !launcher_widget()) |
814 return AUTO_HIDE_HIDDEN; | 811 return AUTO_HIDE_HIDDEN; |
815 | 812 |
816 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) | 813 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) |
817 return gesture_drag_auto_hide_state_; | 814 return gesture_drag_auto_hide_state_; |
818 | 815 |
819 Shell* shell = Shell::GetInstance(); | 816 Shell* shell = Shell::GetInstance(); |
820 if (shell->GetAppListTargetVisibility()) | 817 if (shell->GetAppListTargetVisibility()) |
821 return AUTO_HIDE_SHOWN; | 818 return AUTO_HIDE_SHOWN; |
822 | 819 |
823 if (shell->status_area_widget() && | 820 if (status_area_widget_ && status_area_widget_->ShouldShowLauncher()) |
824 shell->status_area_widget()->ShouldShowLauncher()) | |
825 return AUTO_HIDE_SHOWN; | 821 return AUTO_HIDE_SHOWN; |
826 | 822 |
827 if (launcher_ && launcher_->IsShowingMenu()) | 823 if (launcher_ && launcher_->IsShowingMenu()) |
828 return AUTO_HIDE_SHOWN; | 824 return AUTO_HIDE_SHOWN; |
829 | 825 |
830 if (launcher_ && launcher_->IsShowingOverflowBubble()) | 826 if (launcher_ && launcher_->IsShowingOverflowBubble()) |
831 return AUTO_HIDE_SHOWN; | 827 return AUTO_HIDE_SHOWN; |
832 | 828 |
833 if (launcher_widget()->IsActive() || status_->IsActive()) | 829 if (launcher_widget()->IsActive() || status_area_widget_->IsActive()) |
834 return AUTO_HIDE_SHOWN; | 830 return AUTO_HIDE_SHOWN; |
835 | 831 |
836 // Don't show if the user is dragging the mouse. | 832 // Don't show if the user is dragging the mouse. |
837 if (event_filter_.get() && event_filter_->in_mouse_drag()) | 833 if (event_filter_.get() && event_filter_->in_mouse_drag()) |
838 return AUTO_HIDE_HIDDEN; | 834 return AUTO_HIDE_HIDDEN; |
839 | 835 |
840 gfx::Rect shelf_region = launcher_widget()->GetWindowBoundsInScreen(); | 836 gfx::Rect shelf_region = launcher_widget()->GetWindowBoundsInScreen(); |
841 if (shell->status_area_widget() && | 837 if (status_area_widget_ && |
842 shell->status_area_widget()->IsMessageBubbleShown() && | 838 status_area_widget_->IsMessageBubbleShown() && |
843 IsVisible()) { | 839 IsVisible()) { |
844 // Increase the the hit test area to prevent the shelf from disappearing | 840 // Increase the the hit test area to prevent the shelf from disappearing |
845 // when the mouse is over the bubble gap. | 841 // when the mouse is over the bubble gap. |
846 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? | 842 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? |
847 -kNotificationBubbleGapHeight : 0, | 843 -kNotificationBubbleGapHeight : 0, |
848 alignment_ == SHELF_ALIGNMENT_BOTTOM ? | 844 alignment_ == SHELF_ALIGNMENT_BOTTOM ? |
849 -kNotificationBubbleGapHeight : 0, | 845 -kNotificationBubbleGapHeight : 0, |
850 alignment_ == SHELF_ALIGNMENT_LEFT ? | 846 alignment_ == SHELF_ALIGNMENT_LEFT ? |
851 -kNotificationBubbleGapHeight : 0, | 847 -kNotificationBubbleGapHeight : 0, |
852 0); | 848 0); |
(...skipping 18 matching lines...) Expand all Loading... |
871 break; | 867 break; |
872 case SHELF_ALIGNMENT_RIGHT: | 868 case SHELF_ALIGNMENT_RIGHT: |
873 insets.Set(0, kWorkspaceAreaBottomInset, 0, 0); | 869 insets.Set(0, kWorkspaceAreaBottomInset, 0, 0); |
874 break; | 870 break; |
875 } | 871 } |
876 } | 872 } |
877 if (launcher_widget() && launcher_widget()->GetNativeWindow()) { | 873 if (launcher_widget() && launcher_widget()->GetNativeWindow()) { |
878 launcher_widget()->GetNativeWindow()->SetHitTestBoundsOverrideOuter( | 874 launcher_widget()->GetNativeWindow()->SetHitTestBoundsOverrideOuter( |
879 insets, 1); | 875 insets, 1); |
880 } | 876 } |
881 status_->GetNativeWindow()->SetHitTestBoundsOverrideOuter( insets, 1); | 877 status_area_widget_->GetNativeWindow()-> |
| 878 SetHitTestBoundsOverrideOuter(insets, 1); |
882 } | 879 } |
883 | 880 |
884 bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) { | 881 bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) { |
885 if (!window) | 882 if (!window) |
886 return false; | 883 return false; |
887 return (launcher_widget() && | 884 return (launcher_widget() && |
888 launcher_widget()->GetNativeWindow()->Contains(window)) || | 885 launcher_widget()->GetNativeWindow()->Contains(window)) || |
889 (status_ && status_->GetNativeWindow()->Contains(window)); | 886 (status_area_widget_->GetNativeWindow()->Contains(window)); |
890 } | 887 } |
891 | 888 |
892 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { | 889 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { |
893 if (state.visibility_state == VISIBLE) | 890 if (state.visibility_state == VISIBLE) |
894 return size; | 891 return size; |
895 if (state.visibility_state == AUTO_HIDE) | 892 if (state.visibility_state == AUTO_HIDE) |
896 return kAutoHideSize; | 893 return kAutoHideSize; |
897 return 0; | 894 return 0; |
898 } | 895 } |
899 | 896 |
900 } // namespace internal | 897 } // namespace internal |
901 } // namespace ash | 898 } // namespace ash |
OLD | NEW |