Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4763)

Unified Diff: Source/web/WebSelection.cpp

Issue 929213004: Plumb selection bounds as a single unit (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix test Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/web/WebSelection.cpp
diff --git a/Source/web/WebSelection.cpp b/Source/web/WebSelection.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f7764239049c84a2ea1c8ad5315d3c41f5dc4d48
--- /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_isEmptyTextFormControl(selection.isEmptyTextFormControl)
+{
+}
+
+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_isEmptyTextFormControl(other.m_isEmptyTextFormControl)
+{
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698