blob: 3b03af2d715bd0b1e696d7c6cd96b5129ec41c3d [file] [log] [blame]
// Copyright 2018 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/bind_helpers.h"
#include "base/callback.h"
namespace aura {
class Window;
namespace ash {
namespace wm {
using TransientTreeIgnorePredicate =
// An iterator class that traverses an aura::Window and all of its transient
// descendants.
class ASH_EXPORT WindowTransientDescendantIterator {
// Creates an empty iterator.
// Copy constructor required for iterator purposes.
const WindowTransientDescendantIterator& other);
// Iterates over |root_window| and all of its transient descendants.
explicit WindowTransientDescendantIterator(aura::Window* root_window);
aura::Window* root_window,
TransientTreeIgnorePredicate hide_predicate);
// Prefix increment operator. This assumes there are more items (i.e.
// *this != TransientDescendantIterator()).
const WindowTransientDescendantIterator& operator++();
// Comparison for STL-based loops.
bool operator!=(const WindowTransientDescendantIterator& other) const;
// Dereference operator for STL-compatible iterators.
aura::Window* operator*() const;
// Explicit assignment operator defined because an explicit copy constructor
// is needed and therefore the DISALLOW_COPY_AND_ASSIGN macro cannot be used.
WindowTransientDescendantIterator& operator=(
const WindowTransientDescendantIterator& other) = default;
// The current window that |this| refers to. A null |current_window_| denotes
// an empty iterator and is used as the last possible value in the traversal.
aura::Window* current_window_;
// Windows that satisfy this predicate will not be shown.
TransientTreeIgnorePredicate hide_predicate_ = base::NullCallback();
// Provides a virtual container implementing begin() and end() for a sequence of
// WindowTransientDescendantIterators. This can be used in range-based for
// loops.
class WindowTransientDescendantIteratorRange {
explicit WindowTransientDescendantIteratorRange(
const WindowTransientDescendantIterator& begin);
// Copy constructor required for iterator purposes.
const WindowTransientDescendantIteratorRange& other) = default;
const WindowTransientDescendantIterator& begin() const { return begin_; }
const WindowTransientDescendantIterator& end() const { return end_; }
// Because the explicit copy constructor is needed, explicitly delete the
// assignment operator rather than using DISALLOW_COPY_AND_ASSIGN.
WindowTransientDescendantIteratorRange& operator=(
const WindowTransientDescendantIteratorRange& other) = delete;
WindowTransientDescendantIterator begin_;
WindowTransientDescendantIterator end_;
// Returns the range to iterate over the entire transient-window hierarchy which
// |window| belongs to. If |hide_predicate| is given, windows that satisfy that
// condition will be skipped.
ASH_EXPORT WindowTransientDescendantIteratorRange
GetTransientTreeIterator(aura::Window* window);
ASH_EXPORT WindowTransientDescendantIteratorRange
GetTransientTreeIterator(aura::Window* window,
TransientTreeIgnorePredicate hide_predicate);
} // namespace wm
} // namespace ash