| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/textfield/native_textfield_views.h" | 5 #include "views/controls/textfield/native_textfield_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "grit/ui_strings.h" | 13 #include "grit/ui_strings.h" |
| 14 #include "ui/base/clipboard/clipboard.h" | 14 #include "ui/base/clipboard/clipboard.h" |
| 15 #include "ui/base/dragdrop/drag_drop_types.h" | 15 #include "ui/base/dragdrop/drag_drop_types.h" |
| 16 #include "ui/base/range/range.h" | 16 #include "ui/base/range/range.h" |
| 17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/insets.h" | 18 #include "ui/gfx/insets.h" |
| 19 #include "ui/gfx/render_text.h" | 19 #include "ui/gfx/render_text.h" |
| 20 #include "views/background.h" | 20 #include "views/background.h" |
| 21 #include "views/border.h" | 21 #include "views/border.h" |
| 22 #include "views/controls/focusable_border.h" | 22 #include "views/controls/focusable_border.h" |
| 23 #include "views/controls/menu/menu_item_view.h" | 23 #include "views/controls/menu/menu_item_view.h" |
| 24 #include "views/controls/menu/menu_model_adapter.h" | 24 #include "views/controls/menu/menu_model_adapter.h" |
| 25 #include "views/controls/menu/menu_runner.h" |
| 25 #include "views/controls/textfield/textfield.h" | 26 #include "views/controls/textfield/textfield.h" |
| 26 #include "views/controls/textfield/textfield_controller.h" | 27 #include "views/controls/textfield/textfield_controller.h" |
| 27 #include "views/controls/textfield/textfield_views_model.h" | 28 #include "views/controls/textfield/textfield_views_model.h" |
| 28 #include "views/events/event.h" | 29 #include "views/events/event.h" |
| 29 #include "views/ime/input_method.h" | 30 #include "views/ime/input_method.h" |
| 30 #include "views/metrics.h" | 31 #include "views/metrics.h" |
| 31 #include "views/views_delegate.h" | 32 #include "views/views_delegate.h" |
| 32 #include "views/widget/widget.h" | 33 #include "views/widget/widget.h" |
| 33 | 34 |
| 34 #if defined(OS_LINUX) | 35 #if defined(OS_LINUX) |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 return text_cursor ? gfx::GetCursor(GDK_XTERM) : NULL; | 292 return text_cursor ? gfx::GetCursor(GDK_XTERM) : NULL; |
| 292 #endif | 293 #endif |
| 293 } | 294 } |
| 294 | 295 |
| 295 ///////////////////////////////////////////////////////////////// | 296 ///////////////////////////////////////////////////////////////// |
| 296 // NativeTextfieldViews, ContextMenuController overrides: | 297 // NativeTextfieldViews, ContextMenuController overrides: |
| 297 void NativeTextfieldViews::ShowContextMenuForView(View* source, | 298 void NativeTextfieldViews::ShowContextMenuForView(View* source, |
| 298 const gfx::Point& p, | 299 const gfx::Point& p, |
| 299 bool is_mouse_gesture) { | 300 bool is_mouse_gesture) { |
| 300 UpdateContextMenu(); | 301 UpdateContextMenu(); |
| 301 context_menu_menu_->RunMenuAt(GetWidget(), | 302 if (context_menu_runner_->RunMenuAt( |
| 302 NULL, | 303 GetWidget(), NULL, gfx::Rect(p, gfx::Size()), |
| 303 gfx::Rect(p, gfx::Size()), | 304 views::MenuItemView::TOPLEFT, MenuRunner::HAS_MNEMONICS) == |
| 304 views::MenuItemView::TOPLEFT, | 305 MenuRunner::MENU_DELETED) |
| 305 true); | 306 return; |
| 306 } | 307 } |
| 307 | 308 |
| 308 ///////////////////////////////////////////////////////////////// | 309 ///////////////////////////////////////////////////////////////// |
| 309 // NativeTextfieldViews, views::DragController overrides: | 310 // NativeTextfieldViews, views::DragController overrides: |
| 310 void NativeTextfieldViews::WriteDragDataForView(views::View* sender, | 311 void NativeTextfieldViews::WriteDragDataForView(views::View* sender, |
| 311 const gfx::Point& press_pt, | 312 const gfx::Point& press_pt, |
| 312 OSExchangeData* data) { | 313 OSExchangeData* data) { |
| 313 DCHECK_NE(ui::DragDropTypes::DRAG_NONE, | 314 DCHECK_NE(ui::DragDropTypes::DRAG_NONE, |
| 314 GetDragOperationsForView(sender, press_pt)); | 315 GetDragOperationsForView(sender, press_pt)); |
| 315 data->SetString(GetSelectedText()); | 316 data->SetString(GetSelectedText()); |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); | 969 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); |
| 969 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 970 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
| 970 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); | 971 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); |
| 971 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); | 972 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); |
| 972 context_menu_contents_->AddSeparator(); | 973 context_menu_contents_->AddSeparator(); |
| 973 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, | 974 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, |
| 974 IDS_APP_SELECT_ALL); | 975 IDS_APP_SELECT_ALL); |
| 975 | 976 |
| 976 context_menu_delegate_.reset( | 977 context_menu_delegate_.reset( |
| 977 new views::MenuModelAdapter(context_menu_contents_.get())); | 978 new views::MenuModelAdapter(context_menu_contents_.get())); |
| 978 context_menu_menu_.reset( | 979 context_menu_runner_.reset( |
| 979 new views::MenuItemView(context_menu_delegate_.get())); | 980 new MenuRunner(new views::MenuItemView(context_menu_delegate_.get()))); |
| 980 } | 981 } |
| 981 | 982 |
| 982 context_menu_delegate_->BuildMenu(context_menu_menu_.get()); | 983 context_menu_delegate_->BuildMenu(context_menu_runner_->GetMenu()); |
| 983 } | 984 } |
| 984 | 985 |
| 985 void NativeTextfieldViews::OnTextInputTypeChanged() { | 986 void NativeTextfieldViews::OnTextInputTypeChanged() { |
| 986 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. | 987 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. |
| 987 if (textfield_->GetInputMethod()) | 988 if (textfield_->GetInputMethod()) |
| 988 textfield_->GetInputMethod()->OnTextInputTypeChanged(textfield_); | 989 textfield_->GetInputMethod()->OnTextInputTypeChanged(textfield_); |
| 989 } | 990 } |
| 990 | 991 |
| 991 void NativeTextfieldViews::OnCaretBoundsChanged() { | 992 void NativeTextfieldViews::OnCaretBoundsChanged() { |
| 992 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. | 993 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 // Filter out all control characters, including tab and new line characters, | 1038 // Filter out all control characters, including tab and new line characters, |
| 1038 // and all characters with Alt modifier. But we need to allow characters with | 1039 // and all characters with Alt modifier. But we need to allow characters with |
| 1039 // AltGr modifier. | 1040 // AltGr modifier. |
| 1040 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different | 1041 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different |
| 1041 // flag that we don't care about. | 1042 // flag that we don't care about. |
| 1042 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 1043 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
| 1043 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; | 1044 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; |
| 1044 } | 1045 } |
| 1045 | 1046 |
| 1046 } // namespace views | 1047 } // namespace views |
| OLD | NEW |