| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 gfx::RenderText* SelectionController::GetRenderText() { | 174 gfx::RenderText* SelectionController::GetRenderText() { |
| 175 return delegate_->GetRenderTextForSelectionController(); | 175 return delegate_->GetRenderTextForSelectionController(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void SelectionController::SelectThroughLastDragLocation() { | 178 void SelectionController::SelectThroughLastDragLocation() { |
| 179 gfx::RenderText* render_text = GetRenderText(); | 179 gfx::RenderText* render_text = GetRenderText(); |
| 180 DCHECK(render_text); | 180 DCHECK(render_text); |
| 181 | 181 |
| 182 delegate_->OnBeforePointerAction(); | 182 delegate_->OnBeforePointerAction(); |
| 183 | 183 |
| 184 // TODO(karandeepb): See if this can be handled at the RenderText level. | 184 render_text->MoveCursorTo(last_drag_location_, true); |
| 185 const bool drags_to_end = PlatformStyle::kTextDragVerticallyDragsToEnd; | |
| 186 if (drags_to_end && last_drag_location_.y() < 0) { | |
| 187 render_text->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, | |
| 188 gfx::SELECTION_RETAIN); | |
| 189 } else if (drags_to_end && | |
| 190 last_drag_location_.y() > delegate_->GetViewHeight()) { | |
| 191 render_text->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, | |
| 192 gfx::SELECTION_RETAIN); | |
| 193 } else { | |
| 194 render_text->MoveCursorTo(last_drag_location_, true); | |
| 195 } | |
| 196 | 185 |
| 197 if (aggregated_clicks_ == 1) { | 186 if (aggregated_clicks_ == 1) { |
| 198 render_text->SelectWord(); | 187 render_text->SelectWord(); |
| 199 // Expand the selection so the initially selected word remains selected. | 188 // Expand the selection so the initially selected word remains selected. |
| 200 gfx::Range selection = render_text->selection(); | 189 gfx::Range selection = render_text->selection(); |
| 201 const size_t min = | 190 const size_t min = |
| 202 std::min(selection.GetMin(), double_click_word_.GetMin()); | 191 std::min(selection.GetMin(), double_click_word_.GetMin()); |
| 203 const size_t max = | 192 const size_t max = |
| 204 std::max(selection.GetMax(), double_click_word_.GetMax()); | 193 std::max(selection.GetMax(), double_click_word_.GetMax()); |
| 205 const bool reversed = selection.is_reversed(); | 194 const bool reversed = selection.is_reversed(); |
| 206 selection.set_start(reversed ? max : min); | 195 selection.set_start(reversed ? max : min); |
| 207 selection.set_end(reversed ? min : max); | 196 selection.set_end(reversed ? min : max); |
| 208 render_text->SelectRange(selection); | 197 render_text->SelectRange(selection); |
| 209 } | 198 } |
| 210 delegate_->OnAfterPointerAction(false, true); | 199 delegate_->OnAfterPointerAction(false, true); |
| 211 } | 200 } |
| 212 | 201 |
| 213 } // namespace views | 202 } // namespace views |
| OLD | NEW |