| OLD | NEW |
| 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/native_textfield_views.h" | 5 #include "ui/views/controls/textfield/native_textfield_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 return false; | 186 return false; |
| 187 } | 187 } |
| 188 | 188 |
| 189 bool NativeTextfieldViews::GetDropFormats( | 189 bool NativeTextfieldViews::GetDropFormats( |
| 190 int* formats, | 190 int* formats, |
| 191 std::set<OSExchangeData::CustomFormat>* custom_formats) { | 191 std::set<OSExchangeData::CustomFormat>* custom_formats) { |
| 192 if (!textfield_->enabled() || textfield_->read_only()) | 192 if (!textfield_->enabled() || textfield_->read_only()) |
| 193 return false; | 193 return false; |
| 194 // TODO(msw): Can we support URL, FILENAME, etc.? | 194 // TODO(msw): Can we support URL, FILENAME, etc.? |
| 195 *formats = ui::OSExchangeData::STRING; | 195 *formats = ui::OSExchangeData::STRING; |
| 196 TextfieldController* controller = textfield_->GetController(); |
| 197 if (controller) |
| 198 controller->AppendDropFormats(formats, custom_formats); |
| 196 return true; | 199 return true; |
| 197 } | 200 } |
| 198 | 201 |
| 199 bool NativeTextfieldViews::CanDrop(const OSExchangeData& data) { | 202 bool NativeTextfieldViews::CanDrop(const OSExchangeData& data) { |
| 200 return textfield_->enabled() && !textfield_->read_only() && data.HasString(); | 203 int formats; |
| 204 std::set<OSExchangeData::CustomFormat> custom_formats; |
| 205 GetDropFormats(&formats, &custom_formats); |
| 206 return textfield_->enabled() && !textfield_->read_only() && |
| 207 data.HasAnyFormat(formats, custom_formats); |
| 201 } | 208 } |
| 202 | 209 |
| 203 int NativeTextfieldViews::OnDragUpdated(const ui::DropTargetEvent& event) { | 210 int NativeTextfieldViews::OnDragUpdated(const ui::DropTargetEvent& event) { |
| 204 DCHECK(CanDrop(event.data())); | 211 DCHECK(CanDrop(event.data())); |
| 205 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); | 212 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); |
| 206 is_drop_cursor_visible_ = !in_selection; | 213 is_drop_cursor_visible_ = !in_selection; |
| 207 // TODO(msw): Pan over text when the user drags to the visible text edge. | 214 // TODO(msw): Pan over text when the user drags to the visible text edge. |
| 208 OnCaretBoundsChanged(); | 215 OnCaretBoundsChanged(); |
| 209 SchedulePaint(); | 216 SchedulePaint(); |
| 210 | 217 |
| 211 if (initiating_drag_) { | 218 if (initiating_drag_) { |
| 212 if (in_selection) | 219 if (in_selection) |
| 213 return ui::DragDropTypes::DRAG_NONE; | 220 return ui::DragDropTypes::DRAG_NONE; |
| 214 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY : | 221 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY : |
| 215 ui::DragDropTypes::DRAG_MOVE; | 222 ui::DragDropTypes::DRAG_MOVE; |
| 216 } | 223 } |
| 217 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE; | 224 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE; |
| 218 } | 225 } |
| 219 | 226 |
| 220 int NativeTextfieldViews::OnPerformDrop(const ui::DropTargetEvent& event) { | 227 int NativeTextfieldViews::OnPerformDrop(const ui::DropTargetEvent& event) { |
| 221 DCHECK(CanDrop(event.data())); | 228 DCHECK(CanDrop(event.data())); |
| 229 |
| 230 TextfieldController* controller = textfield_->GetController(); |
| 231 if (controller) { |
| 232 int drag_operation = controller->OnDrop(event.data()); |
| 233 if (drag_operation != ui::DragDropTypes::DRAG_NONE) |
| 234 return drag_operation; |
| 235 } |
| 236 |
| 222 DCHECK(!initiating_drag_ || | 237 DCHECK(!initiating_drag_ || |
| 223 !GetRenderText()->IsPointInSelection(event.location())); | 238 !GetRenderText()->IsPointInSelection(event.location())); |
| 224 OnBeforeUserAction(); | 239 OnBeforeUserAction(); |
| 225 skip_input_method_cancel_composition_ = true; | 240 skip_input_method_cancel_composition_ = true; |
| 226 | 241 |
| 227 gfx::SelectionModel drop_destination_model = | 242 gfx::SelectionModel drop_destination_model = |
| 228 GetRenderText()->FindCursorPosition(event.location()); | 243 GetRenderText()->FindCursorPosition(event.location()); |
| 229 string16 text; | 244 string16 text; |
| 230 event.data().GetString(&text); | 245 event.data().GetString(&text); |
| 231 text = GetTextForDisplay(text); | 246 text = GetTextForDisplay(text); |
| (...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1262 // Filter out all control characters, including tab and new line characters, | 1277 // Filter out all control characters, including tab and new line characters, |
| 1263 // and all characters with Alt modifier. But we need to allow characters with | 1278 // and all characters with Alt modifier. But we need to allow characters with |
| 1264 // AltGr modifier. | 1279 // AltGr modifier. |
| 1265 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different | 1280 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different |
| 1266 // flag that we don't care about. | 1281 // flag that we don't care about. |
| 1267 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 1282 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
| 1268 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; | 1283 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; |
| 1269 } | 1284 } |
| 1270 | 1285 |
| 1271 } // namespace views | 1286 } // namespace views |
| OLD | NEW |