Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/selection_controller.h" | 5 #include "ui/views/selection_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
| 10 #include "ui/gfx/render_text.h" | 10 #include "ui/gfx/render_text.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 delegate_->SetTextBeingDragged(true); | 49 delegate_->SetTextBeingDragged(true); |
| 50 } else { | 50 } else { |
| 51 delegate_->OnBeforePointerAction(); | 51 delegate_->OnBeforePointerAction(); |
| 52 const bool selection_changed = | 52 const bool selection_changed = |
| 53 render_text->MoveCursorTo(event.location(), event.IsShiftDown()); | 53 render_text->MoveCursorTo(event.location(), event.IsShiftDown()); |
| 54 delegate_->OnAfterPointerAction(false, selection_changed); | 54 delegate_->OnAfterPointerAction(false, selection_changed); |
| 55 } | 55 } |
| 56 break; | 56 break; |
| 57 case 1: | 57 case 1: |
| 58 // Select the word at the click location on a double click. | 58 // Select the word at the click location on a double click. |
| 59 delegate_->OnBeforePointerAction(); | 59 SelectWord(event.location()); |
| 60 render_text->MoveCursorTo(event.location(), false); | |
| 61 render_text->SelectWord(); | |
| 62 delegate_->OnAfterPointerAction(false, true); | |
| 63 double_click_word_ = render_text->selection(); | 60 double_click_word_ = render_text->selection(); |
| 64 break; | 61 break; |
| 65 case 2: | 62 case 2: |
| 66 // Select all the text on a triple click. | 63 // Select all the text on a triple click. |
| 67 delegate_->OnBeforePointerAction(); | 64 delegate_->OnBeforePointerAction(); |
| 68 render_text->SelectAll(false); | 65 render_text->SelectAll(false); |
| 69 delegate_->OnAfterPointerAction(false, true); | 66 delegate_->OnAfterPointerAction(false, true); |
| 70 break; | 67 break; |
| 71 default: | 68 default: |
| 72 NOTREACHED(); | 69 NOTREACHED(); |
| 73 } | 70 } |
| 74 } | 71 } |
| 75 | 72 |
| 73 const bool select_word_on_right_click = | |
| 74 event.IsOnlyRightMouseButton() && | |
| 75 PlatformStyle::kSelectWordOnRightClick && | |
| 76 !render_text->IsPointInSelection(event.location()); | |
| 77 if (select_word_on_right_click) | |
| 78 SelectWord(event.location()); | |
|
tapted
2016/12/19 06:49:16
There's another NSTextField behaviour related to t
karandeepb
2016/12/19 07:05:43
Yeah had pointed this out in the comment with the
tapted
2016/12/20 00:12:42
I couldn't find this comment - can you send me a l
karandeepb
2016/12/21 14:20:02
I was referring to the comment with the initial PT
| |
| 79 | |
| 76 if (handles_selection_clipboard_ && event.IsOnlyMiddleMouseButton()) { | 80 if (handles_selection_clipboard_ && event.IsOnlyMiddleMouseButton()) { |
| 77 if (render_text->IsPointInSelection(event.location())) { | 81 if (render_text->IsPointInSelection(event.location())) { |
| 78 delegate_->OnBeforePointerAction(); | 82 delegate_->OnBeforePointerAction(); |
| 79 render_text->ClearSelection(); | 83 render_text->ClearSelection(); |
| 80 delegate_->UpdateSelectionClipboard(); | 84 delegate_->UpdateSelectionClipboard(); |
| 81 delegate_->OnAfterPointerAction(false, true); | 85 delegate_->OnAfterPointerAction(false, true); |
| 82 } else if (!delegate_->IsReadOnly()) { | 86 } else if (!delegate_->IsReadOnly()) { |
| 83 delegate_->OnBeforePointerAction(); | 87 delegate_->OnBeforePointerAction(); |
| 84 const bool selection_changed = | 88 const bool selection_changed = |
| 85 render_text->MoveCursorTo(event.location(), false); | 89 render_text->MoveCursorTo(event.location(), false); |
| 86 const bool text_changed = delegate_->PasteSelectionClipboard(); | 90 const bool text_changed = delegate_->PasteSelectionClipboard(); |
| 87 delegate_->OnAfterPointerAction(text_changed, | 91 delegate_->OnAfterPointerAction(text_changed, |
| 88 selection_changed | text_changed); | 92 selection_changed | text_changed); |
| 89 } | 93 } |
| 90 } | 94 } |
| 91 | 95 |
| 92 return true; | 96 return true; |
| 93 } | 97 } |
| 94 | 98 |
| 99 void SelectionController::SelectWord(const gfx::Point& point) { | |
| 100 gfx::RenderText* render_text = GetRenderText(); | |
| 101 DCHECK(render_text); | |
| 102 delegate_->OnBeforePointerAction(); | |
| 103 render_text->MoveCursorTo(point, false); | |
| 104 render_text->SelectWord(); | |
| 105 delegate_->OnAfterPointerAction(false, true); | |
| 106 } | |
| 107 | |
| 95 bool SelectionController::OnMouseDragged(const ui::MouseEvent& event) { | 108 bool SelectionController::OnMouseDragged(const ui::MouseEvent& event) { |
| 96 DCHECK(GetRenderText()); | 109 DCHECK(GetRenderText()); |
| 97 // If |drag_selection_timer_| is running, |last_drag_location_| will be used | 110 // If |drag_selection_timer_| is running, |last_drag_location_| will be used |
| 98 // to update the selection. | 111 // to update the selection. |
| 99 last_drag_location_ = event.location(); | 112 last_drag_location_ = event.location(); |
| 100 | 113 |
| 101 // Don't adjust the cursor on a potential drag and drop. | 114 // Don't adjust the cursor on a potential drag and drop. |
| 102 if (delegate_->HasTextBeingDragged() || !event.IsOnlyLeftMouseButton()) | 115 if (delegate_->HasTextBeingDragged() || !event.IsOnlyLeftMouseButton()) |
| 103 return true; | 116 return true; |
| 104 | 117 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 std::max(selection.GetMax(), double_click_word_.GetMax()); | 217 std::max(selection.GetMax(), double_click_word_.GetMax()); |
| 205 const bool reversed = selection.is_reversed(); | 218 const bool reversed = selection.is_reversed(); |
| 206 selection.set_start(reversed ? max : min); | 219 selection.set_start(reversed ? max : min); |
| 207 selection.set_end(reversed ? min : max); | 220 selection.set_end(reversed ? min : max); |
| 208 render_text->SelectRange(selection); | 221 render_text->SelectRange(selection); |
| 209 } | 222 } |
| 210 delegate_->OnAfterPointerAction(false, true); | 223 delegate_->OnAfterPointerAction(false, true); |
| 211 } | 224 } |
| 212 | 225 |
| 213 } // namespace views | 226 } // namespace views |
| OLD | NEW |