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" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 SetContextMenuController(this); | 79 SetContextMenuController(this); |
80 } | 80 } |
81 | 81 |
82 NativeTextfieldViews::~NativeTextfieldViews() { | 82 NativeTextfieldViews::~NativeTextfieldViews() { |
83 } | 83 } |
84 | 84 |
85 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
86 // NativeTextfieldViews, View overrides: | 86 // NativeTextfieldViews, View overrides: |
87 | 87 |
88 bool NativeTextfieldViews::OnMousePressed(const views::MouseEvent& e) { | 88 bool NativeTextfieldViews::OnMousePressed(const views::MouseEvent& event) { |
89 OnBeforeUserAction(); | 89 OnBeforeUserAction(); |
90 if (HandleMousePressed(e)) | 90 if (HandleMousePressed(event)) |
91 SchedulePaint(); | 91 SchedulePaint(); |
92 OnAfterUserAction(); | 92 OnAfterUserAction(); |
93 return true; | 93 return true; |
94 } | 94 } |
95 | 95 |
96 bool NativeTextfieldViews::OnMouseDragged(const views::MouseEvent& e) { | 96 bool NativeTextfieldViews::OnMouseDragged(const views::MouseEvent& event) { |
97 OnBeforeUserAction(); | 97 OnBeforeUserAction(); |
98 size_t pos = FindCursorPosition(e.location()); | 98 size_t pos = FindCursorPosition(event.location()); |
99 if (model_->MoveCursorTo(pos, true)) { | 99 if (model_->MoveCursorTo(pos, true)) { |
100 UpdateCursorBoundsAndTextOffset(); | 100 UpdateCursorBoundsAndTextOffset(); |
101 SchedulePaint(); | 101 SchedulePaint(); |
102 } | 102 } |
103 OnAfterUserAction(); | 103 OnAfterUserAction(); |
104 return true; | 104 return true; |
105 } | 105 } |
106 | 106 |
107 void NativeTextfieldViews::OnMouseReleased(const views::MouseEvent& e, | 107 bool NativeTextfieldViews::OnKeyPressed(const views::KeyEvent& event) { |
108 bool canceled) { | |
109 } | |
110 | |
111 bool NativeTextfieldViews::OnKeyPressed(const views::KeyEvent& e) { | |
112 // OnKeyPressed/OnKeyReleased/OnFocus/OnBlur will never be invoked on | 108 // OnKeyPressed/OnKeyReleased/OnFocus/OnBlur will never be invoked on |
113 // NativeTextfieldViews as it will never gain focus. | 109 // NativeTextfieldViews as it will never gain focus. |
114 NOTREACHED(); | 110 NOTREACHED(); |
115 return false; | 111 return false; |
116 } | 112 } |
117 | 113 |
118 bool NativeTextfieldViews::OnKeyReleased(const views::KeyEvent& e) { | 114 bool NativeTextfieldViews::OnKeyReleased(const views::KeyEvent& event) { |
119 NOTREACHED(); | 115 NOTREACHED(); |
120 return false; | 116 return false; |
121 } | 117 } |
122 | 118 |
123 void NativeTextfieldViews::OnPaint(gfx::Canvas* canvas) { | 119 void NativeTextfieldViews::OnPaint(gfx::Canvas* canvas) { |
124 text_border_->set_has_focus(textfield_->HasFocus()); | 120 text_border_->set_has_focus(textfield_->HasFocus()); |
125 OnPaintBackground(canvas); | 121 OnPaintBackground(canvas); |
126 PaintTextAndCursor(canvas); | 122 PaintTextAndCursor(canvas); |
127 if (textfield_->draw_border()) | 123 if (textfield_->draw_border()) |
128 OnPaintBorder(canvas); | 124 OnPaintBorder(canvas); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 456 |
461 if (full_width < width) { | 457 if (full_width < width) { |
462 // Show all text whenever the text fits to the size. | 458 // Show all text whenever the text fits to the size. |
463 text_offset_ = 0; | 459 text_offset_ = 0; |
464 } else if (x_right > width) { | 460 } else if (x_right > width) { |
465 // when the cursor overflows to the right | 461 // when the cursor overflows to the right |
466 text_offset_ = width - cursor_bounds_.right(); | 462 text_offset_ = width - cursor_bounds_.right(); |
467 } else if (x_left < 0) { | 463 } else if (x_left < 0) { |
468 // when the cursor overflows to the left | 464 // when the cursor overflows to the left |
469 text_offset_ = -cursor_bounds_.x(); | 465 text_offset_ = -cursor_bounds_.x(); |
470 } else if(full_width > width && text_offset_ + full_width < width) { | 466 } else if (full_width > width && text_offset_ + full_width < width) { |
471 // when the cursor moves within the textfield with the text | 467 // when the cursor moves within the textfield with the text |
472 // longer than the field. | 468 // longer than the field. |
473 text_offset_ = width - full_width; | 469 text_offset_ = width - full_width; |
474 } else { | 470 } else { |
475 // move cursor freely. | 471 // move cursor freely. |
476 } | 472 } |
477 // shift cursor bounds to fit insets. | 473 // shift cursor bounds to fit insets. |
478 cursor_bounds_.set_x(cursor_bounds_.x() + text_offset_ + insets.left()); | 474 cursor_bounds_.set_x(cursor_bounds_.x() + text_offset_ + insets.left()); |
479 } | 475 } |
480 | 476 |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 } | 818 } |
823 | 819 |
824 void NativeTextfieldViews::TextfieldBorder::SetInsets(int top, | 820 void NativeTextfieldViews::TextfieldBorder::SetInsets(int top, |
825 int left, | 821 int left, |
826 int bottom, | 822 int bottom, |
827 int right) { | 823 int right) { |
828 insets_.Set(top, left, bottom, right); | 824 insets_.Set(top, left, bottom, right); |
829 } | 825 } |
830 | 826 |
831 } // namespace views | 827 } // namespace views |
OLD | NEW |