OLD | NEW |
1 // Copyright (c) 2011 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/native_textfield_views.h" | 5 #include "views/controls/textfield/native_textfield_views.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "grit/app_strings.h" | 13 #include "grit/app_strings.h" |
14 #include "ui/base/clipboard/clipboard.h" | 14 #include "ui/base/clipboard/clipboard.h" |
15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/canvas_skia.h" | 16 #include "ui/gfx/canvas_skia.h" |
17 #include "ui/gfx/insets.h" | 17 #include "ui/gfx/insets.h" |
18 #include "views/background.h" | 18 #include "views/background.h" |
19 #include "views/border.h" | 19 #include "views/border.h" |
20 #include "views/controls/menu/menu_2.h" | 20 #include "views/controls/menu/menu_2.h" |
| 21 #include "views/controls/textfield/text_range.h" |
21 #include "views/controls/textfield/textfield.h" | 22 #include "views/controls/textfield/textfield.h" |
| 23 #include "views/controls/textfield/textfield_controller.h" |
22 #include "views/controls/textfield/textfield_views_model.h" | 24 #include "views/controls/textfield/textfield_views_model.h" |
23 #include "views/events/event.h" | 25 #include "views/events/event.h" |
24 #include "views/metrics.h" | 26 #include "views/metrics.h" |
25 #include "views/views_delegate.h" | 27 #include "views/views_delegate.h" |
26 | 28 |
27 #if defined(OS_LINUX) | 29 #if defined(OS_LINUX) |
28 #include "ui/gfx/gtk_util.h" | 30 #include "ui/gfx/gtk_util.h" |
29 #endif | 31 #endif |
30 | 32 |
31 namespace { | 33 namespace { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 157 |
156 string16 NativeTextfieldViews::GetText() const { | 158 string16 NativeTextfieldViews::GetText() const { |
157 return model_->text(); | 159 return model_->text(); |
158 } | 160 } |
159 | 161 |
160 void NativeTextfieldViews::UpdateText() { | 162 void NativeTextfieldViews::UpdateText() { |
161 bool changed = model_->SetText(textfield_->text()); | 163 bool changed = model_->SetText(textfield_->text()); |
162 UpdateCursorBoundsAndTextOffset(); | 164 UpdateCursorBoundsAndTextOffset(); |
163 SchedulePaint(); | 165 SchedulePaint(); |
164 if (changed) { | 166 if (changed) { |
165 Textfield::Controller* controller = textfield_->GetController(); | 167 TextfieldController* controller = textfield_->GetController(); |
166 if (controller) | 168 if (controller) |
167 controller->ContentsChanged(textfield_, GetText()); | 169 controller->ContentsChanged(textfield_, GetText()); |
168 } | 170 } |
169 } | 171 } |
170 | 172 |
171 void NativeTextfieldViews::AppendText(const string16& text) { | 173 void NativeTextfieldViews::AppendText(const string16& text) { |
172 if (text.empty()) | 174 if (text.empty()) |
173 return; | 175 return; |
174 model_->Append(text); | 176 model_->Append(text); |
175 UpdateCursorBoundsAndTextOffset(); | 177 UpdateCursorBoundsAndTextOffset(); |
176 SchedulePaint(); | 178 SchedulePaint(); |
177 | 179 |
178 Textfield::Controller* controller = textfield_->GetController(); | 180 TextfieldController* controller = textfield_->GetController(); |
179 if (controller) | 181 if (controller) |
180 controller->ContentsChanged(textfield_, GetText()); | 182 controller->ContentsChanged(textfield_, GetText()); |
181 } | 183 } |
182 | 184 |
183 string16 NativeTextfieldViews::GetSelectedText() const { | 185 string16 NativeTextfieldViews::GetSelectedText() const { |
184 return model_->GetSelectedText(); | 186 return model_->GetSelectedText(); |
185 } | 187 } |
186 | 188 |
187 void NativeTextfieldViews::SelectAll() { | 189 void NativeTextfieldViews::SelectAll() { |
188 model_->SelectAll(); | 190 model_->SelectAll(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 model_->SelectRange(range); | 286 model_->SelectRange(range); |
285 UpdateCursorBoundsAndTextOffset(); | 287 UpdateCursorBoundsAndTextOffset(); |
286 SchedulePaint(); | 288 SchedulePaint(); |
287 } | 289 } |
288 | 290 |
289 size_t NativeTextfieldViews::GetCursorPosition() const { | 291 size_t NativeTextfieldViews::GetCursorPosition() const { |
290 return model_->cursor_pos(); | 292 return model_->cursor_pos(); |
291 } | 293 } |
292 | 294 |
293 bool NativeTextfieldViews::HandleKeyPressed(const views::KeyEvent& e) { | 295 bool NativeTextfieldViews::HandleKeyPressed(const views::KeyEvent& e) { |
294 Textfield::Controller* controller = textfield_->GetController(); | 296 TextfieldController* controller = textfield_->GetController(); |
295 bool handled = false; | 297 bool handled = false; |
296 if (controller) | 298 if (controller) |
297 handled = controller->HandleKeyEvent(textfield_, e); | 299 handled = controller->HandleKeyEvent(textfield_, e); |
298 return handled || HandleKeyEvent(e); | 300 return handled || HandleKeyEvent(e); |
299 } | 301 } |
300 | 302 |
301 bool NativeTextfieldViews::HandleKeyReleased(const views::KeyEvent& e) { | 303 bool NativeTextfieldViews::HandleKeyReleased(const views::KeyEvent& e) { |
302 return true; | 304 return true; |
303 } | 305 } |
304 | 306 |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 | 819 |
818 void NativeTextfieldViews::SetCursorForMouseClick(const views::MouseEvent& e) { | 820 void NativeTextfieldViews::SetCursorForMouseClick(const views::MouseEvent& e) { |
819 size_t pos = FindCursorPosition(e.location()); | 821 size_t pos = FindCursorPosition(e.location()); |
820 if (model_->MoveCursorTo(pos, false)) { | 822 if (model_->MoveCursorTo(pos, false)) { |
821 UpdateCursorBoundsAndTextOffset(); | 823 UpdateCursorBoundsAndTextOffset(); |
822 } | 824 } |
823 } | 825 } |
824 | 826 |
825 void NativeTextfieldViews::PropagateTextChange() { | 827 void NativeTextfieldViews::PropagateTextChange() { |
826 textfield_->SyncText(); | 828 textfield_->SyncText(); |
827 Textfield::Controller* controller = textfield_->GetController(); | 829 TextfieldController* controller = textfield_->GetController(); |
828 if (controller) | 830 if (controller) |
829 controller->ContentsChanged(textfield_, GetText()); | 831 controller->ContentsChanged(textfield_, GetText()); |
830 } | 832 } |
831 | 833 |
832 void NativeTextfieldViews::UpdateAfterChange(bool text_changed, | 834 void NativeTextfieldViews::UpdateAfterChange(bool text_changed, |
833 bool cursor_changed) { | 835 bool cursor_changed) { |
834 if (text_changed) | 836 if (text_changed) |
835 PropagateTextChange(); | 837 PropagateTextChange(); |
836 if (cursor_changed) { | 838 if (cursor_changed) { |
837 is_cursor_visible_ = true; | 839 is_cursor_visible_ = true; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 } | 907 } |
906 | 908 |
907 void NativeTextfieldViews::TextfieldBorder::SetInsets(int top, | 909 void NativeTextfieldViews::TextfieldBorder::SetInsets(int top, |
908 int left, | 910 int left, |
909 int bottom, | 911 int bottom, |
910 int right) { | 912 int right) { |
911 insets_.Set(top, left, bottom, right); | 913 insets_.Set(top, left, bottom, right); |
912 } | 914 } |
913 | 915 |
914 } // namespace views | 916 } // namespace views |
OLD | NEW |