summaryrefslogtreecommitdiffstats
path: root/aura
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-01 02:57:32 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-01 02:57:32 +0000
commite0dfebf8d0b7d9d902f16a92d6ab7b6f1140ca99 (patch)
treed71b7f80665b5afc8fd1d4b82db6143a61f913d8 /aura
parent16cd877ed6fc2b62c05eb51ba8071dc169834439 (diff)
downloadchromium_src-e0dfebf8d0b7d9d902f16a92d6ab7b6f1140ca99.zip
chromium_src-e0dfebf8d0b7d9d902f16a92d6ab7b6f1140ca99.tar.gz
chromium_src-e0dfebf8d0b7d9d902f16a92d6ab7b6f1140ca99.tar.bz2
Wire MouseEvents through to the NativeWidgetAura.
http://crbug.com/93933 TEST=none Review URL: http://codereview.chromium.org/7812014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99108 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'aura')
-rw-r--r--aura/demo/demo_main.cc2
-rw-r--r--aura/root_window.cc4
-rw-r--r--aura/window.cc40
-rw-r--r--aura/window.h21
-rw-r--r--aura/window_delegate.h2
-rw-r--r--aura/window_unittest.cc2
6 files changed, 29 insertions, 42 deletions
diff --git a/aura/demo/demo_main.cc b/aura/demo/demo_main.cc
index 2cdeb66..73090d1 100644
--- a/aura/demo/demo_main.cc
+++ b/aura/demo/demo_main.cc
@@ -23,7 +23,7 @@ class DemoWindowDelegate : public aura::WindowDelegate {
public:
explicit DemoWindowDelegate(SkColor color) : color_(color) {}
- virtual bool OnMouseEvent(const aura::MouseEvent& event) OVERRIDE {
+ virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE {
return true;
}
diff --git a/aura/root_window.cc b/aura/root_window.cc
index 6e3df25..36d61c3 100644
--- a/aura/root_window.cc
+++ b/aura/root_window.cc
@@ -24,9 +24,11 @@ bool RootWindow::HandleMouseEvent(const MouseEvent& event) {
target = GetEventHandlerForPoint(event.location());
if (event.type() == ui::ET_MOUSE_PRESSED && !mouse_pressed_handler_)
mouse_pressed_handler_ = target;
+ if (event.type() == ui::ET_MOUSE_RELEASED)
+ mouse_pressed_handler_ = NULL;
if (target->delegate()) {
MouseEvent translated_event(event, this, target);
- return target->delegate()->OnMouseEvent(translated_event);
+ return target->delegate()->OnMouseEvent(&translated_event);
}
return false;
}
diff --git a/aura/window.cc b/aura/window.cc
index 5a81bfe..204e188 100644
--- a/aura/window.cc
+++ b/aura/window.cc
@@ -18,7 +18,6 @@ namespace aura {
Window::Window(WindowDelegate* delegate)
: delegate_(delegate),
visibility_(VISIBILITY_HIDDEN),
- needs_paint_all_(true),
parent_(NULL),
id_(-1) {
}
@@ -32,6 +31,7 @@ Window::~Window() {
void Window::Init() {
layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor()));
+ layer_->set_delegate(this);
}
void Window::SetVisibility(Visibility visibility) {
@@ -39,6 +39,8 @@ void Window::SetVisibility(Visibility visibility) {
return;
visibility_ = visibility;
+ if (visibility_ != VISIBILITY_HIDDEN)
+ SchedulePaint();
}
void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) {
@@ -48,11 +50,8 @@ void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) {
layer_->SetBounds(bounds);
}
-void Window::SchedulePaint(const gfx::Rect& bounds) {
- if (dirty_rect_.IsEmpty())
- dirty_rect_ = bounds;
- else
- dirty_rect_ = dirty_rect_.Union(bounds);
+void Window::SchedulePaintInRect(const gfx::Rect& rect) {
+ layer_->SchedulePaint(rect);
}
void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) {
@@ -71,9 +70,7 @@ void Window::SetParent(Window* parent) {
}
void Window::DrawTree() {
- UpdateLayerCanvas();
Draw();
-
for (Windows::iterator i = children_.begin(); i != children_.end(); ++i)
(*i)->DrawTree();
}
@@ -125,28 +122,17 @@ Window* Window::GetEventHandlerForPoint(const gfx::Point& point) {
return this;
}
-void Window::UpdateLayerCanvas() {
- if (needs_paint_all_) {
- needs_paint_all_ = false;
- dirty_rect_ = gfx::Rect(0, 0, bounds().width(), bounds().height());
- }
- gfx::Rect dirty_rect = dirty_rect_.Intersect(
- gfx::Rect(0, 0, bounds().width(), bounds().height()));
- dirty_rect_.SetRect(0, 0, 0, 0);
- if (dirty_rect.IsEmpty())
- return;
- if (delegate_) {
- scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas(
- dirty_rect.width(), dirty_rect.height(), false));
- canvas->TranslateInt(dirty_rect.x(), dirty_rect.y());
- delegate_->OnPaint(canvas.get());
- SetCanvas(*canvas->AsCanvasSkia(), bounds().origin());
- }
-}
-
void Window::Draw() {
if (visibility_ != VISIBILITY_HIDDEN)
layer_->Draw();
}
+void Window::SchedulePaint() {
+ SchedulePaintInRect(gfx::Rect(0, 0, bounds_.width(), bounds_.height()));
+}
+
+void Window::OnPaint(gfx::Canvas* canvas) {
+ delegate_->OnPaint(canvas);
+}
+
} // namespace aura
diff --git a/aura/window.h b/aura/window.h
index f5667b8..1e62283 100644
--- a/aura/window.h
+++ b/aura/window.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
+#include "ui/gfx/compositor/layer_delegate.h"
#include "ui/gfx/rect.h"
class SkCanvas;
@@ -28,7 +29,7 @@ class WindowDelegate;
// Aura window implementation. Interesting events are sent to the
// WindowDelegate.
// TODO(beng): resolve ownership.
-class Window {
+class Window : public ui::LayerDelegate {
public:
enum Visibility {
// Don't display the window onscreen and don't let it receive mouse
@@ -61,8 +62,8 @@ class Window {
void SetBounds(const gfx::Rect& bounds, int anim_ms);
const gfx::Rect& bounds() const { return bounds_; }
- // Marks the window as needing to be painted.
- void SchedulePaint(const gfx::Rect& bounds);
+ // Marks the a portion of window as needing to be painted.
+ void SchedulePaintInRect(const gfx::Rect& rect);
// Sets the contents of the window.
void SetCanvas(const SkCanvas& canvas, const gfx::Point& origin);
@@ -110,20 +111,18 @@ class Window {
// Draws the Window's contents.
void Draw();
+ // Schedules a paint for the Window's entire bounds.
+ void SchedulePaint();
+
+ // Overridden from ui::LayerDelegate:
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
+
WindowDelegate* delegate_;
Visibility visibility_;
scoped_ptr<ui::Layer> layer_;
- // Union of regions passed to SchedulePaint. Cleaned when UpdateLayerCanvas is
- // invoked.
- gfx::Rect dirty_rect_;
-
- // If true UpdateLayerCanvas paints all. This is set when the window is first
- // created to trigger painting the complete bounds.
- bool needs_paint_all_;
-
// Bounds of the window in the desktop's coordinate system.
gfx::Rect bounds_;
diff --git a/aura/window_delegate.h b/aura/window_delegate.h
index 93ad8f5..fc82fd6 100644
--- a/aura/window_delegate.h
+++ b/aura/window_delegate.h
@@ -17,7 +17,7 @@ class MouseEvent;
// Delegate interface for aura::Window.
class WindowDelegate {
public:
- virtual bool OnMouseEvent(const MouseEvent& event) = 0;
+ virtual bool OnMouseEvent(MouseEvent* event) = 0;
// Asks the delegate to paint window contents into the supplied canvas.
virtual void OnPaint(gfx::Canvas* canvas) = 0;
diff --git a/aura/window_unittest.cc b/aura/window_unittest.cc
index 7e16519..b32a9f9 100644
--- a/aura/window_unittest.cc
+++ b/aura/window_unittest.cc
@@ -23,7 +23,7 @@ class TestWindowDelegate : public WindowDelegate {
virtual ~TestWindowDelegate() {}
// Overridden from WindowDelegate:
- virtual bool OnMouseEvent(const MouseEvent& event) OVERRIDE { return false; }
+ virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { return false; }
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
canvas->AsCanvasSkia()->drawColor(color_, SkXfermode::kSrc_Mode);
}