OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEW_H_ | |
6 #define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEW_H_ | |
7 #pragma once | |
8 | |
9 #include <algorithm> | |
tfarina
2010/11/18 11:55:31
Do you need this include here? Or just in the .cc
| |
10 | |
11 #include "gfx/canvas.h" | |
tfarina
2010/11/18 11:55:31
can't you forward declare this?
| |
12 #include "views/controls/label.h" | |
13 #include "views/controls/textfield/textfield_model.h" | |
14 #include "views/event.h" | |
tfarina
2010/11/18 11:55:31
can't you forward declare this?
| |
15 #include "views/view.h" | |
tfarina
2010/11/18 11:55:31
I think you don't need this include.
| |
16 | |
17 namespace views { | |
18 | |
19 // View for a MVC of a single line textfield. The textfield inherits from Label | |
20 // to re-use its font and color related code. | |
21 class TextfieldView : public Label { | |
22 public: | |
23 TextfieldView(); | |
24 explicit TextfieldView(const std::wstring& text); | |
25 explicit TextfieldView(TextfieldModel* model); | |
tfarina
2010/11/18 11:55:31
Document that you take the ownership of |model|?
| |
26 | |
27 virtual void SetController(TextfieldController* controller); | |
tfarina
2010/11/18 11:55:31
The virtual is not needed, right?
| |
28 // Returns the rectangle in which the text can be painted. This is essentially | |
29 // the bounds of the view minus the border (insets) width. | |
30 gfx::Rect GetTextBounds(); | |
31 | |
32 | |
33 // View Overrides. Refer to view.h for documentation. | |
tfarina
2010/11/18 11:55:31
Please, rewrite this comment as just:
// Overridde
| |
34 virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e); | |
35 virtual bool OnMousePressed(const views::MouseEvent& e); | |
36 virtual bool OnMouseDragged(const views::MouseEvent& e); | |
37 virtual void OnMouseReleased(const views::MouseEvent& e, bool canceled); | |
38 virtual bool OnKeyPressed(const views::KeyEvent& e); | |
39 virtual bool OnKeyReleased(const views::KeyEvent& e); | |
40 virtual void Paint(gfx::Canvas* canvas); | |
41 virtual void WillGainFocus(); | |
42 virtual void DidGainFocus(); | |
43 virtual void WillLoseFocus(); | |
44 virtual std::wstring GetText(); | |
45 | |
46 // Getters | |
tfarina
2010/11/18 11:55:31
remove this comment. It's redundant.
| |
47 int onscreen_cursor_pos() { return onscreen_cursor_pos_; } | |
48 std::wstring visible_text() { return visible_text_; } | |
49 | |
50 static const char kViewClassName[]; | |
51 | |
52 private: | |
53 // Computes the portion of string that can be painted to the left of cursor. | |
54 std::wstring GetStringToLeftOfCursor(std::wstring text, int cursor_pos, | |
55 int onscreen_cursor_pos, gfx::Rect text_bounds); | |
56 | |
57 // Computes the portion of string that can be painted to the left of cursor. | |
58 std::wstring GetStringToRightOfCursor(std::wstring text, int cursor_pos, | |
59 int onscreen_cursor_pos, gfx::Rect text_bounds); | |
60 | |
61 // Utility function. Gets the character corresponding to a key event. | |
62 wchar_t GetWritableChar(const KeyEvent& key_event); | |
63 | |
64 // Utility function. Gets the character corresponding to a key_code. | |
65 wchar_t GetWritableChar(app::KeyboardCode key_code, bool shift); | |
66 bool HandleKeyEvent(const KeyEvent& key_event); | |
67 void Init(const std::wstring& text); | |
68 bool IsDirectionalKey(app::KeyboardCode key_code); | |
69 bool IsWritable(app::KeyboardCode key_code); | |
70 void PaintTextAndCursor(gfx::Canvas* canvas); | |
71 | |
72 // Safely increments the onscreen position of the cursor (making sure it does | |
73 // not exceeds the view bounds). | |
74 void SafeIncCursorPos(int inc); | |
75 | |
76 // Safely decrements the onscreen position of the cursor (making sure it does | |
77 // not go below 0). | |
78 void SafeDecCursorPos(int dec); | |
79 | |
80 scoped_ptr<TextfieldModel> model_; | |
81 scoped_ptr<TextfieldController> controller_; | |
82 std::wstring visible_text_; | |
83 bool selection_on_; | |
84 int selection_start_; | |
85 int onscreen_cursor_pos_; | |
86 }; | |
tfarina
2010/11/18 11:55:31
DISALLOW_COPY_AND_ASSIGN?
| |
87 }; | |
tfarina
2010/11/18 11:55:31
// namespace views
Also don't need the ; here
| |
88 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEW_H_ | |
OLD | NEW |