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

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

Issue 1989143002: MacViews: Correct behavior of move and select commands when selection direction changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_commands
Patch Set: Created 4 years, 7 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
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/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 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 case IDS_MOVE_LEFT: 1258 case IDS_MOVE_LEFT:
1259 case IDS_MOVE_LEFT_AND_MODIFY_SELECTION: 1259 case IDS_MOVE_LEFT_AND_MODIFY_SELECTION:
1260 case IDS_MOVE_RIGHT: 1260 case IDS_MOVE_RIGHT:
1261 case IDS_MOVE_RIGHT_AND_MODIFY_SELECTION: 1261 case IDS_MOVE_RIGHT_AND_MODIFY_SELECTION:
1262 case IDS_MOVE_WORD_LEFT: 1262 case IDS_MOVE_WORD_LEFT:
1263 case IDS_MOVE_WORD_LEFT_AND_MODIFY_SELECTION: 1263 case IDS_MOVE_WORD_LEFT_AND_MODIFY_SELECTION:
1264 case IDS_MOVE_WORD_RIGHT: 1264 case IDS_MOVE_WORD_RIGHT:
1265 case IDS_MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: 1265 case IDS_MOVE_WORD_RIGHT_AND_MODIFY_SELECTION:
1266 case IDS_MOVE_TO_BEGINNING_OF_LINE: 1266 case IDS_MOVE_TO_BEGINNING_OF_LINE:
1267 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: 1267 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION:
1268 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_EXTEND_SELECTION:
1269 case IDS_MOVE_TOWARDS_BEGINNING_OF_LINE_AND_MODIFY_SELECTION:
1268 case IDS_MOVE_TO_END_OF_LINE: 1270 case IDS_MOVE_TO_END_OF_LINE:
1269 case IDS_MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: 1271 case IDS_MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION:
1272 case IDS_MOVE_TO_END_OF_LINE_AND_EXTEND_SELECTION:
1273 case IDS_MOVE_TOWARDS_END_OF_LINE_AND_MODIFY_SELECTION:
1270 return true; 1274 return true;
1271 default: 1275 default:
1272 return false; 1276 return false;
1273 } 1277 }
1274 } 1278 }
1275 1279
1276 bool Textfield::GetAcceleratorForCommandId(int command_id, 1280 bool Textfield::GetAcceleratorForCommandId(int command_id,
1277 ui::Accelerator* accelerator) { 1281 ui::Accelerator* accelerator) {
1278 switch (command_id) { 1282 switch (command_id) {
1279 case IDS_APP_UNDO: 1283 case IDS_APP_UNDO:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 if (!IsCommandIdEnabled(command_id)) 1326 if (!IsCommandIdEnabled(command_id))
1323 return; 1327 return;
1324 1328
1325 bool text_changed = false; 1329 bool text_changed = false;
1326 bool cursor_changed = false; 1330 bool cursor_changed = false;
1327 bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; 1331 bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT;
1328 gfx::VisualCursorDirection begin = rtl ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT; 1332 gfx::VisualCursorDirection begin = rtl ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT;
1329 gfx::VisualCursorDirection end = rtl ? gfx::CURSOR_LEFT : gfx::CURSOR_RIGHT; 1333 gfx::VisualCursorDirection end = rtl ? gfx::CURSOR_LEFT : gfx::CURSOR_RIGHT;
1330 gfx::SelectionModel selection_model = GetSelectionModel(); 1334 gfx::SelectionModel selection_model = GetSelectionModel();
1331 1335
1336 #if defined(OS_MACOSX)
1337 gfx::SelectionReversedBehavior word_selection = gfx::SELECTION_CARET;
1338 #else
1339 gfx::SelectionReversedBehavior word_selection = gfx::SELECTION_START_NEW;
1340 #endif
1341
1332 OnBeforeUserAction(); 1342 OnBeforeUserAction();
1333 switch (command_id) { 1343 switch (command_id) {
1334 case IDS_APP_UNDO: 1344 case IDS_APP_UNDO:
1335 text_changed = cursor_changed = model_->Undo(); 1345 text_changed = cursor_changed = model_->Undo();
1336 break; 1346 break;
1337 case IDS_APP_REDO: 1347 case IDS_APP_REDO:
1338 text_changed = cursor_changed = model_->Redo(); 1348 text_changed = cursor_changed = model_->Redo();
1339 break; 1349 break;
1340 case IDS_APP_CUT: 1350 case IDS_APP_CUT:
1341 text_changed = cursor_changed = Cut(); 1351 text_changed = cursor_changed = Cut();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 case IDS_MOVE_RIGHT: 1393 case IDS_MOVE_RIGHT:
1384 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 1394 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
1385 break; 1395 break;
1386 case IDS_MOVE_RIGHT_AND_MODIFY_SELECTION: 1396 case IDS_MOVE_RIGHT_AND_MODIFY_SELECTION:
1387 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 1397 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
1388 break; 1398 break;
1389 case IDS_MOVE_WORD_LEFT: 1399 case IDS_MOVE_WORD_LEFT:
1390 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false); 1400 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false);
1391 break; 1401 break;
1392 case IDS_MOVE_WORD_LEFT_AND_MODIFY_SELECTION: 1402 case IDS_MOVE_WORD_LEFT_AND_MODIFY_SELECTION:
1393 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 1403 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true,
1404 word_selection);
1394 break; 1405 break;
1395 case IDS_MOVE_WORD_RIGHT: 1406 case IDS_MOVE_WORD_RIGHT:
1396 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); 1407 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false);
1397 break; 1408 break;
1398 case IDS_MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: 1409 case IDS_MOVE_WORD_RIGHT_AND_MODIFY_SELECTION:
1399 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 1410 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true,
1411 word_selection);
1400 break; 1412 break;
1401 case IDS_MOVE_TO_BEGINNING_OF_LINE: 1413 case IDS_MOVE_TO_BEGINNING_OF_LINE:
1402 model_->MoveCursor(gfx::LINE_BREAK, begin, false); 1414 model_->MoveCursor(gfx::LINE_BREAK, begin, false);
1403 break; 1415 break;
1404 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: 1416 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION:
1405 model_->MoveCursor(gfx::LINE_BREAK, begin, true); 1417 model_->MoveCursor(gfx::LINE_BREAK, begin, true,
1418 gfx::SELECTION_START_NEW);
1419 break;
1420 case IDS_MOVE_TO_BEGINNING_OF_LINE_AND_EXTEND_SELECTION:
1421 model_->MoveCursor(gfx::LINE_BREAK, begin, true, gfx::SELECTION_EXTEND);
1422 break;
1423 case IDS_MOVE_TOWARDS_BEGINNING_OF_LINE_AND_MODIFY_SELECTION:
1424 model_->MoveCursor(gfx::LINE_BREAK, begin, true, gfx::SELECTION_CARET);
1406 break; 1425 break;
1407 case IDS_MOVE_TO_END_OF_LINE: 1426 case IDS_MOVE_TO_END_OF_LINE:
1408 model_->MoveCursor(gfx::LINE_BREAK, end, false); 1427 model_->MoveCursor(gfx::LINE_BREAK, end, false);
1409 break; 1428 break;
1410 case IDS_MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: 1429 case IDS_MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION:
1411 model_->MoveCursor(gfx::LINE_BREAK, end, true); 1430 model_->MoveCursor(gfx::LINE_BREAK, end, true, gfx::SELECTION_START_NEW);
1431 break;
1432 case IDS_MOVE_TO_END_OF_LINE_AND_EXTEND_SELECTION:
1433 model_->MoveCursor(gfx::LINE_BREAK, end, true, gfx::SELECTION_EXTEND);
1434 break;
1435 case IDS_MOVE_TOWARDS_END_OF_LINE_AND_MODIFY_SELECTION:
1436 model_->MoveCursor(gfx::LINE_BREAK, end, true, gfx::SELECTION_CARET);
1412 break; 1437 break;
1413 default: 1438 default:
1414 NOTREACHED(); 1439 NOTREACHED();
1415 break; 1440 break;
1416 } 1441 }
1417 1442
1418 cursor_changed |= GetSelectionModel() != selection_model; 1443 cursor_changed |= GetSelectionModel() != selection_model;
1419 if (cursor_changed) 1444 if (cursor_changed)
1420 UpdateSelectionClipboard(); 1445 UpdateSelectionClipboard();
1421 UpdateAfterChange(text_changed, cursor_changed); 1446 UpdateAfterChange(text_changed, cursor_changed);
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 RequestFocus(); 1954 RequestFocus();
1930 model_->MoveCursorTo(mouse); 1955 model_->MoveCursorTo(mouse);
1931 if (!selection_clipboard_text.empty()) { 1956 if (!selection_clipboard_text.empty()) {
1932 model_->InsertText(selection_clipboard_text); 1957 model_->InsertText(selection_clipboard_text);
1933 UpdateAfterChange(true, true); 1958 UpdateAfterChange(true, true);
1934 } 1959 }
1935 OnAfterUserAction(); 1960 OnAfterUserAction();
1936 } 1961 }
1937 1962
1938 } // namespace views 1963 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698