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

Side by Side Diff: ui/views/controls/textfield/native_textfield_views.cc

Issue 10693160: Add and specify Views::Textfield::SelectAll |reversed| flag, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove redundant comments. Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/controls/textfield/native_textfield_views.h" 5 #include "ui/views/controls/textfield/native_textfield_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 switch (event.type()) { 153 switch (event.type()) {
154 case ui::ET_GESTURE_TAP_DOWN: 154 case ui::ET_GESTURE_TAP_DOWN:
155 OnBeforeUserAction(); 155 OnBeforeUserAction();
156 textfield_->RequestFocus(); 156 textfield_->RequestFocus();
157 if (MoveCursorTo(event.location(), false)) 157 if (MoveCursorTo(event.location(), false))
158 SchedulePaint(); 158 SchedulePaint();
159 OnAfterUserAction(); 159 OnAfterUserAction();
160 return ui::GESTURE_STATUS_CONSUMED; 160 return ui::GESTURE_STATUS_CONSUMED;
161 case ui::ET_GESTURE_DOUBLE_TAP: 161 case ui::ET_GESTURE_DOUBLE_TAP:
162 SelectAll(); 162 SelectAll(false);
163 return ui::GESTURE_STATUS_CONSUMED; 163 return ui::GESTURE_STATUS_CONSUMED;
164 case ui::ET_GESTURE_SCROLL_UPDATE: 164 case ui::ET_GESTURE_SCROLL_UPDATE:
165 OnBeforeUserAction(); 165 OnBeforeUserAction();
166 if (MoveCursorTo(event.location(), true)) 166 if (MoveCursorTo(event.location(), true))
167 SchedulePaint(); 167 SchedulePaint();
168 OnAfterUserAction(); 168 OnAfterUserAction();
169 return ui::GESTURE_STATUS_CONSUMED; 169 return ui::GESTURE_STATUS_CONSUMED;
170 default: 170 default:
171 break; 171 break;
172 } 172 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 return; 363 return;
364 model_->Append(GetTextForDisplay(text)); 364 model_->Append(GetTextForDisplay(text));
365 OnCaretBoundsChanged(); 365 OnCaretBoundsChanged();
366 SchedulePaint(); 366 SchedulePaint();
367 } 367 }
368 368
369 string16 NativeTextfieldViews::GetSelectedText() const { 369 string16 NativeTextfieldViews::GetSelectedText() const {
370 return model_->GetSelectedText(); 370 return model_->GetSelectedText();
371 } 371 }
372 372
373 void NativeTextfieldViews::SelectAll() { 373 void NativeTextfieldViews::SelectAll(bool reversed) {
374 OnBeforeUserAction(); 374 OnBeforeUserAction();
375 model_->SelectAll(); 375 model_->SelectAll(reversed);
376 OnCaretBoundsChanged(); 376 OnCaretBoundsChanged();
377 SchedulePaint(); 377 SchedulePaint();
378 OnAfterUserAction(); 378 OnAfterUserAction();
379 } 379 }
380 380
381 void NativeTextfieldViews::ClearSelection() { 381 void NativeTextfieldViews::ClearSelection() {
382 OnBeforeUserAction(); 382 OnBeforeUserAction();
383 model_->ClearSelection(); 383 model_->ClearSelection();
384 OnCaretBoundsChanged(); 384 OnCaretBoundsChanged();
385 SchedulePaint(); 385 SchedulePaint();
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 case IDS_APP_COPY: 611 case IDS_APP_COPY:
612 Copy(); 612 Copy();
613 break; 613 break;
614 case IDS_APP_PASTE: 614 case IDS_APP_PASTE:
615 text_changed = Paste(); 615 text_changed = Paste();
616 break; 616 break;
617 case IDS_APP_DELETE: 617 case IDS_APP_DELETE:
618 text_changed = model_->Delete(); 618 text_changed = model_->Delete();
619 break; 619 break;
620 case IDS_APP_SELECT_ALL: 620 case IDS_APP_SELECT_ALL:
621 SelectAll(); 621 SelectAll(false);
622 break; 622 break;
623 default: 623 default:
624 textfield_->GetController()->ExecuteCommand(command_id); 624 textfield_->GetController()->ExecuteCommand(command_id);
625 break; 625 break;
626 } 626 }
627 627
628 // The cursor must have changed if text changed during cut/paste/delete. 628 // The cursor must have changed if text changed during cut/paste/delete.
629 UpdateAfterChange(text_changed, text_changed); 629 UpdateAfterChange(text_changed, text_changed);
630 OnAfterUserAction(); 630 OnAfterUserAction();
631 } 631 }
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 cursor_changed = text_changed = model_->Undo(); 920 cursor_changed = text_changed = model_->Undo();
921 else if (control && shift && editable) 921 else if (control && shift && editable)
922 cursor_changed = text_changed = model_->Redo(); 922 cursor_changed = text_changed = model_->Redo();
923 break; 923 break;
924 case ui::VKEY_Y: 924 case ui::VKEY_Y:
925 if (control && editable) 925 if (control && editable)
926 cursor_changed = text_changed = model_->Redo(); 926 cursor_changed = text_changed = model_->Redo();
927 break; 927 break;
928 case ui::VKEY_A: 928 case ui::VKEY_A:
929 if (control) { 929 if (control) {
930 model_->SelectAll(); 930 model_->SelectAll(false);
931 cursor_changed = true; 931 cursor_changed = true;
932 } 932 }
933 break; 933 break;
934 case ui::VKEY_X: 934 case ui::VKEY_X:
935 if (control && editable && readable) 935 if (control && editable && readable)
936 cursor_changed = text_changed = Cut(); 936 cursor_changed = text_changed = Cut();
937 break; 937 break;
938 case ui::VKEY_C: 938 case ui::VKEY_C:
939 if (control && readable) 939 if (control && readable)
940 Copy(); 940 Copy();
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 if (can_drag && GetRenderText()->IsPointInSelection(event.location())) 1170 if (can_drag && GetRenderText()->IsPointInSelection(event.location()))
1171 initiating_drag_ = true; 1171 initiating_drag_ = true;
1172 else 1172 else
1173 MoveCursorTo(event.location(), event.IsShiftDown()); 1173 MoveCursorTo(event.location(), event.IsShiftDown());
1174 break; 1174 break;
1175 case 1: 1175 case 1:
1176 model_->SelectWord(); 1176 model_->SelectWord();
1177 OnCaretBoundsChanged(); 1177 OnCaretBoundsChanged();
1178 break; 1178 break;
1179 case 2: 1179 case 2:
1180 model_->SelectAll(); 1180 model_->SelectAll(false);
1181 OnCaretBoundsChanged(); 1181 OnCaretBoundsChanged();
1182 break; 1182 break;
1183 default: 1183 default:
1184 NOTREACHED(); 1184 NOTREACHED();
1185 } 1185 }
1186 SchedulePaint(); 1186 SchedulePaint();
1187 } 1187 }
1188 } 1188 }
1189 1189
1190 bool NativeTextfieldViews::ImeEditingAllowed() const { 1190 bool NativeTextfieldViews::ImeEditingAllowed() const {
1191 // We don't allow the input method to retrieve or delete content from a 1191 // We don't allow the input method to retrieve or delete content from a
1192 // password field. 1192 // password field.
1193 ui::TextInputType t = GetTextInputType(); 1193 ui::TextInputType t = GetTextInputType();
1194 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); 1194 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD);
1195 } 1195 }
1196 1196
1197 // static 1197 // static
1198 bool NativeTextfieldViews::ShouldInsertChar(char16 ch, int flags) { 1198 bool NativeTextfieldViews::ShouldInsertChar(char16 ch, int flags) {
1199 // Filter out all control characters, including tab and new line characters, 1199 // Filter out all control characters, including tab and new line characters,
1200 // and all characters with Alt modifier. But we need to allow characters with 1200 // and all characters with Alt modifier. But we need to allow characters with
1201 // AltGr modifier. 1201 // AltGr modifier.
1202 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different 1202 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different
1203 // flag that we don't care about. 1203 // flag that we don't care about.
1204 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && 1204 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) &&
1205 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; 1205 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN;
1206 } 1206 }
1207 1207
1208 } // namespace views 1208 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/native_textfield_views.h ('k') | ui/views/controls/textfield/native_textfield_views_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698