0

ui: Add methods to Rect classes to get points at each of the rect's corners.

This adds the following methods:
RectBase::TopRight()
RectBase::BottomLeft()
RectBase::BottomRight()

RectBase::origin() still provides the rect's top-left corner.

Tests:
ui_unittests:RectTest.Cornders

BUG=147395
R=sky


Review URL: https://chromiumcodereview.appspot.com/11358240

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168859 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
danakj@chromium.org
2012-11-20 20:28:07 +00:00
parent 948adfcfca
commit 0eef4b889f
10 changed files with 27 additions and 40 deletions

@ -51,7 +51,6 @@
'frame_rate_controller.h',
'frame_rate_counter.cc',
'frame_rate_counter.h',
'geometry.h',
'geometry_binding.cc',
'geometry_binding.h',
'gl_renderer.cc',

@ -1,25 +0,0 @@
// Copyright 2010 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 CC_GEOMETRY_H_
#define CC_GEOMETRY_H_
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_f.h"
#include "ui/gfx/vector2d.h"
#include "ui/gfx/vector2d_f.h"
namespace cc {
inline gfx::Point BottomRight(gfx::Rect rect) {
return gfx::Point(rect.right(), rect.bottom());
}
inline gfx::PointF BottomRight(gfx::RectF rect) {
return gfx::PointF(rect.right(), rect.bottom());
}
} // namespace cc
#endif // CC_GEOMETRY_H_

@ -10,7 +10,6 @@
#include "base/string_util.h"
#include "build/build_config.h"
#include "cc/damage_tracker.h"
#include "cc/geometry.h"
#include "cc/geometry_binding.h"
#include "cc/layer_quad.h"
#include "cc/math_util.h"
@ -707,7 +706,7 @@ void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua
// texCoordRect to match.
gfx::Vector2d topLeftDiff = tileRect.origin() - quad->rect.origin();
gfx::Vector2d bottomRightDiff =
BottomRight(tileRect) - BottomRight(quad->rect);
tileRect.bottom_right() - quad->rect.bottom_right();
texCoordRect.Inset(topLeftDiff.x() / texToGeomScaleX,
topLeftDiff.y() / texToGeomScaleY,
-bottomRightDiff.x() / texToGeomScaleX,
@ -797,10 +796,10 @@ void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua
GLC(context(), context()->uniform4f(uniforms.vertexTexTransformLocation, vertexTexTranslateX, vertexTexTranslateY, vertexTexScaleX, vertexTexScaleY));
GLC(context(), context()->uniform4f(uniforms.fragmentTexTransformLocation, fragmentTexTranslateX, fragmentTexTranslateY, fragmentTexScaleX, fragmentTexScaleY));
gfx::PointF bottomRight(tileRect.right(), tileRect.bottom());
gfx::PointF bottomLeft(tileRect.x(), tileRect.bottom());
gfx::PointF topLeft(tileRect.x(), tileRect.y());
gfx::PointF topRight(tileRect.right(), tileRect.y());
gfx::PointF bottomRight = tileRect.bottom_right();
gfx::PointF bottomLeft = tileRect.bottom_left();
gfx::PointF topLeft = tileRect.origin();
gfx::PointF topRight = tileRect.top_right();
// Map points to device space.
bottomRight = MathUtil::mapPoint(deviceTransform, bottomRight, clipped);

@ -8,7 +8,6 @@
#include "base/stringprintf.h"
#include "cc/debug_border_draw_quad.h"
#include "cc/debug_colors.h"
#include "cc/geometry.h"
#include "cc/layer_sorter.h"
#include "cc/layer_tree_host_impl.h"
#include "cc/math_util.h"

@ -14,7 +14,6 @@
#include "cc/delay_based_time_source.h"
#include "cc/font_atlas.h"
#include "cc/frame_rate_counter.h"
#include "cc/geometry.h"
#include "cc/gl_renderer.h"
#include "cc/heads_up_display_layer_impl.h"
#include "cc/layer_iterator.h"
@ -1016,7 +1015,7 @@ void LayerTreeHostImpl::updateMaxScrollOffset()
viewBounds.Scale(1 / m_pinchZoomViewport.pageScaleDelta());
}
gfx::Vector2dF maxScroll = BottomRight(gfx::Rect(contentBounds)) - BottomRight(gfx::RectF(viewBounds));
gfx::Vector2dF maxScroll = gfx::Rect(contentBounds).bottom_right() - gfx::RectF(viewBounds).bottom_right();
maxScroll.Scale(1 / m_deviceScaleFactor);
// The viewport may be larger than the contents in some cases, such as
@ -1309,7 +1308,7 @@ void LayerTreeHostImpl::computePinchZoomDeltas(ScrollAndScaleSet* scrollInfo)
gfx::Vector2dF scrollEnd = scrollBegin + anchorOffset;
scrollEnd.Scale(m_pinchZoomViewport.minPageScaleFactor() / scaleBegin);
scrollEnd -= anchorOffset;
scrollEnd.ClampToMax(BottomRight(gfx::RectF(scaledContentsSize)) - BottomRight(gfx::Rect(m_deviceViewportSize)));
scrollEnd.ClampToMax(gfx::RectF(scaledContentsSize).bottom_right() - gfx::Rect(m_deviceViewportSize).bottom_right());
scrollEnd.ClampToMin(gfx::Vector2d());
scrollEnd.Scale(1 / pageScaleDeltaToSend);
scrollEnd.Scale(m_deviceScaleFactor);

@ -10,7 +10,6 @@
#include "base/command_line.h"
#include "base/hash_tables.h"
#include "cc/delegated_renderer_layer_impl.h"
#include "cc/geometry.h"
#include "cc/gl_renderer.h"
#include "cc/heads_up_display_layer_impl.h"
#include "cc/io_surface_layer_impl.h"

@ -5,7 +5,6 @@
#include "cc/page_scale_animation.h"
#include "base/logging.h"
#include "cc/geometry.h"
#include "ui/gfx/point_f.h"
#include "ui/gfx/rect_f.h"
#include "ui/gfx/vector2d_conversions.h"
@ -117,7 +116,7 @@ void PageScaleAnimation::inferTargetAnchorFromScrollOffsets()
void PageScaleAnimation::clampTargetScrollOffset()
{
gfx::Vector2dF maxScrollOffset = BottomRight(gfx::RectF(m_rootLayerSize)) - BottomRight(gfx::RectF(targetViewportSize()));
gfx::Vector2dF maxScrollOffset = gfx::RectF(m_rootLayerSize).bottom_right() - gfx::RectF(targetViewportSize()).bottom_right();
m_targetScrollOffset.ClampToMin(gfx::Vector2dF());
m_targetScrollOffset.ClampToMax(maxScrollOffset);
}

@ -6,7 +6,6 @@
#include "base/basictypes.h"
#include "build/build_config.h"
#include "cc/geometry.h"
#include "cc/layer_impl.h"
#include "cc/layer_tree_host.h"
#include "cc/overdraw_metrics.h"

@ -47,6 +47,10 @@ class UI_EXPORT RectBase {
Type right() const { return x() + width(); }
Type bottom() const { return y() + height(); }
PointClass top_right() const { return PointClass(right(), y()); }
PointClass bottom_left() const { return PointClass(x(), bottom()); }
PointClass bottom_right() const { return PointClass(right(), bottom()); }
VectorClass OffsetFromOrigin() const {
return VectorClass(x(), y());
}

@ -743,4 +743,19 @@ TEST(RectTest, Offset) {
EXPECT_EQ(RectF(1.1f, 2.2f, 3.3f, 4.4f).ToString(), f.ToString());
}
TEST(RectTest, Corners) {
Rect i(1, 2, 3, 4);
RectF f(1.1f, 2.1f, 3.1f, 4.1f);
EXPECT_EQ(Point(1, 2).ToString(), i.origin().ToString());
EXPECT_EQ(Point(4, 2).ToString(), i.top_right().ToString());
EXPECT_EQ(Point(1, 6).ToString(), i.bottom_left().ToString());
EXPECT_EQ(Point(4, 6).ToString(), i.bottom_right().ToString());
EXPECT_EQ(PointF(1.1f, 2.1f).ToString(), f.origin().ToString());
EXPECT_EQ(PointF(4.2f, 2.1f).ToString(), f.top_right().ToString());
EXPECT_EQ(PointF(1.1f, 6.2f).ToString(), f.bottom_left().ToString());
EXPECT_EQ(PointF(4.2f, 6.2f).ToString(), f.bottom_right().ToString());
}
} // namespace gfx