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

Unified Diff: views/controls/textfield/textfield.h

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 side-by-side diff with in-line comments
Download patch
Index: views/controls/textfield/textfield.h
diff --git a/views/controls/textfield/textfield.h b/views/controls/textfield/textfield.h
index 3d7ce38c2b47dc0b6b44ed2f74590dc75fa84720..8f8db2e4cbbe541daf5e883f8f262d809dd1ddd2 100644
--- a/views/controls/textfield/textfield.h
+++ b/views/controls/textfield/textfield.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -32,9 +32,57 @@
namespace views {
class KeyEvent;
-
class NativeTextfieldWrapper;
+// TextRange specifies the range of text in the Textfield. This is
+// used to specify selected text and will be used to change the
+// attributes of characters in the textfield. The range preserves the
+// direction, and selecting from the end to the begining is considered
+// "reverse" order.
+class TextRange {
+ public:
+ TextRange() : start_(0), end_(0) {}
+ TextRange(size_t start, size_t end);
+
+ // Allow copy so that the omnibox can save the view state
+ // for each tabs.
+ explicit TextRange(const TextRange& range)
+ : start_(range.start_), end_(range.end_) {}
+
+ // Returns the start position;
+ size_t start() const { return start_; }
+
+ // Returns the end position.
+ size_t end() const { return end_; }
+
+ // Returns true if the selected text is empty.
+ bool is_empty() const { return start_ == end_; }
+
+ // Returns true if the selection is made in reverse order.
+ bool is_reverse() const { return start_ > end_; }
+
+ // Returns the min of selected range.
+ size_t GetMin() const;
+
+ // Returns the max of selected range.
+ size_t GetMax() const;
+
+ // Returns true if |range| has same start, end position.
+ bool Equals(const TextRange& range) const {
+ return start_ == range.start_ && end_ == range.end_;
+ }
+
+ // Set the range with |start| and |end|.
+ void SetRange(size_t start, size_t end);
+
+ private:
+ size_t start_;
+ size_t end_;
+
+ // No assign.
+ void operator=(const TextRange&);
+};
+
// This class implements a ChromeView that wraps a native text (edit) field.
class Textfield : public View {
public:
@@ -185,6 +233,18 @@ class Textfield : public View {
// Returns whether or not an IME is composing text.
bool IsIMEComposing() const;
+ // Gets the selected range. This is views implementation only and
Ben Goodger (Google) 2011/01/19 16:40:16 here, and everywhere else: views-implementation
oshima 2011/01/19 18:22:52 Done.
+ // has to be called after the wrapper is created.
+ void GetSelectedRange(TextRange* range) const;
+
+ // Selects the text given by |range|. This is views implementation only and
+ // has to be called after the wrapper is created.
+ void SelectRange(const TextRange& range);
+
+ // Returns the currnet cursor position. This is views implementation
Ben Goodger (Google) 2011/01/19 16:40:16 current
oshima 2011/01/19 18:22:52 Done.
+ // only and has to be called after the wrapper is created.
+ size_t GetCursorPosition() const;
+
#ifdef UNIT_TEST
gfx::NativeView GetTestingHandle() const {
return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL;

Powered by Google App Engine
This is Rietveld 408576698