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

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: TODO for moving WebSelectionBound Created 5 years, 8 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
« no previous file with comments | « Source/web/ChromeClientImpl.cpp ('k') | Source/web/WebViewImpl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/WebSelection.cpp
diff --git a/Source/web/WebSelection.cpp b/Source/web/WebSelection.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8791a5835fe6223d11b5d03fafd21807a3d3564f
--- /dev/null
+++ b/Source/web/WebSelection.cpp
@@ -0,0 +1,55 @@
+// 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 isStart)
+{
+ ASSERT(selection.type != NoSelection);
+ const CompositedSelectionBound& bound = isStart ? selection.start : selection.end;
+ ASSERT(bound.layer);
+
+ WebSelectionBound::Type type = WebSelectionBound::Caret;
+ if (selection.type == RangeSelection) {
+ if (isStart)
+ 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_start(getWebSelectionBound(selection, true))
+ , m_end(getWebSelectionBound(selection, false))
+ , m_isEditable(selection.isEditable)
+ , m_isEmptyTextFormControl(selection.isEmptyTextFormControl)
+{
+}
+
+WebSelection::WebSelection(const WebSelection& other)
+ : m_selectionType(other.m_selectionType)
+ , m_start(other.m_start)
+ , m_end(other.m_end)
+ , m_isEditable(other.m_isEditable)
+ , m_isEmptyTextFormControl(other.m_isEmptyTextFormControl)
+{
+}
+
+} // namespace blink
« no previous file with comments | « Source/web/ChromeClientImpl.cpp ('k') | Source/web/WebViewImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698