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

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

Issue 6318004: Add TextRange and related methods to Textfield Views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 11 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
OLDNEW
1 // Copyright (c) 2010 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.h" 5 #include "views/controls/textfield/textfield.h"
6 6
7 #if defined(OS_LINUX) 7 #if defined(OS_LINUX)
8 #include <gdk/gdkkeysyms.h> 8 #include <gdk/gdkkeysyms.h>
9 #endif 9 #endif
10 10
11 #include <string> 11 #include <string>
(...skipping 16 matching lines...) Expand all
28 #include "views/controls/textfield/native_textfield_win.h" 28 #include "views/controls/textfield/native_textfield_win.h"
29 #include "views/controls/textfield/native_textfield_views.h" 29 #include "views/controls/textfield/native_textfield_views.h"
30 #endif 30 #endif
31 31
32 namespace views { 32 namespace views {
33 33
34 // static 34 // static
35 const char Textfield::kViewClassName[] = "views/Textfield"; 35 const char Textfield::kViewClassName[] = "views/Textfield";
36 36
37 ///////////////////////////////////////////////////////////////////////////// 37 /////////////////////////////////////////////////////////////////////////////
38 // TextRange
39
40 TextRange::TextRange(size_t start, size_t end)
41 : start_(start),
42 end_(end) {
43 }
44
45 size_t TextRange::GetMin() const {
46 return std::min(start_, end_);
47 }
48
49 size_t TextRange::GetMax() const {
50 return std::max(start_, end_);
51 }
52
53 void TextRange::SetRange(size_t start, size_t end) {
54 start_ = start;
55 end_ = end;
56 }
57
58 /////////////////////////////////////////////////////////////////////////////
38 // Textfield 59 // Textfield
39 60
40 Textfield::Textfield() 61 Textfield::Textfield()
41 : native_wrapper_(NULL), 62 : native_wrapper_(NULL),
42 controller_(NULL), 63 controller_(NULL),
43 style_(STYLE_DEFAULT), 64 style_(STYLE_DEFAULT),
44 read_only_(false), 65 read_only_(false),
45 default_width_in_chars_(0), 66 default_width_in_chars_(0),
46 draw_border_(true), 67 draw_border_(true),
47 text_color_(SK_ColorBLACK), 68 text_color_(SK_ColorBLACK),
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 256
236 void Textfield::SyncText() { 257 void Textfield::SyncText() {
237 if (native_wrapper_) 258 if (native_wrapper_)
238 text_ = native_wrapper_->GetText(); 259 text_ = native_wrapper_->GetText();
239 } 260 }
240 261
241 bool Textfield::IsIMEComposing() const { 262 bool Textfield::IsIMEComposing() const {
242 return native_wrapper_ && native_wrapper_->IsIMEComposing(); 263 return native_wrapper_ && native_wrapper_->IsIMEComposing();
243 } 264 }
244 265
266 void Textfield::GetSelectedRange(TextRange* range) const {
267 DCHECK(native_wrapper_);
268 if (native_wrapper_)
269 native_wrapper_->GetSelectedRange(range);
270 }
271
272 void Textfield::SelectRange(const TextRange& range) {
273 DCHECK(native_wrapper_);
274 if (native_wrapper_)
275 native_wrapper_->SelectRange(range);
276 }
277
278 size_t Textfield::GetCursorPosition() const {
279 DCHECK(native_wrapper_);
280 return native_wrapper_ ? native_wrapper_->GetCursorPosition() : 0;
281 }
282
245 //////////////////////////////////////////////////////////////////////////////// 283 ////////////////////////////////////////////////////////////////////////////////
246 // Textfield, View overrides: 284 // Textfield, View overrides:
247 285
248 void Textfield::Layout() { 286 void Textfield::Layout() {
249 if (native_wrapper_) { 287 if (native_wrapper_) {
250 native_wrapper_->GetView()->SetBounds(GetLocalBounds(true)); 288 native_wrapper_->GetView()->SetBounds(GetLocalBounds(true));
251 native_wrapper_->GetView()->Layout(); 289 native_wrapper_->GetView()->Layout();
252 } 290 }
253 } 291 }
254 292
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 } 411 }
374 #endif 412 #endif
375 } 413 }
376 } 414 }
377 415
378 std::string Textfield::GetClassName() const { 416 std::string Textfield::GetClassName() const {
379 return kViewClassName; 417 return kViewClassName;
380 } 418 }
381 419
382 } // namespace views 420 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698