Chromium Code Reviews| Index: views/controls/textfield/textfield_view.h |
| diff --git a/views/controls/textfield/textfield_view.h b/views/controls/textfield/textfield_view.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c4ff0a10f1cc6d0ffe739486061b3f801608650d |
| --- /dev/null |
| +++ b/views/controls/textfield/textfield_view.h |
| @@ -0,0 +1,88 @@ |
| +// 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_VIEW_H_ |
| +#define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEW_H_ |
| +#pragma once |
| + |
| +#include <algorithm> |
|
tfarina
2010/11/18 11:55:31
Do you need this include here? Or just in the .cc
|
| + |
| +#include "gfx/canvas.h" |
|
tfarina
2010/11/18 11:55:31
can't you forward declare this?
|
| +#include "views/controls/label.h" |
| +#include "views/controls/textfield/textfield_model.h" |
| +#include "views/event.h" |
|
tfarina
2010/11/18 11:55:31
can't you forward declare this?
|
| +#include "views/view.h" |
|
tfarina
2010/11/18 11:55:31
I think you don't need this include.
|
| + |
| +namespace views { |
| + |
| +// View for a MVC of a single line textfield. The textfield inherits from Label |
| +// to re-use its font and color related code. |
| +class TextfieldView : public Label { |
| + public: |
| + TextfieldView(); |
| + explicit TextfieldView(const std::wstring& text); |
| + explicit TextfieldView(TextfieldModel* model); |
|
tfarina
2010/11/18 11:55:31
Document that you take the ownership of |model|?
|
| + |
| + virtual void SetController(TextfieldController* controller); |
|
tfarina
2010/11/18 11:55:31
The virtual is not needed, right?
|
| + // Returns the rectangle in which the text can be painted. This is essentially |
| + // the bounds of the view minus the border (insets) width. |
| + gfx::Rect GetTextBounds(); |
| + |
| + |
| + // View Overrides. Refer to view.h for documentation. |
|
tfarina
2010/11/18 11:55:31
Please, rewrite this comment as just:
// Overridde
|
| + virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e); |
| + virtual bool OnMousePressed(const views::MouseEvent& e); |
| + virtual bool OnMouseDragged(const views::MouseEvent& e); |
| + virtual void OnMouseReleased(const views::MouseEvent& e, bool canceled); |
| + virtual bool OnKeyPressed(const views::KeyEvent& e); |
| + virtual bool OnKeyReleased(const views::KeyEvent& e); |
| + virtual void Paint(gfx::Canvas* canvas); |
| + virtual void WillGainFocus(); |
| + virtual void DidGainFocus(); |
| + virtual void WillLoseFocus(); |
| + virtual std::wstring GetText(); |
| + |
| + // Getters |
|
tfarina
2010/11/18 11:55:31
remove this comment. It's redundant.
|
| + int onscreen_cursor_pos() { return onscreen_cursor_pos_; } |
| + std::wstring visible_text() { return visible_text_; } |
| + |
| + static const char kViewClassName[]; |
| + |
| + private: |
| + // Computes the portion of string that can be painted to the left of cursor. |
| + std::wstring GetStringToLeftOfCursor(std::wstring text, int cursor_pos, |
| + int onscreen_cursor_pos, gfx::Rect text_bounds); |
| + |
| + // Computes the portion of string that can be painted to the left of cursor. |
| + std::wstring GetStringToRightOfCursor(std::wstring text, int cursor_pos, |
| + int onscreen_cursor_pos, gfx::Rect text_bounds); |
| + |
| + // Utility function. Gets the character corresponding to a key event. |
| + wchar_t GetWritableChar(const KeyEvent& key_event); |
| + |
| + // Utility function. Gets the character corresponding to a key_code. |
| + wchar_t GetWritableChar(app::KeyboardCode key_code, bool shift); |
| + bool HandleKeyEvent(const KeyEvent& key_event); |
| + void Init(const std::wstring& text); |
| + bool IsDirectionalKey(app::KeyboardCode key_code); |
| + bool IsWritable(app::KeyboardCode key_code); |
| + void PaintTextAndCursor(gfx::Canvas* canvas); |
| + |
| + // Safely increments the onscreen position of the cursor (making sure it does |
| + // not exceeds the view bounds). |
| + void SafeIncCursorPos(int inc); |
| + |
| + // Safely decrements the onscreen position of the cursor (making sure it does |
| + // not go below 0). |
| + void SafeDecCursorPos(int dec); |
| + |
| + scoped_ptr<TextfieldModel> model_; |
| + scoped_ptr<TextfieldController> controller_; |
| + std::wstring visible_text_; |
| + bool selection_on_; |
| + int selection_start_; |
| + int onscreen_cursor_pos_; |
| +}; |
|
tfarina
2010/11/18 11:55:31
DISALLOW_COPY_AND_ASSIGN?
|
| +}; |
|
tfarina
2010/11/18 11:55:31
// namespace views
Also don't need the ; here
|
| +#endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEW_H_ |