diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-13 13:58:01 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-13 13:58:01 +0000 |
commit | ed5e6138e9a6485b5a74431c148661aa541cd501 (patch) | |
tree | 50f264489983de614ad6f0da87338d804430893e | |
parent | f1c76b9f91496b804665eb88635307402a3381a5 (diff) | |
download | chromium_src-ed5e6138e9a6485b5a74431c148661aa541cd501.zip chromium_src-ed5e6138e9a6485b5a74431c148661aa541cd501.tar.gz chromium_src-ed5e6138e9a6485b5a74431c148661aa541cd501.tar.bz2 |
touchui: Fix child toplevel widget positioning in touchui.
The child widget gets added to the parent widget's view tree. So its origin needs
to be correctly adjusted to be in the parent widget's coordinate system.
BUG=99956
TEST=none
Review URL: http://codereview.chromium.org/8231037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105299 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | views/widget/native_widget_views.cc | 27 | ||||
-rw-r--r-- | views/widget/native_widget_views.h | 3 |
2 files changed, 26 insertions, 4 deletions
diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc index d1b372a..4ed77ca 100644 --- a/views/widget/native_widget_views.cc +++ b/views/widget/native_widget_views.cc @@ -22,6 +22,21 @@ #include "views/window/hit_test.h" #endif +namespace { + +gfx::Rect AdjustRectOriginForParentWidget(const gfx::Rect& rect, + const views::Widget* parent) { + if (!parent) + return rect; + + gfx::Rect adjusted = rect; + gfx::Rect parent_bounds = parent->GetWindowScreenBounds(); + adjusted.Offset(-parent_bounds.x(), -parent_bounds.y()); + return adjusted; +} + +} // namespace + namespace views { //////////////////////////////////////////////////////////////////////////////// @@ -29,6 +44,7 @@ namespace views { NativeWidgetViews::NativeWidgetViews(internal::NativeWidgetDelegate* delegate) : delegate_(delegate), + parent_(NULL), view_(NULL), active_(false), window_state_(ui::SHOW_STATE_DEFAULT), @@ -116,6 +132,7 @@ bool NativeWidgetViews::OnMouseEvent(const MouseEvent& event) { // NativeWidgetViews, NativeWidget implementation: void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) { + parent_ = params.parent_widget; ownership_ = params.ownership; always_on_top_ = params.keep_on_top; View* parent_view = NULL; @@ -130,8 +147,10 @@ void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) { parent_view = widget->GetChildViewParent(); } + gfx::Rect bounds = AdjustRectOriginForParentWidget(params.bounds, + parent_); view_ = new internal::NativeWidgetView(this); - view_->SetBoundsRect(params.bounds); + view_->SetBoundsRect(bounds); view_->SetVisible(params.type == Widget::InitParams::TYPE_CONTROL); // With the default NATIVE_WIDGET_OWNS_WIDGET ownership, the @@ -147,7 +166,6 @@ void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) { view_->SetPaintToLayer(true); if (View::get_use_acceleration_when_possible()) view_->SetFillsBoundsOpaquely(!params.transparent); - view_->SetBoundsRect(params.bounds); // TODO(beng): SetInitParams(). } @@ -310,7 +328,8 @@ void NativeWidgetViews::BecomeModal() { } gfx::Rect NativeWidgetViews::GetWindowScreenBounds() const { - if (GetWidget() == GetWidget()->GetTopLevelWidget()) + if (GetWidget() == GetWidget()->GetTopLevelWidget() && + !parent_) return view_->bounds(); gfx::Point origin = view_->bounds().origin(); View::ConvertPointToScreen(view_->parent(), &origin); @@ -327,7 +346,7 @@ gfx::Rect NativeWidgetViews::GetRestoredBounds() const { void NativeWidgetViews::SetBounds(const gfx::Rect& bounds) { // |bounds| are supplied in the coordinates of the parent. - view_->SetBoundsRect(bounds); + view_->SetBoundsRect(AdjustRectOriginForParentWidget(bounds, parent_)); } void NativeWidgetViews::SetSize(const gfx::Size& size) { diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h index cc853c3..9e4550c 100644 --- a/views/widget/native_widget_views.h +++ b/views/widget/native_widget_views.h @@ -156,6 +156,9 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate { internal::NativeWidgetDelegate* delegate_; + // Parent Widget (can be NULL). + Widget* parent_; + internal::NativeWidgetView* view_; bool active_; |