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