Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Unified Diff: ui/gfx/render_text.cc

Issue 11269022: Add Vector2d classes that represent offsets, instead of using Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more vector use fixes Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index a8246c2d6b1f83905b7092cd9266f2547a179964..25c8e7b000cd06bfa37e150d49aa7e81611be9e1 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -406,7 +406,7 @@ void RenderText::SetText(const string16& text) {
void RenderText::SetHorizontalAlignment(HorizontalAlignment alignment) {
if (horizontal_alignment_ != alignment) {
horizontal_alignment_ = alignment;
- display_offset_ = Point();
+ display_offset_ = Vector2d();
cached_bounds_and_offset_valid_ = false;
}
}
@@ -765,7 +765,7 @@ RenderText::RenderText()
cached_bounds_and_offset_valid_(false) {
}
-const Point& RenderText::GetUpdatedDisplayOffset() {
+const Vector2d& RenderText::GetUpdatedDisplayOffset() {
UpdateCachedBoundsAndOffset();
return display_offset_;
}
@@ -839,41 +839,41 @@ void RenderText::ApplyCompositionAndSelectionStyles(
}
}
-Point RenderText::GetTextOrigin() {
- Point origin = display_rect().origin();
- origin = origin.Add(GetUpdatedDisplayOffset());
- origin = origin.Add(GetAlignmentOffset());
- return origin;
+Vector2d RenderText::GetTextOffset() {
+ Vector2d offset = display_rect().OffsetFromOrigin();
+ offset.Add(GetUpdatedDisplayOffset());
+ offset.Add(GetAlignmentOffset());
+ return offset;
}
Point RenderText::ToTextPoint(const Point& point) {
- return point.Subtract(GetTextOrigin());
+ return point.Subtract(GetTextOffset());
}
Point RenderText::ToViewPoint(const Point& point) {
- return point.Add(GetTextOrigin());
+ return point.Add(GetTextOffset());
}
int RenderText::GetContentWidth() {
return GetStringSize().width() + (cursor_enabled_ ? 1 : 0);
}
-Point RenderText::GetAlignmentOffset() {
+Vector2d RenderText::GetAlignmentOffset() {
if (horizontal_alignment() != ALIGN_LEFT) {
Peter Kasting 2012/10/30 01:14:14 Nit: Can eliminate {} by reversing condition and e
danakj 2012/10/30 19:21:21 yay early-outs. excellent.
int x_offset = display_rect().width() - GetContentWidth();
if (horizontal_alignment() == ALIGN_CENTER)
x_offset /= 2;
- return Point(x_offset, 0);
+ return Vector2d(x_offset, 0);
}
- return Point();
+ return Vector2d();
}
Point RenderText::GetOriginForDrawing() {
- Point origin(GetTextOrigin());
+ Vector2d offset(GetTextOffset());
const int height = GetStringSize().height();
Peter Kasting 2012/10/30 01:14:14 Nit: Inline
// Center the text vertically in the display area.
- origin.Offset(0, (display_rect().height() - height) / 2);
- return origin;
+ offset.Grow(0, (display_rect().height() - height) / 2);
Peter Kasting 2012/10/30 01:14:14 Your CL uses Grow() in only three places besides t
danakj 2012/10/30 19:21:21 I'm not sure. In cases like Vector.Add(Vector) it'
Peter Kasting 2012/10/30 20:24:37 No -- I dislike Grow() solely because it doesn't m
danakj 2012/10/30 21:14:52 Ok, since it sounds like feel strongly, I will rem
+ return gfx::PointAtOffsetFromOrigin(offset);
}
void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) {
@@ -1001,7 +1001,7 @@ void RenderText::UpdateCachedBoundsAndOffset() {
delta_offset = negate_rtl * (display_width - (content_width + offset));
}
- display_offset_.Offset(delta_offset, 0);
+ display_offset_.Grow(delta_offset, 0);
Peter Kasting 2012/10/30 01:14:14 Nit: I suggest declaring a temp vector to enforce
cursor_bounds_.Offset(delta_offset, 0);
}

Powered by Google App Engine
This is Rietveld 408576698