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 "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/wm/workspace/workspace_manager.h" | 8 #include "ash/wm/workspace/workspace_manager.h" |
9 #include "ui/base/events/event.h" | 9 #include "ui/base/events/event.h" |
10 #include "ui/base/events/event_utils.h" | 10 #include "ui/base/events/event_utils.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 scroll_x_(0), | 32 scroll_x_(0), |
33 scroll_y_(0) { | 33 scroll_y_(0) { |
34 ash::Shell::GetInstance()->AddPreTargetHandler(this); | 34 ash::Shell::GetInstance()->AddPreTargetHandler(this); |
35 } | 35 } |
36 | 36 |
37 WorkspaceCycler::~WorkspaceCycler() { | 37 WorkspaceCycler::~WorkspaceCycler() { |
38 scrubbing_ = false; | 38 scrubbing_ = false; |
39 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | 39 ash::Shell::GetInstance()->RemovePreTargetHandler(this); |
40 } | 40 } |
41 | 41 |
42 ui::EventResult WorkspaceCycler::OnScrollEvent(ui::ScrollEvent* event) { | 42 void WorkspaceCycler::OnScrollEvent(ui::ScrollEvent* event) { |
43 if (event->finger_count() != 3 || | 43 if (event->finger_count() != 3 || |
44 event->type() != ui::ET_SCROLL) { | 44 event->type() != ui::ET_SCROLL) { |
45 scrubbing_ = false; | 45 scrubbing_ = false; |
46 return ui::ER_UNHANDLED; | 46 return; |
47 } | 47 } |
48 | 48 |
49 if (!IsScrubbingEnabled()) { | 49 if (!IsScrubbingEnabled()) { |
50 scrubbing_ = false; | 50 scrubbing_ = false; |
51 return ui::ER_UNHANDLED; | 51 return; |
52 } | 52 } |
53 | 53 |
54 if (!scrubbing_) { | 54 if (!scrubbing_) { |
55 scrubbing_ = true; | 55 scrubbing_ = true; |
56 scroll_x_ = 0; | 56 scroll_x_ = 0; |
57 scroll_y_ = 0; | 57 scroll_y_ = 0; |
58 } | 58 } |
59 | 59 |
60 if (ui::IsNaturalScrollEnabled()) { | 60 if (ui::IsNaturalScrollEnabled()) { |
61 scroll_x_ += event->x_offset(); | 61 scroll_x_ += event->x_offset(); |
62 scroll_y_ += event->y_offset(); | 62 scroll_y_ += event->y_offset(); |
63 } else { | 63 } else { |
64 scroll_x_ -= event->x_offset(); | 64 scroll_x_ -= event->x_offset(); |
65 scroll_y_ -= event->y_offset(); | 65 scroll_y_ -= event->y_offset(); |
66 } | 66 } |
67 | 67 |
68 // TODO(pkotwicz): Implement scrubbing through several workspaces as the | 68 // TODO(pkotwicz): Implement scrubbing through several workspaces as the |
69 // result of a single scroll event. | 69 // result of a single scroll event. |
70 if (std::abs(scroll_y_) > kWorkspaceStepSize) { | 70 if (std::abs(scroll_y_) > kWorkspaceStepSize) { |
71 workspace_manager_->CycleToWorkspace(scroll_y_ > 0 ? | 71 workspace_manager_->CycleToWorkspace(scroll_y_ > 0 ? |
72 WorkspaceManager::CYCLE_NEXT : WorkspaceManager::CYCLE_PREVIOUS); | 72 WorkspaceManager::CYCLE_NEXT : WorkspaceManager::CYCLE_PREVIOUS); |
73 | 73 |
74 scroll_x_ = 0; | 74 scroll_x_ = 0; |
75 scroll_y_ = 0; | 75 scroll_y_ = 0; |
76 return ui::ER_HANDLED; | 76 event->SetHandled(); |
| 77 return; |
77 } | 78 } |
78 | 79 |
79 if (std::abs(scroll_x_) > kWorkspaceStepSize) { | 80 if (std::abs(scroll_x_) > kWorkspaceStepSize) { |
80 // Update |scroll_x_| and |scroll_y_| such that workspaces are only cycled | 81 // Update |scroll_x_| and |scroll_y_| such that workspaces are only cycled |
81 // through when there recently was a significant amount of vertical movement | 82 // through when there recently was a significant amount of vertical movement |
82 // as opposed to vertical movement accumulated over a long horizontal three | 83 // as opposed to vertical movement accumulated over a long horizontal three |
83 // finger scroll. | 84 // finger scroll. |
84 scroll_x_ = 0; | 85 scroll_x_ = 0; |
85 scroll_y_ = 0; | 86 scroll_y_ = 0; |
86 } | 87 } |
87 | 88 |
88 // The active workspace was not changed, do not consume the event. | 89 // The active workspace was not changed, do not consume the event. |
89 return ui::ER_UNHANDLED; | |
90 } | 90 } |
91 | 91 |
92 } // namespace internal | 92 } // namespace internal |
93 } // namespace ash | 93 } // namespace ash |
OLD | NEW |