OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/gestures/shelf_gesture_handler.h" | 5 #include "ash/wm/gestures/shelf_gesture_handler.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
9 #include "ash/shelf/shelf_types.h" | 9 #include "ash/shelf/shelf_types.h" |
10 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/shell_delegate.h" | 12 #include "ash/shell_delegate.h" |
13 #include "ash/system/status_area_widget.h" | 13 #include "ash/system/status_area_widget.h" |
14 #include "ash/wm/gestures/tray_gesture_handler.h" | 14 #include "ash/wm/gestures/tray_gesture_handler.h" |
15 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
17 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
18 #include "ui/compositor/scoped_layer_animation_settings.h" | 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
19 #include "ui/gfx/transform.h" | 19 #include "ui/gfx/transform.h" |
20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
21 | 21 |
22 namespace { | |
23 | |
24 // A ShelfResetHandler auto-hides the shelf as soon as the user interacts with | |
25 // any non-shelf part of the system. The ShelfResetHandler manages its own | |
26 // lifetime. | |
27 class ShelfResetHandler : public ui::EventHandler, | |
28 public ash::internal::ShelfLayoutManager::Observer { | |
29 public: | |
30 explicit ShelfResetHandler(ash::internal::ShelfLayoutManager* shelf) | |
31 : shelf_(shelf) { | |
32 shelf_->AddObserver(this); | |
33 ash::Shell::GetInstance()->AddPreTargetHandler(this); | |
34 } | |
35 | |
36 private: | |
37 virtual ~ShelfResetHandler() { | |
38 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | |
39 shelf_->RemoveObserver(this); | |
40 } | |
41 | |
42 void ResetShelfState() { | |
43 shelf_->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | |
44 delete this; | |
45 } | |
46 | |
47 bool ShelfIsEventTarget(const ui::Event& event) { | |
48 aura::Window* target = static_cast<aura::Window*>(event.target()); | |
49 views::Widget* widget = shelf_->shelf_widget(); | |
50 if (widget && widget->GetNativeWindow() == target) | |
51 return true; | |
52 widget = shelf_->shelf_widget()->status_area_widget(); | |
53 if (widget && widget->GetNativeWindow() == target) | |
54 return true; | |
55 return false; | |
56 } | |
57 | |
58 void DecideShelfVisibility(const gfx::Point& location) { | |
59 // For the rest of the mouse events, ignore if the event happens inside the | |
60 // shelf. | |
61 views::Widget* widget = shelf_->shelf_widget(); | |
62 if (widget && | |
63 widget->GetWindowBoundsInScreen().Contains(location)) { | |
64 return; | |
65 } | |
66 | |
67 widget = shelf_->shelf_widget()->status_area_widget(); | |
68 if (widget && | |
69 widget->GetWindowBoundsInScreen().Contains(location)) { | |
70 return; | |
71 } | |
72 | |
73 ResetShelfState(); | |
74 } | |
75 | |
76 // Overridden from ui::EventHandler: | |
77 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE { | |
78 if (!ShelfIsEventTarget(*event)) | |
79 ResetShelfState(); | |
80 } | |
81 | |
82 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | |
83 // Ignore all mouse move events. | |
84 if (event->type() == ui::ET_MOUSE_PRESSED || | |
85 event->type() == ui::ET_MOUSE_RELEASED) { | |
86 DecideShelfVisibility(event->root_location()); | |
87 } | |
88 } | |
89 | |
90 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { | |
91 if (!ShelfIsEventTarget(*event)) | |
92 DecideShelfVisibility(event->root_location()); | |
93 } | |
94 | |
95 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | |
96 if (!ShelfIsEventTarget(*event)) | |
97 DecideShelfVisibility(event->root_location()); | |
98 } | |
99 | |
100 // Overridden from ash::internal::ShelfLayoutManager::Observer: | |
101 virtual void WillDeleteShelf() OVERRIDE { | |
102 delete this; | |
103 } | |
104 | |
105 ash::internal::ShelfLayoutManager* shelf_; | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(ShelfResetHandler); | |
108 }; | |
109 | |
110 } // namespace | |
111 | |
112 namespace ash { | 22 namespace ash { |
113 namespace internal { | 23 namespace internal { |
114 | 24 |
115 ShelfGestureHandler::ShelfGestureHandler() | 25 ShelfGestureHandler::ShelfGestureHandler() |
116 : drag_in_progress_(false) { | 26 : drag_in_progress_(false) { |
117 } | 27 } |
118 | 28 |
119 ShelfGestureHandler::~ShelfGestureHandler() { | 29 ShelfGestureHandler::~ShelfGestureHandler() { |
120 } | 30 } |
121 | 31 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 68 |
159 drag_in_progress_ = false; | 69 drag_in_progress_ = false; |
160 | 70 |
161 if (event.type() == ui::ET_GESTURE_SCROLL_END || | 71 if (event.type() == ui::ET_GESTURE_SCROLL_END || |
162 event.type() == ui::ET_SCROLL_FLING_START) { | 72 event.type() == ui::ET_SCROLL_FLING_START) { |
163 if (tray_handler_.get()) { | 73 if (tray_handler_.get()) { |
164 tray_handler_->CompleteGestureDrag(event); | 74 tray_handler_->CompleteGestureDrag(event); |
165 tray_handler_.reset(); | 75 tray_handler_.reset(); |
166 } | 76 } |
167 | 77 |
168 ShelfVisibilityState old_state = shelf->visibility_state(); | |
169 shelf->CompleteGestureDrag(event); | 78 shelf->CompleteGestureDrag(event); |
170 ShelfVisibilityState new_state = shelf->visibility_state(); | |
171 if (new_state != old_state && new_state == SHELF_VISIBLE) | |
172 new ShelfResetHandler(shelf); | |
173 return true; | 79 return true; |
174 } | 80 } |
175 | 81 |
176 // Unexpected event. Reset the state and let the event fall through. | 82 // Unexpected event. Reset the state and let the event fall through. |
177 shelf->CancelGestureDrag(); | 83 shelf->CancelGestureDrag(); |
178 return false; | 84 return false; |
179 } | 85 } |
180 | 86 |
181 } // namespace internal | 87 } // namespace internal |
182 } // namespace ash | 88 } // namespace ash |
OLD | NEW |