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

Unified Diff: ash/shelf/shelf_layout_manager.cc

Issue 2007003002: mash: Preliminary support for shelf auto-hide (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shutdown
Patch Set: typo Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: ash/shelf/shelf_layout_manager.cc
diff --git a/ash/shelf/shelf_layout_manager.cc b/ash/shelf/shelf_layout_manager.cc
index ff95424866e43eb71462d8b27f3d071040a14ef6..d0872b7b88f89d7f0328a77cfb37887ab8728c0e 100644
--- a/ash/shelf/shelf_layout_manager.cc
+++ b/ash/shelf/shelf_layout_manager.cc
@@ -18,6 +18,7 @@
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_bezel_event_filter.h"
#include "ash/shelf/shelf_constants.h"
+#include "ash/shelf/shelf_delegate.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
#include "ash/shelf/shelf_util.h"
#include "ash/shelf/shelf_widget.h"
@@ -100,7 +101,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 +119,6 @@ class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler {
private:
ShelfLayoutManager* shelf_;
bool in_mouse_drag_;
- ShelfGestureHandler gesture_handler_;
DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter);
};
@@ -139,18 +141,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 --------------------------------------
@@ -261,6 +257,7 @@ ShelfLayoutManager::~ShelfLayoutManager() {
}
void ShelfLayoutManager::PrepareForShutdown() {
+ in_shutdown_ = true;
// Clear all event filters, otherwise sometimes those filters may catch
// synthesized mouse event and cause crashes during the shutdown.
set_workspace_controller(NULL);
@@ -289,6 +286,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);
@@ -376,6 +379,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 generated during status area widget teardown.
+ if (visibility_state() != SHELF_AUTO_HIDE || in_shutdown_)
+ return;
+
+ if (event->type() == ui::ET_MOUSE_MOVED ||
+ event->type() == ui::ET_MOUSE_ENTERED ||
+ event->type() == ui::ET_MOUSE_EXITED)
msw 2016/05/25 01:10:34 nit: curlies?
James Cook 2016/05/25 16:24:26 Done.
+ 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);
@@ -580,13 +607,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();
@@ -634,12 +665,19 @@ void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) {
UpdateBoundsAndOpacity(target_bounds, true,
delay_background_change ? update_shelf_observer_ : NULL);
+ // The delegate must be notified after |state_| is updated so that it can
+ // query the new target bounds.
+ ShelfDelegate* shelf_delegate = Shell::GetInstance()->GetShelfDelegate();
+ if (old_state.visibility_state != state_.visibility_state)
+ shelf_delegate->OnShelfVisibilityStateChanged(shelf_->shelf());
+
// OnAutoHideStateChanged Should be emitted when:
// - firstly state changed to auto-hide from other state
// - or, auto_hide_state has changed
if ((old_state.visibility_state != state_.visibility_state &&
state_.visibility_state == SHELF_AUTO_HIDE) ||
old_state.auto_hide_state != state_.auto_hide_state) {
+ shelf_delegate->OnShelfAutoHideStateChanged(shelf_->shelf());
FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
OnAutoHideStateChanged(state_.auto_hide_state));
}
@@ -998,22 +1036,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_;

Powered by Google App Engine
This is Rietveld 408576698