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.
7 #include "public/web/WebSelection.h"
9 #include "core/editing/SelectionType.h"
10 #include "core/layout/compositing/CompositedSelection.h"
14 static WebSelectionBound
getWebSelectionBound(const CompositedSelection
& selection
, bool isStart
)
16 ASSERT(selection
.type
!= NoSelection
);
17 const CompositedSelectionBound
& bound
= isStart
? selection
.start
: selection
.end
;
20 WebSelectionBound::Type type
= WebSelectionBound::Caret
;
21 if (selection
.type
== RangeSelection
) {
23 type
= bound
.isTextDirectionRTL
? WebSelectionBound::SelectionRight
: WebSelectionBound::SelectionLeft
;
25 type
= bound
.isTextDirectionRTL
? WebSelectionBound::SelectionLeft
: WebSelectionBound::SelectionRight
;
28 WebSelectionBound
result(type
);
29 result
.layerId
= bound
.layer
->platformLayer()->id();
30 result
.edgeTopInLayer
= roundedIntPoint(bound
.edgeTopInLayer
);
31 result
.edgeBottomInLayer
= roundedIntPoint(bound
.edgeBottomInLayer
);
32 result
.isTextDirectionRTL
= bound
.isTextDirectionRTL
;
36 // SelectionType enums have the same values; enforced in AssertMatchingEnums.cpp.
37 WebSelection::WebSelection(const CompositedSelection
& selection
)
38 : m_selectionType(static_cast<WebSelection::SelectionType
>(selection
.type
))
39 , m_start(getWebSelectionBound(selection
, true))
40 , m_end(getWebSelectionBound(selection
, false))
41 , m_isEditable(selection
.isEditable
)
42 , m_isEmptyTextFormControl(selection
.isEmptyTextFormControl
)
46 WebSelection::WebSelection(const WebSelection
& other
)
47 : m_selectionType(other
.m_selectionType
)
48 , m_start(other
.m_start
)
50 , m_isEditable(other
.m_isEditable
)
51 , m_isEmptyTextFormControl(other
.m_isEmptyTextFormControl
)