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

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

Issue 2729133005: Fix: Cursor missing in omnibox after entering a alphabet in NTP 'Search box' (Closed)
Patch Set: add tests Created 3 years, 9 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
« no previous file with comments | « no previous file | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 default: 762 default:
763 return; 763 return;
764 } 764 }
765 } 765 }
766 766
767 // This function is called by BrowserView to execute clipboard commands. 767 // This function is called by BrowserView to execute clipboard commands.
768 bool Textfield::AcceleratorPressed(const ui::Accelerator& accelerator) { 768 bool Textfield::AcceleratorPressed(const ui::Accelerator& accelerator) {
769 ui::KeyEvent event(accelerator.type(), accelerator.key_code(), 769 ui::KeyEvent event(accelerator.type(), accelerator.key_code(),
770 accelerator.modifiers()); 770 accelerator.modifiers());
771 ExecuteTextEditCommand(GetCommandForKeyEvent(event)); 771 ExecuteTextEditCommand(GetCommandForKeyEvent(event));
772 UpdateAfterChange(false, true);
sadrul 2017/03/08 02:02:52 We shouldn't need this here? ExecuteTextEditComman
yiyix 2017/03/08 03:32:41 ExecuteTextEditCommand first calls OmniboxViewView
sadrul 2017/03/08 13:45:36 OK. So it looks like there *are* some cases where
772 return true; 773 return true;
773 } 774 }
774 775
775 bool Textfield::CanHandleAccelerators() const { 776 bool Textfield::CanHandleAccelerators() const {
776 return GetRenderText()->focused() && View::CanHandleAccelerators(); 777 return GetRenderText()->focused() && View::CanHandleAccelerators();
777 } 778 }
778 779
779 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) { 780 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) {
780 SelectAll(false); 781 SelectAll(false);
781 } 782 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 // Adjust the drop destination if it is on or after the current selection. 877 // Adjust the drop destination if it is on or after the current selection.
877 size_t pos = drop_destination_model.caret_pos(); 878 size_t pos = drop_destination_model.caret_pos();
878 pos -= render_text->selection().Intersect(gfx::Range(0, pos)).length(); 879 pos -= render_text->selection().Intersect(gfx::Range(0, pos)).length();
879 model_->DeleteSelectionAndInsertTextAt(new_text, pos); 880 model_->DeleteSelectionAndInsertTextAt(new_text, pos);
880 } else { 881 } else {
881 model_->MoveCursorTo(drop_destination_model); 882 model_->MoveCursorTo(drop_destination_model);
882 // Drop always inserts text even if the textfield is not in insert mode. 883 // Drop always inserts text even if the textfield is not in insert mode.
883 model_->InsertText(new_text); 884 model_->InsertText(new_text);
884 } 885 }
885 skip_input_method_cancel_composition_ = false; 886 skip_input_method_cancel_composition_ = false;
887 OnAfterUserAction();
886 UpdateAfterChange(true, true); 888 UpdateAfterChange(true, true);
887 OnAfterUserAction();
888 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY; 889 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY;
889 } 890 }
890 891
891 void Textfield::OnDragDone() { 892 void Textfield::OnDragDone() {
892 initiating_drag_ = false; 893 initiating_drag_ = false;
893 drop_cursor_visible_ = false; 894 drop_cursor_visible_ = false;
894 } 895 }
895 896
896 void Textfield::GetAccessibleNodeData(ui::AXNodeData* node_data) { 897 void Textfield::GetAccessibleNodeData(ui::AXNodeData* node_data) {
897 node_data->role = ui::AX_ROLE_TEXT_FIELD; 898 node_data->role = ui::AX_ROLE_TEXT_FIELD;
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 // Textfield, ui::TextInputClient overrides: 1257 // Textfield, ui::TextInputClient overrides:
1257 1258
1258 void Textfield::SetCompositionText(const ui::CompositionText& composition) { 1259 void Textfield::SetCompositionText(const ui::CompositionText& composition) {
1259 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) 1260 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE)
1260 return; 1261 return;
1261 1262
1262 OnBeforeUserAction(); 1263 OnBeforeUserAction();
1263 skip_input_method_cancel_composition_ = true; 1264 skip_input_method_cancel_composition_ = true;
1264 model_->SetCompositionText(composition); 1265 model_->SetCompositionText(composition);
1265 skip_input_method_cancel_composition_ = false; 1266 skip_input_method_cancel_composition_ = false;
1267 OnAfterUserAction();
1266 UpdateAfterChange(true, true); 1268 UpdateAfterChange(true, true);
1267 OnAfterUserAction();
1268 } 1269 }
1269 1270
1270 void Textfield::ConfirmCompositionText() { 1271 void Textfield::ConfirmCompositionText() {
1271 if (!model_->HasCompositionText()) 1272 if (!model_->HasCompositionText())
1272 return; 1273 return;
1273 1274
1274 OnBeforeUserAction(); 1275 OnBeforeUserAction();
1275 skip_input_method_cancel_composition_ = true; 1276 skip_input_method_cancel_composition_ = true;
1276 model_->ConfirmCompositionText(); 1277 model_->ConfirmCompositionText();
1277 skip_input_method_cancel_composition_ = false; 1278 skip_input_method_cancel_composition_ = false;
1279 OnAfterUserAction();
1278 UpdateAfterChange(true, true); 1280 UpdateAfterChange(true, true);
1279 OnAfterUserAction();
1280 } 1281 }
1281 1282
1282 void Textfield::ClearCompositionText() { 1283 void Textfield::ClearCompositionText() {
1283 if (!model_->HasCompositionText()) 1284 if (!model_->HasCompositionText())
1284 return; 1285 return;
1285 1286
1286 OnBeforeUserAction(); 1287 OnBeforeUserAction();
1287 skip_input_method_cancel_composition_ = true; 1288 skip_input_method_cancel_composition_ = true;
1288 model_->CancelCompositionText(); 1289 model_->CancelCompositionText();
1289 skip_input_method_cancel_composition_ = false; 1290 skip_input_method_cancel_composition_ = false;
1291 OnAfterUserAction();
1290 UpdateAfterChange(true, true); 1292 UpdateAfterChange(true, true);
1291 OnAfterUserAction();
1292 } 1293 }
1293 1294
1294 void Textfield::InsertText(const base::string16& new_text) { 1295 void Textfield::InsertText(const base::string16& new_text) {
1295 // TODO(suzhe): Filter invalid characters. 1296 // TODO(suzhe): Filter invalid characters.
1296 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE || new_text.empty()) 1297 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE || new_text.empty())
1297 return; 1298 return;
1298 1299
1299 OnBeforeUserAction(); 1300 OnBeforeUserAction();
1300 skip_input_method_cancel_composition_ = true; 1301 skip_input_method_cancel_composition_ = true;
1301 model_->InsertText(new_text); 1302 model_->InsertText(new_text);
1302 skip_input_method_cancel_composition_ = false; 1303 skip_input_method_cancel_composition_ = false;
1304 OnAfterUserAction();
1303 UpdateAfterChange(true, true); 1305 UpdateAfterChange(true, true);
1304 OnAfterUserAction();
1305 } 1306 }
1306 1307
1307 void Textfield::InsertChar(const ui::KeyEvent& event) { 1308 void Textfield::InsertChar(const ui::KeyEvent& event) {
1308 if (read_only()) { 1309 if (read_only()) {
1309 OnEditFailed(); 1310 OnEditFailed();
1310 return; 1311 return;
1311 } 1312 }
1312 1313
1313 // Filter out all control characters, including tab and new line characters, 1314 // Filter out all control characters, including tab and new line characters,
1314 // and all characters with Alt modifier (and Search on ChromeOS, Ctrl on 1315 // and all characters with Alt modifier (and Search on ChromeOS, Ctrl on
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 1577
1577 //////////////////////////////////////////////////////////////////////////////// 1578 ////////////////////////////////////////////////////////////////////////////////
1578 // Textfield, protected: 1579 // Textfield, protected:
1579 1580
1580 void Textfield::DoInsertChar(base::char16 ch) { 1581 void Textfield::DoInsertChar(base::char16 ch) {
1581 OnBeforeUserAction(); 1582 OnBeforeUserAction();
1582 skip_input_method_cancel_composition_ = true; 1583 skip_input_method_cancel_composition_ = true;
1583 model_->InsertChar(ch); 1584 model_->InsertChar(ch);
1584 skip_input_method_cancel_composition_ = false; 1585 skip_input_method_cancel_composition_ = false;
1585 1586
1587 OnAfterUserAction();
1586 UpdateAfterChange(true, true); 1588 UpdateAfterChange(true, true);
1587 OnAfterUserAction();
1588 } 1589 }
1589 1590
1590 gfx::RenderText* Textfield::GetRenderText() const { 1591 gfx::RenderText* Textfield::GetRenderText() const {
1591 return model_->render_text(); 1592 return model_->render_text();
1592 } 1593 }
1593 1594
1594 gfx::Point Textfield::GetLastClickLocation() const { 1595 gfx::Point Textfield::GetLastClickLocation() const {
1595 return selection_controller_.last_click_location(); 1596 return selection_controller_.last_click_location();
1596 } 1597 }
1597 1598
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 case ui::TextEditCommand::SET_MARK: 1789 case ui::TextEditCommand::SET_MARK:
1789 case ui::TextEditCommand::UNSELECT: 1790 case ui::TextEditCommand::UNSELECT:
1790 case ui::TextEditCommand::INVALID_COMMAND: 1791 case ui::TextEditCommand::INVALID_COMMAND:
1791 NOTREACHED(); 1792 NOTREACHED();
1792 break; 1793 break;
1793 } 1794 }
1794 1795
1795 cursor_changed |= GetSelectionModel() != selection_model; 1796 cursor_changed |= GetSelectionModel() != selection_model;
1796 if (cursor_changed && HasSelection()) 1797 if (cursor_changed && HasSelection())
1797 UpdateSelectionClipboard(); 1798 UpdateSelectionClipboard();
1799 OnAfterUserAction();
1798 UpdateAfterChange(text_changed, cursor_changed); 1800 UpdateAfterChange(text_changed, cursor_changed);
1799 OnAfterUserAction();
1800 } 1801 }
1801 1802
1802 //////////////////////////////////////////////////////////////////////////////// 1803 ////////////////////////////////////////////////////////////////////////////////
1803 // Textfield, private: 1804 // Textfield, private:
1804 1805
1805 //////////////////////////////////////////////////////////////////////////////// 1806 ////////////////////////////////////////////////////////////////////////////////
1806 // Textfield, SelectionControllerDelegate overrides: 1807 // Textfield, SelectionControllerDelegate overrides:
1807 1808
1808 gfx::RenderText* Textfield::GetRenderTextForSelectionController() { 1809 gfx::RenderText* Textfield::GetRenderTextForSelectionController() {
1809 return GetRenderText(); 1810 return GetRenderText();
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2086 cursor_blink_timer_.Stop(); 2087 cursor_blink_timer_.Stop();
2087 } 2088 }
2088 2089
2089 void Textfield::OnCursorBlinkTimerFired() { 2090 void Textfield::OnCursorBlinkTimerFired() {
2090 DCHECK(ShouldBlinkCursor()); 2091 DCHECK(ShouldBlinkCursor());
2091 cursor_view_.SetVisible(!cursor_view_.visible()); 2092 cursor_view_.SetVisible(!cursor_view_.visible());
2092 UpdateCursorView(); 2093 UpdateCursorView();
2093 } 2094 }
2094 2095
2095 } // namespace views 2096 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698