summaryrefslogtreecommitdiffstats
path: root/ash/wm/property_util.cc
blob: a51d29888d6adc953b6642dedec0bab174efcc5d (plain)
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
// Copyright (c) 2012 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/wm/property_util.h"

#include "ash/ash_export.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_util.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/rect.h"

namespace ash {
namespace {
bool g_default_windows_persist_across_all_workspaces = false;
}  // namespace

void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) {
  window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds));
}

void SetRestoreBoundsIfNotSet(aura::Window* window) {
  if (!GetRestoreBounds(window))
    SetRestoreBounds(window, window->bounds());
}

const gfx::Rect* GetRestoreBounds(aura::Window* window) {
  return window->GetProperty(aura::client::kRestoreBoundsKey);
}

void ClearRestoreBounds(aura::Window* window) {
  window->ClearProperty(aura::client::kRestoreBoundsKey);
}

void ToggleMaximizedState(aura::Window* window) {
  window->SetProperty(aura::client::kShowStateKey,
                      wm::IsWindowMaximized(window) ? ui::SHOW_STATE_NORMAL
                                                    : ui::SHOW_STATE_MAXIMIZED);
}

void SetTrackedByWorkspace(aura::Window* window, bool value) {
  window->SetProperty(internal::kWindowTrackedByWorkspaceKey, value);
}

bool GetTrackedByWorkspace(aura::Window* window) {
  return window->GetProperty(internal::kWindowTrackedByWorkspaceKey);
}

void SetPersistsAcrossAllWorkspaces(
    aura::Window* window,
    WindowPersistsAcrossAllWorkspacesType type) {
  window->SetProperty(
      internal::kWindowPersistsAcrossAllWorkspacesKey, type);
}

bool GetPersistsAcrossAllWorkspaces(aura::Window* window) {
  switch (window->GetProperty(
      internal::kWindowPersistsAcrossAllWorkspacesKey)) {
    case WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES:
      return true;
    case WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_NO:
      return false;
    case WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_DEFAULT:
      return g_default_windows_persist_across_all_workspaces;
  }
  return false;
}

void SetDefaultPersistsAcrossAllWorkspaces(bool value) {
  g_default_windows_persist_across_all_workspaces = value;
}

internal::RootWindowController* GetRootWindowController(
    aura::RootWindow* root_window) {
  return root_window->GetProperty(internal::kRootWindowControllerKey);
}

void SetRootWindowController(aura::RootWindow* root_window,
                             internal::RootWindowController* controller) {
  root_window->SetProperty(internal::kRootWindowControllerKey, controller);
}

}  // namespace ash