Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / WebSelection.cpp
blob8791a5835fe6223d11b5d03fafd21807a3d3564f
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.
5 #include "config.h"
7 #include "public/web/WebSelection.h"
9 #include "core/editing/SelectionType.h"
10 #include "core/layout/compositing/CompositedSelection.h"
12 namespace blink {
14 static WebSelectionBound getWebSelectionBound(const CompositedSelection& selection, bool isStart)
16 ASSERT(selection.type != NoSelection);
17 const CompositedSelectionBound& bound = isStart ? selection.start : selection.end;
18 ASSERT(bound.layer);
20 WebSelectionBound::Type type = WebSelectionBound::Caret;
21 if (selection.type == RangeSelection) {
22 if (isStart)
23 type = bound.isTextDirectionRTL ? WebSelectionBound::SelectionRight : WebSelectionBound::SelectionLeft;
24 else
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;
33 return result;
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)
49 , m_end(other.m_end)
50 , m_isEditable(other.m_isEditable)
51 , m_isEmptyTextFormControl(other.m_isEmptyTextFormControl)
55 } // namespace blink