Commit f36f8d73 authored by Orin Jaworski's avatar Orin Jaworski Committed by Commit Bot

[omnibox] Replaced insertion drop cursor with replacement outline.

The drop cursor at a particular text location implies dropped text will
be inserted there, and that remains true when dragging selected text
from within omnibox itself (existing edit behavior remains intact).
But when dragging text from elsewhere (no omnibox text selected), the
new behavior will outline omnibox text indicating that the drop will
replace current text.  Drop cursor logic remains the same, only the
meaning of the drop is indicated with a more intuitive render effect.

Bug: 329319
Change-Id: I8aa76a497f857c0c418b9bdd7a350a597169165c
Reviewed-on: https://chromium-review.googlesource.com/1091297
Commit-Queue: Orin Jaworski <orinj@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566664}
parent 5f3d5c18
......@@ -413,6 +413,15 @@ bool OmniboxViewViews::ShouldDoLearning() {
return location_bar_view_ && !location_bar_view_->profile()->IsOffTheRecord();
}
bool OmniboxViewViews::IsDropCursorForInsertion() const {
// Dragging text from within omnibox itself will behave like text input
// editor, showing insertion-style drop cursor as usual;
// but dragging text from outside omnibox will replace entire contents with
// paste-and-go behavior, so returning false in that case prevents the
// confusing insertion-style drop cursor.
return HasTextBeingDragged();
}
void OmniboxViewViews::SetTextAndSelectedRange(const base::string16& text,
const gfx::Range& range) {
SetText(text);
......
......@@ -122,6 +122,9 @@ class OmniboxViewViews : public OmniboxView,
return popup_view_.get();
}
// views::Textfield:
bool IsDropCursorForInsertion() const override;
private:
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, CloseOmniboxPopupOnTextDrag);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, FriendlyAccessibleLabel);
......
......@@ -929,6 +929,10 @@ SelectionModel RenderText::GetSelectionModelForSelectionStart() const {
sel.is_reversed() ? CURSOR_BACKWARD : CURSOR_FORWARD);
}
RectF RenderText::GetStringRect() {
return RectF(PointF(ToViewPoint(Point())), GetStringSizeF());
}
const Vector2d& RenderText::GetUpdatedDisplayOffset() {
UpdateCachedBoundsAndOffset();
return display_offset_;
......
......@@ -27,6 +27,7 @@
#include "ui/gfx/font_render_params.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/range/range.h"
......@@ -490,6 +491,9 @@ class GFX_EXPORT RenderText {
// chosen.
virtual std::vector<FontSpan> GetFontSpansForTesting() = 0;
// Returns rectangle surrounding the current string (from origin to size)
RectF GetStringRect();
// Get the visual bounds containing the logical substring within the |range|.
// If |range| is empty, the result is empty. These bounds could be visually
// discontinuous if the substring is split by a LTR/RTL level change.
......
......@@ -463,7 +463,9 @@ class RenderTextTest : public testing::Test,
Rect GetSubstringBoundsUnion(const Range& range) {
const std::vector<Rect> bounds = render_text_->GetSubstringBounds(range);
return std::accumulate(bounds.begin(), bounds.end(), Rect(), UnionRects);
return std::accumulate(
bounds.begin(), bounds.end(), Rect(),
[](const Rect& a, const Rect& b) { return UnionRects(a, b); });
}
Rect GetSelectionBoundsUnion() {
......
......@@ -1984,6 +1984,10 @@ void Textfield::OffsetDoubleClickWord(int offset) {
selection_controller_.OffsetDoubleClickWord(offset);
}
bool Textfield::IsDropCursorForInsertion() const {
return true;
}
////////////////////////////////////////////////////////////////////////////////
// Textfield, private:
......@@ -2156,10 +2160,16 @@ void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) {
render_text->display_rect(), placeholder_text_draw_flags);
}
if (drop_cursor_visible_ && !IsDropCursorForInsertion()) {
// Mark the entire text that will be replaced by the drop.
canvas->FillRect(ToEnclosedRect(render_text->GetStringRect()),
GetSelectionBackgroundColor());
}
render_text->Draw(canvas);
// Draw the detached drop cursor that marks where the text will be dropped.
if (drop_cursor_visible_) {
if (drop_cursor_visible_ && IsDropCursorForInsertion()) {
// Draw a drop cursor that marks where the text will be dropped/inserted.
canvas->FillRect(render_text->GetCursorBounds(drop_cursor_position_, true),
GetTextColor());
}
......
......@@ -387,6 +387,11 @@ class VIEWS_EXPORT Textfield : public View,
// This is harmless if there is not a currently double-clicked word.
void OffsetDoubleClickWord(int offset);
// Returns true if the drop cursor is for insertion at a target text location,
// the standard behavior/style. Returns false when drop will do something
// else (like replace the text entirely).
virtual bool IsDropCursorForInsertion() const;
private:
friend class TextfieldTestApi;
......
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