OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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/system/tray_drag_controller.h" | |
6 | |
7 #include "ash/shell.h" | |
8 #include "ash/system/tray/tray_background_view.h" | |
9 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
10 | |
11 namespace ash { | |
12 | |
13 bool TrayDragController::ProcessGestureEvent(const ui::GestureEvent& event, | |
14 TrayBackgroundView* target_view, | |
15 bool is_on_bubble) { | |
16 target_view_ = target_view; | |
17 if (!Shell::Get() | |
18 ->maximize_mode_controller() | |
19 ->IsMaximizeModeWindowManagerEnabled() || | |
20 !shelf_->IsHorizontalAlignment()) { | |
msw
2017/07/12 05:04:52
Ah, this only works for horizontal alignments? Do
minch1
2017/07/13 19:10:36
Acknowledged.
| |
21 return false; | |
22 } | |
23 | |
24 is_on_bubble_ = is_on_bubble; | |
25 if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) | |
26 return StartGestureDrag(event); | |
27 | |
28 if (!target_view_->HasBubble() || !is_in_drag_) { | |
msw
2017/07/12 05:04:52
nit: curlies not needed for one-liners
minch1
2017/07/13 19:10:36
Done.
| |
29 return false; | |
30 } | |
31 | |
32 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { | |
33 UpdateGestureDrag(event); | |
34 return true; | |
35 } | |
36 | |
37 if (event.type() == ui::ET_GESTURE_SCROLL_END || | |
38 event.type() == ui::ET_SCROLL_FLING_START) { | |
39 CompleteGestureDrag(event); | |
40 return true; | |
41 } | |
42 | |
43 // Unexpected event. Reset the drag state and close the bubble. | |
44 is_in_drag_ = false; | |
45 target_view_->CloseBubble(); | |
46 return false; | |
47 } | |
48 | |
49 bool TrayDragController::StartGestureDrag(const ui::GestureEvent& gesture) { | |
50 if (!is_on_bubble_) { | |
51 // Dragging happens on the tray view. Close the bubble if there is already | |
52 // one opened. And return false to let shelf handle the event. | |
53 if (target_view_->HasBubble()) { | |
54 target_view_->CloseBubble(); | |
55 return false; | |
56 } | |
57 | |
58 // If the scroll sequence begins to scroll downward, return false so that | |
59 // the event will instead by handled by the shelf. | |
60 if (gesture.details().scroll_y_hint() > 0) | |
61 return false; | |
62 | |
63 target_view_->ShowBubble(); | |
64 } | |
65 | |
66 is_in_drag_ = true; | |
67 gesture_drag_amount_ = 0.f; | |
68 tray_bubble_bounds_ = | |
69 target_view_->GetBubbleView()->GetWidget()->GetWindowBoundsInScreen(); | |
70 UpdateBubbleBounds(); | |
71 return true; | |
72 } | |
73 | |
74 void TrayDragController::UpdateGestureDrag(const ui::GestureEvent& gesture) { | |
75 UpdateBubbleBounds(); | |
76 gesture_drag_amount_ += gesture.details().scroll_y(); | |
msw
2017/07/12 05:04:52
should we be updating this value before calling Up
minch1
2017/07/13 19:10:36
Thanks. I think we should update this value before
| |
77 } | |
78 | |
79 void TrayDragController::CompleteGestureDrag(const ui::GestureEvent& gesture) { | |
80 const bool hide_bubble = !ShouldShowBubbleAfterScrollSequence(gesture); | |
81 gfx::Rect target_bounds = tray_bubble_bounds_; | |
82 | |
83 if (hide_bubble) | |
84 target_bounds.set_y(shelf_->GetIdealBounds().y()); | |
85 | |
86 target_view_->AnimateToTargetBounds(target_bounds, hide_bubble); | |
87 is_in_drag_ = false; | |
88 } | |
89 | |
90 void TrayDragController::UpdateBubbleBounds() { | |
91 gfx::Rect bounds_on_location = tray_bubble_bounds_; | |
msw
2017/07/12 05:04:52
nit: can you imagine a better name for this?
minch1
2017/07/13 19:10:36
How about |current_tray_bubble_bounds|?
| |
92 int bounds_y = | |
93 (is_on_bubble_ ? tray_bubble_bounds_.y() : shelf_->GetIdealBounds().y()) + | |
94 gesture_drag_amount_; | |
95 bounds_on_location.set_y(std::max(bounds_y, tray_bubble_bounds_.y())); | |
96 target_view_->GetBubbleView()->GetWidget()->SetBounds(bounds_on_location); | |
97 } | |
98 | |
99 bool TrayDragController::ShouldShowBubbleAfterScrollSequence( | |
100 const ui::GestureEvent& sequence_end) { | |
101 // If the scroll sequence terminates with a fling, show the bubble if the | |
102 // fling was fast enough and in the correct direction. | |
103 if (sequence_end.type() == ui::ET_SCROLL_FLING_START && | |
104 fabs(sequence_end.details().velocity_y()) > kFlingVelocity) { | |
105 return sequence_end.details().velocity_y() < 0; | |
106 } | |
107 | |
108 DCHECK(sequence_end.type() == ui::ET_GESTURE_SCROLL_END || | |
109 sequence_end.type() == ui::ET_SCROLL_FLING_START); | |
110 | |
111 // Keep the bubble's original state if the |gesture_drag_amount_| doesn't | |
112 // exceed one-third of the bubble's height. | |
113 if (is_on_bubble_) | |
114 return gesture_drag_amount_ < tray_bubble_bounds_.height() / 3.0; | |
115 return -gesture_drag_amount_ >= tray_bubble_bounds_.height() / 3.0; | |
116 } | |
117 | |
118 } // namespace ash | |
OLD | NEW |