| 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 // TODO(crbug.com/676296): Right clicking an unfocused text view should select |
| 74 // all its text on Mac. |
| 75 const bool select_word_on_right_click = |
| 76 event.IsOnlyRightMouseButton() && |
| 77 PlatformStyle::kSelectWordOnRightClick && |
| 78 !render_text->IsPointInSelection(event.location()); |
| 79 if (select_word_on_right_click) |
| 80 SelectWord(event.location()); |
| 81 |
| 76 if (handles_selection_clipboard_ && event.IsOnlyMiddleMouseButton()) { | 82 if (handles_selection_clipboard_ && event.IsOnlyMiddleMouseButton()) { |
| 77 if (render_text->IsPointInSelection(event.location())) { | 83 if (render_text->IsPointInSelection(event.location())) { |
| 78 delegate_->OnBeforePointerAction(); | 84 delegate_->OnBeforePointerAction(); |
| 79 render_text->ClearSelection(); | 85 render_text->ClearSelection(); |
| 80 delegate_->UpdateSelectionClipboard(); | 86 delegate_->UpdateSelectionClipboard(); |
| 81 delegate_->OnAfterPointerAction(false, true); | 87 delegate_->OnAfterPointerAction(false, true); |
| 82 } else if (!delegate_->IsReadOnly()) { | 88 } else if (!delegate_->IsReadOnly()) { |
| 83 delegate_->OnBeforePointerAction(); | 89 delegate_->OnBeforePointerAction(); |
| 84 const bool selection_changed = | 90 const bool selection_changed = |
| 85 render_text->MoveCursorTo(event.location(), false); | 91 render_text->MoveCursorTo(event.location(), false); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // maps 0 to 1, 1 to 2, 2 to 1. | 170 // maps 0 to 1, 1 to 2, 2 to 1. |
| 165 aggregated_clicks_ = (aggregated_clicks_ % 2) + 1; | 171 aggregated_clicks_ = (aggregated_clicks_ % 2) + 1; |
| 166 } else { | 172 } else { |
| 167 aggregated_clicks_ = 0; | 173 aggregated_clicks_ = 0; |
| 168 } | 174 } |
| 169 last_click_time_ = event.time_stamp(); | 175 last_click_time_ = event.time_stamp(); |
| 170 last_click_location_ = event.location(); | 176 last_click_location_ = event.location(); |
| 171 } | 177 } |
| 172 } | 178 } |
| 173 | 179 |
| 180 void SelectionController::SelectWord(const gfx::Point& point) { |
| 181 gfx::RenderText* render_text = GetRenderText(); |
| 182 DCHECK(render_text); |
| 183 delegate_->OnBeforePointerAction(); |
| 184 render_text->MoveCursorTo(point, false); |
| 185 render_text->SelectWord(); |
| 186 delegate_->OnAfterPointerAction(false, true); |
| 187 } |
| 188 |
| 174 gfx::RenderText* SelectionController::GetRenderText() { | 189 gfx::RenderText* SelectionController::GetRenderText() { |
| 175 return delegate_->GetRenderTextForSelectionController(); | 190 return delegate_->GetRenderTextForSelectionController(); |
| 176 } | 191 } |
| 177 | 192 |
| 178 void SelectionController::SelectThroughLastDragLocation() { | 193 void SelectionController::SelectThroughLastDragLocation() { |
| 179 gfx::RenderText* render_text = GetRenderText(); | 194 gfx::RenderText* render_text = GetRenderText(); |
| 180 DCHECK(render_text); | 195 DCHECK(render_text); |
| 181 | 196 |
| 182 delegate_->OnBeforePointerAction(); | 197 delegate_->OnBeforePointerAction(); |
| 183 | 198 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 204 std::max(selection.GetMax(), double_click_word_.GetMax()); | 219 std::max(selection.GetMax(), double_click_word_.GetMax()); |
| 205 const bool reversed = selection.is_reversed(); | 220 const bool reversed = selection.is_reversed(); |
| 206 selection.set_start(reversed ? max : min); | 221 selection.set_start(reversed ? max : min); |
| 207 selection.set_end(reversed ? min : max); | 222 selection.set_end(reversed ? min : max); |
| 208 render_text->SelectRange(selection); | 223 render_text->SelectRange(selection); |
| 209 } | 224 } |
| 210 delegate_->OnAfterPointerAction(false, true); | 225 delegate_->OnAfterPointerAction(false, true); |
| 211 } | 226 } |
| 212 | 227 |
| 213 } // namespace views | 228 } // namespace views |
| OLD | NEW |