summaryrefslogtreecommitdiffstats
path: root/views/desktop
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-26 15:46:44 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-26 15:46:44 +0000
commita10aaf77fe489a9c4ec5d7fdf963342196061185 (patch)
tree3ed6327aeef3fd9047fc47b5bf4537ae7ef7e1ed /views/desktop
parent64a2b8abb122d9d30407fe5fe46c66ee92c248c8 (diff)
downloadchromium_src-a10aaf77fe489a9c4ec5d7fdf963342196061185.zip
chromium_src-a10aaf77fe489a9c4ec5d7fdf963342196061185.tar.gz
chromium_src-a10aaf77fe489a9c4ec5d7fdf963342196061185.tar.bz2
Add a desktop test harness.
http://crbug.com/83663 TEST=none Review URL: http://codereview.chromium.org/7068036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86831 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/desktop')
-rw-r--r--views/desktop/desktop_background.cc55
-rw-r--r--views/desktop/desktop_background.h29
-rw-r--r--views/desktop/desktop_main.cc56
-rw-r--r--views/desktop/desktop_views_delegate.cc77
-rw-r--r--views/desktop/desktop_views_delegate.h54
-rw-r--r--views/desktop/desktop_window.cc149
-rw-r--r--views/desktop/desktop_window.h47
7 files changed, 467 insertions, 0 deletions
diff --git a/views/desktop/desktop_background.cc b/views/desktop/desktop_background.cc
new file mode 100644
index 0000000..a6d7a64
--- /dev/null
+++ b/views/desktop/desktop_background.cc
@@ -0,0 +1,55 @@
+// Copyright (c) 2011 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/desktop/desktop_background.h"
+
+#include "ui/gfx/canvas_skia.h"
+#include "ui/gfx/path.h"
+#include "views/view.h"
+
+namespace views {
+namespace desktop {
+
+DesktopBackground::DesktopBackground() {
+}
+
+DesktopBackground::~DesktopBackground() {
+}
+
+void DesktopBackground::Paint(gfx::Canvas* canvas, View* view) const {
+ // Paint the sky.
+ canvas->FillRectInt(SK_ColorCYAN, 0, 0, view->width(), view->width());
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setStyle(SkPaint::kFill_Style);
+
+ // Paint the rolling fields of green.
+ {
+ gfx::Path path;
+ path.moveTo(0, view->height() / 2);
+ path.cubicTo(view->height() / 4, view->height() / 4,
+ view->height() / 2, view->height() / 2,
+ SkIntToScalar(view->width()), view->height() / 2);
+ path.lineTo(SkIntToScalar(view->width()), SkIntToScalar(view->height()));
+ path.lineTo(0, SkIntToScalar(view->height()));
+ path.close();
+
+ paint.setColor(SK_ColorGREEN);
+ canvas->AsCanvasSkia()->drawPath(path, paint);
+ }
+
+ // Paint the shining sun.
+ {
+ gfx::Path path;
+ path.addCircle(view->height() / 4, view->height() / 8, view->height() / 16);
+ path.close();
+
+ paint.setColor(SK_ColorYELLOW);
+ canvas->AsCanvasSkia()->drawPath(path, paint);
+ }
+}
+
+} // namespace desktop
+} // namespace views
diff --git a/views/desktop/desktop_background.h b/views/desktop/desktop_background.h
new file mode 100644
index 0000000..9ebb2ae
--- /dev/null
+++ b/views/desktop/desktop_background.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2011 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_DESKTOP_DESKTOP_BACKGROUND_H_
+#define VIEWS_DESKTOP_DESKTOP_BACKGROUND_H_
+
+#include "base/compiler_specific.h"
+#include "views/background.h"
+
+namespace views {
+namespace desktop {
+
+class DesktopBackground : public Background {
+ public:
+ DesktopBackground();
+ virtual ~DesktopBackground();
+
+ private:
+ // Overridden from Background:
+ virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(DesktopBackground);
+};
+
+} // namespace desktop
+} // namespace views
+
+#endif // VIEWS_DESKTOP_DESKTOP_BACKGROUND_H_
diff --git a/views/desktop/desktop_main.cc b/views/desktop/desktop_main.cc
new file mode 100644
index 0000000..96bdefd
--- /dev/null
+++ b/views/desktop/desktop_main.cc
@@ -0,0 +1,56 @@
+// Copyright (c) 2011 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 "app/app_paths.h"
+#include "base/at_exit.h"
+#include "base/command_line.h"
+#include "base/i18n/icu_util.h"
+#include "base/process_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/ui_base_paths.h"
+#include "views/desktop/desktop_views_delegate.h"
+#include "views/desktop/desktop_window.h"
+#include "views/focus/accelerator_handler.h"
+#include "views/widget/widget.h"
+
+#if defined(OS_WIN)
+#include <ole2.h>
+#endif
+
+int main(int argc, char** argv) {
+#if defined(OS_WIN)
+ OleInitialize(NULL);
+#endif
+
+ CommandLine::Init(argc, argv);
+
+ base::EnableTerminationOnHeapCorruption();
+
+ // The exit manager is in charge of calling the dtors of singleton objects.
+ base::AtExitManager exit_manager;
+
+ app::RegisterPathProvider();
+ ui::RegisterPathProvider();
+
+ icu_util::Initialize();
+
+ ResourceBundle::InitSharedInstance("en-US");
+
+ MessageLoop main_message_loop(MessageLoop::TYPE_UI);
+
+ views::desktop::DesktopViewsDelegate views_delegate;
+
+ // Desktop mode only supports a pure-views configuration.
+ views::Widget::SetPureViews(true);
+
+ views::desktop::DesktopWindow::CreateDesktopWindow();
+
+ views::AcceleratorHandler accelerator_handler;
+ MessageLoopForUI::current()->Run(&accelerator_handler);
+
+#if defined(OS_WIN)
+ OleUninitialize();
+#endif
+ return 0;
+}
diff --git a/views/desktop/desktop_views_delegate.cc b/views/desktop/desktop_views_delegate.cc
new file mode 100644
index 0000000..00a2014
--- /dev/null
+++ b/views/desktop/desktop_views_delegate.cc
@@ -0,0 +1,77 @@
+// Copyright (c) 2011 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/desktop/desktop_views_delegate.h"
+
+#include "base/logging.h"
+
+namespace views {
+namespace desktop {
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopViewsDelegate, public:
+
+DesktopViewsDelegate::DesktopViewsDelegate() {
+ DCHECK(!views::ViewsDelegate::views_delegate);
+ views::ViewsDelegate::views_delegate = this;
+}
+
+DesktopViewsDelegate::~DesktopViewsDelegate() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopViewsDelegate, ViewsDelegate implementation:
+
+ui::Clipboard* DesktopViewsDelegate::GetClipboard() const {
+ return NULL;
+}
+
+void DesktopViewsDelegate::SaveWindowPlacement(views::Window* window,
+ const std::wstring& window_name,
+ const gfx::Rect& bounds,
+ bool maximized) {
+}
+
+bool DesktopViewsDelegate::GetSavedWindowBounds(views::Window* window,
+ const std::wstring& window_name,
+ gfx::Rect* bounds) const {
+ return false;
+}
+
+bool DesktopViewsDelegate::GetSavedMaximizedState(views::Window* window,
+ const std::wstring& window_name,
+ bool* maximized) const {
+ return false;
+}
+
+void DesktopViewsDelegate::NotifyAccessibilityEvent(
+ views::View* view, ui::AccessibilityTypes::Event event_type) {
+}
+
+void DesktopViewsDelegate::NotifyMenuItemFocused(
+ const std::wstring& menu_name,
+ const std::wstring& menu_item_name,
+ int item_index,
+ int item_count,
+ bool has_submenu) {
+}
+
+#if defined(OS_WIN)
+HICON DesktopViewsDelegate::GetDefaultWindowIcon() const {
+ return NULL;
+}
+#endif
+
+void DesktopViewsDelegate::AddRef() {
+}
+
+void DesktopViewsDelegate::ReleaseRef() {
+}
+
+int DesktopViewsDelegate::GetDispositionForEvent(int event_flags) {
+ return 0;
+}
+
+} // namespace desktop
+} // namespace views
diff --git a/views/desktop/desktop_views_delegate.h b/views/desktop/desktop_views_delegate.h
new file mode 100644
index 0000000..fdc2fe0
--- /dev/null
+++ b/views/desktop/desktop_views_delegate.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2011 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_DESKTOP_DESKTOP_VIEWS_DELEGATE_H_
+#define VIEWS_DESKTOP_DESKTOP_VIEWS_DELEGATE_H_
+
+#include "base/compiler_specific.h"
+#include "views/views_delegate.h"
+
+namespace views {
+namespace desktop {
+
+class DesktopViewsDelegate : public ViewsDelegate {
+ public:
+ DesktopViewsDelegate();
+ virtual ~DesktopViewsDelegate();
+
+ private:
+ // Overridden from ViewsDelegate:
+ virtual ui::Clipboard* GetClipboard() const OVERRIDE;
+ virtual void SaveWindowPlacement(views::Window* window,
+ const std::wstring& window_name,
+ const gfx::Rect& bounds,
+ bool maximized) OVERRIDE;
+ virtual bool GetSavedWindowBounds(views::Window* window,
+ const std::wstring& window_name,
+ gfx::Rect* bounds) const OVERRIDE;
+ virtual bool GetSavedMaximizedState(views::Window* window,
+ const std::wstring& window_name,
+ bool* maximized) const OVERRIDE;
+ virtual void NotifyAccessibilityEvent(
+ views::View* view, ui::AccessibilityTypes::Event event_type) OVERRIDE;
+ virtual void NotifyMenuItemFocused(
+ const std::wstring& menu_name,
+ const std::wstring& menu_item_name,
+ int item_index,
+ int item_count,
+ bool has_submenu) OVERRIDE;
+#if defined(OS_WIN)
+ virtual HICON GetDefaultWindowIcon() const OVERRIDE;
+#endif
+ virtual void AddRef() OVERRIDE;
+ virtual void ReleaseRef() OVERRIDE;
+ virtual int GetDispositionForEvent(int event_flags) OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(DesktopViewsDelegate);
+};
+
+
+} // namespace desktop
+} // namespace views
+
+#endif // VIEWS_DESKTOP_DESKTOP_VIEWS_DELEGATE_H_
diff --git a/views/desktop/desktop_window.cc b/views/desktop/desktop_window.cc
new file mode 100644
index 0000000..a8f9dd8
--- /dev/null
+++ b/views/desktop/desktop_window.cc
@@ -0,0 +1,149 @@
+// Copyright (c) 2011 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/desktop/desktop_window.h"
+
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/transform.h"
+#include "views/desktop/desktop_background.h"
+#include "views/window/native_window_views.h"
+#include "views/window/window.h"
+
+#if defined(OS_WIN)
+#include "views/window/native_window_win.h"
+#elif defined(TOOLKIT_USES_GTK)
+#include "views/window/native_window_gtk.h"
+#endif
+
+namespace views {
+namespace desktop {
+
+class TestWindowContentView : public View,
+ public WindowDelegate {
+ public:
+ TestWindowContentView(const std::wstring& title, SkColor color)
+ : title_(title),
+ color_(color) {
+ }
+ virtual ~TestWindowContentView() {}
+
+ private:
+ // Overridden from View:
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+ canvas->FillRectInt(color_, 0, 0, width(), height());
+ }
+
+ // Overridden from WindowDelegate:
+ virtual std::wstring GetWindowTitle() const OVERRIDE {
+ return title_;
+ }
+ virtual View* GetContentsView() {
+ return this;
+ }
+
+ SkColor color_;
+ std::wstring title_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestWindowContentView);
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopWindow, public:
+
+DesktopWindow::DesktopWindow() {
+ set_background(new DesktopBackground);
+}
+
+DesktopWindow::~DesktopWindow() {
+}
+
+// static
+void DesktopWindow::CreateDesktopWindow() {
+ DesktopWindow* desktop = new DesktopWindow;
+ views::Window* window = new views::Window;
+ views::Window::InitParams params(desktop);
+ // In this environment, CreateChromeWindow will default to creating a views-
+ // window, so we need to construct a NativeWindowWin by hand.
+ // TODO(beng): Replace this with NativeWindow::CreateNativeRootWindow().
+#if defined(OS_WIN)
+ params.native_window = new views::NativeWindowWin(window);
+#elif defined(TOOLKIT_USES_GTK)
+ params.native_window = new views::NativeWindowGtk(window);
+#endif
+ params.widget_init_params.bounds = gfx::Rect(20, 20, 1920, 1200);
+ window->InitWindow(params);
+ window->Show();
+
+ desktop->CreateTestWindow(L"Sample Window 1", SK_ColorWHITE,
+ gfx::Rect(500, 200, 400, 400), true);
+ desktop->CreateTestWindow(L"Sample Window 2", SK_ColorRED,
+ gfx::Rect(600, 650, 450, 300), false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopWindow, View overrides:
+
+void DesktopWindow::Layout() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopWindow, WindowDelegate implementation:
+
+bool DesktopWindow::CanResize() const {
+ return true;
+}
+
+bool DesktopWindow::CanMaximize() const {
+ return CanResize();
+}
+
+std::wstring DesktopWindow::GetWindowTitle() const {
+ return L"Aura Desktop";
+}
+
+SkBitmap DesktopWindow::GetWindowAppIcon() {
+ return SkBitmap();
+}
+
+SkBitmap DesktopWindow::GetWindowIcon() {
+ return SkBitmap();
+}
+
+bool DesktopWindow::ShouldShowWindowIcon() const {
+ return false;
+}
+
+void DesktopWindow::WindowClosing() {
+ MessageLoopForUI::current()->Quit();
+}
+
+View* DesktopWindow::GetContentsView() {
+ return this;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopWindow, private:
+
+void DesktopWindow::CreateTestWindow(const std::wstring& title,
+ SkColor color,
+ gfx::Rect initial_bounds,
+ bool rotate) {
+ views::Window* window = new views::Window;
+ views::NativeWindowViews* nwv = new views::NativeWindowViews(this, window);
+ views::Window::InitParams params(new TestWindowContentView(title, color));
+ params.native_window = nwv;
+ params.widget_init_params.bounds = initial_bounds;
+ window->InitWindow(params);
+ window->Show();
+
+ if (rotate) {
+ ui::Transform transform;
+ transform.SetRotate(90.0f);
+ transform.SetTranslateX(window->GetBounds().width());
+ nwv->GetView()->SetTransform(transform);
+ }
+}
+
+} // namespace desktop
+} // namespace views
diff --git a/views/desktop/desktop_window.h b/views/desktop/desktop_window.h
new file mode 100644
index 0000000..d15bde9
--- /dev/null
+++ b/views/desktop/desktop_window.h
@@ -0,0 +1,47 @@
+// Copyright (c) 2011 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_DESKTOP_DESKTOP_WINDOW_H_
+#define VIEWS_DESKTOP_DESKTOP_WINDOW_H_
+
+#include "views/view.h"
+#include "views/window/window_delegate.h"
+
+namespace views {
+namespace desktop {
+
+class DesktopWindow : public View,
+ public WindowDelegate {
+ public:
+ DesktopWindow();
+ virtual ~DesktopWindow();
+
+ static void CreateDesktopWindow();
+
+ private:
+ // Overridden from View:
+ virtual void Layout() OVERRIDE;
+
+ // Overridden from WindowDelegate:
+ virtual bool CanResize() const OVERRIDE;
+ virtual bool CanMaximize() const OVERRIDE;
+ virtual std::wstring GetWindowTitle() const OVERRIDE;
+ virtual SkBitmap GetWindowAppIcon() OVERRIDE;
+ virtual SkBitmap GetWindowIcon() OVERRIDE;
+ virtual bool ShouldShowWindowIcon() const OVERRIDE;
+ virtual void WindowClosing() OVERRIDE;
+ virtual View* GetContentsView() OVERRIDE;
+
+ void CreateTestWindow(const std::wstring& title,
+ SkColor color,
+ gfx::Rect initial_bounds,
+ bool rotate);
+
+ DISALLOW_COPY_AND_ASSIGN(DesktopWindow);
+};
+
+} // namespace desktop
+} // namespace views
+
+#endif // VIEWS_DESKTOP_DESKTOP_WINDOW_H_