Commit 0108cbbc authored by Hikaru Nishida's avatar Hikaru Nishida Committed by Commit Bot

Introduce ConvertFromWebSelectionBoundType() to refactor

ConvertFromWebSelectionBound()

Before this patch, cc_bound.type is computed using is_start and
web_bound.is_text_direction_rtl. This is redundant because
WebSelectionBound has .type which is computed in the same way in
GetWebSelectionBound() at WebSelection.cpp. is_start and
is_text_direction_rtl is exactly the same value used in both functions
so we can convert kSelectionLeft to LEFT, kSelectionRight to RIGHT
and kCaret to CENTER (default value).
Therefore, we can introduce ConvertFromWebSelectionBoundType()
which directly converts from blink::WebSelectionBound::Type to
gfx::SelectionBound::Type and refactor ConvertFromWebSelectionBound()
with it.
This patch also renames ConvertWebSelectionBound() to
ConvertFromWebSelectionBound() to clarify what type is input.

See also: crrev.com/c/934106

TEST: No change in behavior.

Change-Id: I3cbc4af607438841be6e2b47e10d12deaa273aa3
Reviewed-on: https://chromium-review.googlesource.com/942585Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarEric Karl <ericrk@chromium.org>
Commit-Queue: Hikaru Nishida <hikarun@google.com>
Cr-Commit-Position: refs/heads/master@{#543967}
parent 6390f257
......@@ -190,39 +190,37 @@ bool GetSwitchValueAsInt(const base::CommandLine& command_line,
}
}
cc::LayerSelectionBound ConvertWebSelectionBound(
const WebSelection& web_selection,
bool is_start) {
gfx::SelectionBound::Type ConvertFromWebSelectionBoundType(
blink::WebSelectionBound::Type type) {
if (type == blink::WebSelectionBound::Type::kSelectionLeft)
return gfx::SelectionBound::Type::LEFT;
if (type == blink::WebSelectionBound::Type::kSelectionRight)
return gfx::SelectionBound::Type::RIGHT;
// if WebSelection is not a range (caret or none),
// The type of gfx::SelectionBound should be CENTER.
DCHECK_EQ(type, blink::WebSelectionBound::Type::kCaret);
return gfx::SelectionBound::Type::CENTER;
}
cc::LayerSelectionBound ConvertFromWebSelectionBound(
const blink::WebSelectionBound& bound) {
cc::LayerSelectionBound cc_bound;
if (web_selection.IsNone())
return cc_bound;
const blink::WebSelectionBound& web_bound =
is_start ? web_selection.Start() : web_selection.end();
DCHECK(web_bound.layer_id);
cc_bound.type = gfx::SelectionBound::CENTER;
if (web_selection.IsRange()) {
if (is_start) {
cc_bound.type = web_bound.is_text_direction_rtl
? gfx::SelectionBound::RIGHT
: gfx::SelectionBound::LEFT;
} else {
cc_bound.type = web_bound.is_text_direction_rtl
? gfx::SelectionBound::LEFT
: gfx::SelectionBound::RIGHT;
}
}
cc_bound.layer_id = web_bound.layer_id;
cc_bound.edge_top = gfx::Point(web_bound.edge_top_in_layer);
cc_bound.edge_bottom = gfx::Point(web_bound.edge_bottom_in_layer);
cc_bound.hidden = web_bound.hidden;
DCHECK(bound.layer_id);
cc_bound.type = ConvertFromWebSelectionBoundType(bound.type);
cc_bound.layer_id = bound.layer_id;
cc_bound.edge_top = gfx::Point(bound.edge_top_in_layer);
cc_bound.edge_bottom = gfx::Point(bound.edge_bottom_in_layer);
cc_bound.hidden = bound.hidden;
return cc_bound;
}
cc::LayerSelection ConvertWebSelection(const WebSelection& web_selection) {
cc::LayerSelection ConvertFromWebSelection(const WebSelection& web_selection) {
if (web_selection.IsNone())
return cc::LayerSelection();
cc::LayerSelection cc_selection;
cc_selection.start = ConvertWebSelectionBound(web_selection, true);
cc_selection.end = ConvertWebSelectionBound(web_selection, false);
cc_selection.start = ConvertFromWebSelectionBound(web_selection.Start());
cc_selection.end = ConvertFromWebSelectionBound(web_selection.end());
return cc_selection;
}
......@@ -910,7 +908,7 @@ void RenderWidgetCompositor::ClearViewportLayers() {
void RenderWidgetCompositor::RegisterSelection(
const blink::WebSelection& selection) {
layer_tree_host_->RegisterSelection(ConvertWebSelection(selection));
layer_tree_host_->RegisterSelection(ConvertFromWebSelection(selection));
}
void RenderWidgetCompositor::ClearSelection() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment