summaryrefslogtreecommitdiffstats
path: root/aura
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-18 22:47:50 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-18 22:47:50 +0000
commitb1b155519ce57a29f336a248080b4e5c61c8a10a (patch)
tree57d87f20660354f0a24cbb3be362d0a23cf72b26 /aura
parentdeb02d935d80c1b30d43575378714585a554d7ad (diff)
downloadchromium_src-b1b155519ce57a29f336a248080b4e5c61c8a10a.zip
chromium_src-b1b155519ce57a29f336a248080b4e5c61c8a10a.tar.gz
chromium_src-b1b155519ce57a29f336a248080b4e5c61c8a10a.tar.bz2
Add support for child Windows to the Aura WM library.
BUG=none TEST=none Review URL: http://codereview.chromium.org/7670075 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97383 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'aura')
-rw-r--r--aura/demo/demo_main.cc45
-rw-r--r--aura/desktop.cc21
-rw-r--r--aura/desktop.h20
-rw-r--r--aura/window.cc49
-rw-r--r--aura/window.h36
5 files changed, 107 insertions, 64 deletions
diff --git a/aura/demo/demo_main.cc b/aura/demo/demo_main.cc
index ccb77de..2c8091d 100644
--- a/aura/demo/demo_main.cc
+++ b/aura/demo/demo_main.cc
@@ -23,25 +23,27 @@ namespace {
// Trivial WindowDelegate implementation that draws a blue background.
class DemoWindowDelegate : public aura::WindowDelegate {
public:
- explicit DemoWindowDelegate(aura::Window* window);
+ explicit DemoWindowDelegate(aura::Window* window, SkColor color);
virtual void OnPaint(const gfx::Rect& bounds) OVERRIDE;
private:
aura::Window* window_;
+ SkColor color_;
+
DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
};
-DemoWindowDelegate::DemoWindowDelegate(aura::Window* window)
- : window_(window) {
+DemoWindowDelegate::DemoWindowDelegate(aura::Window* window, SkColor color)
+ : window_(window),
+ color_(color) {
}
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);
+ canvas->AsCanvasSkia()->drawColor(color_, SkXfermode::kSrc_Mode);
window_->SetCanvas(*canvas->AsCanvasSkia(), bounds.origin());
}
@@ -63,12 +65,33 @@ int main(int argc, char** argv) {
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);
+ // Create a hierarchy of test windows.
+ aura::Window window1(&desktop);
+ window1.set_id(1);
+ window1.SetBounds(gfx::Rect(100, 100, 400, 400), 0);
+ window1.SetVisibility(aura::Window::VISIBILITY_SHOWN);
+ DemoWindowDelegate window_delegate1(&window1, SK_ColorBLUE);
+ window1.set_delegate(&window_delegate1);
+
+ desktop.window()->AddChild(&window1);
+
+ aura::Window window2(&desktop);
+ window2.set_id(2);
+ window2.SetBounds(gfx::Rect(200, 200, 350, 350), 0);
+ window2.SetVisibility(aura::Window::VISIBILITY_SHOWN);
+ DemoWindowDelegate window_delegate2(&window2, SK_ColorRED);
+ window2.set_delegate(&window_delegate2);
+
+ desktop.window()->AddChild(&window2);
+
+ aura::Window window3(&desktop);
+ window3.set_id(3);
+ window3.SetBounds(gfx::Rect(10, 10, 50, 50), 0);
+ window3.SetVisibility(aura::Window::VISIBILITY_SHOWN);
+ DemoWindowDelegate window_delegate3(&window3, SK_ColorGREEN);
+ window3.set_delegate(&window_delegate3);
+
+ window2.AddChild(&window3);
host->Show();
diff --git a/aura/desktop.cc b/aura/desktop.cc
index c8b9187..0055450 100644
--- a/aura/desktop.cc
+++ b/aura/desktop.cc
@@ -4,8 +4,6 @@
#include "aura/desktop.h"
-#include <algorithm>
-
#include "aura/window.h"
#include "base/logging.h"
#include "ui/gfx/compositor/compositor.h"
@@ -15,32 +13,17 @@ namespace aura {
Desktop::Desktop(gfx::AcceleratedWidget widget, const gfx::Size& size)
: compositor_(ui::Compositor::Create(widget, size)) {
DCHECK(compositor_.get());
+ window_.reset(new Window(this));
}
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();
+ window_->DrawTree();
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
diff --git a/aura/desktop.h b/aura/desktop.h
index 4bed643..4df3742 100644
--- a/aura/desktop.h
+++ b/aura/desktop.h
@@ -6,8 +6,7 @@
#define AURA_DESKTOP_H_
#pragma once
-#include <vector>
-
+#include "aura/window.h"
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "ui/gfx/native_widget_types.h"
@@ -18,11 +17,12 @@ class Size;
namespace ui {
class Compositor;
-class Window;
}
namespace aura {
+class Window;
+
// Desktop is responsible for hosting a set of windows.
class Desktop {
public:
@@ -35,20 +35,12 @@ class Desktop {
// 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);
+ Window* window() { return window_.get(); }
+ private:
scoped_refptr<ui::Compositor> compositor_;
- // The windows. Topmost window is last.
- std::vector<Window*> windows_;
+ scoped_ptr<Window> window_;
DISALLOW_COPY_AND_ASSIGN(Desktop);
};
diff --git a/aura/window.cc b/aura/window.cc
index 7725ffc..2d63d80 100644
--- a/aura/window.cc
+++ b/aura/window.cc
@@ -4,8 +4,11 @@
#include "aura/window.h"
+#include <algorithm>
+
#include "aura/desktop.h"
#include "aura/window_delegate.h"
+#include "base/logging.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
@@ -14,12 +17,12 @@ namespace aura {
// TODO: do we need to support child windows?
Window::Window(Desktop* desktop)
- : desktop_(desktop),
- delegate_(NULL),
+ : delegate_(NULL),
visibility_(VISIBILITY_HIDDEN),
- // TODO: Need to make layers lazily create the texture.
layer_(new ui::Layer(desktop->compositor())),
- needs_paint_all_(true) {
+ needs_paint_all_(true),
+ parent_(NULL),
+ id_(-1) {
}
Window::~Window() {
@@ -30,13 +33,6 @@ void Window::SetVisibility(Visibility visibility) {
return;
visibility_ = visibility;
- if (visibility_ == VISIBILITY_SHOWN) {
- // TODO: move to top of window stack?
- desktop_->AddWindow(this);
- } else {
- // TODO: hide?
- desktop_->RemoveWindow(this);
- }
}
void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) {
@@ -61,9 +57,29 @@ void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) {
layer_->SetCanvas(canvas, origin);
}
-void Window::Draw() {
- if (visibility_ != VISIBILITY_HIDDEN)
- layer_->Draw();
+void Window::DrawTree() {
+ UpdateLayerCanvas();
+ Draw();
+
+ // First pass updates the layer bitmaps.
+ for (Windows::iterator i = children_.begin(); i != children_.end(); ++i)
+ (*i)->DrawTree();
+}
+
+void Window::AddChild(Window* child) {
+ DCHECK(std::find(children_.begin(), children_.end(), child) ==
+ children_.end());
+ child->parent_ = this;
+ layer_->Add(child->layer_.get());
+ children_.push_back(child);
+}
+
+void Window::RemoveChild(Window* child) {
+ Windows::iterator i = std::find(children_.begin(), children_.end(), child);
+ DCHECK(i != children_.end());
+ child->parent_ = NULL;
+ layer_->Remove(child->layer_.get());
+ children_.erase(i);
}
void Window::UpdateLayerCanvas() {
@@ -80,4 +96,9 @@ void Window::UpdateLayerCanvas() {
delegate_->OnPaint(dirty_rect);
}
+void Window::Draw() {
+ if (visibility_ != VISIBILITY_HIDDEN)
+ layer_->Draw();
+}
+
} // namespace aura
diff --git a/aura/window.h b/aura/window.h
index 14c3ea4..b4611c4 100644
--- a/aura/window.h
+++ b/aura/window.h
@@ -6,6 +6,8 @@
#define AURA_WINDOW_H_
#pragma once
+#include <vector>
+
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "ui/gfx/native_widget_types.h"
@@ -14,6 +16,7 @@
class SkCanvas;
namespace ui {
+class Compositor;
class Layer;
}
@@ -43,7 +46,10 @@ class Window {
void set_delegate(WindowDelegate* d) { delegate_ = d; }
- // Changes the visbility of the window.
+ int id() const { return id_; }
+ void set_id(int id) { id_ = id; }
+
+ // Changes the visibility of the window.
void SetVisibility(Visibility visibility);
Visibility visibility() const { return visibility_; }
@@ -57,15 +63,24 @@ class Window {
// Sets the contents of the window.
void SetCanvas(const SkCanvas& canvas, const gfx::Point& origin);
- // If the window is visible its layer is drawn.
- void Draw();
+ // Draw the window and its children.
+ void DrawTree();
+
+ // Tree operations.
+ // TODO(beng): Child windows are currently not owned by the hierarchy. We
+ // should change this.
+ void AddChild(Window* child);
+ void RemoveChild(Window* child);
+ Window* parent() { return parent_; }
+
+ private:
+ typedef std::vector<Window*> Windows;
// If SchedulePaint has been invoked on the Window the delegate is notified.
void UpdateLayerCanvas();
- private:
- // The desktop we're in.
- Desktop* desktop_;
+ // Draws the Window's contents.
+ void Draw();
WindowDelegate* delegate_;
@@ -84,6 +99,15 @@ class Window {
// Bounds of the window in the desktop's coordinate system.
gfx::Rect bounds_;
+ // The Window's parent.
+ // TODO(beng): Implement NULL-ness for toplevels.
+ Window* parent_;
+
+ // Child windows. Topmost is last.
+ Windows children_;
+
+ int id_;
+
DISALLOW_COPY_AND_ASSIGN(Window);
};