| 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_SHELF_DIMMER_VIEW_H_ | |
| 6 #define ASH_SHELF_DIMMER_VIEW_H_ | |
| 7 | |
| 8 #include "ash/common/shelf/wm_dimmer_view.h" | |
| 9 #include "ash/common/wm/background_animator.h" | |
| 10 #include "ash/common/wm_window_observer.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "ui/events/event_handler.h" | |
| 13 #include "ui/views/view.h" | |
| 14 #include "ui/views/widget/widget_delegate.h" | |
| 15 | |
| 16 namespace ash { | |
| 17 | |
| 18 class WmShelf; | |
| 19 | |
| 20 // DimmerView slightly dims shelf items when a window is maximized and visible. | |
| 21 // TODO(jamescook): Delete this after material design ships, as MD will not | |
| 22 // require shelf dimming. http://crbug.com/614453 | |
| 23 class DimmerView : public views::View, | |
| 24 public views::WidgetDelegate, | |
| 25 public BackgroundAnimatorDelegate, | |
| 26 public WmDimmerView, | |
| 27 public WmWindowObserver { | |
| 28 public: | |
| 29 // Creates and shows a DimmerView and its Widget. The returned view is owned | |
| 30 // by its widget. If |disable_animations_for_test| is set, all changes apply | |
| 31 // instantly. | |
| 32 static DimmerView* Create(WmShelf* shelf, bool disable_animations_for_test); | |
| 33 | |
| 34 // Called by |DimmerEventFilter| when the mouse |hovered| state changes. | |
| 35 void SetHovered(bool hovered); | |
| 36 | |
| 37 // views::View overrides: | |
| 38 void OnPaintBackground(gfx::Canvas* canvas) override; | |
| 39 | |
| 40 // views::WidgetDelegate overrides: | |
| 41 views::Widget* GetWidget() override; | |
| 42 const views::Widget* GetWidget() const override; | |
| 43 | |
| 44 // BackgroundAnimatorDelegate overrides: | |
| 45 void UpdateBackground(BackgroundAnimator* animator, int alpha) override; | |
| 46 void BackgroundAnimationEnded(BackgroundAnimator* animator) override; | |
| 47 | |
| 48 // WmDimmerView: | |
| 49 views::Widget* GetDimmerWidget() override; | |
| 50 void ForceUndimming(bool force) override; | |
| 51 int GetDimmingAlphaForTest() override; | |
| 52 | |
| 53 // WmWindowObserver overrides: | |
| 54 // This will be called when the shelf itself changes its absolute position. | |
| 55 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs | |
| 56 // to be repositioned. The difference to the OnBoundsChanged call above is | |
| 57 // that this gets also triggered when the shelf only moves. | |
| 58 void OnWindowBoundsChanged(WmWindow* window, | |
| 59 const gfx::Rect& old_bounds, | |
| 60 const gfx::Rect& new_bounds) override; | |
| 61 | |
| 62 private: | |
| 63 DimmerView(WmShelf* shelf, bool disable_animations_for_test); | |
| 64 ~DimmerView() override; | |
| 65 | |
| 66 // This class monitors mouse events to see if it is on top of the shelf. | |
| 67 class DimmerEventFilter : public ui::EventHandler { | |
| 68 public: | |
| 69 explicit DimmerEventFilter(DimmerView* owner); | |
| 70 ~DimmerEventFilter() override; | |
| 71 | |
| 72 // Overridden from ui::EventHandler: | |
| 73 void OnMouseEvent(ui::MouseEvent* event) override; | |
| 74 void OnTouchEvent(ui::TouchEvent* event) override; | |
| 75 | |
| 76 private: | |
| 77 // The owning class. | |
| 78 DimmerView* owner_; | |
| 79 | |
| 80 // True if the mouse is inside the shelf. | |
| 81 bool mouse_inside_; | |
| 82 | |
| 83 // True if a touch event is inside the shelf. | |
| 84 bool touch_inside_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(DimmerEventFilter); | |
| 87 }; | |
| 88 | |
| 89 // The shelf that uses this dimmer. | |
| 90 WmShelf* shelf_; | |
| 91 | |
| 92 // The alpha to use for covering the shelf. | |
| 93 int alpha_; | |
| 94 | |
| 95 // True if the event filter claims that we should not be dimmed. | |
| 96 bool is_hovered_; | |
| 97 | |
| 98 // True if someone forces us not to be dimmed (e.g. a menu is open). | |
| 99 bool force_hovered_; | |
| 100 | |
| 101 // True if animations should be suppressed for a test. | |
| 102 bool disable_animations_for_test_; | |
| 103 | |
| 104 // The animator for the background transitions. | |
| 105 BackgroundAnimator background_animator_; | |
| 106 | |
| 107 // Notification of entering / exiting of the shelf area by mouse. | |
| 108 std::unique_ptr<DimmerEventFilter> event_filter_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(DimmerView); | |
| 111 }; | |
| 112 | |
| 113 } // namespace ash | |
| 114 | |
| 115 #endif // ASH_SHELF_DIMMER_VIEW_H_ | |
| OLD | NEW |