OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 159 |
160 void NativeTextfieldViews::OnGestureEvent(ui::GestureEvent* event) { | 160 void NativeTextfieldViews::OnGestureEvent(ui::GestureEvent* event) { |
161 textfield_->OnGestureEvent(event); | 161 textfield_->OnGestureEvent(event); |
162 if (event->handled()) | 162 if (event->handled()) |
163 return; | 163 return; |
164 | 164 |
165 switch (event->type()) { | 165 switch (event->type()) { |
166 case ui::ET_GESTURE_TAP_DOWN: | 166 case ui::ET_GESTURE_TAP_DOWN: |
167 OnBeforeUserAction(); | 167 OnBeforeUserAction(); |
168 textfield_->RequestFocus(); | 168 textfield_->RequestFocus(); |
| 169 ShowImeIfNeeded(); |
169 // We don't deselect if the point is in the selection | 170 // We don't deselect if the point is in the selection |
170 // because TAP_DOWN may turn into a LONG_PRESS. | 171 // because TAP_DOWN may turn into a LONG_PRESS. |
171 if (!GetRenderText()->IsPointInSelection(event->location()) && | 172 if (!GetRenderText()->IsPointInSelection(event->location()) && |
172 MoveCursorTo(event->location(), false)) | 173 MoveCursorTo(event->location(), false)) |
173 SchedulePaint(); | 174 SchedulePaint(); |
174 OnAfterUserAction(); | 175 OnAfterUserAction(); |
175 event->SetHandled(); | 176 event->SetHandled(); |
176 break; | 177 break; |
177 case ui::ET_GESTURE_SCROLL_UPDATE: | 178 case ui::ET_GESTURE_SCROLL_UPDATE: |
178 OnBeforeUserAction(); | 179 OnBeforeUserAction(); |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 | 604 |
604 void NativeTextfieldViews::UpdateVerticalMargins() { | 605 void NativeTextfieldViews::UpdateVerticalMargins() { |
605 int top, bottom; | 606 int top, bottom; |
606 if (!textfield_->GetVerticalMargins(&top, &bottom)) | 607 if (!textfield_->GetVerticalMargins(&top, &bottom)) |
607 return; | 608 return; |
608 gfx::Insets inset = GetInsets(); | 609 gfx::Insets inset = GetInsets(); |
609 text_border_->SetInsets(top, inset.left(), bottom, inset.right()); | 610 text_border_->SetInsets(top, inset.left(), bottom, inset.right()); |
610 OnBoundsChanged(GetBounds()); | 611 OnBoundsChanged(GetBounds()); |
611 } | 612 } |
612 | 613 |
| 614 void NativeTextfieldViews::ShowImeIfNeeded() const { |
| 615 GetInputMethod()->ShowImeIfNeeded(); |
| 616 } |
| 617 |
613 bool NativeTextfieldViews::IsIMEComposing() const { | 618 bool NativeTextfieldViews::IsIMEComposing() const { |
614 return model_->HasCompositionText(); | 619 return model_->HasCompositionText(); |
615 } | 620 } |
616 | 621 |
617 const gfx::Range& NativeTextfieldViews::GetSelectedRange() const { | 622 const gfx::Range& NativeTextfieldViews::GetSelectedRange() const { |
618 return GetRenderText()->selection(); | 623 return GetRenderText()->selection(); |
619 } | 624 } |
620 | 625 |
621 void NativeTextfieldViews::SelectRange(const gfx::Range& range) { | 626 void NativeTextfieldViews::SelectRange(const gfx::Range& range) { |
622 model_->SelectRange(range); | 627 model_->SelectRange(range); |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 aggregated_clicks_ = (aggregated_clicks_ % 2) + 1; | 1442 aggregated_clicks_ = (aggregated_clicks_ % 2) + 1; |
1438 } else { | 1443 } else { |
1439 aggregated_clicks_ = 0; | 1444 aggregated_clicks_ = 0; |
1440 } | 1445 } |
1441 last_click_time_ = event.time_stamp(); | 1446 last_click_time_ = event.time_stamp(); |
1442 last_click_location_ = event.location(); | 1447 last_click_location_ = event.location(); |
1443 } | 1448 } |
1444 } | 1449 } |
1445 | 1450 |
1446 void NativeTextfieldViews::HandleMousePressEvent(const ui::MouseEvent& event) { | 1451 void NativeTextfieldViews::HandleMousePressEvent(const ui::MouseEvent& event) { |
1447 if (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) | 1452 if (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) { |
1448 textfield_->RequestFocus(); | 1453 textfield_->RequestFocus(); |
| 1454 ShowImeIfNeeded(); |
| 1455 } |
1449 | 1456 |
1450 if (!event.IsOnlyLeftMouseButton()) | 1457 if (!event.IsOnlyLeftMouseButton()) |
1451 return; | 1458 return; |
1452 | 1459 |
1453 initiating_drag_ = false; | 1460 initiating_drag_ = false; |
1454 bool can_drag = true; | 1461 bool can_drag = true; |
1455 | 1462 |
1456 switch (aggregated_clicks_) { | 1463 switch (aggregated_clicks_) { |
1457 case 0: | 1464 case 0: |
1458 if (can_drag && GetRenderText()->IsPointInSelection(event.location())) | 1465 if (can_drag && GetRenderText()->IsPointInSelection(event.location())) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 if (index != -1) { | 1526 if (index != -1) { |
1520 obscured_reveal_timer_.Start( | 1527 obscured_reveal_timer_.Start( |
1521 FROM_HERE, | 1528 FROM_HERE, |
1522 duration, | 1529 duration, |
1523 base::Bind(&NativeTextfieldViews::RevealObscuredChar, | 1530 base::Bind(&NativeTextfieldViews::RevealObscuredChar, |
1524 base::Unretained(this), -1, base::TimeDelta())); | 1531 base::Unretained(this), -1, base::TimeDelta())); |
1525 } | 1532 } |
1526 } | 1533 } |
1527 | 1534 |
1528 } // namespace views | 1535 } // namespace views |
OLD | NEW |