1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88

ash / public / cpp / window_backdrop.cc [blame]

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/public/cpp/window_backdrop.h"

#include "ash/public/cpp/window_properties.h"
#include "ui/aura/window.h"

namespace ash {

namespace {

constexpr SkColor kSemiOpaqueBackdropColor =
    SkColorSetARGB(0x99, 0x20, 0x21, 0x24);

}  // namespace

WindowBackdrop::WindowBackdrop(aura::Window* window) : window_(window) {}
WindowBackdrop::~WindowBackdrop() = default;

// static
WindowBackdrop* WindowBackdrop::Get(aura::Window* window) {
  DCHECK(window);

  WindowBackdrop* window_backdrop = window->GetProperty(kWindowBackdropKey);
  if (window_backdrop)
    return window_backdrop;

  window_backdrop = new WindowBackdrop(window);
  window->SetProperty(kWindowBackdropKey, window_backdrop);
  return window_backdrop;
}

void WindowBackdrop::SetBackdropMode(WindowBackdrop::BackdropMode mode) {
  if (mode_ == mode)
    return;

  mode_ = mode;
  NotifyWindowBackdropPropertyChanged();
}

void WindowBackdrop::SetBackdropType(WindowBackdrop::BackdropType type) {
  if (type_ == type)
    return;

  type_ = type;
  NotifyWindowBackdropPropertyChanged();
}

void WindowBackdrop::DisableBackdrop() {
  if (temporarily_disabled_)
    return;

  temporarily_disabled_ = true;
  NotifyWindowBackdropPropertyChanged();
}

void WindowBackdrop::RestoreBackdrop() {
  if (!temporarily_disabled_)
    return;

  temporarily_disabled_ = false;
  NotifyWindowBackdropPropertyChanged();
}

SkColor WindowBackdrop::GetBackdropColor() const {
  if (type_ == BackdropType::kSemiOpaque)
    return kSemiOpaqueBackdropColor;

  DCHECK(type_ == BackdropType::kOpaque);
  return SK_ColorBLACK;
}

void WindowBackdrop::AddObserver(WindowBackdrop::Observer* observer) {
  observers_.AddObserver(observer);
}

void WindowBackdrop::RemoveObserver(WindowBackdrop::Observer* observer) {
  observers_.RemoveObserver(observer);
}

void WindowBackdrop::NotifyWindowBackdropPropertyChanged() {
  for (auto& observer : observers_)
    observer.OnWindowBackdropPropertyChanged(window_);
}

}  // namespace ash