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 "config.h" |
| 6 |
| 7 #include "public/web/WebSelection.h" |
| 8 |
| 9 #include "core/editing/SelectionType.h" |
| 10 #include "core/layout/compositing/CompositedSelection.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 static WebSelectionBound getWebSelectionBound(const CompositedSelection& selecti
on, bool isBase) |
| 15 { |
| 16 ASSERT(selection.type != NoSelection); |
| 17 const CompositedSelectionBound& bound = isBase ? selection.base : selection.
extent; |
| 18 ASSERT(bound.layer); |
| 19 |
| 20 WebSelectionBound::Type type = WebSelectionBound::Caret; |
| 21 if (selection.type == RangeSelection) { |
| 22 if ((isBase && selection.isBaseFirst) || (!isBase && !selection.isBaseFi
rst)) |
| 23 type = bound.isTextDirectionRTL ? WebSelectionBound::SelectionRight
: WebSelectionBound::SelectionLeft; |
| 24 else |
| 25 type = bound.isTextDirectionRTL ? WebSelectionBound::SelectionLeft :
WebSelectionBound::SelectionRight; |
| 26 } |
| 27 |
| 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; |
| 34 } |
| 35 |
| 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_base(getWebSelectionBound(selection, true)) |
| 40 , m_extent(getWebSelectionBound(selection, false)) |
| 41 , m_isBaseFirst(selection.isBaseFirst) |
| 42 , m_isEditable(selection.isEditable) |
| 43 , m_isEditableRegionEmpty(selection.isEditableRegionEmpty) |
| 44 { |
| 45 } |
| 46 |
| 47 WebSelection::WebSelection(const WebSelection& other) |
| 48 : m_selectionType(other.m_selectionType) |
| 49 , m_base(other.m_base) |
| 50 , m_extent(other.m_extent) |
| 51 , m_isBaseFirst(other.m_isBaseFirst) |
| 52 , m_isEditable(other.m_isEditable) |
| 53 , m_isEditableRegionEmpty(other.m_isEditableRegionEmpty) |
| 54 { |
| 55 } |
| 56 |
| 57 } // namespace blink |
OLD | NEW |