Chromium Code Reviews| 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 | |
|
James Cook
2016/08/03 03:09:11
header guards please
msw
2016/08/03 16:48:24
Done.
| |
| 5 #include "ash/common/wm/background_animator.h" | |
| 6 #include "ash/common/wm_window_observer.h" | |
| 7 #include "ui/views/view.h" | |
| 8 #include "ui/views/widget/widget_delegate.h" | |
|
James Cook
2016/08/03 03:09:11
base/macros.h too
msw
2016/08/03 16:48:24
Done.
| |
| 9 | |
|
James Cook
2016/08/03 03:09:10
event_handler.h too
msw
2016/08/03 16:48:24
Done.
| |
| 10 namespace ash { | |
| 11 | |
| 12 class WmShelf; | |
| 13 | |
| 14 // Class used to slightly dim shelf items when maximized and visible. | |
|
James Cook
2016/08/03 03:09:11
nit: "when a window is maximized and visible"
msw
2016/08/03 16:48:24
Done.
| |
| 15 class DimmerView : public views::View, | |
| 16 public views::WidgetDelegate, | |
| 17 public BackgroundAnimatorDelegate, | |
| 18 public WmWindowObserver { | |
| 19 public: | |
| 20 // Creates and shows a DimmerView and its Widget. | |
| 21 static DimmerView* Create(WmShelf* shelf, bool disable_animations_for_test); | |
| 22 | |
| 23 // If |disable_animations_for_test| is set, all changes apply instantly. | |
| 24 DimmerView(WmShelf* shelf, bool disable_animations_for_test); | |
|
James Cook
2016/08/03 03:09:11
Could these be private, or are they accessed from
msw
2016/08/03 16:48:24
Done.
| |
| 25 ~DimmerView() override; | |
| 26 | |
| 27 // Called by |DimmerEventFilter| when the mouse |hovered| state changes. | |
| 28 void SetHovered(bool hovered); | |
| 29 | |
| 30 // Force the dimmer to be undimmed. | |
| 31 void ForceUndimming(bool force); | |
| 32 | |
| 33 // views::WidgetDelegate overrides: | |
| 34 views::Widget* GetWidget() override; | |
| 35 const views::Widget* GetWidget() const override; | |
| 36 | |
| 37 // BackgroundAnimatorDelegate overrides: | |
| 38 void UpdateBackground(BackgroundAnimator* animator, int alpha) override; | |
| 39 void BackgroundAnimationEnded(BackgroundAnimator* animator) override; | |
| 40 | |
| 41 // views::View overrides: | |
|
James Cook
2016/08/03 03:09:10
nit: make the overridden function declaration orde
msw
2016/08/03 16:48:24
Done.
| |
| 42 void OnPaintBackground(gfx::Canvas* canvas) override; | |
| 43 | |
| 44 // WmWindowObserver overrides: | |
| 45 // This will be called when the shelf itself changes its absolute position. | |
| 46 // Since the |dimmer_| panel needs to be placed in screen coordinates it needs | |
| 47 // to be repositioned. The difference to the OnBoundsChanged call above is | |
| 48 // that this gets also triggered when the shelf only moves. | |
| 49 void OnWindowBoundsChanged(WmWindow* window, | |
| 50 const gfx::Rect& old_bounds, | |
| 51 const gfx::Rect& new_bounds) override; | |
| 52 | |
| 53 // A function to test the current alpha used. | |
| 54 int get_dimming_alpha_for_test() { return alpha_; } | |
| 55 | |
| 56 private: | |
| 57 // This class monitors mouse events to see if it is on top of the shelf. | |
| 58 class DimmerEventFilter : public ui::EventHandler { | |
| 59 public: | |
| 60 explicit DimmerEventFilter(DimmerView* owner); | |
| 61 ~DimmerEventFilter() override; | |
| 62 | |
| 63 // Overridden from ui::EventHandler: | |
| 64 void OnMouseEvent(ui::MouseEvent* event) override; | |
| 65 void OnTouchEvent(ui::TouchEvent* event) override; | |
| 66 | |
| 67 private: | |
| 68 // The owning class. | |
| 69 DimmerView* owner_; | |
| 70 | |
| 71 // TRUE if the mouse is inside the shelf. | |
|
James Cook
2016/08/03 03:09:11
nit: TRUE -> True, and below. Some previous code a
msw
2016/08/03 16:48:24
Done.
| |
| 72 bool mouse_inside_; | |
| 73 | |
| 74 // TRUE if a touch event is inside the shelf. | |
| 75 bool touch_inside_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(DimmerEventFilter); | |
| 78 }; | |
| 79 | |
| 80 // The shelf that uses this dimmer. | |
| 81 WmShelf* shelf_; | |
| 82 | |
| 83 // The alpha to use for covering the shelf. | |
| 84 int alpha_; | |
| 85 | |
| 86 // True if the event filter claims that we should not be dimmed. | |
| 87 bool is_hovered_; | |
| 88 | |
| 89 // True if someone forces us not to be dimmed (e.g. a menu is open). | |
| 90 bool force_hovered_; | |
| 91 | |
| 92 // True if animations should be suppressed for a test. | |
| 93 bool disable_animations_for_test_; | |
| 94 | |
| 95 // The animator for the background transitions. | |
| 96 BackgroundAnimator background_animator_; | |
| 97 | |
| 98 // Notification of entering / exiting of the shelf area by mouse. | |
| 99 std::unique_ptr<DimmerEventFilter> event_filter_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(DimmerView); | |
| 102 }; | |
| 103 | |
| 104 } // namespace ash | |
| OLD | NEW |