summaryrefslogtreecommitdiffstats
path: root/views/window/window_delegate.cc
blob: 7b5f2518cadee646a22733dc4d0f7d47249e1b98 (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
87
88
89
90
91
92
93
94
95
96
// Copyright (c) 2006-2008 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 "views/window/window_delegate.h"

// TODO(beng): hrmp. Fix this in http://crbug.com/4406
#include "chrome/browser/browser_process.h"
#include "chrome/common/pref_service.h"
#include "views/window/client_view.h"
#include "views/window/window.h"
#include "skia/include/SkBitmap.h"

namespace views {

WindowDelegate::WindowDelegate() {
}

WindowDelegate::~WindowDelegate() {
  ReleaseWindow();
}

// Returns the icon to be displayed in the window.
SkBitmap WindowDelegate::GetWindowIcon() {
  return SkBitmap();
}

void WindowDelegate::SaveWindowPlacement(const gfx::Rect& bounds,
                                         bool maximized,
                                         bool always_on_top) {
  std::wstring window_name = GetWindowName();
  if (window_name.empty() || !g_browser_process->local_state())
    return;

  DictionaryValue* window_preferences =
      g_browser_process->local_state()->GetMutableDictionary(
          window_name.c_str());
  window_preferences->SetInteger(L"left", bounds.x());
  window_preferences->SetInteger(L"top", bounds.y());
  window_preferences->SetInteger(L"right", bounds.right());
  window_preferences->SetInteger(L"bottom", bounds.bottom());
  window_preferences->SetBoolean(L"maximized", maximized);
  window_preferences->SetBoolean(L"always_on_top", always_on_top);
}

bool WindowDelegate::GetSavedWindowBounds(gfx::Rect* bounds) const {
  std::wstring window_name = GetWindowName();
  if (window_name.empty())
    return false;

  const DictionaryValue* dictionary =
      g_browser_process->local_state()->GetDictionary(window_name.c_str());
  int left, top, right, bottom;
  if (!dictionary || !dictionary->GetInteger(L"left", &left) ||
      !dictionary->GetInteger(L"top", &top) ||
      !dictionary->GetInteger(L"right", &right) ||
      !dictionary->GetInteger(L"bottom", &bottom))
    return false;

  bounds->SetRect(left, top, right - left, bottom - top);
  return true;
}

bool WindowDelegate::GetSavedMaximizedState(bool* maximized) const {
  std::wstring window_name = GetWindowName();
  if (window_name.empty())
    return false;

  const DictionaryValue* dictionary =
      g_browser_process->local_state()->GetDictionary(window_name.c_str());
  return dictionary && dictionary->GetBoolean(L"maximized", maximized);
}

bool WindowDelegate::GetSavedAlwaysOnTopState(bool* always_on_top) const {
  if (!g_browser_process->local_state())
    return false;

  std::wstring window_name = GetWindowName();
  if (window_name.empty())
    return false;

  const DictionaryValue* dictionary =
      g_browser_process->local_state()->GetDictionary(window_name.c_str());
  return dictionary && dictionary->GetBoolean(L"always_on_top", always_on_top);
}


ClientView* WindowDelegate::CreateClientView(Window* window) {
  return new ClientView(window, GetContentsView());
}

void WindowDelegate::ReleaseWindow() {
  window_.release();
}

}  // namespace views