blob: be912dcef21d04b626d6ca2edfc8897ab4122ba9 [file] [log] [blame]
// Copyright 2015 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.
#include "ash/ash_export.h"
#include "base/macros.h"
#include "ui/aura/window_observer.h"
namespace ash {
// WindowDimmer creates a window whose opacity is animated by way of
// SetDimOpacity() and whose size matches that of its parent. WindowDimmer is
// intended to be used in cases where a certain set of windows need to appear
// partially obscured. This is achieved by creating WindowDimmer, setting the
// opacity, and then stacking window() above the windows that are to appear
// obscured.
// WindowDimmer owns the window it creates, but supports having that window
// deleted out from under it (this generally happens if the parent of the
// window is deleted). If WindowDimmer is deleted and the window it created is
// still valid, then WindowDimmer deletes the window.
class ASH_EXPORT WindowDimmer : public aura::WindowObserver {
// Creates a new WindowDimmer. The window() created by WindowDimmer is added
// to |parent| and stacked above all other child windows.
explicit WindowDimmer(aura::Window* parent);
~WindowDimmer() override;
void SetDimOpacity(float target_opacity);
aura::Window* parent() { return parent_; }
aura::Window* window() { return window_; }
// NOTE: WindowDimmer is an observer for both |parent_| and |window_|.
// aura::WindowObserver:
void OnWindowBoundsChanged(aura::Window* window,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds,
ui::PropertyChangeReason reason) override;
void OnWindowDestroying(aura::Window* window) override;
void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override;
aura::Window* parent_;
// See class description for details on ownership.
aura::Window* window_;
} // namespace ash