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

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
« no previous file with comments | « ash/wm/workspace/workspace_cycler.h ('k') | ash/wm/workspace/workspace_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..9bdc388ccf1775e944597aa5163cd60a5e8db6c0
--- /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 ?
+ WorkspaceManager::CYCLE_NEXT : WorkspaceManager::CYCLE_PREVIOUS);
+
+ scroll_x_ = 0;
+ scroll_y_ = 0;
sky 2012/11/29 23:09:51 Lets say I've scrolled by 100. If you set scroll_y
pkotwicz 2012/11/30 01:19:45 As far as I understand it, event->x_offset() is a
+ return ui::ER_HANDLED;
+ }
+
+ if (std::abs(scroll_y_) > kWorkspaceStepSize) {
sky 2012/11/29 23:09:51 You should never get here, right?
pkotwicz 2012/11/30 01:19:45 This should be scroll_x_, fixed!
+ // 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 drag.
+ 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
« no previous file with comments | « ash/wm/workspace/workspace_cycler.h ('k') | ash/wm/workspace/workspace_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698