Index: Source/web/WebSelection.cpp |
diff --git a/Source/web/WebSelection.cpp b/Source/web/WebSelection.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..97a61f9155d43a1005ff81add2a303f8a99c91d1 |
--- /dev/null |
+++ b/Source/web/WebSelection.cpp |
@@ -0,0 +1,57 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+ |
+#include "public/web/WebSelection.h" |
+ |
+#include "core/editing/SelectionType.h" |
+#include "core/layout/compositing/CompositedSelection.h" |
+ |
+namespace blink { |
+ |
+static WebSelectionBound getWebSelectionBound(const CompositedSelection& selection, bool isBase) |
+{ |
+ ASSERT(selection.type != NoSelection); |
+ const CompositedSelectionBound& bound = isBase ? selection.base : selection.extent; |
+ ASSERT(bound.layer); |
+ |
+ WebSelectionBound::Type type = WebSelectionBound::Caret; |
+ if (selection.type == RangeSelection) { |
+ if ((isBase && selection.isBaseFirst) || (!isBase && !selection.isBaseFirst)) |
+ type = bound.isTextDirectionRTL ? WebSelectionBound::SelectionRight : WebSelectionBound::SelectionLeft; |
+ else |
+ type = bound.isTextDirectionRTL ? WebSelectionBound::SelectionLeft : WebSelectionBound::SelectionRight; |
+ } |
+ |
+ WebSelectionBound result(type); |
+ result.layerId = bound.layer->platformLayer()->id(); |
+ result.edgeTopInLayer = roundedIntPoint(bound.edgeTopInLayer); |
+ result.edgeBottomInLayer = roundedIntPoint(bound.edgeBottomInLayer); |
+ result.isTextDirectionRTL = bound.isTextDirectionRTL; |
+ return result; |
+} |
+ |
+// SelectionType enums have the same values; enforced in AssertMatchingEnums.cpp. |
+WebSelection::WebSelection(const CompositedSelection& selection) |
+ : m_selectionType(static_cast<WebSelection::SelectionType>(selection.type)) |
+ , m_base(getWebSelectionBound(selection, true)) |
+ , m_extent(getWebSelectionBound(selection, false)) |
+ , m_isBaseFirst(selection.isBaseFirst) |
+ , m_isEditable(selection.isEditable) |
+ , m_isEditableRegionEmpty(selection.isEditableRegionEmpty) |
+{ |
+} |
+ |
+WebSelection::WebSelection(const WebSelection& other) |
+ : m_selectionType(other.m_selectionType) |
+ , m_base(other.m_base) |
+ , m_extent(other.m_extent) |
+ , m_isBaseFirst(other.m_isBaseFirst) |
+ , m_isEditable(other.m_isEditable) |
+ , m_isEditableRegionEmpty(other.m_isEditableRegionEmpty) |
+{ |
+} |
+ |
+} // namespace blink |