Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ash / wm / gestures / shelf_gesture_handler.cc
bloba4e8737468c556e7a6128b384807c0545418353e
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.
5 #include "ash/wm/gestures/shelf_gesture_handler.h"
7 #include "ash/root_window_controller.h"
8 #include "ash/shelf/shelf_layout_manager.h"
9 #include "ash/shelf/shelf_types.h"
10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h"
12 #include "ash/shell_delegate.h"
13 #include "ash/system/status_area_widget.h"
14 #include "ash/wm/gestures/tray_gesture_handler.h"
15 #include "ash/wm/window_util.h"
16 #include "ui/aura/window.h"
17 #include "ui/compositor/layer.h"
18 #include "ui/compositor/scoped_layer_animation_settings.h"
19 #include "ui/gfx/transform.h"
20 #include "ui/views/widget/widget.h"
22 namespace ash {
23 namespace internal {
25 ShelfGestureHandler::ShelfGestureHandler()
26 : drag_in_progress_(false) {
29 ShelfGestureHandler::~ShelfGestureHandler() {
32 bool ShelfGestureHandler::ProcessGestureEvent(const ui::GestureEvent& event) {
33 Shell* shell = Shell::GetInstance();
34 if (!shell->delegate()->IsUserLoggedIn() ||
35 shell->delegate()->IsScreenLocked()) {
36 // The gestures are disabled in the lock/login screen.
37 return false;
40 // The gesture are disabled for fullscreen windows.
41 aura::Window* active = wm::GetActiveWindow();
42 if (active && wm::IsWindowFullscreen(active))
43 return false;
45 // TODO(oshima): Find the root window controller from event's location.
46 ShelfLayoutManager* shelf =
47 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
48 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) {
49 drag_in_progress_ = true;
50 shelf->StartGestureDrag(event);
51 return true;
54 if (!drag_in_progress_)
55 return false;
57 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) {
58 if (tray_handler_.get()) {
59 if (!tray_handler_->UpdateGestureDrag(event))
60 tray_handler_.reset();
61 } else if (shelf->UpdateGestureDrag(event) ==
62 ShelfLayoutManager::DRAG_TRAY) {
63 tray_handler_.reset(new TrayGestureHandler());
66 return true;
69 drag_in_progress_ = false;
71 if (event.type() == ui::ET_GESTURE_SCROLL_END ||
72 event.type() == ui::ET_SCROLL_FLING_START) {
73 if (tray_handler_.get()) {
74 tray_handler_->CompleteGestureDrag(event);
75 tray_handler_.reset();
78 shelf->CompleteGestureDrag(event);
79 return true;
82 // Unexpected event. Reset the state and let the event fall through.
83 shelf->CancelGestureDrag();
84 return false;
87 } // namespace internal
88 } // namespace ash