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

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: nit 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') | ui/gfx/render_text_unittest.cc » ('j') | 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..20042c59aae6c0942d13d47a9e13654acb7480c6 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -872,6 +872,42 @@ SelectionModel RenderText::GetSelectionModelForSelectionStart() {
sel.is_reversed() ? CURSOR_BACKWARD : CURSOR_FORWARD);
}
+const Vector2d& RenderText::GetUpdatedDisplayOffset() {
+ UpdateCachedBoundsAndOffset();
+ return display_offset_;
+}
+
+void RenderText::SetDisplayOffset(int horizontal_offset) {
+ const int extra_content = GetContentWidth() - display_rect_.width();
+
+ int min_offset = 0;
+ int max_offset = 0;
+ if (extra_content > 0) {
+ switch (horizontal_alignment_) {
+ case ALIGN_LEFT:
+ min_offset = -extra_content;
+ break;
+ case ALIGN_RIGHT:
+ max_offset = extra_content;
+ break;
+ case ALIGN_CENTER:
+ min_offset = -extra_content / 2;
+ max_offset = extra_content / 2;
+ break;
+ default:
+ break;
+ }
+ }
+ if (horizontal_offset < min_offset)
+ horizontal_offset = min_offset;
+ else if (horizontal_offset > max_offset)
+ horizontal_offset = max_offset;
+
+ cached_bounds_and_offset_valid_ = true;
+ display_offset_.set_x(horizontal_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 +934,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') | ui/gfx/render_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698