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

Unified Diff: ui/gfx/render_text.cc

Issue 378723003: RenderText: Allow setting display offset explicitly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
« no previous file with comments | « ui/gfx/render_text.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 4e7281c11695d4b7b70beb85b36e04227f425936..0d4a67a75cf5785824f10d8118a6f57b93e161d2 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -872,6 +872,28 @@ SelectionModel RenderText::GetSelectionModelForSelectionStart() {
sel.is_reversed() ? CURSOR_BACKWARD : CURSOR_FORWARD);
}
+const Vector2d& RenderText::GetUpdatedDisplayOffset() {
+ UpdateCachedBoundsAndOffset();
+ return display_offset_;
+}
+
+void RenderText::SetDisplayOffset(const Vector2d& offset) {
msw 2014/07/08 17:38:23 nit: perhaps this should only take a horizontal of
mohsen 2014/07/08 18:36:16 Done.
+ int display_width = display_rect_.width();
+ int content_width = GetContentWidth();
+ int negate_rtl = horizontal_alignment_ == ALIGN_RIGHT ? -1 : 1;
+
+ Vector2d final_offset = offset;
+ if (content_width <= display_width)
+ final_offset.set_x(0);
+ else if (negate_rtl * final_offset.x() > 0)
+ final_offset.set_x(0);
msw 2014/07/08 17:38:23 q: does this prevent scrolling before the start of
mohsen 2014/07/08 18:36:16 Yes.
+ else if (negate_rtl * final_offset.x() < display_width - content_width)
+ final_offset.set_x(negate_rtl * (display_width - content_width));
+ cached_bounds_and_offset_valid_ = true;
+ display_offset_ = final_offset;
+ cursor_bounds_ = GetCursorBounds(selection_model_, insert_mode_);
+}
+
RenderText::RenderText()
: horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT),
directionality_mode_(DIRECTIONALITY_FROM_TEXT),
@@ -898,11 +920,6 @@ RenderText::RenderText()
cached_bounds_and_offset_valid_(false) {
}
-const Vector2d& RenderText::GetUpdatedDisplayOffset() {
- UpdateCachedBoundsAndOffset();
- return display_offset_;
-}
-
SelectionModel RenderText::GetAdjacentSelectionModel(
const SelectionModel& current,
BreakType break_type,
« no previous file with comments | « ui/gfx/render_text.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698