| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ASH_COMMON_SHELF_WM_SHELF_H_ | |
| 6 #define ASH_COMMON_SHELF_WM_SHELF_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "ash/ash_export.h" | |
| 11 #include "ash/common/shelf/shelf_layout_manager_observer.h" | |
| 12 #include "ash/public/cpp/shelf_types.h" | |
| 13 #include "base/observer_list.h" | |
| 14 | |
| 15 namespace gfx { | |
| 16 class Rect; | |
| 17 } | |
| 18 | |
| 19 namespace ui { | |
| 20 class GestureEvent; | |
| 21 } | |
| 22 | |
| 23 namespace ash { | |
| 24 | |
| 25 enum class AnimationChangeType; | |
| 26 class ShelfBezelEventHandler; | |
| 27 class ShelfLayoutManager; | |
| 28 class ShelfLayoutManagerTest; | |
| 29 class ShelfLockingManager; | |
| 30 class ShelfView; | |
| 31 class ShelfWidget; | |
| 32 class StatusAreaWidget; | |
| 33 class WmShelfObserver; | |
| 34 class WmWindow; | |
| 35 | |
| 36 // Controller for the shelf state. Exists for the lifetime of each root window | |
| 37 // controller. Note that the shelf widget may not be created until after login. | |
| 38 class ASH_EXPORT WmShelf : public ShelfLayoutManagerObserver { | |
| 39 public: | |
| 40 WmShelf(); | |
| 41 ~WmShelf() override; | |
| 42 | |
| 43 // Returns the shelf for the display that |window| is on. Note that the shelf | |
| 44 // widget may not exist, or the shelf may not be visible. | |
| 45 static WmShelf* ForWindow(WmWindow* window); | |
| 46 | |
| 47 // Returns if shelf alignment options are enabled, and the user is able to | |
| 48 // adjust the alignment (eg. not allowed in guest and supervised user modes). | |
| 49 static bool CanChangeShelfAlignment(); | |
| 50 | |
| 51 void CreateShelfWidget(WmWindow* root); | |
| 52 void ShutdownShelfWidget(); | |
| 53 void DestroyShelfWidget(); | |
| 54 | |
| 55 ShelfLayoutManager* shelf_layout_manager() const { | |
| 56 return shelf_layout_manager_; | |
| 57 } | |
| 58 | |
| 59 ShelfWidget* shelf_widget() { return shelf_widget_.get(); } | |
| 60 | |
| 61 // Creates the shelf view. | |
| 62 void CreateShelfView(); | |
| 63 | |
| 64 // TODO(jamescook): Eliminate this method. | |
| 65 void ShutdownShelf(); | |
| 66 | |
| 67 // True after the ShelfView has been created (e.g. after login). | |
| 68 bool IsShelfInitialized() const; | |
| 69 | |
| 70 // Returns the window showing the shelf. | |
| 71 WmWindow* GetWindow(); | |
| 72 | |
| 73 ShelfAlignment alignment() const { return alignment_; } | |
| 74 // TODO(jamescook): Replace with alignment(). | |
| 75 ShelfAlignment GetAlignment() const { return alignment_; } | |
| 76 void SetAlignment(ShelfAlignment alignment); | |
| 77 | |
| 78 // Returns true if the shelf alignment is horizontal (i.e. at the bottom). | |
| 79 bool IsHorizontalAlignment() const; | |
| 80 | |
| 81 // Returns a value based on shelf alignment. | |
| 82 int SelectValueForShelfAlignment(int bottom, int left, int right) const; | |
| 83 | |
| 84 // Returns |horizontal| is shelf is horizontal, otherwise |vertical|. | |
| 85 int PrimaryAxisValue(int horizontal, int vertical) const; | |
| 86 | |
| 87 ShelfAutoHideBehavior auto_hide_behavior() const { | |
| 88 return auto_hide_behavior_; | |
| 89 } | |
| 90 void SetAutoHideBehavior(ShelfAutoHideBehavior behavior); | |
| 91 | |
| 92 ShelfAutoHideState GetAutoHideState() const; | |
| 93 | |
| 94 // Invoke when the auto-hide state may have changed (for example, when the | |
| 95 // system tray bubble opens it should force the shelf to be visible). | |
| 96 void UpdateAutoHideState(); | |
| 97 | |
| 98 ShelfBackgroundType GetBackgroundType() const; | |
| 99 | |
| 100 // Whether the shelf view is visible. | |
| 101 // TODO(jamescook): Consolidate this with GetVisibilityState(). | |
| 102 bool IsVisible() const; | |
| 103 | |
| 104 void UpdateVisibilityState(); | |
| 105 | |
| 106 ShelfVisibilityState GetVisibilityState() const; | |
| 107 | |
| 108 // Returns the ideal bounds of the shelf assuming it is visible. | |
| 109 gfx::Rect GetIdealBounds(); | |
| 110 | |
| 111 gfx::Rect GetUserWorkAreaBounds() const; | |
| 112 | |
| 113 // Updates the icon position given the current window bounds. This is used | |
| 114 // when dragging panels to reposition them with respect to the other panels. | |
| 115 void UpdateIconPositionForPanel(WmWindow* window); | |
| 116 | |
| 117 // Returns the screen bounds of the item for the specified window. If there is | |
| 118 // no item for the specified window an empty rect is returned. | |
| 119 gfx::Rect GetScreenBoundsOfItemIconForWindow(WmWindow* window); | |
| 120 | |
| 121 // Launch a 0-indexed shelf item in the shelf. A negative index launches the | |
| 122 // last shelf item in the shelf. | |
| 123 static void LaunchShelfItem(int item_index); | |
| 124 | |
| 125 // Activates the shelf item specified by the index in the list of shelf items. | |
| 126 static void ActivateShelfItem(int item_index); | |
| 127 | |
| 128 // Handles a gesture |event| coming from a source outside the shelf widget | |
| 129 // (e.g. the status area widget). Allows support for behaviors like toggling | |
| 130 // auto-hide with a swipe, even if that gesture event hits another window. | |
| 131 // Returns true if the event was handled. | |
| 132 bool ProcessGestureEvent(const ui::GestureEvent& event); | |
| 133 | |
| 134 void AddObserver(WmShelfObserver* observer); | |
| 135 void RemoveObserver(WmShelfObserver* observer); | |
| 136 | |
| 137 void NotifyShelfIconPositionsChanged(); | |
| 138 StatusAreaWidget* GetStatusAreaWidget() const; | |
| 139 | |
| 140 void SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds); | |
| 141 ShelfLockingManager* GetShelfLockingManagerForTesting(); | |
| 142 ShelfView* GetShelfViewForTesting(); | |
| 143 | |
| 144 protected: | |
| 145 // ShelfLayoutManagerObserver: | |
| 146 void WillDeleteShelfLayoutManager() override; | |
| 147 void WillChangeVisibilityState(ShelfVisibilityState new_state) override; | |
| 148 void OnAutoHideStateChanged(ShelfAutoHideState new_state) override; | |
| 149 void OnBackgroundUpdated(ShelfBackgroundType background_type, | |
| 150 AnimationChangeType change_type) override; | |
| 151 | |
| 152 private: | |
| 153 class AutoHideEventHandler; | |
| 154 friend class ShelfLayoutManagerTest; | |
| 155 | |
| 156 // Layout manager for the shelf container window. Instances are constructed by | |
| 157 // ShelfWidget and lifetimes are managed by the container windows themselves. | |
| 158 ShelfLayoutManager* shelf_layout_manager_ = nullptr; | |
| 159 | |
| 160 std::unique_ptr<ShelfWidget> shelf_widget_; | |
| 161 | |
| 162 // Internal implementation detail. Do not expose externally. Owned by views | |
| 163 // hierarchy. Null before login and in secondary display init. | |
| 164 ShelfView* shelf_view_ = nullptr; | |
| 165 | |
| 166 // These initial values hide the shelf until user preferences are available. | |
| 167 ShelfAlignment alignment_ = SHELF_ALIGNMENT_BOTTOM_LOCKED; | |
| 168 ShelfAutoHideBehavior auto_hide_behavior_ = SHELF_AUTO_HIDE_ALWAYS_HIDDEN; | |
| 169 | |
| 170 // Sets shelf alignment to bottom during login and screen lock. | |
| 171 std::unique_ptr<ShelfLockingManager> shelf_locking_manager_; | |
| 172 | |
| 173 base::ObserverList<WmShelfObserver> observers_; | |
| 174 | |
| 175 // Forwards mouse and gesture events to ShelfLayoutManager for auto-hide. | |
| 176 // TODO(mash): Facilitate simliar functionality in mash: crbug.com/631216 | |
| 177 std::unique_ptr<AutoHideEventHandler> auto_hide_event_handler_; | |
| 178 | |
| 179 // Forwards touch gestures on a bezel sensor to the shelf. | |
| 180 // TODO(mash): Facilitate simliar functionality in mash: crbug.com/636647 | |
| 181 std::unique_ptr<ShelfBezelEventHandler> bezel_event_handler_; | |
| 182 | |
| 183 DISALLOW_COPY_AND_ASSIGN(WmShelf); | |
| 184 }; | |
| 185 | |
| 186 } // namespace ash | |
| 187 | |
| 188 #endif // ASH_COMMON_SHELF_WM_SHELF_H_ | |
| OLD | NEW |