Chromium Code Reviews| Index: ash/shelf/shelf_layout_manager.cc |
| diff --git a/ash/shelf/shelf_layout_manager.cc b/ash/shelf/shelf_layout_manager.cc |
| index 1d4aeeacc37e0faf3c2c7e07c9d47ece050fe5a5..17eb456fa495a0e5fd070ea87c50a50a5abe548d 100644 |
| --- a/ash/shelf/shelf_layout_manager.cc |
| +++ b/ash/shelf/shelf_layout_manager.cc |
| @@ -100,7 +100,9 @@ const int ShelfLayoutManager::kShelfItemInset = 3; |
| // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- |
| -// Notifies ShelfLayoutManager any time the mouse moves. |
| +// Notifies ShelfLayoutManager any time the mouse moves. Not used on mash. |
| +// TODO(jamescook): Delete this once the mash implementation handles drags on |
| +// and off the shelf. |
| class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { |
| public: |
| explicit AutoHideEventFilter(ShelfLayoutManager* shelf); |
| @@ -116,7 +118,6 @@ class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { |
| private: |
| ShelfLayoutManager* shelf_; |
| bool in_mouse_drag_; |
| - ShelfGestureHandler gesture_handler_; |
| DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter); |
| }; |
| @@ -139,18 +140,12 @@ void ShelfLayoutManager::AutoHideEventFilter::OnMouseEvent( |
| (in_mouse_drag_ && event->type() != ui::ET_MOUSE_RELEASED && |
| event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)) && |
| !shelf_->IsShelfWindow(static_cast<aura::Window*>(event->target())); |
| - if (event->type() == ui::ET_MOUSE_MOVED) |
| - shelf_->UpdateAutoHideState(); |
| - return; |
| + shelf_->UpdateAutoHideForMouseEvent(event); |
| } |
| void ShelfLayoutManager::AutoHideEventFilter::OnGestureEvent( |
| ui::GestureEvent* event) { |
| - aura::Window* target_window = static_cast<aura::Window*>(event->target()); |
| - if (shelf_->IsShelfWindow(target_window)) { |
| - if (gesture_handler_.ProcessGestureEvent(*event, target_window)) |
| - event->StopPropagation(); |
| - } |
| + shelf_->UpdateAutoHideForGestureEvent(event); |
| } |
| // ShelfLayoutManager:UpdateShelfObserver -------------------------------------- |
| @@ -292,6 +287,12 @@ gfx::Rect ShelfLayoutManager::GetIdealBounds() { |
| rect.height())); |
| } |
| +gfx::Size ShelfLayoutManager::GetPreferredSize() { |
| + TargetBounds target_bounds; |
| + CalculateTargetBounds(state_, &target_bounds); |
| + return target_bounds.shelf_bounds_in_root.size(); |
| +} |
| + |
| void ShelfLayoutManager::LayoutShelf() { |
| TargetBounds target_bounds; |
| CalculateTargetBounds(state_, &target_bounds); |
| @@ -379,6 +380,30 @@ void ShelfLayoutManager::UpdateAutoHideState() { |
| } |
| } |
| +void ShelfLayoutManager::UpdateAutoHideForMouseEvent(ui::MouseEvent* event) { |
| + // Don't update during shutdown because synthetic mouse events (e.g. mouse |
| + // exit) may be generate during status area widget teardown. |
|
msw
2016/05/24 20:46:55
nit: generated
James Cook
2016/05/25 00:25:43
Whoops! Done.
|
| + if (visibility_state() != SHELF_AUTO_HIDE || in_shutdown_) |
|
msw
2016/05/24 20:46:55
q: Where is |in_shutdown_| declared and set?
James Cook
2016/05/25 00:25:43
Declared in the header, set in PrepareForShutdown(
|
| + return; |
| + |
| + if (event->type() == ui::ET_MOUSE_MOVED || |
| + event->type() == ui::ET_MOUSE_ENTERED || |
| + event->type() == ui::ET_MOUSE_EXITED) |
| + UpdateAutoHideState(); |
| +} |
| + |
| +void ShelfLayoutManager::UpdateAutoHideForGestureEvent( |
| + ui::GestureEvent* event) { |
| + if (visibility_state() != SHELF_AUTO_HIDE || in_shutdown_) |
| + return; |
| + |
| + aura::Window* target_window = static_cast<aura::Window*>(event->target()); |
| + if (IsShelfWindow(target_window)) { |
| + if (gesture_handler_.ProcessGestureEvent(*event, target_window)) |
| + event->StopPropagation(); |
| + } |
| +} |
| + |
| void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { |
| window_overlaps_shelf_ = value; |
| UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); |
| @@ -583,13 +608,17 @@ void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { |
| FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| WillChangeVisibilityState(visibility_state)); |
| - if (state.visibility_state == SHELF_AUTO_HIDE) { |
| - // When state is SHELF_AUTO_HIDE we need to track when the mouse is over the |
| - // shelf to unhide it. AutoHideEventFilter does that for us. |
| - if (!auto_hide_event_filter_) |
| - auto_hide_event_filter_.reset(new AutoHideEventFilter(this)); |
| - } else { |
| - auto_hide_event_filter_.reset(NULL); |
| + // mash does not support global event handlers. It uses events on the shelf |
| + // and status area widgets to update auto-hide. |
| + if (!Shell::GetInstance()->in_mus()) { |
| + if (state.visibility_state == SHELF_AUTO_HIDE) { |
| + // When state is SHELF_AUTO_HIDE we need to track when the mouse is over |
| + // the shelf to unhide it. AutoHideEventFilter does that for us. |
| + if (!auto_hide_event_filter_) |
| + auto_hide_event_filter_.reset(new AutoHideEventFilter(this)); |
| + } else { |
| + auto_hide_event_filter_.reset(NULL); |
| + } |
| } |
| StopAutoHideTimer(); |
| @@ -637,6 +666,13 @@ void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { |
| UpdateBoundsAndOpacity(target_bounds, true, |
| delay_background_change ? update_shelf_observer_ : NULL); |
| + // These observers must be notified after |state_| is updated so that they can |
| + // query the new target bounds. |
| + if (old_state.visibility_state != state_.visibility_state) { |
| + FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| + DidChangeVisibilityState(this, state_.visibility_state)); |
| + } |
| + |
| // OnAutoHideStateChanged Should be emitted when: |
| // - firstly state changed to auto-hide from other state |
| // - or, auto_hide_state has changed |
| @@ -644,7 +680,7 @@ void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { |
| state_.visibility_state == SHELF_AUTO_HIDE) || |
| old_state.auto_hide_state != state_.auto_hide_state) { |
| FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| - OnAutoHideStateChanged(state_.auto_hide_state)); |
| + OnAutoHideStateChanged(this, state_.auto_hide_state)); |
| } |
| } |
| @@ -923,6 +959,10 @@ void ShelfLayoutManager::UpdateShelfBackground( |
| } |
| wm::ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { |
| + // TODO(jamescook): Get maximized window state from the window manager. |
| + if (Shell::GetInstance()->in_mus()) |
|
msw
2016/05/24 20:46:55
q: Do we actually need this early return? What hap
James Cook
2016/05/25 00:25:43
Good catch, we don't really need this.
|
| + return wm::SHELF_BACKGROUND_DEFAULT; |
| + |
| if (state_.visibility_state != SHELF_AUTO_HIDE && |
| state_.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED) { |
| return wm::SHELF_BACKGROUND_MAXIMIZED; |
| @@ -1001,22 +1041,25 @@ ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( |
| shelf_->status_area_widget()->IsActive())) |
| return SHELF_AUTO_HIDE_SHOWN; |
| - const std::vector<aura::Window*> windows = |
| - shell->mru_window_tracker()->BuildWindowListIgnoreModal(); |
| - |
| - // Process the window list and check if there are any visible windows. |
| - bool visible_window = false; |
| - for (size_t i = 0; i < windows.size(); ++i) { |
| - if (windows[i] && windows[i]->IsVisible() && |
| - !wm::GetWindowState(windows[i])->IsMinimized() && |
| - root_window_ == windows[i]->GetRootWindow()) { |
| - visible_window = true; |
| - break; |
| + // TODO(jamescook): Track visible windows on mash via ShelfDelegate. |
| + if (!Shell::GetInstance()->in_mus()) { |
| + const std::vector<aura::Window*> windows = |
| + shell->mru_window_tracker()->BuildWindowListIgnoreModal(); |
| + |
| + // Process the window list and check if there are any visible windows. |
| + bool visible_window = false; |
| + for (size_t i = 0; i < windows.size(); ++i) { |
| + if (windows[i] && windows[i]->IsVisible() && |
| + !wm::GetWindowState(windows[i])->IsMinimized() && |
| + root_window_ == windows[i]->GetRootWindow()) { |
| + visible_window = true; |
| + break; |
| + } |
| } |
| + // If there are no visible windows do not hide the shelf. |
| + if (!visible_window) |
| + return SHELF_AUTO_HIDE_SHOWN; |
| } |
| - // If there are no visible windows do not hide the shelf. |
| - if (!visible_window) |
| - return SHELF_AUTO_HIDE_SHOWN; |
| if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) |
| return gesture_drag_auto_hide_state_; |