summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-06 10:59:41 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-06 10:59:41 +0000
commit0089360438b9cbbb36779c3eacf436f20ab85209 (patch)
tree33a35c408c7e597ab97c23429f1d96d8dfb13186
parent27c179e4e4a6567ea60a91dbc28d555474c18b0d (diff)
downloadchromium_src-0089360438b9cbbb36779c3eacf436f20ab85209.zip
chromium_src-0089360438b9cbbb36779c3eacf436f20ab85209.tar.gz
chromium_src-0089360438b9cbbb36779c3eacf436f20ab85209.tar.bz2
Clip Views textfield drag images to selected text.
Paint views::Textfield drag images with views::Labels. Makes the drag image fit the size of the selected text. (not as wide as the origin Omnibox/textfield itself) Use an offset for the image similar to the Unity desktop. This changes the appearance of split-selection BiDi text. (doesn't show blank area between the visually split text) See before/after pictures at http://crbug.com/349105 Remove now unused RenderText::DrawSelectedTextForDrag. BUG=349105 TEST=Linux Aura and ChromeOS text drag images look good. R=sky@chromium.org Review URL: https://codereview.chromium.org/177683005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255310 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views.cc2
-rw-r--r--ui/gfx/render_text.cc23
-rw-r--r--ui/gfx/render_text.h4
-rw-r--r--ui/views/controls/textfield/textfield.cc62
4 files changed, 37 insertions, 54 deletions
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index bd87afa..dca4245 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -868,10 +868,10 @@ void OmniboxViewViews::OnGetDragOperationsForTextfield(int* drag_operations) {
}
void OmniboxViewViews::OnWriteDragData(ui::OSExchangeData* data) {
- base::string16 selected_text = GetSelectedText();
GURL url;
bool write_url;
bool is_all_selected = IsSelectAll();
+ base::string16 selected_text = GetSelectedText();
model()->AdjustTextForCopy(GetSelectedRange().GetMin(), is_all_selected,
&selected_text, &url, &write_url);
data->SetString(selected_text);
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 0e5bfd2..ca87aa4 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -718,29 +718,6 @@ void RenderText::DrawCursor(Canvas* canvas, const SelectionModel& position) {
canvas->FillRect(GetCursorBounds(position, true), cursor_color_);
}
-void RenderText::DrawSelectedTextForDrag(Canvas* canvas) {
- EnsureLayout();
- const std::vector<Rect> sel = GetSubstringBounds(selection());
-
- // Override the selection color with black, and force the background to be
- // transparent so that it's rendered without subpixel antialiasing.
- const bool saved_background_is_transparent = background_is_transparent();
- const SkColor saved_selection_color = selection_color();
- set_background_is_transparent(true);
- set_selection_color(SK_ColorBLACK);
-
- for (size_t i = 0; i < sel.size(); ++i) {
- canvas->Save();
- canvas->ClipRect(sel[i]);
- DrawVisualText(canvas);
- canvas->Restore();
- }
-
- // Restore saved transparency and selection color.
- set_selection_color(saved_selection_color);
- set_background_is_transparent(saved_background_is_transparent);
-}
-
Rect RenderText::GetCursorBounds(const SelectionModel& caret,
bool insert_mode) {
// TODO(ckocagil): Support multiline. This function should return the height
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
index 7af9743..9ae2e54 100644
--- a/ui/gfx/render_text.h
+++ b/ui/gfx/render_text.h
@@ -349,10 +349,6 @@ class GFX_EXPORT RenderText {
// Draws a cursor at |position|.
void DrawCursor(Canvas* canvas, const SelectionModel& position);
- // Draw the selected text without a cursor or selection highlight. Subpixel
- // antialiasing is disabled and foreground color is forced to black.
- void DrawSelectedTextForDrag(Canvas* canvas);
-
// Gets the SelectionModel from a visual point in local coordinates.
virtual SelectionModel FindCursorPosition(const Point& point) = 0;
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index 94888d7..8442b7c 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -18,10 +18,13 @@
#include "ui/events/event.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/display.h"
#include "ui/gfx/insets.h"
+#include "ui/gfx/screen.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/background.h"
#include "ui/views/controls/focusable_border.h"
+#include "ui/views/controls/label.h"
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/native/native_view_host.h"
@@ -37,23 +40,23 @@
#include "base/win/win_util.h"
#endif
+namespace views {
+
namespace {
// Default placeholder text color.
const SkColor kDefaultPlaceholderTextColor = SK_ColorLTGRAY;
-void ConvertRectToScreen(const views::View* src, gfx::Rect* r) {
+void ConvertRectToScreen(const View* src, gfx::Rect* r) {
DCHECK(src);
gfx::Point new_origin = r->origin();
- views::View::ConvertPointToScreen(src, &new_origin);
+ View::ConvertPointToScreen(src, &new_origin);
r->set_origin(new_origin);
}
} // namespace
-namespace views {
-
// static
const char Textfield::kViewClassName[] = "Textfield";
@@ -827,40 +830,47 @@ void Textfield::OnCompositionTextConfirmedOrCleared() {
////////////////////////////////////////////////////////////////////////////////
// Textfield, ContextMenuController overrides:
-void Textfield::ShowContextMenuForView(
- View* source,
- const gfx::Point& point,
- ui::MenuSourceType source_type) {
+void Textfield::ShowContextMenuForView(View* source,
+ const gfx::Point& point,
+ ui::MenuSourceType source_type) {
UpdateContextMenu();
- if (context_menu_runner_->RunMenuAt(GetWidget(), NULL,
- gfx::Rect(point, gfx::Size()), views::MenuItemView::TOPLEFT,
- source_type,
- MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) ==
- MenuRunner::MENU_DELETED)
- return;
+ ignore_result(context_menu_runner_->RunMenuAt(GetWidget(), NULL,
+ gfx::Rect(point, gfx::Size()), MenuItemView::TOPLEFT, source_type,
+ MenuRunner::HAS_MNEMONICS | MenuRunner::CONTEXT_MENU));
}
////////////////////////////////////////////////////////////////////////////////
-// Textfield, views::DragController overrides:
+// Textfield, DragController overrides:
-void Textfield::WriteDragDataForView(views::View* sender,
+void Textfield::WriteDragDataForView(View* sender,
const gfx::Point& press_pt,
OSExchangeData* data) {
- DCHECK_NE(ui::DragDropTypes::DRAG_NONE,
- GetDragOperationsForView(sender, press_pt));
- data->SetString(model_->GetSelectedText());
+ const base::string16& selected_text(GetSelectedText());
+ data->SetString(selected_text);
+ Label label(selected_text, GetFontList());
+ const SkColor background = GetBackgroundColor();
+ label.SetBackgroundColor(SkColorSetA(background, SK_AlphaTRANSPARENT));
+ gfx::Size size(label.GetPreferredSize());
+ gfx::NativeView native_view = GetWidget()->GetNativeView();
+ gfx::Display display = gfx::Screen::GetScreenFor(native_view)->
+ GetDisplayNearestWindow(native_view);
+ size.SetToMin(gfx::Size(display.size().width(), height()));
+ label.SetBoundsRect(gfx::Rect(size));
scoped_ptr<gfx::Canvas> canvas(
- views::GetCanvasForDragImage(GetWidget(), size()));
- GetRenderText()->DrawSelectedTextForDrag(canvas.get());
- drag_utils::SetDragImageOnDataObject(*canvas, size(),
- press_pt.OffsetFromOrigin(),
- data);
+ GetCanvasForDragImage(GetWidget(), label.size()));
+ label.SetEnabledColor(GetTextColor());
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+ // Desktop Linux Aura does not yet support transparency in drag images.
+ canvas->DrawColor(background);
+#endif
+ label.Paint(canvas.get());
+ const gfx::Vector2d kOffset(-15, 0);
+ drag_utils::SetDragImageOnDataObject(*canvas, label.size(), kOffset, data);
if (controller_)
controller_->OnWriteDragData(data);
}
-int Textfield::GetDragOperationsForView(views::View* sender,
- const gfx::Point& p) {
+int Textfield::GetDragOperationsForView(View* sender, const gfx::Point& p) {
int drag_operations = ui::DragDropTypes::DRAG_COPY;
if (!enabled() || text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD ||
!GetRenderText()->IsPointInSelection(p)) {