Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: ash/wm/shelf_layout_manager.cc

Issue 11316323: Cleanup enums for shelf (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/shelf_layout_manager.h ('k') | ash/wm/shelf_layout_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 root_window_(status_area_widget->GetNativeView()->GetRootWindow()), 150 root_window_(status_area_widget->GetNativeView()->GetRootWindow()),
151 in_layout_(false), 151 in_layout_(false),
152 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), 152 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER),
153 alignment_(SHELF_ALIGNMENT_BOTTOM), 153 alignment_(SHELF_ALIGNMENT_BOTTOM),
154 launcher_(NULL), 154 launcher_(NULL),
155 status_area_widget_(status_area_widget), 155 status_area_widget_(status_area_widget),
156 workspace_controller_(NULL), 156 workspace_controller_(NULL),
157 window_overlaps_shelf_(false), 157 window_overlaps_shelf_(false),
158 gesture_drag_status_(GESTURE_DRAG_NONE), 158 gesture_drag_status_(GESTURE_DRAG_NONE),
159 gesture_drag_amount_(0.f), 159 gesture_drag_amount_(0.f),
160 gesture_drag_auto_hide_state_(AUTO_HIDE_SHOWN), 160 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN),
161 update_shelf_observer_(NULL) { 161 update_shelf_observer_(NULL) {
162 Shell::GetInstance()->AddShellObserver(this); 162 Shell::GetInstance()->AddShellObserver(this);
163 aura::client::GetActivationClient(root_window_)->AddObserver(this); 163 aura::client::GetActivationClient(root_window_)->AddObserver(this);
164 } 164 }
165 165
166 ShelfLayoutManager::~ShelfLayoutManager() { 166 ShelfLayoutManager::~ShelfLayoutManager() {
167 if (update_shelf_observer_) 167 if (update_shelf_observer_)
168 update_shelf_observer_->Detach(); 168 update_shelf_observer_->Detach();
169 169
170 FOR_EACH_OBSERVER(Observer, observers_, WillDeleteShelf()); 170 FOR_EACH_OBSERVER(Observer, observers_, WillDeleteShelf());
171 Shell::GetInstance()->RemoveShellObserver(this); 171 Shell::GetInstance()->RemoveShellObserver(this);
172 aura::client::GetActivationClient(root_window_)->RemoveObserver(this); 172 aura::client::GetActivationClient(root_window_)->RemoveObserver(this);
173 } 173 }
174 174
175 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { 175 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) {
176 if (auto_hide_behavior_ == behavior) 176 if (auto_hide_behavior_ == behavior)
177 return; 177 return;
178 auto_hide_behavior_ = behavior; 178 auto_hide_behavior_ = behavior;
179 UpdateVisibilityState(); 179 UpdateVisibilityState();
180 FOR_EACH_OBSERVER(Observer, observers_, 180 FOR_EACH_OBSERVER(Observer, observers_,
181 OnAutoHideStateChanged(state_.auto_hide_state)); 181 OnAutoHideStateChanged(state_.auto_hide_state));
182 } 182 }
183 183
184 bool ShelfLayoutManager::IsVisible() const { 184 bool ShelfLayoutManager::IsVisible() const {
185 return status_area_widget_->IsVisible() && 185 return status_area_widget_->IsVisible() &&
186 (state_.visibility_state == VISIBLE || 186 (state_.visibility_state == SHELF_VISIBLE ||
187 (state_.visibility_state == AUTO_HIDE && 187 (state_.visibility_state == SHELF_AUTO_HIDE &&
188 state_.auto_hide_state == AUTO_HIDE_SHOWN)); 188 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN));
189 } 189 }
190 190
191 void ShelfLayoutManager::SetLauncher(Launcher* launcher) { 191 void ShelfLayoutManager::SetLauncher(Launcher* launcher) {
192 if (launcher == launcher_) 192 if (launcher == launcher_)
193 return; 193 return;
194 194
195 launcher_ = launcher; 195 launcher_ = launcher;
196 if (launcher_) 196 if (launcher_)
197 launcher_->SetAlignment(alignment_); 197 launcher_->SetAlignment(alignment_);
198 LayoutShelf(); 198 LayoutShelf();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 target_bounds.status_bounds_in_root)); 251 target_bounds.status_bounds_in_root));
252 Shell::GetInstance()->SetDisplayWorkAreaInsets( 252 Shell::GetInstance()->SetDisplayWorkAreaInsets(
253 Shell::GetPrimaryRootWindow(), 253 Shell::GetPrimaryRootWindow(),
254 target_bounds.work_area_insets); 254 target_bounds.work_area_insets);
255 UpdateHitTestBounds(); 255 UpdateHitTestBounds();
256 } 256 }
257 257
258 void ShelfLayoutManager::UpdateVisibilityState() { 258 void ShelfLayoutManager::UpdateVisibilityState() {
259 ShellDelegate* delegate = Shell::GetInstance()->delegate(); 259 ShellDelegate* delegate = Shell::GetInstance()->delegate();
260 if (delegate && delegate->IsScreenLocked()) { 260 if (delegate && delegate->IsScreenLocked()) {
261 SetState(VISIBLE); 261 SetState(SHELF_VISIBLE);
262 } else if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) { 262 } else if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) {
263 SetState(AUTO_HIDE); 263 SetState(SHELF_AUTO_HIDE);
264 } else { 264 } else {
265 WorkspaceWindowState window_state(workspace_controller_->GetWindowState()); 265 WorkspaceWindowState window_state(workspace_controller_->GetWindowState());
266 switch (window_state) { 266 switch (window_state) {
267 case WORKSPACE_WINDOW_STATE_FULL_SCREEN: 267 case WORKSPACE_WINDOW_STATE_FULL_SCREEN:
268 SetState(HIDDEN); 268 SetState(SHELF_HIDDEN);
269 break; 269 break;
270 270
271 case WORKSPACE_WINDOW_STATE_MAXIMIZED: 271 case WORKSPACE_WINDOW_STATE_MAXIMIZED:
272 SetState(auto_hide_behavior_ == SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? 272 SetState(auto_hide_behavior_ == SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ?
273 AUTO_HIDE : VISIBLE); 273 SHELF_AUTO_HIDE : SHELF_VISIBLE);
274 break; 274 break;
275 275
276 case WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF: 276 case WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF:
277 case WORKSPACE_WINDOW_STATE_DEFAULT: 277 case WORKSPACE_WINDOW_STATE_DEFAULT:
278 SetState(auto_hide_behavior_ == SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? 278 SetState(auto_hide_behavior_ == SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ?
279 AUTO_HIDE : VISIBLE); 279 SHELF_AUTO_HIDE : SHELF_VISIBLE);
280 SetWindowOverlapsShelf(window_state == 280 SetWindowOverlapsShelf(window_state ==
281 WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF); 281 WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF);
282 break; 282 break;
283 } 283 }
284 } 284 }
285 } 285 }
286 286
287 void ShelfLayoutManager::UpdateAutoHideState() { 287 void ShelfLayoutManager::UpdateAutoHideState() {
288 AutoHideState auto_hide_state = 288 ShelfAutoHideState auto_hide_state =
289 CalculateAutoHideState(state_.visibility_state); 289 CalculateAutoHideState(state_.visibility_state);
290 if (auto_hide_state != state_.auto_hide_state) { 290 if (auto_hide_state != state_.auto_hide_state) {
291 if (auto_hide_state == AUTO_HIDE_HIDDEN) { 291 if (auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) {
292 // Hides happen immediately. 292 // Hides happen immediately.
293 SetState(state_.visibility_state); 293 SetState(state_.visibility_state);
294 FOR_EACH_OBSERVER(Observer, observers_, 294 FOR_EACH_OBSERVER(Observer, observers_,
295 OnAutoHideStateChanged(auto_hide_state)); 295 OnAutoHideStateChanged(auto_hide_state));
296 } else { 296 } else {
297 auto_hide_timer_.Stop(); 297 auto_hide_timer_.Stop();
298 auto_hide_timer_.Start( 298 auto_hide_timer_.Start(
299 FROM_HERE, 299 FROM_HERE,
300 base::TimeDelta::FromMilliseconds(kAutoHideDelayMS), 300 base::TimeDelta::FromMilliseconds(kAutoHideDelayMS),
301 this, &ShelfLayoutManager::UpdateAutoHideStateNow); 301 this, &ShelfLayoutManager::UpdateAutoHideStateNow);
(...skipping 17 matching lines...) Expand all
319 void ShelfLayoutManager::RemoveObserver(Observer* observer) { 319 void ShelfLayoutManager::RemoveObserver(Observer* observer) {
320 observers_.RemoveObserver(observer); 320 observers_.RemoveObserver(observer);
321 } 321 }
322 322
323 //////////////////////////////////////////////////////////////////////////////// 323 ////////////////////////////////////////////////////////////////////////////////
324 // ShelfLayoutManager, Gesture dragging: 324 // ShelfLayoutManager, Gesture dragging:
325 325
326 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { 326 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) {
327 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; 327 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS;
328 gesture_drag_amount_ = 0.f; 328 gesture_drag_amount_ = 0.f;
329 gesture_drag_auto_hide_state_ = visibility_state() == AUTO_HIDE ? 329 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE ?
330 auto_hide_state() : AUTO_HIDE_SHOWN; 330 auto_hide_state() : SHELF_AUTO_HIDE_SHOWN;
331 UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); 331 UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE);
332 } 332 }
333 333
334 ShelfLayoutManager::DragState ShelfLayoutManager::UpdateGestureDrag( 334 ShelfLayoutManager::DragState ShelfLayoutManager::UpdateGestureDrag(
335 const ui::GestureEvent& gesture) { 335 const ui::GestureEvent& gesture) {
336 bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM; 336 bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM;
337 gesture_drag_amount_ += horizontal ? gesture.details().scroll_y() : 337 gesture_drag_amount_ += horizontal ? gesture.details().scroll_y() :
338 gesture.details().scroll_x(); 338 gesture.details().scroll_x();
339 LayoutShelf(); 339 LayoutShelf();
340 340
341 // Start reveling the status menu when: 341 // Start reveling the status menu when:
342 // - dragging up on an already visible shelf 342 // - dragging up on an already visible shelf
343 // - dragging up on a hidden shelf, but it is currently completely visible. 343 // - dragging up on a hidden shelf, but it is currently completely visible.
344 if (horizontal && gesture.details().scroll_y() < 0) { 344 if (horizontal && gesture.details().scroll_y() < 0) {
345 int min_height = 0; 345 int min_height = 0;
346 if (gesture_drag_auto_hide_state_ == AUTO_HIDE_HIDDEN && launcher_widget()) 346 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN &&
347 launcher_widget())
347 min_height = launcher_widget()->GetContentsView()-> 348 min_height = launcher_widget()->GetContentsView()->
348 GetPreferredSize().height(); 349 GetPreferredSize().height();
349 350
350 if (min_height < launcher_widget()->GetWindowBoundsInScreen().height() && 351 if (min_height < launcher_widget()->GetWindowBoundsInScreen().height() &&
351 gesture.root_location().x() >= 352 gesture.root_location().x() >=
352 status_area_widget_->GetWindowBoundsInScreen().x() && 353 status_area_widget_->GetWindowBoundsInScreen().x() &&
353 IsDraggingTrayEnabled()) 354 IsDraggingTrayEnabled())
354 return DRAG_TRAY; 355 return DRAG_TRAY;
355 } 356 }
356 357
357 return DRAG_SHELF; 358 return DRAG_SHELF;
358 } 359 }
359 360
360 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { 361 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) {
361 bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM; 362 bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM;
362 bool should_change = false; 363 bool should_change = false;
363 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) { 364 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) {
364 // The visibility of the shelf changes only if the shelf was dragged X% 365 // The visibility of the shelf changes only if the shelf was dragged X%
365 // along the correct axis. If the shelf was already visible, then the 366 // along the correct axis. If the shelf was already visible, then the
366 // direction of the drag does not matter. 367 // direction of the drag does not matter.
367 const float kDragHideThreshold = 0.4f; 368 const float kDragHideThreshold = 0.4f;
368 gfx::Rect bounds = GetIdealBounds(); 369 gfx::Rect bounds = GetIdealBounds();
369 float drag_ratio = fabs(gesture_drag_amount_) / 370 float drag_ratio = fabs(gesture_drag_amount_) /
370 (horizontal ? bounds.height() : bounds.width()); 371 (horizontal ? bounds.height() : bounds.width());
371 if (gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN) { 372 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) {
372 should_change = drag_ratio > kDragHideThreshold; 373 should_change = drag_ratio > kDragHideThreshold;
373 } else { 374 } else {
374 bool correct_direction = false; 375 bool correct_direction = false;
375 switch (alignment()) { 376 switch (alignment()) {
376 case SHELF_ALIGNMENT_BOTTOM: 377 case SHELF_ALIGNMENT_BOTTOM:
377 case SHELF_ALIGNMENT_RIGHT: 378 case SHELF_ALIGNMENT_RIGHT:
378 correct_direction = gesture_drag_amount_ < 0; 379 correct_direction = gesture_drag_amount_ < 0;
379 break; 380 break;
380 case SHELF_ALIGNMENT_LEFT: 381 case SHELF_ALIGNMENT_LEFT:
381 correct_direction = gesture_drag_amount_ > 0; 382 correct_direction = gesture_drag_amount_ > 0;
382 break; 383 break;
383 } 384 }
384 should_change = correct_direction && drag_ratio > kDragHideThreshold; 385 should_change = correct_direction && drag_ratio > kDragHideThreshold;
385 } 386 }
386 } else if (gesture.type() == ui::ET_SCROLL_FLING_START) { 387 } else if (gesture.type() == ui::ET_SCROLL_FLING_START) {
387 if (gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN) { 388 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) {
388 should_change = horizontal ? fabs(gesture.details().velocity_y()) > 0 : 389 should_change = horizontal ? fabs(gesture.details().velocity_y()) > 0 :
389 fabs(gesture.details().velocity_x()) > 0; 390 fabs(gesture.details().velocity_x()) > 0;
390 } else { 391 } else {
391 if (horizontal) 392 if (horizontal)
392 should_change = gesture.details().velocity_y() < 0; 393 should_change = gesture.details().velocity_y() < 0;
393 else if (alignment() == SHELF_ALIGNMENT_LEFT) 394 else if (alignment() == SHELF_ALIGNMENT_LEFT)
394 should_change = gesture.details().velocity_x() > 0; 395 should_change = gesture.details().velocity_x() > 0;
395 else 396 else
396 should_change = gesture.details().velocity_x() < 0; 397 should_change = gesture.details().velocity_x() < 0;
397 } 398 }
398 } else { 399 } else {
399 NOTREACHED(); 400 NOTREACHED();
400 } 401 }
401 402
402 if (!should_change) { 403 if (!should_change) {
403 CancelGestureDrag(); 404 CancelGestureDrag();
404 return; 405 return;
405 } 406 }
406 407
407 gesture_drag_auto_hide_state_ = 408 gesture_drag_auto_hide_state_ =
408 gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN ? AUTO_HIDE_HIDDEN : 409 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN ?
409 AUTO_HIDE_SHOWN; 410 SHELF_AUTO_HIDE_HIDDEN : SHELF_AUTO_HIDE_SHOWN;
410 if (launcher_widget()) 411 if (launcher_widget())
411 launcher_widget()->Deactivate(); 412 launcher_widget()->Deactivate();
412 status_area_widget_->Deactivate(); 413 status_area_widget_->Deactivate();
413 if (gesture_drag_auto_hide_state_ == AUTO_HIDE_HIDDEN && 414 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN &&
414 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS) { 415 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS) {
415 gesture_drag_status_ = GESTURE_DRAG_NONE; 416 gesture_drag_status_ = GESTURE_DRAG_NONE;
416 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 417 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
417 } else if (gesture_drag_auto_hide_state_ == AUTO_HIDE_SHOWN && 418 } else if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN &&
418 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_NEVER) { 419 auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_NEVER) {
419 gesture_drag_status_ = GESTURE_DRAG_NONE; 420 gesture_drag_status_ = GESTURE_DRAG_NONE;
420 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 421 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
421 } else { 422 } else {
422 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; 423 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS;
423 UpdateVisibilityState(); 424 UpdateVisibilityState();
424 gesture_drag_status_ = GESTURE_DRAG_NONE; 425 gesture_drag_status_ = GESTURE_DRAG_NONE;
425 } 426 }
426 } 427 }
427 428
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 void ShelfLayoutManager::OnWindowActivated(aura::Window* active, 475 void ShelfLayoutManager::OnWindowActivated(aura::Window* active,
475 aura::Window* old_active) { 476 aura::Window* old_active) {
476 UpdateAutoHideStateNow(); 477 UpdateAutoHideStateNow();
477 } 478 }
478 479
479 //////////////////////////////////////////////////////////////////////////////// 480 ////////////////////////////////////////////////////////////////////////////////
480 // ShelfLayoutManager, private: 481 // ShelfLayoutManager, private:
481 482
482 ShelfLayoutManager::TargetBounds::TargetBounds() : opacity(0.0f) {} 483 ShelfLayoutManager::TargetBounds::TargetBounds() : opacity(0.0f) {}
483 484
484 void ShelfLayoutManager::SetState(VisibilityState visibility_state) { 485 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) {
485 ShellDelegate* delegate = Shell::GetInstance()->delegate(); 486 ShellDelegate* delegate = Shell::GetInstance()->delegate();
486 State state; 487 State state;
487 state.visibility_state = visibility_state; 488 state.visibility_state = visibility_state;
488 state.auto_hide_state = CalculateAutoHideState(visibility_state); 489 state.auto_hide_state = CalculateAutoHideState(visibility_state);
489 state.is_screen_locked = delegate && delegate->IsScreenLocked(); 490 state.is_screen_locked = delegate && delegate->IsScreenLocked();
490 491
491 // It's possible for SetState() when a window becomes maximized but the state 492 // It's possible for SetState() when a window becomes maximized but the state
492 // won't have changed value. Do the dimming check before the early exit. 493 // won't have changed value. Do the dimming check before the early exit.
493 if (launcher_ && workspace_controller_) { 494 if (launcher_ && workspace_controller_) {
494 launcher_->SetDimsShelf( 495 launcher_->SetDimsShelf(
495 (state.visibility_state == VISIBLE) && 496 (state.visibility_state == SHELF_VISIBLE) &&
496 workspace_controller_->GetWindowState() == 497 workspace_controller_->GetWindowState() ==
497 WORKSPACE_WINDOW_STATE_MAXIMIZED); 498 WORKSPACE_WINDOW_STATE_MAXIMIZED);
498 } 499 }
499 500
500 if (state_.Equals(state)) 501 if (state_.Equals(state))
501 return; // Nothing changed. 502 return; // Nothing changed.
502 503
503 FOR_EACH_OBSERVER(Observer, observers_, 504 FOR_EACH_OBSERVER(Observer, observers_,
504 WillChangeVisibilityState(visibility_state)); 505 WillChangeVisibilityState(visibility_state));
505 506
506 if (state.visibility_state == AUTO_HIDE) { 507 if (state.visibility_state == SHELF_AUTO_HIDE) {
507 // When state is AUTO_HIDE we need to track when the mouse is over the 508 // When state is SHELF_AUTO_HIDE we need to track when the mouse is over the
508 // launcher to unhide the shelf. AutoHideEventFilter does that for us. 509 // launcher to unhide the shelf. AutoHideEventFilter does that for us.
509 if (!event_filter_.get()) 510 if (!event_filter_.get())
510 event_filter_.reset(new AutoHideEventFilter(this)); 511 event_filter_.reset(new AutoHideEventFilter(this));
511 } else { 512 } else {
512 event_filter_.reset(NULL); 513 event_filter_.reset(NULL);
513 } 514 }
514 515
515 auto_hide_timer_.Stop(); 516 auto_hide_timer_.Stop();
516 517
517 // Animating the background when transitioning from auto-hide & hidden to 518 // Animating the background when transitioning from auto-hide & hidden to
518 // visible is janky. Update the background immediately in this case. 519 // visible is janky. Update the background immediately in this case.
519 internal::BackgroundAnimator::ChangeType change_type = 520 internal::BackgroundAnimator::ChangeType change_type =
520 (state_.visibility_state == AUTO_HIDE && 521 (state_.visibility_state == SHELF_AUTO_HIDE &&
521 state_.auto_hide_state == AUTO_HIDE_HIDDEN && 522 state_.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN &&
522 state.visibility_state == VISIBLE) ? 523 state.visibility_state == SHELF_VISIBLE) ?
523 internal::BackgroundAnimator::CHANGE_IMMEDIATE : 524 internal::BackgroundAnimator::CHANGE_IMMEDIATE :
524 internal::BackgroundAnimator::CHANGE_ANIMATE; 525 internal::BackgroundAnimator::CHANGE_ANIMATE;
525 StopAnimating(); 526 StopAnimating();
526 527
527 State old_state = state_; 528 State old_state = state_;
528 state_ = state; 529 state_ = state;
529 TargetBounds target_bounds; 530 TargetBounds target_bounds;
530 CalculateTargetBounds(state_, &target_bounds); 531 CalculateTargetBounds(state_, &target_bounds);
531 if (launcher_widget()) { 532 if (launcher_widget()) {
532 ui::ScopedLayerAnimationSettings launcher_animation_setter( 533 ui::ScopedLayerAnimationSettings launcher_animation_setter(
533 GetLayer(launcher_widget())->GetAnimator()); 534 GetLayer(launcher_widget())->GetAnimator());
534 launcher_animation_setter.SetTransitionDuration( 535 launcher_animation_setter.SetTransitionDuration(
535 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); 536 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS));
536 launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT); 537 launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT);
537 GetLayer(launcher_widget())->SetBounds( 538 GetLayer(launcher_widget())->SetBounds(
538 target_bounds.launcher_bounds_in_root); 539 target_bounds.launcher_bounds_in_root);
539 GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity); 540 GetLayer(launcher_widget())->SetOpacity(target_bounds.opacity);
540 } 541 }
541 ui::ScopedLayerAnimationSettings status_animation_setter( 542 ui::ScopedLayerAnimationSettings status_animation_setter(
542 GetLayer(status_area_widget_)->GetAnimator()); 543 GetLayer(status_area_widget_)->GetAnimator());
543 status_animation_setter.SetTransitionDuration( 544 status_animation_setter.SetTransitionDuration(
544 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); 545 base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS));
545 status_animation_setter.SetTweenType(ui::Tween::EASE_OUT); 546 status_animation_setter.SetTweenType(ui::Tween::EASE_OUT);
546 547
547 // Delay updating the background when going from AUTO_HIDE_SHOWN to 548 // Delay updating the background when going from SHELF_AUTO_HIDE_SHOWN to
548 // AUTO_HIDE_HIDDEN until the shelf animates out. Otherwise during the 549 // SHELF_AUTO_HIDE_HIDDEN until the shelf animates out. Otherwise during the
549 // animation you see the background change. 550 // animation you see the background change.
550 // Also delay the animation when the shelf was hidden, and has just been made 551 // Also delay the animation when the shelf was hidden, and has just been made
551 // visible (e.g. using a gesture-drag). 552 // visible (e.g. using a gesture-drag).
552 bool delay_shelf_update = 553 bool delay_shelf_update =
553 state.visibility_state == AUTO_HIDE && 554 state.visibility_state == SHELF_AUTO_HIDE &&
554 state.auto_hide_state == AUTO_HIDE_HIDDEN && 555 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN &&
555 old_state.visibility_state == AUTO_HIDE; 556 old_state.visibility_state == SHELF_AUTO_HIDE;
556 557
557 if (state.visibility_state == VISIBLE && 558 if (state.visibility_state == SHELF_VISIBLE &&
558 old_state.visibility_state == AUTO_HIDE && 559 old_state.visibility_state == SHELF_AUTO_HIDE &&
559 old_state.auto_hide_state == AUTO_HIDE_HIDDEN) 560 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN)
560 delay_shelf_update = true; 561 delay_shelf_update = true;
561 562
562 if (delay_shelf_update) { 563 if (delay_shelf_update) {
563 if (update_shelf_observer_) 564 if (update_shelf_observer_)
564 update_shelf_observer_->Detach(); 565 update_shelf_observer_->Detach();
565 // UpdateShelfBackground deletes itself when the animation is done. 566 // UpdateShelfBackground deletes itself when the animation is done.
566 update_shelf_observer_ = new UpdateShelfObserver(this); 567 update_shelf_observer_ = new UpdateShelfObserver(this);
567 status_animation_setter.AddObserver(update_shelf_observer_); 568 status_animation_setter.AddObserver(update_shelf_observer_);
568 } 569 }
569 ui::Layer* layer = GetLayer(status_area_widget_); 570 ui::Layer* layer = GetLayer(status_area_widget_);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 void ShelfLayoutManager::CalculateTargetBounds( 614 void ShelfLayoutManager::CalculateTargetBounds(
614 const State& state, 615 const State& state,
615 TargetBounds* target_bounds) { 616 TargetBounds* target_bounds) {
616 const gfx::Rect& available_bounds(root_window_->bounds()); 617 const gfx::Rect& available_bounds(root_window_->bounds());
617 gfx::Rect status_size(status_area_widget_->GetWindowBoundsInScreen().size()); 618 gfx::Rect status_size(status_area_widget_->GetWindowBoundsInScreen().size());
618 gfx::Size launcher_size = launcher_ ? 619 gfx::Size launcher_size = launcher_ ?
619 launcher_widget()->GetContentsView()->GetPreferredSize() : gfx::Size(); 620 launcher_widget()->GetContentsView()->GetPreferredSize() : gfx::Size();
620 int shelf_size = 0; 621 int shelf_size = 0;
621 int shelf_width = 0, shelf_height = 0; 622 int shelf_width = 0, shelf_height = 0;
622 GetShelfSize(&shelf_width, &shelf_height); 623 GetShelfSize(&shelf_width, &shelf_height);
623 if (state.visibility_state == VISIBLE || 624 if (state.visibility_state == SHELF_VISIBLE ||
624 (state.visibility_state == AUTO_HIDE && 625 (state.visibility_state == SHELF_AUTO_HIDE &&
625 state.auto_hide_state == AUTO_HIDE_SHOWN)) { 626 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)) {
626 shelf_size = std::max(shelf_width, shelf_height); 627 shelf_size = std::max(shelf_width, shelf_height);
627 launcher_size.set_width(std::max(shelf_width,launcher_size.width())); 628 launcher_size.set_width(std::max(shelf_width,launcher_size.width()));
628 launcher_size.set_height(std::max(shelf_height,launcher_size.height())); 629 launcher_size.set_height(std::max(shelf_height,launcher_size.height()));
629 } else if (state.visibility_state == AUTO_HIDE && 630 } else if (state.visibility_state == SHELF_AUTO_HIDE &&
630 state.auto_hide_state == AUTO_HIDE_HIDDEN) { 631 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) {
631 shelf_size = kAutoHideSize; 632 shelf_size = kAutoHideSize;
632 // Keep the launcher to its full height when dragging is in progress. 633 // Keep the launcher to its full height when dragging is in progress.
633 if (gesture_drag_status_ == GESTURE_DRAG_NONE) { 634 if (gesture_drag_status_ == GESTURE_DRAG_NONE) {
634 if (SHELF_ALIGNMENT_BOTTOM == alignment_) 635 if (SHELF_ALIGNMENT_BOTTOM == alignment_)
635 launcher_size.set_height(kAutoHideSize); 636 launcher_size.set_height(kAutoHideSize);
636 else 637 else
637 launcher_size.set_width(kAutoHideSize); 638 launcher_size.set_width(kAutoHideSize);
638 } 639 }
639 } 640 }
640 switch(alignment_) { 641 switch(alignment_) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 target_bounds->launcher_bounds_in_root = gfx::Rect( 678 target_bounds->launcher_bounds_in_root = gfx::Rect(
678 available_bounds.right() - launcher_size.width(), 679 available_bounds.right() - launcher_size.width(),
679 available_bounds.y(), 680 available_bounds.y(),
680 launcher_size.width(), available_bounds.height()); 681 launcher_size.width(), available_bounds.height());
681 target_bounds->work_area_insets.Set( 682 target_bounds->work_area_insets.Set(
682 0, 0, 0, GetWorkAreaSize(state, launcher_size.width())); 683 0, 0, 0, GetWorkAreaSize(state, launcher_size.width()));
683 break; 684 break;
684 } 685 }
685 target_bounds->opacity = 686 target_bounds->opacity =
686 (gesture_drag_status_ != GESTURE_DRAG_NONE || 687 (gesture_drag_status_ != GESTURE_DRAG_NONE ||
687 state.visibility_state == VISIBLE || 688 state.visibility_state == SHELF_VISIBLE ||
688 state.visibility_state == AUTO_HIDE) ? 1.0f : 0.0f; 689 state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f;
689 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS) 690 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS)
690 UpdateTargetBoundsForGesture(target_bounds); 691 UpdateTargetBoundsForGesture(target_bounds);
691 } 692 }
692 693
693 void ShelfLayoutManager::UpdateTargetBoundsForGesture( 694 void ShelfLayoutManager::UpdateTargetBoundsForGesture(
694 TargetBounds* target_bounds) const { 695 TargetBounds* target_bounds) const {
695 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); 696 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_);
696 bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM; 697 bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM;
697 int resistance_free_region = 0; 698 int resistance_free_region = 0;
698 699
699 if (gesture_drag_auto_hide_state_ == AUTO_HIDE_HIDDEN && 700 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN &&
700 visibility_state() == AUTO_HIDE && auto_hide_state() != AUTO_HIDE_SHOWN) { 701 visibility_state() == SHELF_AUTO_HIDE &&
702 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) {
701 // If the shelf was hidden when the drag started (and the state hasn't 703 // If the shelf was hidden when the drag started (and the state hasn't
702 // changed since then, e.g. because the tray-menu was shown because of the 704 // changed since then, e.g. because the tray-menu was shown because of the
703 // drag), then allow the drag some resistance-free region at first to make 705 // drag), then allow the drag some resistance-free region at first to make
704 // sure the shelf sticks with the finger until the shelf is visible. 706 // sure the shelf sticks with the finger until the shelf is visible.
705 resistance_free_region += horizontal ? 707 resistance_free_region += horizontal ?
706 target_bounds->launcher_bounds_in_root.height() : 708 target_bounds->launcher_bounds_in_root.height() :
707 target_bounds->launcher_bounds_in_root.width(); 709 target_bounds->launcher_bounds_in_root.width();
708 resistance_free_region -= kAutoHideSize; 710 resistance_free_region -= kAutoHideSize;
709 } 711 }
710 712
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 ShellDelegate* delegate = Shell::GetInstance()->delegate(); 792 ShellDelegate* delegate = Shell::GetInstance()->delegate();
791 bool delegate_allows_tray_bg = 793 bool delegate_allows_tray_bg =
792 delegate->IsUserLoggedIn() && !delegate->IsScreenLocked(); 794 delegate->IsUserLoggedIn() && !delegate->IsScreenLocked();
793 bool status_area_paints = !launcher_paints && delegate_allows_tray_bg; 795 bool status_area_paints = !launcher_paints && delegate_allows_tray_bg;
794 status_area_widget_->SetPaintsBackground(status_area_paints, type); 796 status_area_widget_->SetPaintsBackground(status_area_paints, type);
795 } 797 }
796 798
797 bool ShelfLayoutManager::GetLauncherPaintsBackground() const { 799 bool ShelfLayoutManager::GetLauncherPaintsBackground() const {
798 return gesture_drag_status_ != GESTURE_DRAG_NONE || 800 return gesture_drag_status_ != GESTURE_DRAG_NONE ||
799 (!state_.is_screen_locked && window_overlaps_shelf_) || 801 (!state_.is_screen_locked && window_overlaps_shelf_) ||
800 (state_.visibility_state == AUTO_HIDE) ; 802 (state_.visibility_state == SHELF_AUTO_HIDE) ;
801 } 803 }
802 804
803 void ShelfLayoutManager::UpdateAutoHideStateNow() { 805 void ShelfLayoutManager::UpdateAutoHideStateNow() {
804 SetState(state_.visibility_state); 806 SetState(state_.visibility_state);
805 } 807 }
806 808
807 ShelfLayoutManager::AutoHideState ShelfLayoutManager::CalculateAutoHideState( 809 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState(
808 VisibilityState visibility_state) const { 810 ShelfVisibilityState visibility_state) const {
809 if (visibility_state != AUTO_HIDE || !launcher_widget()) 811 if (visibility_state != SHELF_AUTO_HIDE || !launcher_widget())
810 return AUTO_HIDE_HIDDEN; 812 return SHELF_AUTO_HIDE_HIDDEN;
811 813
812 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) 814 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS)
813 return gesture_drag_auto_hide_state_; 815 return gesture_drag_auto_hide_state_;
814 816
815 Shell* shell = Shell::GetInstance(); 817 Shell* shell = Shell::GetInstance();
816 if (shell->GetAppListTargetVisibility()) 818 if (shell->GetAppListTargetVisibility())
817 return AUTO_HIDE_SHOWN; 819 return SHELF_AUTO_HIDE_SHOWN;
818 820
819 if (status_area_widget_ && status_area_widget_->ShouldShowLauncher()) 821 if (status_area_widget_ && status_area_widget_->ShouldShowLauncher())
820 return AUTO_HIDE_SHOWN; 822 return SHELF_AUTO_HIDE_SHOWN;
821 823
822 if (launcher_ && launcher_->IsShowingMenu()) 824 if (launcher_ && launcher_->IsShowingMenu())
823 return AUTO_HIDE_SHOWN; 825 return SHELF_AUTO_HIDE_SHOWN;
824 826
825 if (launcher_ && launcher_->IsShowingOverflowBubble()) 827 if (launcher_ && launcher_->IsShowingOverflowBubble())
826 return AUTO_HIDE_SHOWN; 828 return SHELF_AUTO_HIDE_SHOWN;
827 829
828 if (launcher_widget()->IsActive() || status_area_widget_->IsActive()) 830 if (launcher_widget()->IsActive() || status_area_widget_->IsActive())
829 return AUTO_HIDE_SHOWN; 831 return SHELF_AUTO_HIDE_SHOWN;
830 832
831 // Don't show if the user is dragging the mouse. 833 // Don't show if the user is dragging the mouse.
832 if (event_filter_.get() && event_filter_->in_mouse_drag()) 834 if (event_filter_.get() && event_filter_->in_mouse_drag())
833 return AUTO_HIDE_HIDDEN; 835 return SHELF_AUTO_HIDE_HIDDEN;
834 836
835 gfx::Rect shelf_region = launcher_widget()->GetWindowBoundsInScreen(); 837 gfx::Rect shelf_region = launcher_widget()->GetWindowBoundsInScreen();
836 if (status_area_widget_ && 838 if (status_area_widget_ &&
837 status_area_widget_->IsMessageBubbleShown() && 839 status_area_widget_->IsMessageBubbleShown() &&
838 IsVisible()) { 840 IsVisible()) {
839 // Increase the the hit test area to prevent the shelf from disappearing 841 // Increase the the hit test area to prevent the shelf from disappearing
840 // when the mouse is over the bubble gap. 842 // when the mouse is over the bubble gap.
841 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? 843 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ?
842 -kNotificationBubbleGapHeight : 0, 844 -kNotificationBubbleGapHeight : 0,
843 alignment_ == SHELF_ALIGNMENT_BOTTOM ? 845 alignment_ == SHELF_ALIGNMENT_BOTTOM ?
844 -kNotificationBubbleGapHeight : 0, 846 -kNotificationBubbleGapHeight : 0,
845 alignment_ == SHELF_ALIGNMENT_LEFT ? 847 alignment_ == SHELF_ALIGNMENT_LEFT ?
846 -kNotificationBubbleGapHeight : 0, 848 -kNotificationBubbleGapHeight : 0,
847 0); 849 0);
848 } 850 }
849 return shelf_region.Contains(Shell::GetScreen()->GetCursorScreenPoint()) ? 851 return shelf_region.Contains(Shell::GetScreen()->GetCursorScreenPoint()) ?
850 AUTO_HIDE_SHOWN : AUTO_HIDE_HIDDEN; 852 SHELF_AUTO_HIDE_SHOWN : SHELF_AUTO_HIDE_HIDDEN;
851 } 853 }
852 854
853 void ShelfLayoutManager::UpdateHitTestBounds() { 855 void ShelfLayoutManager::UpdateHitTestBounds() {
854 gfx::Insets insets; 856 gfx::Insets insets;
855 // Only modify the hit test when the shelf is visible, so we don't mess with 857 // Only modify the hit test when the shelf is visible, so we don't mess with
856 // hover hit testing in the auto-hide state. 858 // hover hit testing in the auto-hide state.
857 if (state_.visibility_state == VISIBLE) { 859 if (state_.visibility_state == SHELF_VISIBLE) {
858 // Let clicks at the very top of the launcher through so windows can be 860 // Let clicks at the very top of the launcher through so windows can be
859 // resized with the bottom-right corner and bottom edge. 861 // resized with the bottom-right corner and bottom edge.
860 switch (alignment_) { 862 switch (alignment_) {
861 case SHELF_ALIGNMENT_BOTTOM: 863 case SHELF_ALIGNMENT_BOTTOM:
862 insets.Set(kWorkspaceAreaBottomInset, 0, 0, 0); 864 insets.Set(kWorkspaceAreaBottomInset, 0, 0, 0);
863 break; 865 break;
864 case SHELF_ALIGNMENT_LEFT: 866 case SHELF_ALIGNMENT_LEFT:
865 insets.Set(0, 0, 0, kWorkspaceAreaBottomInset); 867 insets.Set(0, 0, 0, kWorkspaceAreaBottomInset);
866 break; 868 break;
867 case SHELF_ALIGNMENT_RIGHT: 869 case SHELF_ALIGNMENT_RIGHT:
(...skipping 11 matching lines...) Expand all
879 881
880 bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) { 882 bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) {
881 if (!window) 883 if (!window)
882 return false; 884 return false;
883 return (launcher_widget() && 885 return (launcher_widget() &&
884 launcher_widget()->GetNativeWindow()->Contains(window)) || 886 launcher_widget()->GetNativeWindow()->Contains(window)) ||
885 (status_area_widget_->GetNativeWindow()->Contains(window)); 887 (status_area_widget_->GetNativeWindow()->Contains(window));
886 } 888 }
887 889
888 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { 890 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const {
889 if (state.visibility_state == VISIBLE) 891 if (state.visibility_state == SHELF_VISIBLE)
890 return size; 892 return size;
891 if (state.visibility_state == AUTO_HIDE) 893 if (state.visibility_state == SHELF_AUTO_HIDE)
892 return kAutoHideSize; 894 return kAutoHideSize;
893 return 0; 895 return 0;
894 } 896 }
895 897
896 } // namespace internal 898 } // namespace internal
897 } // namespace ash 899 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/shelf_layout_manager.h ('k') | ash/wm/shelf_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698