Commit 85c10dcb authored by Zhuoyu Qian's avatar Zhuoyu Qian Committed by Commit Bot

Move FirstRectForRange() to VisibleUnits.

Move FirstRectForRange() to VisibleUnits, make |Editor| class simpler
for improving code health.

BUG=672405
Signed-off-by: default avatarZhuoyu Qian <zhuoyu.qian@samsung.com>
Change-Id: Iaca3148ba5a6f186a7870ede3ef59e0ddf4078bd
Reviewed-on: https://chromium-review.googlesource.com/938888Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539765}
parent 01cf9081
...@@ -923,45 +923,6 @@ void Editor::ChangeSelectionAfterCommand( ...@@ -923,45 +923,6 @@ void Editor::ChangeSelectionAfterCommand(
} }
} }
IntRect Editor::FirstRectForRange(const EphemeralRange& range) const {
DCHECK(!GetFrame().GetDocument()->NeedsLayoutTreeUpdate());
DocumentLifecycle::DisallowTransitionScope disallow_transition(
GetFrame().GetDocument()->Lifecycle());
LayoutUnit extra_width_to_end_of_line;
DCHECK(range.IsNotNull());
const PositionWithAffinity start_position(
CreateVisiblePosition(range.StartPosition()).DeepEquivalent(),
TextAffinity::kDownstream);
const IntRect start_caret_rect =
AbsoluteCaretRectOfPosition(start_position, &extra_width_to_end_of_line);
if (start_caret_rect.IsEmpty())
return IntRect();
const PositionWithAffinity end_position(
CreateVisiblePosition(range.EndPosition()).DeepEquivalent(),
TextAffinity::kUpstream);
const IntRect end_caret_rect = AbsoluteCaretRectOfPosition(end_position);
if (end_caret_rect.IsEmpty())
return IntRect();
if (start_caret_rect.Y() == end_caret_rect.Y()) {
// start and end are on the same line
return IntRect(
std::min(start_caret_rect.X(), end_caret_rect.X()),
start_caret_rect.Y(), abs(end_caret_rect.X() - start_caret_rect.X()),
std::max(start_caret_rect.Height(), end_caret_rect.Height()));
}
// start and end aren't on the same line, so go from start to the end of its
// line
return IntRect(
start_caret_rect.X(), start_caret_rect.Y(),
(start_caret_rect.Width() + extra_width_to_end_of_line).ToInt(),
start_caret_rect.Height());
}
EphemeralRange Editor::RangeForPoint(const IntPoint& frame_point) const { EphemeralRange Editor::RangeForPoint(const IntPoint& frame_point) const {
const PositionWithAffinity position_with_affinity = const PositionWithAffinity position_with_affinity =
GetFrame().PositionForPoint(frame_point); GetFrame().PositionForPoint(frame_point);
......
...@@ -220,8 +220,6 @@ class CORE_EXPORT Editor final : public GarbageCollectedFinalized<Editor> { ...@@ -220,8 +220,6 @@ class CORE_EXPORT Editor final : public GarbageCollectedFinalized<Editor> {
void ComputeAndSetTypingStyle(CSSPropertyValueSet*, InputEvent::InputType); void ComputeAndSetTypingStyle(CSSPropertyValueSet*, InputEvent::InputType);
// |firstRectForRange| requires up-to-date layout.
IntRect FirstRectForRange(const EphemeralRange&) const;
EphemeralRange RangeForPoint(const IntPoint&) const; EphemeralRange RangeForPoint(const IntPoint&) const;
void RespondToChangedSelection(); void RespondToChangedSelection();
......
...@@ -538,10 +538,8 @@ bool FrameSelection::ComputeAbsoluteBounds(IntRect& anchor, ...@@ -538,10 +538,8 @@ bool FrameSelection::ComputeAbsoluteBounds(IntRect& anchor,
ComputeVisibleSelectionInDOMTree().ToNormalizedEphemeralRange(); ComputeVisibleSelectionInDOMTree().ToNormalizedEphemeralRange();
if (selected_range.IsNull()) if (selected_range.IsNull())
return false; return false;
anchor = frame_->GetEditor().FirstRectForRange( anchor = FirstRectForRange(EphemeralRange(selected_range.StartPosition()));
EphemeralRange(selected_range.StartPosition())); focus = FirstRectForRange(EphemeralRange(selected_range.EndPosition()));
focus = frame_->GetEditor().FirstRectForRange(
EphemeralRange(selected_range.EndPosition()));
} }
if (!ComputeVisibleSelectionInDOMTree().IsBaseFirst()) if (!ComputeVisibleSelectionInDOMTree().IsBaseFirst())
......
...@@ -1514,4 +1514,43 @@ FloatRect ComputeTextFloatRect(const EphemeralRange& range) { ...@@ -1514,4 +1514,43 @@ FloatRect ComputeTextFloatRect(const EphemeralRange& range) {
return ComputeTextRectTemplate(range); return ComputeTextRectTemplate(range);
} }
IntRect FirstRectForRange(const EphemeralRange& range) {
DCHECK(!range.GetDocument().NeedsLayoutTreeUpdate());
DocumentLifecycle::DisallowTransitionScope disallow_transition(
range.GetDocument().Lifecycle());
LayoutUnit extra_width_to_end_of_line;
DCHECK(range.IsNotNull());
const PositionWithAffinity start_position(
CreateVisiblePosition(range.StartPosition()).DeepEquivalent(),
TextAffinity::kDownstream);
const IntRect start_caret_rect =
AbsoluteCaretRectOfPosition(start_position, &extra_width_to_end_of_line);
if (start_caret_rect.IsEmpty())
return IntRect();
const PositionWithAffinity end_position(
CreateVisiblePosition(range.EndPosition()).DeepEquivalent(),
TextAffinity::kUpstream);
const IntRect end_caret_rect = AbsoluteCaretRectOfPosition(end_position);
if (end_caret_rect.IsEmpty())
return IntRect();
if (start_caret_rect.Y() == end_caret_rect.Y()) {
// start and end are on the same line
return IntRect(
std::min(start_caret_rect.X(), end_caret_rect.X()),
start_caret_rect.Y(), abs(end_caret_rect.X() - start_caret_rect.X()),
std::max(start_caret_rect.Height(), end_caret_rect.Height()));
}
// start and end aren't on the same line, so go from start to the end of its
// line
return IntRect(
start_caret_rect.X(), start_caret_rect.Y(),
(start_caret_rect.Width() + extra_width_to_end_of_line).ToInt(),
start_caret_rect.Height());
}
} // namespace blink } // namespace blink
...@@ -281,6 +281,9 @@ CORE_EXPORT IntRect ComputeTextRect(const EphemeralRange&); ...@@ -281,6 +281,9 @@ CORE_EXPORT IntRect ComputeTextRect(const EphemeralRange&);
IntRect ComputeTextRect(const EphemeralRangeInFlatTree&); IntRect ComputeTextRect(const EphemeralRangeInFlatTree&);
FloatRect ComputeTextFloatRect(const EphemeralRange&); FloatRect ComputeTextFloatRect(const EphemeralRange&);
// |FirstRectForRange| requires up-to-date layout.
IntRect FirstRectForRange(const EphemeralRange&);
// Export below functions only for |VisibleUnit| family. // Export below functions only for |VisibleUnit| family.
enum BoundarySearchContextAvailability { enum BoundarySearchContextAvailability {
kDontHaveMoreContext, kDontHaveMoreContext,
......
...@@ -1022,7 +1022,7 @@ bool WebLocalFrameImpl::FirstRectForCharacterRange( ...@@ -1022,7 +1022,7 @@ bool WebLocalFrameImpl::FirstRectForCharacterRange(
PlainTextRange(location, location + length).CreateRange(*editable); PlainTextRange(location, location + length).CreateRange(*editable);
if (range.IsNull()) if (range.IsNull())
return false; return false;
IntRect int_rect = GetFrame()->GetEditor().FirstRectForRange(range); IntRect int_rect = FirstRectForRange(range);
rect_in_viewport = WebRect(int_rect); rect_in_viewport = WebRect(int_rect);
rect_in_viewport = GetFrame()->View()->ContentsToViewport(rect_in_viewport); rect_in_viewport = GetFrame()->View()->ContentsToViewport(rect_in_viewport);
return true; return true;
......
...@@ -1874,9 +1874,9 @@ WebInputEventResult EventHandler::ShowNonLocatedContextMenu( ...@@ -1874,9 +1874,9 @@ WebInputEventResult EventHandler::ShowNonLocatedContextMenu(
if (!override_target_element && ShouldShowContextMenuAtSelection(selection)) { if (!override_target_element && ShouldShowContextMenuAtSelection(selection)) {
DCHECK(!doc->NeedsLayoutTreeUpdate()); DCHECK(!doc->NeedsLayoutTreeUpdate());
IntRect first_rect = frame_->GetEditor().FirstRectForRange( IntRect first_rect =
selection.ComputeVisibleSelectionInDOMTree() FirstRectForRange(selection.ComputeVisibleSelectionInDOMTree()
.ToNormalizedEphemeralRange()); .ToNormalizedEphemeralRange());
int x = right_aligned ? first_rect.MaxX() : first_rect.X(); int x = right_aligned ? first_rect.MaxX() : first_rect.X();
// In a multiline edit, firstRect.maxY() would end up on the next line, so // In a multiline edit, firstRect.maxY() would end up on the next line, so
......
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