| Index: views/controls/textfield/textfield_model.h
|
| ===================================================================
|
| --- views/controls/textfield/textfield_model.h (revision 0)
|
| +++ views/controls/textfield/textfield_model.h (revision 0)
|
| @@ -0,0 +1,78 @@
|
| +// Copyright (c) 2010 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.
|
| +
|
| +#ifndef VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_
|
| +#define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_
|
| +#pragma once
|
| +
|
| +#include <string>
|
| +#include <vector>
|
| +
|
| +#include "base/gap_buffer.h"
|
| +#include "views/event.h"
|
| +
|
| +namespace views {
|
| +
|
| +// Model for a single line textfield. It uses a gap buffer under the hood to
|
| +// store data and perform cursor movement.
|
| +class TextfieldModel {
|
| + public:
|
| + TextfieldModel();
|
| + explicit TextfieldModel(const std::wstring& text);
|
| +
|
| + // Inserts a character at the current cursor position.
|
| + void Insert(wchar_t c);
|
| +
|
| + // Deletes the first character after the current cursor position (as if, the
|
| + // the user has pressed delete key in the textfield).
|
| + wchar_t InsertDelete();
|
| +
|
| + // Deletes the first character before the current cursor position (as if, the
|
| + // the user has pressed backspace key in the textfield).
|
| + wchar_t InsertBackspace();
|
| +
|
| + // Returns the current cursor position.
|
| + int GetCurrentCursorPos();
|
| +
|
| + // Moves the cursor left by one position (as if, the user has pressed the left
|
| + // arrow key).
|
| + void MoveCursorLeft();
|
| +
|
| + // Moves the cursor right by one position (as if, the user has pressed the
|
| + // right arrow key).
|
| + void MoveCursorRight();
|
| +
|
| + // Moves the cursor left by one word (word boundry is defined by space).
|
| + void MoveCursorToPreviousWord();
|
| +
|
| + // Moves the cursor right by one word (word boundry is defined by space).
|
| + void MoveCursorToNextWord();
|
| +
|
| + // Moves the cursor to start of the textfield contents.
|
| + void MoveCursorToStart();
|
| +
|
| + // Moves the cursor to end of the textfield contents.
|
| + void MoveCursorToEnd();
|
| +
|
| + // Returns the current contents of the textfield model.
|
| + std::wstring text();
|
| +
|
| + private:
|
| + // Synchronizes this model's member field "text_" with the contents of the
|
| + // underlying gap buffer. The need for synchronization is determined by the
|
| + // "dirty_" flag.
|
| + void SyncText();
|
| +
|
| + scoped_ptr<base::GapBuffer<wchar_t> > buffer_;
|
| + std::wstring text_;
|
| + bool dirty_;
|
| +};
|
| +
|
| +class TextfieldController {
|
| + public:
|
| + virtual ~TextfieldController();
|
| + virtual void TextChanged(const std::wstring new_text);
|
| +};
|
| +};
|
| +#endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_
|
|
|
| Property changes on: views/controls/textfield/textfield_model.h
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|