diff options
Diffstat (limited to 'views/widget')
-rw-r--r-- | views/widget/native_widget_gtk.cc | 6 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.h | 2 | ||||
-rw-r--r-- | views/widget/native_widget_private.h | 2 | ||||
-rw-r--r-- | views/widget/native_widget_view.cc | 35 | ||||
-rw-r--r-- | views/widget/native_widget_view.h | 2 | ||||
-rw-r--r-- | views/widget/native_widget_views.cc | 43 | ||||
-rw-r--r-- | views/widget/native_widget_views.h | 4 | ||||
-rw-r--r-- | views/widget/native_widget_win.cc | 6 | ||||
-rw-r--r-- | views/widget/native_widget_win.h | 2 | ||||
-rw-r--r-- | views/widget/root_view.cc | 46 | ||||
-rw-r--r-- | views/widget/root_view.h | 8 | ||||
-rw-r--r-- | views/widget/widget.cc | 6 | ||||
-rw-r--r-- | views/widget/widget.h | 11 | ||||
-rw-r--r-- | views/widget/window_manager.cc | 88 | ||||
-rw-r--r-- | views/widget/window_manager.h | 63 |
15 files changed, 249 insertions, 75 deletions
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_ |