| 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/app_strings.h" | 13 #include "grit/app_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 "views/background.h" | 19 #include "views/background.h" |
| 20 #include "views/border.h" | 20 #include "views/border.h" |
| 21 #include "views/controls/focusable_border.h" | 21 #include "views/controls/focusable_border.h" |
| 22 #include "views/controls/menu/menu_2.h" | 22 #include "views/controls/menu/menu_item_view.h" |
| 23 #include "views/controls/menu/menu_model_adapter.h" |
| 23 #include "views/controls/textfield/text_style.h" | 24 #include "views/controls/textfield/text_style.h" |
| 24 #include "views/controls/textfield/textfield.h" | 25 #include "views/controls/textfield/textfield.h" |
| 25 #include "views/controls/textfield/textfield_controller.h" | 26 #include "views/controls/textfield/textfield_controller.h" |
| 26 #include "views/controls/textfield/textfield_views_model.h" | 27 #include "views/controls/textfield/textfield_views_model.h" |
| 27 #include "views/events/event.h" | 28 #include "views/events/event.h" |
| 28 #include "views/ime/input_method.h" | 29 #include "views/ime/input_method.h" |
| 29 #include "views/metrics.h" | 30 #include "views/metrics.h" |
| 30 #include "views/views_delegate.h" | 31 #include "views/views_delegate.h" |
| 31 #include "views/widget/widget.h" | 32 #include "views/widget/widget.h" |
| 33 #include "views/window/window.h" |
| 32 | 34 |
| 33 #if defined(OS_LINUX) | 35 #if defined(OS_LINUX) |
| 34 #include "ui/gfx/gtk_util.h" | 36 #include "ui/gfx/gtk_util.h" |
| 35 #endif | 37 #endif |
| 36 | 38 |
| 37 namespace { | 39 namespace { |
| 38 | 40 |
| 39 // A global flag to switch the Textfield wrapper to TextfieldViews. | 41 // A global flag to switch the Textfield wrapper to TextfieldViews. |
| 40 bool textfield_view_enabled = false; | 42 bool textfield_view_enabled = false; |
| 41 | 43 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 #else | 253 #else |
| 252 return text ? gfx::GetCursor(GDK_XTERM) : NULL; | 254 return text ? gfx::GetCursor(GDK_XTERM) : NULL; |
| 253 #endif | 255 #endif |
| 254 } | 256 } |
| 255 | 257 |
| 256 ///////////////////////////////////////////////////////////////// | 258 ///////////////////////////////////////////////////////////////// |
| 257 // NativeTextfieldViews, ContextMenuController overrides: | 259 // NativeTextfieldViews, ContextMenuController overrides: |
| 258 void NativeTextfieldViews::ShowContextMenuForView(View* source, | 260 void NativeTextfieldViews::ShowContextMenuForView(View* source, |
| 259 const gfx::Point& p, | 261 const gfx::Point& p, |
| 260 bool is_mouse_gesture) { | 262 bool is_mouse_gesture) { |
| 261 InitContextMenuIfRequired(); | 263 UpdateContextMenu(); |
| 262 context_menu_menu_->RunContextMenuAt(p); | 264 context_menu_menu_->RunMenuAt(GetWindow()->GetNativeWindow(), |
| 265 NULL, |
| 266 gfx::Rect(p, gfx::Size()), |
| 267 views::MenuItemView::TOPLEFT, |
| 268 true); |
| 263 } | 269 } |
| 264 | 270 |
| 265 ///////////////////////////////////////////////////////////////// | 271 ///////////////////////////////////////////////////////////////// |
| 266 // NativeTextfieldViews, views::DragController overrides: | 272 // NativeTextfieldViews, views::DragController overrides: |
| 267 void NativeTextfieldViews::WriteDragDataForView(views::View* sender, | 273 void NativeTextfieldViews::WriteDragDataForView(views::View* sender, |
| 268 const gfx::Point& press_pt, | 274 const gfx::Point& press_pt, |
| 269 OSExchangeData* data) { | 275 OSExchangeData* data) { |
| 270 DCHECK_NE(ui::DragDropTypes::DRAG_NONE, | 276 DCHECK_NE(ui::DragDropTypes::DRAG_NONE, |
| 271 GetDragOperationsForView(sender, press_pt)); | 277 GetDragOperationsForView(sender, press_pt)); |
| 272 data->SetString(GetSelectedText()); | 278 data->SetString(GetSelectedText()); |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 if (cursor_changed) { | 1031 if (cursor_changed) { |
| 1026 is_cursor_visible_ = true; | 1032 is_cursor_visible_ = true; |
| 1027 RepaintCursor(); | 1033 RepaintCursor(); |
| 1028 } | 1034 } |
| 1029 if (text_changed || cursor_changed) { | 1035 if (text_changed || cursor_changed) { |
| 1030 UpdateCursorBoundsAndTextOffset(); | 1036 UpdateCursorBoundsAndTextOffset(); |
| 1031 SchedulePaint(); | 1037 SchedulePaint(); |
| 1032 } | 1038 } |
| 1033 } | 1039 } |
| 1034 | 1040 |
| 1035 void NativeTextfieldViews::InitContextMenuIfRequired() { | 1041 void NativeTextfieldViews::UpdateContextMenu() { |
| 1036 if (context_menu_menu_.get()) | 1042 if (!context_menu_contents_.get()) { |
| 1037 return; | 1043 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); |
| 1038 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); | 1044 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); |
| 1039 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); | 1045 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
| 1040 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1046 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); |
| 1041 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); | 1047 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); |
| 1042 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); | 1048 context_menu_contents_->AddSeparator(); |
| 1043 context_menu_contents_->AddSeparator(); | 1049 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, |
| 1044 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, | 1050 IDS_APP_SELECT_ALL); |
| 1045 IDS_APP_SELECT_ALL); | 1051 |
| 1046 context_menu_menu_.reset(new Menu2(context_menu_contents_.get())); | 1052 context_menu_delegate_.reset( |
| 1053 new views::MenuModelAdapter(context_menu_contents_.get())); |
| 1054 context_menu_menu_.reset( |
| 1055 new views::MenuItemView(context_menu_delegate_.get())); |
| 1056 } |
| 1057 |
| 1058 context_menu_delegate_->BuildMenu(context_menu_menu_.get()); |
| 1047 } | 1059 } |
| 1048 | 1060 |
| 1049 void NativeTextfieldViews::OnTextInputTypeChanged() { | 1061 void NativeTextfieldViews::OnTextInputTypeChanged() { |
| 1050 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. | 1062 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. |
| 1051 if (textfield_->GetInputMethod()) | 1063 if (textfield_->GetInputMethod()) |
| 1052 textfield_->GetInputMethod()->OnTextInputTypeChanged(textfield_); | 1064 textfield_->GetInputMethod()->OnTextInputTypeChanged(textfield_); |
| 1053 } | 1065 } |
| 1054 | 1066 |
| 1055 void NativeTextfieldViews::OnCaretBoundsChanged() { | 1067 void NativeTextfieldViews::OnCaretBoundsChanged() { |
| 1056 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. | 1068 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 // Filter out all control characters, including tab and new line characters, | 1100 // Filter out all control characters, including tab and new line characters, |
| 1089 // and all characters with Alt modifier. But we need to allow characters with | 1101 // and all characters with Alt modifier. But we need to allow characters with |
| 1090 // AltGr modifier. | 1102 // AltGr modifier. |
| 1091 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different | 1103 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different |
| 1092 // flag that we don't care about. | 1104 // flag that we don't care about. |
| 1093 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 1105 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
| 1094 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; | 1106 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; |
| 1095 } | 1107 } |
| 1096 | 1108 |
| 1097 } // namespace views | 1109 } // namespace views |
| OLD | NEW |