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

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

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months 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
« no previous file with comments | « ash/shelf/shelf_layout_manager.h ('k') | ash/shelf/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/shelf/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 #include <cstring> 9 #include <cstring>
10 #include <string> 10 #include <string>
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 void OnGestureEvent(ui::GestureEvent* event) override; 106 void OnGestureEvent(ui::GestureEvent* event) override;
107 107
108 private: 108 private:
109 ShelfLayoutManager* shelf_; 109 ShelfLayoutManager* shelf_;
110 bool in_mouse_drag_; 110 bool in_mouse_drag_;
111 DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter); 111 DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter);
112 }; 112 };
113 113
114 ShelfLayoutManager::AutoHideEventFilter::AutoHideEventFilter( 114 ShelfLayoutManager::AutoHideEventFilter::AutoHideEventFilter(
115 ShelfLayoutManager* shelf) 115 ShelfLayoutManager* shelf)
116 : shelf_(shelf), 116 : shelf_(shelf), in_mouse_drag_(false) {
117 in_mouse_drag_(false) {
118 Shell::GetInstance()->AddPreTargetHandler(this); 117 Shell::GetInstance()->AddPreTargetHandler(this);
119 } 118 }
120 119
121 ShelfLayoutManager::AutoHideEventFilter::~AutoHideEventFilter() { 120 ShelfLayoutManager::AutoHideEventFilter::~AutoHideEventFilter() {
122 Shell::GetInstance()->RemovePreTargetHandler(this); 121 Shell::GetInstance()->RemovePreTargetHandler(this);
123 } 122 }
124 123
125 void ShelfLayoutManager::AutoHideEventFilter::OnMouseEvent( 124 void ShelfLayoutManager::AutoHideEventFilter::OnMouseEvent(
126 ui::MouseEvent* event) { 125 ui::MouseEvent* event) {
127 // This also checks IsShelfWindow() to make sure we don't attempt to hide the 126 // This also checks IsShelfWindow() to make sure we don't attempt to hide the
128 // shelf if the mouse down occurs on the shelf. 127 // shelf if the mouse down occurs on the shelf.
129 in_mouse_drag_ = (event->type() == ui::ET_MOUSE_DRAGGED || 128 in_mouse_drag_ =
130 (in_mouse_drag_ && event->type() != ui::ET_MOUSE_RELEASED && 129 (event->type() == ui::ET_MOUSE_DRAGGED ||
131 event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)) && 130 (in_mouse_drag_ && event->type() != ui::ET_MOUSE_RELEASED &&
131 event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)) &&
132 !shelf_->IsShelfWindow(static_cast<aura::Window*>(event->target())); 132 !shelf_->IsShelfWindow(static_cast<aura::Window*>(event->target()));
133 shelf_->UpdateAutoHideForMouseEvent(event); 133 shelf_->UpdateAutoHideForMouseEvent(event);
134 } 134 }
135 135
136 void ShelfLayoutManager::AutoHideEventFilter::OnGestureEvent( 136 void ShelfLayoutManager::AutoHideEventFilter::OnGestureEvent(
137 ui::GestureEvent* event) { 137 ui::GestureEvent* event) {
138 shelf_->UpdateAutoHideForGestureEvent(event); 138 shelf_->UpdateAutoHideForGestureEvent(event);
139 } 139 }
140 140
141 // ShelfLayoutManager:UpdateShelfObserver -------------------------------------- 141 // ShelfLayoutManager:UpdateShelfObserver --------------------------------------
142 142
143 // UpdateShelfObserver is used to delay updating the background until the 143 // UpdateShelfObserver is used to delay updating the background until the
144 // animation completes. 144 // animation completes.
145 class ShelfLayoutManager::UpdateShelfObserver 145 class ShelfLayoutManager::UpdateShelfObserver
146 : public ui::ImplicitAnimationObserver { 146 : public ui::ImplicitAnimationObserver {
147 public: 147 public:
148 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) { 148 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) {
149 shelf_->update_shelf_observer_ = this; 149 shelf_->update_shelf_observer_ = this;
150 } 150 }
151 151
152 void Detach() { 152 void Detach() { shelf_ = NULL; }
153 shelf_ = NULL;
154 }
155 153
156 void OnImplicitAnimationsCompleted() override { 154 void OnImplicitAnimationsCompleted() override {
157 if (shelf_) 155 if (shelf_)
158 shelf_->UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); 156 shelf_->UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE);
159 delete this; 157 delete this;
160 } 158 }
161 159
162 private: 160 private:
163 ~UpdateShelfObserver() override { 161 ~UpdateShelfObserver() override {
164 if (shelf_) 162 if (shelf_)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 228 }
231 229
232 ShelfLayoutManager::~ShelfLayoutManager() { 230 ShelfLayoutManager::~ShelfLayoutManager() {
233 if (update_shelf_observer_) 231 if (update_shelf_observer_)
234 update_shelf_observer_->Detach(); 232 update_shelf_observer_->Detach();
235 233
236 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 234 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
237 WillDeleteShelfLayoutManager()); 235 WillDeleteShelfLayoutManager());
238 WmShell::Get()->RemoveShellObserver(this); 236 WmShell::Get()->RemoveShellObserver(this);
239 Shell::GetInstance()->lock_state_controller()->RemoveObserver(this); 237 Shell::GetInstance()->lock_state_controller()->RemoveObserver(this);
240 Shell::GetInstance()-> 238 Shell::GetInstance()->session_state_delegate()->RemoveSessionStateObserver(
241 session_state_delegate()->RemoveSessionStateObserver(this); 239 this);
242 if (root_window_controller_observer_) { 240 if (root_window_controller_observer_) {
243 WmWindowAura::Get(root_window_) 241 WmWindowAura::Get(root_window_)
244 ->GetRootWindowController() 242 ->GetRootWindowController()
245 ->RemoveObserver(root_window_controller_observer_.get()); 243 ->RemoveObserver(root_window_controller_observer_.get());
246 } 244 }
247 } 245 }
248 246
249 void ShelfLayoutManager::PrepareForShutdown() { 247 void ShelfLayoutManager::PrepareForShutdown() {
250 in_shutdown_ = true; 248 in_shutdown_ = true;
251 // Clear all event filters, otherwise sometimes those filters may catch 249 // Clear all event filters, otherwise sometimes those filters may catch
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 SetState(SHELF_VISIBLE); 314 SetState(SHELF_VISIBLE);
317 } else if (WmShell::Get()->IsPinned()) { 315 } else if (WmShell::Get()->IsPinned()) {
318 SetState(SHELF_HIDDEN); 316 SetState(SHELF_HIDDEN);
319 } else { 317 } else {
320 // TODO(zelidrag): Verify shelf drag animation still shows on the device 318 // TODO(zelidrag): Verify shelf drag animation still shows on the device
321 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. 319 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN.
322 wm::WorkspaceWindowState window_state( 320 wm::WorkspaceWindowState window_state(
323 workspace_controller_->GetWindowState()); 321 workspace_controller_->GetWindowState());
324 switch (window_state) { 322 switch (window_state) {
325 case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: { 323 case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: {
326 const aura::Window* fullscreen_window = GetRootWindowController( 324 const aura::Window* fullscreen_window =
327 root_window_)->GetWindowForFullscreenMode(); 325 GetRootWindowController(root_window_)->GetWindowForFullscreenMode();
328 if (fullscreen_window && wm::GetWindowState(fullscreen_window)-> 326 if (fullscreen_window &&
329 hide_shelf_when_fullscreen()) { 327 wm::GetWindowState(fullscreen_window)
328 ->hide_shelf_when_fullscreen()) {
330 SetState(SHELF_HIDDEN); 329 SetState(SHELF_HIDDEN);
331 } else { 330 } else {
332 // The shelf is sometimes not hidden when in immersive fullscreen. 331 // The shelf is sometimes not hidden when in immersive fullscreen.
333 // Force the shelf to be auto hidden in this case. 332 // Force the shelf to be auto hidden in this case.
334 SetState(SHELF_AUTO_HIDE); 333 SetState(SHELF_AUTO_HIDE);
335 } 334 }
336 break; 335 break;
337 } 336 }
338 337
339 case wm::WORKSPACE_WINDOW_STATE_MAXIMIZED: 338 case wm::WORKSPACE_WINDOW_STATE_MAXIMIZED:
(...skipping 17 matching lines...) Expand all
357 if (auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { 356 if (auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) {
358 // Hides happen immediately. 357 // Hides happen immediately.
359 SetState(state_.visibility_state); 358 SetState(state_.visibility_state);
360 } else { 359 } else {
361 if (!auto_hide_timer_.IsRunning()) { 360 if (!auto_hide_timer_.IsRunning()) {
362 mouse_over_shelf_when_auto_hide_timer_started_ = 361 mouse_over_shelf_when_auto_hide_timer_started_ =
363 shelf_widget_->GetWindowBoundsInScreen().Contains( 362 shelf_widget_->GetWindowBoundsInScreen().Contains(
364 display::Screen::GetScreen()->GetCursorScreenPoint()); 363 display::Screen::GetScreen()->GetCursorScreenPoint());
365 } 364 }
366 auto_hide_timer_.Start( 365 auto_hide_timer_.Start(
367 FROM_HERE, 366 FROM_HERE, base::TimeDelta::FromMilliseconds(kAutoHideDelayMS), this,
368 base::TimeDelta::FromMilliseconds(kAutoHideDelayMS), 367 &ShelfLayoutManager::UpdateAutoHideStateNow);
369 this, &ShelfLayoutManager::UpdateAutoHideStateNow);
370 } 368 }
371 } else { 369 } else {
372 StopAutoHideTimer(); 370 StopAutoHideTimer();
373 } 371 }
374 } 372 }
375 373
376 void ShelfLayoutManager::UpdateAutoHideForMouseEvent(ui::MouseEvent* event) { 374 void ShelfLayoutManager::UpdateAutoHideForMouseEvent(ui::MouseEvent* event) {
377 // Don't update during shutdown because synthetic mouse events (e.g. mouse 375 // Don't update during shutdown because synthetic mouse events (e.g. mouse
378 // exit) may be generated during status area widget teardown. 376 // exit) may be generated during status area widget teardown.
379 if (visibility_state() != SHELF_AUTO_HIDE || in_shutdown_) 377 if (visibility_state() != SHELF_AUTO_HIDE || in_shutdown_)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 gesture_drag_auto_hide_state_ = SHELF_AUTO_HIDE_SHOWN; 417 gesture_drag_auto_hide_state_ = SHELF_AUTO_HIDE_SHOWN;
420 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; 418 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS;
421 UpdateVisibilityState(); 419 UpdateVisibilityState();
422 gesture_drag_status_ = GESTURE_DRAG_NONE; 420 gesture_drag_status_ = GESTURE_DRAG_NONE;
423 } 421 }
424 } 422 }
425 423
426 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { 424 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) {
427 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; 425 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS;
428 gesture_drag_amount_ = 0.f; 426 gesture_drag_amount_ = 0.f;
429 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE ? 427 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE
430 auto_hide_state() : SHELF_AUTO_HIDE_SHOWN; 428 ? auto_hide_state()
429 : SHELF_AUTO_HIDE_SHOWN;
431 UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); 430 UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE);
432 } 431 }
433 432
434 void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) { 433 void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) {
435 gesture_drag_amount_ += PrimaryAxisValue(gesture.details().scroll_y(), 434 gesture_drag_amount_ += PrimaryAxisValue(gesture.details().scroll_y(),
436 gesture.details().scroll_x()); 435 gesture.details().scroll_x());
437 LayoutShelf(); 436 LayoutShelf();
438 } 437 }
439 438
440 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { 439 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) {
(...skipping 18 matching lines...) Expand all
459 correct_direction = gesture_drag_amount_ < 0; 458 correct_direction = gesture_drag_amount_ < 0;
460 break; 459 break;
461 case SHELF_ALIGNMENT_LEFT: 460 case SHELF_ALIGNMENT_LEFT:
462 correct_direction = gesture_drag_amount_ > 0; 461 correct_direction = gesture_drag_amount_ > 0;
463 break; 462 break;
464 } 463 }
465 should_change = correct_direction && drag_ratio > kDragHideThreshold; 464 should_change = correct_direction && drag_ratio > kDragHideThreshold;
466 } 465 }
467 } else if (gesture.type() == ui::ET_SCROLL_FLING_START) { 466 } else if (gesture.type() == ui::ET_SCROLL_FLING_START) {
468 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { 467 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) {
469 should_change = horizontal ? fabs(gesture.details().velocity_y()) > 0 : 468 should_change = horizontal ? fabs(gesture.details().velocity_y()) > 0
470 fabs(gesture.details().velocity_x()) > 0; 469 : fabs(gesture.details().velocity_x()) > 0;
471 } else { 470 } else {
472 should_change = 471 should_change =
473 SelectValueForShelfAlignment(gesture.details().velocity_y() < 0, 472 SelectValueForShelfAlignment(gesture.details().velocity_y() < 0,
474 gesture.details().velocity_x() > 0, 473 gesture.details().velocity_x() > 0,
475 gesture.details().velocity_x() < 0); 474 gesture.details().velocity_x() < 0);
476 } 475 }
477 } else { 476 } else {
478 NOTREACHED(); 477 NOTREACHED();
479 } 478 }
480 479
481 if (!should_change) { 480 if (!should_change) {
482 CancelGestureDrag(); 481 CancelGestureDrag();
483 return; 482 return;
484 } 483 }
485 if (shelf_widget_) { 484 if (shelf_widget_) {
486 shelf_widget_->Deactivate(); 485 shelf_widget_->Deactivate();
487 shelf_widget_->status_area_widget()->Deactivate(); 486 shelf_widget_->status_area_widget()->Deactivate();
488 } 487 }
489 gesture_drag_auto_hide_state_ = 488 gesture_drag_auto_hide_state_ =
490 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN ? 489 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN
491 SHELF_AUTO_HIDE_HIDDEN : SHELF_AUTO_HIDE_SHOWN; 490 ? SHELF_AUTO_HIDE_HIDDEN
491 : SHELF_AUTO_HIDE_SHOWN;
492 ShelfAutoHideBehavior new_auto_hide_behavior = 492 ShelfAutoHideBehavior new_auto_hide_behavior =
493 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN ? 493 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN
494 SHELF_AUTO_HIDE_BEHAVIOR_NEVER : SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; 494 ? SHELF_AUTO_HIDE_BEHAVIOR_NEVER
495 : SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
495 496
496 // When in fullscreen and the shelf is forced to be auto hidden, the auto hide 497 // When in fullscreen and the shelf is forced to be auto hidden, the auto hide
497 // behavior affects neither the visibility state nor the auto hide state. Set 498 // behavior affects neither the visibility state nor the auto hide state. Set
498 // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto 499 // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto
499 // hide state to |gesture_drag_auto_hide_state_|. 500 // hide state to |gesture_drag_auto_hide_state_|.
500 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; 501 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS;
501 Shelf* shelf = shelf_widget_->shelf(); 502 Shelf* shelf = shelf_widget_->shelf();
502 if (shelf->auto_hide_behavior() != new_auto_hide_behavior) 503 if (shelf->auto_hide_behavior() != new_auto_hide_behavior)
503 shelf->SetAutoHideBehavior(new_auto_hide_behavior); 504 shelf->SetAutoHideBehavior(new_auto_hide_behavior);
504 else 505 else
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 } else { 657 } else {
657 UpdateShelfBackground(change_type); 658 UpdateShelfBackground(change_type);
658 } 659 }
659 660
660 shelf_widget_->SetDimsShelf(state.visibility_state == SHELF_VISIBLE && 661 shelf_widget_->SetDimsShelf(state.visibility_state == SHELF_VISIBLE &&
661 state.window_state == 662 state.window_state ==
662 wm::WORKSPACE_WINDOW_STATE_MAXIMIZED); 663 wm::WORKSPACE_WINDOW_STATE_MAXIMIZED);
663 664
664 TargetBounds target_bounds; 665 TargetBounds target_bounds;
665 CalculateTargetBounds(state_, &target_bounds); 666 CalculateTargetBounds(state_, &target_bounds);
666 UpdateBoundsAndOpacity(target_bounds, true, 667 UpdateBoundsAndOpacity(target_bounds, true, delay_background_change
667 delay_background_change ? update_shelf_observer_ : NULL); 668 ? update_shelf_observer_
669 : NULL);
668 670
669 // The delegate must be notified after |state_| is updated so that it can 671 // The delegate must be notified after |state_| is updated so that it can
670 // query the new target bounds. 672 // query the new target bounds.
671 ShelfDelegate* shelf_delegate = Shell::GetInstance()->GetShelfDelegate(); 673 ShelfDelegate* shelf_delegate = Shell::GetInstance()->GetShelfDelegate();
672 if (old_state.visibility_state != state_.visibility_state) 674 if (old_state.visibility_state != state_.visibility_state)
673 shelf_delegate->OnShelfVisibilityStateChanged(shelf_widget_->shelf()); 675 shelf_delegate->OnShelfVisibilityStateChanged(shelf_widget_->shelf());
674 676
675 // OnAutoHideStateChanged Should be emitted when: 677 // OnAutoHideStateChanged Should be emitted when:
676 // - firstly state changed to auto-hide from other state 678 // - firstly state changed to auto-hide from other state
677 // - or, auto_hide_state has changed 679 // - or, auto_hide_state has changed
(...skipping 10 matching lines...) Expand all
688 const TargetBounds& target_bounds, 690 const TargetBounds& target_bounds,
689 bool animate, 691 bool animate,
690 ui::ImplicitAnimationObserver* observer) { 692 ui::ImplicitAnimationObserver* observer) {
691 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); 693 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true);
692 { 694 {
693 ui::ScopedLayerAnimationSettings shelf_animation_setter( 695 ui::ScopedLayerAnimationSettings shelf_animation_setter(
694 GetLayer(shelf_widget_)->GetAnimator()); 696 GetLayer(shelf_widget_)->GetAnimator());
695 ui::ScopedLayerAnimationSettings status_animation_setter( 697 ui::ScopedLayerAnimationSettings status_animation_setter(
696 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()); 698 GetLayer(shelf_widget_->status_area_widget())->GetAnimator());
697 if (animate) { 699 if (animate) {
698 int duration = duration_override_in_ms_ ? duration_override_in_ms_ : 700 int duration = duration_override_in_ms_ ? duration_override_in_ms_
699 kCrossFadeDurationMS; 701 : kCrossFadeDurationMS;
700 shelf_animation_setter.SetTransitionDuration( 702 shelf_animation_setter.SetTransitionDuration(
701 base::TimeDelta::FromMilliseconds(duration)); 703 base::TimeDelta::FromMilliseconds(duration));
702 shelf_animation_setter.SetTweenType(gfx::Tween::EASE_OUT); 704 shelf_animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
703 shelf_animation_setter.SetPreemptionStrategy( 705 shelf_animation_setter.SetPreemptionStrategy(
704 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 706 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
705 status_animation_setter.SetTransitionDuration( 707 status_animation_setter.SetTransitionDuration(
706 base::TimeDelta::FromMilliseconds(duration)); 708 base::TimeDelta::FromMilliseconds(duration));
707 status_animation_setter.SetTweenType(gfx::Tween::EASE_OUT); 709 status_animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
708 status_animation_setter.SetPreemptionStrategy( 710 status_animation_setter.SetPreemptionStrategy(
709 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 711 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height); 809 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height);
808 810
809 gfx::Size status_size( 811 gfx::Size status_size(
810 shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size()); 812 shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size());
811 if (IsHorizontalAlignment()) 813 if (IsHorizontalAlignment())
812 status_size.set_height(GetShelfConstant(SHELF_SIZE)); 814 status_size.set_height(GetShelfConstant(SHELF_SIZE));
813 else 815 else
814 status_size.set_width(GetShelfConstant(SHELF_SIZE)); 816 status_size.set_width(GetShelfConstant(SHELF_SIZE));
815 817
816 gfx::Point status_origin = SelectValueForShelfAlignment( 818 gfx::Point status_origin = SelectValueForShelfAlignment(
817 gfx::Point(0, 0), 819 gfx::Point(0, 0), gfx::Point(shelf_width - status_size.width(),
818 gfx::Point(shelf_width - status_size.width(), 820 shelf_height - status_size.height()),
819 shelf_height - status_size.height()),
820 gfx::Point(0, shelf_height - status_size.height())); 821 gfx::Point(0, shelf_height - status_size.height()));
821 if (IsHorizontalAlignment() && !base::i18n::IsRTL()) 822 if (IsHorizontalAlignment() && !base::i18n::IsRTL())
822 status_origin.set_x(shelf_width - status_size.width()); 823 status_origin.set_x(shelf_width - status_size.width());
823 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size); 824 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size);
824 825
825 target_bounds->work_area_insets = SelectValueForShelfAlignment( 826 target_bounds->work_area_insets = SelectValueForShelfAlignment(
826 gfx::Insets(0, 0, GetWorkAreaInsets(state, shelf_height), 0), 827 gfx::Insets(0, 0, GetWorkAreaInsets(state, shelf_height), 0),
827 gfx::Insets(0, GetWorkAreaInsets(state, shelf_width), 0, 0), 828 gfx::Insets(0, GetWorkAreaInsets(state, shelf_width), 0, 0),
828 gfx::Insets(0, 0, 0, GetWorkAreaInsets(state, shelf_width))); 829 gfx::Insets(0, 0, 0, GetWorkAreaInsets(state, shelf_width)));
829 830
830 // TODO(varkha): The functionality of managing insets for display areas 831 // TODO(varkha): The functionality of managing insets for display areas
831 // should probably be pushed to a separate component. This would simplify or 832 // should probably be pushed to a separate component. This would simplify or
832 // remove entirely the dependency on keyboard and dock. 833 // remove entirely the dependency on keyboard and dock.
833 834
834 if (!keyboard_bounds_.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled()) { 835 if (!keyboard_bounds_.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled()) {
835 // Also push in the work area inset for the keyboard if it is visible. 836 // Also push in the work area inset for the keyboard if it is visible.
836 gfx::Insets keyboard_insets(0, 0, keyboard_bounds_.height(), 0); 837 gfx::Insets keyboard_insets(0, 0, keyboard_bounds_.height(), 0);
837 target_bounds->work_area_insets += keyboard_insets; 838 target_bounds->work_area_insets += keyboard_insets;
838 } 839 }
839 840
840 // Also push in the work area inset for the dock if it is visible. 841 // Also push in the work area inset for the dock if it is visible.
841 if (!dock_bounds_.IsEmpty()) { 842 if (!dock_bounds_.IsEmpty()) {
842 gfx::Insets dock_insets( 843 gfx::Insets dock_insets(
843 0, (dock_bounds_.x() > 0 ? 0 : dock_bounds_.width()), 844 0, (dock_bounds_.x() > 0 ? 0 : dock_bounds_.width()), 0,
844 0, (dock_bounds_.x() > 0 ? dock_bounds_.width() : 0)); 845 (dock_bounds_.x() > 0 ? dock_bounds_.width() : 0));
845 target_bounds->work_area_insets += dock_insets; 846 target_bounds->work_area_insets += dock_insets;
846 } 847 }
847 848
848 // Also push in the work area insets for the ChromeVox panel if it's visible. 849 // Also push in the work area insets for the ChromeVox panel if it's visible.
849 if (chromevox_panel_height_) { 850 if (chromevox_panel_height_) {
850 gfx::Insets chromevox_insets(chromevox_panel_height_, 0, 0, 0); 851 gfx::Insets chromevox_insets(chromevox_panel_height_, 0, 0, 0);
851 target_bounds->work_area_insets += chromevox_insets; 852 target_bounds->work_area_insets += chromevox_insets;
852 } 853 }
853 854
854 target_bounds->opacity = ComputeTargetOpacity(state); 855 target_bounds->opacity = ComputeTargetOpacity(state);
855 target_bounds->status_opacity = 856 target_bounds->status_opacity =
856 (state.visibility_state == SHELF_AUTO_HIDE && 857 (state.visibility_state == SHELF_AUTO_HIDE &&
857 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && 858 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN &&
858 gesture_drag_status_ != GESTURE_DRAG_IN_PROGRESS) ? 859 gesture_drag_status_ != GESTURE_DRAG_IN_PROGRESS)
859 0.0f : target_bounds->opacity; 860 ? 0.0f
861 : target_bounds->opacity;
860 862
861 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS) 863 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS)
862 UpdateTargetBoundsForGesture(target_bounds); 864 UpdateTargetBoundsForGesture(target_bounds);
863 865
864 // This needs to happen after calling UpdateTargetBoundsForGesture(), because 866 // This needs to happen after calling UpdateTargetBoundsForGesture(), because
865 // that can change the size of the shelf. 867 // that can change the size of the shelf.
866 target_bounds->shelf_bounds_in_shelf = SelectValueForShelfAlignment( 868 target_bounds->shelf_bounds_in_shelf = SelectValueForShelfAlignment(
867 gfx::Rect(0, 0, shelf_width - status_size.width(), 869 gfx::Rect(0, 0, shelf_width - status_size.width(),
868 target_bounds->shelf_bounds_in_root.height()), 870 target_bounds->shelf_bounds_in_root.height()),
869 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(), 871 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(),
(...skipping 19 matching lines...) Expand all
889 visibility_state() == SHELF_AUTO_HIDE && 891 visibility_state() == SHELF_AUTO_HIDE &&
890 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { 892 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) {
891 // If the shelf was hidden when the drag started (and the state hasn't 893 // If the shelf was hidden when the drag started (and the state hasn't
892 // changed since then, e.g. because the tray-menu was shown because of the 894 // changed since then, e.g. because the tray-menu was shown because of the
893 // drag), then allow the drag some resistance-free region at first to make 895 // drag), then allow the drag some resistance-free region at first to make
894 // sure the shelf sticks with the finger until the shelf is visible. 896 // sure the shelf sticks with the finger until the shelf is visible.
895 resistance_free_region = GetShelfConstant(SHELF_SIZE) - kShelfAutoHideSize; 897 resistance_free_region = GetShelfConstant(SHELF_SIZE) - kShelfAutoHideSize;
896 } 898 }
897 899
898 bool resist = SelectValueForShelfAlignment( 900 bool resist = SelectValueForShelfAlignment(
899 gesture_drag_amount_ < -resistance_free_region, 901 gesture_drag_amount_<-resistance_free_region, gesture_drag_amount_>
900 gesture_drag_amount_ > resistance_free_region, 902 resistance_free_region,
901 gesture_drag_amount_ < -resistance_free_region); 903 gesture_drag_amount_ < -resistance_free_region);
902 904
903 float translate = 0.f; 905 float translate = 0.f;
904 if (resist) { 906 if (resist) {
905 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; 907 float diff = fabsf(gesture_drag_amount_) - resistance_free_region;
906 diff = std::min(diff, sqrtf(diff)); 908 diff = std::min(diff, sqrtf(diff));
907 if (gesture_drag_amount_ < 0) 909 if (gesture_drag_amount_ < 0)
908 translate = -resistance_free_region - diff; 910 translate = -resistance_free_region - diff;
909 else 911 else
910 translate = resistance_free_region + diff; 912 translate = resistance_free_region + diff;
911 } else { 913 } else {
912 translate = gesture_drag_amount_; 914 translate = gesture_drag_amount_;
913 } 915 }
914 int shelf_insets = GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); 916 int shelf_insets = GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE);
915 if (horizontal) { 917 if (horizontal) {
916 // Move and size the shelf with the gesture. 918 // Move and size the shelf with the gesture.
917 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; 919 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate;
918 shelf_height = std::max(shelf_height, shelf_insets); 920 shelf_height = std::max(shelf_height, shelf_insets);
919 target_bounds->shelf_bounds_in_root.set_height(shelf_height); 921 target_bounds->shelf_bounds_in_root.set_height(shelf_height);
920 if (IsHorizontalAlignment()) { 922 if (IsHorizontalAlignment()) {
921 target_bounds->shelf_bounds_in_root.set_y( 923 target_bounds->shelf_bounds_in_root.set_y(available_bounds.bottom() -
922 available_bounds.bottom() - shelf_height); 924 shelf_height);
923 } 925 }
924 926
925 target_bounds->status_bounds_in_shelf.set_y(0); 927 target_bounds->status_bounds_in_shelf.set_y(0);
926 } else { 928 } else {
927 // Move and size the shelf with the gesture. 929 // Move and size the shelf with the gesture.
928 int shelf_width = target_bounds->shelf_bounds_in_root.width(); 930 int shelf_width = target_bounds->shelf_bounds_in_root.width();
929 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; 931 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT;
930 if (right_aligned) 932 if (right_aligned)
931 shelf_width -= translate; 933 shelf_width -= translate;
932 else 934 else
933 shelf_width += translate; 935 shelf_width += translate;
934 shelf_width = std::max(shelf_width, shelf_insets); 936 shelf_width = std::max(shelf_width, shelf_insets);
935 target_bounds->shelf_bounds_in_root.set_width(shelf_width); 937 target_bounds->shelf_bounds_in_root.set_width(shelf_width);
936 if (right_aligned) { 938 if (right_aligned) {
937 target_bounds->shelf_bounds_in_root.set_x( 939 target_bounds->shelf_bounds_in_root.set_x(available_bounds.right() -
938 available_bounds.right() - shelf_width); 940 shelf_width);
939 } 941 }
940 942
941 if (right_aligned) { 943 if (right_aligned) {
942 target_bounds->status_bounds_in_shelf.set_x(0); 944 target_bounds->status_bounds_in_shelf.set_x(0);
943 } else { 945 } else {
944 target_bounds->status_bounds_in_shelf.set_x( 946 target_bounds->status_bounds_in_shelf.set_x(
945 target_bounds->shelf_bounds_in_root.width() - 947 target_bounds->shelf_bounds_in_root.width() -
946 GetShelfConstant(SHELF_SIZE)); 948 GetShelfConstant(SHELF_SIZE));
947 } 949 }
948 } 950 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 if (ash::MaterialDesignController::IsShelfMaterial()) { 1207 if (ash::MaterialDesignController::IsShelfMaterial()) {
1206 return (state.visibility_state == SHELF_AUTO_HIDE && 1208 return (state.visibility_state == SHELF_AUTO_HIDE &&
1207 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN) 1209 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)
1208 ? 1.0f 1210 ? 1.0f
1209 : 0.0f; 1211 : 0.0f;
1210 } 1212 }
1211 return (state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; 1213 return (state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f;
1212 } 1214 }
1213 1215
1214 } // namespace ash 1216 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_layout_manager.h ('k') | ash/shelf/shelf_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698