diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-29 15:06:04 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-29 15:06:04 +0000 |
commit | a1f4eb5b056e68cbd81829e8b1d459c68649814f (patch) | |
tree | e065d24054d09e8861372977f1ad9b8f3b3d2da6 | |
parent | 3973da97f5942403c845e2427f365bb0f99ee23d (diff) | |
download | chromium_src-a1f4eb5b056e68cbd81829e8b1d459c68649814f.zip chromium_src-a1f4eb5b056e68cbd81829e8b1d459c68649814f.tar.gz chromium_src-a1f4eb5b056e68cbd81829e8b1d459c68649814f.tar.bz2 |
Convert the rect to the widget's coordinates correctly.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7276053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90952 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view_layout.cc | 7 | ||||
-rw-r--r-- | views/controls/native/native_view_host.cc | 7 | ||||
-rw-r--r-- | views/ime/input_method_base.cc | 9 | ||||
-rw-r--r-- | views/view.cc | 18 | ||||
-rw-r--r-- | views/view.h | 4 | ||||
-rw-r--r-- | views/view_unittest.cc | 48 |
7 files changed, 69 insertions, 30 deletions
diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc index 13a73fb..b364a5f 100644 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc @@ -615,11 +615,7 @@ void AutocompletePopupContentsView::UpdateBlurRegion() { // Translate the contents rect into widget coordinates, since that's what // DwmEnableBlurBehindWindow expects a region in. - gfx::Rect contents_rect = GetContentsBounds(); - gfx::Point origin(contents_rect.origin()); - views::View::ConvertPointToWidget(this, &origin); - contents_rect.set_origin(origin); - + gfx::Rect contents_rect = ConvertRectToWidget(GetContentsBounds()); gfx::Path contents_path; MakeContentsPath(&contents_path, contents_rect); base::win::ScopedGDIObject<HRGN> popup_region; diff --git a/chrome/browser/ui/views/frame/browser_view_layout.cc b/chrome/browser/ui/views/frame/browser_view_layout.cc index fb2634e..9e66933 100644 --- a/chrome/browser/ui/views/frame/browser_view_layout.cc +++ b/chrome/browser/ui/views/frame/browser_view_layout.cc @@ -123,11 +123,8 @@ gfx::Rect BrowserViewLayout::GetFindBarBoundingBox() const { // First determine the bounding box of the content area in Widget // coordinates. - gfx::Rect bounding_box(contents_container_->bounds()); - - gfx::Point topleft; - views::View::ConvertPointToWidget(contents_container_, &topleft); - bounding_box.set_origin(topleft); + gfx::Rect bounding_box = contents_container_->ConvertRectToWidget( + contents_container_->GetLocalBounds()); // Adjust the position and size of the bounding box by the find bar offset // calculated during the last Layout. diff --git a/views/controls/native/native_view_host.cc b/views/controls/native/native_view_host.cc index 1a304a6..c9fd990 100644 --- a/views/controls/native/native_view_host.cc +++ b/views/controls/native/native_view_host.cc @@ -113,11 +113,8 @@ void NativeViewHost::Layout() { // positioned in the coordinate system of the Widget, not the current // view. Also, they should be positioned respecting the border insets // of the native view. - gfx::Insets insets = GetInsets(); - gfx::Point top_left(insets.left(), insets.top()); - ConvertPointToWidget(this, &top_left); - gfx::Rect local_bounds = GetContentsBounds(); - native_wrapper_->ShowWidget(top_left.x(), top_left.y(), + gfx::Rect local_bounds = ConvertRectToWidget(GetContentsBounds()); + native_wrapper_->ShowWidget(local_bounds.x(), local_bounds.y(), local_bounds.width(), local_bounds.height()); } else { diff --git a/views/ime/input_method_base.cc b/views/ime/input_method_base.cc index 857cfee..5716f46 100644 --- a/views/ime/input_method_base.cc +++ b/views/ime/input_method_base.cc @@ -95,14 +95,7 @@ bool InputMethodBase::GetCaretBoundsInWidget(gfx::Rect* rect) const { if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) return false; - *rect = client->GetCaretBounds(); - gfx::Point origin = rect->origin(); - gfx::Point end = gfx::Point(rect->right(), rect->bottom()); - - View::ConvertPointToWidget(focused_view_, &origin); - View::ConvertPointToWidget(focused_view_, &end); - rect->SetRect(origin.x(), origin.y(), - end.x() - origin.x(), end.y() - origin.y()); + *rect = focused_view_->ConvertRectToWidget(client->GetCaretBounds()); // We need to do coordinate conversion if the focused view is inside a child // Widget. diff --git a/views/view.cc b/views/view.cc index db5f589..27acc0a4 100644 --- a/views/view.cc +++ b/views/view.cc @@ -333,7 +333,6 @@ gfx::Rect View::GetVisibleBounds() const { static_cast<float>(view->y())); vis_bounds = view->ConvertRectToParent(vis_bounds); - vis_bounds.Offset(view->GetMirroredPosition()); const View* ancestor = view->parent_; if (ancestor != NULL) { ancestor_bounds.SetRect(0, 0, ancestor->width(), ancestor->height()); @@ -672,10 +671,17 @@ void View::ConvertPointToScreen(const View* src, gfx::Point* p) { } gfx::Rect View::ConvertRectToParent(const gfx::Rect& rect) const { - if (!transform()) - return rect; gfx::Rect x_rect = rect; - transform()->TransformRect(&x_rect); + if (transform()) + transform()->TransformRect(&x_rect); + x_rect.Offset(GetMirroredPosition()); + return x_rect; +} + +gfx::Rect View::ConvertRectToWidget(const gfx::Rect& rect) const { + gfx::Rect x_rect = rect; + for (const View* v = this; v; v = v->parent_) + x_rect = v->ConvertRectToParent(x_rect); return x_rect; } @@ -1185,9 +1191,7 @@ void View::SchedulePaintInternal(const gfx::Rect& rect) { if (parent_) { // Translate the requested paint rect to the parent's coordinate system // then pass this notification up to the parent. - gfx::Rect paint_rect = ConvertRectToParent(rect); - paint_rect.Offset(GetMirroredPosition()); - parent_->SchedulePaintInternal(paint_rect); + parent_->SchedulePaintInternal(ConvertRectToParent(rect)); } } diff --git a/views/view.h b/views/view.h index a76b125..629e400 100644 --- a/views/view.h +++ b/views/view.h @@ -429,6 +429,10 @@ class View : public AcceleratorTarget { // system, to convert it into the parent's coordinate system. gfx::Rect ConvertRectToParent(const gfx::Rect& rect) const; + // Converts a rectangle from this views coordinate system to its widget + // cooridnate system. + gfx::Rect ConvertRectToWidget(const gfx::Rect& rect) const; + // Painting ------------------------------------------------------------------ // Mark all or part of the View's bounds as dirty (needing repaint). diff --git a/views/view_unittest.cc b/views/view_unittest.cc index 8afc10a..73e7a75 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -1902,6 +1902,54 @@ TEST_F(ViewTest, ConvertPointToViewWithTransform) { } } +// Tests conversion methods for rectangles. +TEST_F(ViewTest, ConvertRectWithTransform) { + scoped_ptr<Widget> widget(new Widget); + Widget::InitParams params(Widget::InitParams::TYPE_POPUP); + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + params.bounds = gfx::Rect(50, 50, 650, 650); + widget->Init(params); + View* root = widget->GetRootView(); + + TestView* v1 = new TestView; + TestView* v2 = new TestView; + root->AddChildView(v1); + v1->AddChildView(v2); + + v1->SetBounds(10, 10, 500, 500); + v2->SetBounds(20, 20, 100, 200); + + // |v2| now occupies (30, 30) to (130, 230) in |widget| + gfx::Rect rect(5, 5, 15, 40); + EXPECT_EQ(gfx::Rect(25, 25, 15, 40), v2->ConvertRectToParent(rect)); + EXPECT_EQ(gfx::Rect(35, 35, 15, 40), v2->ConvertRectToWidget(rect)); + + // Rotate |v2| + ui::Transform t2; + t2.SetRotate(-90.0f); + t2.SetTranslateY(100.0f); + v2->SetTransform(t2); + + // |v2| now occupies (30, 30) to (230, 130) in |widget| + EXPECT_EQ(gfx::Rect(25, 100, 40, 15), v2->ConvertRectToParent(rect)); + EXPECT_EQ(gfx::Rect(35, 110, 40, 15), v2->ConvertRectToWidget(rect)); + + // Scale down |v1| + ui::Transform t1; + t1.SetScale(0.5, 0.5); + v1->SetTransform(t1); + + // The rectangle should remain the same for |v1|. + EXPECT_EQ(gfx::Rect(25, 100, 40, 15), v2->ConvertRectToParent(rect)); + + // |v2| now occupies (20, 20) to (120, 70) in |widget| + // There are some rounding of floating values here. These values may change if + // floating operations are improved/changed. + EXPECT_EQ(gfx::Rect(22, 60, 20, 7), v2->ConvertRectToWidget(rect)); + + widget->CloseNow(); +} + class ObserverView : public View { public: ObserverView(); |