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

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: 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
« no previous file with comments | « ash/shelf/shelf_layout_manager.h ('k') | ash/shelf/shelf_layout_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
sadrul 2013/05/31 14:40:38 const method
rharrison 2013/05/31 15:15:46 Done.
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) {
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 default:
sadrul 2013/05/31 14:40:38 remove default
rharrison 2013/05/31 15:15:46 Done.
214 break;
215 }
216 return false;
217 }
218
131 // ShelfLayoutManager:UpdateShelfObserver -------------------------------------- 219 // ShelfLayoutManager:UpdateShelfObserver --------------------------------------
132 220
133 // UpdateShelfObserver is used to delay updating the background until the 221 // UpdateShelfObserver is used to delay updating the background until the
134 // animation completes. 222 // animation completes.
135 class ShelfLayoutManager::UpdateShelfObserver 223 class ShelfLayoutManager::UpdateShelfObserver
136 : public ui::ImplicitAnimationObserver { 224 : public ui::ImplicitAnimationObserver {
137 public: 225 public:
138 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) { 226 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) {
139 shelf_->update_shelf_observer_ = this; 227 shelf_->update_shelf_observer_ = this;
140 } 228 }
(...skipping 24 matching lines...) Expand all
165 // ShelfLayoutManager ---------------------------------------------------------- 253 // ShelfLayoutManager ----------------------------------------------------------
166 254
167 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf) 255 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf)
168 : root_window_(shelf->GetNativeView()->GetRootWindow()), 256 : root_window_(shelf->GetNativeView()->GetRootWindow()),
169 in_layout_(false), 257 in_layout_(false),
170 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), 258 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER),
171 alignment_(SHELF_ALIGNMENT_BOTTOM), 259 alignment_(SHELF_ALIGNMENT_BOTTOM),
172 shelf_(shelf), 260 shelf_(shelf),
173 workspace_controller_(NULL), 261 workspace_controller_(NULL),
174 window_overlaps_shelf_(false), 262 window_overlaps_shelf_(false),
263 bezel_event_filter_(new BezelEventFilter(this)),
175 gesture_drag_status_(GESTURE_DRAG_NONE), 264 gesture_drag_status_(GESTURE_DRAG_NONE),
176 gesture_drag_amount_(0.f), 265 gesture_drag_amount_(0.f),
177 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), 266 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN),
178 update_shelf_observer_(NULL) { 267 update_shelf_observer_(NULL) {
179 Shell::GetInstance()->AddShellObserver(this); 268 Shell::GetInstance()->AddShellObserver(this);
180 aura::client::GetActivationClient(root_window_)->AddObserver(this); 269 aura::client::GetActivationClient(root_window_)->AddObserver(this);
181 } 270 }
182 271
183 ShelfLayoutManager::~ShelfLayoutManager() { 272 ShelfLayoutManager::~ShelfLayoutManager() {
184 if (update_shelf_observer_) 273 if (update_shelf_observer_)
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 649
561 if (state_.Equals(state)) 650 if (state_.Equals(state))
562 return; // Nothing changed. 651 return; // Nothing changed.
563 652
564 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 653 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
565 WillChangeVisibilityState(visibility_state)); 654 WillChangeVisibilityState(visibility_state));
566 655
567 if (state.visibility_state == SHELF_AUTO_HIDE) { 656 if (state.visibility_state == SHELF_AUTO_HIDE) {
568 // When state is SHELF_AUTO_HIDE we need to track when the mouse is over the 657 // 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. 658 // launcher to unhide the shelf. AutoHideEventFilter does that for us.
570 if (!event_filter_) 659 if (!auto_hide_event_filter_)
571 event_filter_.reset(new AutoHideEventFilter(this)); 660 auto_hide_event_filter_.reset(new AutoHideEventFilter(this));
572 } else { 661 } else {
573 event_filter_.reset(NULL); 662 auto_hide_event_filter_.reset(NULL);
574 } 663 }
575 664
576 auto_hide_timer_.Stop(); 665 auto_hide_timer_.Stop();
577 666
578 // Animating the background when transitioning from auto-hide & hidden to 667 // Animating the background when transitioning from auto-hide & hidden to
579 // visible is janky. Update the background immediately in this case. 668 // visible is janky. Update the background immediately in this case.
580 BackgroundAnimator::ChangeType change_type = 669 BackgroundAnimator::ChangeType change_type =
581 (state_.visibility_state == SHELF_AUTO_HIDE && 670 (state_.visibility_state == SHELF_AUTO_HIDE &&
582 state_.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && 671 state_.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN &&
583 state.visibility_state == SHELF_VISIBLE) ? 672 state.visibility_state == SHELF_VISIBLE) ?
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 if (shelf_->launcher() && shelf_->launcher()->IsShowingMenu()) 956 if (shelf_->launcher() && shelf_->launcher()->IsShowingMenu())
868 return SHELF_AUTO_HIDE_SHOWN; 957 return SHELF_AUTO_HIDE_SHOWN;
869 958
870 if (shelf_->launcher() && shelf_->launcher()->IsShowingOverflowBubble()) 959 if (shelf_->launcher() && shelf_->launcher()->IsShowingOverflowBubble())
871 return SHELF_AUTO_HIDE_SHOWN; 960 return SHELF_AUTO_HIDE_SHOWN;
872 961
873 if (shelf_->IsActive() || shelf_->status_area_widget()->IsActive()) 962 if (shelf_->IsActive() || shelf_->status_area_widget()->IsActive())
874 return SHELF_AUTO_HIDE_SHOWN; 963 return SHELF_AUTO_HIDE_SHOWN;
875 964
876 // Don't show if the user is dragging the mouse. 965 // Don't show if the user is dragging the mouse.
877 if (event_filter_.get() && event_filter_->in_mouse_drag()) 966 if (auto_hide_event_filter_.get() && auto_hide_event_filter_->in_mouse_drag())
878 return SHELF_AUTO_HIDE_HIDDEN; 967 return SHELF_AUTO_HIDE_HIDDEN;
879 968
880 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); 969 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen();
881 if (shelf_->status_area_widget() && 970 if (shelf_->status_area_widget() &&
882 shelf_->status_area_widget()->IsMessageBubbleShown() && 971 shelf_->status_area_widget()->IsMessageBubbleShown() &&
883 IsVisible()) { 972 IsVisible()) {
884 // Increase the the hit test area to prevent the shelf from disappearing 973 // Increase the the hit test area to prevent the shelf from disappearing
885 // when the mouse is over the bubble gap. 974 // when the mouse is over the bubble gap.
886 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? 975 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ?
887 -kNotificationBubbleGapHeight : 0, 976 -kNotificationBubbleGapHeight : 0,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 return gfx::Insets(0, distance, 0, 0); 1058 return gfx::Insets(0, distance, 0, 0);
970 case SHELF_ALIGNMENT_TOP: 1059 case SHELF_ALIGNMENT_TOP:
971 return gfx::Insets(0, 0, distance, 0); 1060 return gfx::Insets(0, 0, distance, 0);
972 } 1061 }
973 NOTREACHED(); 1062 NOTREACHED();
974 return gfx::Insets(); 1063 return gfx::Insets();
975 } 1064 }
976 1065
977 } // namespace internal 1066 } // namespace internal
978 } // namespace ash 1067 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_layout_manager.h ('k') | ash/shelf/shelf_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698