| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_SHELF_SHELF_VIEW_H_ | 5 #ifndef ASH_SHELF_SHELF_VIEW_H_ |
| 6 #define ASH_SHELF_SHELF_VIEW_H_ | 6 #define ASH_SHELF_SHELF_VIEW_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "ash/common/shelf/shelf_item_delegate.h" | 13 #include "ash/common/shelf/shelf_item_delegate.h" |
| 14 #include "ash/common/shelf/shelf_model_observer.h" | 14 #include "ash/common/shelf/shelf_model_observer.h" |
| 15 #include "ash/shelf/shelf_button_pressed_metric_tracker.h" | 15 #include "ash/shelf/shelf_button_pressed_metric_tracker.h" |
| 16 #include "ash/shelf/shelf_tooltip_manager.h" | 16 #include "ash/shelf/shelf_tooltip_manager.h" |
| 17 #include "ash/wm/gestures/shelf_gesture_handler.h" | 17 #include "ash/wm/gestures/shelf_gesture_handler.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
| 20 #include "ui/app_list/views/app_list_drag_and_drop_host.h" | 20 #include "ui/app_list/views/app_list_drag_and_drop_host.h" |
| 21 #include "ui/views/animation/bounds_animator_observer.h" | 21 #include "ui/views/animation/bounds_animator_observer.h" |
| 22 #include "ui/views/animation/ink_drop_state.h" |
| 22 #include "ui/views/context_menu_controller.h" | 23 #include "ui/views/context_menu_controller.h" |
| 23 #include "ui/views/controls/button/button.h" | 24 #include "ui/views/controls/button/button.h" |
| 24 #include "ui/views/focus/focus_manager.h" | 25 #include "ui/views/focus/focus_manager.h" |
| 25 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
| 26 #include "ui/views/view_model.h" | 27 #include "ui/views/view_model.h" |
| 27 | 28 |
| 28 namespace ui { | 29 namespace ui { |
| 29 class MenuModel; | 30 class MenuModel; |
| 30 } | 31 } |
| 31 | 32 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 50 class ShelfViewTestAPI; | 51 class ShelfViewTestAPI; |
| 51 } | 52 } |
| 52 | 53 |
| 53 extern const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM; | 54 extern const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM; |
| 54 extern const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT; | 55 extern const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT; |
| 55 extern const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT; | 56 extern const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT; |
| 56 extern const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT; | 57 extern const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT; |
| 57 | 58 |
| 58 class ASH_EXPORT ShelfView : public views::View, | 59 class ASH_EXPORT ShelfView : public views::View, |
| 59 public ShelfModelObserver, | 60 public ShelfModelObserver, |
| 60 public views::ButtonListener, | |
| 61 public views::ContextMenuController, | 61 public views::ContextMenuController, |
| 62 public views::FocusTraversable, | 62 public views::FocusTraversable, |
| 63 public views::BoundsAnimatorObserver, | 63 public views::BoundsAnimatorObserver, |
| 64 public app_list::ApplicationDragAndDropHost { | 64 public app_list::ApplicationDragAndDropHost { |
| 65 public: | 65 public: |
| 66 ShelfView(ShelfModel* model, ShelfDelegate* delegate, Shelf* shelf); | 66 ShelfView(ShelfModel* model, ShelfDelegate* delegate, Shelf* shelf); |
| 67 ~ShelfView() override; | 67 ~ShelfView() override; |
| 68 | 68 |
| 69 Shelf* shelf() const { return shelf_; } | 69 Shelf* shelf() const { return shelf_; } |
| 70 ShelfModel* model() const { return model_; } | 70 ShelfModel* model() const { return model_; } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 const gfx::Vector2d& cursor_offset_from_center, | 127 const gfx::Vector2d& cursor_offset_from_center, |
| 128 float scale_factor) override; | 128 float scale_factor) override; |
| 129 void UpdateDragIconProxy( | 129 void UpdateDragIconProxy( |
| 130 const gfx::Point& location_in_screen_coordinates) override; | 130 const gfx::Point& location_in_screen_coordinates) override; |
| 131 void DestroyDragIconProxy() override; | 131 void DestroyDragIconProxy() override; |
| 132 bool StartDrag(const std::string& app_id, | 132 bool StartDrag(const std::string& app_id, |
| 133 const gfx::Point& location_in_screen_coordinates) override; | 133 const gfx::Point& location_in_screen_coordinates) override; |
| 134 bool Drag(const gfx::Point& location_in_screen_coordinates) override; | 134 bool Drag(const gfx::Point& location_in_screen_coordinates) override; |
| 135 void EndDrag(bool cancel) override; | 135 void EndDrag(bool cancel) override; |
| 136 | 136 |
| 137 // Returns true if the event on the shelf item is not going to activate the |
| 138 // item. Used to determine whether a pending ink drop should be shown or not. |
| 139 bool WillIgnoreEventOnButton(views::View* view, const ui::Event& event); |
| 140 |
| 137 // The shelf buttons use the Pointer interface to enable item reordering. | 141 // The shelf buttons use the Pointer interface to enable item reordering. |
| 138 enum Pointer { NONE, DRAG_AND_DROP, MOUSE, TOUCH }; | 142 enum Pointer { NONE, DRAG_AND_DROP, MOUSE, TOUCH }; |
| 139 void PointerPressedOnButton(views::View* view, | 143 void PointerPressedOnButton(views::View* view, |
| 140 Pointer pointer, | 144 Pointer pointer, |
| 141 const ui::LocatedEvent& event); | 145 const ui::LocatedEvent& event); |
| 142 void PointerDraggedOnButton(views::View* view, | 146 void PointerDraggedOnButton(views::View* view, |
| 143 Pointer pointer, | 147 Pointer pointer, |
| 144 const ui::LocatedEvent& event); | 148 const ui::LocatedEvent& event); |
| 145 void PointerReleasedOnButton(views::View* view, | 149 void PointerReleasedOnButton(views::View* view, |
| 146 Pointer pointer, | 150 Pointer pointer, |
| 147 bool canceled); | 151 bool canceled); |
| 148 | 152 |
| 153 // TODO(mohsen): |ink_drop| is used to do appropriate ink drop animation based |
| 154 // on the action performed. A better approach would be to return a value |
| 155 // indicating the type of action performed such that the button can animate |
| 156 // the ink drop. Currently it is not possible because showing menu is |
| 157 // synchronous and blocks the call. Fix this after menu is converted to |
| 158 // asynchronous. Long-term, the return value can be merged into |
| 159 // ButtonListener. |
| 160 void ButtonPressed(views::Button* sender, |
| 161 const ui::Event& event, |
| 162 views::InkDrop* ink_drop); |
| 163 |
| 149 // Return the view model for test purposes. | 164 // Return the view model for test purposes. |
| 150 const views::ViewModel* view_model_for_test() const { | 165 const views::ViewModel* view_model_for_test() const { |
| 151 return view_model_.get(); | 166 return view_model_.get(); |
| 152 } | 167 } |
| 153 | 168 |
| 154 private: | 169 private: |
| 155 friend class ash::test::ShelfViewTestAPI; | 170 friend class ash::test::ShelfViewTestAPI; |
| 156 | 171 |
| 157 class FadeOutAnimationDelegate; | 172 class FadeOutAnimationDelegate; |
| 158 class StartFadeAnimationDelegate; | 173 class StartFadeAnimationDelegate; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 264 |
| 250 // Invoked after the fading out animation for item deletion is ended. | 265 // Invoked after the fading out animation for item deletion is ended. |
| 251 void OnFadeOutAnimationEnded(); | 266 void OnFadeOutAnimationEnded(); |
| 252 | 267 |
| 253 // Fade in last visible item. | 268 // Fade in last visible item. |
| 254 void StartFadeInLastVisibleItem(); | 269 void StartFadeInLastVisibleItem(); |
| 255 | 270 |
| 256 // Updates the visible range of overflow items in |overflow_view|. | 271 // Updates the visible range of overflow items in |overflow_view|. |
| 257 void UpdateOverflowRange(ShelfView* overflow_view) const; | 272 void UpdateOverflowRange(ShelfView* overflow_view) const; |
| 258 | 273 |
| 274 // Helper function handling button press. Returns whether an action was |
| 275 // performed or not. |
| 276 bool ButtonPressedImpl(views::Button* sender, |
| 277 const ui::Event& event, |
| 278 views::InkDrop* ink_drop); |
| 279 |
| 259 // Overridden from views::View: | 280 // Overridden from views::View: |
| 260 gfx::Size GetPreferredSize() const override; | 281 gfx::Size GetPreferredSize() const override; |
| 261 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | 282 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; |
| 262 FocusTraversable* GetPaneFocusTraversable() override; | 283 FocusTraversable* GetPaneFocusTraversable() override; |
| 263 void GetAccessibleState(ui::AXViewState* state) override; | 284 void GetAccessibleState(ui::AXViewState* state) override; |
| 264 void ViewHierarchyChanged( | 285 void ViewHierarchyChanged( |
| 265 const ViewHierarchyChangedDetails& details) override; | 286 const ViewHierarchyChangedDetails& details) override; |
| 266 | 287 |
| 267 // Overridden from ui::EventHandler: | 288 // Overridden from ui::EventHandler: |
| 268 void OnGestureEvent(ui::GestureEvent* event) override; | 289 void OnGestureEvent(ui::GestureEvent* event) override; |
| 269 | 290 |
| 270 // Overridden from ShelfModelObserver: | 291 // Overridden from ShelfModelObserver: |
| 271 void ShelfItemAdded(int model_index) override; | 292 void ShelfItemAdded(int model_index) override; |
| 272 void ShelfItemRemoved(int model_index, ShelfID id) override; | 293 void ShelfItemRemoved(int model_index, ShelfID id) override; |
| 273 void ShelfItemChanged(int model_index, const ShelfItem& old_item) override; | 294 void ShelfItemChanged(int model_index, const ShelfItem& old_item) override; |
| 274 void ShelfItemMoved(int start_index, int target_index) override; | 295 void ShelfItemMoved(int start_index, int target_index) override; |
| 275 | 296 |
| 276 // Overridden from views::ButtonListener: | |
| 277 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 278 | |
| 279 // Show a list of all running items for this shelf |item|; it only shows a | 297 // Show a list of all running items for this shelf |item|; it only shows a |
| 280 // menu if there are multiple running items. |source| specifies the view | 298 // menu if there are multiple running items. |source| specifies the view |
| 281 // responsible for showing the menu, and the bubble will point towards it. | 299 // responsible for showing the menu, and the bubble will point towards it. |
| 282 // The |event_flags| are the flags of the event which triggered this menu. | 300 // The |event_flags| are the flags of the event which triggered this menu. |
| 283 void ShowListMenuForView(const ShelfItem& item, | 301 // Returns |true| if a menu is shown. |
| 302 bool ShowListMenuForView(const ShelfItem& item, |
| 284 views::View* source, | 303 views::View* source, |
| 285 const ui::Event& event); | 304 const ui::Event& event, |
| 305 views::InkDrop* ink_drop); |
| 286 | 306 |
| 287 // Overridden from views::ContextMenuController: | 307 // Overridden from views::ContextMenuController: |
| 288 void ShowContextMenuForView(views::View* source, | 308 void ShowContextMenuForView(views::View* source, |
| 289 const gfx::Point& point, | 309 const gfx::Point& point, |
| 290 ui::MenuSourceType source_type) override; | 310 ui::MenuSourceType source_type) override; |
| 291 | 311 |
| 292 // Show either a context or normal click menu of given |menu_model|. | 312 // Show either a context or normal click menu of given |menu_model|. |
| 293 // If |context_menu| is set, the displayed menu is a context menu and not | 313 // If |context_menu| is set, the displayed menu is a context menu and not |
| 294 // a menu listing one or more running applications. | 314 // a menu listing one or more running applications. |
| 295 // The |click_point| is only used for |context_menu|'s. | 315 // The |click_point| is only used for |context_menu|'s. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 461 |
| 442 // Tracks UMA metrics based on shelf button press actions. | 462 // Tracks UMA metrics based on shelf button press actions. |
| 443 ShelfButtonPressedMetricTracker shelf_button_pressed_metric_tracker_; | 463 ShelfButtonPressedMetricTracker shelf_button_pressed_metric_tracker_; |
| 444 | 464 |
| 445 DISALLOW_COPY_AND_ASSIGN(ShelfView); | 465 DISALLOW_COPY_AND_ASSIGN(ShelfView); |
| 446 }; | 466 }; |
| 447 | 467 |
| 448 } // namespace ash | 468 } // namespace ash |
| 449 | 469 |
| 450 #endif // ASH_SHELF_SHELF_VIEW_H_ | 470 #endif // ASH_SHELF_SHELF_VIEW_H_ |
| OLD | NEW |