forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shell of implementation for embedded windows. At this point this is
just a proof of concept. Next step is going to be pulling code from the window manager into this. Desktop will likely be renamed to WindowManager. At this point just make sure you think I'm not going off into the weeds. BUG=none TEST=none R=derat@chromium.org Review URL: http://codereview.chromium.org/7534002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94733 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
sky@chromium.org
committed
Jul 29, 2011
1 parent
f1aa356
commit 81585f3
Showing
13 changed files
with
584 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# 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. | ||
|
||
{ | ||
'variables': { | ||
'chromium_code': 1, | ||
}, | ||
'targets': [ | ||
{ | ||
'target_name': 'aura', | ||
'type': 'static_library', | ||
'dependencies': [ | ||
'../base/base.gyp:base', | ||
'../base/base.gyp:base_i18n', | ||
'../skia/skia.gyp:skia', | ||
'../ui/gfx/compositor/compositor.gyp:compositor', | ||
'../ui/ui.gyp:gfx_resources', | ||
'../ui/ui.gyp:ui', | ||
'../ui/ui.gyp:ui_resources', | ||
], | ||
'sources': [ | ||
'desktop_host.h', | ||
'desktop_host_win.cc', | ||
'desktop_host_win.h', | ||
'desktop.cc', | ||
'desktop.h', | ||
'window.cc', | ||
'window.h', | ||
'window_delegate.h', | ||
], | ||
}, | ||
{ | ||
'target_name': 'aura_demo', | ||
'type': 'executable', | ||
'dependencies': [ | ||
'../base/base.gyp:base', | ||
'../base/base.gyp:base_i18n', | ||
'../skia/skia.gyp:skia', | ||
'../third_party/icu/icu.gyp:icui18n', | ||
'../third_party/icu/icu.gyp:icuuc', | ||
'../ui/gfx/compositor/compositor.gyp:compositor', | ||
'../ui/ui.gyp:gfx_resources', | ||
'../ui/ui.gyp:ui', | ||
'../ui/ui.gyp:ui_resources', | ||
'aura', | ||
], | ||
'include_dirs': [ | ||
'..', | ||
], | ||
'sources': [ | ||
'demo/demo_main.cc', | ||
'<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc', | ||
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources.rc', | ||
], | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// 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 "aura/desktop.h" | ||
#include "aura/desktop_host.h" | ||
#include "aura/window.h" | ||
#include "aura/window_delegate.h" | ||
#include "base/at_exit.h" | ||
#include "base/command_line.h" | ||
#include "base/i18n/icu_util.h" | ||
#include "base/memory/scoped_ptr.h" | ||
#include "base/message_loop.h" | ||
#include "third_party/skia/include/core/SkXfermode.h" | ||
#include "ui/base/resource/resource_bundle.h" | ||
#include "ui/gfx/canvas.h" | ||
#include "ui/gfx/canvas_skia.h" | ||
#include "ui/gfx/rect.h" | ||
#include "ui/base/ui_base_paths.h" | ||
|
||
namespace { | ||
|
||
// Trivial WindowDelegate implementation that draws a blue background. | ||
class DemoWindowDelegate : public aura::WindowDelegate { | ||
public: | ||
explicit DemoWindowDelegate(aura::Window* window); | ||
|
||
virtual void OnPaint(const gfx::Rect& bounds) OVERRIDE; | ||
|
||
private: | ||
aura::Window* window_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); | ||
}; | ||
|
||
DemoWindowDelegate::DemoWindowDelegate(aura::Window* window) | ||
: window_(window) { | ||
} | ||
|
||
void DemoWindowDelegate::OnPaint(const gfx::Rect& bounds) { | ||
scoped_ptr<gfx::Canvas> canvas( | ||
gfx::Canvas::CreateCanvas(bounds.width(), bounds.height(), false)); | ||
canvas->AsCanvasSkia()->drawColor( | ||
SK_ColorBLUE, SkXfermode::kSrc_Mode); | ||
window_->SetCanvas(*canvas->AsCanvasSkia(), bounds.origin()); | ||
} | ||
|
||
} // namespace | ||
|
||
int main(int argc, char** argv) { | ||
CommandLine::Init(argc, argv); | ||
|
||
// The exit manager is in charge of calling the dtors of singleton objects. | ||
base::AtExitManager exit_manager; | ||
|
||
ui::RegisterPathProvider(); | ||
icu_util::Initialize(); | ||
ResourceBundle::InitSharedInstance("en-US"); | ||
|
||
// Create the DesktopHost and Desktop. | ||
scoped_ptr<aura::DesktopHost> host( | ||
aura::DesktopHost::Create(gfx::Rect(200, 200, 1024, 768))); | ||
aura::Desktop desktop(host->GetAcceleratedWidget(), host->GetSize()); | ||
host->SetDesktop(&desktop); | ||
|
||
// Create a test window and give it a size. | ||
aura::Window window(&desktop); | ||
window.SetBounds(gfx::Rect(100, 100, 400, 400), 0); | ||
window.SetVisibility(aura::Window::VISIBILITY_SHOWN); | ||
DemoWindowDelegate window_delegate(&window); | ||
window.set_delegate(&window_delegate); | ||
|
||
host->Show(); | ||
|
||
MessageLoop main_message_loop(MessageLoop::TYPE_UI); | ||
MessageLoopForUI::current()->Run(NULL); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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 "aura/desktop.h" | ||
|
||
#include <algorithm> | ||
|
||
#include "aura/window.h" | ||
#include "base/logging.h" | ||
#include "ui/gfx/compositor/compositor.h" | ||
|
||
namespace aura { | ||
|
||
Desktop::Desktop(gfx::AcceleratedWidget widget, const gfx::Size& size) | ||
: compositor_(ui::Compositor::Create(widget, size)) { | ||
DCHECK(compositor_.get()); | ||
} | ||
|
||
Desktop::~Desktop() { | ||
} | ||
|
||
void Desktop::Draw() { | ||
// First pass updates the layer bitmaps. | ||
for (Windows::iterator i = windows_.begin(); i != windows_.end(); ++i) | ||
(*i)->UpdateLayerCanvas(); | ||
|
||
// Second pass renders the layers. | ||
compositor_->NotifyStart(); | ||
for (Windows::iterator i = windows_.begin(); i != windows_.end(); ++i) | ||
(*i)->Draw(); | ||
compositor_->NotifyEnd(); | ||
} | ||
|
||
void Desktop::AddWindow(Window* window) { | ||
DCHECK(std::find(windows_.begin(), windows_.end(), window) == windows_.end()); | ||
windows_.push_back(window); | ||
} | ||
|
||
void Desktop::RemoveWindow(Window* window) { | ||
Windows::iterator i = std::find(windows_.begin(), windows_.end(), window); | ||
DCHECK(i != windows_.end()); | ||
windows_.erase(i); | ||
} | ||
|
||
} // namespace aura |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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 AURA_DESKTOP_H_ | ||
#define AURA_DESKTOP_H_ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "base/basictypes.h" | ||
#include "base/memory/ref_counted.h" | ||
#include "ui/gfx/native_widget_types.h" | ||
|
||
namespace gfx { | ||
class Size; | ||
} | ||
|
||
namespace ui { | ||
class Compositor; | ||
class Window; | ||
} | ||
|
||
namespace aura { | ||
|
||
// Desktop is responsible for hosting a set of windows. | ||
class Desktop { | ||
public: | ||
Desktop(gfx::AcceleratedWidget widget, const gfx::Size& size); | ||
~Desktop(); | ||
|
||
// Draws the necessary set of windows. | ||
void Draw(); | ||
|
||
// Compositor we're drawing to. | ||
ui::Compositor* compositor() { return compositor_.get(); } | ||
|
||
private: | ||
friend class Window; | ||
|
||
typedef std::vector<Window*> Windows; | ||
|
||
// Methods invoked by Window. | ||
// TODO: move these into an interface that Window uses to talk to Desktop. | ||
void AddWindow(Window* window); | ||
void RemoveWindow(Window* window); | ||
|
||
scoped_refptr<ui::Compositor> compositor_; | ||
|
||
// The windows. Topmost window is last. | ||
std::vector<Window*> windows_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(Desktop); | ||
}; | ||
|
||
} // namespace aura | ||
|
||
#endif // AURA_DESKTOP_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// 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 AURA_DESKTOP_HOST_H_ | ||
#define AURA_DESKTOP_HOST_H_ | ||
#pragma once | ||
|
||
#include "ui/gfx/native_widget_types.h" | ||
|
||
namespace gfx { | ||
class Rect; | ||
class Size; | ||
} | ||
|
||
namespace aura { | ||
|
||
class Desktop; | ||
|
||
// DesktopHost bridges between a native window and the embedded Desktop. It | ||
// provides the accelerated widget and maps events from the native os to aura. | ||
class DesktopHost { | ||
public: | ||
virtual ~DesktopHost() {} | ||
|
||
// Creates a new DesktopHost. The caller owns the returned value. | ||
static DesktopHost* Create(const gfx::Rect& bounds); | ||
|
||
// Sets the Desktop this DesktopHost is hosting. DesktopHost does not own the | ||
// Desktop. | ||
virtual void SetDesktop(Desktop* desktop) = 0; | ||
|
||
// Returns the accelerated widget. | ||
virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0; | ||
|
||
// Shows the DesktopHost. | ||
virtual void Show() = 0; | ||
|
||
// Returns the size of the DesktopHost. | ||
virtual gfx::Size GetSize() = 0; | ||
}; | ||
|
||
} // namespace aura | ||
|
||
#endif // AURA_DESKTOP_HOST_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
#include "aura/desktop_host_win.h" | ||
|
||
#include "aura/desktop.h" | ||
#include "base/message_loop.h" | ||
|
||
namespace aura { | ||
|
||
// static | ||
DesktopHost* DesktopHost::Create(const gfx::Rect& bounds) { | ||
return new DesktopHostWin(bounds); | ||
} | ||
|
||
DesktopHostWin::DesktopHostWin(const gfx::Rect& bounds) : desktop_(NULL) { | ||
Init(NULL, bounds); | ||
} | ||
|
||
DesktopHostWin::~DesktopHostWin() { | ||
DestroyWindow(hwnd()); | ||
} | ||
|
||
void DesktopHostWin::SetDesktop(Desktop* desktop) { | ||
desktop_ = desktop; | ||
} | ||
|
||
gfx::AcceleratedWidget DesktopHostWin::GetAcceleratedWidget() { | ||
return hwnd(); | ||
} | ||
|
||
void DesktopHostWin::Show() { | ||
ShowWindow(hwnd(), SW_SHOWNORMAL); | ||
} | ||
|
||
gfx::Size DesktopHostWin::GetSize() { | ||
RECT r; | ||
GetClientRect(hwnd(), &r); | ||
return gfx::Rect(r).size(); | ||
} | ||
|
||
void DesktopHostWin::OnClose() { | ||
// TODO: this obviously shouldn't be here. | ||
MessageLoopForUI::current()->Quit(); | ||
} | ||
|
||
void DesktopHostWin::OnPaint(HDC dc) { | ||
if (desktop_) | ||
desktop_->Draw(); | ||
ValidateRect(hwnd(), NULL); | ||
} | ||
|
||
} // namespace aura |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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 AURA_DESKTOP_HOST_WIN_H_ | ||
#define AURA_DESKTOP_HOST_WIN_H_ | ||
#pragma once | ||
|
||
#include "aura/desktop_host.h" | ||
#include "base/compiler_specific.h" | ||
#include "ui/base/win/window_impl.h" | ||
|
||
namespace aura { | ||
|
||
class DesktopHostWin : public DesktopHost, public ui::WindowImpl { | ||
public: | ||
DesktopHostWin(const gfx::Rect& bounds); | ||
virtual ~DesktopHostWin(); | ||
|
||
// DesktopHost: | ||
virtual void SetDesktop(Desktop* desktop) OVERRIDE; | ||
virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; | ||
virtual void Show() OVERRIDE; | ||
virtual gfx::Size GetSize() OVERRIDE; | ||
|
||
private: | ||
BEGIN_MSG_MAP_EX(DesktopHostWin) | ||
MSG_WM_CLOSE(OnClose) | ||
MSG_WM_PAINT(OnPaint) | ||
END_MSG_MAP() | ||
|
||
void OnClose(); | ||
void OnPaint(HDC dc); | ||
|
||
Desktop* desktop_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(DesktopHostWin); | ||
}; | ||
|
||
} // namespace aura | ||
|
||
#endif // AURA_DESKTOP_HOST_WIN_H_ |
Oops, something went wrong.