OLD | NEW |
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/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 case IDS_MOVE_LEFT: | 1254 case IDS_MOVE_LEFT: |
1255 case IDS_MOVE_LEFT_AND_MODIFY_SELECTION: | 1255 case IDS_MOVE_LEFT_AND_MODIFY_SELECTION: |
1256 case IDS_MOVE_RIGHT: | 1256 case IDS_MOVE_RIGHT: |
1257 case IDS_MOVE_RIGHT_AND_MODIFY_SELECTION: | 1257 case IDS_MOVE_RIGHT_AND_MODIFY_SELECTION: |
1258 case IDS_MOVE_WORD_LEFT: | 1258 case IDS_MOVE_WORD_LEFT: |
1259 case IDS_MOVE_WORD_LEFT_AND_MODIFY_SELECTION: | 1259 case IDS_MOVE_WORD_LEFT_AND_MODIFY_SELECTION: |
1260 case IDS_MOVE_WORD_RIGHT: | 1260 case IDS_MOVE_WORD_RIGHT: |
1261 case IDS_MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: | 1261 case IDS_MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: |
1262 case IDS_MOVE_TO_BEGINNING_OF_LINE: | 1262 case IDS_MOVE_TO_BEGINNING_OF_LINE: |
1263 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: | 1263 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: |
| 1264 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_EXTEND_SELECTION: |
| 1265 case IDS_MOVE_TOWARDS_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: |
1264 case IDS_MOVE_TO_END_OF_LINE: | 1266 case IDS_MOVE_TO_END_OF_LINE: |
1265 case IDS_MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: | 1267 case IDS_MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: |
| 1268 case IDS_MOVE_TO_END_OF_LINE_AND_EXTEND_SELECTION: |
| 1269 case IDS_MOVE_TOWARDS_END_OF_LINE_AND_MODIFY_SELECTION: |
1266 return true; | 1270 return true; |
1267 default: | 1271 default: |
1268 return false; | 1272 return false; |
1269 } | 1273 } |
1270 } | 1274 } |
1271 | 1275 |
1272 bool Textfield::GetAcceleratorForCommandId(int command_id, | 1276 bool Textfield::GetAcceleratorForCommandId(int command_id, |
1273 ui::Accelerator* accelerator) { | 1277 ui::Accelerator* accelerator) { |
1274 switch (command_id) { | 1278 switch (command_id) { |
1275 case IDS_APP_UNDO: | 1279 case IDS_APP_UNDO: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 if (!IsCommandIdEnabled(command_id)) | 1322 if (!IsCommandIdEnabled(command_id)) |
1319 return; | 1323 return; |
1320 | 1324 |
1321 bool text_changed = false; | 1325 bool text_changed = false; |
1322 bool cursor_changed = false; | 1326 bool cursor_changed = false; |
1323 bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; | 1327 bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; |
1324 gfx::VisualCursorDirection begin = rtl ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT; | 1328 gfx::VisualCursorDirection begin = rtl ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT; |
1325 gfx::VisualCursorDirection end = rtl ? gfx::CURSOR_LEFT : gfx::CURSOR_RIGHT; | 1329 gfx::VisualCursorDirection end = rtl ? gfx::CURSOR_LEFT : gfx::CURSOR_RIGHT; |
1326 gfx::SelectionModel selection_model = GetSelectionModel(); | 1330 gfx::SelectionModel selection_model = GetSelectionModel(); |
1327 | 1331 |
| 1332 #if defined(OS_MACOSX) |
| 1333 gfx::SelectionReversedBehavior word_selection = gfx::SELECTION_CARET; |
| 1334 #else |
| 1335 gfx::SelectionReversedBehavior word_selection = gfx::SELECTION_START_NEW; |
| 1336 #endif |
| 1337 |
1328 OnBeforeUserAction(); | 1338 OnBeforeUserAction(); |
1329 switch (command_id) { | 1339 switch (command_id) { |
1330 case IDS_APP_UNDO: | 1340 case IDS_APP_UNDO: |
1331 text_changed = cursor_changed = model_->Undo(); | 1341 text_changed = cursor_changed = model_->Undo(); |
1332 break; | 1342 break; |
1333 case IDS_APP_REDO: | 1343 case IDS_APP_REDO: |
1334 text_changed = cursor_changed = model_->Redo(); | 1344 text_changed = cursor_changed = model_->Redo(); |
1335 break; | 1345 break; |
1336 case IDS_APP_CUT: | 1346 case IDS_APP_CUT: |
1337 text_changed = cursor_changed = Cut(); | 1347 text_changed = cursor_changed = Cut(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 case IDS_MOVE_RIGHT: | 1389 case IDS_MOVE_RIGHT: |
1380 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); | 1390 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); |
1381 break; | 1391 break; |
1382 case IDS_MOVE_RIGHT_AND_MODIFY_SELECTION: | 1392 case IDS_MOVE_RIGHT_AND_MODIFY_SELECTION: |
1383 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 1393 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
1384 break; | 1394 break; |
1385 case IDS_MOVE_WORD_LEFT: | 1395 case IDS_MOVE_WORD_LEFT: |
1386 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false); | 1396 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false); |
1387 break; | 1397 break; |
1388 case IDS_MOVE_WORD_LEFT_AND_MODIFY_SELECTION: | 1398 case IDS_MOVE_WORD_LEFT_AND_MODIFY_SELECTION: |
1389 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 1399 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true, |
| 1400 word_selection); |
1390 break; | 1401 break; |
1391 case IDS_MOVE_WORD_RIGHT: | 1402 case IDS_MOVE_WORD_RIGHT: |
1392 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); | 1403 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); |
1393 break; | 1404 break; |
1394 case IDS_MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: | 1405 case IDS_MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: |
1395 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); | 1406 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true, |
| 1407 word_selection); |
1396 break; | 1408 break; |
1397 case IDS_MOVE_TO_BEGINNING_OF_LINE: | 1409 case IDS_MOVE_TO_BEGINNING_OF_LINE: |
1398 model_->MoveCursor(gfx::LINE_BREAK, begin, false); | 1410 model_->MoveCursor(gfx::LINE_BREAK, begin, false); |
1399 break; | 1411 break; |
1400 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: | 1412 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: |
1401 model_->MoveCursor(gfx::LINE_BREAK, begin, true); | 1413 model_->MoveCursor(gfx::LINE_BREAK, begin, true, |
| 1414 gfx::SELECTION_START_NEW); |
| 1415 break; |
| 1416 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_EXTEND_SELECTION: |
| 1417 model_->MoveCursor(gfx::LINE_BREAK, begin, true, gfx::SELECTION_EXTEND); |
| 1418 break; |
| 1419 case IDS_MOVE_TOWARDS_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: |
| 1420 model_->MoveCursor(gfx::LINE_BREAK, begin, true, gfx::SELECTION_CARET); |
1402 break; | 1421 break; |
1403 case IDS_MOVE_TO_END_OF_LINE: | 1422 case IDS_MOVE_TO_END_OF_LINE: |
1404 model_->MoveCursor(gfx::LINE_BREAK, end, false); | 1423 model_->MoveCursor(gfx::LINE_BREAK, end, false); |
1405 break; | 1424 break; |
1406 case IDS_MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: | 1425 case IDS_MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: |
1407 model_->MoveCursor(gfx::LINE_BREAK, end, true); | 1426 model_->MoveCursor(gfx::LINE_BREAK, end, true, gfx::SELECTION_START_NEW); |
| 1427 break; |
| 1428 case IDS_MOVE_TO_END_OF_LINE_AND_EXTEND_SELECTION: |
| 1429 model_->MoveCursor(gfx::LINE_BREAK, end, true, gfx::SELECTION_EXTEND); |
| 1430 break; |
| 1431 case IDS_MOVE_TOWARDS_END_OF_LINE_AND_MODIFY_SELECTION: |
| 1432 model_->MoveCursor(gfx::LINE_BREAK, end, true, gfx::SELECTION_CARET); |
1408 break; | 1433 break; |
1409 default: | 1434 default: |
1410 NOTREACHED(); | 1435 NOTREACHED(); |
1411 break; | 1436 break; |
1412 } | 1437 } |
1413 | 1438 |
1414 cursor_changed |= GetSelectionModel() != selection_model; | 1439 cursor_changed |= GetSelectionModel() != selection_model; |
1415 if (cursor_changed) | 1440 if (cursor_changed) |
1416 UpdateSelectionClipboard(); | 1441 UpdateSelectionClipboard(); |
1417 UpdateAfterChange(text_changed, cursor_changed); | 1442 UpdateAfterChange(text_changed, cursor_changed); |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1925 RequestFocus(); | 1950 RequestFocus(); |
1926 model_->MoveCursorTo(mouse); | 1951 model_->MoveCursorTo(mouse); |
1927 if (!selection_clipboard_text.empty()) { | 1952 if (!selection_clipboard_text.empty()) { |
1928 model_->InsertText(selection_clipboard_text); | 1953 model_->InsertText(selection_clipboard_text); |
1929 UpdateAfterChange(true, true); | 1954 UpdateAfterChange(true, true); |
1930 } | 1955 } |
1931 OnAfterUserAction(); | 1956 OnAfterUserAction(); |
1932 } | 1957 } |
1933 | 1958 |
1934 } // namespace views | 1959 } // namespace views |
OLD | NEW |