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 | 8 |
9 #include "ash/launcher/launcher.h" | 9 #include "ash/launcher/launcher.h" |
10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 ShelfLayoutManager::~ShelfLayoutManager() { | 138 ShelfLayoutManager::~ShelfLayoutManager() { |
139 Shell::GetInstance()->RemoveShellObserver(this); | 139 Shell::GetInstance()->RemoveShellObserver(this); |
140 aura::client::GetActivationClient(root_window_)->RemoveObserver(this); | 140 aura::client::GetActivationClient(root_window_)->RemoveObserver(this); |
141 } | 141 } |
142 | 142 |
143 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { | 143 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { |
144 if (auto_hide_behavior_ == behavior) | 144 if (auto_hide_behavior_ == behavior) |
145 return; | 145 return; |
146 auto_hide_behavior_ = behavior; | 146 auto_hide_behavior_ = behavior; |
147 UpdateVisibilityState(); | 147 UpdateVisibilityState(); |
| 148 FOR_EACH_OBSERVER(Observer, observers_, |
| 149 OnAutoHideStateChanged(state_.auto_hide_state)); |
148 } | 150 } |
149 | 151 |
150 bool ShelfLayoutManager::IsVisible() const { | 152 bool ShelfLayoutManager::IsVisible() const { |
151 return status_->IsVisible() && (state_.visibility_state == VISIBLE || | 153 return status_->IsVisible() && (state_.visibility_state == VISIBLE || |
152 (state_.visibility_state == AUTO_HIDE && | 154 (state_.visibility_state == AUTO_HIDE && |
153 state_.auto_hide_state == AUTO_HIDE_SHOWN)); | 155 state_.auto_hide_state == AUTO_HIDE_SHOWN)); |
154 } | 156 } |
155 | 157 |
156 gfx::Rect ShelfLayoutManager::GetMaximizedWindowBounds( | 158 gfx::Rect ShelfLayoutManager::GetMaximizedWindowBounds( |
157 aura::Window* window) { | 159 aura::Window* window) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 } | 274 } |
273 } | 275 } |
274 | 276 |
275 void ShelfLayoutManager::UpdateAutoHideState() { | 277 void ShelfLayoutManager::UpdateAutoHideState() { |
276 AutoHideState auto_hide_state = | 278 AutoHideState auto_hide_state = |
277 CalculateAutoHideState(state_.visibility_state); | 279 CalculateAutoHideState(state_.visibility_state); |
278 if (auto_hide_state != state_.auto_hide_state) { | 280 if (auto_hide_state != state_.auto_hide_state) { |
279 if (auto_hide_state == AUTO_HIDE_HIDDEN) { | 281 if (auto_hide_state == AUTO_HIDE_HIDDEN) { |
280 // Hides happen immediately. | 282 // Hides happen immediately. |
281 SetState(state_.visibility_state); | 283 SetState(state_.visibility_state); |
| 284 FOR_EACH_OBSERVER(Observer, observers_, |
| 285 OnAutoHideStateChanged(auto_hide_state)); |
282 } else { | 286 } else { |
283 auto_hide_timer_.Stop(); | 287 auto_hide_timer_.Stop(); |
284 auto_hide_timer_.Start( | 288 auto_hide_timer_.Start( |
285 FROM_HERE, | 289 FROM_HERE, |
286 base::TimeDelta::FromMilliseconds(kAutoHideDelayMS), | 290 base::TimeDelta::FromMilliseconds(kAutoHideDelayMS), |
287 this, &ShelfLayoutManager::UpdateAutoHideStateNow); | 291 this, &ShelfLayoutManager::UpdateAutoHideStateNow); |
288 } | 292 } |
289 } else { | 293 } else { |
290 auto_hide_timer_.Stop(); | 294 auto_hide_timer_.Stop(); |
291 } | 295 } |
292 } | 296 } |
293 | 297 |
294 void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { | 298 void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { |
295 window_overlaps_shelf_ = value; | 299 window_overlaps_shelf_ = value; |
296 UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); | 300 UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); |
297 } | 301 } |
298 | 302 |
| 303 void ShelfLayoutManager::AddObserver(Observer* observer) { |
| 304 observers_.AddObserver(observer); |
| 305 } |
| 306 |
| 307 void ShelfLayoutManager::RemoveObserver(Observer* observer) { |
| 308 observers_.RemoveObserver(observer); |
| 309 } |
| 310 |
299 //////////////////////////////////////////////////////////////////////////////// | 311 //////////////////////////////////////////////////////////////////////////////// |
300 // ShelfLayoutManager, aura::LayoutManager implementation: | 312 // ShelfLayoutManager, aura::LayoutManager implementation: |
301 | 313 |
302 void ShelfLayoutManager::OnWindowResized() { | 314 void ShelfLayoutManager::OnWindowResized() { |
303 LayoutShelf(); | 315 LayoutShelf(); |
304 } | 316 } |
305 | 317 |
306 void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 318 void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
307 } | 319 } |
308 | 320 |
(...skipping 29 matching lines...) Expand all Loading... |
338 void ShelfLayoutManager::SetState(VisibilityState visibility_state) { | 350 void ShelfLayoutManager::SetState(VisibilityState visibility_state) { |
339 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | 351 ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
340 State state; | 352 State state; |
341 state.visibility_state = visibility_state; | 353 state.visibility_state = visibility_state; |
342 state.auto_hide_state = CalculateAutoHideState(visibility_state); | 354 state.auto_hide_state = CalculateAutoHideState(visibility_state); |
343 state.is_screen_locked = delegate && delegate->IsScreenLocked(); | 355 state.is_screen_locked = delegate && delegate->IsScreenLocked(); |
344 | 356 |
345 if (state_.Equals(state)) | 357 if (state_.Equals(state)) |
346 return; // Nothing changed. | 358 return; // Nothing changed. |
347 | 359 |
| 360 FOR_EACH_OBSERVER(Observer, observers_, |
| 361 WillVisibilityStateChange(visibility_state)); |
| 362 |
348 if (state.visibility_state == AUTO_HIDE) { | 363 if (state.visibility_state == AUTO_HIDE) { |
349 // When state is AUTO_HIDE we need to track when the mouse is over the | 364 // When state is AUTO_HIDE we need to track when the mouse is over the |
350 // launcher to unhide the shelf. AutoHideEventFilter does that for us. | 365 // launcher to unhide the shelf. AutoHideEventFilter does that for us. |
351 if (!event_filter_.get()) | 366 if (!event_filter_.get()) |
352 event_filter_.reset(new AutoHideEventFilter(this)); | 367 event_filter_.reset(new AutoHideEventFilter(this)); |
353 } else { | 368 } else { |
354 event_filter_.reset(NULL); | 369 event_filter_.reset(NULL); |
355 } | 370 } |
356 | 371 |
357 auto_hide_timer_.Stop(); | 372 auto_hide_timer_.Stop(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 status_area_widget->SetPaintsBackground(!launcher_paints, type); | 515 status_area_widget->SetPaintsBackground(!launcher_paints, type); |
501 } | 516 } |
502 | 517 |
503 bool ShelfLayoutManager::GetLauncherPaintsBackground() const { | 518 bool ShelfLayoutManager::GetLauncherPaintsBackground() const { |
504 return (!state_.is_screen_locked && window_overlaps_shelf_) || | 519 return (!state_.is_screen_locked && window_overlaps_shelf_) || |
505 state_.visibility_state == AUTO_HIDE; | 520 state_.visibility_state == AUTO_HIDE; |
506 } | 521 } |
507 | 522 |
508 void ShelfLayoutManager::UpdateAutoHideStateNow() { | 523 void ShelfLayoutManager::UpdateAutoHideStateNow() { |
509 SetState(state_.visibility_state); | 524 SetState(state_.visibility_state); |
| 525 FOR_EACH_OBSERVER(Observer, observers_, OnAutoHideStateChanged( |
| 526 CalculateAutoHideState(state_.visibility_state))); |
510 } | 527 } |
511 | 528 |
512 ShelfLayoutManager::AutoHideState ShelfLayoutManager::CalculateAutoHideState( | 529 ShelfLayoutManager::AutoHideState ShelfLayoutManager::CalculateAutoHideState( |
513 VisibilityState visibility_state) const { | 530 VisibilityState visibility_state) const { |
514 if (visibility_state != AUTO_HIDE || !launcher_widget()) | 531 if (visibility_state != AUTO_HIDE || !launcher_widget()) |
515 return AUTO_HIDE_HIDDEN; | 532 return AUTO_HIDE_HIDDEN; |
516 | 533 |
517 Shell* shell = Shell::GetInstance(); | 534 Shell* shell = Shell::GetInstance(); |
518 if (shell->GetAppListTargetVisibility()) | 535 if (shell->GetAppListTargetVisibility()) |
519 return AUTO_HIDE_SHOWN; | 536 return AUTO_HIDE_SHOWN; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { | 591 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { |
575 if (state.visibility_state == VISIBLE) | 592 if (state.visibility_state == VISIBLE) |
576 return size; | 593 return size; |
577 if (state.visibility_state == AUTO_HIDE) | 594 if (state.visibility_state == AUTO_HIDE) |
578 return kAutoHideSize; | 595 return kAutoHideSize; |
579 return 0; | 596 return 0; |
580 } | 597 } |
581 | 598 |
582 } // namespace internal | 599 } // namespace internal |
583 } // namespace ash | 600 } // namespace ash |
OLD | NEW |