Chromium Code Reviews| Index: ash/shelf/dimmer_view.h |
| diff --git a/ash/shelf/dimmer_view.h b/ash/shelf/dimmer_view.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cc3405624585c1d079c3e03084cd06e4b96078ad |
| --- /dev/null |
| +++ b/ash/shelf/dimmer_view.h |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
|
James Cook
2016/08/03 03:09:11
header guards please
msw
2016/08/03 16:48:24
Done.
|
| +#include "ash/common/wm/background_animator.h" |
| +#include "ash/common/wm_window_observer.h" |
| +#include "ui/views/view.h" |
| +#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.
|
| + |
|
James Cook
2016/08/03 03:09:10
event_handler.h too
msw
2016/08/03 16:48:24
Done.
|
| +namespace ash { |
| + |
| +class WmShelf; |
| + |
| +// 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.
|
| +class DimmerView : public views::View, |
| + public views::WidgetDelegate, |
| + public BackgroundAnimatorDelegate, |
| + public WmWindowObserver { |
| + public: |
| + // Creates and shows a DimmerView and its Widget. |
| + static DimmerView* Create(WmShelf* shelf, bool disable_animations_for_test); |
| + |
| + // If |disable_animations_for_test| is set, all changes apply instantly. |
| + 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.
|
| + ~DimmerView() override; |
| + |
| + // Called by |DimmerEventFilter| when the mouse |hovered| state changes. |
| + void SetHovered(bool hovered); |
| + |
| + // Force the dimmer to be undimmed. |
| + void ForceUndimming(bool force); |
| + |
| + // views::WidgetDelegate overrides: |
| + views::Widget* GetWidget() override; |
| + const views::Widget* GetWidget() const override; |
| + |
| + // BackgroundAnimatorDelegate overrides: |
| + void UpdateBackground(BackgroundAnimator* animator, int alpha) override; |
| + void BackgroundAnimationEnded(BackgroundAnimator* animator) override; |
| + |
| + // 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.
|
| + void OnPaintBackground(gfx::Canvas* canvas) override; |
| + |
| + // WmWindowObserver overrides: |
| + // This will be called when the shelf itself changes its absolute position. |
| + // Since the |dimmer_| panel needs to be placed in screen coordinates it needs |
| + // to be repositioned. The difference to the OnBoundsChanged call above is |
| + // that this gets also triggered when the shelf only moves. |
| + void OnWindowBoundsChanged(WmWindow* window, |
| + const gfx::Rect& old_bounds, |
| + const gfx::Rect& new_bounds) override; |
| + |
| + // A function to test the current alpha used. |
| + int get_dimming_alpha_for_test() { return alpha_; } |
| + |
| + private: |
| + // This class monitors mouse events to see if it is on top of the shelf. |
| + class DimmerEventFilter : public ui::EventHandler { |
| + public: |
| + explicit DimmerEventFilter(DimmerView* owner); |
| + ~DimmerEventFilter() override; |
| + |
| + // Overridden from ui::EventHandler: |
| + void OnMouseEvent(ui::MouseEvent* event) override; |
| + void OnTouchEvent(ui::TouchEvent* event) override; |
| + |
| + private: |
| + // The owning class. |
| + DimmerView* owner_; |
| + |
| + // 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.
|
| + bool mouse_inside_; |
| + |
| + // TRUE if a touch event is inside the shelf. |
| + bool touch_inside_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DimmerEventFilter); |
| + }; |
| + |
| + // The shelf that uses this dimmer. |
| + WmShelf* shelf_; |
| + |
| + // The alpha to use for covering the shelf. |
| + int alpha_; |
| + |
| + // True if the event filter claims that we should not be dimmed. |
| + bool is_hovered_; |
| + |
| + // True if someone forces us not to be dimmed (e.g. a menu is open). |
| + bool force_hovered_; |
| + |
| + // True if animations should be suppressed for a test. |
| + bool disable_animations_for_test_; |
| + |
| + // The animator for the background transitions. |
| + BackgroundAnimator background_animator_; |
| + |
| + // Notification of entering / exiting of the shelf area by mouse. |
| + std::unique_ptr<DimmerEventFilter> event_filter_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DimmerView); |
| +}; |
| + |
| +} // namespace ash |