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

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..d8e2bc62af1d99eda9c96904e2032cb23c4a5f15
--- /dev/null
+++ b/ash/wm/workspace/workspace_cycler.cc
@@ -0,0 +1,137 @@
+// 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/aura/window.h"
+#include "ui/base/events/event.h"
+
+namespace ash {
+namespace internal {
+
+namespace {
+
+// The required vertical distance to scrub to the next workspace.
+const int kWorkspaceStepSize = 50;
+
+// The maximum horizontal movement in between switching between two workspaces
+// before the workspace scrubbing session is cancelled.
+const int kMaxHorizontalMovementPerWorkspaceStep = 50;
+
+// 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),
+ scrub_state_(NOT_SCRUBBING),
+ initial_workspace_window_(NULL) {
+ ash::Shell::GetInstance()->AddPreTargetHandler(this);
+}
+
+WorkspaceCycler::~WorkspaceCycler() {
sadrul 2012/11/26 16:55:50 RemovePreTargetHandler here
+}
+
+void WorkspaceCycler::StartScrubbing() {
+ scrub_state_ = SCRUBBING;
+ initial_workspace_window_ = workspace_manager_->GetActiveWorkspaceWindow();
+ DCHECK(initial_workspace_window_->IsVisible());
+ initial_workspace_window_->AddObserver(this);
+}
+
+void WorkspaceCycler::StopScrubbing() {
+ if (initial_workspace_window_)
+ initial_workspace_window_->RemoveObserver(this);
+ initial_workspace_window_ = NULL;
+
+ scrub_state_ = NOT_SCRUBBING;
+}
+
+void WorkspaceCycler::OnWindowDestroyed(aura::Window* window) {
+ DCHECK_EQ(window, initial_workspace_window_);
+ window->RemoveObserver(this);
+
+ // |initial_workspace_window_| may be destroyed while scrubbing is active
+ // if the user closes or unmaximizes windows via the keyboard in the
+ // workspace corresponding to |initial_workspace_window_|.
+ initial_workspace_window_ = NULL;
+ scrub_state_ = CANCELLED_SCRUBBING;
+}
+
+ui::EventResult WorkspaceCycler::OnKeyEvent(ui::KeyEvent* event) {
+ return ui::ER_UNHANDLED;
+}
+
+ui::EventResult WorkspaceCycler::OnMouseEvent(ui::MouseEvent* event) {
+ if (!IsScrubbingEnabled())
+ return ui::ER_UNHANDLED;
+
+ if (!(event->type() == ui::ET_MOUSE_PRESSED ||
+ event->type() == ui::ET_MOUSE_DRAGGED ||
+ event->type() == ui::ET_MOUSE_RELEASED)) {
+ return ui::ER_UNHANDLED;
+ }
+
+ if (event->type() == ui::ET_MOUSE_RELEASED ||
+ !(event->flags() & ui::EF_CONTROL_DOWN) ||
+ !(event->flags() & ui::EF_LEFT_MOUSE_BUTTON)) {
+ StopScrubbing();
+ return ui::ER_UNHANDLED;
+ }
+
+ if (scrub_state_ == CANCELLED_SCRUBBING)
+ return ui::ER_UNHANDLED;
+
+ if (scrub_state_ == NOT_SCRUBBING) {
+ StartScrubbing();
+ last_transition_position_ = event->root_location();
+ return ui::ER_HANDLED;
+ }
+
+ gfx::Point event_location = event->root_location();
+ int delta_x = event_location.x() - last_transition_position_.x();
+ int delta_y = event_location.y() - last_transition_position_.y();
+ if (std::abs(delta_x) > kMaxHorizontalMovementPerWorkspaceStep) {
+ scrub_state_ = CANCELLED_SCRUBBING;
+ return ui::ER_UNHANDLED;
+ }
+
+ if (std::abs(delta_y) > kWorkspaceStepSize) {
+ if (delta_y > 0) {
+ workspace_manager_->CycleToNextUnhiddenWorkspace();
+ } else {
+ // If the initial workspace is visible, then cycling to hidden workspaces
+ // should be disabled as not to scrub to workspaces which were minimized
+ // before scrubbing was initiated.
+ if (!initial_workspace_window_->IsVisible())
+ workspace_manager_->CycleToNextHiddenWorkspace();
+ }
+
+ last_transition_position_ = event_location;
+ }
+
+ return ui::ER_HANDLED;
+}
+
+ui::EventResult WorkspaceCycler::OnScrollEvent(ui::ScrollEvent* event) {
sadrul 2012/11/26 16:55:50 You don't need to override these since you aren't
+ return ui::ER_UNHANDLED;
+}
+
+ui::EventResult WorkspaceCycler::OnTouchEvent(ui::TouchEvent* event) {
+ return ui::ER_UNHANDLED;
+}
+
+ui::EventResult WorkspaceCycler::OnGestureEvent(ui::GestureEvent* 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