Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ash / wm / gestures / shelf_gesture_handler.cc
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/gestures/shelf_gesture_handler.h"
6
7 #include "ash/root_window_controller.h"
8 #include "ash/session_state_delegate.h"
9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_types.h"
11 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h"
13 #include "ash/system/status_area_widget.h"
14 #include "ash/wm/gestures/tray_gesture_handler.h"
15 #include "ash/wm/window_state.h"
16 #include "ash/wm/window_util.h"
17 #include "ui/aura/window.h"
18 #include "ui/compositor/layer.h"
19 #include "ui/compositor/scoped_layer_animation_settings.h"
20 #include "ui/gfx/transform.h"
21 #include "ui/views/widget/widget.h"
22
23 namespace ash {
24 namespace internal {
25
26 ShelfGestureHandler::ShelfGestureHandler()
27     : drag_in_progress_(false) {
28 }
29
30 ShelfGestureHandler::~ShelfGestureHandler() {
31 }
32
33 bool ShelfGestureHandler::ProcessGestureEvent(const ui::GestureEvent& event) {
34   Shell* shell = Shell::GetInstance();
35   if (!shell->session_state_delegate()->NumberOfLoggedInUsers() ||
36       shell->session_state_delegate()->IsScreenLocked()) {
37     // The gestures are disabled in the lock/login screen.
38     return false;
39   }
40
41   // TODO(oshima): Find the root window controller from event's location.
42   RootWindowController* controller = Shell::GetPrimaryRootWindowController();
43
44   ShelfLayoutManager* shelf = controller->GetShelfLayoutManager();
45
46   if (event.type() == ui::ET_GESTURE_WIN8_EDGE_SWIPE) {
47     shelf->OnGestureEdgeSwipe(event);
48     return true;
49   }
50
51   const aura::Window* fullscreen = controller->GetWindowForFullscreenMode();
52   if (fullscreen &&
53       ash::wm::GetWindowState(fullscreen)->hide_shelf_when_fullscreen()) {
54     return false;
55   }
56
57   if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) {
58     drag_in_progress_ = true;
59     shelf->StartGestureDrag(event);
60     return true;
61   }
62
63   if (!drag_in_progress_)
64     return false;
65
66   if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) {
67     if (tray_handler_) {
68       if (!tray_handler_->UpdateGestureDrag(event))
69         tray_handler_.reset();
70     } else if (shelf->UpdateGestureDrag(event) ==
71         ShelfLayoutManager::DRAG_TRAY) {
72       tray_handler_.reset(new TrayGestureHandler());
73     }
74
75     return true;
76   }
77
78   drag_in_progress_ = false;
79
80   if (event.type() == ui::ET_GESTURE_SCROLL_END ||
81       event.type() == ui::ET_SCROLL_FLING_START) {
82     if (tray_handler_) {
83       tray_handler_->CompleteGestureDrag(event);
84       tray_handler_.reset();
85     }
86
87     shelf->CompleteGestureDrag(event);
88     return true;
89   }
90
91   // Unexpected event. Reset the state and let the event fall through.
92   shelf->CancelGestureDrag();
93   return false;
94 }
95
96 }  // namespace internal
97 }  // namespace ash