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

Unified Diff: ash/wm/workspace/workspace_cycler.cc

Issue 11417150: Implement workspace scrubbing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: ash/wm/workspace/workspace_cycler.cc
diff --git a/ash/wm/workspace/workspace_cycler.cc b/ash/wm/workspace/workspace_cycler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d16506c181d4540768ffd323e135558c96c15506
--- /dev/null
+++ b/ash/wm/workspace/workspace_cycler.cc
@@ -0,0 +1,91 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/wm/workspace/workspace_cycler.h"
+
+#include "ash/shell.h"
+#include "ash/wm/workspace/workspace_manager.h"
+#include "ui/base/events/event.h"
+#include "ui/base/events/event_utils.h"
+
+namespace ash {
+namespace internal {
+
+namespace {
+
+// The required vertical distance to scrub to the next workspace.
+const int kWorkspaceStepSize = 10;
+
+// Returns true is scrubbing is enabled.
+bool IsScrubbingEnabled() {
+ // Scrubbing is disabled if the screen is locked or a modal dialog is open.
+ return !Shell::GetInstance()->IsScreenLocked() &&
+ !Shell::GetInstance()->IsSystemModalWindowOpen();
+}
+
+} // namespace
+
+WorkspaceCycler::WorkspaceCycler(WorkspaceManager* workspace_manager)
+ : workspace_manager_(workspace_manager),
+ scrubbing_(false),
+ scroll_x_(0),
+ scroll_y_(0) {
+ ash::Shell::GetInstance()->AddPreTargetHandler(this);
+}
+
+WorkspaceCycler::~WorkspaceCycler() {
+ scrubbing_ = false;
+ ash::Shell::GetInstance()->RemovePreTargetHandler(this);
+}
+
+ui::EventResult WorkspaceCycler::OnScrollEvent(ui::ScrollEvent* event) {
+ if (event->finger_count() != 3 ||
+ event->type() != ui::ET_SCROLL) {
+ scrubbing_ = false;
+ return ui::ER_UNHANDLED;
+ }
+
+ if (!IsScrubbingEnabled()) {
+ scrubbing_ = false;
+ return ui::ER_UNHANDLED;
+ }
+
+ if (!scrubbing_) {
+ scrubbing_ = true;
+ scroll_x_ = 0;
+ scroll_y_ = 0;
+ }
+
+ if (ui::IsNaturalScrollEnabled()) {
+ scroll_x_ += event->x_offset();
+ scroll_y_ += event->y_offset();
+ } else {
+ scroll_x_ -= event->x_offset();
+ scroll_y_ -= event->y_offset();
+ }
+
+ if (std::abs(scroll_y_) > kWorkspaceStepSize) {
+ 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
+ WorkspaceManager::CYCLE_NEXT : WorkspaceManager::CYCLE_PREVIOUS);
+
+ scroll_x_ = 0;
+ scroll_y_ = 0;
+ return ui::ER_HANDLED;
+ }
+
+ if (std::abs(scroll_x_) > kWorkspaceStepSize) {
+ // Update |scroll_x_| and |scroll_y_| such that workspaces are only cycled
+ // through when there recently was a significant amount of vertical movement
+ // as opposed to vertical movement accumulated over a long horizontal three
+ // finger scroll.
+ scroll_x_ = 0;
+ scroll_y_ = 0;
+ }
+
+ // The active workspace was not changed, do not consume the event.
+ return ui::ER_UNHANDLED;
+}
+
+} // namespace internal
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698