Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/wm/workspace/workspace_cycler.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/wm/workspace/workspace_manager.h" | |
| 9 #include "ui/base/events/event.h" | |
| 10 #include "ui/base/events/event_utils.h" | |
| 11 | |
| 12 namespace ash { | |
| 13 namespace internal { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 // The required vertical distance to scrub to the next workspace. | |
| 18 const int kWorkspaceStepSize = 10; | |
| 19 | |
| 20 // Returns true is scrubbing is enabled. | |
| 21 bool IsScrubbingEnabled() { | |
| 22 // Scrubbing is disabled if the screen is locked or a modal dialog is open. | |
| 23 return !Shell::GetInstance()->IsScreenLocked() && | |
| 24 !Shell::GetInstance()->IsSystemModalWindowOpen(); | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 WorkspaceCycler::WorkspaceCycler(WorkspaceManager* workspace_manager) | |
| 30 : workspace_manager_(workspace_manager), | |
| 31 scrubbing_(false), | |
| 32 scroll_x_(0), | |
| 33 scroll_y_(0) { | |
| 34 ash::Shell::GetInstance()->AddPreTargetHandler(this); | |
| 35 } | |
| 36 | |
| 37 WorkspaceCycler::~WorkspaceCycler() { | |
| 38 scrubbing_ = false; | |
| 39 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | |
| 40 } | |
| 41 | |
| 42 ui::EventResult WorkspaceCycler::OnScrollEvent(ui::ScrollEvent* event) { | |
| 43 if (event->finger_count() != 3 || | |
| 44 event->type() != ui::ET_SCROLL) { | |
| 45 scrubbing_ = false; | |
| 46 return ui::ER_UNHANDLED; | |
| 47 } | |
| 48 | |
| 49 if (!IsScrubbingEnabled()) { | |
| 50 scrubbing_ = false; | |
| 51 return ui::ER_UNHANDLED; | |
| 52 } | |
| 53 | |
| 54 if (!scrubbing_) { | |
| 55 scrubbing_ = true; | |
| 56 scroll_x_ = 0; | |
| 57 scroll_y_ = 0; | |
| 58 } | |
| 59 | |
| 60 if (ui::IsNaturalScrollEnabled()) { | |
| 61 scroll_x_ += event->x_offset(); | |
| 62 scroll_y_ += event->y_offset(); | |
| 63 } else { | |
| 64 scroll_x_ -= event->x_offset(); | |
| 65 scroll_y_ -= event->y_offset(); | |
| 66 } | |
| 67 | |
| 68 if (std::abs(scroll_y_) > kWorkspaceStepSize) { | |
| 69 workspace_manager_->CycleToWorkspace(scroll_y_ > 0 ? | |
|
sky
2012/11/30 01:39:45
You sure you don't want the logic I outlined in th
pkotwicz
2012/11/30 02:12:48
I am unsure if I completely understand your commen
| |
| 70 WorkspaceManager::CYCLE_NEXT : WorkspaceManager::CYCLE_PREVIOUS); | |
| 71 | |
| 72 scroll_x_ = 0; | |
| 73 scroll_y_ = 0; | |
| 74 return ui::ER_HANDLED; | |
| 75 } | |
| 76 | |
| 77 if (std::abs(scroll_x_) > kWorkspaceStepSize) { | |
| 78 // Update |scroll_x_| and |scroll_y_| such that workspaces are only cycled | |
| 79 // through when there recently was a significant amount of vertical movement | |
| 80 // as opposed to vertical movement accumulated over a long horizontal three | |
| 81 // finger scroll. | |
| 82 scroll_x_ = 0; | |
| 83 scroll_y_ = 0; | |
| 84 } | |
| 85 | |
| 86 // The active workspace was not changed, do not consume the event. | |
| 87 return ui::ER_UNHANDLED; | |
| 88 } | |
| 89 | |
| 90 } // namespace internal | |
| 91 } // namespace ash | |
| OLD | NEW |