summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/DEPS26
-rw-r--r--chrome/browser/views/chrome_views_delegate.cc85
-rw-r--r--chrome/browser/views/chrome_views_delegate.h36
-rw-r--r--views/views_delegate.h64
4 files changed, 198 insertions, 13 deletions
diff --git a/app/DEPS b/app/DEPS
index cf364f4..5ad4cd1 100644
--- a/app/DEPS
+++ b/app/DEPS
@@ -1,16 +1,16 @@
-include_rules = [
+include_rules = [
# TODO(beng): Modify this link to be more specific about what resource
# headers are included once app gets its own strings.
- "+grit",
- "+net",
- # TODO(beng): Sever these links once we have extracted all deps from
- # chrome/common.
- "+chrome/common/chrome_paths.h",
- "+chrome/common/chrome_switches.h",
- "+chrome/common/gtk_util.h",
+ "+grit",
+ "+net",
+ # TODO(beng): Sever these links once we have extracted all deps from
+ # chrome/common.
+ "+chrome/common/chrome_paths.h",
+ "+chrome/common/chrome_switches.h",
+ "+chrome/common/gtk_util.h",
- # TODO(beng): l10n_util_unittest.cc:
- "+chrome/test/data/resource.h",
-
- "+skia",
-]
+ # TODO(beng): l10n_util_unittest.cc:
+ "+chrome/test/data/resource.h",
+
+ "+skia",
+]
diff --git a/chrome/browser/views/chrome_views_delegate.cc b/chrome/browser/views/chrome_views_delegate.cc
new file mode 100644
index 0000000..1c04bc6
--- /dev/null
+++ b/chrome/browser/views/chrome_views_delegate.cc
@@ -0,0 +1,85 @@
+// Copyright (c) 2009 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 "chrome/browser/views/chrome_views_delegate.h"
+
+#include "base/clipboard.h"
+#include "base/gfx/rect.h"
+#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/common/pref_service.h"
+
+///////////////////////////////////////////////////////////////////////////////
+// ChromeViewsDelegate, views::ViewsDelegate implementation:
+
+Clipboard* ChromeViewsDelegate::GetClipboard() const {
+ return g_browser_process->clipboard();
+}
+
+void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name,
+ const gfx::Rect& bounds,
+ bool maximized,
+ bool always_on_top) {
+ if (!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 ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name,
+ gfx::Rect* bounds) const {
+ if (!g_browser_process->local_state())
+ 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 ChromeViewsDelegate::GetSavedMaximizedState(
+ const std::wstring& window_name,
+ bool* maximized) const {
+ if (!g_browser_process->local_state())
+ return false;
+
+ const DictionaryValue* dictionary =
+ g_browser_process->local_state()->GetDictionary(window_name.c_str());
+ return dictionary && dictionary->GetBoolean(L"maximized", maximized) &&
+ maximized;
+}
+
+bool ChromeViewsDelegate::GetSavedAlwaysOnTopState(
+ const std::wstring& window_name,
+ bool* always_on_top) const {
+ if (!g_browser_process->local_state())
+ 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) &&
+ always_on_top;
+}
+
+#if defined(OS_WIN)
+HICON ChromeViewsDelegate::GetDefaultWindowIcon() const {
+ return LoadIcon(GetModuleHandle(L"chrome.dll"),
+ MAKEINTRESOURCE(IDR_MAINFRAME));
+}
+#endif
diff --git a/chrome/browser/views/chrome_views_delegate.h b/chrome/browser/views/chrome_views_delegate.h
new file mode 100644
index 0000000..007e7b0
--- /dev/null
+++ b/chrome/browser/views/chrome_views_delegate.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2009 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.
+
+#ifndef CHROME_BROWSER_VIEWS_CHROME_VIEWS_DELEGATE_H_
+#define CHROME_BROWSER_VIEWS_CHROME_VIEWS_DELEGATE_H_
+
+#include "base/logging.h"
+#include "views/views_delegate.h"
+
+class ChromeViewsDelegate : public views::ViewsDelegate {
+ public:
+ ChromeViewsDelegate() {}
+ virtual ~ChromeViewsDelegate() {}
+
+ // Overridden from views::ViewsDelegate:
+ virtual Clipboard* GetClipboard() const;
+ virtual void SaveWindowPlacement(const std::wstring& window_name,
+ const gfx::Rect& bounds,
+ bool maximized,
+ bool always_on_top);
+ virtual bool GetSavedWindowBounds(const std::wstring& window_name,
+ gfx::Rect* bounds) const;
+ virtual bool GetSavedMaximizedState(const std::wstring& window_name,
+ bool* maximized) const;
+ virtual bool GetSavedAlwaysOnTopState(const std::wstring& window_name,
+ bool* always_on_top) const;
+#if defined(OS_WIN)
+ virtual HICON GetDefaultWindowIcon() const;
+#endif
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ChromeViewsDelegate);
+};
+
+#endif // #ifndef CHROME_BROWSER_VIEWS_CHROME_VIEWS_DELEGATE_H_
diff --git a/views/views_delegate.h b/views/views_delegate.h
new file mode 100644
index 0000000..082689c
--- /dev/null
+++ b/views/views_delegate.h
@@ -0,0 +1,64 @@
+// Copyright (c) 2009 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.
+
+#ifndef VIEWS_VIEWS_DELEGATE_H_
+#define VIEWS_VIEWS_DELEGATE_H_
+
+#include <string>
+#if defined(OS_WIN)
+#include <windows.h>
+#endif
+
+class Clipboard;
+namespace gfx {
+class Rect;
+}
+
+namespace views {
+
+// ViewsDelegate is an interface implemented by an object using the views
+// framework. It is used to obtain various high level application utilities
+// and perform some actions such as window placement saving.
+//
+// The embedding app must set views_delegate to assign its ViewsDelegate
+// implementation.
+class ViewsDelegate {
+ public:
+ // Gets the clipboard.
+ virtual Clipboard* GetClipboard() const = 0;
+
+ // Saves the position, size, maximized and always-on-top state for the
+ // window with the specified name.
+ virtual void SaveWindowPlacement(const std::wstring& window_name,
+ const gfx::Rect& bounds,
+ bool maximized,
+ bool always_on_top) = 0;
+
+ // Retrieves the saved position and size for the window with the specified
+ // name.
+ virtual bool GetSavedWindowBounds(const std::wstring& window_name,
+ gfx::Rect* bounds) const = 0;
+
+ // Retrieves the saved maximized state for the window with the specified
+ // name.
+ virtual bool GetSavedMaximizedState(const std::wstring& window_name,
+ bool* maximized) const = 0;
+
+ // Retrieves the saved always-on-top state for the window with the specified
+ // name.
+ virtual bool GetSavedAlwaysOnTopState(const std::wstring& window_name,
+ bool* always_on_top) const = 0;
+
+#if defined(OS_WIN)
+ // Retrieves the default window icon to use for windows if none is specified.
+ virtual HICON GetDefaultWindowIcon() const = 0;
+#endif
+
+ // The active ViewsDelegate used by the views system.
+ static ViewsDelegate* views_delegate;
+};
+
+} // namespace views
+
+#endif // #ifndef VIEWS_VIEWS_DELEGATE_H_