| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 alignment_(SHELF_ALIGNMENT_BOTTOM), | 129 alignment_(SHELF_ALIGNMENT_BOTTOM), |
| 130 launcher_(NULL), | 130 launcher_(NULL), |
| 131 status_(status), | 131 status_(status), |
| 132 workspace_manager_(NULL), | 132 workspace_manager_(NULL), |
| 133 window_overlaps_shelf_(false) { | 133 window_overlaps_shelf_(false) { |
| 134 Shell::GetInstance()->AddShellObserver(this); | 134 Shell::GetInstance()->AddShellObserver(this); |
| 135 aura::client::GetActivationClient(root_window_)->AddObserver(this); | 135 aura::client::GetActivationClient(root_window_)->AddObserver(this); |
| 136 } | 136 } |
| 137 | 137 |
| 138 ShelfLayoutManager::~ShelfLayoutManager() { | 138 ShelfLayoutManager::~ShelfLayoutManager() { |
| 139 FOR_EACH_OBSERVER(Observer, observers_, WillDeleteShelf()); |
| 139 Shell::GetInstance()->RemoveShellObserver(this); | 140 Shell::GetInstance()->RemoveShellObserver(this); |
| 140 aura::client::GetActivationClient(root_window_)->RemoveObserver(this); | 141 aura::client::GetActivationClient(root_window_)->RemoveObserver(this); |
| 141 } | 142 } |
| 142 | 143 |
| 143 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { | 144 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { |
| 144 if (auto_hide_behavior_ == behavior) | 145 if (auto_hide_behavior_ == behavior) |
| 145 return; | 146 return; |
| 146 auto_hide_behavior_ = behavior; | 147 auto_hide_behavior_ = behavior; |
| 147 UpdateVisibilityState(); | 148 UpdateVisibilityState(); |
| 149 FOR_EACH_OBSERVER(Observer, observers_, |
| 150 OnAutoHideStateChanged(state_.auto_hide_state)); |
| 148 } | 151 } |
| 149 | 152 |
| 150 bool ShelfLayoutManager::IsVisible() const { | 153 bool ShelfLayoutManager::IsVisible() const { |
| 151 return status_->IsVisible() && (state_.visibility_state == VISIBLE || | 154 return status_->IsVisible() && (state_.visibility_state == VISIBLE || |
| 152 (state_.visibility_state == AUTO_HIDE && | 155 (state_.visibility_state == AUTO_HIDE && |
| 153 state_.auto_hide_state == AUTO_HIDE_SHOWN)); | 156 state_.auto_hide_state == AUTO_HIDE_SHOWN)); |
| 154 } | 157 } |
| 155 | 158 |
| 156 gfx::Rect ShelfLayoutManager::GetMaximizedWindowBounds( | 159 gfx::Rect ShelfLayoutManager::GetMaximizedWindowBounds( |
| 157 aura::Window* window) { | 160 aura::Window* window) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 275 } |
| 273 } | 276 } |
| 274 | 277 |
| 275 void ShelfLayoutManager::UpdateAutoHideState() { | 278 void ShelfLayoutManager::UpdateAutoHideState() { |
| 276 AutoHideState auto_hide_state = | 279 AutoHideState auto_hide_state = |
| 277 CalculateAutoHideState(state_.visibility_state); | 280 CalculateAutoHideState(state_.visibility_state); |
| 278 if (auto_hide_state != state_.auto_hide_state) { | 281 if (auto_hide_state != state_.auto_hide_state) { |
| 279 if (auto_hide_state == AUTO_HIDE_HIDDEN) { | 282 if (auto_hide_state == AUTO_HIDE_HIDDEN) { |
| 280 // Hides happen immediately. | 283 // Hides happen immediately. |
| 281 SetState(state_.visibility_state); | 284 SetState(state_.visibility_state); |
| 285 FOR_EACH_OBSERVER(Observer, observers_, |
| 286 OnAutoHideStateChanged(auto_hide_state)); |
| 282 } else { | 287 } else { |
| 283 auto_hide_timer_.Stop(); | 288 auto_hide_timer_.Stop(); |
| 284 auto_hide_timer_.Start( | 289 auto_hide_timer_.Start( |
| 285 FROM_HERE, | 290 FROM_HERE, |
| 286 base::TimeDelta::FromMilliseconds(kAutoHideDelayMS), | 291 base::TimeDelta::FromMilliseconds(kAutoHideDelayMS), |
| 287 this, &ShelfLayoutManager::UpdateAutoHideStateNow); | 292 this, &ShelfLayoutManager::UpdateAutoHideStateNow); |
| 293 FOR_EACH_OBSERVER(Observer, observers_, OnAutoHideStateChanged( |
| 294 CalculateAutoHideState(state_.visibility_state))); |
| 288 } | 295 } |
| 289 } else { | 296 } else { |
| 290 auto_hide_timer_.Stop(); | 297 auto_hide_timer_.Stop(); |
| 291 } | 298 } |
| 292 } | 299 } |
| 293 | 300 |
| 294 void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { | 301 void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { |
| 295 window_overlaps_shelf_ = value; | 302 window_overlaps_shelf_ = value; |
| 296 UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); | 303 UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); |
| 297 } | 304 } |
| 298 | 305 |
| 306 void ShelfLayoutManager::AddObserver(Observer* observer) { |
| 307 observers_.AddObserver(observer); |
| 308 } |
| 309 |
| 310 void ShelfLayoutManager::RemoveObserver(Observer* observer) { |
| 311 observers_.RemoveObserver(observer); |
| 312 } |
| 313 |
| 299 //////////////////////////////////////////////////////////////////////////////// | 314 //////////////////////////////////////////////////////////////////////////////// |
| 300 // ShelfLayoutManager, aura::LayoutManager implementation: | 315 // ShelfLayoutManager, aura::LayoutManager implementation: |
| 301 | 316 |
| 302 void ShelfLayoutManager::OnWindowResized() { | 317 void ShelfLayoutManager::OnWindowResized() { |
| 303 LayoutShelf(); | 318 LayoutShelf(); |
| 304 } | 319 } |
| 305 | 320 |
| 306 void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 321 void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 307 } | 322 } |
| 308 | 323 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 338 void ShelfLayoutManager::SetState(VisibilityState visibility_state) { | 353 void ShelfLayoutManager::SetState(VisibilityState visibility_state) { |
| 339 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | 354 ShellDelegate* delegate = Shell::GetInstance()->delegate(); |
| 340 State state; | 355 State state; |
| 341 state.visibility_state = visibility_state; | 356 state.visibility_state = visibility_state; |
| 342 state.auto_hide_state = CalculateAutoHideState(visibility_state); | 357 state.auto_hide_state = CalculateAutoHideState(visibility_state); |
| 343 state.is_screen_locked = delegate && delegate->IsScreenLocked(); | 358 state.is_screen_locked = delegate && delegate->IsScreenLocked(); |
| 344 | 359 |
| 345 if (state_.Equals(state)) | 360 if (state_.Equals(state)) |
| 346 return; // Nothing changed. | 361 return; // Nothing changed. |
| 347 | 362 |
| 363 FOR_EACH_OBSERVER(Observer, observers_, |
| 364 WillChangeVisibilityState(visibility_state)); |
| 365 |
| 348 if (state.visibility_state == AUTO_HIDE) { | 366 if (state.visibility_state == AUTO_HIDE) { |
| 349 // When state is AUTO_HIDE we need to track when the mouse is over the | 367 // 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. | 368 // launcher to unhide the shelf. AutoHideEventFilter does that for us. |
| 351 if (!event_filter_.get()) | 369 if (!event_filter_.get()) |
| 352 event_filter_.reset(new AutoHideEventFilter(this)); | 370 event_filter_.reset(new AutoHideEventFilter(this)); |
| 353 } else { | 371 } else { |
| 354 event_filter_.reset(NULL); | 372 event_filter_.reset(NULL); |
| 355 } | 373 } |
| 356 | 374 |
| 357 auto_hide_timer_.Stop(); | 375 auto_hide_timer_.Stop(); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { | 592 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { |
| 575 if (state.visibility_state == VISIBLE) | 593 if (state.visibility_state == VISIBLE) |
| 576 return size; | 594 return size; |
| 577 if (state.visibility_state == AUTO_HIDE) | 595 if (state.visibility_state == AUTO_HIDE) |
| 578 return kAutoHideSize; | 596 return kAutoHideSize; |
| 579 return 0; | 597 return 0; |
| 580 } | 598 } |
| 581 | 599 |
| 582 } // namespace internal | 600 } // namespace internal |
| 583 } // namespace ash | 601 } // namespace ash |
| OLD | NEW |