Chromium Code Reviews| Index: views/controls/textfield/native_textfield_views.cc |
| diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc |
| index 07725fffba6e7513e1f4288c3917505fb99ddf15..cf35c247b8e88e00cf76d15abd9aa4b5bf618eb1 100644 |
| --- a/views/controls/textfield/native_textfield_views.cc |
| +++ b/views/controls/textfield/native_textfield_views.cc |
| @@ -95,44 +95,13 @@ NativeTextfieldViews::~NativeTextfieldViews() { |
| bool NativeTextfieldViews::OnMousePressed(const MouseEvent& event) { |
| OnBeforeUserAction(); |
| - textfield_->RequestFocus(); |
| + TrackMouseClicks(event); |
| - if (event.IsOnlyLeftMouseButton()) { |
| - base::TimeDelta time_delta = event.time_stamp() - last_click_time_; |
| - gfx::Point location_delta = event.location().Subtract(last_click_location_); |
| - if (time_delta.InMilliseconds() <= GetDoubleClickInterval() && |
| - !ExceededDragThreshold(location_delta.x(), location_delta.y())) { |
| - aggregated_clicks_ = (aggregated_clicks_ + 1) % 3; |
| - } else { |
| - aggregated_clicks_ = 0; |
| - } |
| - last_click_time_ = event.time_stamp(); |
| - last_click_location_ = event.location(); |
| - |
| - initiating_drag_ = false; |
| - bool can_drag = true; |
| -#if defined(TOUCH_UI) |
| - can_drag = false; |
| -#endif |
| - switch(aggregated_clicks_) { |
| - case 0: |
| - if (can_drag && GetRenderText()->IsPointInSelection(event.location())) |
| - initiating_drag_ = true; |
| - else |
| - MoveCursorTo(event.location(), event.IsShiftDown()); |
| - break; |
| - case 1: |
| - model_->SelectWord(); |
| - OnCaretBoundsChanged(); |
| - break; |
| - case 2: |
| - model_->SelectAll(); |
| - OnCaretBoundsChanged(); |
| - break; |
| - default: |
| - NOTREACHED(); |
| - } |
| - SchedulePaint(); |
| + // Allow the textfield/omnibox to optionally handle the mouse pressed event. |
| + // This should be removed once native textfield implementations are |
| + // consolidated to textfield. |
| + if (!textfield_->OnMousePressed(event)) { |
| + HandleMousePressEvent(event); |
| } |
|
oshima
2011/11/14 19:31:09
nuke {}
jennyz
2011/11/14 19:50:14
Done.
|
| OnAfterUserAction(); |
| @@ -1065,6 +1034,53 @@ bool NativeTextfieldViews::Paste() { |
| return success; |
| } |
| +void NativeTextfieldViews::TrackMouseClicks(const MouseEvent& event) { |
| + if (event.IsOnlyLeftMouseButton()) { |
| + base::TimeDelta time_delta = event.time_stamp() - last_click_time_; |
| + gfx::Point location_delta = event.location().Subtract(last_click_location_); |
| + if (time_delta.InMilliseconds() <= GetDoubleClickInterval() && |
| + !ExceededDragThreshold(location_delta.x(), location_delta.y())) { |
| + aggregated_clicks_ = (aggregated_clicks_ + 1) % 3; |
| + } else { |
| + aggregated_clicks_ = 0; |
| + } |
| + last_click_time_ = event.time_stamp(); |
| + last_click_location_ = event.location(); |
| + } |
| +} |
| + |
| +void NativeTextfieldViews::HandleMousePressEvent(const MouseEvent& event) { |
| + if (event.IsOnlyLeftMouseButton()) { |
| + textfield_->RequestFocus(); |
| + |
| + initiating_drag_ = false; |
| + bool can_drag = true; |
| +#if defined(TOUCH_UI) |
| + // Temporarily disable drag and drop on touch builds; see crbug.com/97845. |
| + can_drag = false; |
| +#endif |
| + switch(aggregated_clicks_) { |
| + case 0: |
| + if (can_drag && GetRenderText()->IsPointInSelection(event.location())) |
| + initiating_drag_ = true; |
| + else |
| + MoveCursorTo(event.location(), event.IsShiftDown()); |
| + break; |
| + case 1: |
| + model_->SelectWord(); |
| + OnCaretBoundsChanged(); |
| + break; |
| + case 2: |
| + model_->SelectAll(); |
| + OnCaretBoundsChanged(); |
| + break; |
| + default: |
| + NOTREACHED(); |
| + } |
| + SchedulePaint(); |
| + } |
| +} |
| + |
| // static |
| bool NativeTextfieldViews::ShouldInsertChar(char16 ch, int flags) { |
| // Filter out all control characters, including tab and new line characters, |