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

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. 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 return text ? gfx::GetCursor(GDK_XTERM) : NULL; 256 return text ? gfx::GetCursor(GDK_XTERM) : NULL;
255 #endif 257 #endif
256 } 258 }
257 259
258 ///////////////////////////////////////////////////////////////// 260 /////////////////////////////////////////////////////////////////
259 // NativeTextfieldViews, ContextMenuController overrides: 261 // NativeTextfieldViews, ContextMenuController overrides:
260 void NativeTextfieldViews::ShowContextMenuForView(View* source, 262 void NativeTextfieldViews::ShowContextMenuForView(View* source,
261 const gfx::Point& p, 263 const gfx::Point& p,
262 bool is_mouse_gesture) { 264 bool is_mouse_gesture) {
263 InitContextMenuIfRequired(); 265 InitContextMenuIfRequired();
264 context_menu_menu_->RunContextMenuAt(p); 266
267 views::MenuModelAdapter menu_delegate(context_menu_contents_.get());
268 views::MenuItemView menu(&menu_delegate);
oshima 2011/06/03 17:06:23 Any reason to change from member variable to stack
rhashimoto 2011/06/03 19:20:44 The menu needs to be updated because item enabled
269 menu_delegate.BuildMenu(&menu);
270 menu.RunMenuAt(GetWindow()->GetNativeWindow(), NULL,
271 gfx::Rect(p, gfx::Size(0, 0)),
272 views::MenuItemView::TOPLEFT,
oshima 2011/06/03 17:06:23 RTL?
rhashimoto 2011/06/03 19:20:44 Should I make it TOPRIGHT for RTL? Menu2 context
273 true);
265 } 274 }
266 275
267 ///////////////////////////////////////////////////////////////// 276 /////////////////////////////////////////////////////////////////
268 // NativeTextfieldViews, views::DragController overrides: 277 // NativeTextfieldViews, views::DragController overrides:
269 void NativeTextfieldViews::WriteDragDataForView(views::View* sender, 278 void NativeTextfieldViews::WriteDragDataForView(views::View* sender,
270 const gfx::Point& press_pt, 279 const gfx::Point& press_pt,
271 OSExchangeData* data) { 280 OSExchangeData* data) {
272 DCHECK_NE(ui::DragDropTypes::DRAG_NONE, 281 DCHECK_NE(ui::DragDropTypes::DRAG_NONE,
273 GetDragOperationsForView(sender, press_pt)); 282 GetDragOperationsForView(sender, press_pt));
274 data->SetString(GetSelectedText()); 283 data->SetString(GetSelectedText());
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 is_cursor_visible_ = true; 1033 is_cursor_visible_ = true;
1025 RepaintCursor(); 1034 RepaintCursor();
1026 } 1035 }
1027 if (text_changed || cursor_changed) { 1036 if (text_changed || cursor_changed) {
1028 UpdateCursorBoundsAndTextOffset(); 1037 UpdateCursorBoundsAndTextOffset();
1029 SchedulePaint(); 1038 SchedulePaint();
1030 } 1039 }
1031 } 1040 }
1032 1041
1033 void NativeTextfieldViews::InitContextMenuIfRequired() { 1042 void NativeTextfieldViews::InitContextMenuIfRequired() {
1034 if (context_menu_menu_.get()) 1043 if (context_menu_contents_.get())
1035 return; 1044 return;
1036 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); 1045 context_menu_contents_.reset(new ui::SimpleMenuModel(this));
1037 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); 1046 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT);
1038 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); 1047 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY);
1039 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); 1048 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE);
1040 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE); 1049 context_menu_contents_->AddItemWithStringId(IDS_APP_DELETE, IDS_APP_DELETE);
1041 context_menu_contents_->AddSeparator(); 1050 context_menu_contents_->AddSeparator();
1042 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, 1051 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL,
1043 IDS_APP_SELECT_ALL); 1052 IDS_APP_SELECT_ALL);
1044 context_menu_menu_.reset(new Menu2(context_menu_contents_.get()));
1045 } 1053 }
1046 1054
1047 void NativeTextfieldViews::OnTextInputTypeChanged() { 1055 void NativeTextfieldViews::OnTextInputTypeChanged() {
1048 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. 1056 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320.
1049 if (textfield_->GetInputMethod()) 1057 if (textfield_->GetInputMethod())
1050 textfield_->GetInputMethod()->OnTextInputTypeChanged(textfield_); 1058 textfield_->GetInputMethod()->OnTextInputTypeChanged(textfield_);
1051 } 1059 }
1052 1060
1053 void NativeTextfieldViews::OnCaretBoundsChanged() { 1061 void NativeTextfieldViews::OnCaretBoundsChanged() {
1054 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320. 1062 // TODO(suzhe): changed from DCHECK. See http://crbug.com/81320.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 // Filter out all control characters, including tab and new line characters, 1094 // Filter out all control characters, including tab and new line characters,
1087 // and all characters with Alt modifier. But we need to allow characters with 1095 // and all characters with Alt modifier. But we need to allow characters with
1088 // AltGr modifier. 1096 // AltGr modifier.
1089 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different 1097 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different
1090 // flag that we don't care about. 1098 // flag that we don't care about.
1091 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && 1099 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) &&
1092 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; 1100 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN;
1093 } 1101 }
1094 1102
1095 } // namespace views 1103 } // 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