diff options
-rw-r--r-- | aura/aura.gyp | 3 | ||||
-rw-r--r-- | aura/demo/demo_main.cc | 4 | ||||
-rw-r--r-- | aura/hit_test.h | 42 | ||||
-rw-r--r-- | aura/root_window.cc | 2 | ||||
-rw-r--r-- | aura/window.cc | 25 | ||||
-rw-r--r-- | aura/window.h | 9 | ||||
-rw-r--r-- | aura/window_delegate.h | 5 | ||||
-rw-r--r-- | aura/window_manager.cc | 62 | ||||
-rw-r--r-- | aura/window_manager.h | 47 | ||||
-rw-r--r-- | aura/window_unittest.cc | 3 | ||||
-rw-r--r-- | views/aura_desktop/aura_desktop_main.cc | 3 | ||||
-rw-r--r-- | views/widget/native_widget_aura.cc | 6 | ||||
-rw-r--r-- | views/widget/native_widget_aura.h | 1 |
13 files changed, 206 insertions, 6 deletions
diff --git a/aura/aura.gyp b/aura/aura.gyp index a304860..cbea4f6 100644 --- a/aura/aura.gyp +++ b/aura/aura.gyp @@ -29,11 +29,14 @@ 'event.cc', 'event.h', 'event_win.cc', + 'hit_test.h', 'root_window.cc', 'root_window.h', 'window.cc', 'window.h', 'window_delegate.h', + 'window_manager.cc', + 'window_manager.h', ], }, { diff --git a/aura/demo/demo_main.cc b/aura/demo/demo_main.cc index 73090d1..c994390 100644 --- a/aura/demo/demo_main.cc +++ b/aura/demo/demo_main.cc @@ -23,6 +23,10 @@ class DemoWindowDelegate : public aura::WindowDelegate { public: explicit DemoWindowDelegate(SkColor color) : color_(color) {} + virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { + return HTCAPTION; + } + virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE { return true; } diff --git a/aura/hit_test.h b/aura/hit_test.h new file mode 100644 index 0000000..c064866 --- /dev/null +++ b/aura/hit_test.h @@ -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_HIT_TEST_H_ +#define AURA_HIT_TEST_H_ +#pragma once + +// Defines the same symbolic names used by the WM_NCHITTEST Notification under +// win32 (the integer values are not guaranteed to be equivalent). We do this +// because we have a whole bunch of code that deals with window resizing and +// such that requires these values. +enum HitTestCompat { + HTBORDER = 1, + HTBOTTOM, + HTBOTTOMLEFT, + HTBOTTOMRIGHT, + HTCAPTION, + HTCLIENT, + HTCLOSE, + HTERROR, + HTGROWBOX, + HTHELP, + HTHSCROLL, + HTLEFT, + HTMENU, + HTMAXBUTTON, + HTMINBUTTON, + HTNOWHERE, + HTREDUCE, + HTRIGHT, + HTSIZE, + HTSYSMENU, + HTTOP, + HTTOPLEFT, + HTTOPRIGHT, + HTTRANSPARENT, + HTVSCROLL, + HTZOOM +}; + +#endif // AURA_HIT_TEST_H_ diff --git a/aura/root_window.cc b/aura/root_window.cc index 36d61c3..d14dcda 100644 --- a/aura/root_window.cc +++ b/aura/root_window.cc @@ -28,7 +28,7 @@ bool RootWindow::HandleMouseEvent(const MouseEvent& event) { mouse_pressed_handler_ = NULL; if (target->delegate()) { MouseEvent translated_event(event, this, target); - return target->delegate()->OnMouseEvent(&translated_event); + return target->OnMouseEvent(&translated_event); } return false; } diff --git a/aura/window.cc b/aura/window.cc index 204e188..2ebc210 100644 --- a/aura/window.cc +++ b/aura/window.cc @@ -7,7 +7,9 @@ #include <algorithm> #include "aura/desktop.h" +#include "aura/event.h" #include "aura/window_delegate.h" +#include "aura/window_manager.h" #include "base/logging.h" #include "ui/gfx/canvas_skia.h" #include "ui/gfx/compositor/compositor.h" @@ -46,8 +48,13 @@ void Window::SetVisibility(Visibility visibility) { void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) { // TODO: support anim_ms // TODO: funnel this through the Desktop. + bool was_move = bounds_.size() == bounds.size(); bounds_ = bounds; layer_->SetBounds(bounds); + if (was_move) + SchedulePaintInRect(gfx::Rect()); + else + SchedulePaint(); } void Window::SchedulePaintInRect(const gfx::Rect& rect) { @@ -69,6 +76,18 @@ void Window::SetParent(Window* parent) { Desktop::GetInstance()->window()->AddChild(this); } +void Window::MoveChildToFront(Window* child) { + DCHECK_EQ(child->parent(), this); + const Windows::iterator i(std::find(children_.begin(), children_.end(), + child)); + DCHECK(i != children_.end()); + children_.erase(i); + + // TODO(beng): this obviously has to handle different window types. + children_.insert(children_.begin() + children_.size(), child); + SchedulePaintInRect(gfx::Rect()); +} + void Window::DrawTree() { Draw(); for (Windows::iterator i = children_.begin(); i != children_.end(); ++i) @@ -98,8 +117,10 @@ void Window::ConvertPointToWindow(Window* source, ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point); } -bool Window::OnMouseEvent(const MouseEvent& event) { - return true; +bool Window::OnMouseEvent(MouseEvent* event) { + if (!window_manager_.get()) + window_manager_.reset(new WindowManager(this)); + return window_manager_->OnMouseEvent(event) || delegate_->OnMouseEvent(event); } bool Window::HitTest(const gfx::Point& point) { diff --git a/aura/window.h b/aura/window.h index 1e62283..0b5bfd4 100644 --- a/aura/window.h +++ b/aura/window.h @@ -25,6 +25,7 @@ namespace aura { class Desktop; class MouseEvent; class WindowDelegate; +class WindowManager; // Aura window implementation. Interesting events are sent to the // WindowDelegate. @@ -73,6 +74,10 @@ class Window : public ui::LayerDelegate { void SetParent(Window* parent); Window* parent() { return parent_; } + // Move the specified child of this Window to the front of the z-order. + // TODO(beng): this is (obviously) feeble. + void MoveChildToFront(Window* child); + // Draw the window and its children. void DrawTree(); @@ -87,7 +92,7 @@ class Window : public ui::LayerDelegate { gfx::Point* point); // Handles a mouse event. Returns true if handled. - bool OnMouseEvent(const MouseEvent& event); + bool OnMouseEvent(MouseEvent* event); WindowDelegate* delegate() { return delegate_; } @@ -135,6 +140,8 @@ class Window : public ui::LayerDelegate { int id_; + scoped_ptr<WindowManager> window_manager_; + DISALLOW_COPY_AND_ASSIGN(Window); }; diff --git a/aura/window_delegate.h b/aura/window_delegate.h index fc82fd6..4627d4f 100644 --- a/aura/window_delegate.h +++ b/aura/window_delegate.h @@ -8,6 +8,7 @@ namespace gfx { class Canvas; +class Point; } namespace aura { @@ -17,6 +18,10 @@ class MouseEvent; // Delegate interface for aura::Window. class WindowDelegate { public: + // Returns the non-client component (see hit_test.h) containing |point|, in + // window coordinates. + virtual int GetNonClientComponent(const gfx::Point& point) const = 0; + virtual bool OnMouseEvent(MouseEvent* event) = 0; // Asks the delegate to paint window contents into the supplied canvas. diff --git a/aura/window_manager.cc b/aura/window_manager.cc new file mode 100644 index 0000000..ea07281 --- /dev/null +++ b/aura/window_manager.cc @@ -0,0 +1,62 @@ +// 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/window_manager.h" + +#include "aura/event.h" +#include "aura/window.h" +#include "aura/window_delegate.h" + +#if !defined(OS_WIN) +#include "aura/hit_test.h" +#endif + +namespace aura { + +WindowManager::WindowManager(Window* owner) + : owner_(owner), + window_component_(HTNOWHERE) { +} + +WindowManager::~WindowManager() { +} + +bool WindowManager::OnMouseEvent(MouseEvent* event) { + switch (event->type()) { + case ui::ET_MOUSE_PRESSED: + window_component_ = + owner_->delegate()->GetNonClientComponent(event->location()); + MoveWindowToFront(); + mouse_down_offset_ = event->location(); + window_location_ = owner_->bounds().origin(); + break; + case ui::ET_MOUSE_DRAGGED: + if (window_component_ == HTCAPTION) { + gfx::Point new_origin(event->location()); + new_origin.Offset(-mouse_down_offset_.x(), -mouse_down_offset_.y()); + new_origin.Offset(owner_->bounds().x(), owner_->bounds().y()); + owner_->SetBounds(gfx::Rect(new_origin, owner_->bounds().size()), 0); + return true; + } + break; + case ui::ET_MOUSE_RELEASED: + window_component_ = HTNOWHERE; + break; + default: + break; + } + return false; +} + +void WindowManager::MoveWindowToFront() { + Window* parent = owner_->parent(); + Window* child = owner_; + while (parent) { + parent->MoveChildToFront(child); + parent = parent->parent(); + child = child->parent(); + } +} + +} // namespace aura diff --git a/aura/window_manager.h b/aura/window_manager.h new file mode 100644 index 0000000..0ed18cd --- /dev/null +++ b/aura/window_manager.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 AURA_WINDOW_MANAGER_H_ +#define AURA_WINDOW_MANAGER_H_ +#pragma once + +#include "base/logging.h" +#include "ui/gfx/point.h" + +namespace aura { + +class Window; +class MouseEvent; + +// An object that filters events sent to an owner window, potentially performing +// adjustments to the window's position, size and z-index. +// +// TODO(beng): Make this into an interface so we can have specializations for +// different types of Window and product. +class WindowManager { + public: + explicit WindowManager(Window* owner); + ~WindowManager(); + + // Try to handle |event| (before the owner's delegate gets a chance to). + // Returns true if the event was handled by the WindowManager and should not + // be forwarded to the owner's delegate. + bool OnMouseEvent(MouseEvent* event); + + private: + // Moves the owner window and all of its parents to the front of their + // respective z-orders. + void MoveWindowToFront(); + + Window* owner_; + gfx::Point mouse_down_offset_; + gfx::Point window_location_; + int window_component_; + + DISALLOW_COPY_AND_ASSIGN(WindowManager); +}; + +} // namespace aura + +#endif // AURA_WINDOW_MANAGER_H_ diff --git a/aura/window_unittest.cc b/aura/window_unittest.cc index b32a9f9..db09a86 100644 --- a/aura/window_unittest.cc +++ b/aura/window_unittest.cc @@ -23,6 +23,9 @@ class TestWindowDelegate : public WindowDelegate { virtual ~TestWindowDelegate() {} // Overridden from WindowDelegate: + virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { + return HTCLIENT; + } virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { return false; } virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { canvas->AsCanvasSkia()->drawColor(color_, SkXfermode::kSrc_Mode); diff --git a/views/aura_desktop/aura_desktop_main.cc b/views/aura_desktop/aura_desktop_main.cc index 219f5e5..6c3d049 100644 --- a/views/aura_desktop/aura_desktop_main.cc +++ b/views/aura_desktop/aura_desktop_main.cc @@ -27,6 +27,9 @@ class DemoWindowDelegate : public aura::WindowDelegate { public: explicit DemoWindowDelegate(SkColor color) : color_(color) {} + virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { + return HTCLIENT; + } virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE { return true; } diff --git a/views/widget/native_widget_aura.cc b/views/widget/native_widget_aura.cc index fc5e5bb..92572e2 100644 --- a/views/widget/native_widget_aura.cc +++ b/views/widget/native_widget_aura.cc @@ -363,6 +363,10 @@ void NativeWidgetAura::DispatchKeyEventPostIME(const KeyEvent& key) { //////////////////////////////////////////////////////////////////////////////// // NativeWidgetAura, aura::WindowDelegate implementation: +int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { + return delegate_->GetNonClientComponent(point); +} + bool NativeWidgetAura::OnMouseEvent(aura::MouseEvent* event) { return delegate_->OnMouseEvent(MouseEvent(event)); } @@ -394,8 +398,6 @@ bool Widget::ConvertRect(const Widget* source, return false; } - - namespace internal { //////////////////////////////////////////////////////////////////////////////// diff --git a/views/widget/native_widget_aura.h b/views/widget/native_widget_aura.h index 8c1f495..3a870d9 100644 --- a/views/widget/native_widget_aura.h +++ b/views/widget/native_widget_aura.h @@ -109,6 +109,7 @@ class NativeWidgetAura : public internal::NativeWidgetPrivate, virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE; // Overridden from aura::WindowDelegate: + virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE; virtual bool OnMouseEvent(aura::MouseEvent* event) OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual void OnWindowDestroyed() OVERRIDE; |