[email protected] | 1b62b89 | 2012-01-17 17:08:15 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 5 | #include "ash/shelf/shelf_layout_manager.h" |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 6 | |
[email protected] | c2d58b4 | 2012-05-30 08:11:29 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 91d966a7 | 2012-09-06 03:42:27 | [diff] [blame] | 8 | #include <cmath> |
[email protected] | c2d58b4 | 2012-05-30 08:11:29 | [diff] [blame] | 9 | |
[email protected] | fd42270 | 2012-09-25 17:45:14 | [diff] [blame] | 10 | #include "ash/ash_switches.h" |
[email protected] | 7634f96 | 2011-12-23 21:35:52 | [diff] [blame] | 11 | #include "ash/launcher/launcher.h" |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 12 | #include "ash/launcher/launcher_types.h" |
[email protected] | 88d7112 | 2012-10-18 07:11:01 | [diff] [blame] | 13 | #include "ash/root_window_controller.h" |
[email protected] | 1a2145b | 2012-03-13 21:09:17 | [diff] [blame] | 14 | #include "ash/screen_ash.h" |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 15 | #include "ash/session_state_delegate.h" |
[email protected] | 7841e117 | 2013-05-07 03:53:33 | [diff] [blame] | 16 | #include "ash/shelf/shelf_layout_manager_observer.h" |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 17 | #include "ash/shelf/shelf_widget.h" |
[email protected] | b65bdda | 2011-12-23 23:35:31 | [diff] [blame] | 18 | #include "ash/shell.h" |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 19 | #include "ash/shell_window_ids.h" |
[email protected] | 6d6546e | 2012-05-30 23:12:02 | [diff] [blame] | 20 | #include "ash/system/status_area_widget.h" |
[email protected] | d3643b5 | 2013-05-01 16:00:48 | [diff] [blame] | 21 | #include "ash/wm/gestures/shelf_gesture_handler.h" |
[email protected] | 2ee2f5d | 2013-01-10 23:37:16 | [diff] [blame] | 22 | #include "ash/wm/property_util.h" |
[email protected] | ca8f905b | 2013-01-22 21:53:25 | [diff] [blame] | 23 | #include "ash/wm/window_cycle_controller.h" |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 24 | #include "ash/wm/window_properties.h" |
[email protected] | ca8f905b | 2013-01-22 21:53:25 | [diff] [blame] | 25 | #include "ash/wm/window_util.h" |
[email protected] | f4bb9fde | 2012-08-03 19:33:50 | [diff] [blame] | 26 | #include "ash/wm/workspace_controller.h" |
[email protected] | ba38e00 | 2012-10-12 16:39:41 | [diff] [blame] | 27 | #include "ash/wm/workspace/workspace_animations.h" |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 28 | #include "base/auto_reset.h" |
[email protected] | fd42270 | 2012-09-25 17:45:14 | [diff] [blame] | 29 | #include "base/command_line.h" |
[email protected] | e24b609 | 2012-04-12 18:58:51 | [diff] [blame] | 30 | #include "base/i18n/rtl.h" |
[email protected] | 8676f047 | 2012-03-29 20:30:12 | [diff] [blame] | 31 | #include "ui/aura/client/activation_client.h" |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 32 | #include "ui/aura/root_window.h" |
[email protected] | 153472d7 | 2012-09-04 21:33:02 | [diff] [blame] | 33 | #include "ui/base/events/event.h" |
[email protected] | f9f017c | 2012-11-12 19:05:17 | [diff] [blame] | 34 | #include "ui/base/events/event_handler.h" |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 35 | #include "ui/compositor/layer.h" |
| 36 | #include "ui/compositor/layer_animation_observer.h" |
| 37 | #include "ui/compositor/layer_animator.h" |
| 38 | #include "ui/compositor/scoped_layer_animation_settings.h" |
[email protected] | b82c42c4 | 2012-04-25 20:03:41 | [diff] [blame] | 39 | #include "ui/gfx/screen.h" |
[email protected] | c13be0d | 2011-11-22 02:09:58 | [diff] [blame] | 40 | #include "ui/views/widget/widget.h" |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 41 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 42 | namespace ash { |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 43 | namespace internal { |
| 44 | |
| 45 | namespace { |
| 46 | |
[email protected] | cadd8c4 | 2012-03-27 02:44:31 | [diff] [blame] | 47 | // Delay before showing the launcher. This is after the mouse stops moving. |
| 48 | const int kAutoHideDelayMS = 200; |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 49 | |
[email protected] | 2e195f5 | 2012-09-22 00:24:46 | [diff] [blame] | 50 | // To avoid hiding the shelf when the mouse transitions from a message bubble |
| 51 | // into the shelf, the hit test area is enlarged by this amount of pixels to |
| 52 | // keep the shelf from hiding. |
| 53 | const int kNotificationBubbleGapHeight = 6; |
| 54 | |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 55 | ui::Layer* GetLayer(views::Widget* widget) { |
| 56 | return widget->GetNativeView()->layer(); |
| 57 | } |
| 58 | |
[email protected] | fd42270 | 2012-09-25 17:45:14 | [diff] [blame] | 59 | bool IsDraggingTrayEnabled() { |
| 60 | static bool dragging_tray_allowed = CommandLine::ForCurrentProcess()-> |
| 61 | HasSwitch(ash::switches::kAshEnableTrayDragging); |
| 62 | return dragging_tray_allowed; |
| 63 | } |
| 64 | |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 65 | } // namespace |
| 66 | |
[email protected] | bbb59f8 | 2012-03-14 04:04:35 | [diff] [blame] | 67 | // static |
[email protected] | d3643b5 | 2013-05-01 16:00:48 | [diff] [blame] | 68 | const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; |
| 69 | |
| 70 | // static |
| 71 | const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; |
[email protected] | bbb59f8 | 2012-03-14 04:04:35 | [diff] [blame] | 72 | |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 73 | // static |
[email protected] | 7b675df61 | 2012-09-16 18:33:20 | [diff] [blame] | 74 | const int ShelfLayoutManager::kAutoHideSize = 3; |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 75 | |
[email protected] | e4d9fe9 | 2012-09-10 14:04:49 | [diff] [blame] | 76 | // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- |
| 77 | |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 78 | // Notifies ShelfLayoutManager any time the mouse moves. |
[email protected] | f9f017c | 2012-11-12 19:05:17 | [diff] [blame] | 79 | class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 80 | public: |
| 81 | explicit AutoHideEventFilter(ShelfLayoutManager* shelf); |
| 82 | virtual ~AutoHideEventFilter(); |
| 83 | |
[email protected] | 5f1d99dc | 2012-04-12 21:42:37 | [diff] [blame] | 84 | // Returns true if the last mouse event was a mouse drag. |
| 85 | bool in_mouse_drag() const { return in_mouse_drag_; } |
| 86 | |
[email protected] | f9f017c | 2012-11-12 19:05:17 | [diff] [blame] | 87 | // Overridden from ui::EventHandler: |
[email protected] | d44efe0 | 2012-12-18 06:08:18 | [diff] [blame] | 88 | virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
[email protected] | d3643b5 | 2013-05-01 16:00:48 | [diff] [blame] | 89 | virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 90 | |
| 91 | private: |
| 92 | ShelfLayoutManager* shelf_; |
[email protected] | 5f1d99dc | 2012-04-12 21:42:37 | [diff] [blame] | 93 | bool in_mouse_drag_; |
[email protected] | d3643b5 | 2013-05-01 16:00:48 | [diff] [blame] | 94 | ShelfGestureHandler gesture_handler_; |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 95 | |
| 96 | DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter); |
| 97 | }; |
| 98 | |
| 99 | ShelfLayoutManager::AutoHideEventFilter::AutoHideEventFilter( |
| 100 | ShelfLayoutManager* shelf) |
[email protected] | 5f1d99dc | 2012-04-12 21:42:37 | [diff] [blame] | 101 | : shelf_(shelf), |
| 102 | in_mouse_drag_(false) { |
[email protected] | f9f017c | 2012-11-12 19:05:17 | [diff] [blame] | 103 | Shell::GetInstance()->AddPreTargetHandler(this); |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | ShelfLayoutManager::AutoHideEventFilter::~AutoHideEventFilter() { |
[email protected] | f9f017c | 2012-11-12 19:05:17 | [diff] [blame] | 107 | Shell::GetInstance()->RemovePreTargetHandler(this); |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 108 | } |
| 109 | |
[email protected] | d44efe0 | 2012-12-18 06:08:18 | [diff] [blame] | 110 | void ShelfLayoutManager::AutoHideEventFilter::OnMouseEvent( |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 111 | ui::MouseEvent* event) { |
[email protected] | 5f1d99dc | 2012-04-12 21:42:37 | [diff] [blame] | 112 | // This also checks IsShelfWindow() to make sure we don't attempt to hide the |
| 113 | // shelf if the mouse down occurs on the shelf. |
| 114 | in_mouse_drag_ = (event->type() == ui::ET_MOUSE_DRAGGED || |
| 115 | (in_mouse_drag_ && event->type() != ui::ET_MOUSE_RELEASED && |
| 116 | event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)) && |
[email protected] | f9f017c | 2012-11-12 19:05:17 | [diff] [blame] | 117 | !shelf_->IsShelfWindow(static_cast<aura::Window*>(event->target())); |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 118 | if (event->type() == ui::ET_MOUSE_MOVED) |
| 119 | shelf_->UpdateAutoHideState(); |
[email protected] | d44efe0 | 2012-12-18 06:08:18 | [diff] [blame] | 120 | return; |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 121 | } |
| 122 | |
[email protected] | d3643b5 | 2013-05-01 16:00:48 | [diff] [blame] | 123 | void ShelfLayoutManager::AutoHideEventFilter::OnGestureEvent( |
| 124 | ui::GestureEvent* event) { |
[email protected] | 65767e6 | 2013-05-14 09:29:50 | [diff] [blame] | 125 | if (shelf_->IsShelfWindow(static_cast<aura::Window*>(event->target()))) { |
| 126 | if (gesture_handler_.ProcessGestureEvent(*event)) |
| 127 | event->StopPropagation(); |
| 128 | } |
[email protected] | d3643b5 | 2013-05-01 16:00:48 | [diff] [blame] | 129 | } |
| 130 | |
[email protected] | e4d9fe9 | 2012-09-10 14:04:49 | [diff] [blame] | 131 | // ShelfLayoutManager:UpdateShelfObserver -------------------------------------- |
| 132 | |
| 133 | // UpdateShelfObserver is used to delay updating the background until the |
| 134 | // animation completes. |
| 135 | class ShelfLayoutManager::UpdateShelfObserver |
| 136 | : public ui::ImplicitAnimationObserver { |
| 137 | public: |
| 138 | explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) { |
| 139 | shelf_->update_shelf_observer_ = this; |
| 140 | } |
| 141 | |
| 142 | void Detach() { |
| 143 | shelf_ = NULL; |
| 144 | } |
| 145 | |
| 146 | virtual void OnImplicitAnimationsCompleted() OVERRIDE { |
| 147 | if (shelf_) { |
[email protected] | 1fcfb99 | 2012-12-05 01:47:23 | [diff] [blame] | 148 | shelf_->UpdateShelfBackground(BackgroundAnimator::CHANGE_ANIMATE); |
[email protected] | e4d9fe9 | 2012-09-10 14:04:49 | [diff] [blame] | 149 | } |
| 150 | delete this; |
| 151 | } |
| 152 | |
| 153 | private: |
| 154 | virtual ~UpdateShelfObserver() { |
| 155 | if (shelf_) |
| 156 | shelf_->update_shelf_observer_ = NULL; |
| 157 | } |
| 158 | |
| 159 | // Shelf we're in. NULL if deleted before we're deleted. |
| 160 | ShelfLayoutManager* shelf_; |
| 161 | |
| 162 | DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); |
| 163 | }; |
| 164 | |
| 165 | // ShelfLayoutManager ---------------------------------------------------------- |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 166 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 167 | ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf) |
| 168 | : root_window_(shelf->GetNativeView()->GetRootWindow()), |
[email protected] | 8676f047 | 2012-03-29 20:30:12 | [diff] [blame] | 169 | in_layout_(false), |
[email protected] | eefd51b2 | 2012-09-25 20:26:24 | [diff] [blame] | 170 | auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 171 | alignment_(SHELF_ALIGNMENT_BOTTOM), |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 172 | shelf_(shelf), |
[email protected] | f4bb9fde | 2012-08-03 19:33:50 | [diff] [blame] | 173 | workspace_controller_(NULL), |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 174 | window_overlaps_shelf_(false), |
| 175 | gesture_drag_status_(GESTURE_DRAG_NONE), |
[email protected] | 4982ee1 | 2012-09-04 22:16:10 | [diff] [blame] | 176 | gesture_drag_amount_(0.f), |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 177 | gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), |
[email protected] | e4d9fe9 | 2012-09-10 14:04:49 | [diff] [blame] | 178 | update_shelf_observer_(NULL) { |
[email protected] | 8e43cdf4 | 2012-05-11 17:03:31 | [diff] [blame] | 179 | Shell::GetInstance()->AddShellObserver(this); |
[email protected] | e76310a9 | 2012-06-04 19:06:11 | [diff] [blame] | 180 | aura::client::GetActivationClient(root_window_)->AddObserver(this); |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 181 | } |
| 182 | |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 183 | ShelfLayoutManager::~ShelfLayoutManager() { |
[email protected] | e4d9fe9 | 2012-09-10 14:04:49 | [diff] [blame] | 184 | if (update_shelf_observer_) |
| 185 | update_shelf_observer_->Detach(); |
| 186 | |
[email protected] | 7841e117 | 2013-05-07 03:53:33 | [diff] [blame] | 187 | FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, WillDeleteShelf()); |
[email protected] | 8e43cdf4 | 2012-05-11 17:03:31 | [diff] [blame] | 188 | Shell::GetInstance()->RemoveShellObserver(this); |
[email protected] | e76310a9 | 2012-06-04 19:06:11 | [diff] [blame] | 189 | aura::client::GetActivationClient(root_window_)->RemoveObserver(this); |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | 09f3fc8 | 2012-03-26 23:26:56 | [diff] [blame] | 192 | void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { |
| 193 | if (auto_hide_behavior_ == behavior) |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 194 | return; |
[email protected] | 09f3fc8 | 2012-03-26 23:26:56 | [diff] [blame] | 195 | auto_hide_behavior_ = behavior; |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 196 | UpdateVisibilityState(); |
[email protected] | 7841e117 | 2013-05-07 03:53:33 | [diff] [blame] | 197 | FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
[email protected] | cbc278f | 2012-07-10 03:40:21 | [diff] [blame] | 198 | OnAutoHideStateChanged(state_.auto_hide_state)); |
[email protected] | 7841e117 | 2013-05-07 03:53:33 | [diff] [blame] | 199 | FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
[email protected] | 7ed9895 | 2013-04-02 23:04:50 | [diff] [blame] | 200 | OnAutoHideBehaviorChanged(auto_hide_behavior_)); |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 201 | } |
| 202 | |
[email protected] | 40429f0 | 2012-03-28 20:38:50 | [diff] [blame] | 203 | bool ShelfLayoutManager::IsVisible() const { |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 204 | return shelf_->status_area_widget()->IsVisible() && |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 205 | (state_.visibility_state == SHELF_VISIBLE || |
| 206 | (state_.visibility_state == SHELF_AUTO_HIDE && |
| 207 | state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); |
[email protected] | 40429f0 | 2012-03-28 20:38:50 | [diff] [blame] | 208 | } |
| 209 | |
[email protected] | c2d58b4 | 2012-05-30 08:11:29 | [diff] [blame] | 210 | bool ShelfLayoutManager::SetAlignment(ShelfAlignment alignment) { |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 211 | if (alignment_ == alignment) |
[email protected] | c2d58b4 | 2012-05-30 08:11:29 | [diff] [blame] | 212 | return false; |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 213 | |
| 214 | alignment_ = alignment; |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 215 | if (shelf_->launcher()) |
| 216 | shelf_->launcher()->SetAlignment(alignment); |
| 217 | shelf_->status_area_widget()->SetShelfAlignment(alignment); |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 218 | LayoutShelf(); |
[email protected] | c2d58b4 | 2012-05-30 08:11:29 | [diff] [blame] | 219 | return true; |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | gfx::Rect ShelfLayoutManager::GetIdealBounds() { |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 223 | gfx::Rect bounds( |
| 224 | ScreenAsh::GetDisplayBoundsInParent(shelf_->GetNativeView())); |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 225 | int width = 0, height = 0; |
| 226 | GetShelfSize(&width, &height); |
[email protected] | 8572c487 | 2013-01-12 17:16:07 | [diff] [blame] | 227 | return SelectValueForShelfAlignment( |
| 228 | gfx::Rect(bounds.x(), bounds.bottom() - height, bounds.width(), height), |
| 229 | gfx::Rect(bounds.x(), bounds.y(), width, bounds.height()), |
| 230 | gfx::Rect(bounds.right() - width, bounds.y(), width, bounds.height()), |
| 231 | gfx::Rect(bounds.x(), bounds.y(), bounds.width(), height)); |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 232 | } |
| 233 | |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 234 | void ShelfLayoutManager::LayoutShelf() { |
[email protected] | 997ec9f | 2012-11-21 04:44:14 | [diff] [blame] | 235 | base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 236 | StopAnimating(); |
| 237 | TargetBounds target_bounds; |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 238 | CalculateTargetBounds(state_, &target_bounds); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 239 | GetLayer(shelf_)->SetOpacity(target_bounds.opacity); |
[email protected] | 14f5d0e | 2013-03-27 07:30:20 | [diff] [blame] | 240 | shelf_->SetWidgetBounds( |
[email protected] | ec1930c3 | 2012-07-19 23:57:42 | [diff] [blame] | 241 | ScreenAsh::ConvertRectToScreen( |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 242 | shelf_->GetNativeView()->parent(), |
| 243 | target_bounds.shelf_bounds_in_root)); |
| 244 | if (shelf_->launcher()) |
| 245 | shelf_->launcher()->SetLauncherViewBounds( |
| 246 | target_bounds.launcher_bounds_in_shelf); |
| 247 | GetLayer(shelf_->status_area_widget())->SetOpacity(target_bounds.opacity); |
| 248 | // TODO(harrym): Once status area widget is a child view of shelf |
| 249 | // this can be simplified. |
| 250 | gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; |
| 251 | status_bounds.set_x(status_bounds.x() + |
| 252 | target_bounds.shelf_bounds_in_root.x()); |
| 253 | status_bounds.set_y(status_bounds.y() + |
| 254 | target_bounds.shelf_bounds_in_root.y()); |
| 255 | shelf_->status_area_widget()->SetBounds( |
| 256 | ScreenAsh::ConvertRectToScreen( |
| 257 | shelf_->status_area_widget()->GetNativeView()->parent(), |
| 258 | status_bounds)); |
[email protected] | 2e236a5 | 2012-06-27 22:21:47 | [diff] [blame] | 259 | Shell::GetInstance()->SetDisplayWorkAreaInsets( |
[email protected] | b913a3a | 2012-12-11 13:07:19 | [diff] [blame] | 260 | root_window_, target_bounds.work_area_insets); |
[email protected] | 128fd373 | 2012-03-27 01:55:12 | [diff] [blame] | 261 | UpdateHitTestBounds(); |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 262 | } |
| 263 | |
[email protected] | 8e837ec | 2013-01-31 01:48:33 | [diff] [blame] | 264 | ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { |
| 265 | switch(auto_hide_behavior_) { |
| 266 | case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
| 267 | return SHELF_AUTO_HIDE; |
| 268 | case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
| 269 | return SHELF_VISIBLE; |
| 270 | case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: |
| 271 | return SHELF_HIDDEN; |
| 272 | } |
| 273 | return SHELF_VISIBLE; |
| 274 | } |
| 275 | |
| 276 | ShelfVisibilityState |
| 277 | ShelfLayoutManager::CalculateShelfVisibilityWhileDragging() { |
| 278 | switch(auto_hide_behavior_) { |
| 279 | case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
| 280 | case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
| 281 | return SHELF_AUTO_HIDE; |
| 282 | case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: |
| 283 | return SHELF_HIDDEN; |
| 284 | } |
| 285 | return SHELF_VISIBLE; |
| 286 | } |
| 287 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 288 | void ShelfLayoutManager::UpdateVisibilityState() { |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 289 | if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) { |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 290 | SetState(SHELF_VISIBLE); |
[email protected] | 4982ee1 | 2012-09-04 22:16:10 | [diff] [blame] | 291 | } else if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) { |
[email protected] | 8e837ec | 2013-01-31 01:48:33 | [diff] [blame] | 292 | // TODO(zelidrag): Verify shelf drag animation still shows on the device |
| 293 | // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. |
| 294 | SetState(CalculateShelfVisibilityWhileDragging()); |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 295 | } else { |
[email protected] | f4bb9fde | 2012-08-03 19:33:50 | [diff] [blame] | 296 | WorkspaceWindowState window_state(workspace_controller_->GetWindowState()); |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 297 | switch (window_state) { |
[email protected] | f4bb9fde | 2012-08-03 19:33:50 | [diff] [blame] | 298 | case WORKSPACE_WINDOW_STATE_FULL_SCREEN: |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 299 | { |
| 300 | aura::Window* fullscreen_window = |
| 301 | GetRootWindowController(root_window_)->GetFullscreenWindow(); |
| 302 | if (fullscreen_window->GetProperty(kFullscreenUsesMinimalChromeKey)) { |
| 303 | DCHECK_NE(auto_hide_behavior_, SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 304 | SetState(SHELF_AUTO_HIDE); |
| 305 | } else { |
| 306 | SetState(SHELF_HIDDEN); |
| 307 | } |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 308 | break; |
[email protected] | 700849f | 2013-04-30 17:49:20 | [diff] [blame] | 309 | } |
[email protected] | f4bb9fde | 2012-08-03 19:33:50 | [diff] [blame] | 310 | case WORKSPACE_WINDOW_STATE_MAXIMIZED: |
[email protected] | 8e837ec | 2013-01-31 01:48:33 | [diff] [blame] | 311 | SetState(CalculateShelfVisibility()); |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 312 | break; |
| 313 | |
[email protected] | f4bb9fde | 2012-08-03 19:33:50 | [diff] [blame] | 314 | case WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF: |
| 315 | case WORKSPACE_WINDOW_STATE_DEFAULT: |
[email protected] | 8e837ec | 2013-01-31 01:48:33 | [diff] [blame] | 316 | SetState(CalculateShelfVisibility()); |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 317 | SetWindowOverlapsShelf(window_state == |
[email protected] | f4bb9fde | 2012-08-03 19:33:50 | [diff] [blame] | 318 | WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF); |
[email protected] | e4d9fe9 | 2012-09-10 14:04:49 | [diff] [blame] | 319 | break; |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | void ShelfLayoutManager::UpdateAutoHideState() { |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 325 | ShelfAutoHideState auto_hide_state = |
[email protected] | cadd8c4 | 2012-03-27 02:44:31 | [diff] [blame] | 326 | CalculateAutoHideState(state_.visibility_state); |
| 327 | if (auto_hide_state != state_.auto_hide_state) { |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 328 | if (auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
[email protected] | cadd8c4 | 2012-03-27 02:44:31 | [diff] [blame] | 329 | // Hides happen immediately. |
| 330 | SetState(state_.visibility_state); |
[email protected] | 7841e117 | 2013-05-07 03:53:33 | [diff] [blame] | 331 | FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
[email protected] | cbc278f | 2012-07-10 03:40:21 | [diff] [blame] | 332 | OnAutoHideStateChanged(auto_hide_state)); |
[email protected] | cadd8c4 | 2012-03-27 02:44:31 | [diff] [blame] | 333 | } else { |
| 334 | auto_hide_timer_.Stop(); |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 335 | auto_hide_timer_.Start( |
| 336 | FROM_HERE, |
| 337 | base::TimeDelta::FromMilliseconds(kAutoHideDelayMS), |
| 338 | this, &ShelfLayoutManager::UpdateAutoHideStateNow); |
[email protected] | 7841e117 | 2013-05-07 03:53:33 | [diff] [blame] | 339 | FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 340 | OnAutoHideStateChanged( |
| 341 | CalculateAutoHideState(state_.visibility_state))); |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 342 | } |
| 343 | } else { |
| 344 | auto_hide_timer_.Stop(); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { |
| 349 | window_overlaps_shelf_ = value; |
[email protected] | 1fcfb99 | 2012-12-05 01:47:23 | [diff] [blame] | 350 | UpdateShelfBackground(BackgroundAnimator::CHANGE_ANIMATE); |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 351 | } |
| 352 | |
[email protected] | 7841e117 | 2013-05-07 03:53:33 | [diff] [blame] | 353 | void ShelfLayoutManager::AddObserver(ShelfLayoutManagerObserver* observer) { |
[email protected] | cbc278f | 2012-07-10 03:40:21 | [diff] [blame] | 354 | observers_.AddObserver(observer); |
| 355 | } |
| 356 | |
[email protected] | 7841e117 | 2013-05-07 03:53:33 | [diff] [blame] | 357 | void ShelfLayoutManager::RemoveObserver(ShelfLayoutManagerObserver* observer) { |
[email protected] | cbc278f | 2012-07-10 03:40:21 | [diff] [blame] | 358 | observers_.RemoveObserver(observer); |
| 359 | } |
| 360 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 361 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 362 | // ShelfLayoutManager, Gesture dragging: |
| 363 | |
| 364 | void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { |
| 365 | gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; |
| 366 | gesture_drag_amount_ = 0.f; |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 367 | gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE ? |
| 368 | auto_hide_state() : SHELF_AUTO_HIDE_SHOWN; |
[email protected] | 1fcfb99 | 2012-12-05 01:47:23 | [diff] [blame] | 369 | UpdateShelfBackground(BackgroundAnimator::CHANGE_ANIMATE); |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 370 | } |
| 371 | |
[email protected] | c8e2e83 | 2012-09-12 21:48:28 | [diff] [blame] | 372 | ShelfLayoutManager::DragState ShelfLayoutManager::UpdateGestureDrag( |
| 373 | const ui::GestureEvent& gesture) { |
[email protected] | 8572c487 | 2013-01-12 17:16:07 | [diff] [blame] | 374 | bool horizontal = IsHorizontalAlignment(); |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 375 | gesture_drag_amount_ += horizontal ? gesture.details().scroll_y() : |
| 376 | gesture.details().scroll_x(); |
| 377 | LayoutShelf(); |
[email protected] | c8e2e83 | 2012-09-12 21:48:28 | [diff] [blame] | 378 | |
| 379 | // Start reveling the status menu when: |
| 380 | // - dragging up on an already visible shelf |
| 381 | // - dragging up on a hidden shelf, but it is currently completely visible. |
| 382 | if (horizontal && gesture.details().scroll_y() < 0) { |
| 383 | int min_height = 0; |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 384 | if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && shelf_) |
| 385 | min_height = shelf_->GetContentsView()->GetPreferredSize().height(); |
[email protected] | c8e2e83 | 2012-09-12 21:48:28 | [diff] [blame] | 386 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 387 | if (min_height < shelf_->GetWindowBoundsInScreen().height() && |
[email protected] | 88d7112 | 2012-10-18 07:11:01 | [diff] [blame] | 388 | gesture.root_location().x() >= |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 389 | shelf_->status_area_widget()->GetWindowBoundsInScreen().x() && |
[email protected] | fd42270 | 2012-09-25 17:45:14 | [diff] [blame] | 390 | IsDraggingTrayEnabled()) |
[email protected] | c8e2e83 | 2012-09-12 21:48:28 | [diff] [blame] | 391 | return DRAG_TRAY; |
| 392 | } |
| 393 | |
| 394 | return DRAG_SHELF; |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 395 | } |
| 396 | |
[email protected] | 4982ee1 | 2012-09-04 22:16:10 | [diff] [blame] | 397 | void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { |
[email protected] | 8572c487 | 2013-01-12 17:16:07 | [diff] [blame] | 398 | bool horizontal = IsHorizontalAlignment(); |
[email protected] | 4982ee1 | 2012-09-04 22:16:10 | [diff] [blame] | 399 | bool should_change = false; |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 400 | if (gesture.type() == ui::ET_GESTURE_SCROLL_END) { |
[email protected] | 9bf222b | 2012-11-28 02:21:16 | [diff] [blame] | 401 | // The visibility of the shelf changes only if the shelf was dragged X% |
| 402 | // along the correct axis. If the shelf was already visible, then the |
| 403 | // direction of the drag does not matter. |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 404 | const float kDragHideThreshold = 0.4f; |
| 405 | gfx::Rect bounds = GetIdealBounds(); |
[email protected] | 9bf222b | 2012-11-28 02:21:16 | [diff] [blame] | 406 | float drag_ratio = fabs(gesture_drag_amount_) / |
| 407 | (horizontal ? bounds.height() : bounds.width()); |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 408 | if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { |
[email protected] | 9bf222b | 2012-11-28 02:21:16 | [diff] [blame] | 409 | should_change = drag_ratio > kDragHideThreshold; |
| 410 | } else { |
| 411 | bool correct_direction = false; |
[email protected] | 1fcfb99 | 2012-12-05 01:47:23 | [diff] [blame] | 412 | switch (alignment_) { |
[email protected] | 9bf222b | 2012-11-28 02:21:16 | [diff] [blame] | 413 | case SHELF_ALIGNMENT_BOTTOM: |
| 414 | case SHELF_ALIGNMENT_RIGHT: |
| 415 | correct_direction = gesture_drag_amount_ < 0; |
| 416 | break; |
| 417 | case SHELF_ALIGNMENT_LEFT: |
[email protected] | 8572c487 | 2013-01-12 17:16:07 | [diff] [blame] | 418 | case SHELF_ALIGNMENT_TOP: |
[email protected] | 9bf222b | 2012-11-28 02:21:16 | [diff] [blame] | 419 | correct_direction = gesture_drag_amount_ > 0; |
| 420 | break; |
| 421 | } |
| 422 | should_change = correct_direction && drag_ratio > kDragHideThreshold; |
| 423 | } |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 424 | } else if (gesture.type() == ui::ET_SCROLL_FLING_START) { |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 425 | if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { |
[email protected] | 9bf222b | 2012-11-28 02:21:16 | [diff] [blame] | 426 | should_change = horizontal ? fabs(gesture.details().velocity_y()) > 0 : |
| 427 | fabs(gesture.details().velocity_x()) > 0; |
| 428 | } else { |
[email protected] | 8572c487 | 2013-01-12 17:16:07 | [diff] [blame] | 429 | should_change = SelectValueForShelfAlignment( |
| 430 | gesture.details().velocity_y() < 0, |
| 431 | gesture.details().velocity_x() > 0, |
| 432 | gesture.details().velocity_x() < 0, |
| 433 | gesture.details().velocity_y() > 0); |
[email protected] | 9bf222b | 2012-11-28 02:21:16 | [diff] [blame] | 434 | } |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 435 | } else { |
| 436 | NOTREACHED(); |
| 437 | } |
| 438 | |
[email protected] | 4982ee1 | 2012-09-04 22:16:10 | [diff] [blame] | 439 | if (!should_change) { |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 440 | CancelGestureDrag(); |
| 441 | return; |
| 442 | } |
| 443 | |
[email protected] | 4982ee1 | 2012-09-04 22:16:10 | [diff] [blame] | 444 | gesture_drag_auto_hide_state_ = |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 445 | gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN ? |
| 446 | SHELF_AUTO_HIDE_HIDDEN : SHELF_AUTO_HIDE_SHOWN; |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 447 | if (shelf_) |
| 448 | shelf_->Deactivate(); |
| 449 | shelf_->status_area_widget()->Deactivate(); |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 450 | if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
[email protected] | e10392c | 2012-09-11 21:13:08 | [diff] [blame] | 451 | auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS) { |
| 452 | gesture_drag_status_ = GESTURE_DRAG_NONE; |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 453 | SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 454 | } else if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN && |
[email protected] | e10392c | 2012-09-11 21:13:08 | [diff] [blame] | 455 | auto_hide_behavior_ != SHELF_AUTO_HIDE_BEHAVIOR_NEVER) { |
| 456 | gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 457 | SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 458 | } else { |
| 459 | gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 460 | UpdateVisibilityState(); |
[email protected] | e10392c | 2012-09-11 21:13:08 | [diff] [blame] | 461 | gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 462 | } |
[email protected] | c3371c2 | 2013-04-18 04:42:23 | [diff] [blame] | 463 | LayoutShelf(); |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | void ShelfLayoutManager::CancelGestureDrag() { |
[email protected] | e10392c | 2012-09-11 21:13:08 | [diff] [blame] | 467 | gesture_drag_status_ = GESTURE_DRAG_NONE; |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 468 | ui::ScopedLayerAnimationSettings |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 469 | launcher_settings(GetLayer(shelf_)->GetAnimator()), |
| 470 | status_settings(GetLayer(shelf_->status_area_widget())->GetAnimator()); |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 471 | LayoutShelf(); |
| 472 | UpdateVisibilityState(); |
[email protected] | 1fcfb99 | 2012-12-05 01:47:23 | [diff] [blame] | 473 | UpdateShelfBackground(BackgroundAnimator::CHANGE_ANIMATE); |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 477 | // ShelfLayoutManager, aura::LayoutManager implementation: |
| 478 | |
| 479 | void ShelfLayoutManager::OnWindowResized() { |
| 480 | LayoutShelf(); |
| 481 | } |
| 482 | |
| 483 | void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 484 | } |
| 485 | |
| 486 | void ShelfLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { |
| 487 | } |
| 488 | |
[email protected] | fa893ab6 | 2012-04-20 01:26:51 | [diff] [blame] | 489 | void ShelfLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
| 490 | } |
| 491 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 492 | void ShelfLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, |
| 493 | bool visible) { |
| 494 | } |
| 495 | |
| 496 | void ShelfLayoutManager::SetChildBounds(aura::Window* child, |
| 497 | const gfx::Rect& requested_bounds) { |
| 498 | SetChildBoundsDirect(child, requested_bounds); |
[email protected] | 9d9b320 | 2012-09-09 22:39:32 | [diff] [blame] | 499 | // We may contain other widgets (such as frame maximize bubble) but they don't |
| 500 | // effect the layout in anyway. |
| 501 | if (!in_layout_ && |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 502 | ((shelf_->GetNativeView() == child) || |
| 503 | (shelf_->status_area_widget()->GetNativeView() == child))) { |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 504 | LayoutShelf(); |
[email protected] | 9d9b320 | 2012-09-09 22:39:32 | [diff] [blame] | 505 | } |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 506 | } |
| 507 | |
[email protected] | 8e43cdf4 | 2012-05-11 17:03:31 | [diff] [blame] | 508 | void ShelfLayoutManager::OnLockStateChanged(bool locked) { |
| 509 | UpdateVisibilityState(); |
| 510 | } |
| 511 | |
[email protected] | 1ae36165 | 2012-12-12 22:39:51 | [diff] [blame] | 512 | void ShelfLayoutManager::OnWindowActivated(aura::Window* gained_active, |
| 513 | aura::Window* lost_active) { |
[email protected] | e76310a9 | 2012-06-04 19:06:11 | [diff] [blame] | 514 | UpdateAutoHideStateNow(); |
[email protected] | 8676f047 | 2012-03-29 20:30:12 | [diff] [blame] | 515 | } |
| 516 | |
[email protected] | 1fcfb99 | 2012-12-05 01:47:23 | [diff] [blame] | 517 | bool ShelfLayoutManager::IsHorizontalAlignment() const { |
[email protected] | 8572c487 | 2013-01-12 17:16:07 | [diff] [blame] | 518 | return alignment_ == SHELF_ALIGNMENT_BOTTOM || |
| 519 | alignment_ == SHELF_ALIGNMENT_TOP; |
[email protected] | 1fcfb99 | 2012-12-05 01:47:23 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | // static |
| 523 | ShelfLayoutManager* ShelfLayoutManager::ForLauncher(aura::Window* window) { |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 524 | ShelfWidget* shelf = RootWindowController::ForLauncher(window)->shelf(); |
| 525 | return shelf ? shelf->shelf_layout_manager() : NULL; |
[email protected] | 1fcfb99 | 2012-12-05 01:47:23 | [diff] [blame] | 526 | } |
| 527 | |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 528 | //////////////////////////////////////////////////////////////////////////////// |
| 529 | // ShelfLayoutManager, private: |
| 530 | |
[email protected] | 9e52129b9 | 2012-08-09 16:14:30 | [diff] [blame] | 531 | ShelfLayoutManager::TargetBounds::TargetBounds() : opacity(0.0f) {} |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 532 | ShelfLayoutManager::TargetBounds::~TargetBounds() {} |
[email protected] | 9e52129b9 | 2012-08-09 16:14:30 | [diff] [blame] | 533 | |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 534 | void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { |
[email protected] | b920e7d | 2013-04-19 03:29:35 | [diff] [blame] | 535 | if (!shelf_->GetNativeView()) |
| 536 | return; |
| 537 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 538 | State state; |
[email protected] | c758fbf | 2012-03-25 22:53:59 | [diff] [blame] | 539 | state.visibility_state = visibility_state; |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 540 | state.auto_hide_state = CalculateAutoHideState(visibility_state); |
[email protected] | fcb123d | 2013-04-17 15:58:49 | [diff] [blame] | 541 | state.is_screen_locked = |
| 542 | Shell::GetInstance()->session_state_delegate()->IsScreenLocked(); |
[email protected] | 30676816 | 2012-02-02 02:04:41 | [diff] [blame] | 543 | |
[email protected] | b7d0812 | 2012-09-16 18:24:46 | [diff] [blame] | 544 | // It's possible for SetState() when a window becomes maximized but the state |
| 545 | // won't have changed value. Do the dimming check before the early exit. |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 546 | if (workspace_controller_) { |
| 547 | shelf_->SetDimsShelf( |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 548 | (state.visibility_state == SHELF_VISIBLE) && |
[email protected] | b7d0812 | 2012-09-16 18:24:46 | [diff] [blame] | 549 | workspace_controller_->GetWindowState() == |
| 550 | WORKSPACE_WINDOW_STATE_MAXIMIZED); |
| 551 | } |
| 552 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 553 | if (state_.Equals(state)) |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 554 | return; // Nothing changed. |
| 555 | |
[email protected] | 7841e117 | 2013-05-07 03:53:33 | [diff] [blame] | 556 | FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
[email protected] | cbc278f | 2012-07-10 03:40:21 | [diff] [blame] | 557 | WillChangeVisibilityState(visibility_state)); |
| 558 | |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 559 | if (state.visibility_state == SHELF_AUTO_HIDE) { |
| 560 | // When state is SHELF_AUTO_HIDE we need to track when the mouse is over the |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 561 | // launcher to unhide the shelf. AutoHideEventFilter does that for us. |
[email protected] | 7f7f65c | 2013-04-17 16:47:13 | [diff] [blame] | 562 | if (!event_filter_) |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 563 | event_filter_.reset(new AutoHideEventFilter(this)); |
| 564 | } else { |
| 565 | event_filter_.reset(NULL); |
| 566 | } |
| 567 | |
| 568 | auto_hide_timer_.Stop(); |
| 569 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 570 | // Animating the background when transitioning from auto-hide & hidden to |
[email protected] | e4d9fe9 | 2012-09-10 14:04:49 | [diff] [blame] | 571 | // visible is janky. Update the background immediately in this case. |
[email protected] | 1fcfb99 | 2012-12-05 01:47:23 | [diff] [blame] | 572 | BackgroundAnimator::ChangeType change_type = |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 573 | (state_.visibility_state == SHELF_AUTO_HIDE && |
| 574 | state_.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && |
| 575 | state.visibility_state == SHELF_VISIBLE) ? |
[email protected] | 1fcfb99 | 2012-12-05 01:47:23 | [diff] [blame] | 576 | BackgroundAnimator::CHANGE_IMMEDIATE : BackgroundAnimator::CHANGE_ANIMATE; |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 577 | StopAnimating(); |
[email protected] | e10392c | 2012-09-11 21:13:08 | [diff] [blame] | 578 | |
| 579 | State old_state = state_; |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 580 | state_ = state; |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 581 | TargetBounds target_bounds; |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 582 | CalculateTargetBounds(state_, &target_bounds); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 583 | |
| 584 | ui::ScopedLayerAnimationSettings launcher_animation_setter( |
| 585 | GetLayer(shelf_)->GetAnimator()); |
| 586 | launcher_animation_setter.SetTransitionDuration( |
| 587 | base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); |
| 588 | launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT); |
| 589 | GetLayer(shelf_)->SetBounds( |
| 590 | target_bounds.shelf_bounds_in_root); |
| 591 | GetLayer(shelf_)->SetOpacity(target_bounds.opacity); |
[email protected] | 30676816 | 2012-02-02 02:04:41 | [diff] [blame] | 592 | ui::ScopedLayerAnimationSettings status_animation_setter( |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 593 | GetLayer(shelf_->status_area_widget())->GetAnimator()); |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 594 | status_animation_setter.SetTransitionDuration( |
[email protected] | c96b981 | 2012-10-17 16:04:04 | [diff] [blame] | 595 | base::TimeDelta::FromMilliseconds(kWorkspaceSwitchTimeMS)); |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 596 | status_animation_setter.SetTweenType(ui::Tween::EASE_OUT); |
[email protected] | e10392c | 2012-09-11 21:13:08 | [diff] [blame] | 597 | |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 598 | // Delay updating the background when going from SHELF_AUTO_HIDE_SHOWN to |
| 599 | // SHELF_AUTO_HIDE_HIDDEN until the shelf animates out. Otherwise during the |
[email protected] | e4d9fe9 | 2012-09-10 14:04:49 | [diff] [blame] | 600 | // animation you see the background change. |
[email protected] | e10392c | 2012-09-11 21:13:08 | [diff] [blame] | 601 | // Also delay the animation when the shelf was hidden, and has just been made |
| 602 | // visible (e.g. using a gesture-drag). |
| 603 | bool delay_shelf_update = |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 604 | state.visibility_state == SHELF_AUTO_HIDE && |
| 605 | state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && |
| 606 | old_state.visibility_state == SHELF_AUTO_HIDE; |
[email protected] | e10392c | 2012-09-11 21:13:08 | [diff] [blame] | 607 | |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 608 | if (state.visibility_state == SHELF_VISIBLE && |
| 609 | old_state.visibility_state == SHELF_AUTO_HIDE && |
| 610 | old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) |
[email protected] | e10392c | 2012-09-11 21:13:08 | [diff] [blame] | 611 | delay_shelf_update = true; |
| 612 | |
[email protected] | e4d9fe9 | 2012-09-10 14:04:49 | [diff] [blame] | 613 | if (delay_shelf_update) { |
| 614 | if (update_shelf_observer_) |
| 615 | update_shelf_observer_->Detach(); |
| 616 | // UpdateShelfBackground deletes itself when the animation is done. |
| 617 | update_shelf_observer_ = new UpdateShelfObserver(this); |
| 618 | status_animation_setter.AddObserver(update_shelf_observer_); |
| 619 | } |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 620 | ui::Layer* layer = GetLayer(shelf_->status_area_widget()); |
| 621 | // TODO(harrym): Remove when status_area is view (crbug.com/180422). |
| 622 | gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; |
| 623 | status_bounds.set_x(status_bounds.x() + |
| 624 | target_bounds.shelf_bounds_in_root.x()); |
| 625 | status_bounds.set_y(status_bounds.y() + |
| 626 | target_bounds.shelf_bounds_in_root.y()); |
| 627 | layer->SetBounds(status_bounds); |
[email protected] | 88d7112 | 2012-10-18 07:11:01 | [diff] [blame] | 628 | layer->SetOpacity(target_bounds.opacity); |
[email protected] | 2e236a5 | 2012-06-27 22:21:47 | [diff] [blame] | 629 | Shell::GetInstance()->SetDisplayWorkAreaInsets( |
[email protected] | b913a3a | 2012-12-11 13:07:19 | [diff] [blame] | 630 | root_window_, target_bounds.work_area_insets); |
[email protected] | 128fd373 | 2012-03-27 01:55:12 | [diff] [blame] | 631 | UpdateHitTestBounds(); |
[email protected] | e4d9fe9 | 2012-09-10 14:04:49 | [diff] [blame] | 632 | if (!delay_shelf_update) |
| 633 | UpdateShelfBackground(change_type); |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 634 | } |
[email protected] | 63ef2159 | 2012-03-21 01:15:40 | [diff] [blame] | 635 | |
[email protected] | 4bb1650 | 2011-12-06 14:44:58 | [diff] [blame] | 636 | void ShelfLayoutManager::StopAnimating() { |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 637 | GetLayer(shelf_)->GetAnimator()->StopAnimating(); |
| 638 | GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 639 | } |
| 640 | |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 641 | void ShelfLayoutManager::GetShelfSize(int* width, int* height) { |
| 642 | *width = *height = 0; |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 643 | gfx::Size status_size( |
| 644 | shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); |
[email protected] | 8572c487 | 2013-01-12 17:16:07 | [diff] [blame] | 645 | if (IsHorizontalAlignment()) |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 646 | *height = std::max(kLauncherPreferredSize, status_size.height()); |
[email protected] | 0ab08e5 | 2012-05-19 00:04:21 | [diff] [blame] | 647 | else |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 648 | *width = std::max(kLauncherPreferredSize, status_size.width()); |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, |
| 652 | gfx::Rect* bounds) const { |
[email protected] | 8572c487 | 2013-01-12 17:16:07 | [diff] [blame] | 653 | bounds->Inset(SelectValueForShelfAlignment( |
| 654 | gfx::Insets(0, 0, inset, 0), |
| 655 | gfx::Insets(0, inset, 0, 0), |
| 656 | gfx::Insets(0, 0, 0, inset), |
| 657 | gfx::Insets(inset, 0, 0, 0))); |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 658 | } |
| 659 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 660 | void ShelfLayoutManager::CalculateTargetBounds( |
| 661 | const State& state, |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 662 | TargetBounds* target_bounds) { |
[email protected] | 5416f28 | 2013-04-29 20:52:48 | [diff] [blame] | 663 | const gfx::Rect available_bounds(GetAvailableBounds()); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 664 | gfx::Rect status_size( |
| 665 | shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 666 | int shelf_width = 0, shelf_height = 0; |
| 667 | GetShelfSize(&shelf_width, &shelf_height); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 668 | if (IsHorizontalAlignment()) |
| 669 | shelf_width = available_bounds.width(); |
| 670 | else |
| 671 | shelf_height = available_bounds.height(); |
| 672 | |
| 673 | if (state.visibility_state == SHELF_AUTO_HIDE && |
| 674 | state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
[email protected] | 17da26a8 | 2013-04-09 21:20:32 | [diff] [blame] | 675 | // Auto-hidden shelf always starts with the default size. If a gesture-drag |
| 676 | // is in progress, then the call to UpdateTargetBoundsForGesture() below |
| 677 | // takes care of setting the height properly. |
| 678 | if (IsHorizontalAlignment()) |
| 679 | shelf_height = kAutoHideSize; |
| 680 | else |
| 681 | shelf_width = kAutoHideSize; |
[email protected] | 5416f28 | 2013-04-29 20:52:48 | [diff] [blame] | 682 | } else if (state.visibility_state == SHELF_HIDDEN || |
| 683 | !keyboard_bounds_.IsEmpty()) { |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 684 | if (IsHorizontalAlignment()) |
| 685 | shelf_height = 0; |
| 686 | else |
| 687 | shelf_width = 0; |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 688 | } |
[email protected] | 17da26a8 | 2013-04-09 21:20:32 | [diff] [blame] | 689 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 690 | target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( |
| 691 | gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height, |
| 692 | available_bounds.width(), shelf_height), |
| 693 | gfx::Rect(available_bounds.x(), available_bounds.y(), |
| 694 | shelf_width, available_bounds.height()), |
| 695 | gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), |
| 696 | shelf_width, available_bounds.height()), |
| 697 | gfx::Rect(available_bounds.x(), available_bounds.y(), |
| 698 | available_bounds.width(), shelf_height)); |
| 699 | |
| 700 | int status_inset = (kLauncherPreferredSize - |
| 701 | PrimaryAxisValue(status_size.height(), status_size.width())); |
| 702 | |
| 703 | target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( |
| 704 | gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
| 705 | status_inset, status_size.width(), status_size.height()), |
| 706 | gfx::Rect(shelf_width - (status_size.width() + status_inset), |
| 707 | shelf_height - status_size.height(), status_size.width(), |
| 708 | status_size.height()), |
| 709 | gfx::Rect(status_inset, shelf_height - status_size.height(), |
| 710 | status_size.width(), status_size.height()), |
| 711 | gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), |
| 712 | shelf_height - (status_size.height() + status_inset), |
| 713 | status_size.width(), status_size.height())); |
| 714 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 715 | target_bounds->work_area_insets = SelectValueForShelfAlignment( |
| 716 | gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0), |
| 717 | gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0), |
| 718 | gfx::Insets(0, 0, 0, GetWorkAreaSize(state, shelf_width)), |
| 719 | gfx::Insets(GetWorkAreaSize(state, shelf_height), 0, 0, 0)); |
| 720 | |
[email protected] | 5416f28 | 2013-04-29 20:52:48 | [diff] [blame] | 721 | // Also push in the work area inset for the keyboard if it is visible. |
| 722 | if (!keyboard_bounds_.IsEmpty()) { |
| 723 | target_bounds->work_area_insets.Set( |
| 724 | target_bounds->work_area_insets.top(), |
| 725 | target_bounds->work_area_insets.left(), |
| 726 | target_bounds->work_area_insets.bottom() + keyboard_bounds_.height(), |
| 727 | target_bounds->work_area_insets.right()); |
| 728 | } |
| 729 | |
[email protected] | 27f6af6 | 2012-03-21 05:34:40 | [diff] [blame] | 730 | target_bounds->opacity = |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 731 | (gesture_drag_status_ != GESTURE_DRAG_NONE || |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 732 | state.visibility_state == SHELF_VISIBLE || |
| 733 | state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; |
[email protected] | 17da26a8 | 2013-04-09 21:20:32 | [diff] [blame] | 734 | |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 735 | if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS) |
| 736 | UpdateTargetBoundsForGesture(target_bounds); |
[email protected] | 17da26a8 | 2013-04-09 21:20:32 | [diff] [blame] | 737 | |
| 738 | // This needs to happen after calling UpdateTargetBoundsForGesture(), because |
| 739 | // that can change the size of the shelf. |
| 740 | target_bounds->launcher_bounds_in_shelf = SelectValueForShelfAlignment( |
| 741 | gfx::Rect(base::i18n::IsRTL() ? status_size.width() : 0, 0, |
| 742 | shelf_width - status_size.width(), |
| 743 | target_bounds->shelf_bounds_in_root.height()), |
| 744 | gfx::Rect(0, 0, shelf_width, shelf_height - status_size.height()), |
| 745 | gfx::Rect(0, 0, shelf_width, shelf_height - status_size.height()), |
| 746 | gfx::Rect(base::i18n::IsRTL() ? status_size.width() : 0, 0, |
| 747 | shelf_width - status_size.width(), |
| 748 | target_bounds->shelf_bounds_in_root.height())); |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | void ShelfLayoutManager::UpdateTargetBoundsForGesture( |
| 752 | TargetBounds* target_bounds) const { |
| 753 | CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); |
[email protected] | 8572c487 | 2013-01-12 17:16:07 | [diff] [blame] | 754 | bool horizontal = IsHorizontalAlignment(); |
[email protected] | 7d1d2d2 | 2013-03-24 04:25:57 | [diff] [blame] | 755 | const gfx::Rect& available_bounds(root_window_->bounds()); |
[email protected] | 407ffd3 | 2012-09-11 17:47:36 | [diff] [blame] | 756 | int resistance_free_region = 0; |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 757 | |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 758 | if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
| 759 | visibility_state() == SHELF_AUTO_HIDE && |
| 760 | auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
[email protected] | c8e2e83 | 2012-09-12 21:48:28 | [diff] [blame] | 761 | // If the shelf was hidden when the drag started (and the state hasn't |
| 762 | // changed since then, e.g. because the tray-menu was shown because of the |
| 763 | // drag), then allow the drag some resistance-free region at first to make |
| 764 | // sure the shelf sticks with the finger until the shelf is visible. |
[email protected] | 7d1d2d2 | 2013-03-24 04:25:57 | [diff] [blame] | 765 | resistance_free_region = kLauncherPreferredSize - kAutoHideSize; |
[email protected] | 91d966a7 | 2012-09-06 03:42:27 | [diff] [blame] | 766 | } |
| 767 | |
[email protected] | 8572c487 | 2013-01-12 17:16:07 | [diff] [blame] | 768 | bool resist = SelectValueForShelfAlignment( |
| 769 | gesture_drag_amount_ < -resistance_free_region, |
| 770 | gesture_drag_amount_ > resistance_free_region, |
| 771 | gesture_drag_amount_ < -resistance_free_region, |
| 772 | gesture_drag_amount_ > resistance_free_region); |
[email protected] | 91d966a7 | 2012-09-06 03:42:27 | [diff] [blame] | 773 | |
| 774 | float translate = 0.f; |
| 775 | if (resist) { |
| 776 | float diff = fabsf(gesture_drag_amount_) - resistance_free_region; |
[email protected] | 407ffd3 | 2012-09-11 17:47:36 | [diff] [blame] | 777 | diff = std::min(diff, sqrtf(diff)); |
[email protected] | 91d966a7 | 2012-09-06 03:42:27 | [diff] [blame] | 778 | if (gesture_drag_amount_ < 0) |
| 779 | translate = -resistance_free_region - diff; |
| 780 | else |
| 781 | translate = resistance_free_region + diff; |
[email protected] | 4982ee1 | 2012-09-04 22:16:10 | [diff] [blame] | 782 | } else { |
[email protected] | 91d966a7 | 2012-09-06 03:42:27 | [diff] [blame] | 783 | translate = gesture_drag_amount_; |
[email protected] | 4982ee1 | 2012-09-04 22:16:10 | [diff] [blame] | 784 | } |
| 785 | |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 786 | if (horizontal) { |
[email protected] | 7d1d2d2 | 2013-03-24 04:25:57 | [diff] [blame] | 787 | // Move and size the launcher with the gesture. |
[email protected] | 17da26a8 | 2013-04-09 21:20:32 | [diff] [blame] | 788 | int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; |
| 789 | shelf_height = std::max(shelf_height, kAutoHideSize); |
| 790 | target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
[email protected] | 7d1d2d2 | 2013-03-24 04:25:57 | [diff] [blame] | 791 | if (alignment_ == SHELF_ALIGNMENT_BOTTOM) { |
[email protected] | 17da26a8 | 2013-04-09 21:20:32 | [diff] [blame] | 792 | target_bounds->shelf_bounds_in_root.set_y( |
| 793 | available_bounds.bottom() - shelf_height); |
[email protected] | 91d966a7 | 2012-09-06 03:42:27 | [diff] [blame] | 794 | } |
[email protected] | 7d1d2d2 | 2013-03-24 04:25:57 | [diff] [blame] | 795 | |
| 796 | // The statusbar should be in the center of the shelf. |
| 797 | gfx::Rect status_y = target_bounds->shelf_bounds_in_root; |
| 798 | status_y.set_y(0); |
| 799 | status_y.ClampToCenteredSize( |
| 800 | target_bounds->status_bounds_in_shelf.size()); |
| 801 | target_bounds->status_bounds_in_shelf.set_y(status_y.y()); |
| 802 | } else { |
| 803 | // Move and size the launcher with the gesture. |
[email protected] | 17da26a8 | 2013-04-09 21:20:32 | [diff] [blame] | 804 | int shelf_width = target_bounds->shelf_bounds_in_root.width() - translate; |
| 805 | shelf_width = std::max(shelf_width, kAutoHideSize); |
| 806 | target_bounds->shelf_bounds_in_root.set_width(shelf_width); |
[email protected] | 7d1d2d2 | 2013-03-24 04:25:57 | [diff] [blame] | 807 | if (alignment_ == SHELF_ALIGNMENT_RIGHT) { |
[email protected] | 17da26a8 | 2013-04-09 21:20:32 | [diff] [blame] | 808 | target_bounds->shelf_bounds_in_root.set_y( |
| 809 | available_bounds.right() - shelf_width); |
[email protected] | 7d1d2d2 | 2013-03-24 04:25:57 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | // The statusbar should be in the center of the shelf. |
| 813 | gfx::Rect status_x = target_bounds->shelf_bounds_in_root; |
| 814 | status_x.set_x(0); |
| 815 | status_x.ClampToCenteredSize( |
| 816 | target_bounds->status_bounds_in_shelf.size()); |
| 817 | target_bounds->status_bounds_in_shelf.set_x(status_x.x()); |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 818 | } |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 819 | } |
| 820 | |
[email protected] | a160baec | 2012-03-21 20:52:15 | [diff] [blame] | 821 | void ShelfLayoutManager::UpdateShelfBackground( |
| 822 | BackgroundAnimator::ChangeType type) { |
| 823 | bool launcher_paints = GetLauncherPaintsBackground(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 824 | shelf_->SetPaintsBackground(launcher_paints, type); |
[email protected] | a160baec | 2012-03-21 20:52:15 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | bool ShelfLayoutManager::GetLauncherPaintsBackground() const { |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 828 | return gesture_drag_status_ != GESTURE_DRAG_NONE || |
| 829 | (!state_.is_screen_locked && window_overlaps_shelf_) || |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 830 | (state_.visibility_state == SHELF_AUTO_HIDE) ; |
[email protected] | ae18b911 | 2011-11-07 16:59:13 | [diff] [blame] | 831 | } |
| 832 | |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 833 | void ShelfLayoutManager::UpdateAutoHideStateNow() { |
| 834 | SetState(state_.visibility_state); |
| 835 | } |
| 836 | |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 837 | ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( |
| 838 | ShelfVisibilityState visibility_state) const { |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 839 | if (visibility_state != SHELF_AUTO_HIDE || !shelf_) |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 840 | return SHELF_AUTO_HIDE_HIDDEN; |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 841 | |
[email protected] | 4982ee1 | 2012-09-04 22:16:10 | [diff] [blame] | 842 | if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) |
| 843 | return gesture_drag_auto_hide_state_; |
[email protected] | 3c6abbe | 2012-08-30 23:48:57 | [diff] [blame] | 844 | |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 845 | Shell* shell = Shell::GetInstance(); |
[email protected] | 7510d108 | 2012-03-30 21:58:34 | [diff] [blame] | 846 | if (shell->GetAppListTargetVisibility()) |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 847 | return SHELF_AUTO_HIDE_SHOWN; |
[email protected] | 7510d108 | 2012-03-30 21:58:34 | [diff] [blame] | 848 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 849 | if (shelf_->status_area_widget() && |
| 850 | shelf_->status_area_widget()->ShouldShowLauncher()) |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 851 | return SHELF_AUTO_HIDE_SHOWN; |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 852 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 853 | if (shelf_->launcher() && shelf_->launcher()->IsShowingMenu()) |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 854 | return SHELF_AUTO_HIDE_SHOWN; |
[email protected] | e9992b1 | 2012-03-27 00:11:27 | [diff] [blame] | 855 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 856 | if (shelf_->launcher() && shelf_->launcher()->IsShowingOverflowBubble()) |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 857 | return SHELF_AUTO_HIDE_SHOWN; |
[email protected] | 3475f5e | 2012-07-12 22:10:32 | [diff] [blame] | 858 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 859 | if (shelf_->IsActive() || shelf_->status_area_widget()->IsActive()) |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 860 | return SHELF_AUTO_HIDE_SHOWN; |
[email protected] | 8676f047 | 2012-03-29 20:30:12 | [diff] [blame] | 861 | |
[email protected] | 5f1d99dc | 2012-04-12 21:42:37 | [diff] [blame] | 862 | // Don't show if the user is dragging the mouse. |
| 863 | if (event_filter_.get() && event_filter_->in_mouse_drag()) |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 864 | return SHELF_AUTO_HIDE_HIDDEN; |
[email protected] | 5f1d99dc | 2012-04-12 21:42:37 | [diff] [blame] | 865 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 866 | gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); |
| 867 | if (shelf_->status_area_widget() && |
| 868 | shelf_->status_area_widget()->IsMessageBubbleShown() && |
[email protected] | 2e195f5 | 2012-09-22 00:24:46 | [diff] [blame] | 869 | IsVisible()) { |
| 870 | // Increase the the hit test area to prevent the shelf from disappearing |
| 871 | // when the mouse is over the bubble gap. |
| 872 | shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? |
| 873 | -kNotificationBubbleGapHeight : 0, |
| 874 | alignment_ == SHELF_ALIGNMENT_BOTTOM ? |
| 875 | -kNotificationBubbleGapHeight : 0, |
| 876 | alignment_ == SHELF_ALIGNMENT_LEFT ? |
| 877 | -kNotificationBubbleGapHeight : 0, |
[email protected] | 8572c487 | 2013-01-12 17:16:07 | [diff] [blame] | 878 | alignment_ == SHELF_ALIGNMENT_TOP ? |
| 879 | -kNotificationBubbleGapHeight : 0); |
[email protected] | 2e195f5 | 2012-09-22 00:24:46 | [diff] [blame] | 880 | } |
[email protected] | ca8f905b | 2013-01-22 21:53:25 | [diff] [blame] | 881 | |
| 882 | if (shelf_region.Contains(Shell::GetScreen()->GetCursorScreenPoint())) |
| 883 | return SHELF_AUTO_HIDE_SHOWN; |
| 884 | |
| 885 | const std::vector<aura::Window*> windows = |
[email protected] | 3f540b4 | 2013-03-26 07:43:18 | [diff] [blame] | 886 | ash::WindowCycleController::BuildWindowList(NULL, false); |
[email protected] | ca8f905b | 2013-01-22 21:53:25 | [diff] [blame] | 887 | |
| 888 | // Process the window list and check if there are any visible windows. |
| 889 | for (size_t i = 0; i < windows.size(); ++i) { |
| 890 | if (windows[i] && windows[i]->IsVisible() && |
[email protected] | 0dd0772 | 2013-04-12 23:07:43 | [diff] [blame] | 891 | !ash::wm::IsWindowMinimized(windows[i]) && |
| 892 | root_window_ == windows[i]->GetRootWindow()) |
[email protected] | ca8f905b | 2013-01-22 21:53:25 | [diff] [blame] | 893 | return SHELF_AUTO_HIDE_HIDDEN; |
| 894 | } |
| 895 | |
| 896 | // If there are no visible windows do not hide the shelf. |
| 897 | return SHELF_AUTO_HIDE_SHOWN; |
[email protected] | b1c37fc | 2012-03-22 03:36:13 | [diff] [blame] | 898 | } |
| 899 | |
[email protected] | 128fd373 | 2012-03-27 01:55:12 | [diff] [blame] | 900 | void ShelfLayoutManager::UpdateHitTestBounds() { |
[email protected] | d3643b5 | 2013-05-01 16:00:48 | [diff] [blame] | 901 | gfx::Insets mouse_insets; |
| 902 | gfx::Insets touch_insets; |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 903 | if (state_.visibility_state == SHELF_VISIBLE) { |
[email protected] | 128fd373 | 2012-03-27 01:55:12 | [diff] [blame] | 904 | // Let clicks at the very top of the launcher through so windows can be |
| 905 | // resized with the bottom-right corner and bottom edge. |
[email protected] | d3643b5 | 2013-05-01 16:00:48 | [diff] [blame] | 906 | mouse_insets = GetInsetsForAlignment(kWorkspaceAreaVisibleInset); |
| 907 | } else if (state_.visibility_state == SHELF_AUTO_HIDE) { |
| 908 | // Extend the touch hit target out a bit to allow users to drag shelf out |
| 909 | // while hidden. |
| 910 | touch_insets = GetInsetsForAlignment(-kWorkspaceAreaAutoHideInset); |
[email protected] | 128fd373 | 2012-03-27 01:55:12 | [diff] [blame] | 911 | } |
[email protected] | d3643b5 | 2013-05-01 16:00:48 | [diff] [blame] | 912 | |
| 913 | if (shelf_ && shelf_->GetNativeWindow()) |
| 914 | shelf_->GetNativeWindow()->SetHitTestBoundsOverrideOuter(mouse_insets, |
| 915 | touch_insets); |
| 916 | shelf_->status_area_widget()->GetNativeWindow()-> |
| 917 | SetHitTestBoundsOverrideOuter(mouse_insets, touch_insets); |
[email protected] | 128fd373 | 2012-03-27 01:55:12 | [diff] [blame] | 918 | } |
| 919 | |
[email protected] | 5f1d99dc | 2012-04-12 21:42:37 | [diff] [blame] | 920 | bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) { |
| 921 | if (!window) |
| 922 | return false; |
[email protected] | bb0c7cd4 | 2013-05-20 23:39:45 | [diff] [blame^] | 923 | return (shelf_ && shelf_->GetNativeWindow()->Contains(window)) || |
| 924 | (shelf_->status_area_widget() && |
| 925 | shelf_->status_area_widget()->GetNativeWindow()->Contains(window)); |
[email protected] | 5f1d99dc | 2012-04-12 21:42:37 | [diff] [blame] | 926 | } |
| 927 | |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 928 | int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 929 | if (state.visibility_state == SHELF_VISIBLE) |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 930 | return size; |
[email protected] | ef80e430 | 2012-12-04 19:37:31 | [diff] [blame] | 931 | if (state.visibility_state == SHELF_AUTO_HIDE) |
[email protected] | 5544450 | 2012-05-10 15:43:53 | [diff] [blame] | 932 | return kAutoHideSize; |
| 933 | return 0; |
| 934 | } |
| 935 | |
[email protected] | 5416f28 | 2013-04-29 20:52:48 | [diff] [blame] | 936 | gfx::Rect ShelfLayoutManager::GetAvailableBounds() const { |
| 937 | gfx::Rect bounds(root_window_->bounds()); |
| 938 | bounds.set_height(bounds.height() - keyboard_bounds_.height()); |
| 939 | return bounds; |
| 940 | } |
| 941 | |
| 942 | void ShelfLayoutManager::OnKeyboardBoundsChanging( |
| 943 | const gfx::Rect& keyboard_bounds) { |
| 944 | keyboard_bounds_ = keyboard_bounds; |
| 945 | OnWindowResized(); |
| 946 | } |
| 947 | |
[email protected] | d3643b5 | 2013-05-01 16:00:48 | [diff] [blame] | 948 | gfx::Insets ShelfLayoutManager::GetInsetsForAlignment(int distance) const { |
| 949 | switch (alignment_) { |
| 950 | case SHELF_ALIGNMENT_BOTTOM: |
| 951 | return gfx::Insets(distance, 0, 0, 0); |
| 952 | case SHELF_ALIGNMENT_LEFT: |
| 953 | return gfx::Insets(0, 0, 0, distance); |
| 954 | case SHELF_ALIGNMENT_RIGHT: |
| 955 | return gfx::Insets(0, distance, 0, 0); |
| 956 | case SHELF_ALIGNMENT_TOP: |
| 957 | return gfx::Insets(0, 0, distance, 0); |
| 958 | } |
| 959 | NOTREACHED(); |
| 960 | return gfx::Insets(); |
| 961 | } |
| 962 | |
[email protected] | 55f59335 | 2011-12-24 05:42:46 | [diff] [blame] | 963 | } // namespace internal |
| 964 | } // namespace ash |