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

Side by Side Diff: ash/shelf/shelf_layout_manager.cc

Issue 15931005: Move bezel event routing for the shelf into ShelfLayoutManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits for sadrul@ Created 7 years, 6 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/shelf/shelf_layout_manager.h" 5 #include "ash/shelf/shelf_layout_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <cstring>
10 #include <string>
11 #include <vector>
9 12
10 #include "ash/ash_switches.h" 13 #include "ash/ash_switches.h"
11 #include "ash/launcher/launcher.h" 14 #include "ash/launcher/launcher.h"
12 #include "ash/launcher/launcher_types.h" 15 #include "ash/launcher/launcher_types.h"
13 #include "ash/root_window_controller.h" 16 #include "ash/root_window_controller.h"
14 #include "ash/screen_ash.h" 17 #include "ash/screen_ash.h"
15 #include "ash/session_state_delegate.h" 18 #include "ash/session_state_delegate.h"
16 #include "ash/shelf/shelf_layout_manager_observer.h" 19 #include "ash/shelf/shelf_layout_manager_observer.h"
17 #include "ash/shelf/shelf_widget.h" 20 #include "ash/shelf/shelf_widget.h"
18 #include "ash/shell.h" 21 #include "ash/shell.h"
19 #include "ash/shell_window_ids.h" 22 #include "ash/shell_window_ids.h"
20 #include "ash/system/status_area_widget.h" 23 #include "ash/system/status_area_widget.h"
21 #include "ash/wm/gestures/shelf_gesture_handler.h" 24 #include "ash/wm/gestures/shelf_gesture_handler.h"
22 #include "ash/wm/property_util.h" 25 #include "ash/wm/property_util.h"
23 #include "ash/wm/window_cycle_controller.h" 26 #include "ash/wm/window_cycle_controller.h"
24 #include "ash/wm/window_properties.h" 27 #include "ash/wm/window_properties.h"
25 #include "ash/wm/window_util.h" 28 #include "ash/wm/window_util.h"
29 #include "ash/wm/workspace/workspace_animations.h"
26 #include "ash/wm/workspace_controller.h" 30 #include "ash/wm/workspace_controller.h"
27 #include "ash/wm/workspace/workspace_animations.h"
28 #include "base/auto_reset.h" 31 #include "base/auto_reset.h"
29 #include "base/command_line.h" 32 #include "base/command_line.h"
33 #include "base/command_line.h"
30 #include "base/i18n/rtl.h" 34 #include "base/i18n/rtl.h"
35 #include "base/string_number_conversions.h"
36 #include "base/string_util.h"
31 #include "ui/aura/client/activation_client.h" 37 #include "ui/aura/client/activation_client.h"
32 #include "ui/aura/root_window.h" 38 #include "ui/aura/root_window.h"
33 #include "ui/base/events/event.h" 39 #include "ui/base/events/event.h"
34 #include "ui/base/events/event_handler.h" 40 #include "ui/base/events/event_handler.h"
41 #include "ui/base/ui_base_switches.h"
35 #include "ui/compositor/layer.h" 42 #include "ui/compositor/layer.h"
36 #include "ui/compositor/layer_animation_observer.h" 43 #include "ui/compositor/layer_animation_observer.h"
37 #include "ui/compositor/layer_animator.h" 44 #include "ui/compositor/layer_animator.h"
38 #include "ui/compositor/scoped_layer_animation_settings.h" 45 #include "ui/compositor/scoped_layer_animation_settings.h"
39 #include "ui/gfx/screen.h" 46 #include "ui/gfx/screen.h"
40 #include "ui/views/widget/widget.h" 47 #include "ui/views/widget/widget.h"
41 48
42 namespace ash { 49 namespace ash {
43 namespace internal { 50 namespace internal {
44 51
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 bool in_mouse_drag() const { return in_mouse_drag_; } 92 bool in_mouse_drag() const { return in_mouse_drag_; }
86 93
87 // Overridden from ui::EventHandler: 94 // Overridden from ui::EventHandler:
88 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 95 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
89 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 96 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
90 97
91 private: 98 private:
92 ShelfLayoutManager* shelf_; 99 ShelfLayoutManager* shelf_;
93 bool in_mouse_drag_; 100 bool in_mouse_drag_;
94 ShelfGestureHandler gesture_handler_; 101 ShelfGestureHandler gesture_handler_;
95
96 DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter); 102 DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter);
97 }; 103 };
98 104
99 ShelfLayoutManager::AutoHideEventFilter::AutoHideEventFilter( 105 ShelfLayoutManager::AutoHideEventFilter::AutoHideEventFilter(
100 ShelfLayoutManager* shelf) 106 ShelfLayoutManager* shelf)
101 : shelf_(shelf), 107 : shelf_(shelf),
102 in_mouse_drag_(false) { 108 in_mouse_drag_(false) {
103 Shell::GetInstance()->AddPreTargetHandler(this); 109 Shell::GetInstance()->AddPreTargetHandler(this);
104 } 110 }
105 111
(...skipping 15 matching lines...) Expand all
121 } 127 }
122 128
123 void ShelfLayoutManager::AutoHideEventFilter::OnGestureEvent( 129 void ShelfLayoutManager::AutoHideEventFilter::OnGestureEvent(
124 ui::GestureEvent* event) { 130 ui::GestureEvent* event) {
125 if (shelf_->IsShelfWindow(static_cast<aura::Window*>(event->target()))) { 131 if (shelf_->IsShelfWindow(static_cast<aura::Window*>(event->target()))) {
126 if (gesture_handler_.ProcessGestureEvent(*event)) 132 if (gesture_handler_.ProcessGestureEvent(*event))
127 event->StopPropagation(); 133 event->StopPropagation();
128 } 134 }
129 } 135 }
130 136
137 // ShelfLayoutManager::BezelEventFilter -------------------------------------
138
139 // Notifies ShelfLayoutManager any time the mouse moves.
140 class ShelfLayoutManager::BezelEventFilter : public ui::EventHandler {
141 public:
142 explicit BezelEventFilter(ShelfLayoutManager* shelf);
143 virtual ~BezelEventFilter();
144
145 // Overridden from ui::EventHandler:
146 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
147
148 private:
149 bool IsShelfOnBezel(const gfx::Rect& screen,
150 const gfx::Point& point) const;
151
152 ShelfLayoutManager* shelf_; // non-owned
153 bool in_touch_drag_;
154 ShelfGestureHandler gesture_handler_;
155 DISALLOW_COPY_AND_ASSIGN(BezelEventFilter);
156 };
157
158 ShelfLayoutManager::BezelEventFilter::BezelEventFilter(
159 ShelfLayoutManager* shelf)
160 : shelf_(shelf),
161 in_touch_drag_(false) {
162 Shell::GetInstance()->AddPreTargetHandler(this);
163 }
164
165 ShelfLayoutManager::BezelEventFilter::~BezelEventFilter() {
166 Shell::GetInstance()->RemovePreTargetHandler(this);
167 }
168
169 void ShelfLayoutManager::BezelEventFilter::OnGestureEvent(
170 ui::GestureEvent* event) {
171 gfx::Rect screen =
172 Shell::GetScreen()->GetDisplayNearestPoint(event->location()).bounds();
173 if ((!screen.Contains(event->location()) &&
174 IsShelfOnBezel(screen, event->location())) ||
175 in_touch_drag_) {
176 if (gesture_handler_.ProcessGestureEvent(*event)) {
177 switch (event->type()) {
178 case ui::ET_GESTURE_SCROLL_BEGIN:
179 in_touch_drag_ = true;
180 break;
181 case ui::ET_GESTURE_SCROLL_END:
182 case ui::ET_SCROLL_FLING_START:
183 in_touch_drag_ = false;
184 break;
185 default:
186 break;
187 }
188 event->StopPropagation();
189 }
190 }
191 }
192
193 bool ShelfLayoutManager::BezelEventFilter::IsShelfOnBezel(
194 const gfx::Rect& screen,
195 const gfx::Point& point) const{
196 switch (shelf_->GetAlignment()) {
197 case SHELF_ALIGNMENT_BOTTOM:
198 if (point.y() >= screen.bottom())
199 return true;
200 break;
201 case SHELF_ALIGNMENT_LEFT:
202 if (point.x() <= screen.x())
203 return true;
204 break;
205 case SHELF_ALIGNMENT_TOP:
206 if (point.y() <= screen.y())
207 return true;
208 break;
209 case SHELF_ALIGNMENT_RIGHT:
210 if (point.x() >= screen.right())
211 return true;
212 break;
213 }
214 return false;
215 }
216
131 // ShelfLayoutManager:UpdateShelfObserver -------------------------------------- 217 // ShelfLayoutManager:UpdateShelfObserver --------------------------------------
132 218
133 // UpdateShelfObserver is used to delay updating the background until the 219 // UpdateShelfObserver is used to delay updating the background until the
134 // animation completes. 220 // animation completes.
135 class ShelfLayoutManager::UpdateShelfObserver 221 class ShelfLayoutManager::UpdateShelfObserver
136 : public ui::ImplicitAnimationObserver { 222 : public ui::ImplicitAnimationObserver {
137 public: 223 public:
138 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) { 224 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) {
139 shelf_->update_shelf_observer_ = this; 225 shelf_->update_shelf_observer_ = this;
140 } 226 }
(...skipping 24 matching lines...) Expand all
165 // ShelfLayoutManager ---------------------------------------------------------- 251 // ShelfLayoutManager ----------------------------------------------------------
166 252
167 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf) 253 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf)
168 : root_window_(shelf->GetNativeView()->GetRootWindow()), 254 : root_window_(shelf->GetNativeView()->GetRootWindow()),
169 in_layout_(false), 255 in_layout_(false),
170 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), 256 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER),
171 alignment_(SHELF_ALIGNMENT_BOTTOM), 257 alignment_(SHELF_ALIGNMENT_BOTTOM),
172 shelf_(shelf), 258 shelf_(shelf),
173 workspace_controller_(NULL), 259 workspace_controller_(NULL),
174 window_overlaps_shelf_(false), 260 window_overlaps_shelf_(false),
261 bezel_event_filter_(new BezelEventFilter(this)),
175 gesture_drag_status_(GESTURE_DRAG_NONE), 262 gesture_drag_status_(GESTURE_DRAG_NONE),
176 gesture_drag_amount_(0.f), 263 gesture_drag_amount_(0.f),
177 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), 264 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN),
178 update_shelf_observer_(NULL) { 265 update_shelf_observer_(NULL) {
179 Shell::GetInstance()->AddShellObserver(this); 266 Shell::GetInstance()->AddShellObserver(this);
180 aura::client::GetActivationClient(root_window_)->AddObserver(this); 267 aura::client::GetActivationClient(root_window_)->AddObserver(this);
181 } 268 }
182 269
183 ShelfLayoutManager::~ShelfLayoutManager() { 270 ShelfLayoutManager::~ShelfLayoutManager() {
184 if (update_shelf_observer_) 271 if (update_shelf_observer_)
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 647
561 if (state_.Equals(state)) 648 if (state_.Equals(state))
562 return; // Nothing changed. 649 return; // Nothing changed.
563 650
564 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 651 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
565 WillChangeVisibilityState(visibility_state)); 652 WillChangeVisibilityState(visibility_state));
566 653
567 if (state.visibility_state == SHELF_AUTO_HIDE) { 654 if (state.visibility_state == SHELF_AUTO_HIDE) {
568 // When state is SHELF_AUTO_HIDE we need to track when the mouse is over the 655 // When state is SHELF_AUTO_HIDE we need to track when the mouse is over the
569 // launcher to unhide the shelf. AutoHideEventFilter does that for us. 656 // launcher to unhide the shelf. AutoHideEventFilter does that for us.
570 if (!event_filter_) 657 if (!auto_hide_event_filter_)
571 event_filter_.reset(new AutoHideEventFilter(this)); 658 auto_hide_event_filter_.reset(new AutoHideEventFilter(this));
572 } else { 659 } else {
573 event_filter_.reset(NULL); 660 auto_hide_event_filter_.reset(NULL);
574 } 661 }
575 662
576 auto_hide_timer_.Stop(); 663 auto_hide_timer_.Stop();
577 664
578 // Animating the background when transitioning from auto-hide & hidden to 665 // Animating the background when transitioning from auto-hide & hidden to
579 // visible is janky. Update the background immediately in this case. 666 // visible is janky. Update the background immediately in this case.
580 BackgroundAnimator::ChangeType change_type = 667 BackgroundAnimator::ChangeType change_type =
581 (state_.visibility_state == SHELF_AUTO_HIDE && 668 (state_.visibility_state == SHELF_AUTO_HIDE &&
582 state_.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && 669 state_.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN &&
583 state.visibility_state == SHELF_VISIBLE) ? 670 state.visibility_state == SHELF_VISIBLE) ?
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 if (shelf_->launcher() && shelf_->launcher()->IsShowingMenu()) 954 if (shelf_->launcher() && shelf_->launcher()->IsShowingMenu())
868 return SHELF_AUTO_HIDE_SHOWN; 955 return SHELF_AUTO_HIDE_SHOWN;
869 956
870 if (shelf_->launcher() && shelf_->launcher()->IsShowingOverflowBubble()) 957 if (shelf_->launcher() && shelf_->launcher()->IsShowingOverflowBubble())
871 return SHELF_AUTO_HIDE_SHOWN; 958 return SHELF_AUTO_HIDE_SHOWN;
872 959
873 if (shelf_->IsActive() || shelf_->status_area_widget()->IsActive()) 960 if (shelf_->IsActive() || shelf_->status_area_widget()->IsActive())
874 return SHELF_AUTO_HIDE_SHOWN; 961 return SHELF_AUTO_HIDE_SHOWN;
875 962
876 // Don't show if the user is dragging the mouse. 963 // Don't show if the user is dragging the mouse.
877 if (event_filter_.get() && event_filter_->in_mouse_drag()) 964 if (auto_hide_event_filter_.get() && auto_hide_event_filter_->in_mouse_drag())
878 return SHELF_AUTO_HIDE_HIDDEN; 965 return SHELF_AUTO_HIDE_HIDDEN;
879 966
880 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); 967 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen();
881 if (shelf_->status_area_widget() && 968 if (shelf_->status_area_widget() &&
882 shelf_->status_area_widget()->IsMessageBubbleShown() && 969 shelf_->status_area_widget()->IsMessageBubbleShown() &&
883 IsVisible()) { 970 IsVisible()) {
884 // Increase the the hit test area to prevent the shelf from disappearing 971 // Increase the the hit test area to prevent the shelf from disappearing
885 // when the mouse is over the bubble gap. 972 // when the mouse is over the bubble gap.
886 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? 973 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ?
887 -kNotificationBubbleGapHeight : 0, 974 -kNotificationBubbleGapHeight : 0,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 return gfx::Insets(0, distance, 0, 0); 1056 return gfx::Insets(0, distance, 0, 0);
970 case SHELF_ALIGNMENT_TOP: 1057 case SHELF_ALIGNMENT_TOP:
971 return gfx::Insets(0, 0, distance, 0); 1058 return gfx::Insets(0, 0, distance, 0);
972 } 1059 }
973 NOTREACHED(); 1060 NOTREACHED();
974 return gfx::Insets(); 1061 return gfx::Insets();
975 } 1062 }
976 1063
977 } // namespace internal 1064 } // namespace internal
978 } // namespace ash 1065 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698