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

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 208313009: Fix the HTML5 drag and drop demos on Linux and CrOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "grit/ui_strings.h" 10 #include "grit/ui_strings.h"
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 MenuRunner::HAS_MNEMONICS | MenuRunner::CONTEXT_MENU)); 983 MenuRunner::HAS_MNEMONICS | MenuRunner::CONTEXT_MENU));
984 } 984 }
985 985
986 //////////////////////////////////////////////////////////////////////////////// 986 ////////////////////////////////////////////////////////////////////////////////
987 // Textfield, DragController overrides: 987 // Textfield, DragController overrides:
988 988
989 void Textfield::WriteDragDataForView(View* sender, 989 void Textfield::WriteDragDataForView(View* sender,
990 const gfx::Point& press_pt, 990 const gfx::Point& press_pt,
991 OSExchangeData* data) { 991 OSExchangeData* data) {
992 const base::string16& selected_text(GetSelectedText()); 992 const base::string16& selected_text(GetSelectedText());
993 data->SetString(selected_text);
994 Label label(selected_text, GetFontList()); 993 Label label(selected_text, GetFontList());
995 const SkColor background = GetBackgroundColor(); 994 const SkColor background = GetBackgroundColor();
996 label.SetBackgroundColor(SkColorSetA(background, SK_AlphaTRANSPARENT)); 995 label.SetBackgroundColor(SkColorSetA(background, SK_AlphaTRANSPARENT));
997 gfx::Size size(label.GetPreferredSize()); 996 gfx::Size size(label.GetPreferredSize());
998 gfx::NativeView native_view = GetWidget()->GetNativeView(); 997 gfx::NativeView native_view = GetWidget()->GetNativeView();
999 gfx::Display display = gfx::Screen::GetScreenFor(native_view)-> 998 gfx::Display display = gfx::Screen::GetScreenFor(native_view)->
1000 GetDisplayNearestWindow(native_view); 999 GetDisplayNearestWindow(native_view);
1001 size.SetToMin(gfx::Size(display.size().width(), height())); 1000 size.SetToMin(gfx::Size(display.size().width(), height()));
1002 label.SetBoundsRect(gfx::Rect(size)); 1001 label.SetBoundsRect(gfx::Rect(size));
1003 scoped_ptr<gfx::Canvas> canvas( 1002 scoped_ptr<gfx::Canvas> canvas(
1004 GetCanvasForDragImage(GetWidget(), label.size())); 1003 GetCanvasForDragImage(GetWidget(), label.size()));
1005 label.SetEnabledColor(GetTextColor()); 1004 label.SetEnabledColor(GetTextColor());
1006 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1005 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1007 // Desktop Linux Aura does not yet support transparency in drag images. 1006 // Desktop Linux Aura does not yet support transparency in drag images.
1008 canvas->DrawColor(background); 1007 canvas->DrawColor(background);
1009 #endif 1008 #endif
1010 label.Paint(canvas.get(), views::CullSet()); 1009 label.Paint(canvas.get(), views::CullSet());
1011 const gfx::Vector2d kOffset(-15, 0); 1010 const gfx::Vector2d kOffset(-15, 0);
1012 drag_utils::SetDragImageOnDataObject(*canvas, kOffset, data); 1011 drag_utils::SetDragImageOnDataObject(*canvas, kOffset, data);
1013 if (controller_) 1012 if (controller_)
1014 controller_->OnWriteDragData(data); 1013 controller_->OnWriteDragData(data);
1014
1015 // Set the string to |selected_text| if a string was not set by
1016 // |controller_|.
1017 if (!data->HasString())
1018 data->SetString(selected_text);
1015 } 1019 }
1016 1020
1017 int Textfield::GetDragOperationsForView(View* sender, const gfx::Point& p) { 1021 int Textfield::GetDragOperationsForView(View* sender, const gfx::Point& p) {
1018 int drag_operations = ui::DragDropTypes::DRAG_COPY; 1022 int drag_operations = ui::DragDropTypes::DRAG_COPY;
1019 if (!enabled() || text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD || 1023 if (!enabled() || text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD ||
1020 !GetRenderText()->IsPointInSelection(p)) { 1024 !GetRenderText()->IsPointInSelection(p)) {
1021 drag_operations = ui::DragDropTypes::DRAG_NONE; 1025 drag_operations = ui::DragDropTypes::DRAG_NONE;
1022 } else if (sender == this && !read_only()) { 1026 } else if (sender == this && !read_only()) {
1023 drag_operations = 1027 drag_operations =
1024 ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY; 1028 ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY;
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 const size_t length = selection_clipboard_text.length(); 1764 const size_t length = selection_clipboard_text.length();
1761 range = gfx::Range(range.start() + length, range.end() + length); 1765 range = gfx::Range(range.start() + length, range.end() + length);
1762 } 1766 }
1763 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); 1767 model_->MoveCursorTo(gfx::SelectionModel(range, affinity));
1764 UpdateAfterChange(true, true); 1768 UpdateAfterChange(true, true);
1765 OnAfterUserAction(); 1769 OnAfterUserAction();
1766 } 1770 }
1767 } 1771 }
1768 1772
1769 } // namespace views 1773 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698