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

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

Issue 265713007: views: Update event-related API to use PointF/RectF instead of Point/Rect. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 gfx::Rect(point, gfx::Size()), 930 gfx::Rect(point, gfx::Size()),
931 MENU_ANCHOR_TOPLEFT, 931 MENU_ANCHOR_TOPLEFT,
932 source_type, 932 source_type,
933 MenuRunner::HAS_MNEMONICS | MenuRunner::CONTEXT_MENU)); 933 MenuRunner::HAS_MNEMONICS | MenuRunner::CONTEXT_MENU));
934 } 934 }
935 935
936 //////////////////////////////////////////////////////////////////////////////// 936 ////////////////////////////////////////////////////////////////////////////////
937 // Textfield, DragController overrides: 937 // Textfield, DragController overrides:
938 938
939 void Textfield::WriteDragDataForView(View* sender, 939 void Textfield::WriteDragDataForView(View* sender,
940 const gfx::Point& press_pt, 940 const gfx::PointF& press_pt,
941 OSExchangeData* data) { 941 OSExchangeData* data) {
942 const base::string16& selected_text(GetSelectedText()); 942 const base::string16& selected_text(GetSelectedText());
943 data->SetString(selected_text); 943 data->SetString(selected_text);
944 Label label(selected_text, GetFontList()); 944 Label label(selected_text, GetFontList());
945 const SkColor background = GetBackgroundColor(); 945 const SkColor background = GetBackgroundColor();
946 label.SetBackgroundColor(SkColorSetA(background, SK_AlphaTRANSPARENT)); 946 label.SetBackgroundColor(SkColorSetA(background, SK_AlphaTRANSPARENT));
947 gfx::Size size(label.GetPreferredSize()); 947 gfx::Size size(label.GetPreferredSize());
948 gfx::NativeView native_view = GetWidget()->GetNativeView(); 948 gfx::NativeView native_view = GetWidget()->GetNativeView();
949 gfx::Display display = gfx::Screen::GetScreenFor(native_view)-> 949 gfx::Display display = gfx::Screen::GetScreenFor(native_view)->
950 GetDisplayNearestWindow(native_view); 950 GetDisplayNearestWindow(native_view);
951 size.SetToMin(gfx::Size(display.size().width(), height())); 951 size.SetToMin(gfx::Size(display.size().width(), height()));
952 label.SetBoundsRect(gfx::Rect(size)); 952 label.SetBoundsRect(gfx::Rect(size));
953 scoped_ptr<gfx::Canvas> canvas( 953 scoped_ptr<gfx::Canvas> canvas(
954 GetCanvasForDragImage(GetWidget(), label.size())); 954 GetCanvasForDragImage(GetWidget(), label.size()));
955 label.SetEnabledColor(GetTextColor()); 955 label.SetEnabledColor(GetTextColor());
956 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 956 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
957 // Desktop Linux Aura does not yet support transparency in drag images. 957 // Desktop Linux Aura does not yet support transparency in drag images.
958 canvas->DrawColor(background); 958 canvas->DrawColor(background);
959 #endif 959 #endif
960 label.Paint(canvas.get()); 960 label.Paint(canvas.get());
961 const gfx::Vector2d kOffset(-15, 0); 961 const gfx::Vector2d kOffset(-15, 0);
962 drag_utils::SetDragImageOnDataObject(*canvas, label.size(), kOffset, data); 962 drag_utils::SetDragImageOnDataObject(*canvas, label.size(), kOffset, data);
963 if (controller_) 963 if (controller_)
964 controller_->OnWriteDragData(data); 964 controller_->OnWriteDragData(data);
965 } 965 }
966 966
967 int Textfield::GetDragOperationsForView(View* sender, const gfx::Point& p) { 967 int Textfield::GetDragOperationsForView(View* sender, const gfx::PointF& p) {
968 int drag_operations = ui::DragDropTypes::DRAG_COPY; 968 int drag_operations = ui::DragDropTypes::DRAG_COPY;
969 if (!enabled() || text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD || 969 if (!enabled() || text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD ||
970 !GetRenderText()->IsPointInSelection(p)) { 970 !GetRenderText()->IsPointInSelection(gfx::ToFlooredPoint(p))) {
971 drag_operations = ui::DragDropTypes::DRAG_NONE; 971 drag_operations = ui::DragDropTypes::DRAG_NONE;
972 } else if (sender == this && !read_only()) { 972 } else if (sender == this && !read_only()) {
973 drag_operations = 973 drag_operations =
974 ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY; 974 ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY;
975 } 975 }
976 if (controller_) 976 if (controller_)
977 controller_->OnGetDragOperationsForTextfield(&drag_operations); 977 controller_->OnGetDragOperationsForTextfield(&drag_operations);
978 return drag_operations; 978 return drag_operations;
979 } 979 }
980 980
981 bool Textfield::CanStartDragForView(View* sender, 981 bool Textfield::CanStartDragForView(View* sender,
982 const gfx::Point& press_pt, 982 const gfx::PointF& press_pt,
983 const gfx::Point& p) { 983 const gfx::PointF& p) {
984 return initiating_drag_ && GetRenderText()->IsPointInSelection(press_pt); 984 return initiating_drag_ &&
985 GetRenderText()->IsPointInSelection(gfx::ToFlooredPoint(press_pt));
985 } 986 }
986 987
987 //////////////////////////////////////////////////////////////////////////////// 988 ////////////////////////////////////////////////////////////////////////////////
988 // Textfield, ui::TouchEditable overrides: 989 // Textfield, ui::TouchEditable overrides:
989 990
990 void Textfield::SelectRect(const gfx::Point& start, const gfx::Point& end) { 991 void Textfield::SelectRect(const gfx::Point& start, const gfx::Point& end) {
991 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) 992 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE)
992 return; 993 return;
993 994
994 gfx::SelectionModel start_caret = GetRenderText()->FindCursorPosition(start); 995 gfx::SelectionModel start_caret = GetRenderText()->FindCursorPosition(start);
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 const size_t length = selection_clipboard_text.length(); 1679 const size_t length = selection_clipboard_text.length();
1679 range = gfx::Range(range.start() + length, range.end() + length); 1680 range = gfx::Range(range.start() + length, range.end() + length);
1680 } 1681 }
1681 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); 1682 model_->MoveCursorTo(gfx::SelectionModel(range, affinity));
1682 UpdateAfterChange(true, true); 1683 UpdateAfterChange(true, true);
1683 OnAfterUserAction(); 1684 OnAfterUserAction();
1684 } 1685 }
1685 } 1686 }
1686 1687
1687 } // namespace views 1688 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698