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

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

Issue 7104013: Convert NativeTextFieldViews context menu from Menu2 to MenuItemView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test compile. Created 9 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) 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
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(), NULL,
oshima 2011/06/07 17:21:44 move NULL to next line
rhashimoto 2011/06/07 21:07:22 Done.
265 gfx::Rect(p, gfx::Size()),
266 views::MenuItemView::TOPLEFT,
267 true);
263 } 268 }
264 269
265 ///////////////////////////////////////////////////////////////// 270 /////////////////////////////////////////////////////////////////
266 // NativeTextfieldViews, views::DragController overrides: 271 // NativeTextfieldViews, views::DragController overrides:
267 void NativeTextfieldViews::WriteDragDataForView(views::View* sender, 272 void NativeTextfieldViews::WriteDragDataForView(views::View* sender,
268 const gfx::Point& press_pt, 273 const gfx::Point& press_pt,
269 OSExchangeData* data) { 274 OSExchangeData* data) {
270 DCHECK_NE(ui::DragDropTypes::DRAG_NONE, 275 DCHECK_NE(ui::DragDropTypes::DRAG_NONE,
271 GetDragOperationsForView(sender, press_pt)); 276 GetDragOperationsForView(sender, press_pt));
272 data->SetString(GetSelectedText()); 277 data->SetString(GetSelectedText());
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 if (cursor_changed) { 1030 if (cursor_changed) {
1026 is_cursor_visible_ = true; 1031 is_cursor_visible_ = true;
1027 RepaintCursor(); 1032 RepaintCursor();
1028 } 1033 }
1029 if (text_changed || cursor_changed) { 1034 if (text_changed || cursor_changed) {
1030 UpdateCursorBoundsAndTextOffset(); 1035 UpdateCursorBoundsAndTextOffset();
1031 SchedulePaint(); 1036 SchedulePaint();
1032 } 1037 }
1033 } 1038 }
1034 1039
1035 void NativeTextfieldViews::InitContextMenuIfRequired() { 1040 void NativeTextfieldViews::UpdateContextMenu() {
1036 if (context_menu_menu_.get()) 1041 if (!context_menu_contents_.get()) {
1037 return; 1042 context_menu_contents_.reset(new ui::SimpleMenuModel(this));
1038 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); 1043 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT);
1039 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); 1044 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY);
1040 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); 1045 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE);
1041 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); 1046 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE);
1042 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); 1047 context_menu_contents_->AddSeparator();
1043 context_menu_contents_->AddSeparator(); 1048 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL,
1044 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, 1049 IDS_APP_SELECT_ALL);
1045 IDS_APP_SELECT_ALL); 1050
1046 context_menu_menu_.reset(new Menu2(context_menu_contents_.get())); 1051 context_menu_delegate_.reset(
1052 new views::MenuModelAdapter(context_menu_contents_.get()));
1053 context_menu_menu_.reset(
1054 new views::MenuItemView(context_menu_delegate_.get()));
1055 }
1056
1057 context_menu_delegate_->BuildMenu(context_menu_menu_.get());
1047 } 1058 }
1048 1059
1049 void NativeTextfieldViews::OnTextInputTypeChanged() { 1060 void NativeTextfieldViews::OnTextInputTypeChanged() {
1050 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. 1061 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320.
1051 if (textfield_->GetInputMethod()) 1062 if (textfield_->GetInputMethod())
1052 textfield_->GetInputMethod()->OnTextInputTypeChanged(textfield_); 1063 textfield_->GetInputMethod()->OnTextInputTypeChanged(textfield_);
1053 } 1064 }
1054 1065
1055 void NativeTextfieldViews::OnCaretBoundsChanged() { 1066 void NativeTextfieldViews::OnCaretBoundsChanged() {
1056 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. 1067 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 // Filter out all control characters, including tab and new line characters, 1099 // 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 1100 // and all characters with Alt modifier. But we need to allow characters with
1090 // AltGr modifier. 1101 // AltGr modifier.
1091 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different 1102 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different
1092 // flag that we don't care about. 1103 // flag that we don't care about.
1093 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && 1104 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) &&
1094 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; 1105 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN;
1095 } 1106 }
1096 1107
1097 } // namespace views 1108 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/native_textfield_views.h ('k') | views/controls/textfield/native_textfield_views_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698