| 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/workspace/workspace_cycler.h" | 5 #include "ash/wm/workspace/workspace_cycler.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/wm/workspace/workspace_cycler_configuration.h" |
| 10 #include "ash/wm/workspace/workspace_manager.h" | 11 #include "ash/wm/workspace/workspace_manager.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "ui/base/events/event.h" | 13 #include "ui/base/events/event.h" |
| 13 #include "ui/base/events/event_utils.h" | 14 #include "ui/base/events/event_utils.h" |
| 14 | 15 |
| 16 typedef ash::WorkspaceCyclerConfiguration Config; |
| 17 |
| 15 namespace ash { | 18 namespace ash { |
| 16 namespace internal { | 19 namespace internal { |
| 17 | 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 // The required vertical distance to initiate workspace cycling. | |
| 21 const float kDistanceToInitiateWorkspaceCycling = 10.0f; | |
| 22 | |
| 23 // Returns true if cycling is allowed. | 23 // Returns true if cycling is allowed. |
| 24 bool IsCyclingAllowed() { | 24 bool IsCyclingAllowed() { |
| 25 // Cycling is disabled if the screen is locked or a modal dialog is open. | 25 // Cycling is disabled if the screen is locked or a modal dialog is open. |
| 26 return !Shell::GetInstance()->IsScreenLocked() && | 26 return !Shell::GetInstance()->IsScreenLocked() && |
| 27 !Shell::GetInstance()->IsSystemModalWindowOpen(); | 27 !Shell::GetInstance()->IsSystemModalWindowOpen(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 WorkspaceCycler::WorkspaceCycler(WorkspaceManager* workspace_manager) | 32 WorkspaceCycler::WorkspaceCycler(WorkspaceManager* workspace_manager) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 void WorkspaceCycler::OnMouseEvent(ui::MouseEvent* event) { | 110 void WorkspaceCycler::OnMouseEvent(ui::MouseEvent* event) { |
| 111 if (event->type() == ui::ET_MOUSE_PRESSED && state_ != NOT_CYCLING) { | 111 if (event->type() == ui::ET_MOUSE_PRESSED && state_ != NOT_CYCLING) { |
| 112 SetState(STOPPING_CYCLING); | 112 SetState(STOPPING_CYCLING); |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 | 115 |
| 116 if (event->type() != ui::ET_MOUSEWHEEL) | 116 if (event->type() != ui::ET_MOUSEWHEEL) |
| 117 return; | 117 return; |
| 118 | 118 |
| 119 if (!IsCyclingAllowed() || !workspace_manager_->CanStartCyclingThroughWorkspac
es()) { | 119 if (!IsCyclingAllowed() || |
| 120 !workspace_manager_->CanStartCyclingThroughWorkspaces()) { |
| 120 CHECK_EQ(NOT_CYCLING, state_); | 121 CHECK_EQ(NOT_CYCLING, state_); |
| 121 return; | 122 return; |
| 122 } | 123 } |
| 123 | 124 |
| 124 float offset = static_cast<ui::MouseWheelEvent*>(event)->offset(); | 125 float offset = static_cast<ui::MouseWheelEvent*>(event)->offset(); |
| 125 | 126 |
| 126 if (offset != 0) { | 127 if (offset != 0) { |
| 127 if (state_ == NOT_CYCLING) { | 128 if (state_ == NOT_CYCLING) { |
| 128 SetState(NOT_CYCLING_TRACKING_SCROLL); | 129 SetState(NOT_CYCLING_TRACKING_SCROLL); |
| 129 SetState(STARTING_CYCLING); | 130 SetState(STARTING_CYCLING); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 164 |
| 164 if (ui::IsNaturalScrollEnabled()) { | 165 if (ui::IsNaturalScrollEnabled()) { |
| 165 scroll_x_ += event->x_offset(); | 166 scroll_x_ += event->x_offset(); |
| 166 scroll_y_ += event->y_offset(); | 167 scroll_y_ += event->y_offset(); |
| 167 } else { | 168 } else { |
| 168 scroll_x_ -= event->x_offset(); | 169 scroll_x_ -= event->x_offset(); |
| 169 scroll_y_ -= event->y_offset(); | 170 scroll_y_ -= event->y_offset(); |
| 170 } | 171 } |
| 171 | 172 |
| 172 if (state_ == NOT_CYCLING_TRACKING_SCROLL) { | 173 if (state_ == NOT_CYCLING_TRACKING_SCROLL) { |
| 173 if (fabs(scroll_x_) > kDistanceToInitiateWorkspaceCycling) { | 174 double distance_to_initiate_cycling = Config::GetDouble( |
| 175 Config::DISTANCE_TO_INITIATE_CYCLING); |
| 176 |
| 177 if (fabs(scroll_x_) > distance_to_initiate_cycling) { |
| 174 // Only initiate workspace cycling if there recently was a significant | 178 // Only initiate workspace cycling if there recently was a significant |
| 175 // amount of vertical movement as opposed to vertical movement | 179 // amount of vertical movement as opposed to vertical movement |
| 176 // accumulated over a long horizontal three finger scroll. | 180 // accumulated over a long horizontal three finger scroll. |
| 177 scroll_x_ = 0.0f; | 181 scroll_x_ = 0.0f; |
| 178 scroll_y_ = 0.0f; | 182 scroll_y_ = 0.0f; |
| 179 } | 183 } |
| 180 | 184 |
| 181 if (fabs(scroll_y_) >= kDistanceToInitiateWorkspaceCycling) | 185 if (fabs(scroll_y_) >= distance_to_initiate_cycling) |
| 182 SetState(STARTING_CYCLING); | 186 SetState(STARTING_CYCLING); |
| 183 } | 187 } |
| 184 | 188 |
| 185 if (state_ == CYCLING && event->y_offset() != 0.0f) { | 189 if (state_ == CYCLING && event->y_offset() != 0.0f) { |
| 186 DCHECK(animator_.get()); | 190 DCHECK(animator_.get()); |
| 187 animator_->AnimateCyclingByScrollDelta(event->y_offset()); | 191 animator_->AnimateCyclingByScrollDelta(event->y_offset()); |
| 188 event->SetHandled(); | 192 event->SetHandled(); |
| 189 } | 193 } |
| 190 } | 194 } |
| 191 | 195 |
| 192 void WorkspaceCycler::StartWorkspaceCyclerAnimationFinished() { | 196 void WorkspaceCycler::StartWorkspaceCyclerAnimationFinished() { |
| 193 DCHECK_EQ(STARTING_CYCLING, state_); | 197 DCHECK_EQ(STARTING_CYCLING, state_); |
| 194 SetState(CYCLING); | 198 SetState(CYCLING); |
| 195 } | 199 } |
| 196 | 200 |
| 197 void WorkspaceCycler::StopWorkspaceCyclerAnimationFinished() { | 201 void WorkspaceCycler::StopWorkspaceCyclerAnimationFinished() { |
| 198 DCHECK_EQ(STOPPING_CYCLING, state_); | 202 DCHECK_EQ(STOPPING_CYCLING, state_); |
| 199 Workspace* workspace_to_activate = animator_->get_selected_workspace(); | 203 Workspace* workspace_to_activate = animator_->get_selected_workspace(); |
| 200 animator_.reset(); | 204 animator_.reset(); |
| 201 SetState(NOT_CYCLING); | 205 SetState(NOT_CYCLING); |
| 202 | 206 |
| 203 // Activate the workspace after updating the state so that a call to | 207 // Activate the workspace after updating the state so that a call to |
| 204 // AbortCycling() as a result of SetActiveWorkspaceFromCycler() is a noop. | 208 // AbortCycling() as a result of SetActiveWorkspaceFromCycler() is a noop. |
| 205 workspace_manager_->SetActiveWorkspaceFromCycler(workspace_to_activate); | 209 workspace_manager_->SetActiveWorkspaceFromCycler(workspace_to_activate); |
| 206 } | 210 } |
| 207 | 211 |
| 208 } // namespace internal | 212 } // namespace internal |
| 209 } // namespace ash | 213 } // namespace ash |
| OLD | NEW |