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

Side by Side Diff: views/controls/textfield/textfield_views_model.cc

Issue 6982055: Draw a NativeTextfieldViews drop location cursor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Combine cursor bounds data members, revise UpdateCursorBoundsAndTextOffset. Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/textfield/textfield_views_model.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/controls/textfield/textfield_views_model.h" 5 #include "views/controls/textfield/textfield_views_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/break_iterator.h" 9 #include "base/i18n/break_iterator.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 bool TextfieldViewsModel::MoveCursorTo(size_t pos, bool select) { 615 bool TextfieldViewsModel::MoveCursorTo(size_t pos, bool select) {
616 if (HasCompositionText()) 616 if (HasCompositionText())
617 ConfirmCompositionText(); 617 ConfirmCompositionText();
618 bool changed = cursor_pos_ != pos || select != HasSelection(); 618 bool changed = cursor_pos_ != pos || select != HasSelection();
619 cursor_pos_ = pos; 619 cursor_pos_ = pos;
620 if (!select) 620 if (!select)
621 ClearSelection(); 621 ClearSelection();
622 return changed; 622 return changed;
623 } 623 }
624 624
625 gfx::Rect TextfieldViewsModel::GetCursorBounds(const gfx::Font& font) const {
626 string16 text = GetVisibleText();
627 int x = font.GetStringWidth(text.substr(0U, cursor_pos_));
628 int h = font.GetHeight();
629 DCHECK(x >= 0);
630 if (text.length() == cursor_pos_) {
631 return gfx::Rect(x, 0, 0, h);
632 } else {
633 int x_end = font.GetStringWidth(text.substr(0U, cursor_pos_ + 1U));
634 return gfx::Rect(x, 0, x_end - x, h);
635 }
636 }
637
638 gfx::Rect TextfieldViewsModel::GetSelectionBounds(const gfx::Font& font) const { 625 gfx::Rect TextfieldViewsModel::GetSelectionBounds(const gfx::Font& font) const {
639 if (!HasSelection()) 626 if (!HasSelection())
640 return gfx::Rect(); 627 return gfx::Rect();
641 size_t start = std::min(selection_start_, cursor_pos_); 628 size_t start = std::min(selection_start_, cursor_pos_);
642 size_t end = std::max(selection_start_, cursor_pos_); 629 size_t end = std::max(selection_start_, cursor_pos_);
643 int start_x = font.GetStringWidth(text_.substr(0, start)); 630 int start_x = font.GetStringWidth(text_.substr(0, start));
644 int end_x = font.GetStringWidth(text_.substr(0, end)); 631 int end_x = font.GetStringWidth(text_.substr(0, end));
645 return gfx::Rect(start_x, 0, end_x - start_x, font.GetHeight()); 632 return gfx::Rect(start_x, 0, end_x - start_x, font.GetHeight());
646 } 633 }
647 634
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1076 }
1090 1077
1091 // static 1078 // static
1092 TextStyle* TextfieldViewsModel::CreateUnderlineStyle() { 1079 TextStyle* TextfieldViewsModel::CreateUnderlineStyle() {
1093 TextStyle* style = new TextStyle(); 1080 TextStyle* style = new TextStyle();
1094 style->set_underline(true); 1081 style->set_underline(true);
1095 return style; 1082 return style;
1096 } 1083 }
1097 1084
1098 } // namespace views 1085 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/textfield_views_model.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698