| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "public/web/WebSelection.h" | 5 #include "public/web/WebSelection.h" |
| 6 | 6 |
| 7 #include "core/editing/SelectionType.h" | 7 #include "core/editing/SelectionType.h" |
| 8 #include "core/layout/compositing/CompositedSelection.h" | 8 #include "core/layout/compositing/CompositedSelection.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 static WebSelectionBound GetWebSelectionBound( | 12 static WebSelectionBound GetWebSelectionBound( |
| 13 const CompositedSelection& selection, | 13 const CompositedSelection& selection, |
| 14 bool is_start) { | 14 bool is_start) { |
| 15 DCHECK_NE(selection.type, kNoSelection); | 15 DCHECK_NE(selection.type, kNoSelection); |
| 16 const CompositedSelectionBound& bound = | 16 const CompositedSelectionBound& bound = |
| 17 is_start ? selection.start : selection.end; | 17 is_start ? selection.start : selection.end; |
| 18 DCHECK(bound.layer); | 18 DCHECK(bound.layer); |
| 19 | 19 |
| 20 WebSelectionBound::Type type = WebSelectionBound::kCaret; | 20 WebSelectionBound::Type type = WebSelectionBound::kCaret; |
| 21 if (selection.type == kRangeSelection) { | 21 if (selection.type == kRangeSelection) { |
| 22 if (is_start) | 22 if (is_start) { |
| 23 type = bound.is_text_direction_rtl ? WebSelectionBound::kSelectionRight | 23 type = bound.is_text_direction_rtl ? WebSelectionBound::kSelectionRight |
| 24 : WebSelectionBound::kSelectionLeft; | 24 : WebSelectionBound::kSelectionLeft; |
| 25 else | 25 } else { |
| 26 type = bound.is_text_direction_rtl ? WebSelectionBound::kSelectionLeft | 26 type = bound.is_text_direction_rtl ? WebSelectionBound::kSelectionLeft |
| 27 : WebSelectionBound::kSelectionRight; | 27 : WebSelectionBound::kSelectionRight; |
| 28 } |
| 28 } | 29 } |
| 29 | 30 |
| 30 WebSelectionBound result(type); | 31 WebSelectionBound result(type); |
| 31 result.layer_id = bound.layer->PlatformLayer()->Id(); | 32 result.layer_id = bound.layer->PlatformLayer()->Id(); |
| 32 result.edge_top_in_layer = RoundedIntPoint(bound.edge_top_in_layer); | 33 result.edge_top_in_layer = RoundedIntPoint(bound.edge_top_in_layer); |
| 33 result.edge_bottom_in_layer = RoundedIntPoint(bound.edge_bottom_in_layer); | 34 result.edge_bottom_in_layer = RoundedIntPoint(bound.edge_bottom_in_layer); |
| 34 result.is_text_direction_rtl = bound.is_text_direction_rtl; | 35 result.is_text_direction_rtl = bound.is_text_direction_rtl; |
| 35 return result; | 36 return result; |
| 36 } | 37 } |
| 37 | 38 |
| 38 // SelectionType enums have the same values; enforced in | 39 // SelectionType enums have the same values; enforced in |
| 39 // AssertMatchingEnums.cpp. | 40 // AssertMatchingEnums.cpp. |
| 40 WebSelection::WebSelection(const CompositedSelection& selection) | 41 WebSelection::WebSelection(const CompositedSelection& selection) |
| 41 : selection_type_(static_cast<WebSelection::SelectionType>(selection.type)), | 42 : selection_type_(static_cast<WebSelection::SelectionType>(selection.type)), |
| 42 start_(GetWebSelectionBound(selection, true)), | 43 start_(GetWebSelectionBound(selection, true)), |
| 43 end_(GetWebSelectionBound(selection, false)) {} | 44 end_(GetWebSelectionBound(selection, false)) {} |
| 44 | 45 |
| 45 WebSelection::WebSelection(const WebSelection& other) | 46 WebSelection::WebSelection(const WebSelection& other) |
| 46 : selection_type_(other.selection_type_), | 47 : selection_type_(other.selection_type_), |
| 47 start_(other.start_), | 48 start_(other.start_), |
| 48 end_(other.end_) {} | 49 end_(other.end_) {} |
| 49 | 50 |
| 50 } // namespace blink | 51 } // namespace blink |
| OLD | NEW |