diff options
author | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-12 22:48:37 +0000 |
---|---|---|
committer | oshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-12 22:48:37 +0000 |
commit | a2d2ebb2bebebb570439c39e8eb5f6940dd2f788 (patch) | |
tree | 1ba145974abb0bb91cf4a9b63a79ca15909a9277 /views | |
parent | afb56b486dd195e57a9b412fcb0b77cc7ac711e7 (diff) | |
download | chromium_src-a2d2ebb2bebebb570439c39e8eb5f6940dd2f788.zip chromium_src-a2d2ebb2bebebb570439c39e8eb5f6940dd2f788.tar.gz chromium_src-a2d2ebb2bebebb570439c39e8eb5f6940dd2f788.tar.bz2 |
Use TabContentsViewViews for RenderWidgetHostViweViews.
* Removed TabContentsViewTouch.
* Changed so that mouse and resize event goes through NativeWidgetViews so that NativeTabContentsViewViews can invoke NativeTabContentsViewDelegates.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7460001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100792 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/button/menu_button.cc | 4 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.cc | 28 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.h | 1 | ||||
-rw-r--r-- | views/widget/native_widget_private.h | 1 | ||||
-rw-r--r-- | views/widget/native_widget_view.cc | 51 | ||||
-rw-r--r-- | views/widget/native_widget_views.cc | 79 | ||||
-rw-r--r-- | views/widget/native_widget_views.h | 12 | ||||
-rw-r--r-- | views/widget/native_widget_win.cc | 4 | ||||
-rw-r--r-- | views/widget/native_widget_win.h | 1 | ||||
-rw-r--r-- | views/widget/widget.cc | 6 | ||||
-rw-r--r-- | views/widget/widget.h | 3 |
11 files changed, 118 insertions, 72 deletions
diff --git a/views/controls/button/menu_button.cc b/views/controls/button/menu_button.cc index 64f4795..e9d8f61 100644 --- a/views/controls/button/menu_button.cc +++ b/views/controls/button/menu_button.cc @@ -258,9 +258,7 @@ int MenuButton::GetMaximumScreenXCoordinate() { return 0; } - gfx::Rect monitor_bounds = - gfx::Screen::GetMonitorWorkAreaNearestWindow( - GetWidget()->GetTopLevelWidget()->GetNativeView()); + gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); return monitor_bounds.right() - 1; } diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc index 7cb5892..d1eeb23 100644 --- a/views/widget/native_widget_gtk.cc +++ b/views/widget/native_widget_gtk.cc @@ -1333,6 +1333,10 @@ bool NativeWidgetGtk::ConvertPointFromAncestor( return false; } +gfx::Rect NativeWidgetGtk::GetWorkAreaBoundsInScreen() const { + return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); +} + //////////////////////////////////////////////////////////////////////////////// // NativeWidgetGtk, protected: @@ -2134,22 +2138,20 @@ bool Widget::ConvertRect(const Widget* source, DCHECK(target); DCHECK(rect); - GtkWidget* source_widget = source->GetNativeView(); - GtkWidget* target_widget = target->GetNativeView(); - if (source_widget == target_widget) - return true; + // TODO(oshima): Add check if source and target belongs to the same + // screen. - if (!source_widget || !target_widget) + if (source == target) + return true; + if (!source || !target) return false; - GdkRectangle gdk_rect = rect->ToGdkRectangle(); - if (gtk_widget_translate_coordinates(source_widget, target_widget, - gdk_rect.x, gdk_rect.y, - &gdk_rect.x, &gdk_rect.y)) { - *rect = gdk_rect; - return true; - } - return false; + gfx::Point source_point = source->GetWindowScreenBounds().origin(); + gfx::Point target_point = target->GetWindowScreenBounds().origin(); + + rect->set_origin( + source_point.Subtract(target_point).Add(rect->origin())); + return true; } namespace internal { diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h index eb5ec4a..fed434f 100644 --- a/views/widget/native_widget_gtk.h +++ b/views/widget/native_widget_gtk.h @@ -220,6 +220,7 @@ class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate, virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE; virtual bool ConvertPointFromAncestor( const Widget* ancestor, gfx::Point* point) const OVERRIDE; + virtual gfx::Rect GetWorkAreaBoundsInScreen() 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 dbeab12..f47c5ac 100644 --- a/views/widget/native_widget_private.h +++ b/views/widget/native_widget_private.h @@ -204,6 +204,7 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget, virtual void FocusNativeView(gfx::NativeView native_view) = 0; virtual bool ConvertPointFromAncestor( const Widget* ancestor, gfx::Point* point) const = 0; + virtual gfx::Rect GetWorkAreaBoundsInScreen() 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 0b60850..500c614 100644 --- a/views/widget/native_widget_view.cc +++ b/views/widget/native_widget_view.cc @@ -5,10 +5,6 @@ #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 { @@ -67,7 +63,7 @@ void NativeWidgetView::ViewHierarchyChanged(bool is_add, } void NativeWidgetView::OnBoundsChanged(const gfx::Rect& previous_bounds) { - delegate()->OnNativeWidgetSizeChanged(size()); + native_widget_->OnBoundsChanged(bounds(), previous_bounds); } void NativeWidgetView::OnPaint(gfx::Canvas* canvas) { @@ -79,46 +75,15 @@ gfx::NativeCursor NativeWidgetView::GetCursor(const MouseEvent& event) { } bool NativeWidgetView::OnMousePressed(const MouseEvent& event) { - 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); + return native_widget_->OnMouseEvent(event); } bool NativeWidgetView::OnMouseDragged(const MouseEvent& event) { - return delegate()->OnMouseEvent(event); + return native_widget_->OnMouseEvent(event); } void NativeWidgetView::OnMouseReleased(const MouseEvent& event) { - delegate()->OnMouseEvent(event); + native_widget_->OnMouseEvent(event); } void NativeWidgetView::OnMouseCaptureLost() { @@ -126,15 +91,15 @@ void NativeWidgetView::OnMouseCaptureLost() { } void NativeWidgetView::OnMouseMoved(const MouseEvent& event) { - delegate()->OnMouseEvent(event); + native_widget_->OnMouseEvent(event); } void NativeWidgetView::OnMouseEntered(const MouseEvent& event) { - delegate()->OnMouseEvent(event); + native_widget_->OnMouseEvent(event); } void NativeWidgetView::OnMouseExited(const MouseEvent& event) { - delegate()->OnMouseEvent(event); + native_widget_->OnMouseEvent(event); } ui::TouchStatus NativeWidgetView::OnTouchEvent(const TouchEvent& event) { @@ -150,7 +115,7 @@ bool NativeWidgetView::OnKeyReleased(const KeyEvent& event) { } bool NativeWidgetView::OnMouseWheel(const MouseWheelEvent& event) { - return delegate()->OnMouseEvent(event); + return native_widget_->OnMouseEvent(event); } void NativeWidgetView::VisibilityChanged(View* starting_from, diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc index 44f2d9d..68b9c0e 100644 --- a/views/widget/native_widget_views.cc +++ b/views/widget/native_widget_views.cc @@ -18,6 +18,10 @@ #include "views/ime/mock_input_method.h" #endif +#if defined(OS_LINUX) +#include "views/window/hit_test.h" +#endif + namespace views { //////////////////////////////////////////////////////////////////////////////// @@ -30,7 +34,6 @@ NativeWidgetViews::NativeWidgetViews(internal::NativeWidgetDelegate* delegate) minimized_(false), always_on_top_(false), ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), - hosting_widget_(NULL), ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), delete_native_view_(true) { } @@ -95,6 +98,18 @@ void NativeWidgetViews::DispatchKeyEventPostIME(const KeyEvent& key) { } //////////////////////////////////////////////////////////////////////////////// +// NativeWidgetViews, protected: + +void NativeWidgetViews::OnBoundsChanged(const gfx::Rect& new_bounds, + const gfx::Rect& old_bounds) { + delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); +} + +bool NativeWidgetViews::OnMouseEvent(const MouseEvent& event) { + return HandleWindowOperation(event) ? true : delegate_->OnMouseEvent(event); +} + +//////////////////////////////////////////////////////////////////////////////// // NativeWidgetViews, NativeWidget implementation: void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) { @@ -102,11 +117,12 @@ void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) { always_on_top_ = params.keep_on_top; View* parent_view = NULL; if (params.parent_widget) { - hosting_widget_ = params.parent_widget; - parent_view = hosting_widget_->GetChildViewParent(); - } else { + parent_view = params.parent_widget->GetChildViewParent(); + } else if (ViewsDelegate::views_delegate->GetDefaultParentView()) { parent_view = ViewsDelegate::views_delegate->GetDefaultParentView(); - hosting_widget_ = parent_view->GetWidget(); + } else if (params.parent) { + Widget* widget = Widget::GetWidgetForNativeView(params.parent); + parent_view = widget->GetChildViewParent(); } view_ = new internal::NativeWidgetView(this); @@ -124,7 +140,8 @@ void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) { if (ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET) view_->set_delete_native_widget(false); - parent_view->AddChildView(view_); + if (parent_view) + parent_view->AddChildView(view_); // TODO(beng): SetInitParams(). } @@ -176,11 +193,11 @@ Widget* NativeWidgetViews::GetTopLevelWidget() { } const ui::Compositor* NativeWidgetViews::GetCompositor() const { - return hosting_widget_->GetCompositor(); + return view_->GetWidget() ? view_->GetWidget()->GetCompositor() : NULL; } ui::Compositor* NativeWidgetViews::GetCompositor() { - return hosting_widget_->GetCompositor(); + return view_->GetWidget() ? view_->GetWidget()->GetCompositor() : NULL; } void NativeWidgetViews::MarkLayerDirty() { @@ -470,7 +487,7 @@ void NativeWidgetViews::RunShellDrag(View* view, } void NativeWidgetViews::SchedulePaintInRect(const gfx::Rect& rect) { - view_->SchedulePaintInternal(rect); + view_->SchedulePaintInRect(rect); } void NativeWidgetViews::SetCursor(gfx::NativeCursor cursor) { @@ -507,6 +524,13 @@ bool NativeWidgetViews::ConvertPointFromAncestor( return false; } +gfx::Rect NativeWidgetViews::GetWorkAreaBoundsInScreen() const { + // TODO(oshima): This should return the views desktop window's + // working area when the system is running under views desktop + // rather than native window's working area. + return GetParentNativeWidget()->GetWorkAreaBoundsInScreen(); +} + //////////////////////////////////////////////////////////////////////////////// // NativeWidgetViews, private: @@ -525,4 +549,41 @@ const internal::NativeWidgetPrivate* NULL; } +bool NativeWidgetViews::HandleWindowOperation(const MouseEvent& event) { + if (event.type() != ui::ET_MOUSE_PRESSED) + return false; + + Widget* widget = GetWidget(); + if (widget->non_client_view()) { + int hittest_code = widget->non_client_view()->NonClientHitTest( + event.location()); + switch (hittest_code) { + case HTCAPTION: { + if (!event.IsOnlyRightMouseButton()) { + WindowManager::Get()->StartMoveDrag(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( + widget, event.location(), hittest_code); + return true; + } + default: + // Everything else falls into standard client event handling. + break; + } + } + return false; +} + } // namespace views diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h index eaa2804..b0c2ea3 100644 --- a/views/widget/native_widget_views.h +++ b/views/widget/native_widget_views.h @@ -47,7 +47,12 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate { internal::NativeWidgetDelegate* delegate() const { return delegate_; } protected: - friend class NativeWidgetView; + friend class internal::NativeWidgetView; + + // Event handlers that subclass can implmenet custom behavior. + virtual void OnBoundsChanged(const gfx::Rect& new_bounds, + const gfx::Rect& old_bounds); + virtual bool OnMouseEvent(const MouseEvent& event); // Overridden from internal::NativeWidgetPrivate: virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE; @@ -130,6 +135,7 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate { virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE; virtual bool ConvertPointFromAncestor( const Widget* ancestor, gfx::Point* point) const OVERRIDE; + virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE; // Overridden from internal::InputMethodDelegate virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE; @@ -141,6 +147,8 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate { internal::NativeWidgetPrivate* GetParentNativeWidget(); const internal::NativeWidgetPrivate* GetParentNativeWidget() const; + bool HandleWindowOperation(const MouseEvent& event); + internal::NativeWidgetDelegate* delegate_; internal::NativeWidgetView* view_; @@ -159,8 +167,6 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate { gfx::Rect restored_bounds_; ui::Transform restored_transform_; - Widget* hosting_widget_; - // See class documentation for Widget in widget.h for a note about ownership. Widget::InitParams::Ownership ownership_; diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc index 23ef015..b75a4a9 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -1092,6 +1092,10 @@ bool NativeWidgetWin::ConvertPointFromAncestor( return false; } +gfx::Rect NativeWidgetWin::GetWorkAreaBoundsInScreen() const { + return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); +} + //////////////////////////////////////////////////////////////////////////////// // NativeWidgetWin, MessageLoop::Observer implementation: diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h index 967ed85..43b4a76 100644 --- a/views/widget/native_widget_win.h +++ b/views/widget/native_widget_win.h @@ -266,6 +266,7 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE; virtual bool ConvertPointFromAncestor( const Widget* ancestor, gfx::Point* point) const OVERRIDE; + virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE; protected: // Information saved before going into fullscreen mode, used to restore the diff --git a/views/widget/widget.cc b/views/widget/widget.cc index 8ed6c8d..39e7e8b 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -604,7 +604,7 @@ ThemeProvider* Widget::GetThemeProvider() const { } FocusManager* Widget::GetFocusManager() { - Widget* toplevel_widget = GetTopLevelWidget(); + const Widget* toplevel_widget = GetTopLevelWidget(); return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL; } @@ -803,6 +803,10 @@ View* Widget::GetChildViewParent() { return GetContentsView() ? GetContentsView() : GetRootView(); } +gfx::Rect Widget::GetWorkAreaBoundsInScreen() const { + return native_widget_->GetWorkAreaBoundsInScreen(); +} + //////////////////////////////////////////////////////////////////////////////// // Widget, NativeWidgetDelegate implementation: diff --git a/views/widget/widget.h b/views/widget/widget.h index dd23dd6..b5ba346 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -565,6 +565,9 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, // TYPE_CONTROL and TYPE_TOOLTIP is not considered top level. bool is_top_level() const { return is_top_level_; } + // Returns the bounds of work area in the screen that Widget belongs to. + gfx::Rect GetWorkAreaBoundsInScreen() const; + // Overridden from NativeWidgetDelegate: virtual bool IsModal() const OVERRIDE; virtual bool IsDialogBox() const OVERRIDE; |