summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/desktop/desktop_window_manager.cc193
-rw-r--r--views/desktop/desktop_window_manager.h69
-rw-r--r--views/desktop/desktop_window_view.cc6
-rw-r--r--views/view.cc23
-rw-r--r--views/views.gyp4
-rw-r--r--views/widget/native_widget_gtk.cc6
-rw-r--r--views/widget/native_widget_gtk.h2
-rw-r--r--views/widget/native_widget_private.h2
-rw-r--r--views/widget/native_widget_view.cc35
-rw-r--r--views/widget/native_widget_view.h2
-rw-r--r--views/widget/native_widget_views.cc43
-rw-r--r--views/widget/native_widget_views.h4
-rw-r--r--views/widget/native_widget_win.cc6
-rw-r--r--views/widget/native_widget_win.h2
-rw-r--r--views/widget/root_view.cc46
-rw-r--r--views/widget/root_view.h8
-rw-r--r--views/widget/widget.cc6
-rw-r--r--views/widget/widget.h11
-rw-r--r--views/widget/window_manager.cc88
-rw-r--r--views/widget/window_manager.h63
20 files changed, 540 insertions, 79 deletions
diff --git a/views/desktop/desktop_window_manager.cc b/views/desktop/desktop_window_manager.cc
new file mode 100644
index 0000000..7276ecc
--- /dev/null
+++ b/views/desktop/desktop_window_manager.cc
@@ -0,0 +1,193 @@
+// 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_manager.h"
+
+#include "views/events/event.h"
+#include "views/widget/widget.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
+#include "views/widget/widget.h"
+#include "views/widget/native_widget_private.h"
+#include "views/widget/native_widget_views.h"
+#include "views/widget/widget_delegate.h"
+#if defined(OS_LINUX)
+#include "views/window/hit_test.h"
+#endif
+#include "views/window/non_client_view.h"
+
+namespace {
+
+class MoveWindowController : public views::desktop::WindowController {
+ public:
+ MoveWindowController(views::Widget* widget, const gfx::Point& start)
+ : target_(widget),
+ offset_(start) {
+ }
+
+ virtual ~MoveWindowController() {
+ }
+
+ bool OnMouseEvent(const views::MouseEvent& event) {
+ if (event.type()== ui::ET_MOUSE_DRAGGED) {
+ gfx::Point origin = event.location().Subtract(offset_);
+ gfx::Rect rect = target_->GetWindowScreenBounds();
+ rect.set_origin(origin);
+ target_->SetBounds(rect);
+ return true;
+ }
+ return false;
+ }
+
+ private:
+ views::Widget* target_;
+ gfx::Point offset_;
+
+ DISALLOW_COPY_AND_ASSIGN(MoveWindowController);
+};
+
+// Simple resize controller that handle all resize as if the bottom
+// right corner is selected.
+class ResizeWindowController : public views::desktop::WindowController {
+ public:
+ ResizeWindowController(views::Widget* widget)
+ : target_(widget) {
+ }
+
+ virtual ~ResizeWindowController() {
+ }
+
+ bool OnMouseEvent(const views::MouseEvent& event) OVERRIDE {
+ if (event.type()== ui::ET_MOUSE_DRAGGED) {
+ gfx::Point location = event.location();
+ gfx::Rect rect = target_->GetWindowScreenBounds();
+ gfx::Point size = location.Subtract(rect.origin());
+ target_->SetSize(gfx::Size(std::max(10, size.x()),
+ std::max(10, size.y())));
+ return true;
+ }
+ return false;
+ }
+
+ private:
+ views::Widget* target_;
+
+ DISALLOW_COPY_AND_ASSIGN(ResizeWindowController);
+};
+
+} // namespace
+
+namespace views {
+namespace desktop {
+
+WindowController::WindowController() {
+}
+
+WindowController::~WindowController() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopWindowManager, public:
+
+DesktopWindowManager::DesktopWindowManager(Widget* desktop)
+ : desktop_(desktop),
+ mouse_capture_(NULL) {
+}
+
+DesktopWindowManager::~DesktopWindowManager() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopWindowManager, WindowManager implementation:
+
+void DesktopWindowManager::StartMoveDrag(
+ views::Widget* widget,
+ const gfx::Point& point) {
+ DCHECK(!window_controller_.get());
+ DCHECK(!HasMouseCapture());
+ if (!widget->IsMaximized() && !widget->IsMinimized()) {
+ gfx::Point new_point = point;
+ if (desktop_->non_client_view()) {
+ gfx::Rect client =
+ desktop_->non_client_view()->frame_view()->GetBoundsForClientView();
+ new_point.Offset(client.x(), client.y());
+ }
+ SetMouseCapture();
+ window_controller_.reset(new MoveWindowController(widget, new_point));
+ }
+}
+
+void DesktopWindowManager::StartResizeDrag(
+ views::Widget* widget, const gfx::Point& point, int hittest_code) {
+ DCHECK(!window_controller_.get());
+ DCHECK(!HasMouseCapture());
+ if (!widget->IsMaximized() &&
+ !widget->IsMinimized() &&
+ (widget->widget_delegate() || widget->widget_delegate()->CanResize())) {
+ SetMouseCapture();
+ window_controller_.reset(new ResizeWindowController(widget));
+ }
+}
+
+bool DesktopWindowManager::SetMouseCapture(views::Widget* widget) {
+ if (mouse_capture_)
+ return false;
+ if (mouse_capture_ == widget)
+ return true;
+ DCHECK(!HasMouseCapture());
+ SetMouseCapture();
+ mouse_capture_ = widget;
+ return true;
+}
+
+bool DesktopWindowManager::ReleaseMouseCapture(views::Widget* widget) {
+ if (!widget || mouse_capture_ != widget)
+ return false;
+ DCHECK(HasMouseCapture());
+ ReleaseMouseCapture();
+ mouse_capture_ = NULL;
+ return true;
+}
+
+bool DesktopWindowManager::HasMouseCapture(const views::Widget* widget) const {
+ return widget && mouse_capture_ == widget;
+}
+
+bool DesktopWindowManager::HandleMouseEvent(
+ views::Widget* widget, const views::MouseEvent& event) {
+
+ if (window_controller_.get()) {
+ if (!window_controller_->OnMouseEvent(event)) {
+ ReleaseMouseCapture();
+ window_controller_.reset();
+ }
+ return true;
+ }
+
+ if (mouse_capture_) {
+ views::MouseEvent translated(event, widget->GetRootView(),
+ mouse_capture_->GetRootView());
+ mouse_capture_->OnMouseEvent(translated);
+ return true;
+ }
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopWindowManager, private:
+
+void DesktopWindowManager::SetMouseCapture() {
+ return desktop_->native_widget_private()->SetMouseCapture();
+}
+
+void DesktopWindowManager::ReleaseMouseCapture() {
+ return desktop_->native_widget_private()->ReleaseMouseCapture();
+}
+
+bool DesktopWindowManager::HasMouseCapture() const {
+ return desktop_->native_widget_private()->HasMouseCapture();
+}
+
+} // namespace desktop
+} // namespace views
diff --git a/views/desktop/desktop_window_manager.h b/views/desktop/desktop_window_manager.h
new file mode 100644
index 0000000..146bb2a
--- /dev/null
+++ b/views/desktop/desktop_window_manager.h
@@ -0,0 +1,69 @@
+// 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_MANAGER_H_
+#define VIEWS_DESKTOP_DESKTOP_WINDOW_MANAGER_H_
+
+#include "base/compiler_specific.h"
+#include "base/scoped_ptr.h"
+#include "views/widget/window_manager.h"
+
+namespace gfx {
+class Point;
+}
+
+namespace views {
+class Widget;
+
+namespace desktop {
+class WindowController;
+
+// A tentative window manager for views destktop until we have *right*
+// implementation based on aura/layer API. This is minimum
+// implmenetation and complicated actio like moving transformed window
+// doesn't work. TODO(oshima): move active widget to WindowManager.
+class DesktopWindowManager : public views::WindowManager {
+ public:
+ DesktopWindowManager(Widget* desktop);
+ virtual ~DesktopWindowManager();
+
+ // views::WindowManager implementations:
+ virtual void StartMoveDrag(views::Widget* widget,
+ const gfx::Point& point) OVERRIDE;
+ virtual void StartResizeDrag(views::Widget* widget,
+ const gfx::Point& point,
+ int hittest_code);
+ virtual bool SetMouseCapture(views::Widget* widget) OVERRIDE;
+ virtual bool ReleaseMouseCapture(views::Widget* widget) OVERRIDE;
+ virtual bool HasMouseCapture(const views::Widget* widget) const OVERRIDE;
+ virtual bool HandleMouseEvent(views::Widget* widget,
+ const views::MouseEvent& event) OVERRIDE;
+
+ private:
+ void SetMouseCapture();
+ void ReleaseMouseCapture();
+ bool HasMouseCapture() const;
+
+ views::Widget* desktop_;
+ views::Widget* mouse_capture_;
+ scoped_ptr<WindowController> window_controller_;
+
+ DISALLOW_COPY_AND_ASSIGN(DesktopWindowManager);
+};
+
+// An behavioral interface for objects implements window resize/movement.
+class WindowController {
+ public:
+ WindowController();
+ virtual ~WindowController();
+ virtual bool OnMouseEvent(const views::MouseEvent& event) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(WindowController);
+};
+
+} // namespace desktop
+} // namespace views
+
+#endif // VIEWS_DESKTOP_DESKTOP_WINDOW_MANAGER_H_
diff --git a/views/desktop/desktop_window_view.cc b/views/desktop/desktop_window_view.cc
index 966f2fc..1c3c72f 100644
--- a/views/desktop/desktop_window_view.cc
+++ b/views/desktop/desktop_window_view.cc
@@ -8,6 +8,7 @@
#include "ui/gfx/transform.h"
#include "views/desktop/desktop_background.h"
#include "views/desktop/desktop_window_root_view.h"
+#include "views/desktop/desktop_window_manager.h"
#include "views/layer_property_setter.h"
#include "views/widget/native_widget_view.h"
#include "views/widget/native_widget_views.h"
@@ -51,7 +52,8 @@ class DesktopWindow : public Widget {
if (native_widget)
return native_widget->delegate()->OnMouseEvent(event);
}
- return Widget::OnMouseEvent(event);
+ return WindowManager::Get()->HandleMouseEvent(this, event) ||
+ Widget::OnMouseEvent(event);
}
DesktopWindowView* desktop_window_view_;
@@ -128,6 +130,8 @@ void DesktopWindowView::CreateDesktopWindow(DesktopType type) {
views::Widget* window = new DesktopWindow(desktop_window_view);
desktop_window_view->widget_ = window;
+ WindowManager::Install(new DesktopWindowManager(window));
+
views::Widget::InitParams params;
params.delegate = desktop_window_view;
// In this environment, CreateChromeWindow will default to creating a views-
diff --git a/views/view.cc b/views/view.cc
index 46c5ed2..75a93b1 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -26,6 +26,7 @@
#include "views/layout/layout_manager.h"
#include "views/views_delegate.h"
#include "views/widget/native_widget_private.h"
+#include "views/widget/native_widget_views.h"
#include "views/widget/root_view.h"
#include "views/widget/tooltip_manager.h"
#include "views/widget/widget.h"
@@ -1687,12 +1688,28 @@ void View::ConvertPointToView(const View* src,
DCHECK(dst);
DCHECK(point);
+ const Widget* src_widget = src ? src->GetWidget() : NULL ;
+ const Widget* dst_widget = dst->GetWidget();
+ // If dest and src aren't in the same widget, try to convert the
+ // point to the destination widget's coordinates first.
+ // TODO(oshima|sadrul): Cleanup and consolidate conversion methods.
+ if (Widget::IsPureViews() && src_widget && src_widget != dst_widget) {
+ // convert to src_widget first.
+ gfx::Point p = *point;
+ src->ConvertPointForAncestor(src_widget->GetRootView(), &p);
+ if (dst_widget->ConvertPointFromAncestor(src_widget, &p)) {
+ // Convertion to destination widget's coordinates was successful.
+ // Use destination's root as a source to convert the point further.
+ src = dst_widget->GetRootView();
+ *point = p;
+ }
+ }
+
if (src == NULL || src->Contains(dst)) {
dst->ConvertPointFromAncestor(src, point);
if (!src) {
- const Widget* widget = dst->GetWidget();
- if (widget) {
- gfx::Rect b = widget->GetClientAreaScreenBounds();
+ if (dst_widget) {
+ gfx::Rect b = dst_widget->GetClientAreaScreenBounds();
point->SetPoint(point->x() - b.x(), point->y() - b.y());
}
}
diff --git a/views/views.gyp b/views/views.gyp
index 42d37ac..e8fe9f9 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -350,6 +350,8 @@
'widget/widget.h',
'widget/widget_delegate.cc',
'widget/widget_delegate.h',
+ 'widget/window_manager.cc',
+ 'widget/window_manager.h',
'window/client_view.cc',
'window/client_view.h',
'window/custom_frame_view.cc',
@@ -641,6 +643,8 @@
'sources': [
'desktop/desktop_background.cc',
'desktop/desktop_background.h',
+ 'desktop/desktop_window_manager.cc',
+ 'desktop/desktop_window_manager.h',
'desktop/desktop_window_root_view.cc',
'desktop/desktop_window_root_view.h',
'desktop/desktop_window_view.cc',
diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc
index b24412c..a57da4a 100644
--- a/views/widget/native_widget_gtk.cc
+++ b/views/widget/native_widget_gtk.cc
@@ -1328,6 +1328,12 @@ void NativeWidgetGtk::FocusNativeView(gfx::NativeView native_view) {
gtk_widget_grab_focus(native_view);
}
+bool NativeWidgetGtk::ConvertPointFromAncestor(
+ const Widget* ancestor, gfx::Point* point) const {
+ NOTREACHED();
+ return false;
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetGtk, protected:
diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h
index 8c9b3fa..051e40c 100644
--- a/views/widget/native_widget_gtk.h
+++ b/views/widget/native_widget_gtk.h
@@ -218,6 +218,8 @@ class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate,
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void ClearNativeFocus() OVERRIDE;
virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE;
+ virtual bool ConvertPointFromAncestor(
+ const Widget* ancestor, gfx::Point* point) const OVERRIDE;
protected:
// Modifies event coordinates to the targeted widget contained by this widget.
diff --git a/views/widget/native_widget_private.h b/views/widget/native_widget_private.h
index 3846b34..3c31663 100644
--- a/views/widget/native_widget_private.h
+++ b/views/widget/native_widget_private.h
@@ -209,6 +209,8 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget {
virtual void SetCursor(gfx::NativeCursor cursor) = 0;
virtual void ClearNativeFocus() = 0;
virtual void FocusNativeView(gfx::NativeView native_view) = 0;
+ virtual bool ConvertPointFromAncestor(
+ const Widget* ancestor, gfx::Point* point) const = 0;
// Overridden from NativeWidget:
virtual internal::NativeWidgetPrivate* AsNativeWidgetPrivate() OVERRIDE;
diff --git a/views/widget/native_widget_view.cc b/views/widget/native_widget_view.cc
index c816c0f..f3d675b 100644
--- a/views/widget/native_widget_view.cc
+++ b/views/widget/native_widget_view.cc
@@ -5,6 +5,10 @@
#include "views/widget/native_widget_view.h"
#include "ui/gfx/canvas.h"
+#if defined(OS_LINUX)
+#include "views/window/hit_test.h"
+#endif
+#include "views/widget/window_manager.h"
namespace views {
namespace internal {
@@ -76,6 +80,37 @@ gfx::NativeCursor NativeWidgetView::GetCursor(const MouseEvent& event) {
bool NativeWidgetView::OnMousePressed(const MouseEvent& event) {
MouseEvent e(event, this);
+ Widget* hosting_widget = GetAssociatedWidget();
+ if (hosting_widget->non_client_view()) {
+ int hittest_code = hosting_widget->non_client_view()->NonClientHitTest(
+ event.location());
+ switch (hittest_code) {
+ case HTCAPTION: {
+ if (!event.IsOnlyRightMouseButton()) {
+ WindowManager::Get()->StartMoveDrag(hosting_widget, event.location());
+ return true;
+ }
+ break;
+ }
+ case HTBOTTOM:
+ case HTBOTTOMLEFT:
+ case HTBOTTOMRIGHT:
+ case HTGROWBOX:
+ case HTLEFT:
+ case HTRIGHT:
+ case HTTOP:
+ case HTTOPLEFT:
+ case HTTOPRIGHT: {
+ WindowManager::Get()->StartResizeDrag(
+ hosting_widget, event.location(), hittest_code);
+ return true;
+ }
+ default:
+ // Everything else falls into standard client event handling...
+ break;
+ }
+ }
+
return delegate()->OnMouseEvent(event);
}
diff --git a/views/widget/native_widget_view.h b/views/widget/native_widget_view.h
index 88131132..9d2004f 100644
--- a/views/widget/native_widget_view.h
+++ b/views/widget/native_widget_view.h
@@ -15,8 +15,6 @@ enum TouchStatus;
}
namespace views {
-class NativeWidgetViews;
-
namespace internal {
////////////////////////////////////////////////////////////////////////////////
diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc
index 4009df8..ebb141e 100644
--- a/views/widget/native_widget_views.cc
+++ b/views/widget/native_widget_views.cc
@@ -10,6 +10,7 @@
#include "views/views_delegate.h"
#include "views/widget/native_widget_view.h"
#include "views/widget/root_view.h"
+#include "views/widget/window_manager.h"
#if defined(HAVE_IBUS)
#include "views/ime/input_method_ibus.h"
@@ -215,28 +216,15 @@ void NativeWidgetViews::SendNativeAccessibilityEvent(
}
void NativeWidgetViews::SetMouseCapture() {
- View* parent_root_view = GetParentNativeWidget()->GetWidget()->GetRootView();
- static_cast<internal::RootView*>(parent_root_view)->set_capture_view(view_);
- GetParentNativeWidget()->SetMouseCapture();
+ WindowManager::Get()->SetMouseCapture(GetWidget());
}
void NativeWidgetViews::ReleaseMouseCapture() {
- View* parent_root_view = GetParentNativeWidget()->GetWidget()->GetRootView();
- static_cast<internal::RootView*>(parent_root_view)->set_capture_view(NULL);
- GetParentNativeWidget()->ReleaseMouseCapture();
+ WindowManager::Get()->ReleaseMouseCapture(GetWidget());
}
bool NativeWidgetViews::HasMouseCapture() const {
- // NOTE: we may need to tweak this to only return true if the parent native
- // widget's RootView has us as the capture view.
- const internal::NativeWidgetPrivate* parent_widget = GetParentNativeWidget();
- if (!parent_widget)
- return false;
- const internal::RootView* parent_root =
- static_cast<const internal::RootView*>(parent_widget->GetWidget()->
- GetRootView());
- return parent_widget->HasMouseCapture() &&
- view_ == parent_root->capture_view();
+ return WindowManager::Get()->HasMouseCapture(GetWidget());
}
InputMethod* NativeWidgetViews::GetInputMethodNative() {
@@ -363,6 +351,8 @@ void NativeWidgetViews::Show() {
void NativeWidgetViews::Hide() {
view_->SetVisible(false);
+ if (HasMouseCapture())
+ ReleaseMouseCapture();
}
void NativeWidgetViews::ShowWithState(ShowState state) {
@@ -491,6 +481,27 @@ void NativeWidgetViews::FocusNativeView(gfx::NativeView native_view) {
GetParentNativeWidget()->FocusNativeView(native_view);
}
+bool NativeWidgetViews::ConvertPointFromAncestor(
+ const Widget* ancestor, gfx::Point* point) const {
+ // This method converts the point from ancestor's coordinates to
+ // this widget's coordinate using recursion as the widget hierachy
+ // is usually shallow.
+
+ if (ancestor == GetWidget())
+ return true; // no conversion necessary
+
+ const Widget* parent_widget = view_->GetWidget();
+ if (!parent_widget) // couldn't reach the ancestor.
+ return false;
+
+ if (parent_widget == ancestor ||
+ parent_widget->ConvertPointFromAncestor(ancestor, point)) {
+ View::ConvertPointToView(parent_widget->GetRootView(), GetView(), point);
+ return true;
+ }
+ return false;
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetViews, private:
diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h
index ed63ce8..1b4ad7d 100644
--- a/views/widget/native_widget_views.h
+++ b/views/widget/native_widget_views.h
@@ -48,6 +48,8 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate,
internal::NativeWidgetDelegate* delegate() { return delegate_; }
protected:
+ friend class NativeWidgetView;
+
// Overridden from internal::NativeWidgetPrivate:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
@@ -127,6 +129,8 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate,
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void ClearNativeFocus() OVERRIDE;
virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE;
+ virtual bool ConvertPointFromAncestor(
+ const Widget* ancestor, gfx::Point* point) const OVERRIDE;
// Overridden from internal::InputMethodDelegate
virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE;
diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc
index 36ae766..e7f1ebd 100644
--- a/views/widget/native_widget_win.cc
+++ b/views/widget/native_widget_win.cc
@@ -1090,6 +1090,12 @@ void NativeWidgetWin::FocusNativeView(gfx::NativeView native_view) {
::SetFocus(native_view);
}
+bool NativeWidgetWin::ConvertPointFromAncestor(
+ const Widget* ancestor, gfx::Point* point) const {
+ NOTREACHED();
+ return false;
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetWin, MessageLoop::Observer implementation:
diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h
index 1551f35..1525de7 100644
--- a/views/widget/native_widget_win.h
+++ b/views/widget/native_widget_win.h
@@ -268,6 +268,8 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
virtual void ClearNativeFocus() OVERRIDE;
virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE;
+ virtual bool ConvertPointFromAncestor(
+ const Widget* ancestor, gfx::Point* point) const OVERRIDE;
protected:
// Information saved before going into fullscreen mode, used to restore the
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc
index 85cb537..3e85938 100644
--- a/views/widget/root_view.cc
+++ b/views/widget/root_view.cc
@@ -30,7 +30,6 @@ const char RootView::kViewClassName[] = "views/RootView";
RootView::RootView(Widget* widget)
: widget_(widget),
- capture_view_(NULL),
mouse_pressed_handler_(NULL),
mouse_move_handler_(NULL),
last_click_handler_(NULL),
@@ -169,11 +168,6 @@ void RootView::SchedulePaintInternal(const gfx::Rect& rect) {
bool RootView::OnMousePressed(const MouseEvent& event) {
MouseEvent e(event, this);
- if (capture_view_) {
- MouseEvent ce(e, this, capture_view_);
- return capture_view_->OnMousePressed(ce);
- }
-
UpdateCursor(e);
SetMouseLocationAndFlags(e);
@@ -248,11 +242,6 @@ bool RootView::OnMousePressed(const MouseEvent& event) {
bool RootView::OnMouseDragged(const MouseEvent& event) {
MouseEvent e(event, this);
- if (capture_view_) {
- MouseEvent ce(e, this, capture_view_);
- return capture_view_->OnMouseDragged(ce);
- }
-
UpdateCursor(e);
if (mouse_pressed_handler_) {
@@ -266,12 +255,6 @@ bool RootView::OnMouseDragged(const MouseEvent& event) {
void RootView::OnMouseReleased(const MouseEvent& event) {
MouseEvent e(event, this);
- if (capture_view_) {
- MouseEvent ce(e, this, capture_view_);
- capture_view_->OnMouseReleased(ce);
- return;
- }
-
UpdateCursor(e);
if (mouse_pressed_handler_) {
@@ -286,13 +269,6 @@ void RootView::OnMouseReleased(const MouseEvent& event) {
}
void RootView::OnMouseCaptureLost() {
- if (capture_view_) {
- View* capture_view = capture_view_;
- capture_view_ = NULL;
- capture_view->OnMouseCaptureLost();
- return;
- }
-
if (mouse_pressed_handler_) {
// Synthesize a release event for UpdateCursor.
MouseEvent release_event(ui::ET_MOUSE_RELEASED, last_mouse_event_x_,
@@ -309,12 +285,6 @@ void RootView::OnMouseCaptureLost() {
void RootView::OnMouseMoved(const MouseEvent& event) {
MouseEvent e(event, this);
- if (capture_view_) {
- MouseEvent ce(e, this, capture_view_);
- capture_view_->OnMouseMoved(ce);
- return;
- }
-
View* v = GetEventHandlerForPoint(e.location());
// Find the first enabled view, or the existing move handler, whichever comes
// first. The check for the existing handler is because if a view becomes
@@ -341,12 +311,6 @@ void RootView::OnMouseMoved(const MouseEvent& event) {
}
void RootView::OnMouseExited(const MouseEvent& event) {
- if (capture_view_) {
- MouseEvent e(event, this, capture_view_);
- capture_view_->OnMouseExited(e);
- return;
- }
-
if (mouse_move_handler_ != NULL) {
mouse_move_handler_->OnMouseExited(event);
mouse_move_handler_ = NULL;
@@ -354,9 +318,6 @@ void RootView::OnMouseExited(const MouseEvent& event) {
}
bool RootView::OnMouseWheel(const MouseWheelEvent& event) {
- if (capture_view_)
- return capture_view_->OnMouseWheel(event);
-
MouseWheelEvent e(event, this);
bool consumed = false;
View* v = GetFocusManager()->GetFocusedView();
@@ -367,10 +328,6 @@ bool RootView::OnMouseWheel(const MouseWheelEvent& event) {
ui::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) {
TouchEvent e(event, this);
- if (capture_view_) {
- TouchEvent ce(e, this, capture_view_);
- return capture_view_->OnTouchEvent(ce);
- }
// If touch_pressed_handler_ is non null, we are currently processing
// a touch down on the screen situation. In that case we send the
@@ -456,8 +413,6 @@ void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
mouse_move_handler_ = NULL;
if (touch_pressed_handler_ == child)
touch_pressed_handler_ = NULL;
- if (capture_view_ == child)
- capture_view_ = NULL;
}
}
@@ -506,4 +461,3 @@ void RootView::SetMouseLocationAndFlags(const MouseEvent& event) {
} // namespace internal
} // namespace views
-
diff --git a/views/widget/root_view.h b/views/widget/root_view.h
index a02b5d3..c71b2a0 100644
--- a/views/widget/root_view.h
+++ b/views/widget/root_view.h
@@ -64,11 +64,6 @@ class VIEWS_EXPORT RootView : public View, public FocusTraversable {
// Input ---------------------------------------------------------------------
- // If a capture view has been set all mouse events are forwarded to the
- // capture view, regardless of whether the mouse is over the view.
- void set_capture_view(View* v) { capture_view_ = v; }
- const View* capture_view() const { return capture_view_; }
-
// Process a key event. Send the event to the focused view and up the focus
// path, and finally to the default keyboard handler, until someone consumes
// it. Returns whether anyone consumed the event.
@@ -161,9 +156,6 @@ class VIEWS_EXPORT RootView : public View, public FocusTraversable {
// Input ---------------------------------------------------------------------
- // View capturing mouse input.
- View* capture_view_;
-
// The view currently handing down - drag - up
View* mouse_pressed_handler_;
diff --git a/views/widget/widget.cc b/views/widget/widget.cc
index 133947a..691ab97 100644
--- a/views/widget/widget.cc
+++ b/views/widget/widget.cc
@@ -766,6 +766,11 @@ bool Widget::SetInitialFocus() {
return !!v;
}
+bool Widget::ConvertPointFromAncestor(
+ const Widget* ancestor, gfx::Point* point) const {
+ return native_widget_->ConvertPointFromAncestor(ancestor, point);
+}
+
View* Widget::GetChildViewParent() {
return GetContentsView() ? GetContentsView() : GetRootView();
}
@@ -951,7 +956,6 @@ bool Widget::OnMouseEvent(const MouseEvent& event) {
void Widget::OnMouseCaptureLost() {
if (is_mouse_button_pressed_)
GetRootView()->OnMouseCaptureLost();
- static_cast<internal::RootView*>(GetRootView())->set_capture_view(NULL);
is_mouse_button_pressed_ = false;
}
diff --git a/views/widget/widget.h b/views/widget/widget.h
index 24278a4..4827eae 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -252,8 +252,8 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
void NotifyNativeViewHierarchyChanged(bool attached,
gfx::NativeView native_view);
- // Returns the topmost Widget in a hierarchy. Will return NULL if called
- // before the underlying Native Widget has been initialized.
+ // Returns the top level Widget in a hierarchy. Will return NULL the widget
+ // is not yet attached to top leve widget's hierarchy.
Widget* GetTopLevelWidget();
const Widget* GetTopLevelWidget() const;
@@ -540,6 +540,13 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
focus_on_creation_ = focus_on_creation;
}
+ // Converts the |point| in ancestor's coordinate to this widget's coordinates.
+ // Returns false if |ancestor| is not an ancestor of this widget.
+ // The receiver has to be pure views widget (NativeWidgetViews) and
+ // ancestor can be of any type.
+ bool ConvertPointFromAncestor(
+ const Widget* ancestor, gfx::Point* point) const;
+
// Returns a View* that any child Widgets backed by NativeWidgetViews
// are added to. The default implementation returns the contents view
// if it exists and the root view otherwise.
diff --git a/views/widget/window_manager.cc b/views/widget/window_manager.cc
new file mode 100644
index 0000000..b02b32b
--- /dev/null
+++ b/views/widget/window_manager.cc
@@ -0,0 +1,88 @@
+// 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/widget/window_manager.h"
+
+#include "base/compiler_specific.h"
+#include "views/events/event.h"
+#include "views/widget/widget.h"
+
+namespace {
+
+views::WindowManager* window_manager = NULL;
+
+class NullWindowManager : public views::WindowManager {
+ public:
+ NullWindowManager() : mouse_capture_(NULL) {
+ }
+
+ virtual void StartMoveDrag(views::Widget* widget,
+ const gfx::Point& screen_point) OVERRIDE {
+ NOTIMPLEMENTED();
+ }
+
+ virtual void StartResizeDrag(views::Widget* widget,
+ const gfx::Point& screen_point,
+ int hittest_code) OVERRIDE {
+ NOTIMPLEMENTED();
+ }
+
+ virtual bool SetMouseCapture(views::Widget* widget) OVERRIDE {
+ if (mouse_capture_ == widget)
+ return true;
+ if (mouse_capture_)
+ return false;
+ mouse_capture_ = widget;
+ return true;
+ }
+
+ virtual bool ReleaseMouseCapture(views::Widget* widget) OVERRIDE {
+ if (widget && mouse_capture_ != widget)
+ return false;
+ mouse_capture_ = NULL;
+ return true;
+ }
+
+ virtual bool HasMouseCapture(const views::Widget* widget) const OVERRIDE {
+ return mouse_capture_ == widget;
+ }
+
+ virtual bool HandleMouseEvent(views::Widget* widget,
+ const views::MouseEvent& event) OVERRIDE {
+ if (mouse_capture_) {
+ views::MouseEvent translated(event, widget->GetRootView(),
+ mouse_capture_->GetRootView());
+ mouse_capture_->OnMouseEvent(translated);
+ return true;
+ }
+ return false;
+ }
+
+ private:
+ views::Widget* mouse_capture_;
+};
+
+} // namespace
+
+namespace views {
+
+WindowManager::WindowManager() {
+}
+
+WindowManager::~WindowManager() {
+}
+
+// static
+void WindowManager::Install(WindowManager* wm) {
+ window_manager = wm;
+}
+
+// static
+WindowManager* WindowManager::Get() {
+ if (!window_manager)
+ window_manager = new NullWindowManager();
+ return window_manager;
+}
+
+} // namespace views
diff --git a/views/widget/window_manager.h b/views/widget/window_manager.h
new file mode 100644
index 0000000..05c12ad
--- /dev/null
+++ b/views/widget/window_manager.h
@@ -0,0 +1,63 @@
+// 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_WIDGET_WINDOW_MANAGER_H_
+#define VIEWS_WIDGET_WINDOW_MANAGER_H_
+#pragma once
+
+#include "base/basictypes.h"
+
+namespace gfx {
+class Point;
+}
+
+namespace views {
+class MouseEvent;
+class Widget;
+
+// A interface to WindowManager.
+class WindowManager {
+ public:
+ WindowManager();
+ virtual ~WindowManager();
+
+ // Starts moving window given by |widget|. |point| represents the
+ // initial location of the mouse pointer.
+ virtual void StartMoveDrag(Widget* widget, const gfx::Point& point) = 0;
+
+ // Starts resizing window give by |widget|. |point| represents the
+ // initial location of the mouse pointer and |hittest_code| represents
+ // the edge of the window a user selected to resize the window. See
+ // views/window/hit_test.h for the hittest_code definition.
+ virtual void StartResizeDrag(
+ Widget* widget, const gfx::Point& point, int hittest_code) = 0;
+
+ // Sets mouse capture on |widget|. Returns false if other widget
+ // already has mouse capture.
+ virtual bool SetMouseCapture(Widget* widget) = 0;
+
+ // Releases the mouse capture on |widget|. Returns false if |widget|
+ // haven't capture the mouse.
+ virtual bool ReleaseMouseCapture(Widget* widget) = 0;
+
+ // Checks if the |widget| has mouse capture.
+ virtual bool HasMouseCapture(const Widget* widget) const = 0;
+
+ // WindowManager handles mouse event first. It may reisze/move window,
+ // or send the event to widget that has mouse capture.
+ virtual bool HandleMouseEvent(Widget* widget, const MouseEvent& event) = 0;
+
+ // Installs window manager.
+ static void Install(WindowManager* wm);
+
+ // Returns installed WindowManager.
+ static WindowManager* Get();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(WindowManager);
+};
+
+} // namespace views
+
+#endif // VIEWS_WIDGET_WINDOW_MANAGER_H_